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