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