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