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