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