]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/spacing.itely
Merge branch 'master' of ssh+git://git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / Documentation / user / spacing.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
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.  See TRANSLATION for details.
8 @end ignore
9
10 @c A menu is needed before every deeper *section nesting of @node's; run
11 @c     M-x texinfo-all-menus-update
12 @c to automatically fill in these menus before saving changes
13
14 @node Spacing issues
15 @chapter Spacing issues
16
17 The global paper layout is determined by three factors: the page layout, the
18 line breaks, and the spacing.  These all influence each other.  The
19 choice of spacing determines how densely each system of music is set.
20 This influences where line breaks are chosen, and thus ultimately, how
21 many pages a piece of music takes.
22
23 Globally speaking, this procedure happens in four steps: first,
24 flexible distances (@q{springs}) are chosen, based on durations.  All
25 possible line breaking combinations are tried, and a @q{badness} score
26 is calculated for each. Then the height of each possible system is
27 estimated. Finally, a page breaking and line breaking combination is chosen
28 so that neither the horizontal nor the vertical spacing is too cramped
29 or stretched.
30
31 @menu
32 * Paper and pages::             
33 * Music layout::                
34 * Displaying spacing::          
35 * Breaks::                      
36 * Vertical spacing::            
37 * Horizontal spacing::          
38 @end menu
39
40
41 @node Paper and pages
42 @section Paper and pages
43
44 This section deals with the boundaries that define the area
45 that music can be printed inside.
46
47 @menu
48 * Paper size::                  
49 * Page formatting::             
50 @end menu
51
52
53 @node Paper size
54 @subsection Paper size
55
56 @cindex paper size
57 @cindex page size
58 @funindex papersize
59
60 To change the paper size, there are two commands,
61 @example
62 #(set-default-paper-size "a4")
63 \paper @{
64   #(set-paper-size "a4")
65 @}
66 @end example
67
68 The first command sets the size of all pages.  The second command sets the
69 size
70 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
71 block is at the top of the file, then it will apply to all pages.  If the
72 @code{\paper} block is inside a @code{\book}, then the paper size will only
73 apply to that book.
74
75 Support for the following paper sizes are included by default,
76 @code{a6}, @code{a5}, @code{a4}, @code{a3}, @code{legal}, @code{letter},
77 @code{11x17} (also known as tabloid).
78
79 Extra sizes may be added by editing the definition for
80 @code{paper-alist} in the initialization file @file{scm/paper.scm}.
81
82 @cindex orientation
83 @cindex landscape
84
85 If the symbol @code{landscape} is supplied as an argument to
86 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
87 and wider line widths will be set correspondingly.
88
89 @example
90 #(set-default-paper-size "a6" 'landscape)
91 @end example
92
93 Setting the paper size will adjust a number of @code{\paper} variables
94 (such as margins).  To use a particular paper size with altered
95 @code{\paper} variables, set the paper size before setting the variables.
96
97
98 @node Page formatting
99 @subsection Page formatting
100
101 @cindex page formatting
102 @cindex margins
103 @cindex header, page
104 @cindex footer, page
105
106 LilyPond will do page layout, set margins, and add headers and
107 footers to each page.
108
109 The default layout responds to the following settings in the
110 @code{\paper} block.
111
112 @funindex \paper
113
114 @quotation
115 @table @code
116 @funindex first-page-number
117 @item first-page-number
118 The value of the page number of the first page.  Default is@tie{}1.
119
120 @funindex print-first-page-number
121 @item print-first-page-number
122 If set to true, will print the page number in the first page.  Default is
123 false.
124
125 @funindex print-page-number
126 @item print-page-number
127 If set to false, page numbers will not be printed. Default is true.
128
129 @funindex paper-width
130 @item paper-width
131 The width of the page. The default is taken from the current paper size,
132 see @ref{Paper size}. 
133
134 @funindex paper-height
135 @item paper-height
136 The height of the page. The default is taken from the current paper size,
137 see @ref{Paper size}. 
138
139 @funindex top-margin
140 @item top-margin
141 Margin between header and top of the page. Default is@tie{}5mm.
142
143 @funindex bottom-margin
144 @item bottom-margin
145 Margin between footer and bottom of the page. Default is@tie{}6mm.
146
147 @funindex left-margin
148 @item left-margin
149 Margin between the left side of the page and the beginning of the
150 music. Unset by default, which means that the margins is determined
151 based on the @code{paper-width} and @code{line-width} to center the
152 score on the paper. 
153
154 @funindex line-width
155 @item line-width
156 The length of the systems. Default is @code{paper-width} minus @tie{}20mm.
157
158 @funindex head-separation
159 @item head-separation
160 Distance between the top-most music system and the page header. Default
161 is@tie{}4mm. 
162
163 @funindex foot-separation
164 @item foot-separation
165 Distance between the bottom-most music system and the page
166 footer. Default is@tie{}4mm.
167
168 @funindex page-top-space
169 @item page-top-space
170 Distance from the top of the printable area to the center of the first
171 staff. This only works for staves which are vertically small. Big staves
172 are set with the top of their bounding box aligned to the top of the
173 printable area. Default is@tie{}12mm.
174
175 @funindex ragged-bottom
176 @item ragged-bottom
177 If set to true, systems will not be spread vertically across the page.  This
178 does not affect the last page. Default is false.
179
180 This should be set to true for pieces that have only two or three
181 systems per page, for example orchestral scores.
182
183 @funindex ragged-last-bottom
184 @item ragged-last-bottom
185 If set to false, systems will be spread vertically to fill the last
186 page. Default is true.
187
188 Pieces that amply fill two pages or more should have this set to
189 true.
190
191 @funindex system-count
192 @item system-count
193 This variable, if set, specifies into how many lines a score should be
194 broken. Unset by default.
195
196 @funindex between-system-space
197 @item between-system-space
198 This dimensions determines the distance between systems.  It is the
199 ideal distance between the center of the bottom staff of one system
200 and the center of the top staff of the next system. Default is@tie{}20mm.
201
202 Increasing this will provide a more even appearance of the page at the
203 cost of using more vertical space.
204
205 @funindex between-system-padding
206 @item between-system-padding
207 This dimension is the minimum amount of white space that will always
208 be present between the bottom-most symbol of one system, and the
209 top-most of the next system. Default is@tie{}4mm.
210
211 Increasing this will put systems whose bounding boxes almost touch
212 farther apart.
213
214
215 @funindex horizontal-shift
216 @item horizontal-shift
217 All systems (including titles and system separators) are shifted by
218 this amount to the right. Page markup, such as headers and footers are
219 not affected by this. The purpose of this variable is to make space
220 for instrument names at the left. Default is@tie{}0.
221
222 @funindex after-title-space
223 @item after-title-space
224 Amount of space between the title and the first system. Default is@tie{}5mm.
225
226 @funindex before-title-space
227 @item before-title-space
228 Amount of space between the last system of the previous piece and the
229 title of the next. Default is@tie{}10mm.
230
231 @funindex between-title-space
232 @item between-title-space
233 Amount of space between consecutive titles (e.g., the title of the
234 book and the title of a piece). Default is@tie{}2mm.
235
236 @funindex printallheaders
237 @item printallheaders
238 Setting this to #t will print all headers for each \score in the
239 output.  Normally only the piece and opus \headers are printed.
240
241 @funindex systemSeparatorMarkup
242 @item systemSeparatorMarkup
243 This contains a markup object, which will be inserted between
244 systems.  This is often used for orchestral scores. Unset by default.
245
246 The markup command @code{\slashSeparator} is provided as a sensible
247 default,  for example
248
249 @lilypond[ragged-right]
250 #(set-default-paper-size "a6" 'landscape)
251 \book {
252   \score {
253     \relative { c1 \break c1 }
254   }
255   \paper {
256     systemSeparatorMarkup = \slashSeparator
257   }
258 }
259 @end lilypond
260
261 @funindex blank-page-force
262 @item blank-page-force
263 The penalty for having a blank page in the middle of a
264 score. This is not used by @code{ly:optimal-breaking} since it will
265 never consider blank pages in the middle of a score. Default value
266 is 10.
267
268 @funindex blank-last-page-force
269 @item blank-last-page-force
270 The penalty for ending the score on an odd-numbered page.
271 Default value is 0.
272
273 @funindex page-spacing-weight
274 @item page-spacing-weight
275 The relative importance of page (vertical) spacing and line (horizontal)
276 spacing. High values will make page spacing more important. Default
277 value is 10.
278
279 @funindex auto-first-page-number
280 @item auto-first-page-number
281 The page breaking algorithm is affected by the first page number being
282 odd or even.  If this variable is set to #t, the page breaking algorithm
283 will decide whether to start with an odd or even number.  This will 
284 result in the first page number remaining as is or being increased by one.
285
286 @end table
287 @end quotation
288
289 Example:
290
291 @example
292 \paper@{
293   paper-width = 2\cm
294   top-margin = 3\cm
295   bottom-margin = 3\cm
296   ragged-last-bottom = ##t
297 @}
298 @end example
299
300 You can also define these values in Scheme.  In that case @code{mm},
301 @code{in}, @code{pt}, and @code{cm} are variables defined in
302 @file{paper-defaults.ly} with values in millimeters.  That is why the
303 value must be multiplied in the example
304
305 @example
306 \paper @{
307   #(define bottom-margin (* 2 cm))
308 @}
309 @end example
310
311 The header and footer are created by the functions @code{make-footer}
312 and @code{make-header}, defined in @code{\paper}.  The default
313 implementations are in @file{ly/@/paper@/-defaults@/.ly} and
314 @file{ly/@/titling@/-init@/.ly}.
315
316 The page layout itself is done by two functions in the
317 @code{\paper} block, @code{page-music-height} and
318 @code{page-make-stencil}.  The former tells the line-breaking algorithm
319 how much space can be spent on a page, the latter creates the actual
320 page given the system to put on it.
321
322
323 @refbugs
324
325 The option right-margin is defined but doesn't set the right margin
326 yet.  The value for the right margin has to be defined adjusting the
327 values of @code{left-margin} and @code{line-width}.
328
329 The default page header puts the page number and the @code{instrument}
330 field from the @code{\header} block on a line.
331
332 The titles (from the @code{\header@{@}} section) are treated as a
333 system, so @code{ragged-bottom} and @code{ragged-last-bottom} will
334 add space between the titles and the first system of the score.
335
336
337 @node Music layout
338 @section Music layout
339
340 @menu
341 * Setting the staff size::      
342 * Score layout::                
343 @end menu
344
345
346 @node Setting the staff size
347 @subsection Setting the staff size
348
349 @cindex font size, setting
350 @cindex staff size, setting
351 @funindex layout file
352
353 To set the staff size globally for all scores in a file (or
354 in a @code{book} block, to be precise), use @code{set-global-staff-size}.
355
356 @example
357 #(set-global-staff-size 14)
358 @end example
359
360 @noindent
361 This sets the global default size to 14pt staff height and scales all
362 fonts accordingly.
363
364 To set the staff size individually for each score, use 
365 @example
366 \score@{
367   ...
368   \layout@{
369   #(layout-set-staff-size 15)
370   @}
371 @}
372 @end example
373
374 The Feta font provides musical symbols at eight different
375 sizes.  Each font is tuned for a different staff size: at a smaller size
376 the font becomes heavier, to match the relatively heavier staff lines.
377 The recommended font sizes are listed in the following table:
378
379 @quotation
380 @multitable @columnfractions .15 .2 .22 .2
381
382 @item @b{font name}
383 @tab @b{staff height (pt)}
384 @tab @b{staff height (mm)}
385 @tab @b{use}
386
387 @item feta11
388 @tab 11.22
389 @tab 3.9
390 @tab pocket scores
391
392 @item feta13
393 @tab 12.60
394 @tab 4.4
395 @tab
396
397 @item feta14
398 @tab 14.14
399 @tab 5.0
400 @tab
401
402 @item feta16
403 @tab 15.87
404 @tab 5.6
405 @tab
406
407 @item feta18
408 @tab 17.82
409 @tab 6.3
410 @tab song books
411
412 @item feta20
413 @tab 20
414 @tab 7.0
415 @tab standard parts
416
417 @item feta23
418 @tab 22.45
419 @tab 7.9
420 @tab
421
422 @item feta26
423 @tab 25.2
424 @tab 8.9
425 @tab
426 @c modern rental material?
427
428 @end multitable
429 @end quotation
430
431 These fonts are available in any sizes.  The context property
432 @code{fontSize} and the layout property @code{staff-space} (in
433 @internalsref{StaffSymbol}) can be used to tune the size for individual
434 staves.  The sizes of individual staves are relative to the global size.
435
436 @example
437
438 @end example
439
440 @seealso
441
442 This manual: @ref{Selecting notation font size}.
443
444
445 @node Score layout
446 @subsection Score layout
447
448 @funindex \layout
449
450 While @code{\paper} contains settings that relate to the page formatting
451 of the whole document, @code{\layout} contains settings for score-specific
452 layout.
453
454 @example
455 \layout @{
456   indent = 2.0\cm
457   \context @{ \Staff
458     \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
459   @}
460   \context @{ \Voice
461     \override TextScript #'padding = #1.0
462     \override Glissando #'thickness = #3
463   @}
464 @}
465 @end example
466
467
468 @seealso
469
470 This manual: @ref{Changing context default settings}
471
472
473 @node Displaying spacing
474 @section Displaying spacing
475
476 @funindex annotate-spacing
477 @cindex Spacing, display of properties
478
479 To graphically display the dimensions of vertical properties that may
480 be altered for page formatting, set @code{annotate-spacing} in the
481 @code{\paper} block, like this
482
483
484 @lilypond[verbatim]
485 #(set-default-paper-size "a6" 'landscape)
486
487 \book {
488   \score { { c4 } }
489   \paper { annotate-spacing = ##t }
490 }
491 @end lilypond
492
493 @c need to have \book{} otherwise we get  the separate systems. -hwn
494
495 @noindent
496 @c  FIXME: really bad vagueness due to bug in annotate-spacing.  -gp
497 Some unit dimensions are measured in staff spaces, while others
498 are measured in millimeters.
499 The pairs
500 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
501 @var{b} the upper edge of the interval.
502
503
504 @node Breaks
505 @section Breaks
506
507 @menu
508 * Line breaking::               
509 * Page breaking::               
510 * Optimal page breaking::       
511 * Optimal page turning::        
512 * Explicit breaks::             
513 * Using an extra voice for breaks::  
514 @end menu
515
516 @node Line breaking
517 @subsection Line breaking
518
519 @cindex line breaks
520 @cindex breaking lines
521
522 Line breaks are normally computed automatically.  They are chosen so
523 that lines look neither cramped nor loose, and that consecutive lines
524 have similar density.
525
526 Occasionally you might want to override the automatic breaks; you can
527 do this by specifying @code{\break}.  This will force a line break at
528 this point.  Line breaks can only occur at places where there are bar
529 lines.  If you want to have a line break where there is no bar line,
530 you can force an invisible bar line by entering @code{\bar
531 ""}.  Similarly, @code{\noBreak} forbids a line break at a
532 point.
533
534
535 @cindex regular line breaks
536 @cindex four bar music.
537
538 For line breaks at regular intervals use @code{\break} separated by
539 skips and repeated with @code{\repeat}:
540 @example
541 << \repeat unfold 7 @{
542          s1 \noBreak s1 \noBreak
543          s1 \noBreak s1 \break @}
544    @emph{the real music}
545 >>
546 @end example
547
548 @noindent
549 This makes the following 28 measures (assuming 4/4 time) be broken every
550 4 measures, and only there.
551
552 @refcommands
553
554 @code{\break}, and @code{\noBreak}.
555 @funindex \break
556 @funindex \noBreak
557
558 @seealso
559
560 Internals: @internalsref{LineBreakEvent}.
561
562 A linebreaking configuration can now be saved as a @code{.ly} file
563 automatically.  This allows vertical alignments to be stretched to
564 fit pages in a second formatting run.  This is fairly new and
565 complicated.  More details are available in
566 @lsrdir{spacing}
567
568
569 @refbugs
570
571 Line breaks can only occur if there is a @q{proper} bar line.  A note
572 which is hanging over a bar line is not proper, such as
573
574 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
575 c4 c2 c2 \break   % this does nothing
576 c2 c4 |           % a break here would work
577 c4 c2 c4 ~ \break % as does this break
578 c4 c2 c4
579 @end lilypond
580
581 To allow line breaks on such bar lines, the
582 @code{Forbid_line_break_engraver} can be removed from @code{Voice}
583 context, like so
584
585
586 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
587 \new Voice \with {
588   \remove "Forbid_line_break_engraver"
589 } {
590   c4 c2 c2 \break   % now the break is allowed
591   c2 c4
592 }
593 @end lilypond
594
595
596
597 @node Page breaking
598 @subsection Page breaking
599
600 The default page breaking may be overriden by inserting
601 @code{\pageBreak} or @code{\noPageBreak} commands.  These commands are
602 analogous to @code{\break} and @code{\noBreak}.  They should be
603 inserted at a bar line.  These commands force and forbid a page-break
604 from happening.  Of course, the @code{\pageBreak} command also forces
605 a line break.
606
607 Page breaks are computed by the @code{page-breaking} function.
608 LilyPond provides two algorithms for computing page
609 breaks, @code{ly:optimal-breaking} and @code{ly:page-turn-breaking}. The
610 default is @code{ly:optimal-breaking}, but the value can be changed in
611 the @code{\paper} block:
612
613 @example
614 \paper@{
615   #(define page-breaking ly:page-turn-breaking)
616 @}
617 @end example
618
619 The old page breaking algorithm is called
620 @code{optimal-page-breaks}. If you are having trouble with the new page
621 breakers, you can enable the old one as a workaround.
622
623 @refcommands
624
625 @funindex \pageBreak
626 @code{\pageBreak}
627 @funindex \noPageBreak
628 @code{\noPageBreak}
629
630
631 @node Optimal page breaking
632 @subsection Optimal page breaking
633
634 @funindex ly:optimal-breaking
635
636 The @code{ly:optimal-breaking} function is LilyPond's default method of
637 determining page breaks. It attempts to find a page breaking that minimizes
638 cramping and stretching, both horizontally and vertically. Unlike
639 @code{ly:page-turn-breaking}, it has no concept of page turns.
640
641
642 @node Optimal page turning
643 @subsection Optimal page turning
644
645 @funindex ly:page-turn-breaking
646
647 Often it is necessary to find a page breaking configuration so that there is
648 a rest at the end of every second page. This way, the musician can turn the
649 page without having to miss notes. The @code{ly:page-turn-breaking} function
650 attempts to find a page breaking minimizing cramping and stretching, but with
651 the additional restriction that it is only allowed to introduce page turns
652 in specified places.
653
654 There are two steps to using this page breaking function. First, you must
655 enable it in the @code{\paper} block. Then, you must tell the function
656 where you would like to allow page breaks.
657
658 There are two ways to achieve the second step. First, you can specify each
659 potential page turn manually, by inserting @code{\allowPageTurn} into your
660 input file at the appropriate places.
661
662 If this is too tedious, you can add a @code{Page_turn_engraver} to a Staff or
663 Voice context. The @code{Page_turn_engraver} will scan the context for
664 sections without notes (note that it does not scan for rests; it scans for
665 the absence of notes. This is so that single-staff polyphony with rests in one
666 of the parts does not throw off the @code{Page_turn_engraver}). When it finds
667 a sufficiently long section without notes, the @code{Page_turn_engraver} will
668 insert an @code{\allowPageTurn} at the final barline in that section, unless
669 there is a @q{special} barline (such as a double bar), in which case the
670 @code{\allowPageTurn} will be inserted at the final @q{special} barline in
671 the section.
672
673 @funindex minimumPageTurnLength
674 The @code{Page_turn_engraver} reads the context property
675 @code{minimumPageTurnLength} to determine how long a note-free section must
676 be before a page turn is considered. The default value for
677 @code{minimumPageTurnLength} is @code{#(ly:make-moment 1 1)}. If you want
678 to disable page turns, you can set it to something very large.
679
680 @example
681 \new Staff \with @{ \consists "Page_turn_engraver" @}
682 @{
683   a4 b c d |
684   R1 | % a page turn will be allowed here
685   a4 b c d |
686   \set Staff.minimumPageTurnLength = #(ly:make-moment 5 2)
687   R1 | % a page turn will not be allowed here
688   a4 b r2 |
689   R1*2 | % a page turn will be allowed here
690   a1
691 @}
692 @end example
693
694 @funindex minimumRepeatLengthForPageTurn
695 The @code{Page_turn_engraver} detects volta repeats. It will only allow a page
696 turn during the repeat if there is enough time at the beginning and end of the
697 repeat to turn the page back. The @code{Page_turn_engraver} can also disable
698 page turns if the repeat is very short. If you set the context property
699 @code{minimumRepeatLengthForPageTurn} then the @code{Page_turn_engraver} will
700 only allow turns in repeats whose duration is longer than this value.
701
702 @refbugs
703
704 There should only be one @code{Page_turn_engraver} in a score. If there is more
705 than one, they will interfere with each other.
706
707
708 @node Explicit breaks
709 @subsection Explicit breaks
710
711 Lily sometimes rejects explicit @code{\break} and @code{\pageBreak}
712 commands.  There are two commands to override this behavior:
713
714 @example
715 \override NonMusicalPaperColumn #'line-break-permission = ##f
716 \override NonMusicalPaperColumn #'page-break-permission = ##f
717 @end example
718
719 When @code{line-break-permission} is overriden to false, Lily will insert
720 line breaks at explicit @code{\break} commands and nowhere else.  When
721 @code{page-break-permission} is overriden to false, Lily will insert
722 page breaks at explicit @code{\pageBreak} commands and nowhere else.
723
724 @lilypond[quote,verbatim]
725 \paper {
726   indent = #0
727   ragged-right = ##t
728   ragged-bottom = ##t
729 }
730
731 \score {
732   \new Score \with {
733     \override NonMusicalPaperColumn #'line-break-permission = ##f
734     \override NonMusicalPaperColumn #'page-break-permission = ##f
735   } {
736     \new Staff {
737       \repeat unfold 2 { c'8 c'8 c'8 c'8 } \break
738       \repeat unfold 4 { c'8 c'8 c'8 c'8 } \break
739       \repeat unfold 6 { c'8 c'8 c'8 c'8 } \break
740       \repeat unfold 8 { c'8 c'8 c'8 c'8 } \pageBreak
741       \repeat unfold 8 { c'8 c'8 c'8 c'8 } \break
742       \repeat unfold 6 { c'8 c'8 c'8 c'8 } \break
743       \repeat unfold 4 { c'8 c'8 c'8 c'8 } \break
744       \repeat unfold 2 { c'8 c'8 c'8 c'8 }
745     }
746   }
747 }
748 @end lilypond
749
750
751 @node Using an extra voice for breaks
752 @subsection Using an extra voice for breaks
753
754 Line- and page-breaking information usually appears within note entry directly.
755
756 @example
757 \new Score @{
758   \new Staff @{
759     \repeat unfold 2 @{ c'4 c'4 c'4 c'4 @}
760     \break
761     \repeat unfold 3 @{ c'4 c'4 c'4 c'4 @}
762   @}
763 @}
764 @end example
765
766 This makes @code{\break} and @code{\pageBreak} commands easy to enter but mixes
767 music entry with information that specifies how music should lay out
768 on the page.  You can keep music entry and line- and page-breaking
769 information in two separate places by introducing an extra voice to 
770 contain the  breaks.  This extra voice
771 contains only skips together with @code{\break}, @code{pageBreak} and other
772 breaking layout information.
773
774 @lilypond[quote,verbatim]
775 \new Score {
776   \new Staff <<
777      \new Voice {
778         s1 * 2 \break
779         s1 * 3 \break
780         s1 * 6 \break
781         s1 * 5 \break
782      }
783      \new Voice {
784         \repeat unfold 2 { c'4 c'4 c'4 c'4 }
785         \repeat unfold 3 { c'4 c'4 c'4 c'4 }
786         \repeat unfold 6 { c'4 c'4 c'4 c'4 }
787         \repeat unfold 5 { c'4 c'4 c'4 c'4 }
788      }
789   >>
790 }
791 @end lilypond
792
793 This pattern becomes especially helpful when overriding
794 @code{line-break-system-details} and the other useful but long properties of
795 @code{NonMusicalPaperColumnGrob}, as explained in @ref{Vertical spacing}.
796
797 @lilypond[quote,verbatim]
798 \new Score {
799   \new Staff <<
800      \new Voice {
801
802         \overrideProperty "Score.NonMusicalPaperColumn"
803         #'line-break-system-details #'((Y-offset . 0))
804         s1 * 2 \break
805
806         \overrideProperty "Score.NonMusicalPaperColumn"
807         #'line-break-system-details #'((Y-offset . 35))
808         s1 * 3 \break
809
810         \overrideProperty "Score.NonMusicalPaperColumn"
811         #'line-break-system-details #'((Y-offset . 70))
812         s1 * 6 \break
813
814         \overrideProperty "Score.NonMusicalPaperColumn"
815         #'line-break-system-details #'((Y-offset . 105))
816         s1 * 5 \break
817      }
818      \new Voice {
819         \repeat unfold 2 { c'4 c'4 c'4 c'4 }
820         \repeat unfold 3 { c'4 c'4 c'4 c'4 }
821         \repeat unfold 6 { c'4 c'4 c'4 c'4 }
822         \repeat unfold 5 { c'4 c'4 c'4 c'4 }
823      }
824   >>
825 }
826 @end lilypond
827
828
829 @node Vertical spacing
830 @section Vertical spacing
831
832 @cindex vertical spacing
833 @cindex spacing, vertical
834
835 Vertical spacing is controlled by three things: the amount of
836 space available (i.e., paper size and margins), the amount of
837 space between systems, and the amount of space between
838 staves inside a system.
839
840 @menu
841 * Vertical spacing inside a system::  
842 * Vertical spacing between systems::  
843 * Explicit staff and system positioning::  
844 * Two-pass vertical spacing::   
845 * Vertical collision avoidance::  
846 @end menu
847
848
849 @node Vertical spacing inside a system
850 @subsection Vertical spacing inside a system
851
852 @cindex distance between staves
853 @cindex staff distance
854 @cindex space between staves
855 @cindex space inside systems
856
857 The height of each system is determined automatically.  To prevent
858 staves from bumping into each other, some minimum distances are set.
859 By changing these, you can put staves closer together.  This
860 reduces the amount of space each system requires, and may result
861 in having more systems per page.
862
863 Normally staves are stacked vertically.  To make staves maintain a
864 distance, their vertical size is padded.  This is done with the
865 property @code{minimum-Y-extent}.  When applied to a
866 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
867 line, such as a staff or a line of lyrics.  @code{minimum-Y-extent}
868 takes a pair of numbers, so
869 if you want to make it smaller than its default @code{#'(-4 . 4)}
870 then you could set
871
872 @example
873 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
874 @end example
875
876 @noindent
877 This sets the vertical size of the current staff to 3 staff spaces on
878 either side of the center staff line.  The value @code{(-3 . 3)} is
879 interpreted as an interval, where the center line is the 0, so the
880 first number is generally negative.  The numbers need not match;
881 for example, the staff can be made larger at the bottom by setting
882 it to @code{(-6 . 4)}.
883
884
885 @seealso
886
887 Internals: Vertical alignment of staves is handled by the
888 @internalsref{VerticalAlignment} object. The context parameters
889 specifying the vertical extent are described in connection with
890 the @internalsref{Axis_group_engraver}.
891
892 Example files: @lsr{spacing,page-spacing.ly},
893 @lsr{spacing,alignment-vertical-spacing.ly}.
894
895
896 @node Vertical spacing between systems
897 @subsection Vertical spacing between systems
898
899 Space between systems are controlled by four @code{\paper} variables,
900
901 @example
902 \paper @{
903   between-system-space = 1.5\cm
904   between-system-padding = #1
905   ragged-bottom=##f
906   ragged-last-bottom=##f
907 @}
908 @end example
909
910
911 @node Explicit staff and system positioning
912 @subsection Explicit staff and system positioning
913
914 One way to understand the @code{VerticalAxisGroup} and @code{\paper}
915 settings explained in the previous two sections is as a collection of
916 different settings that primarily concern the amount of vertical padding
917 different staves and systems running down the page.
918
919 It is possible to approach vertical spacing in a different way using
920 @code{NonMusicalPaperColumn #'line-break-system-details}.  Where
921 @code{VerticalAxisGroup} and @code{\paper} settings specify vertical padding,
922 @code{NonMusicalPaperColumn #'line-break-system-details} specifies exact
923 vertical positions on the page.
924
925 @code{NonMusicalPaperColumn #'line-break-system-details} accepts an associative
926 list of five different settings:
927
928 @itemize 
929 @item @code{X-offset}
930 @item @code{Y-offset}
931 @item @code{alignment-offsets}
932 @item @code{alignment-extra-space}
933 @item @code{fixed-alignment-extra-space}
934 @end itemize
935
936 Grob overrides, including the overrides for @code{NonMusicalPaperColumn}
937 below, can occur in any of three different places in an input file:
938
939 @itemize
940 @item in the middle of note entry directly
941 @item in a @code{\context} block
942 @item in the @code{\with} block
943 @end itemize
944
945 When we override @code{NonMusicalPaperColumn}, we use the usual
946 @code{\override} command in @code{\context} blocks and in the
947 @code{\with} block.  On the other hand, when we override
948 @code{NonMusicalPaperColumn} in the middle of note entry,
949 use the special @code{\overrideProperty} command.  Here are some
950 example @code{NonMusicalPaperColumn} overrides with the special
951 @code{\overrideProperty} command:
952
953 @example
954 \overrideProperty NonMusicalPaperColumn
955   #'line-break-system-details #'((X-offset . 20))
956
957 \overrideProperty NonMusicalPaperColumn
958   #'line-break-system-details #'((Y-offset . 40))
959
960 \overrideProperty NonMusicalPaperColumn
961   #'line-break-system-details #'((X-offset . 20) (Y-offset . 40))
962
963 \override NonMusicalPaperColumn
964   #'line-break-system-details #'((alignment-offsets . (0 -15)))
965
966 \override NonMusicalPaperColumn
967   #'line-break-system-details #'((X-offset . 20) (Y-offset . 40)
968                                  (alignment-offsets . (0 -15)))
969 @end example
970
971 To understand how each of these different settings work, we begin
972 by looking at an example that includes no overrides at all.
973
974 @lilypond[quote,ragged-right]
975 \new Score <<
976   \new Staff <<
977     \new Voice {
978       s1 * 6 \break
979       s1 * 6 \break
980       s1 * 6 \break
981     }
982     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
983   >>
984   \new Staff {
985     \repeat unfold 18 { d'4 d'4 d'4 d'4 }
986   }
987 >>
988 @end lilypond
989
990 This score isolates line- and page-breaking information in a dedicated
991 voice. This technique of creating a breaks voice will help keep layout
992 separate from music entry as our example becomes more complicated.
993 See @ref{Using an extra voice for breaks}.
994
995 Explicit @code{\breaks} evenly divide the music into six measures per
996 line.  Vertical spacing results from LilyPond's defaults.  To set
997 the vertical startpoint of each system explicitly, we can set
998 the @code{Y-offset} pair in the @code{line-break-system-details}
999 attribute of the @code{NonMusicalPaperColumn} grob:
1000
1001 @lilypond[quote,ragged-right]
1002 \new Score <<
1003   \new Staff <<
1004     \new Voice {
1005       \overrideProperty #"Score.NonMusicalPaperColumn"
1006         #'line-break-system-details #'((Y-offset . 0))
1007       s1 * 6 \break
1008       \overrideProperty #"Score.NonMusicalPaperColumn"
1009         #'line-break-system-details #'((Y-offset . 40))
1010       s1 * 6 \break
1011       \overrideProperty #"Score.NonMusicalPaperColumn"
1012         #'line-break-system-details #'((Y-offset . 80))
1013       s1 * 6 \break
1014     }
1015     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
1016   >>
1017   \new Staff {
1018     \repeat unfold 18 { d'4 d'4 d'4 d'4 }
1019   }
1020 >>
1021 @end lilypond
1022
1023 Note that @code{line-break-system-details} takes an associative list of
1024 potentially many values, but that we set only one value here.  Note,
1025 too, that the @code{Y-offset} property here determines the exact vertical
1026 position on the page at which each new system will render.
1027
1028 Now that we have set the vertical startpoint of each system
1029 explicitly, we can also set the vertical startpoint of each staff
1030 within each system manually.  We do this using the @code{alignment-offsets}
1031 subproperty of @code{line-break-system-details}.
1032
1033 @lilypond[quote,ragged-right]
1034 \new Score <<
1035   \new Staff <<
1036     \new Voice {
1037       \overrideProperty #"Score.NonMusicalPaperColumn"
1038         #'line-break-system-details #'((Y-offset . 20)
1039           (alignment-offsets . (0 -15)))
1040       s1 * 6 \break
1041       \overrideProperty #"Score.NonMusicalPaperColumn"
1042         #'line-break-system-details #'((Y-offset . 60)
1043           (alignment-offsets . (0 -15)))
1044       s1 * 6 \break
1045       \overrideProperty #"Score.NonMusicalPaperColumn"
1046         #'line-break-system-details #'((Y-offset . 100)
1047           (alignment-offsets . (0 -15)))
1048       s1 * 6 \break
1049     }
1050     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
1051   >>
1052   \new Staff {
1053     \repeat unfold 18 { d'4 d'4 d'4 d'4 }
1054   }
1055 >>
1056 @end lilypond
1057
1058 Note that here we assign two different values to the
1059 @code{line-break-system-details} attribute of the
1060 @code{NonMusicalPaperColumn} grob.  Though the
1061 @code{line-break-system-details} attribute alist accepts many
1062 additional spacing parameters (including, for example, a corresponding
1063 @code{X-offset} pair), we need only set the @code{Y-offset} and
1064 @code{alignment-offsets} pairs to control the vertical startpoint of
1065 every system and every staff.  Finally, note that @code{alignment-offsets}
1066 specifies the vertical positioning of staves but not of staff groups.
1067
1068 @lilypond[quote,ragged-right]
1069 \new Score <<
1070   \new Staff <<
1071     \new Voice {
1072       \overrideProperty #"Score.NonMusicalPaperColumn"
1073       #'line-break-system-details #'((Y-offset . 0)
1074         (alignment-offsets . (0 -30 -40)))
1075       s1 * 6 \break
1076       \overrideProperty #"Score.NonMusicalPaperColumn"
1077       #'line-break-system-details #'((Y-offset . 60)
1078         (alignment-offsets . (0 -10 -20)))
1079       s1 * 6 \break
1080       \overrideProperty #"Score.NonMusicalPaperColumn"
1081       #'line-break-system-details #'((Y-offset . 100)
1082         (alignment-offsets . (0 -10, -40)))
1083       s1 * 6 \break
1084     }
1085     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
1086   >>
1087   \new StaffGroup <<
1088     \new Staff {
1089       \repeat unfold 18 { d'4 d'4 d'4 d'4 }
1090     }
1091     \new Staff {
1092       \repeat unfold 18 { e'4 e'4 e'4 e'4 }
1093     }
1094   >>
1095 >>
1096 @end lilypond
1097
1098 Some points to consider:
1099
1100 @itemize
1101 @item When using @code{alignment-offsets}, lyrics count as a staff.
1102
1103 @item The units of the numbers passed to @code{X-offset},
1104 @code{Y-offset} and @code{alignment-offsets} are interpreted as multiples
1105 of the distance between adjacent staff lines.  Positive values move staves
1106 and lyrics up, negative values move staves and lyrics down.
1107
1108 @item Because the @code{NonMusicalPaperColumn #'line-break-system-details}
1109 settings given here allow the positioning of staves and systems anywhere
1110 on the page, it is possible to violate paper or margin boundaries or even
1111 to print staves or systems on top of one another.  Reasonable values
1112 passed to these different settings will avoid this.
1113 @end itemize
1114
1115
1116 @node Two-pass vertical spacing
1117 @subsection Two-pass vertical spacing
1118
1119 In order to automatically stretch systems so that they should fill the
1120 space left on a page, a two-pass technique can be used:
1121
1122 @enumerate
1123 @item In the first pass, the amount of vertical space used to increase
1124 the height of each system is computed and dumped to a file.
1125 @item In the second pass, spacing inside the systems are
1126 stretched according to the data in the page layout file.
1127 @end enumerate
1128
1129 The @code{ragged-bottom} property adds space between systems, while
1130 the two-pass technique adds space between staves inside a system.
1131
1132 To allow this behaviour, a @code{tweak-key} variable has to be set in
1133 each score @code{\layout} block, and the tweaks included in each score
1134 music, using the @code{\scoreTweak} music function.
1135
1136 @quotation
1137 @verbatim
1138 %% include the generated page layout file:
1139 \includePageLayoutFile
1140
1141 \score {
1142   \new StaffGroup <<
1143     \new Staff <<
1144       %% Include this score tweaks:
1145       \scoreTweak "scoreA"
1146       { \clef french c''1 \break c''1 } 
1147     >>
1148     \new Staff { \clef soprano g'1 g'1 }
1149     \new Staff { \clef mezzosoprano e'1 e'1 }
1150     \new Staff { \clef alto g1 g1 }
1151     \new Staff { \clef bass c1 c1 }
1152   >>
1153   \header {
1154     piece = "Score with tweaks"
1155   }
1156   %% Define how to name the tweaks for this score:
1157   \layout { #(define tweak-key "scoreA") }
1158 }
1159 @end verbatim
1160 @end quotation
1161
1162 For the first pass, the @code{dump-tweaks} option should be set to
1163 generate the page layout file.
1164
1165 @example
1166 lilypond -dbackend=null -d dump-tweaks <file>.ly
1167 lilypond <file>.ly
1168 @end example
1169
1170
1171 @node Vertical collision avoidance
1172 @subsection Vertical collision avoidance
1173
1174 @funindex outside-staff-priority
1175 @funindex outside-staff-padding
1176 @funindex outside-staff-horizontal-padding
1177
1178 Intuitively, there are some objects in musical notation that belong
1179 to the staff and there are other objects that should be placed outside
1180 the staff.  Objects belonging outside the staff include things such as
1181 rehearsal marks, text and dynamic markings (from now on, these will
1182 be called outside-staff objects).  LilyPond's rule for the
1183 vertical placement of outside-staff objects is to place them as close
1184 to the staff as possible but not so close that they collide with
1185 another object.
1186
1187 LilyPond uses the @code{outside-staff-priority} property to determine
1188 whether a grob is an outside-staff object: if @code{outside-staff-priority}
1189 is a number, the grob is an outside-staff object.  In addition,
1190 @code{outside-staff-priority} tells LilyPond in which order the objects
1191 should be placed.
1192
1193 First, LilyPond places all the objects that do not belong outside
1194 the staff.  Then it sorts the outside-staff objects according to their
1195 @code{outside-staff-priority} (in increasing order).  One by one, LilyPond
1196 takes the outside-staff objects and places them so that they do
1197 not collide with any objects that have already been placed.  That
1198 is, if two outside-staff grobs are competing for the same space, the one
1199 with the lower @code{outside-staff-priority} will be placed closer to
1200 the staff.
1201
1202 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1203 c4_"Text"\pp
1204 r2.
1205 \once \override TextScript #'outside-staff-priority = #1
1206 c4_"Text"\pp % this time the text will be closer to the staff
1207 r2.
1208 % by setting outside-staff-priority to a non-number, we
1209 % disable the automatic collision avoidance
1210 \once \override TextScript #'outside-staff-priority = ##f
1211 \once \override DynamicLineSpanner #'outside-staff-priority = ##f
1212 c4_"Text"\pp % now they will collide
1213 @end lilypond
1214
1215 The vertical padding between an outside-staff object and the
1216 previously-positioned grobs can be controlled with
1217 @code{outside-staff-padding}.
1218
1219 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1220 \once \override TextScript #'outside-staff-padding = #0
1221 a'^"This text is placed very close to the note"
1222 \once \override TextScript #'outside-staff-padding = #3
1223 c^"This text is padded away from the previous text"
1224 c^"This text is placed close to the previous text"
1225 @end lilypond
1226
1227 By default, outside-staff objects are placed without regard to
1228 their horizontal distance from the previously-posititioned grobs.  This
1229 can lead to situations in which objects are placed very close to each
1230 other horizontally.  Setting @code{outside-staff-horizontal-padding}
1231 causes an object to be offset vertically so that such a situation
1232 doesn't occur.
1233
1234 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1235 % the markup is too close to the following note
1236 c2^"Text"
1237 c''2
1238 % setting outside-staff-horizontal-padding fixes this
1239 R1
1240 \once \override TextScript #'outside-staff-horizontal-padding = #1
1241 c,,2^"Text"
1242 c''2
1243 @end lilypond
1244
1245
1246
1247 @node Horizontal spacing
1248 @section Horizontal Spacing
1249
1250 @cindex horizontal spacing
1251 @cindex spacing, horizontal
1252
1253 @menu
1254 * Horizontal spacing overview::  
1255 * New spacing area::            
1256 * Changing horizontal spacing::  
1257 * Line length::                 
1258 * Proportional notation::       
1259 @end menu
1260
1261
1262 @node Horizontal spacing overview
1263 @subsection Horizontal spacing overview
1264
1265 The spacing engine translates differences in durations into stretchable
1266 distances (@q{springs}) of differring lengths.  Longer durations get
1267 more space, shorter durations get less.  The shortest durations get a
1268 fixed amount of space (which is controlled by
1269 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
1270 object).  The longer the duration, the more space it gets: doubling a
1271 duration adds a fixed amount (this amount is controlled by
1272 @code{spacing-increment}) of space to the note.
1273
1274 For example, the following piece contains lots of half, quarter, and
1275 8th notes; the eighth note is followed by 1 note head width (NHW).
1276 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
1277
1278 @lilypond[quote,fragment,verbatim,relative=1]
1279 c2 c4. c8 c4. c8 c4. c8 c8
1280 c8 c4 c4 c4
1281 @end lilypond
1282
1283 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
1284 approximately the width of a note head, and
1285 @code{shortest-duration-space} is set to 2.0, meaning that the
1286 shortest note gets 2.4 staff space (2.0 times the
1287 @code{spacing-increment}) of horizontal space.  This space is counted
1288 from the left edge of the symbol, so the shortest notes are generally
1289 followed by one NHW of space.
1290
1291 If one would follow the above procedure exactly, then adding a single
1292 32nd note to a score that uses 8th and 16th notes, would widen up the
1293 entire score a lot.  The shortest note is no longer a 16th, but a 32nd,
1294 thus adding 1 NHW to every note.  To prevent this, the shortest
1295 duration for spacing is not the shortest note in the score, but rather
1296 the one which occurs most frequently.
1297
1298
1299 The most common shortest duration is determined as follows: in every
1300 measure, the shortest duration is determined.  The most common shortest
1301 duration is taken as the basis for the spacing, with the stipulation
1302 that this shortest duration should always be equal to or shorter than
1303 an 8th note.  The shortest duration is printed when you run
1304 @code{lilypond} with the @code{--verbose} option.
1305
1306 These durations may also be customized.  If you set the
1307 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
1308 this sets the base duration for spacing.  The maximum duration for this
1309 base (normally an 8th), is set through @code{base-shortest-duration}.
1310
1311 @funindex common-shortest-duration
1312 @funindex base-shortest-duration
1313 @funindex stem-spacing-correction
1314 @funindex spacing
1315
1316 Notes that are even shorter than the common shortest note are
1317 followed by a space that is proportional to their duration relative to
1318 the common shortest note.  So if we were to add only a few 16th notes
1319 to the example above, they would be followed by half a NHW:
1320
1321 @lilypond[quote,fragment,verbatim,relative=2]
1322 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
1323 @end lilypond
1324
1325
1326 In the introduction (see @ref{Engraving}), it was explained that stem
1327 directions influence spacing.  This is controlled with the
1328 @code{stem-spacing-correction} property in the
1329 @internalsref{NoteSpacing}, object.  These are generated for every
1330 @internalsref{Voice} context.  The @code{StaffSpacing} object
1331 (generated in @internalsref{Staff} context) contains the same property
1332 for controlling the stem/bar line spacing.  The following example shows
1333 these corrections, once with default settings, and once with
1334 exaggerated corrections:
1335
1336 @lilypond[quote,ragged-right]
1337 {
1338   c'4 e''4 e'4 b'4 |
1339   b'4 e''4 b'4 e''4|
1340   \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
1341   \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
1342   c'4 e''4 e'4 b'4 |
1343   b'4 e''4 b'4 e''4|
1344 }
1345 @end lilypond
1346
1347 Proportional notation is supported; see @ref{Proportional notation}.
1348
1349
1350 @seealso
1351
1352 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
1353 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
1354 @internalsref{SeparatingGroupSpanner}.
1355
1356
1357 @refbugs
1358
1359 There is no convenient mechanism to manually override spacing.  The
1360 following work-around may be used to insert extra space into a score.
1361 @example
1362  \once \override Score.SeparationItem #'padding = #1
1363 @end example
1364
1365 No work-around exists for decreasing the amount of space.
1366
1367
1368 @node New spacing area
1369 @subsection New spacing area
1370
1371 New sections with different spacing parameters can be started with
1372 @code{newSpacingSection}.  This is useful when there are  
1373 sections with a different notions of long and short notes.
1374
1375 In the following example, the time signature change introduces a new
1376 section, and hence the 16ths notes are spaced wider.
1377
1378 @lilypond[relative,fragment,verbatim,quote]
1379 \time 2/4
1380 c4 c8 c 
1381 c8 c c4 c16[ c c8] c4
1382 \newSpacingSection
1383 \time 4/16
1384 c16[ c c8]
1385 @end lilypond
1386
1387
1388 The @code{\newSpacingSection} command creates a new
1389 @internalsref{SpacingSpanner} object, and hence new @code{\override}s
1390 may be used in that location.
1391
1392
1393 @node Changing horizontal spacing
1394 @subsection Changing horizontal spacing
1395
1396 Horizontal spacing may be altered with the
1397 @code{base-shortest-duration} property.  Here
1398 we compare the same music; once without altering
1399 the property, and then altered.  Larger values
1400 of @code{ly:make-moment} will produce smaller
1401 music.  Note that @code{ly:make-moment} constructs
1402 a duration, so @code{1 4} is a longer duration
1403 than @code{1 16}.
1404
1405 @lilypond[relative,verbatim,line-width=12\cm]
1406 \score {
1407   \relative c'' {
1408     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
1409     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1410     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
1411     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1412   }
1413 }
1414 @end lilypond
1415
1416 @lilypond[relative,verbatim,line-width=12\cm]
1417 \score {
1418   \relative c'' {
1419     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
1420     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1421     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
1422     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1423   }
1424   \layout {
1425     \context {
1426       \Score
1427       \override SpacingSpanner
1428                 #'base-shortest-duration = #(ly:make-moment 1 16)
1429     }
1430   }
1431 }
1432 @end lilypond
1433
1434
1435 @commonprop
1436
1437 By default, spacing in tuplets depends on various non-duration
1438 factors (such as accidentals, clef changes, etc).  To disregard
1439 such symbols and force uniform equal-duration spacing, use
1440 @code{Score.SpacingSpanner #'uniform-stretching}.  This
1441 property can only be changed at the beginning of a score,
1442
1443 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1444 \new Score \with {
1445   \override SpacingSpanner #'uniform-stretching = ##t
1446 } <<
1447   \new Staff{
1448     \times 4/5 {
1449       c8 c8 c8 c8 c8
1450     }
1451     c8 c8 c8 c8
1452   }
1453   \new Staff{
1454     c8 c8 c8 c8
1455     \times 4/5 {
1456       c8 c8 c8 c8 c8
1457     }
1458   }
1459 >>
1460 @end lilypond
1461
1462
1463 When @code{strict-note-spacing} is set, notes are spaced without
1464 regard for clefs, bar lines, and grace notes,
1465
1466 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1467 \override Score.SpacingSpanner #'strict-note-spacing = ##t
1468 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c]  c32[ c32] }
1469 @end lilypond
1470
1471
1472 @node Line length
1473 @subsection Line length
1474
1475 @cindex page breaks
1476 @cindex breaking pages
1477
1478 @funindex indent
1479 @funindex line-width
1480 @funindex ragged-right
1481 @funindex ragged-last
1482
1483 @c Although line-width can be set in \layout, it should be set in paper
1484 @c block, to get page layout right.
1485 @c Setting indent in \paper block makes not much sense, but it works.
1486
1487 @c Bit verbose and vague, use examples?
1488 The most basic settings influencing the spacing are @code{indent} and
1489 @code{line-width}.  They are set in the @code{\layout} block.  They
1490 control the indentation of the first line of music, and the lengths of
1491 the lines.
1492
1493 If @code{ragged-right} is set to true in the @code{\layout} block, then
1494 systems ends at their natural horizontal length, instead of being spread
1495 horizontally to fill the whole line.  This is useful for
1496 short fragments, and for checking how tight the natural spacing is.
1497
1498 @cindex page layout
1499 @cindex vertical spacing
1500
1501 The option @code{ragged-last} is similar to @code{ragged-right}, but
1502 only affects the last line of the piece.  No restrictions are put on
1503 that line.  The result is similar to formatting text paragraphs.  In a
1504 paragraph, the last line simply takes its natural horizontal length.
1505 @c Note that for text there are several options for the last line.
1506 @c While Knuth TeX uses natural length, lead typesetters use the same
1507 @c stretch as the previous line.  eTeX uses \lastlinefit to
1508 @c interpolate between both these solutions.
1509
1510 @example
1511 \layout @{
1512   indent = #0
1513   line-width = #150
1514   ragged-last = ##t
1515 @}
1516 @end example
1517
1518
1519 @node Proportional notation
1520 @subsection Proportional notation
1521
1522 LilyPond supports proportional notation, a type of horizontal spacing
1523 in which each note consumes an amount of horizontal space exactly
1524 equivalent to its rhythmic duration. This type of proportional spacing
1525 is comparable to horizontal spacing on top of graph paper. Some late
1526 20th- and early 21st-century scores use proportional notation to
1527 clarify complex rhythmic relationships or to faciliate the placement
1528 of timelines or other graphics directly in the score.
1529
1530 LilyPond supports five different settings for proportional notation,
1531 which may be used together or alone:
1532
1533 @itemize
1534 proportionalNotationDuration
1535 uniform-stretching
1536 strict-note-spacing
1537 \remove Separating_line_group_engraver
1538 \override PaperColumn #'used = ##t
1539 @end itemize
1540
1541 In the examples that follow, we explore these five different
1542 proportional notation settings and examine how these settings interact.
1543
1544 We start with the following one-measure example, which uses classical
1545 spacing with ragged-right turned on.
1546
1547 @lilypond[quote,verbatim,ragged-right]
1548 \new Score <<
1549   \new RhythmicStaff {
1550     c'2
1551     c'16 c'16 c'16 c'16
1552     \times 4/5 {
1553       c'16 c'16 c'16 c'16 c'16
1554     }
1555   }
1556 >>
1557 @end lilypond
1558
1559 Notice that the half note which begins the measure takes up far less
1560 than half of the horizontal space of the measure.  Likewise, the
1561 sixteenth notes and sixteenth-note quintuplets (or twentieth notes)
1562 which end the measure together take up far more than half the
1563 horizontal space of the measure.
1564
1565 In classical engraving, this spacing may be exactly what we want
1566 because we can borrow horizontal space from the half note and conserve
1567 horizontal space across the measure as a whole.
1568
1569 On the other hand, if we want to insert a measured timeline or other
1570 graphic above or below our score, we need proportional notation.  We
1571 turn proportional notation on with the proportionalNotationDuration
1572 setting.
1573
1574 @lilypond[quote,verbatim,ragged-right]
1575 \new Score \with {
1576   proportionalNotationDuration = #(ly:make-moment 1 20)
1577 } <<
1578   \new RhythmicStaff {
1579     c'2
1580     c'16 c'16 c'16 c'16
1581     \times 4/5 {
1582       c'16 c'16 c'16 c'16 c'16
1583     }
1584   }
1585 >>
1586 @end lilypond
1587
1588 The half note at the beginning of the measure and the faster notes in
1589 the second half of the measure now occupy equal amounts of horizontal
1590 space.  We could place a measured timeline or graphic above or below
1591 this example.
1592
1593 The @code{proportionalNotationDuration} setting is a context setting that
1594 lives in @context{Score}.  Recall that context settings appear in one of
1595 three locations in our input file -- in a @code{\with} block, in a
1596 @code{\context} block, or directly in music entry
1597 preceeded by the @code{\set} command.  As with all
1598 context settings, users can pick which of the three different
1599 locations they would like to set @code{proportionalNotationDuration}.
1600
1601 The @code{proportionalNotationDuration} setting takes a single argument,
1602 which is the reference duration against which all music will be
1603 spaced.  The LilyPond Scheme function make-moment takes two arguments
1604 -- a numerator and denominator which together express some fraction of
1605 a whole note. The call @code{#(ly:make-moment 1 20)} therefore produces a
1606 reference duration of a twentieth note. The values
1607 @code{#(ly:make-moment 1 16)}, @code{#(ly:make-moment 1 8)}, and
1608 @code{#(ly:make-moment 3 97)} are all possible as well.
1609
1610 How do we select the right reference duration to pass to
1611 @code{proportionalNotationDuration}?  Usually by a process of trial and error,
1612 beginning with a duration close to the fastest (or smallest) duration
1613 in the piece.  Smaller reference durations space music loosely; larger
1614 reference durations space music tightly.
1615
1616 @lilypond[quote,verbatim,ragged-right]
1617 \new Score \with {
1618   proportionalNotationDuration = #(ly:make-moment 1 8)
1619 } <<
1620   \new RhythmicStaff {
1621     c'2
1622     c'16 c'16 c'16 c'16
1623     \times 4/5 {
1624       c'16 c'16 c'16 c'16 c'16
1625     }
1626   }
1627 >>
1628
1629 \new Score \with {
1630   proportionalNotationDuration = #(ly:make-moment 1 16)
1631 } <<
1632   \new RhythmicStaff {
1633     c'2
1634     c'16 c'16 c'16 c'16
1635     \times 4/5 {
1636       c'16 c'16 c'16 c'16 c'16
1637     }
1638   }
1639 >>
1640
1641 \new Score \with {
1642   proportionalNotationDuration = #(ly:make-moment 1 32)
1643 } <<
1644   \new RhythmicStaff {
1645     c'2
1646     c'16 c'16 c'16 c'16
1647     \times 4/5 {
1648       c'16 c'16 c'16 c'16 c'16
1649     }
1650   }
1651 >>
1652 @end lilypond
1653
1654 Note that too large a reference duration -- such as the eighth note,
1655 above -- spaces music too tightly and can cause notehead collisions.
1656 Note also that proportional notation in general takes up more
1657 horizontal space that does classical spacing.  Proportional spacing
1658 provides rhythmic clarity at the expense of horizontal space.
1659
1660 Next we examine how to optimally space overlapping tuplets.
1661
1662 We start by examining what happens to our original example, with
1663 classical spacing, when we add a second staff with a different type of
1664 tuplet.
1665
1666 @lilypond[quote,verbatim,ragged-right]
1667 \new Score <<
1668   \new RhythmicStaff {
1669     c'2
1670     c'16 c'16 c'16 c'16
1671     \times 4/5 {
1672       c'16 c'16 c'16 c'16 c'16
1673     }
1674   }
1675   \new RhythmicStaff {
1676     \times 8/9 {
1677       c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8
1678     }
1679   }
1680 >>
1681 @end lilypond
1682
1683 The spacing is bad because the evenly notes of the bottom staff do not
1684 stretch uniformly.  Classical engraving includes very few complex
1685 triplets and so classical engraving rules can generate this type of
1686 result.  Setting @code{proportionalNotationDuration} remedies this
1687 situation considerably.
1688
1689 @lilypond[quote,verbatim,ragged-right]
1690 \new Score \with {
1691   proportionalNotationDuration = #(ly:make-moment 1 20)
1692 } <<
1693   \new RhythmicStaff {
1694     c'2
1695     c'16 c'16 c'16 c'16
1696     \times 4/5 {
1697       c'16 c'16 c'16 c'16 c'16
1698     }
1699   }
1700   \new RhythmicStaff {
1701     \times 8/9 {
1702       c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8
1703     }
1704   }
1705 >>
1706 @end lilypond
1707
1708 But if we look very carefully we can see that notes of the second half
1709 of the 9-tuplet space ever so slightly more widely than do the notes
1710 of the first half of the 9-tuplet.  To ensure uniform stretching, we
1711 turn on @code{uniform-stretching}, which is a property of
1712 @code{SpacingSpanner}.
1713
1714 @lilypond[quote,verbatim,ragged-right]
1715 \new Score \with {
1716   proportionalNotationDuration = #(ly:make-moment 1 20)
1717   \override SpacingSpanner #'uniform-stretching = ##t
1718 } <<
1719   \new RhythmicStaff {
1720     c'2
1721     c'16 c'16 c'16 c'16
1722     \times 4/5 {
1723       c'16 c'16 c'16 c'16 c'16
1724     }
1725   }
1726   \new RhythmicStaff {
1727     \times 8/9 {
1728       c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8 c'8
1729     }
1730   }
1731 >>
1732 @end lilypond
1733
1734 Our two-staff example now spaces exactly, our rhythmic relationships
1735 are visually clear, and we can include a measured timeline or graphic
1736 if we want.
1737
1738 The @code{SpacingSpanner} is an abstract grob that lives in the
1739 @context{Score} context.  As with our settings of
1740 @code{proportionalNotationDuration},
1741 overrides to the @code{SpacingSpanner} can occur in any of three different
1742 places in our input file -- in the Score @code{\with} block, in a
1743 Score @code{\context} block, or in note entry directly.
1744
1745 There is by default only one @code{SpacingSpanner} per @code{Score}.  This
1746 means that, by default, @code{uniform-stretching} is either turned on for the
1747 entire score or turned off for the entire score.  We can, however,
1748 override this behavior and turn on different spacing features at
1749 different places in the score.  We do this with the command
1750 @code{\newSpacingSection}.  See @ref{New spacing area} for more info.
1751
1752 Next we examine the effects of the @code{Separating_line_group_engraver} and
1753 see why proportional scores frequently remove this engraver.  The following
1754 example shows that there is a small amount of @qq{preferatory} space
1755 just before the first note in each system.
1756
1757 @lilypond[quote,verbatim,ragged-right]
1758 \paper {
1759   indent = #0
1760 }
1761
1762 \new Staff {
1763   c'1
1764   \break
1765   c'1
1766 }
1767 @end lilypond
1768
1769
1770 The amount of this preferatory space is the same whether after a time
1771 signature, a key signature or a clef.  @code{Separating_line_group_engraver}
1772 is responsible for this space.  Removing @code{Separating_line_group_engraver}
1773 reduces this space to zero.
1774
1775 @lilypond[quote,verbatim,ragged-right]
1776 \paper {
1777   indent = #0
1778 }
1779
1780 \new Staff \with {
1781   \remove Separating_line_group_engraver
1782 } {
1783   c'1
1784   \break
1785   c'1
1786 }
1787 @end lilypond
1788
1789 Nonmusical elements like time signatures, key signatures, clefs and
1790 accidentals are problemmatic in proportional notation.  None of these
1791 elements has rhythmic duration.  But all of these elements consume
1792 horizontal space.  Different proportional scores approach these
1793 problems differently.
1794
1795 It may be possible to avoid spacing problems with key signatures
1796 simply by not having any.  This is a valid option since most
1797 proportional scores are contemporary music.  The same may be true
1798 of time signatures, especially for those scores
1799 that include a measured timeline or other graphic.  But these scores
1800 are exceptional and most proportional scores include at least some
1801 time signatures.  Clefs and accidentals are even more essential.
1802
1803 So what strategies exist for spacing nonmusical elements in a
1804 proportional context?  One good option is the @code{strict-note-spacing}
1805 property of @code{SpacingSpanner}.  Compare the two scores below:
1806
1807 @lilypond[quote,verbatim,ragged-right]
1808 \new Staff {
1809   \set Score.proportionalNotationDuration = #(ly:make-moment 1 16)
1810   c''8
1811   c''8
1812   c''8
1813   \clef alto
1814   d'8
1815   d'2
1816 }
1817
1818 \new Staff {
1819   \set Score.proportionalNotationDuration = #(ly:make-moment 1 16)
1820   \override Score.SpacingSpanner #'strict-note-spacing = ##t
1821   c''8
1822   c''8
1823   c''8
1824   \clef alto
1825   d'8
1826   d'2
1827 }
1828 @end lilypond
1829
1830 Both scores are proportional, but the spacing in the first score is
1831 too loose because of the clef change.  The spacing of the second score
1832 remains strict, however, because @code{strict-note-spacing} is turned
1833 on.  Turning on @code{strict-note-spacing} causes the width of time
1834 signatures, key signatures and clefs to play no part in the spacing
1835 algorithm.  Accidentals are a different matter, however.  By default, all
1836 accidentals consume a little extra space, as the following pair of
1837 scores shows.
1838
1839 @lilypond[quote,verbatim,ragged-right]
1840 \new Staff {
1841   \set Score.proportionalNotationDuration = #(ly:make-moment 1 32)
1842   c'16
1843   c'16
1844   c'16
1845   c'16
1846   c'16
1847   c'16
1848   c'16
1849   c'16
1850 }
1851
1852 \new Staff {
1853   \set Score.proportionalNotationDuration = #(ly:make-moment 1 32)
1854   c'16
1855   cis'16
1856   c'16
1857   c'16
1858   c'16
1859   c'16
1860   c'16
1861   c'16
1862 }
1863 @end lilypond
1864
1865 Both scores are proportional but the second score exhibits spacing
1866 irregularities due to accidentals.  Turning on @code{strict-note-spacing}
1867 does not work for accidentals.  Instead,
1868 we override the @code{X-extent} of all accidentals to zero and then move the
1869 accidentals to the left of the notes they modify.
1870
1871 @lilypond[quote,verbatim,ragged-right]
1872 \new Staff {
1873   \set Score.proportionalNotationDuration = #(ly:make-moment 1 32)
1874   \override Accidental #'X-extent = #'(0 . 0)
1875   \override Accidental #'extra-offset = #'(-1 . 0)
1876   c'16
1877   cis'16
1878   c'16
1879   c'16
1880   c'16
1881   c'16
1882   c'16
1883   c'16
1884 }
1885 @end lilypond
1886
1887 In addition to the settings given here, there are other settings that
1888 frequently appear in proportional scores.  These include:
1889
1890 @itemize
1891 @item @code{\override SpacingSpanner #'strict-grace-spacing = ##t}
1892 @item @code{tupletFullLength = ##t}
1893 @item @code{\override Beam #'breakable = ##t}
1894 @item @code{\override Glissando #'breakable = ##t}
1895 @item @code{\override TextSpanner #'breakable = ##t}
1896 @item @code{\remove Forbid_line_break_engraver in the Voice context}
1897 @end itemize
1898
1899 These settings space grace notes strictly, extend tuplet brackets to
1900 mark both rhythmic start- and stop-points, and allow spanning elements
1901 to break across systems and pages.  See the respective parts of the manual
1902 for these related settings.
1903
1904