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