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