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