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