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