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