]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/notation/spacing.itely
Docs: Fix broken refs
[lilypond.git] / Documentation / notation / spacing.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.12.0"
11
12 @ignore
13 GDP TODO list
14
15 Negative numbers are allowed:
16 > Are you sure? The following works well
17 > \paper{
18 >   first-page-number = -2
19 > }
20 > and prints page number -1 on the second page, for example.
21
22
23 In 5.2.1 the @refbugs (line 495 in spacing.itely on master) it
24 states:
25
26 "@code{layout-set-staff-size} does not change the distance between
27 the
28 staff lines."
29
30 Could we add a sentence:
31 "Use instead the pair               fontSize = #@var{N}
32             \override StaffSymbol #'staff-space = #(magstep
33 @var{N})
34 inside the Staff context to change the size of the font and the
35 distance between
36 staff lines accordingly."
37
38 Actually I found, that the @internalsref{StaffSymbol} at line 481
39 sends to an uncomplete
40 documentation. The property staff-space is not explained here. I
41 thought Y-extent might be of
42 help, but it is in turn explained by x-space which again is
43 missing from the list. Who has the
44 knowledge to fix this?
45
46
47 Clarify
48 http://code.google.com/p/lilypond/issues/detail?id=68
49
50 @end ignore
51
52
53 @node Spacing issues
54 @chapter Spacing issues
55
56 The global paper layout is determined by three factors: the page layout, the
57 line breaks, and the spacing.  These all influence each other.  The
58 choice of spacing determines how densely each system of music is set.
59 This influences where line breaks are chosen, and thus ultimately, how
60 many pages a piece of music takes.
61
62 Globally speaking, this procedure happens in four steps: first,
63 flexible distances (@q{springs}) are chosen, based on durations.  All
64 possible line breaking combinations are tried, and a @q{badness} score
65 is calculated for each.  Then the height of each possible system is
66 estimated.  Finally, a page breaking and line breaking combination is chosen
67 so that neither the horizontal nor the vertical spacing is too cramped
68 or stretched.
69
70 Settings which influence layout may be placed in two blocks.
71 The @code{\paper @{...@}} block is placed outside any
72 @code{\score @{...@}} blocks and contains settings that
73 relate to the entire document.  The @code{\layout @{...@}}
74 block is placed within a @code{\score @{...@}} block and
75 contains settings for that particular score.  If you have
76 only one @code{\score @{...@}} block the two have the same
77 effect.  In general the commands shown in this chapter can
78 be placed in either.
79
80 @menu
81 * Paper and pages::
82 * Music layout::
83 * Breaks::
84 * Vertical spacing::
85 * Horizontal spacing::
86 * Fitting music onto fewer pages::
87 @end menu
88
89
90 @node Paper and pages
91 @section Paper and pages
92
93 This section deals with the boundaries that define the area
94 within which music can be printed.
95
96 @menu
97 * Paper size::
98 * Page formatting::
99 @end menu
100
101
102 @node Paper size
103 @subsection Paper size
104
105 @cindex paper size
106 @cindex page size
107
108 Two functions are available for changing the paper size:
109 @code{set-default-paper-size} and @code{set-paper-size}.
110 @code{set-default-paper-size} must be placed in the toplevel
111 scope, and @code{set-paper-size} must be placed in a @code{\paper}
112 block:
113
114 @example
115 #(set-default-paper-size "a4")
116 @end example
117
118 @example
119 \paper @{
120   #(set-paper-size "a4")
121 @}
122 @end example
123
124 @noindent
125 @code{set-default-paper-size} sets the size of all pages, whereas
126 @code{set-paper-size} only sets the size of the pages that the
127 @code{\paper} block applies to.  For example, if the @code{\paper}
128 block is at the top of the file, then it will apply the paper size
129 to all pages.  If the @code{\paper} block is inside a
130 @code{\book}, then the paper size will only apply to that book.
131
132 Common paper sizes are available, including @code{a4},
133 @code{letter}, @code{legal}, and @code{11x17} (also known as
134 tabloid).  Many more paper sizes are supported by default.  For
135 details, see @file{scm/@/paper@/.scm}, and search for the
136 definition of @code{paper-alist}.
137
138 @c TODO add a new appendix for paper sizes (auto-generated) -pm
139
140 @warning{The default paper size is @code{a4}.}
141
142 Extra sizes may be added by editing the definition of
143 @code{paper-alist} in the initialization file
144 @file{scm/@/paper@/.scm}, however they will be overridden on a
145 subsequent install.
146
147 @cindex orientation
148 @cindex landscape
149
150 If the symbol @code{'landscape} is supplied as an argument to
151 @code{set-default-paper-size}, pages will be rotated by 90
152 degrees, and wider line widths will be set accordingly.
153
154 @example
155 #(set-default-paper-size "a6" 'landscape)
156 @end example
157
158 Setting the paper size will adjust a number of @code{\paper}
159 variables, such as margins.  To use a particular paper size with
160 altered @code{\paper} variables, set the paper size before setting
161 the variables.
162
163
164 @seealso
165 Installed Files:
166 @file{scm/@/paper@/.scm}.
167
168 Snippets:
169 @rlsr{Spacing}.
170
171
172 @node Page formatting
173 @subsection Page formatting
174
175 Margins, headers, and footers and other layout variables are
176 automatically set according to the paper size.
177
178 This section lists and describes a number of paper variables that
179 may be altered.
180
181 @menu
182 * Vertical dimensions::
183 * Horizontal dimensions::
184 * Other layout variables::
185 @end menu
186
187
188 @node Vertical dimensions
189 @unnumberedsubsubsec Vertical dimensions
190
191 These variables are used to set different vertical dimensions on a
192 page:
193
194 @funindex \paper
195
196 @table @code
197
198 @item after-title-space
199 @funindex after-title-space
200
201 The amount of space between the title and the first system.
202 Default: @code{5\mm}.
203
204 @item before-title-space
205 @funindex before-title-space
206
207 Amount of space between the last system of the previous piece and the
208 title of the next.  Default: @code{10\mm}.
209
210 @item between-system-padding
211 @funindex between-system-padding
212
213 The minimum amount of white space that will always be present
214 between the bottom-most symbol of one system, and the top-most of
215 the next system.  Default: @code{4\mm}.
216
217 Increasing this will put systems whose bounding boxes almost touch
218 farther apart.
219
220 @item between-system-space
221 @funindex between-system-space
222
223 The distance between systems.  It is the ideal distance between
224 the center of the bottom staff of one system and the center of the
225 top staff of the next system.  Default: @code{20\mm}.
226
227 Increasing this value will provide a more even appearance of the
228 page at the cost of using more vertical space.
229
230 @item between-title-space
231 @funindex between-title-space
232
233 Amount of space between consecutive titles (e.g., the title of the
234 book and the title of a piece).  Default: @code{2\mm}.
235
236 @item bottom-margin
237 @funindex bottom-margin
238
239 The margin between footer and bottom of the page.  Default:
240 @code{6\mm}.
241
242 @item foot-separation
243 @funindex foot-separation
244
245 Distance between the bottom-most music system and the page
246 footer.  Default: @code{4\mm}.
247
248 @item head-separation
249 @funindex head-separation
250
251 Distance between the header markup (@code{oddHeaderMarkup} and
252 @code{evenHeaderMarkup}) and the title markup
253 (@code{bookTitleMarkup}, @code{title}, and others).  If the header
254 markup and title markup are not present, it is the distance
255 between @code{top-margin} and the spot where the title markup
256 would normally appear.  Default: @code{4\mm}.
257
258 @item page-top-space
259 @funindex page-top-space
260
261 Distance from the top of the printable area to the center of the
262 first staff.  This only works for staves that are vertically
263 small.  Big staves are set with the top of their bounding box
264 aligned to the top of the printable area.  Default: @code{12\mm}.
265
266 @item paper-height
267 @funindex paper-height
268
269 The height of the page.  Default: the height of the current paper
270 size.  For details, see @ref{Paper size}.
271
272 @item top-margin
273 @funindex top-margin
274
275 The margin between header and top of the page.  Default:
276 @code{5\mm}.
277
278 @end table
279
280
281 @snippets
282
283 The header and footer are created by the functions make-footer and
284 make-header, defined in \paper.  The default implementations are in
285 ly/paper-defaults.ly and ly/titling-init.ly.
286
287 The page layout itself is done by two functions in the \paper block,
288 page-music-height and page-make-stencil.  The former tells the
289 line-breaking algorithm how much space can be spent on a page, the
290 latter creates the actual page given the system to put on it.
291
292 You can define paper block values in Scheme.  In that case mm, in, pt,
293 and cm are variables defined in paper-defaults.ly with values in
294 millimeters.  That is why the value 2 cm must be multiplied in the
295 example
296
297 @example
298 \paper @{
299  #(define bottom-margin (* 2 cm))
300 @}
301 @end example
302
303
304 Example:
305
306 @example
307 \paper@{
308   paper-width = 2\cm
309   top-margin = 3\cm
310   bottom-margin = 3\cm
311   ragged-last-bottom = ##t
312 @}
313 @end example
314
315 This second example centers page numbers at the bottom of every page.
316
317 @example
318 \paper @{
319   print-page-number = ##t
320   print-first-page-number = ##t
321   oddHeaderMarkup = \markup \fill-line @{ " " @}
322   evenHeaderMarkup = \markup \fill-line @{ " " @}
323   oddFooterMarkup = \markup @{ \fill-line @{
324      \bold \fontsize #3 \on-the-fly #print-page-number-check-first
325      \fromproperty #'page:page-number-string @} @}
326   evenFooterMarkup = \markup @{ \fill-line @{
327      \bold \fontsize #3 \on-the-fly #print-page-number-check-first
328      \fromproperty #'page:page-number-string @} @}
329 @}
330 @end example
331
332 You can also define these values in Scheme.  In that case @code{mm},
333 @code{in}, @code{pt}, and @code{cm} are variables defined in
334 @file{paper-defaults.ly} with values in millimeters.  That is why the
335 value must be multiplied in the example
336
337 @example
338 \paper @{
339   #(define bottom-margin (* 2 cm))
340 @}
341 @end example
342
343 The header and footer are created by the functions @code{make-footer}
344 and @code{make-header}, defined in @code{\paper}.  The default
345 implementations are in @file{ly/@/paper@/-defaults@/.ly} and
346 @file{ly/@/titling@/-init@/.ly}.
347
348 The page layout itself is done by two functions in the
349 @code{\paper} block, @code{page-music-height} and
350 @code{page-make-stencil}.  The former tells the line-breaking algorithm
351 how much space can be spent on a page, the latter creates the actual
352 page given the system to put on it.
353
354
355 @seealso
356 Notation Reference:
357 @ref{Vertical spacing between systems}.
358
359 Snippets:
360 @rlsr{Spacing}.
361
362
363 @node Horizontal dimensions
364 @unnumberedsubsubsec Horizontal dimensions
365
366 @warning{If @code{paper-width} is manually set, @code{line-width},
367 @code{left-margin}, @code{indent}, and @code{short-indent} may
368 have to be adjusted as well.}
369
370 There are a few variables that determine the horizontal dimensions
371 on a page:
372
373 @table @code
374
375 @item horizontal-shift
376 @funindex horizontal-shift
377
378 The amount that all systems (including titles and system
379 separators) are shifted to the right.  Default: @code{0.0}.
380
381 @item indent
382 @funindex indent
383
384 The level of indentation for the first system in a score.
385 Default: @code{paper-width} divided by @code{14}, as determined by
386 @code{set-default-paper-size} or @code{set-paper-size}.
387
388 @item left-margin
389 @funindex left-margin
390
391 The margin between the left edge of the page and the beginning of
392 each system.  Default: @code{10\mm}, as determined by
393 @code{set-default-paper-size} or @code{set-paper-size}.
394
395 @item line-width
396 @funindex line-width
397
398 The width of music systems.  Default: @code{paper-width} minus
399 @code{20\mm}, as determined by @code{set-default-paper-size} or
400 @code{set-paper-size}.
401
402 @item paper-width
403 @funindex paper-width
404
405 The width of the page.  Default: the width of the current paper
406 size.  For details, see @ref{Paper size}.
407
408 @item short-indent
409 @funindex short-indent
410
411 The level of indentation for all systems in a score besides the
412 first system.  Default: @code{0}, as determined by
413 @code{set-default-paper-size} or @code{set-paper-size}.
414
415 @end table
416
417
418 @seealso
419 Snippets:
420 @rlsr{Spacing}.
421
422
423 @knownissues
424
425 The option @code{right-margin} is defined but doesn't set the
426 right margin yet.  The value for the right margin has to be
427 defined by adjusting the values of @code{left-margin} and
428 @code{line-width}.
429
430
431 @node Other layout variables
432 @unnumberedsubsubsec Other layout variables
433
434 These variables can be used to adjust page layout in general.
435
436 @table @code
437
438 @item auto-first-page-number
439 @funindex auto-first-page-number
440
441 The page breaking algorithm is affected by the first page number
442 being odd or even.  If set to true, the page breaking algorithm
443 will decide whether to start with an odd or even number.  This
444 will result in the first page number remaining as is or being
445 increased by one.  Default: @code{##f}.
446
447 @ignore
448
449 FIXME: this variable is used, but I don't know what it does. -pm
450 @item blank-after-score-page-force
451 @funindex blank-after-score-page-force
452
453 Default: @code{2}.
454
455 @end ignore
456
457 @item blank-last-page-force
458 @funindex blank-last-page-force
459
460 The penalty for ending the score on an odd-numbered page.
461 Default: @code{0}.
462
463 @item blank-page-force
464 @funindex blank-page-force
465
466 The penalty for having a blank page in the middle of a
467 score.  This is not used by @code{ly:optimal-breaking} since it will
468 never consider blank pages in the middle of a score.  Default:
469 @code{5}.
470
471 @item first-page-number
472 @funindex first-page-number
473
474 The value of the page number on the first page.  Default:
475 @code{#1}.
476
477 @item max-systems-per-page
478 The maximum number of systems that will be placed on a page. This
479 is currently supported only by the @code{ly:optimal-breaking} algorithm.
480 Default: unset.
481
482 @item min-systems-per-page
483 The minimum number of systems that will be placed on a page. This
484 may cause pages to be overfilled if it is made too large. This is
485 currently supported only by the @code{ly:optimal-breaking} algorithm.
486 Default: unset.
487
488 @item page-breaking-between-system-padding
489 @funindex page-breaking-between-system-padding
490
491 Tricks the page breaker into thinking that
492 @code{between-system-padding} is set to something different than
493 it really is.  For example, if this variable is set to something
494 substantially larger than @code{between-system-padding}, then the
495 page-breaker will put fewer systems on each page.  Default: unset.
496
497 @item page-count
498 @funindex page-count
499
500 The number of pages to be used for a score.  Default: unset.
501
502 @item page-limit-inter-system-space
503 @funindex page-limit-inter-system-space
504
505 If set to true, limits space between systems on a page with a lot
506 of space left.  Default: @code{##f}.  For details, see
507 @ref{Vertical spacing between systems}.
508
509 @item page-limit-inter-system-space-factor
510 @funindex page-limit-inter-system-space-factor
511
512 The factor used by @code{page-limit-inter-system-space}.  Default:
513 @code{1.4}.  For details, see
514 @ref{Vertical spacing between systems}.
515
516 @item page-spacing-weight
517 @funindex page-spacing-weight
518
519 The relative importance of page (vertical) spacing and line
520 (horizontal) spacing.  High values will make page spacing more
521 important.  Default: @code{#10}.
522
523 @item print-all-headers
524 @funindex print-all-headers
525
526 If set to true, this will print all headers for each \score in the
527 output.  Normally only the piece and opus header variables are
528 printed.  Default: @code{##f}.
529
530 @item print-first-page-number
531 @funindex print-first-page-number
532
533 If set to true, a page number is printed on the first page.
534 Default: @code{##f}.
535
536 @item print-page-number
537 @funindex print-page-number
538
539 If set to false, page numbers are not printed.  Default:
540 @code{##t}.
541
542 @item ragged-bottom
543 @funindex ragged-bottom
544
545 If set to true, systems will not spread vertically across the
546 page.  This does not affect the last page.  Default: @code{##f}.
547
548 This should be set to true for pieces that have only two or three
549 systems per page, for example orchestral scores.
550
551 @item ragged-last
552 @funindex ragged-last
553
554 If set to true, the last system in the score will not fill the
555 line width.  Instead the last system ends at its natural
556 horizontal length.  Default: @code{##f}.
557
558 @item ragged-last-bottom
559 @funindex ragged-last-bottom
560
561 If set to false, systems will spread vertically across the last
562 page.  Default: @code{##t}.
563
564 Pieces that amply fill two pages or more should have this set to
565 true.
566
567 It also affects the last page of book parts, ie parts of a book created
568 with @code{\bookpart} blocks.
569
570 @item ragged-right
571 @funindex ragged-right
572
573 If set to true, systems will not fill the line width.  Instead,
574 systems end at their natural horizontal length.  Default:
575 @code{##f}.
576
577 If the score has only one system, the default value is @code{##t}.
578
579 @item system-separator-markup
580 @funindex system-separator-markup
581
582 A markup object that is inserted between systems.  This is often
583 used for orchestral scores.  Default: unset.
584
585 The markup command @code{\slashSeparator} is provided as a sensible
586 default,  for example
587
588 @lilypond[quote,ragged-right]
589 #(set-default-paper-size "a6" 'landscape)
590 \book {
591   \score {
592     \relative { c1 \break c1 }
593   }
594   \paper {
595     system-separator-markup = \slashSeparator
596   }
597 }
598 @end lilypond
599
600 @item system-count
601 @funindex system-count
602
603 The number of systems to be used for a score.
604 Default: unset.
605
606 @item systems-per-page
607 @funindex systems-per-page
608
609 The number of systems that should be placed on each page.
610 This is currently supported only by the @code{ly:optimal-breaking} algorithm.
611 Default: unset.
612
613 @end table
614
615
616 @seealso
617 Snippets:
618 @rlsr{Spacing}.
619
620
621 @knownissues
622
623 The default page header puts the page number and the @code{instrument}
624 field from the @code{\header} block on a line.
625
626 The titles (from the @code{\header@{@}} section) are treated as a
627 system, so @code{ragged-bottom} and @code{ragged-last-bottom} will
628 add space between the titles and the first system of the score.
629
630
631 @node Music layout
632 @section Music layout
633
634 @menu
635 * Setting the staff size::
636 * Score layout::
637 @end menu
638
639
640 @node Setting the staff size
641 @subsection Setting the staff size
642
643 @cindex font size, setting
644 @cindex staff size, setting
645 @funindex layout file
646
647 The default @strong{staff size} is set to 20 points.
648 This may be changed in two ways:
649
650 To set the staff size globally for all scores in a file (or
651 in a @code{book} block, to be precise), use @code{set-global-staff-size}.
652
653 @example
654 #(set-global-staff-size 14)
655 @end example
656
657 @noindent
658 This sets the global default size to 14pt staff height and scales all
659 fonts accordingly.
660
661 To set the staff size individually for each score, use
662 @example
663 \score@{
664   ...
665   \layout@{
666   #(layout-set-staff-size 15)
667   @}
668 @}
669 @end example
670
671 The Feta font provides musical symbols at eight different
672 sizes.  Each font is tuned for a different staff size: at a smaller size
673 the font becomes heavier, to match the relatively heavier staff lines.
674 The recommended font sizes are listed in the following table:
675
676 @quotation
677 @multitable @columnfractions .15 .2 .22 .2
678
679 @item @b{font name}
680 @tab @b{staff height (pt)}
681 @tab @b{staff height (mm)}
682 @tab @b{use}
683
684 @item feta11
685 @tab 11.22
686 @tab 3.9
687 @tab pocket scores
688
689 @item feta13
690 @tab 12.60
691 @tab 4.4
692 @tab
693
694 @item feta14
695 @tab 14.14
696 @tab 5.0
697 @tab
698
699 @item feta16
700 @tab 15.87
701 @tab 5.6
702 @tab
703
704 @item feta18
705 @tab 17.82
706 @tab 6.3
707 @tab song books
708
709 @item feta20
710 @tab 20
711 @tab 7.0
712 @tab standard parts
713
714 @item feta23
715 @tab 22.45
716 @tab 7.9
717 @tab
718
719 @item feta26
720 @tab 25.2
721 @tab 8.9
722 @tab
723 @c modern rental material?
724
725 @end multitable
726 @end quotation
727
728 These fonts are available in any sizes.  The context property
729 @code{fontSize} and the layout property @code{staff-space} (in
730 @rinternals{StaffSymbol}) can be used to tune the size for individual
731 staves.  The sizes of individual staves are relative to the global size.
732
733
734 @seealso
735 Notation Reference:
736 @ref{Selecting notation font size}.
737
738 Snippets:
739 @rlsr{Spacing}.
740
741
742 @knownissues
743
744 @code{layout-set-staff-size} does not change the distance between the
745 staff lines.
746
747
748 @node Score layout
749 @subsection Score layout
750
751 @funindex \layout
752
753 While @code{\paper} contains settings that relate to the page formatting
754 of the whole document, @code{\layout} contains settings for score-specific
755 layout.
756
757 @example
758 \layout @{
759   indent = 2.0\cm
760   \context @{ \Staff
761     \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
762   @}
763   \context @{ \Voice
764     \override TextScript #'padding = #1.0
765     \override Glissando #'thickness = #3
766   @}
767 @}
768 @end example
769
770
771 @seealso
772 Notation Reference:
773 @ref{Changing context default settings}.
774
775 Snippets:
776 @rlsr{Spacing}.
777
778
779 @node Breaks
780 @section Breaks
781
782 @menu
783 * Line breaking::
784 * Page breaking::
785 * Optimal page breaking::
786 * Optimal page turning::
787 * Minimal page breaking::
788 * Explicit breaks::
789 * Using an extra voice for breaks::
790 @end menu
791
792
793 @node Line breaking
794 @subsection Line breaking
795
796 @cindex line breaks
797 @cindex breaking lines
798
799 Line breaks are normally determined automatically. They are chosen
800 so that lines look neither cramped nor loose, and consecutive
801 lines have similar density.  Occasionally you might want to
802 override the automatic breaks; you can do this by specifying
803 @code{\break}. This will force a line break at this point.  However,
804 line breaks can only occur at the end of @q{complete} bars, i.e.,
805 where there are no notes or tuplets left @q{hanging} over the bar
806 line.  If you want to have a line break where there is no bar line,
807 you can force an invisible bar line by entering @code{\bar ""},
808 although again there must be no notes left hanging over in any of
809 the staves at this point, or it will be ignored.
810
811 The opposite command, @code{\noBreak}, forbids a line break at the
812 bar line where it is inserted.
813
814 The most basic settings influencing line spacing are @code{indent}
815 and @code{line-width}. They are set in the @code{\layout} block.
816 They control the indentation of the first line of music, and the
817 lengths of the lines.
818
819 If @code{ragged-right} is set to true in the @code{\layout} block,
820 then systems end at their natural horizontal length, instead of
821 being spread horizontally to fill the whole line. This is useful
822 for short fragments, and for checking how tight the natural
823 spacing is.
824
825 @c TODO Check and add para on default for ragged-right
826
827 The option @code{ragged-last} is similar to @code{ragged-right},
828 but affects only the last line of the piece.
829
830 @example
831 \layout @{
832 indent = #0
833 line-width = #150
834 ragged-last = ##t
835 @}
836 @end example
837
838
839
840 @cindex regular line breaks
841 @cindex four bar music.
842
843 For line breaks at regular intervals use @code{\break} separated by
844 skips and repeated with @code{\repeat}.  For example, this would
845 cause the following 28 measures (assuming 4/4 time) to be broken
846 every 4 measures, and only there:
847
848 @example
849 << \repeat unfold 7 @{
850          s1 \noBreak s1 \noBreak
851          s1 \noBreak s1 \break @}
852    @emph{the real music}
853 >>
854 @end example
855
856 @c TODO Check this
857 A linebreaking configuration can be saved as a @code{.ly} file
858 automatically.  This allows vertical alignments to be stretched to
859 fit pages in a second formatting run.  This is fairly new and
860 complicated.  More details are available in
861 @rlsr{Spacing}.
862
863
864 @predefined
865 @funindex \break
866 @code{\break},
867 @funindex \noBreak
868 @code{\noBreak}.
869 @endpredefined
870
871
872 @seealso
873 Internals Reference:
874 @rinternals{LineBreakEvent}.
875
876 Snippets:
877 @rlsr{Spacing}.
878
879
880 @knownissues
881
882 Line breaks can only occur if there is a @q{proper} bar line.  A note
883 which is hanging over a bar line is not proper, such as
884
885 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
886 c4 c2 << c2 {s4 \break } >>  % this does nothing
887 c2 c4 |           % a break here would work
888 c4 c2 c4 ~ \break % as does this break
889 c4 c2 c4
890 @end lilypond
891
892 This can be avoided by removing the @code{Forbid_line_break_engraver}.
893 Note that manually forced line breaks have to be added in parallel
894 with the music.
895
896 @lilypond[quote,ragged-right,verbatim]
897 \new Voice \with {
898   \remove Forbid_line_break_engraver
899 } {
900   c4 c2 << c2 {s4 \break } >>  % now the break is allowed
901   c2 c4
902 }
903 @end lilypond
904
905 Similarly, line breaks are normally forbidden when beams cross bar
906 lines.  This behavior can be changed by setting
907 @code{\override Beam #'breakable = ##t}.
908
909
910 @node Page breaking
911 @subsection Page breaking
912
913 The default page breaking may be overridden by inserting
914 @code{\pageBreak} or @code{\noPageBreak} commands.  These commands are
915 analogous to @code{\break} and @code{\noBreak}.  They should be
916 inserted at a bar line.  These commands force and forbid a page-break
917 from happening.  Of course, the @code{\pageBreak} command also forces
918 a line break.
919
920 The @code{\pageBreak} and @code{\noPageBreak} commands may also be
921 inserted at top-level, between scores and top-level markups.
922
923 There are also analogous settings to @code{ragged-right} and
924 @code{ragged-last} which have the same effect on vertical spacing:
925 @code{ragged-bottom} and @code{ragged-last-bottom}.  If set to
926 @code{##t} the systems on all pages or just the last page
927 respectively will not be justified vertically.
928
929 For more details see @ref{Vertical spacing}.
930
931 Page breaks are computed by the @code{page-breaking} function.  LilyPond
932 provides three algorithms for computing page breaks,
933 @code{ly:optimal-breaking}, @code{ly:page-turn-breaking} and
934 @code{ly:minimal-breaking}.  The default is @code{ly:optimal-breaking},
935 but the value can be changed in the @code{\paper} block:
936
937 @example
938 \paper@{
939   #(define page-breaking ly:page-turn-breaking)
940 @}
941 @end example
942
943 @c TODO Check this -td
944 The old page breaking algorithm is called
945 @code{optimal-page-breaks}.  If you are having trouble with the new page
946 breakers, you can enable the old one as a workaround.
947
948 @funindex \bookpart
949
950 When a book has many scores and pages, the page breaking problem may be
951 difficult to solve, requiring large processing time and memory.  To ease
952 the page breaking process, @code{\bookpart} blocks are used to divide
953 the book into several parts: the page breaking occurs separately on each
954 part.  Different page breaking functions may also be used in different
955 book parts.
956
957 @example
958 \bookpart @{
959   \header @{
960     subtitle = "Preface"
961   @}
962   \paper @{
963      %% In a part consisting mostly of text,
964      %% ly:minimal-breaking may be prefered
965      #(define page-breaking ly:minimal-breaking)
966   @}
967   \markup @{ @dots{} @}
968   @dots{}
969 @}
970 \bookpart @{
971   %% In this part, consisting of music, the default optimal
972   %% page breaking function is used.
973   \header @{
974     subtitle = "First movement"
975   @}
976   \score @{ @dots{} @}
977   @dots{}
978 @}
979 @end example
980
981
982 @predefined
983 @funindex \pageBreak
984 @code{\pageBreak},
985 @funindex \noPageBreak
986 @code{\noPageBreak}.
987 @endpredefined
988
989
990 @seealso
991 Snippets:
992 @rlsr{Spacing}.
993
994
995 @node Optimal page breaking
996 @subsection Optimal page breaking
997
998 @funindex ly:optimal-breaking
999
1000 The @code{ly:optimal-breaking} function is LilyPond's default method of
1001 determining page breaks.  It attempts to find a page breaking that minimizes
1002 cramping and stretching, both horizontally and vertically.  Unlike
1003 @code{ly:page-turn-breaking}, it has no concept of page turns.
1004
1005
1006 @seealso
1007 Snippets:
1008 @rlsr{Spacing}.
1009
1010
1011 @node Optimal page turning
1012 @subsection Optimal page turning
1013
1014 @funindex ly:page-turn-breaking
1015
1016 Often it is necessary to find a page breaking configuration so that there is
1017 a rest at the end of every second page.  This way, the musician can turn the
1018 page without having to miss notes.  The @code{ly:page-turn-breaking} function
1019 attempts to find a page breaking minimizing cramping and stretching, but with
1020 the additional restriction that it is only allowed to introduce page turns
1021 in specified places.
1022
1023 There are two steps to using this page breaking function.  First, you
1024 must enable it in the @code{\paper} block, as explained in @ref{Page
1025 breaking}.  Then you must tell the function where you would like to allow
1026 page breaks.
1027
1028 There are two ways to achieve the second step.  First, you can specify each
1029 potential page turn manually, by inserting @code{\allowPageTurn} into your
1030 input file at the appropriate places.
1031
1032 If this is too tedious, you can add a @code{Page_turn_engraver} to a Staff or
1033 Voice context.  The @code{Page_turn_engraver} will scan the context for
1034 sections without notes (note that it does not scan for rests; it scans for
1035 the absence of notes.  This is so that single-staff polyphony with rests in one
1036 of the parts does not throw off the @code{Page_turn_engraver}).  When it finds
1037 a sufficiently long section without notes, the @code{Page_turn_engraver} will
1038 insert an @code{\allowPageTurn} at the final bar line in that section, unless
1039 there is a @q{special} bar line (such as a double bar), in which case the
1040 @code{\allowPageTurn} will be inserted at the final @q{special} bar line in
1041 the section.
1042
1043 @funindex minimumPageTurnLength
1044 The @code{Page_turn_engraver} reads the context property
1045 @code{minimumPageTurnLength} to determine how long a note-free section must
1046 be before a page turn is considered.  The default value for
1047 @code{minimumPageTurnLength} is @code{#(ly:make-moment 1 1)}.  If you want
1048 to disable page turns, you can set it to something very large.
1049
1050 @example
1051 \new Staff \with @{ \consists "Page_turn_engraver" @}
1052 @{
1053   a4 b c d |
1054   R1 | % a page turn will be allowed here
1055   a4 b c d |
1056   \set Staff.minimumPageTurnLength = #(ly:make-moment 5 2)
1057   R1 | % a page turn will not be allowed here
1058   a4 b r2 |
1059   R1*2 | % a page turn will be allowed here
1060   a1
1061 @}
1062 @end example
1063
1064 @funindex minimumRepeatLengthForPageTurn
1065 The @code{Page_turn_engraver} detects volta repeats.  It will only allow a page
1066 turn during the repeat if there is enough time at the beginning and end of the
1067 repeat to turn the page back.  The @code{Page_turn_engraver} can also disable
1068 page turns if the repeat is very short.  If you set the context property
1069 @code{minimumRepeatLengthForPageTurn} then the @code{Page_turn_engraver} will
1070 only allow turns in repeats whose duration is longer than this value.
1071
1072 The page turning commands, @code{\pageTurn}, @code{\noPageTurn} and
1073 @code{\allowPageTurn}, may also be used at top-level, between scores and
1074 top-level markups.
1075
1076
1077 @predefined
1078 @funindex \pageTurn
1079 @code{\pageTurn},
1080 @funindex \noPageTurn
1081 @code{\noPageTurn},
1082 @funindex \allowPageTurn
1083 @code{\allowPageTurn}.
1084 @endpredefined
1085
1086
1087 @seealso
1088 Snippets:
1089 @rlsr{Spacing}.
1090
1091
1092 @knownissues
1093
1094 There should only be one @code{Page_turn_engraver} in a score.  If there is more
1095 than one, they will interfere with each other.
1096
1097
1098 @node Minimal page breaking
1099 @subsection Minimal page breaking
1100
1101 @funindex ly:minimal-breaking
1102
1103 The @code{ly:minimal-breaking} function performs minimal computations to
1104 calculate the page breaking: it fills a page with as many systems as
1105 possible before moving to the next one.  Thus, it may be preferred for
1106 scores with many pages, where the other page breaking functions could be
1107 too slow or memory demanding, or a lot of texts.  It is enabled using:
1108
1109 @example
1110 \paper @{
1111   #(define page-breaking ly:minimal-breaking)
1112 @}
1113 @end example
1114
1115
1116 @seealso
1117 Snippets:
1118 @rlsr{Spacing}.
1119
1120
1121 @node Explicit breaks
1122 @subsection Explicit breaks
1123
1124 Lily sometimes rejects explicit @code{\break} and @code{\pageBreak}
1125 commands.  There are two commands to override this behavior:
1126
1127 @example
1128 \override NonMusicalPaperColumn #'line-break-permission = ##f
1129 \override NonMusicalPaperColumn #'page-break-permission = ##f
1130 @end example
1131
1132 When @code{line-break-permission} is overridden to false, Lily will insert
1133 line breaks at explicit @code{\break} commands and nowhere else.  When
1134 @code{page-break-permission} is overridden to false, Lily will insert
1135 page breaks at explicit @code{\pageBreak} commands and nowhere else.
1136
1137 @lilypond[quote,verbatim]
1138 \paper {
1139   indent = #0
1140   ragged-right = ##t
1141   ragged-bottom = ##t
1142 }
1143
1144 \score {
1145   \new Score \with {
1146     \override NonMusicalPaperColumn #'line-break-permission = ##f
1147     \override NonMusicalPaperColumn #'page-break-permission = ##f
1148   } {
1149     \new Staff {
1150       \repeat unfold 2 { c'8 c'8 c'8 c'8 } \break
1151       \repeat unfold 4 { c'8 c'8 c'8 c'8 } \break
1152       \repeat unfold 6 { c'8 c'8 c'8 c'8 } \break
1153       \repeat unfold 8 { c'8 c'8 c'8 c'8 } \pageBreak
1154       \repeat unfold 8 { c'8 c'8 c'8 c'8 } \break
1155       \repeat unfold 6 { c'8 c'8 c'8 c'8 } \break
1156       \repeat unfold 4 { c'8 c'8 c'8 c'8 } \break
1157       \repeat unfold 2 { c'8 c'8 c'8 c'8 }
1158     }
1159   }
1160 }
1161 @end lilypond
1162
1163
1164 @seealso
1165 Snippets:
1166 @rlsr{Spacing}.
1167
1168
1169 @node Using an extra voice for breaks
1170 @subsection Using an extra voice for breaks
1171
1172 Line- and page-breaking information usually appears within note entry directly.
1173
1174 @example
1175 \new Score @{
1176   \new Staff @{
1177     \repeat unfold 2 @{ c'4 c'4 c'4 c'4 @}
1178     \break
1179     \repeat unfold 3 @{ c'4 c'4 c'4 c'4 @}
1180   @}
1181 @}
1182 @end example
1183
1184 This makes @code{\break} and @code{\pageBreak} commands easy to enter but mixes
1185 music entry with information that specifies how music should lay out
1186 on the page.  You can keep music entry and line- and page-breaking
1187 information in two separate places by introducing an extra voice to
1188 contain the  breaks.  This extra voice
1189 contains only skips together with @code{\break}, @code{pageBreak} and other
1190 breaking layout information.
1191
1192 @lilypond[quote,verbatim]
1193 \new Score {
1194   \new Staff <<
1195      \new Voice {
1196         s1 * 2 \break
1197         s1 * 3 \break
1198         s1 * 6 \break
1199         s1 * 5 \break
1200      }
1201      \new Voice {
1202         \repeat unfold 2 { c'4 c'4 c'4 c'4 }
1203         \repeat unfold 3 { c'4 c'4 c'4 c'4 }
1204         \repeat unfold 6 { c'4 c'4 c'4 c'4 }
1205         \repeat unfold 5 { c'4 c'4 c'4 c'4 }
1206      }
1207   >>
1208 }
1209 @end lilypond
1210
1211 This pattern becomes especially helpful when overriding
1212 @code{line-break-system-details} and the other useful but long properties of
1213 @code{NonMusicalPaperColumnGrob}, as explained in @ref{Vertical spacing}.
1214
1215 @lilypond[quote,verbatim]
1216 \new Score {
1217   \new Staff <<
1218      \new Voice {
1219
1220         \overrideProperty "Score.NonMusicalPaperColumn"
1221         #'line-break-system-details #'((Y-offset . 0))
1222         s1 * 2 \break
1223
1224         \overrideProperty "Score.NonMusicalPaperColumn"
1225         #'line-break-system-details #'((Y-offset . 35))
1226         s1 * 3 \break
1227
1228         \overrideProperty "Score.NonMusicalPaperColumn"
1229         #'line-break-system-details #'((Y-offset . 70))
1230         s1 * 6 \break
1231
1232         \overrideProperty "Score.NonMusicalPaperColumn"
1233         #'line-break-system-details #'((Y-offset . 105))
1234         s1 * 5 \break
1235      }
1236      \new Voice {
1237         \repeat unfold 2 { c'4 c'4 c'4 c'4 }
1238         \repeat unfold 3 { c'4 c'4 c'4 c'4 }
1239         \repeat unfold 6 { c'4 c'4 c'4 c'4 }
1240         \repeat unfold 5 { c'4 c'4 c'4 c'4 }
1241      }
1242   >>
1243 }
1244 @end lilypond
1245
1246
1247 @seealso
1248 Notation Reference:
1249 @ref{Vertical spacing}.
1250
1251 Snippets:
1252 @rlsr{Spacing}.
1253
1254
1255 @node Vertical spacing
1256 @section Vertical spacing
1257
1258 @cindex vertical spacing
1259 @cindex spacing, vertical
1260
1261 Vertical spacing is controlled by three things: the amount of
1262 space available (i.e., paper size and margins), the amount of
1263 space between systems, and the amount of space between
1264 staves inside a system.
1265
1266 @menu
1267 * Vertical spacing inside a system::
1268 * Vertical spacing between systems::
1269 * Explicit staff and system positioning::
1270 * Two-pass vertical spacing::
1271 * Vertical collision avoidance::
1272 @end menu
1273
1274
1275 @node Vertical spacing inside a system
1276 @subsection Vertical spacing inside a system
1277
1278 @cindex distance between staves
1279 @cindex staff distance
1280 @cindex space between staves
1281 @cindex space inside systems
1282
1283 The height of each system is determined automatically.  To prevent
1284 staves from bumping into each other, some minimum distances are set.
1285 By changing these, you can put staves closer together.  This
1286 reduces the amount of space each system requires, and may result
1287 in having more systems per page.
1288
1289 Normally staves are stacked vertically.  To make staves maintain a
1290 distance, their vertical size is padded.  This is done with the
1291 property @code{minimum-Y-extent}.  When applied to a
1292 @rinternals{VerticalAxisGroup}, it controls the size of a horizontal
1293 line, such as a staff or a line of lyrics.  @code{minimum-Y-extent}
1294 takes a pair of numbers, so
1295 if you want to make it smaller than its default @code{#'(-4 . 4)}
1296 then you could set
1297
1298 @example
1299 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
1300 @end example
1301
1302 @noindent
1303 This sets the vertical size of the current staff to 3 staff spaces on
1304 either side of the center staff line.  The value @code{(-3 . 3)} is
1305 interpreted as an interval, where the center line is the 0, so the
1306 first number is generally negative.  The numbers need not match;
1307 for example, the staff can be made larger at the bottom by setting
1308 it to @code{(-6 . 4)}.
1309
1310 After page breaks are determined, the vertical spacing within each
1311 system is reevaluated in order to fill the page more evenly; if a page
1312 has space left over, systems are stretched in order to fill that space.
1313 The amount of stretching can be configured though the @code{max-stretch}
1314 property of the @rinternals{VerticalAlignment} grob. By default,
1315 @code{max-stretch} is set to zero, disabling stretching. To enable
1316 stretching, a sane value for @code{max-stretch}
1317 is @code{ly:align-interface::calc-max-stretch}.
1318
1319 In some situations, you may want to stretch most of a system while
1320 leaving some parts fixed.  For example, if a piano part occurs in the
1321 middle of an orchestral score, you may want to leave the piano staves
1322 close to each other while stretching the rest of the score.  The
1323 @code{keep-fixed-while-stretching} property of
1324 @rinternals{VerticalAxisGroup} can be used to achieve this.  When set
1325 to @code{##t}, this property keeps its staff (or line of lyrics) from
1326 moving relative to the one directly above it.  In the example above,
1327 you would override @code{keep-fixed-while-stretching} to @code{##t} in
1328 the second piano staff:
1329
1330 @lilypond[verbatim]
1331 #(set-default-paper-size "a6")
1332 #(set-global-staff-size 14.0)
1333
1334 \book {
1335 \paper {
1336   ragged-last-bottom = ##f
1337 }
1338
1339 \new Score \with
1340 {
1341   \override VerticalAlignment #'max-stretch = #ly:align-interface::calc-max-stretch
1342 }
1343 {
1344 \new GrandStaff
1345 <<
1346   \new StaffGroup
1347   <<
1348     \new Staff {c' d' e' f'}
1349     \new Staff {c' d' e' f'}
1350     \new Staff {c' d' e' f'}
1351   >>
1352
1353   \new PianoStaff
1354   <<
1355     \new Staff {c' d' e' f'}
1356     \new Staff \with {
1357       \override VerticalAxisGroup #'keep-fixed-while-stretching = ##t
1358     }
1359     {c' d' e' f'}
1360   >>
1361
1362   \new StaffGroup
1363   <<
1364     \new Staff {c' d' e' f'}
1365     \new Staff {c' d' e' f'}
1366   >>
1367 >>
1368 }
1369 }
1370 @end lilypond
1371
1372 Vertical alignment of staves is handled by the
1373 @code{VerticalAlignment} object.  The context parameters
1374 specifying the vertical extent are described in connection with
1375 the @code{Axis_group_engraver}.
1376
1377
1378 @seealso
1379 Snippets:
1380 @rlsr{Spacing}.
1381
1382 @c @lsr{spacing,page-spacing.ly},
1383 @c @lsr{spacing,alignment-vertical-spacing.ly}.
1384
1385 Internals Reference:
1386 @rinternals{VerticalAlignment},
1387 @rinternals{Axis_group_engraver}.
1388
1389
1390 @node Vertical spacing between systems
1391 @subsection Vertical spacing between systems
1392
1393 Space between systems are controlled by four @code{\paper} variables,
1394
1395 @example
1396 \paper @{
1397   between-system-space = 1.5\cm
1398   between-system-padding = #1
1399   ragged-bottom=##f
1400   ragged-last-bottom=##f
1401 @}
1402 @end example
1403
1404 When only a couple of flat systems are placed on a page, the resulting
1405 vertical spacing may be non-elegant: one system at the top of the page,
1406 and the other at the bottom, with a huge gap between them.  To avoid this
1407 situation, the space added between the systems can be limited.  This
1408 feature is activated by setting to @code{#t} the
1409 @code{page-limit-inter-system-space} variable in the @code{\paper}
1410 block.  The paper variable @code{page-limit-inter-system-space-factor}
1411 determines how much the space can be increased: for instance, the value
1412 @code{1.3} means that the space can be 30% larger than what it would be
1413 on a ragged-bottom page.
1414
1415 In the following example, if the inter system space were not limited,
1416 the second system of page 1 would be placed at the page bottom.  By
1417 activating the space limitation, the second system is placed closer to
1418 the first one.  By setting @code{page-limit-inter-system-space-factor} to
1419 @code{1}, the spacing would the same as on a ragged-bottom page, like
1420 the last one.
1421
1422 @lilypond[verbatim]
1423 #(set-default-paper-size "a6")
1424 \book {
1425   \paper {
1426     page-limit-inter-system-space = ##t
1427     page-limit-inter-system-space-factor = 1.3
1428
1429     oddFooterMarkup = \markup "page bottom"
1430     evenFooterMarkup = \markup "page bottom"
1431     oddHeaderMarkup = \markup \fill-line {
1432       "page top" \fromproperty #'page:page-number-string }
1433     evenHeaderMarkup = \markup \fill-line {
1434       "page top" \fromproperty #'page:page-number-string }
1435   }
1436   \new Staff << \repeat unfold 4 { g'4 g' g' g' \break }
1437                 { s1*2 \pageBreak } >>
1438 }
1439 @end lilypond
1440
1441
1442 @seealso
1443 Snippets:
1444 @rlsr{Spacing}.
1445
1446
1447 @node Explicit staff and system positioning
1448 @subsection Explicit staff and system positioning
1449
1450 One way to understand the @code{VerticalAxisGroup} and @code{\paper}
1451 settings explained in the previous two sections is as a collection of
1452 different settings that primarily concern the amount of vertical padding
1453 different staves and systems running down the page.
1454
1455 It is possible to approach vertical spacing in a different way using
1456 @code{NonMusicalPaperColumn #'line-break-system-details}.  Where
1457 @code{VerticalAxisGroup} and @code{\paper} settings specify vertical padding,
1458 @code{NonMusicalPaperColumn #'line-break-system-details} specifies exact
1459 vertical positions on the page.
1460
1461 @code{NonMusicalPaperColumn #'line-break-system-details} accepts an associative
1462 list of five different settings:
1463
1464 @itemize
1465 @item @code{X-offset}
1466 @item @code{Y-offset}
1467 @item @code{alignment-offsets}
1468 @item @code{alignment-extra-space}
1469 @item @code{fixed-alignment-extra-space}
1470 @end itemize
1471
1472 Grob overrides, including the overrides for @code{NonMusicalPaperColumn}
1473 below, can occur in any of three different places in an input file:
1474
1475 @itemize
1476 @item in the middle of note entry directly
1477 @item in a @code{\context} block
1478 @item in the @code{\with} block
1479 @end itemize
1480
1481 When we override @code{NonMusicalPaperColumn}, we use the usual
1482 @code{\override} command in @code{\context} blocks and in the
1483 @code{\with} block.  On the other hand, when we override
1484 @code{NonMusicalPaperColumn} in the middle of note entry,
1485 use the special @code{\overrideProperty} command.  Here are some
1486 example @code{NonMusicalPaperColumn} overrides with the special
1487 @code{\overrideProperty} command:
1488
1489 @example
1490 \overrideProperty NonMusicalPaperColumn
1491   #'line-break-system-details #'((X-offset . 20))
1492
1493 \overrideProperty NonMusicalPaperColumn
1494   #'line-break-system-details #'((Y-offset . 40))
1495
1496 \overrideProperty NonMusicalPaperColumn
1497   #'line-break-system-details #'((X-offset . 20) (Y-offset . 40))
1498
1499 \overrideProperty NonMusicalPaperColumn
1500   #'line-break-system-details #'((alignment-offsets . (0 -15)))
1501
1502 \overrideProperty NonMusicalPaperColumn
1503   #'line-break-system-details #'((X-offset . 20) (Y-offset . 40)
1504                                  (alignment-offsets . (0 -15)))
1505 @end example
1506
1507 To understand how each of these different settings work, we begin
1508 by looking at an example that includes no overrides at all.
1509
1510 @c \book { } is required in these examples to ensure the spacing
1511 @c overrides can be seen between systems. -np
1512
1513 @lilypond[quote]
1514 \header { tagline = ##f }
1515 \paper { left-margin = 0\mm }
1516 \book {
1517   \score {
1518     <<
1519       \new Staff <<
1520         \new Voice {
1521           s1*5 \break
1522           s1*5 \break
1523           s1*5 \break
1524         }
1525         \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
1526       >>
1527       \new Staff {
1528         \repeat unfold 15 { d'4 d' d' d' }
1529       }
1530     >>
1531   }
1532 }
1533 @end lilypond
1534
1535 This score isolates line- and page-breaking information in a dedicated
1536 voice.  This technique of creating a breaks voice will help keep layout
1537 separate from music entry as our example becomes more complicated.
1538 See @ref{Using an extra voice for breaks}.
1539
1540 Explicit @code{\breaks} evenly divide the music into six measures per
1541 line.  Vertical spacing results from LilyPond's defaults.  To set
1542 the vertical startpoint of each system explicitly, we can set
1543 the @code{Y-offset} pair in the @code{line-break-system-details}
1544 attribute of the @code{NonMusicalPaperColumn} grob:
1545
1546 @lilypond[quote]
1547 \header { tagline = ##f }
1548 \paper { left-margin = 0\mm }
1549 \book {
1550   \score {
1551     <<
1552       \new Staff <<
1553         \new Voice {
1554           \overrideProperty #"Score.NonMusicalPaperColumn"
1555             #'line-break-system-details #'((Y-offset . 0))
1556           s1*5 \break
1557           \overrideProperty #"Score.NonMusicalPaperColumn"
1558             #'line-break-system-details #'((Y-offset . 40))
1559           s1*5 \break
1560           \overrideProperty #"Score.NonMusicalPaperColumn"
1561             #'line-break-system-details #'((Y-offset . 80))
1562           s1*5 \break
1563         }
1564         \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
1565       >>
1566       \new Staff {
1567         \repeat unfold 15 { d'4 d' d' d' }
1568       }
1569     >>
1570   }
1571 }
1572 @end lilypond
1573
1574 Note that @code{line-break-system-details} takes an associative list of
1575 potentially many values, but that we set only one value here.  Note,
1576 too, that the @code{Y-offset} property here determines the exact vertical
1577 position on the page at which each new system will render.
1578
1579 Now that we have set the vertical startpoint of each system
1580 explicitly, we can also set the vertical startpoint of each staff
1581 within each system manually.  We do this using the @code{alignment-offsets}
1582 subproperty of @code{line-break-system-details}.
1583
1584 @lilypond[quote]
1585 \header { tagline = ##f }
1586 \paper { left-margin = 0\mm }
1587 \book {
1588   \score {
1589     <<
1590       \new Staff <<
1591         \new Voice {
1592           \overrideProperty #"Score.NonMusicalPaperColumn"
1593             #'line-break-system-details #'((Y-offset . 20)
1594                                            (alignment-offsets . (0 -15)))
1595           s1*5 \break
1596           \overrideProperty #"Score.NonMusicalPaperColumn"
1597             #'line-break-system-details #'((Y-offset . 60)
1598                                            (alignment-offsets . (0 -15)))
1599           s1*5 \break
1600           \overrideProperty #"Score.NonMusicalPaperColumn"
1601             #'line-break-system-details #'((Y-offset . 100)
1602                                            (alignment-offsets . (0 -15)))
1603           s1*5 \break
1604         }
1605         \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
1606       >>
1607       \new Staff {
1608         \repeat unfold 15 { d'4 d' d' d' }
1609       }
1610     >>
1611   }
1612 }
1613 @end lilypond
1614
1615 Note that here we assign two different values to the
1616 @code{line-break-system-details} attribute of the
1617 @code{NonMusicalPaperColumn} grob.  Though the
1618 @code{line-break-system-details} attribute alist accepts many
1619 additional spacing parameters (including, for example, a corresponding
1620 @code{X-offset} pair), we need only set the @code{Y-offset} and
1621 @code{alignment-offsets} pairs to control the vertical startpoint of
1622 every system and every staff.  Finally, note that @code{alignment-offsets}
1623 specifies the vertical positioning of staves but not of staff groups.
1624
1625 @lilypond[quote]
1626 \header { tagline = ##f }
1627 \paper { left-margin = 0\mm }
1628 \book {
1629   \score {
1630     <<
1631       \new Staff <<
1632         \new Voice {
1633           \overrideProperty #"Score.NonMusicalPaperColumn"
1634             #'line-break-system-details #'((Y-offset . 0)
1635                                            (alignment-offsets . (0 -30 -40)))
1636           s1*5 \break
1637           \overrideProperty #"Score.NonMusicalPaperColumn"
1638             #'line-break-system-details #'((Y-offset . 60)
1639                                            (alignment-offsets . (0 -10 -20)))
1640           s1*5 \break
1641           \overrideProperty #"Score.NonMusicalPaperColumn"
1642             #'line-break-system-details #'((Y-offset . 100)
1643                                            (alignment-offsets . (0 -10 -40)))
1644           s1*5 \break
1645         }
1646         \new Voice { \repeat unfold 15 { c'4 c' c' c' } }
1647       >>
1648       \new StaffGroup <<
1649         \new Staff { \repeat unfold 15 { d'4 d' d' d' } }
1650         \new Staff { \repeat unfold 15 { e'4 e' e' e' } }
1651       >>
1652     >>
1653   }
1654 }
1655 @end lilypond
1656
1657 Some points to consider:
1658
1659 @itemize
1660 @item When using @code{alignment-offsets}, lyrics count as a staff.
1661
1662 @item The units of the numbers passed to @code{X-offset},
1663 @code{Y-offset} and @code{alignment-offsets} are interpreted as multiples
1664 of the distance between adjacent staff lines.  Positive values move staves
1665 and lyrics up, negative values move staves and lyrics down.
1666
1667 @item Because the @code{NonMusicalPaperColumn #'line-break-system-details}
1668 settings given here allow the positioning of staves and systems anywhere
1669 on the page, it is possible to violate paper or margin boundaries or even
1670 to print staves or systems on top of one another.  Reasonable values
1671 passed to these different settings will avoid this.
1672 @end itemize
1673
1674
1675 @seealso
1676 Snippets:
1677 @rlsr{Spacing}.
1678
1679
1680 @node Two-pass vertical spacing
1681 @subsection Two-pass vertical spacing
1682
1683 @warning{Two-pass vertical spacing is deprecated and will be removed in
1684 a future version of LilyPond.  Systems are now stretched automatically
1685 in a single pass.  See @ref{Vertical spacing inside a system}.}
1686
1687 In order to automatically stretch systems so that they should fill the
1688 space left on a page, a two-pass technique can be used:
1689
1690 @enumerate
1691 @item In the first pass, the amount of vertical space used to increase
1692 the height of each system is computed and dumped to a file.
1693 @item In the second pass, spacing inside the systems are
1694 stretched according to the data in the page layout file.
1695 @end enumerate
1696
1697 The @code{ragged-bottom} property adds space between systems, while
1698 the two-pass technique adds space between staves inside a system.
1699
1700 To allow this behavior, a @code{tweak-key} variable has to be set in
1701 each score @code{\layout} block, and the tweaks included in each score
1702 music, using the @code{\scoreTweak} music function.
1703
1704 @quotation
1705 @verbatim
1706 %% include the generated page layout file:
1707 \includePageLayoutFile
1708
1709 \score {
1710   \new StaffGroup <<
1711     \new Staff <<
1712       %% Include this score tweaks:
1713       \scoreTweak "scoreA"
1714       { \clef french c''1 \break c''1 }
1715     >>
1716     \new Staff { \clef soprano g'1 g'1 }
1717     \new Staff { \clef mezzosoprano e'1 e'1 }
1718     \new Staff { \clef alto g1 g1 }
1719     \new Staff { \clef bass c1 c1 }
1720   >>
1721   \header {
1722     piece = "Score with tweaks"
1723   }
1724   %% Define how to name the tweaks for this score:
1725   \layout { #(define tweak-key "scoreA") }
1726 }
1727 @end verbatim
1728 @end quotation
1729
1730 For the first pass, the @code{dump-tweaks} option should be set to
1731 generate the page layout file.
1732
1733 @example
1734 lilypond -dbackend=null -d dump-tweaks <file>.ly
1735 lilypond <file>.ly
1736 @end example
1737
1738
1739 @seealso
1740 Snippets:
1741 @rlsr{Spacing}.
1742
1743
1744 @node Vertical collision avoidance
1745 @subsection Vertical collision avoidance
1746
1747 @funindex outside-staff-priority
1748 @funindex outside-staff-padding
1749 @funindex outside-staff-horizontal-padding
1750
1751 Intuitively, there are some objects in musical notation that belong
1752 to the staff and there are other objects that should be placed outside
1753 the staff.  Objects belonging outside the staff include things such as
1754 rehearsal marks, text and dynamic markings (from now on, these will
1755 be called outside-staff objects).  LilyPond's rule for the
1756 vertical placement of outside-staff objects is to place them as close
1757 to the staff as possible but not so close that they collide with
1758 another object.
1759
1760 LilyPond uses the @code{outside-staff-priority} property to determine
1761 whether a grob is an outside-staff object: if @code{outside-staff-priority}
1762 is a number, the grob is an outside-staff object.  In addition,
1763 @code{outside-staff-priority} tells LilyPond in which order the objects
1764 should be placed.
1765
1766 First, LilyPond places all the objects that do not belong outside
1767 the staff.  Then it sorts the outside-staff objects according to their
1768 @code{outside-staff-priority} (in increasing order).  One by one, LilyPond
1769 takes the outside-staff objects and places them so that they do
1770 not collide with any objects that have already been placed.  That
1771 is, if two outside-staff grobs are competing for the same space, the one
1772 with the lower @code{outside-staff-priority} will be placed closer to
1773 the staff.
1774
1775 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1776 c4_"Text"\pp
1777 r2.
1778 \once \override TextScript #'outside-staff-priority = #1
1779 c4_"Text"\pp % this time the text will be closer to the staff
1780 r2.
1781 % by setting outside-staff-priority to a non-number,
1782 % we disable the automatic collision avoidance
1783 \once \override TextScript #'outside-staff-priority = ##f
1784 \once \override DynamicLineSpanner #'outside-staff-priority = ##f
1785 c4_"Text"\pp % now they will collide
1786 @end lilypond
1787
1788 The vertical padding between an outside-staff object and the
1789 previously-positioned grobs can be controlled with
1790 @code{outside-staff-padding}.
1791
1792 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1793 \once \override TextScript #'outside-staff-padding = #0
1794 a'^"This text is placed very close to the note"
1795 \once \override TextScript #'outside-staff-padding = #3
1796 c^"This text is padded away from the previous text"
1797 c^"This text is placed close to the previous text"
1798 @end lilypond
1799
1800
1801 By default, outside-staff objects are placed only to avoid
1802 a horizontal collision with previously-positioned grobs.  This
1803 can lead to situations in which objects are placed very close to each
1804 other horizontally.  The vertical spacing between staffs can
1805 also be set so that outside staff objects are interleaved.
1806 Setting @code{outside-staff-horizontal-padding}
1807 causes an object to be offset vertically so that such a situation
1808 doesn't occur.
1809
1810 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1811 % the markup is too close to the following note
1812 c4^"Text"
1813 c4
1814 c''2
1815 % setting outside-staff-horizontal-padding fixes this
1816 R1
1817 \once \override TextScript #'outside-staff-horizontal-padding = #1
1818 c,,4^"Text"
1819 c4
1820 c''2
1821 @end lilypond
1822
1823
1824 @seealso
1825 Snippets:
1826 @rlsr{Spacing}.
1827
1828
1829 @node Horizontal spacing
1830 @section Horizontal spacing
1831
1832 @cindex horizontal spacing
1833 @cindex spacing, horizontal
1834
1835 @menu
1836 * Horizontal spacing overview::
1837 * New spacing area::
1838 * Changing horizontal spacing::
1839 * Line length::
1840 * Proportional notation::
1841 @end menu
1842
1843
1844 @node Horizontal spacing overview
1845 @subsection Horizontal spacing overview
1846
1847 The spacing engine translates differences in durations into stretchable
1848 distances (@q{springs}) of differing lengths.  Longer durations get
1849 more space, shorter durations get less.  The shortest durations get a
1850 fixed amount of space (which is controlled by
1851 @code{shortest-duration-space} in the @rinternals{SpacingSpanner}
1852 object).  The longer the duration, the more space it gets: doubling a
1853 duration adds a fixed amount (this amount is controlled by
1854 @code{spacing-increment}) of space to the note.
1855
1856 For example, the following piece contains lots of half, quarter, and
1857 8th notes; the eighth note is followed by 1 note head width (NHW).
1858 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
1859
1860 @lilypond[quote,fragment,verbatim,relative=1]
1861 c2 c4. c8 c4. c8 c4. c8 c8
1862 c8 c4 c4 c4
1863 @end lilypond
1864
1865 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
1866 approximately the width of a note head, and
1867 @code{shortest-duration-space} is set to 2.0, meaning that the
1868 shortest note gets 2.4 staff space (2.0 times the
1869 @code{spacing-increment}) of horizontal space.  This space is counted
1870 from the left edge of the symbol, so the shortest notes are generally
1871 followed by one NHW of space.
1872
1873 If one would follow the above procedure exactly, then adding a single
1874 32nd note to a score that uses 8th and 16th notes, would widen up the
1875 entire score a lot.  The shortest note is no longer a 16th, but a 32nd,
1876 thus adding 1 NHW to every note.  To prevent this, the shortest
1877 duration for spacing is not the shortest note in the score, but rather
1878 the one which occurs most frequently.
1879
1880
1881 The most common shortest duration is determined as follows: in every
1882 measure, the shortest duration is determined.  The most common shortest
1883 duration is taken as the basis for the spacing, with the stipulation
1884 that this shortest duration should always be equal to or shorter than
1885 an 8th note.  The shortest duration is printed when you run
1886 @code{lilypond} with the @code{--verbose} option.
1887
1888 These durations may also be customized.  If you set the
1889 @code{common-shortest-duration} in @rinternals{SpacingSpanner}, then
1890 this sets the base duration for spacing.  The maximum duration for this
1891 base (normally an 8th), is set through @code{base-shortest-duration}.
1892
1893 @funindex common-shortest-duration
1894 @funindex base-shortest-duration
1895 @funindex stem-spacing-correction
1896 @funindex spacing
1897
1898 Notes that are even shorter than the common shortest note are
1899 followed by a space that is proportional to their duration relative to
1900 the common shortest note.  So if we were to add only a few 16th notes
1901 to the example above, they would be followed by half a NHW:
1902
1903 @lilypond[quote,fragment,verbatim,relative=2]
1904 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
1905 @end lilypond
1906
1907
1908 In the introduction
1909 FIXME FIXME FIXME
1910 @c (see @rlearning{Engraving}), 
1911 it was explained that stem
1912 directions influence spacing.  This is controlled with the
1913 @code{stem-spacing-correction} property in the
1914 @rinternals{NoteSpacing}, object.  These are generated for every
1915 @rinternals{Voice} context.  The @code{StaffSpacing} object
1916 (generated in @rinternals{Staff} context) contains the same property
1917 for controlling the stem/bar line spacing.  The following example shows
1918 these corrections, once with default settings, and once with
1919 exaggerated corrections:
1920
1921 @lilypond[quote,ragged-right]
1922 {
1923   c'4 e''4 e'4 b'4 |
1924   b'4 e''4 b'4 e''4|
1925   \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
1926   \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
1927   c'4 e''4 e'4 b'4 |
1928   b'4 e''4 b'4 e''4|
1929 }
1930 @end lilypond
1931
1932 Proportional notation is supported; see @ref{Proportional notation}.
1933
1934
1935 @seealso
1936 Snippets:
1937 @rlsr{Spacing}.
1938
1939 Internals Reference:
1940 @rinternals{SpacingSpanner},
1941 @rinternals{NoteSpacing},
1942 @rinternals{StaffSpacing},
1943 @rinternals{NonMusicalPaperColumn}.
1944
1945
1946 @knownissues
1947
1948 There is no convenient mechanism to manually override spacing.  The
1949 following work-around may be used to insert extra space into a score,
1950 adjusting the padding value as necessary.
1951 @example
1952  \override Score.NonMusicalPaperColumn #'padding = #10
1953 @end example
1954
1955 No work-around exists for decreasing the amount of space.
1956
1957
1958 @node New spacing area
1959 @subsection New spacing area
1960
1961 New sections with different spacing parameters can be started with
1962 @code{newSpacingSection}.  This is useful when there are
1963 sections with a different notions of long and short notes.
1964
1965 In the following example, the time signature change introduces a new
1966 section, and hence the 16ths notes are spaced wider.
1967
1968 @lilypond[relative,fragment,verbatim,quote]
1969 \time 2/4
1970 c4 c8 c
1971 c8 c c4 c16[ c c8] c4
1972 \newSpacingSection
1973 \time 4/16
1974 c16[ c c8]
1975 @end lilypond
1976
1977 The @code{\newSpacingSection} command creates a new
1978 @code{SpacingSpanner} object, and hence new @code{\override}s
1979 may be used in that location.
1980
1981
1982 @seealso
1983 Snippets:
1984 @rlsr{Spacing}.
1985
1986 Internals Reference:
1987 @rinternals{SpacingSpanner}.
1988
1989
1990 @node Changing horizontal spacing
1991 @subsection Changing horizontal spacing
1992
1993 Horizontal spacing may be altered with the
1994 @code{base-shortest-duration} property.  Here
1995 we compare the same music; once without altering
1996 the property, and then altered.  Larger values
1997 of @code{ly:make-moment} will produce smaller
1998 music.  Note that @code{ly:make-moment} constructs
1999 a duration, so @code{1 4} is a longer duration
2000 than @code{1 16}.
2001
2002 @lilypond[verbatim,line-width=12\cm]
2003 \score {
2004   \relative c'' {
2005     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
2006     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2007     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
2008     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2009   }
2010 }
2011 @end lilypond
2012
2013 @lilypond[verbatim,line-width=12\cm]
2014 \score {
2015   \relative c'' {
2016     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
2017     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2018     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
2019     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2020   }
2021   \layout {
2022     \context {
2023       \Score
2024       \override SpacingSpanner
2025                 #'base-shortest-duration = #(ly:make-moment 1 16)
2026     }
2027   }
2028 }
2029 @end lilypond
2030
2031
2032 @snippets
2033
2034 By default, spacing in tuplets depends on various non-duration
2035 factors (such as accidentals, clef changes, etc).  To disregard
2036 such symbols and force uniform equal-duration spacing, use
2037 @code{Score.SpacingSpanner #'uniform-stretching}.  This
2038 property can only be changed at the beginning of a score,
2039
2040 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
2041 \new Score \with {
2042   \override SpacingSpanner #'uniform-stretching = ##t
2043 } <<
2044   \new Staff{
2045     \times 4/5 {
2046       c8 c8 c8 c8 c8
2047     }
2048     c8 c8 c8 c8
2049   }
2050   \new Staff{
2051     c8 c8 c8 c8
2052     \times 4/5 {
2053       c8 c8 c8 c8 c8
2054     }
2055   }
2056 >>
2057 @end lilypond
2058
2059 When @code{strict-note-spacing} is set, notes are spaced without
2060 regard for clefs, bar lines, and grace notes,
2061
2062 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
2063 \override Score.SpacingSpanner #'strict-note-spacing = ##t
2064 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c]  c32[ c32] }
2065 @end lilypond
2066
2067
2068 @seealso
2069 Snippets:
2070 @rlsr{Spacing}.
2071
2072
2073 @node Line length
2074 @subsection Line length
2075
2076 @cindex page breaks
2077 @cindex breaking pages
2078
2079 @funindex indent
2080 @funindex line-width
2081 @funindex ragged-right
2082 @funindex ragged-last
2083
2084 @c Although line-width can be set in \layout, it should be set in paper
2085 @c block, to get page layout right.
2086 @c Setting indent in \paper block makes not much sense, but it works.
2087
2088 @c Bit verbose and vague, use examples?
2089 The most basic settings influencing the spacing are @code{indent} and
2090 @code{line-width}.  They are set in the @code{\layout} block.  They
2091 control the indentation of the first line of music, and the lengths of
2092 the lines.
2093
2094 If @code{ragged-right} is set to true in the @code{\layout} block, then
2095 systems ends at their natural horizontal length, instead of being spread
2096 horizontally to fill the whole line.  This is useful for
2097 short fragments, and for checking how tight the natural spacing is.
2098
2099 @cindex page layout
2100 @cindex vertical spacing
2101
2102 The option @code{ragged-last} is similar to @code{ragged-right}, but
2103 only affects the last line of the piece.  No restrictions are put on
2104 that line.  The result is similar to formatting text paragraphs.  In a
2105 paragraph, the last line simply takes its natural horizontal length.
2106 @c Note that for text there are several options for the last line.
2107 @c While Knuth TeX uses natural length, lead typesetters use the same
2108 @c stretch as the previous line.  eTeX uses \lastlinefit to
2109 @c interpolate between both these solutions.
2110
2111 @example
2112 \layout @{
2113   indent = #0
2114   line-width = #150
2115   ragged-last = ##t
2116 @}
2117 @end example
2118
2119
2120 @seealso
2121 Snippets:
2122 @rlsr{Spacing}.
2123
2124
2125 @node Proportional notation
2126 @subsection Proportional notation
2127
2128 LilyPond supports proportional notation, a type of horizontal spacing
2129 in which each note consumes an amount of horizontal space exactly
2130 equivalent to its rhythmic duration.  This type of proportional spacing
2131 is comparable to horizontal spacing on top of graph paper.  Some late
2132 20th- and early 21st-century scores use proportional notation to
2133 clarify complex rhythmic relationships or to facilitate the placement
2134 of timelines or other graphics directly in the score.
2135
2136 LilyPond supports five different settings for proportional notation,
2137 which may be used together or alone:
2138
2139 @itemize
2140 @item @code{proportionalNotationDuration}
2141 @item @code{uniform-stretching}
2142 @item @code{strict-note-spacing}
2143 @item @code{\remove Separating_line_group_engraver}
2144 @item @code{\override PaperColumn #'used = ##t}
2145 @end itemize
2146
2147 In the examples that follow, we explore these five different
2148 proportional notation settings and examine how these settings interact.
2149
2150 We start with the following one-measure example, which uses classical
2151 spacing with ragged-right turned on.
2152
2153 @lilypond[quote,verbatim,ragged-right]
2154 \new Score <<
2155   \new RhythmicStaff {
2156     c'2
2157     c'16 c'16 c'16 c'16
2158     \times 4/5 {
2159       c'16 c'16 c'16 c'16 c'16
2160     }
2161   }
2162 >>
2163 @end lilypond
2164
2165 Notice that the half note which begins the measure takes up far less
2166 than half of the horizontal space of the measure.  Likewise, the
2167 sixteenth notes and sixteenth-note quintuplets (or twentieth notes)
2168 which end the measure together take up far more than half the
2169 horizontal space of the measure.
2170
2171 In classical engraving, this spacing may be exactly what we want
2172 because we can borrow horizontal space from the half note and conserve
2173 horizontal space across the measure as a whole.
2174
2175 On the other hand, if we want to insert a measured timeline or other
2176 graphic above or below our score, we need proportional notation.  We
2177 turn proportional notation on with the proportionalNotationDuration
2178 setting.
2179
2180 @lilypond[quote,verbatim,ragged-right]
2181 \new Score \with {
2182   proportionalNotationDuration = #(ly:make-moment 1 20)
2183 } <<
2184   \new RhythmicStaff {
2185     c'2
2186     c'16 c'16 c'16 c'16
2187     \times 4/5 {
2188       c'16 c'16 c'16 c'16 c'16
2189     }
2190   }
2191 >>
2192 @end lilypond
2193
2194 The half note at the beginning of the measure and the faster notes in
2195 the second half of the measure now occupy equal amounts of horizontal
2196 space.  We could place a measured timeline or graphic above or below
2197 this example.
2198
2199 The @code{proportionalNotationDuration} setting is a context setting that
2200 lives in @code{Score}.  Recall that context settings appear in one of
2201 three locations in our input file -- in a @code{\with} block, in a
2202 @code{\context} block, or directly in music entry
2203 preceded by the @code{\set} command.  As with all
2204 context settings, users can pick which of the three different
2205 locations they would like to set @code{proportionalNotationDuration}.
2206
2207 The @code{proportionalNotationDuration} setting takes a single argument,
2208 which is the reference duration against which all music will be
2209 spaced.  The LilyPond Scheme function make-moment takes two arguments
2210 -- a numerator and denominator which together express some fraction of
2211 a whole note.  The call @code{#(ly:make-moment 1 20)} therefore produces a
2212 reference duration of a twentieth note.  The values
2213 @code{#(ly:make-moment 1 16)}, @code{#(ly:make-moment 1 8)}, and
2214 @code{#(ly:make-moment 3 97)} are all possible as well.
2215
2216 How do we select the right reference duration to pass to
2217 @code{proportionalNotationDuration}?  Usually by a process of trial and error,
2218 beginning with a duration close to the fastest (or smallest) duration
2219 in the piece.  Smaller reference durations space music loosely; larger
2220 reference durations space music tightly.
2221
2222 @lilypond[quote,verbatim,ragged-right]
2223 \new Score \with {
2224   proportionalNotationDuration = #(ly:make-moment 1 8)
2225 } <<
2226   \new RhythmicStaff {
2227     c'2
2228     c'16 c'16 c'16 c'16
2229     \times 4/5 {
2230       c'16 c'16 c'16 c'16 c'16
2231     }
2232   }
2233 >>
2234
2235 \new Score \with {
2236   proportionalNotationDuration = #(ly:make-moment 1 16)
2237 } <<
2238   \new RhythmicStaff {
2239     c'2
2240     c'16 c'16 c'16 c'16
2241     \times 4/5 {
2242       c'16 c'16 c'16 c'16 c'16
2243     }
2244   }
2245 >>
2246
2247 \new Score \with {
2248   proportionalNotationDuration = #(ly:make-moment 1 32)
2249 } <<
2250   \new RhythmicStaff {
2251     c'2
2252     c'16 c'16 c'16 c'16
2253     \times 4/5 {
2254       c'16 c'16 c'16 c'16 c'16
2255     }
2256   }
2257 >>
2258 @end lilypond
2259
2260 Note that too large a reference duration -- such as the eighth note,
2261 above -- spaces music too tightly and can cause note head collisions.
2262 Note also that proportional notation in general takes up more
2263 horizontal space that does classical spacing.  Proportional spacing
2264 provides rhythmic clarity at the expense of horizontal space.
2265
2266 Next we examine how to optimally space overlapping tuplets.
2267
2268 We start by examining what happens to our original example, with
2269 classical spacing, when we add a second staff with a different type of
2270 tuplet.
2271
2272 @lilypond[quote,verbatim,ragged-right]
2273 \new Score <<
2274   \new RhythmicStaff {
2275     c'2
2276     c'16 c'16 c'16 c'16
2277     \times 4/5 {
2278       c'16 c'16 c'16 c'16 c'16
2279     }
2280   }
2281   \new RhythmicStaff {
2282     \times 8/9 {
2283       c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8
2284     }
2285   }
2286 >>
2287 @end lilypond
2288
2289 The spacing is bad because the evenly notes of the bottom staff do not
2290 stretch uniformly.  Classical engraving includes very few complex
2291 triplets and so classical engraving rules can generate this type of
2292 result.  Setting @code{proportionalNotationDuration} remedies this
2293 situation considerably.
2294
2295 @lilypond[quote,verbatim,ragged-right]
2296 \new Score \with {
2297   proportionalNotationDuration = #(ly:make-moment 1 20)
2298 } <<
2299   \new RhythmicStaff {
2300     c'2
2301     c'16 c'16 c'16 c'16
2302     \times 4/5 {
2303       c'16 c'16 c'16 c'16 c'16
2304     }
2305   }
2306   \new RhythmicStaff {
2307     \times 8/9 {
2308       c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8
2309     }
2310   }
2311 >>
2312 @end lilypond
2313
2314 But if we look very carefully we can see that notes of the second half
2315 of the 9-tuplet space ever so slightly more widely than do the notes
2316 of the first half of the 9-tuplet.  To ensure uniform stretching, we
2317 turn on @code{uniform-stretching}, which is a property of
2318 @code{SpacingSpanner}.
2319
2320 @lilypond[quote,verbatim,ragged-right]
2321 \new Score \with {
2322   proportionalNotationDuration = #(ly:make-moment 1 20)
2323   \override SpacingSpanner #'uniform-stretching = ##t
2324 } <<
2325   \new RhythmicStaff {
2326     c'2
2327     c'16 c'16 c'16 c'16
2328     \times 4/5 {
2329       c'16 c'16 c'16 c'16 c'16
2330     }
2331   }
2332   \new RhythmicStaff {
2333     \times 8/9 {
2334       c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8
2335     }
2336   }
2337 >>
2338 @end lilypond
2339
2340 Our two-staff example now spaces exactly, our rhythmic
2341 relationships are visually clear, and we can include a measured
2342 timeline or graphic if we want.
2343
2344 Note that the LilyPond's proportional notation package expects
2345 that all proportional scores set the SpacingSpanner's
2346 'uniform-stretching attribute to ##t. Setting
2347 proportionalNotationDuration without also setting the
2348 SpacingSpanner's 'uniform-stretching attribute to ##t will, for
2349 example, cause Skips to consume an incorrect amount of horizontal
2350 space.
2351
2352 The SpacingSpanner is an abstract grob that lives in the Score
2353 context. As with our settings of proportionalNotationDuration,
2354 overrides to the SpacingSpanner can occur in any of three
2355 different places in our input file â€“ in the Score \with block, in
2356 a Score \context block, or in note entry directly.
2357
2358 There is by default only one @code{SpacingSpanner} per @code{Score}.  This
2359 means that, by default, @code{uniform-stretching} is either turned on for the
2360 entire score or turned off for the entire score.  We can, however,
2361 override this behavior and turn on different spacing features at
2362 different places in the score.  We do this with the command
2363 @code{\newSpacingSection}.  See @ref{New spacing area}, for more info.
2364
2365 Next we examine the effects of the @code{Separating_line_group_engraver} and
2366 see why proportional scores frequently remove this engraver.  The following
2367 example shows that there is a small amount of @qq{preferatory} space
2368 just before the first note in each system.
2369
2370 @lilypond[quote,verbatim,ragged-right]
2371 \paper {
2372   indent = #0
2373 }
2374
2375 \new Staff {
2376   c'1
2377   \break
2378   c'1
2379 }
2380 @end lilypond
2381
2382
2383 The amount of this preferatory space is the same whether after a time
2384 signature, a key signature or a clef.  @code{Separating_line_group_engraver}
2385 is responsible for this space.  Removing @code{Separating_line_group_engraver}
2386 reduces this space to zero.
2387
2388 @lilypond[quote,verbatim,ragged-right]
2389 \paper {
2390   indent = #0
2391 }
2392
2393 \new Staff \with {
2394   \remove Separating_line_group_engraver
2395 } {
2396   c'1
2397   \break
2398   c'1
2399 }
2400 @end lilypond
2401
2402 Nonmusical elements like time signatures, key signatures, clefs and
2403 accidentals are problematic in proportional notation.  None of these
2404 elements has rhythmic duration.  But all of these elements consume
2405 horizontal space.  Different proportional scores approach these
2406 problems differently.
2407
2408 It may be possible to avoid spacing problems with key signatures
2409 simply by not having any.  This is a valid option since most
2410 proportional scores are contemporary music.  The same may be true
2411 of time signatures, especially for those scores
2412 that include a measured timeline or other graphic.  But these scores
2413 are exceptional and most proportional scores include at least some
2414 time signatures.  Clefs and accidentals are even more essential.
2415
2416 So what strategies exist for spacing nonmusical elements in a
2417 proportional context?  One good option is the @code{strict-note-spacing}
2418 property of @code{SpacingSpanner}.  Compare the two scores below:
2419
2420 @lilypond[quote,verbatim,ragged-right]
2421 \new Staff {
2422   \set Score.proportionalNotationDuration = #(ly:make-moment 1 16)
2423   c''8
2424   c''8
2425   c''8
2426   \clef alto
2427   d'8
2428   d'2
2429 }
2430
2431 \new Staff {
2432   \set Score.proportionalNotationDuration = #(ly:make-moment 1 16)
2433   \override Score.SpacingSpanner #'strict-note-spacing = ##t
2434   c''8
2435   c''8
2436   c''8
2437   \clef alto
2438   d'8
2439   d'2
2440 }
2441 @end lilypond
2442
2443 Both scores are proportional, but the spacing in the first score
2444 is too loose because of the clef change. The spacing of the second
2445 score remains strict, however, because strict-note-spacing is
2446 turned on.  Turning on strict-note-spacing causes the width of
2447 time signatures, key signatures, clefs and accidentals to play no
2448 part in the spacing algorithm.
2449
2450 In addition to the settings given here, there are other settings
2451 that frequently appear in proportional scores. These include:
2452
2453 @itemize
2454 @item @code{\override SpacingSpanner #'strict-grace-spacing = ##t}
2455 @item @code{tupletFullLength = ##t}
2456 @item @code{\override Beam #'breakable = ##t}
2457 @item @code{\override Glissando #'breakable = ##t}
2458 @item @code{\override TextSpanner #'breakable = ##t}
2459 @item @code{\remove Forbid_line_break_engraver in the Voice context}
2460 @end itemize
2461
2462 These settings space grace notes strictly, extend tuplet brackets to
2463 mark both rhythmic start- and stop-points, and allow spanning elements
2464 to break across systems and pages.  See the respective parts of the manual
2465 for these related settings.
2466
2467
2468 @seealso
2469 Notation Reference:
2470 @ref{New spacing area}.
2471
2472 Snippets:
2473 @rlsr{Spacing}.
2474
2475
2476 @node Fitting music onto fewer pages
2477 @section Fitting music onto fewer pages
2478
2479 Sometimes you can end up with one or two staves on a second
2480 (or third, or fourth...) page.  This is annoying, especially
2481 if you look at previous pages and it looks like there is plenty
2482 of room left on those.
2483
2484 When investigating layout issues, @code{annotate-spacing} is an
2485 invaluable tool.  This command prints the values of various layout
2486 spacing variables; for more details see the following section,
2487 @ref{Displaying spacing}.
2488
2489 @menu
2490 * Displaying spacing::
2491 * Changing spacing::
2492 @end menu
2493
2494
2495 @node Displaying spacing
2496 @subsection Displaying spacing
2497
2498 @funindex annotate-spacing
2499 @cindex spacing, display of layout
2500
2501 To graphically display the dimensions of vertical layout variables
2502 that may be altered for page formatting, set
2503 @code{annotate-spacing} in the @code{\paper} block:
2504
2505 @c need to have \book{} otherwise we get the separate systems. -hwn
2506 @lilypond[verbatim,quote]
2507 #(set-default-paper-size "a6" 'landscape)
2508 \book {
2509   \score { { c4 } }
2510   \paper { annotate-spacing = ##t }
2511 }
2512 @end lilypond
2513
2514
2515 @noindent
2516 All layout dimensions are displayed in staff-spaces, regardless
2517 of the units specified in the @code{\paper} or @code{\layout} block.
2518 In the above example, @code{paper-height} has a value of 59.75
2519 @code{staff-spaces}, and the @code{staff-size} is 20 points (the
2520 default value). Note that:
2521
2522 @multitable {1 staff-space} {staff-size)/4 * (25.4/72.27) mm}
2523
2524 @item 1 point
2525 @tab = (25.4/72.27) mm
2526
2527 @item 1 staff-space
2528 @tab = (@code{staff-size})/4 pts
2529 @item
2530 @tab = (@code{staff-size})/4 * (25.4/72.27) mm
2531
2532 @end multitable
2533
2534 @noindent
2535 In this case, one @code{staff-space} is approximately equal to
2536 1.757mm. Thus the @code{paper-height} measurement of 59.75
2537 @code{staff-spaces} is equivalent to 105 millimeters, the height
2538 of @code{a6} paper in landscape orientation.  The pairs
2539 (@var{a},@var{b}) are intervals, where @var{a} is the lower
2540 edge and @var{b} the upper edge of the interval.
2541
2542
2543 @seealso
2544 @ref{Setting the staff size}
2545 Snippets:
2546 @rlsr{Spacing}.
2547
2548
2549 @node Changing spacing
2550 @subsection Changing spacing
2551
2552 The output of @code{annotate-spacing} reveals vertical dimensions
2553 in great detail.  For details about modifying margins and other
2554 layout variables, see @ref{Page formatting}.
2555
2556 Other than margins, there are a few other options to save space:
2557
2558 @itemize
2559 @item
2560 Force systems to move as close together as possible (to fit as
2561 many systems as possible onto a page) while being spaced so that
2562 there is no blank space at the bottom of the page.
2563
2564 @example
2565 \paper @{
2566   between-system-padding = #0.1
2567   between-system-space = #0.1
2568   ragged-last-bottom = ##f
2569   ragged-bottom = ##f
2570 @}
2571 @end example
2572
2573 @item
2574 Force the number of systems.  This can help in two ways.  Just
2575 setting a value, even the same value as the number of systems
2576 being typeset by default, will sometimes cause more systems to
2577 be fitted onto each page, as an estimation step is then bypassed,
2578 giving a more accurate fit to each page.  Also, forcing an actual
2579 reduction in the number of systems may save a further page. For
2580 example, if the default layout has 11 systems, the following
2581 assignment will force a layout with 10 systems.
2582
2583 @example
2584 \paper @{
2585   system-count = #10
2586 @}
2587 @end example
2588
2589 @item
2590 Avoid (or reduce) objects that increase the vertical size of a
2591 system.  For example, volta repeats (or alternate repeats) require
2592 extra space.  If these repeats are spread over two systems, they
2593 will take up more space than one system with the volta repeats and
2594 another system without.  For example, dynamics that @q{stick out} of
2595 a system can be moved closer to the staff:
2596
2597 @lilypond[verbatim,quote,relative=1]
2598 e4 c g\f c
2599 \override DynamicText #'extra-offset = #'( -2.2 . 2.0)
2600 e4 c g\f c
2601 @end lilypond
2602
2603 @item
2604 Alter the horizontal spacing via @code{SpacingSpanner}.  For more
2605 details, see @ref{Changing horizontal spacing}.  The following
2606 example illustrates the default spacing:
2607
2608 @lilypond[verbatim,quote]
2609 \score {
2610   \relative c'' {
2611     g4 e e2 |
2612     f4 d d2 |
2613     c4 d e f |
2614     g4 g g2 |
2615     g4 e e2 |
2616   }
2617 }
2618 @end lilypond
2619
2620 @noindent
2621 The next example modifies @code{common-shortest-duration} from a
2622 value of @code{1/4} to @code{1/2}.  The quarter note is the most
2623 common and shortest duration in this example, so by making this
2624 duration longer, a @q{squeezing} effect occurs:
2625
2626 @lilypond[verbatim,quote]
2627 \score {
2628   \relative c'' {
2629     g4 e e2 |
2630     f4 d d2 |
2631     c4 d e f |
2632     g4 g g2 |
2633     g4 e e2 |
2634   }
2635   \layout {
2636     \context {
2637       \Score
2638       \override SpacingSpanner
2639         #'common-shortest-duration = #(ly:make-moment 1 2)
2640     }
2641   }
2642 }
2643 @end lilypond
2644
2645 @noindent
2646 The @code{common-shortest-duration} property cannot be modified
2647 dynamically, so it must always be placed in a @code{\context}
2648 block so that it applies to the whole score.
2649
2650 @end itemize
2651
2652
2653 @seealso
2654 Notation Reference:
2655 @ref{Page formatting},
2656 @ref{Changing horizontal spacing}.
2657
2658 Snippets:
2659 @rlsr{Spacing}.