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