1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
4 @c A menu is needed before every deeper *section nesting of @node's; run
5 @c M-x texinfo-all-menus-update
6 @c to automatically fill in these menus before saving changes
9 @chapter Spacing issues
11 The global paper layout is determined by three factors: the page layout, the
12 line breaks, and the spacing. These all influence each other. The
13 choice of spacing determines how densely each system of music is set.
14 This influences where line breaks are chosen, and thus ultimately, how
15 many pages a piece of music takes.
17 Globally spoken, this procedure happens in three steps: first,
18 flexible distances (``springs'') are chosen, based on durations. All
19 possible line breaking combinations are tried, and the one with the
20 best results -- a layout that has uniform density and requires as
21 little stretching or cramping as possible -- is chosen.
23 After spacing and linebreaking, the systems are distributed across
24 pages, taking into account the size of the page, and the size of the
31 * Horizontal spacing::
33 * Displaying spacing::
38 @section Paper and pages
40 This section deals with the boundaries that define the area
41 that music can be printed inside.
50 @subsection Paper size
56 To change the paper size, there are two commands,
58 #(set-default-paper-size "a4")
60 #(set-paper-size "a4")
64 The first command sets the size of all pages. The second command sets the
66 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
67 block is at the top of the file, then it will apply to all pages. If the
68 @code{\paper} block is inside a @code{\book}, then the paper size will only
71 Support for the following paper sizes are included by default,
72 @code{a6}, @code{a5}, @code{a4}, @code{a3}, @code{legal}, @code{letter},
73 @code{11x17} (also known as tabloid).
75 Extra sizes may be added by editing the definition for
76 @code{paper-alist} in the initialization file @file{scm/paper.scm}.
81 If the symbol @code{landscape} is supplied as an argument to
82 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
83 and wider line widths will be set correspondingly.
86 #(set-default-paper-size "a6" 'landscape)
89 Setting the paper size will adjust a number of @code{\paper} variables
90 (such as margins). To use a particular paper size with altered
91 @code{\paper} variables, set the paper size before setting the variables.
95 @subsection Page formatting
97 @cindex page formatting
102 LilyPond will do page layout, set margins, and add headers and
103 footers to each page.
105 The default layout responds to the following settings in the
112 @findex first-page-number
113 @item first-page-number
114 The value of the page number of the first page. Default is@tie{}1.
116 @findex printfirst-page-number
117 @item printfirst-page-number
118 If set to true, will print the page number in the first page. Default is
121 @findex print-page-number
122 @item print-page-number
123 If set to false, page numbers will not be printed.
127 The width of the page.
131 The height of the page.
135 Margin between header and top of the page.
137 @findex bottom-margin
139 Margin between footer and bottom of the page.
143 Margin between the left side of the page and the beginning of the music.
147 The length of the systems.
149 @findex head-separation
150 @item head-separation
151 Distance between the top-most music system and the page header.
153 @findex foot-separation
154 @item foot-separation
155 Distance between the bottom-most music system and the page footer.
157 @findex page-top-space
158 Distance from the top of the printable area to the center of the first
159 staff. This only works for staves which are vertically small. Big staves
160 are set with the top of their bounding box aligned to the top of the
163 @findex ragged-bottom
165 If set to true, systems will not be spread vertically across the page. This
166 does not affect the last page.
168 This should be set to true for pieces that have only two or three
169 systems per page, for example orchestral scores.
171 @findex ragged-last-bottom
172 @item ragged-last-bottom
173 If set to false, systems will be spread vertically to fill the last page.
175 Pieces that amply fill two pages or more should have this set to
180 This variable, if set, specifies into how many lines a score should be
183 @findex between-system-space
184 @item between-system-space
185 This dimensions determines the distance between systems. It is the
186 ideal distance between the center of the bottom staff of one system
187 and the center of the top staff of the next system.
189 Increasing this will provide a more even appearance of the page at the
190 cost of using more vertical space.
192 @findex between-system-padding
193 @item between-system-padding
194 This dimension is the minimum amount of white space that will always
195 be present between the bottom-most symbol of one system, and the
196 top-most of the next system.
198 Increasing this will put systems whose bounding boxes almost touch
202 @findex horizontal-shift
203 @item horizontal-shift
204 All systems (including titles and system separators) are shifted by
205 this amount to the right. Page markup, such as headers and footers are
206 not affected by this. The purpose of this variable is to make space
207 for instrument names at the left.
209 @findex after-title-space
210 @item after-title-space
211 Amount of space between the title and the first system.
213 @findex after-title-space
214 @item before-title-space
215 Amount of space between the last system of the previous piece and the
218 @findex between-title-space
219 @item between-title-space
220 Amount of space between consecutive titles (e.g., the title of the
221 book and the title of a piece).
223 @findex printallheaders
224 @item printallheaders
225 Setting this to #t will print all headers for each \score in a
226 \book. Normally only the piece and opus \headers are printed.
228 @findex systemSeparatorMarkup
229 @item systemSeparatorMarkup
230 This contains a markup object, which will be inserted between
231 systems. This is often used for orchestral scores.
233 The markup command @code{\slashSeparator} is provided as a sensible
236 @lilypond[ragged-right]
239 \relative { c1 \break c1 }
242 systemSeparatorMarkup = \slashSeparator
258 ragged-last-bottom = ##t
262 You can also define these values in Scheme. In that case @code{mm},
263 @code{in}, @code{pt}, and @code{cm} are variables defined in
264 @file{paper-defaults.ly} with values in millimeters. That is why the
265 value must be multiplied in the example
269 #(define bottom-margin (* 2 cm))
273 The header and footer are created by the functions @code{make-footer}
274 and @code{make-header}, defined in @code{\paper}. The default
275 implementations are in @file{ly/@/paper@/-defaults@/.ly} and
276 @file{ly/@/titling@/-init@/.ly}.
278 The page layout itself is done by two functions in the
279 @code{\paper} block, @code{page-music-height} and
280 @code{page-make-stencil}. The former tells the line-breaking algorithm
281 how much space can be spent on a page, the latter creates the actual
282 page given the system to put on it.
287 The option right-margin is defined but doesn't set the right margin
288 yet. The value for the right margin has to be defined adjusting the
289 values of @code{left-margin} and @code{line-width}.
291 The default page header puts the page number and the @code{instrument}
292 field from the @code{\header} block on a line.
294 The titles (from the @code{\header@{@}} section) are treated as a
295 system, so @code{ragged-bottom} and @code{ragged-last-bottom} will
296 add space between the titles and the first system of the score.
300 @section Music layout
303 * Setting global staff size::
308 @node Setting global staff size
309 @subsection Setting global staff size
311 @cindex font size, setting
312 @cindex staff size, setting
315 To set the global staff size, use @code{set-global-staff-size}.
318 #(set-global-staff-size 14)
322 This sets the global default size to 14pt staff height and scales all
325 The Feta font provides musical symbols at eight different
326 sizes. Each font is tuned for a different staff size: at a smaller size
327 the font becomes heavier, to match the relatively heavier staff lines.
328 The recommended font sizes are listed in the following table:
331 @multitable @columnfractions .15 .2 .22 .2
334 @tab @b{staff height (pt)}
335 @tab @b{staff height (mm)}
377 @c modern rental material?
382 These fonts are available in any sizes. The context property
383 @code{fontSize} and the layout property @code{staff-space} (in
384 @internalsref{StaffSymbol}) can be used to tune the size for individual
385 staves. The sizes of individual staves are relative to the global size.
393 This manual: @ref{Selecting notation font size}.
397 @subsection Score layout
401 While @code{\paper} contains settings that relate to the page formatting
402 of the whole document, @code{\layout} contains settings for score-specific
409 \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
412 \override TextScript #'padding = #1.0
413 \override Glissando #'thickness = #3
421 This manual: @ref{Changing context default settings}
424 @node Vertical spacing
425 @section Vertical spacing
427 @cindex vertical spacing
428 @cindex spacing, vertical
430 Vertical spacing is controlled by three things: the amount of
431 space available (i.e. paper size and margins), the amount of
432 space between systems, and the amount of space between
433 staves inside a system.
436 * Vertical spacing inside a system::
437 * Vertical spacing of piano staves::
438 * Vertical spacing between systems::
439 * Controlling spacing of individual systems::
443 @node Vertical spacing inside a system
444 @subsection Vertical spacing inside a system
446 @cindex distance between staves
447 @cindex staff distance
448 @cindex space between staves
449 @cindex space inside systems
451 The height of each system is determined automatically. To prevent
452 staves from bumping into each other, some minimum distances are set.
453 By changing these, you can put staves closer together. This
454 reduces the amount of space each system requires, and may result
455 in having more systems per page.
457 Normally staves are stacked vertically. To make staves maintain a
458 distance, their vertical size is padded. This is done with the
459 property @code{minimum-Y-extent}. When applied to a
460 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
461 line, such as a staff or a line of lyrics. @code{minimum-Y-extent}
462 takes a pair of numbers, so
463 if you want to make it smaller than its default @code{#'(-4 . 4)}
467 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
471 This sets the vertical size of the current staff to 3 staff spaces on
472 either side of the center staff line. The value @code{(-3 . 3)} is
473 interpreted as an interval, where the center line is the 0, so the
474 first number is generally negative. The numbers need not match;
475 for example, the staff can be made larger at the bottom by setting
476 it to @code{(-6 . 4)}.
481 Internals: Vertical alignment of staves is handled by the
482 @internalsref{VerticalAlignment} object. The context parameters
483 specifying the vertical extent are described in connection with
484 the @internalsref{Axis_group_engraver}.
486 Example files: @inputfileref{input/regression/,page-spacing.ly},
487 @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
490 @node Vertical spacing of piano staves
491 @subsection Vertical spacing of piano staves
493 The distance between staves of a @internalsref{PianoStaff} cannot be
494 computed during formatting. Rather, to make cross-staff beaming work
495 correctly, that distance has to be fixed beforehand.
497 The distance of staves in a @code{PianoStaff} is set with the
498 @code{forced-distance} property of the
499 @internalsref{VerticalAlignment} object, created in
500 @internalsref{PianoStaff}.
502 It can be adjusted as follows
504 \new PianoStaff \with @{
505 \override VerticalAlignment #'forced-distance = #7
512 This would bring the staves together at a distance of 7 staff spaces,
513 measured from the center line of each staff.
515 The difference is demonstrated in the following example,
516 @lilypond[quote,verbatim]
518 \new PianoStaff \with {
519 \override VerticalAlignment #'forced-distance = #7
534 Example files: @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
537 @node Vertical spacing between systems
538 @subsection Vertical spacing between systems
540 Space between systems are controlled by four @code{\paper} variables,
544 between-system-space = 1.5\cm
545 between-system-padding = #1
547 ragged-last-bottom=##f
552 @node Controlling spacing of individual systems
553 @subsection Controlling spacing of individual systems
555 It is also possible to change the distance between for each system
556 individually. This is done by including the command
560 #"Score.NonMusicalPaperColumn"
561 #'line-break-system-details
562 #'((fixed-alignment-extra-space . 15))
566 at the line break before the system to be changed. The distance
567 @code{15} is distributed over all staves that have a fixed distance
568 alignment. For example,
570 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
576 #"Score.NonMusicalPaperColumn"
577 #'line-break-system-details
578 #'((fixed-alignment-extra-space . 15))
586 The distance for @code{fixed-alignment-extra-space} may also be
591 @node Horizontal spacing
592 @section Horizontal Spacing
594 @cindex horizontal spacing
595 @cindex spacing, horizontal
598 * Horizontal spacing overview::
600 * Changing horizontal spacing::
605 @node Horizontal spacing overview
606 @subsection Horizontal spacing overview
608 The spacing engine translates differences in durations into stretchable
609 distances (``springs'') of differring lengths. Longer durations get
610 more space, shorter durations get less. The shortest durations get a
611 fixed amount of space (which is controlled by
612 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
613 object). The longer the duration, the more space it gets: doubling a
614 duration adds a fixed amount (this amount is controlled by
615 @code{spacing-increment}) of space to the note.
617 For example, the following piece contains lots of half, quarter, and
618 8th notes; the eighth note is followed by 1 note head width (NHW).
619 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
621 @lilypond[quote,fragment,verbatim,relative=1]
622 c2 c4. c8 c4. c8 c4. c8 c8
626 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
627 approximately the width of a note head, and
628 @code{shortest-duration-space} is set to 2.0, meaning that the
629 shortest note gets 2.4 staff space (2.0 times the
630 @code{spacing-increment}) of horizontal space. This space is counted
631 from the left edge of the symbol, so the shortest notes are generally
632 followed by one NHW of space.
634 If one would follow the above procedure exactly, then adding a single
635 32nd note to a score that uses 8th and 16th notes, would widen up the
636 entire score a lot. The shortest note is no longer a 16th, but a 32nd,
637 thus adding 1 NHW to every note. To prevent this, the shortest
638 duration for spacing is not the shortest note in the score, but rather
639 the one which occurs most frequently.
642 The most common shortest duration is determined as follows: in every
643 measure, the shortest duration is determined. The most common shortest
644 duration is taken as the basis for the spacing, with the stipulation
645 that this shortest duration should always be equal to or shorter than
646 an 8th note. The shortest duration is printed when you run
647 @code{lilypond} with the @code{--verbose} option.
649 These durations may also be customized. If you set the
650 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
651 this sets the base duration for spacing. The maximum duration for this
652 base (normally an 8th), is set through @code{base-shortest-duration}.
654 @findex common-shortest-duration
655 @findex base-shortest-duration
656 @findex stem-spacing-correction
659 Notes that are even shorter than the common shortest note are
660 followed by a space that is proportional to their duration relative to
661 the common shortest note. So if we were to add only a few 16th notes
662 to the example above, they would be followed by half a NHW:
664 @lilypond[quote,fragment,verbatim,relative=2]
665 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
669 In the introduction (see @ref{Engraving}), it was explained that stem
670 directions influence spacing. This is controlled with the
671 @code{stem-spacing-correction} property in the
672 @internalsref{NoteSpacing}, object. These are generated for every
673 @internalsref{Voice} context. The @code{StaffSpacing} object
674 (generated in @internalsref{Staff} context) contains the same property
675 for controlling the stem/bar line spacing. The following example shows
676 these corrections, once with default settings, and once with
677 exaggerated corrections:
679 @lilypond[quote,ragged-right]
683 \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
684 \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
690 Proportional notation is supported; see @ref{Proportional notation}.
695 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
696 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
697 @internalsref{SeparatingGroupSpanner}.
702 There is no convenient mechanism to manually override spacing. The
703 following work-around may be used to insert extra space into a score.
705 \once \override Score.SeparationItem #'padding = #1
708 No work-around exists for decreasing the amount of space.
711 @node New spacing area
712 @subsection New spacing area
714 New sections with different spacing parameters can be started with
715 @code{newSpacingSection}. This is useful when there are
716 sections with a different notions of long and short notes.
718 In the following example, the time signature change introduces a new
719 section, and hence the 16ths notes are spaced wider.
721 FIXME: wait until we're definitely adding NEWS items. -gp
723 @lilypond[relative,fragment,verbatim]
726 c8 c c4 c16[ c c8] c4
733 @node Changing horizontal spacing
734 @subsection Changing horizontal spacing
736 By default, spacing in tuplets depends on various non-duration
737 factors (such as accidentals, clef changes, etc). To disregard
738 such symbols and force uniform equal-duration spacing, use
739 @code{Score.SpacingSpanner #'uniform-stretching}. This
740 property can only be changed at the beginning of a score,
742 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
744 \override SpacingSpanner #'uniform-stretching = ##t
762 When @code{strict-note-spacing} is set, notes are spaced without
763 regard for clefs, bar lines, and grace notes,
765 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
766 \override Score.SpacingSpanner #'strict-note-spacing = ##t
767 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c] c32[ c32] }
772 @subsection Line length
775 @cindex breaking pages
782 @c Although line-width can be set in \layout, it should be set in paper
783 @c block, to get page layout right.
784 @c Setting indent in \paper block makes not much sense, but it works.
786 @c Bit verbose and vague, use examples?
787 The most basic settings influencing the spacing are @code{indent} and
788 @code{line-width}. They are set in the @code{\layout} block. They
789 control the indentation of the first line of music, and the lengths of
792 If @code{ragged-right} is set to true in the @code{\layout} block, then
793 systems ends at their natural horizontal length, instead of being spread
794 horizontally to fill the whole line. This is useful for
795 short fragments, and for checking how tight the natural spacing is.
798 @cindex vertical spacing
800 The option @code{ragged-last} is similar to @code{ragged-right}, but
801 only affects the last line of the piece. No restrictions are put on
802 that line. The result is similar to formatting text paragraphs. In a
803 paragraph, the last line simply takes its natural horizontal length.
804 @c Note that for text there are several options for the last line.
805 @c While Knuth TeX uses natural length, lead typesetters use the same
806 @c stretch as the previous line. eTeX uses \lastlinefit to
807 @c interpolate between both these solutions.
827 @subsection Line breaking
830 @cindex breaking lines
832 Line breaks are normally computed automatically. They are chosen so
833 that lines look neither cramped nor loose, and that consecutive lines
834 have similar density.
836 Occasionally you might want to override the automatic breaks; you can
837 do this by specifying @code{\break}. This will force a line break at
838 this point. Line breaks can only occur at places where there are bar
839 lines. If you want to have a line break where there is no bar line,
840 you can force an invisible bar line by entering @code{\bar
841 ""}. Similarly, @code{\noBreak} forbids a line break at a
845 @cindex regular line breaks
846 @cindex four bar music.
848 For line breaks at regular intervals use @code{\break} separated by
849 skips and repeated with @code{\repeat}:
851 << \repeat unfold 7 @{
852 s1 \noBreak s1 \noBreak
853 s1 \noBreak s1 \break @}
854 @emph{the real music}
859 This makes the following 28 measures (assuming 4/4 time) be broken every
860 4 measures, and only there.
864 @code{\break}, and @code{\noBreak}.
870 Internals: @internalsref{BreakEvent}.
872 A linebreaking configuration can now be saved as a @code{.ly} file
873 automatically. This allows vertical alignments to be stretched to
874 fit pages in a second formatting run. This is fairly new and
875 complicated; see @inputfileref{input/regression/,page-layout-twopass.ly}
880 Line breaks can only occur if there is a ``proper'' bar line. A note
881 which is hanging over a bar line is not proper, such as
883 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
884 c4 c2 c2 \break % this does nothing
885 c2 c4 | % a break here would work
886 c4 c2 c4 ~ \break % as does this break
892 @subsection Page breaking
894 The default page breaking may be overriden by inserting
895 @code{\pageBreak} or @code{\noPageBreak} commands. These commands are
896 analogous to @code{\break} and @code{\noBreak}. They should be
897 inserted at a bar line. These commands force and forbid a page-break
898 from happening. Of course, the @code{\pageBreak} command also forces
901 Page breaks are computed by the @code{page-breaking} function in the
904 To force a new page for a new piece (in a collection of pieces or a
905 piece in several movements), use @code{breakbefore} in the header.
924 The @code{breakbefore=##t} header requires that there is a @code{piece}
925 header as well. It may be used as a normal header, or left blank
926 (@code{=""}) as in the example above, but it must be present.
929 @node Displaying spacing
930 @section Displaying spacing
932 @findex annotate-spacing
933 @cindex Spacing, display of properties
935 To graphically display the dimensions of vertical properties
936 that may be altered for page formatting, use
939 \paper { annotate-spacing = ##t }
944 @c FIXME: really bad vagueness due to bug in annotate-spacing. -gp
945 Some unit dimensions are measured in staff spaces, while others
946 are measured in millimeters.
948 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
949 @var{b} the upper edge of the interval.