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