]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/page.itely
* ly/titling-init.ly (scoreTitleMarkup): Rename (typo!?)
[lilypond.git] / Documentation / user / page.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3
4 @c A menu is needed before every deeper *section nesting of @node's; run
5 @c     M-x texinfo-all-menus-update
6 @c to automatically fill in these menus before saving changes
7
8 @node Spacing issues
9 @chapter Spacing issues
10
11 The global paper layout is determined by three factors: the page layout, the
12 line breaks, and the spacing.  These all influence each other.  The
13 choice of spacing determines how densely each system of music is set.
14 This influences where line breaks are chosen, and thus ultimately, how
15 many pages a piece of music takes.
16
17 Globally speaking, this procedure happens in four steps: first,
18 flexible distances (``springs'') are chosen, based on durations.  All
19 possible line breaking combinations are tried, and a ``badness'' score
20 is calculated for each. Then the height of each possible system is
21 estimated. Finally, a page breaking and line breaking combination is chosen
22 so that neither the horizontal nor the vertical spacing is too cramped
23 or stretched.
24
25 @menu
26 * Paper and pages::             
27 * Music layout::                
28 * Vertical spacing::            
29 * Horizontal spacing::          
30 * Breaks::                      
31 * Displaying spacing::          
32 @end menu
33
34
35 @node Paper and pages
36 @section Paper and pages
37
38 This section deals with the boundaries that define the area
39 that music can be printed inside.
40
41 @menu
42 * Paper size::                  
43 * Page formatting::             
44 @end menu
45
46
47 @node Paper size
48 @subsection Paper size
49
50 @cindex paper size
51 @cindex page size
52 @funindex papersize
53
54 To change the paper size, there are two commands,
55 @example
56 #(set-default-paper-size "a4")
57 \paper @{
58   #(set-paper-size "a4")
59 @}
60 @end example
61
62 The first command sets the size of all pages.  The second command sets the
63 size
64 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
65 block is at the top of the file, then it will apply to all pages.  If the
66 @code{\paper} block is inside a @code{\book}, then the paper size will only
67 apply to that book.
68
69 Support for the following paper sizes are included by default,
70 @code{a6}, @code{a5}, @code{a4}, @code{a3}, @code{legal}, @code{letter},
71 @code{11x17} (also known as tabloid).
72
73 Extra sizes may be added by editing the definition for
74 @code{paper-alist} in the initialization file @file{scm/paper.scm}.
75
76 @cindex orientation
77 @cindex landscape
78
79 If the symbol @code{landscape} is supplied as an argument to
80 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
81 and wider line widths will be set correspondingly.
82
83 @example
84 #(set-default-paper-size "a6" 'landscape)
85 @end example
86
87 Setting the paper size will adjust a number of @code{\paper} variables
88 (such as margins).  To use a particular paper size with altered
89 @code{\paper} variables, set the paper size before setting the variables.
90
91
92 @node Page formatting
93 @subsection Page formatting
94
95 @cindex page formatting
96 @cindex margins
97 @cindex header, page
98 @cindex footer, page
99
100 LilyPond will do page layout, set margins, and add headers and
101 footers to each page.
102
103 The default layout responds to the following settings in the
104 @code{\paper} block.
105
106 @funindex \paper
107
108 @quotation
109 @table @code
110 @funindex first-page-number
111 @item first-page-number
112 The value of the page number of the first page.  Default is@tie{}1.
113
114 @funindex printfirst-page-number
115 @item print-first-page-number
116 If set to true, will print the page number in the first page.  Default is
117 false.
118
119 @funindex print-page-number
120 @item print-page-number
121 If set to false, page numbers will not be printed. Default is true.
122
123 @funindex paper-width
124 @item paper-width
125 The width of the page. The default is taken from the current paper size,
126 see @ref{Paper size}. 
127
128 @funindex paper-height
129 @item paper-height
130 The height of the page. The default is taken from the current paper size,
131 see @ref{Paper size}. 
132
133 @funindex top-margin
134 @item top-margin
135 Margin between header and top of the page. Default is@tie{}5mm.
136
137 @funindex bottom-margin
138 @item bottom-margin
139 Margin between footer and bottom of the page. Default is@tie{}6mm.
140
141 @funindex left-margin
142 @item left-margin
143 Margin between the left side of the page and the beginning of the
144 music. Unset by default, which means that the margins is determined
145 based on the @code{paper-width} and @code{line-width} to center the
146 score on the paper. 
147
148 @funindex line-width
149 @item line-width
150 The length of the systems. Default is $code{paper-width} minus @tie{}20mm.
151
152 @funindex head-separation
153 @item head-separation
154 Distance between the top-most music system and the page header. Default
155 is@tie{}4mm. 
156
157 @funindex foot-separation
158 @item foot-separation
159 Distance between the bottom-most music system and the page
160 footer. Default is@tie{}4mm.
161
162 @funindex page-top-space
163 Distance from the top of the printable area to the center of the first
164 staff. This only works for staves which are vertically small. Big staves
165 are set with the top of their bounding box aligned to the top of the
166 printable area. Default is@tie{}12mm.
167
168 @funindex ragged-bottom
169 @item ragged-bottom
170 If set to true, systems will not be spread vertically across the page.  This
171 does not affect the last page. Default is false.
172
173 This should be set to true for pieces that have only two or three
174 systems per page, for example orchestral scores.
175
176 @funindex ragged-last-bottom
177 @item ragged-last-bottom
178 If set to false, systems will be spread vertically to fill the last
179 page. Default is true.
180
181 Pieces that amply fill two pages or more should have this set to
182 true.
183
184 @funindex system-count
185 @item system-count
186 This variable, if set, specifies into how many lines a score should be
187 broken. Unset by default.
188
189 @funindex between-system-space
190 @item between-system-space
191 This dimensions determines the distance between systems.  It is the
192 ideal distance between the center of the bottom staff of one system
193 and the center of the top staff of the next system. Default is@tie{}20mm.
194
195 Increasing this will provide a more even appearance of the page at the
196 cost of using more vertical space.
197
198 @funindex between-system-padding
199 @item between-system-padding
200 This dimension is the minimum amount of white space that will always
201 be present between the bottom-most symbol of one system, and the
202 top-most of the next system. Default is@tie{}4mm.
203
204 Increasing this will put systems whose bounding boxes almost touch
205 farther apart.
206
207
208 @funindex horizontal-shift
209 @item horizontal-shift
210 All systems (including titles and system separators) are shifted by
211 this amount to the right. Page markup, such as headers and footers are
212 not affected by this. The purpose of this variable is to make space
213 for instrument names at the left. Default is@tie{}0.
214
215 @funindex after-title-space
216 @item after-title-space
217 Amount of space between the title and the first system. Default is@tie{}5mm.
218
219 @funindex before-title-space
220 @item before-title-space
221 Amount of space between the last system of the previous piece and the
222 title of the next. Default is@tie{}10mm.
223
224 @funindex between-title-space
225 @item between-title-space
226 Amount of space between consecutive titles (e.g., the title of the
227 book and the title of a piece). Default is@tie{}2mm.
228
229 @funindex printallheaders
230 @item printallheaders
231 Setting this to #t will print all headers for each \score in a
232 \book.  Normally only the piece and opus \headers are printed.
233
234 @funindex systemSeparatorMarkup
235 @item systemSeparatorMarkup
236 This contains a markup object, which will be inserted between
237 systems.  This is often used for orchestral scores. Unset by default.
238
239 The markup command @code{\slashSeparator} is provided as a sensible
240 default,  for example
241
242 @lilypond[ragged-right]
243 \book {
244   \score {
245     \relative { c1 \break c1 }
246   }
247   \paper {
248     systemSeparatorMarkup = \slashSeparator
249   }
250 }
251 @end lilypond
252
253 @funindex blank-page-force
254 @item blank-page-force
255 The penalty for having a blank page in the middle of a
256 score. This is not used by @code{ly:optimal-breaking} since it will
257 never consider blank pages in the middle of a score. Default value
258 is 10.
259
260 @funindex blank-last-page-force
261 @item blank-last-page-force
262 The penalty for ending the score on an odd-numbered page.
263 Default value is 0.
264
265 @funindex page-spacing-weight
266 @item page-spacing-weight
267 The relative importance of page (vertical) spacing and line (horizontal)
268 spacing. High values will make page spacing more important. Default
269 value is 1.
270
271 @end table
272 @end quotation
273
274 Example:
275
276 @example
277 \paper@{
278   paper-width = 2\cm
279   top-margin = 3\cm
280   bottom-margin = 3\cm
281   ragged-last-bottom = ##t
282 @}
283 @end example
284
285 You can also define these values in Scheme.  In that case @code{mm},
286 @code{in}, @code{pt}, and @code{cm} are variables defined in
287 @file{paper-defaults.ly} with values in millimeters.  That is why the
288 value must be multiplied in the example
289
290 @example
291 \paper @{
292   #(define bottom-margin (* 2 cm))
293 @}
294 @end example
295
296 The header and footer are created by the functions @code{make-footer}
297 and @code{make-header}, defined in @code{\paper}.  The default
298 implementations are in @file{ly/@/paper@/-defaults@/.ly} and
299 @file{ly/@/titling@/-init@/.ly}.
300
301 The page layout itself is done by two functions in the
302 @code{\paper} block, @code{page-music-height} and
303 @code{page-make-stencil}.  The former tells the line-breaking algorithm
304 how much space can be spent on a page, the latter creates the actual
305 page given the system to put on it.
306
307
308 @refbugs
309
310 The option right-margin is defined but doesn't set the right margin
311 yet.  The value for the right margin has to be defined adjusting the
312 values of @code{left-margin} and @code{line-width}.
313
314 The default page header puts the page number and the @code{instrument}
315 field from the @code{\header} block on a line.
316
317 The titles (from the @code{\header@{@}} section) are treated as a
318 system, so @code{ragged-bottom} and @code{ragged-last-bottom} will
319 add space between the titles and the first system of the score.
320
321
322 @node Music layout
323 @section Music layout
324
325 @menu
326 * Setting global staff size::   
327 * Score layout::                
328 @end menu
329
330
331 @node Setting global staff size
332 @subsection Setting global staff size
333
334 @cindex font size, setting
335 @cindex staff size, setting
336 @funindex layout file
337
338 To set the global staff size, use @code{set-global-staff-size}.
339
340 @example
341 #(set-global-staff-size 14)
342 @end example
343
344 @noindent
345 This sets the global default size to 14pt staff height and scales all
346 fonts accordingly.
347
348 The Feta font provides musical symbols at eight different
349 sizes.  Each font is tuned for a different staff size: at a smaller size
350 the font becomes heavier, to match the relatively heavier staff lines.
351 The recommended font sizes are listed in the following table:
352
353 @quotation
354 @multitable @columnfractions .15 .2 .22 .2
355
356 @item @b{font name}
357 @tab @b{staff height (pt)}
358 @tab @b{staff height (mm)}
359 @tab @b{use}
360
361 @item feta11
362 @tab 11.22
363 @tab 3.9
364 @tab pocket scores
365
366 @item feta13
367 @tab 12.60
368 @tab 4.4
369 @tab
370
371 @item feta14
372 @tab 14.14
373 @tab 5.0
374 @tab
375
376 @item feta16
377 @tab 15.87
378 @tab 5.6
379 @tab
380
381 @item feta18
382 @tab 17.82
383 @tab 6.3
384 @tab song books
385
386 @item feta20
387 @tab 20
388 @tab 7.0
389 @tab standard parts
390
391 @item feta23
392 @tab 22.45
393 @tab 7.9
394 @tab
395
396 @item feta26
397 @tab 25.2
398 @tab 8.9
399 @tab
400 @c modern rental material?
401
402 @end multitable
403 @end quotation
404
405 These fonts are available in any sizes.  The context property
406 @code{fontSize} and the layout property @code{staff-space} (in
407 @internalsref{StaffSymbol}) can be used to tune the size for individual
408 staves.  The sizes of individual staves are relative to the global size.
409
410 @example
411
412 @end example
413
414 @seealso
415
416 This manual: @ref{Selecting notation font size}.
417
418
419 @node Score layout
420 @subsection Score layout
421
422 @funindex \layout
423
424 While @code{\paper} contains settings that relate to the page formatting
425 of the whole document, @code{\layout} contains settings for score-specific
426 layout.
427
428 @example
429 \layout @{
430   indent = 2.0\cm
431   \context @{ \Staff
432     \override VerticalAxisGroup #'minimum-Y-extent = #'(-6 . 6)
433   @}
434   \context @{ \Voice
435     \override TextScript #'padding = #1.0
436     \override Glissando #'thickness = #3
437   @}
438 @}
439 @end example
440
441
442 @seealso
443
444 This manual: @ref{Changing context default settings}
445
446
447 @node Vertical spacing
448 @section Vertical spacing
449
450 @cindex vertical spacing
451 @cindex spacing, vertical
452
453 Vertical spacing is controlled by three things: the amount of
454 space available (i.e., paper size and margins), the amount of
455 space between systems, and the amount of space between
456 staves inside a system.
457
458 @menu
459 * Vertical spacing inside a system::  
460 * Vertical spacing of piano staves::  
461 * Vertical spacing between systems::  
462 * Controlling spacing of individual systems::  
463 @end menu
464
465
466 @node Vertical spacing inside a system
467 @subsection Vertical spacing inside a system
468
469 @cindex distance between staves
470 @cindex staff distance
471 @cindex space between staves
472 @cindex space inside systems
473
474 The height of each system is determined automatically.  To prevent
475 staves from bumping into each other, some minimum distances are set.
476 By changing these, you can put staves closer together.  This
477 reduces the amount of space each system requires, and may result
478 in having more systems per page.
479
480 Normally staves are stacked vertically.  To make staves maintain a
481 distance, their vertical size is padded.  This is done with the
482 property @code{minimum-Y-extent}.  When applied to a
483 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
484 line, such as a staff or a line of lyrics.  @code{minimum-Y-extent}
485 takes a pair of numbers, so
486 if you want to make it smaller than its default @code{#'(-4 . 4)}
487 then you could set
488
489 @example
490 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
491 @end example
492
493 @noindent
494 This sets the vertical size of the current staff to 3 staff spaces on
495 either side of the center staff line.  The value @code{(-3 . 3)} is
496 interpreted as an interval, where the center line is the 0, so the
497 first number is generally negative.  The numbers need not match;
498 for example, the staff can be made larger at the bottom by setting
499 it to @code{(-6 . 4)}.
500
501
502 @seealso
503
504 Internals: Vertical alignment of staves is handled by the
505 @internalsref{VerticalAlignment} object. The context parameters
506 specifying the vertical extent are described in connection with
507 the @internalsref{Axis_group_engraver}.
508
509 Example files: @inputfileref{input/regression/,page-spacing.ly},
510 @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
511
512
513 @node Vertical spacing of piano staves
514 @subsection Vertical spacing of piano staves
515
516 The distance between staves of a @internalsref{PianoStaff} cannot be
517 computed during formatting.  Rather, to make cross-staff beaming work
518 correctly, that distance has to be fixed beforehand.
519
520 The distance of staves in a @code{PianoStaff} is set with the
521 @code{forced-distance} property of the
522 @internalsref{VerticalAlignment} object, created in
523 @internalsref{PianoStaff}.
524
525 It can be adjusted as follows
526 @example
527 \new PianoStaff \with @{
528   \override VerticalAlignment #'forced-distance = #7
529 @} @{
530   ...
531 @}
532 @end example
533
534 @noindent
535 This would bring the staves together at a distance of 7 staff spaces,
536 measured from the center line of each staff.
537
538 The difference is demonstrated in the following example,
539 @lilypond[quote,verbatim]
540 \relative c'' <<
541   \new PianoStaff \with {
542     \override VerticalAlignment #'forced-distance = #7
543   } <<
544     \new Staff { c1 }
545     \new Staff { c }
546   >>
547   \new PianoStaff <<
548     \new Staff { c }
549     \new Staff { c }
550   >>
551 >>
552 @end lilypond
553
554
555 @seealso
556
557 Example files: @inputfileref{input/regression/,alignment-vertical-spacing.ly}.
558
559
560 @node Vertical spacing between systems
561 @subsection Vertical spacing between systems
562
563 Space between systems are controlled by four @code{\paper} variables,
564
565 @example
566 \paper @{
567   between-system-space = 1.5\cm
568   between-system-padding = #1
569   ragged-bottom=##f
570   ragged-last-bottom=##f
571 @}
572 @end example
573
574
575 @node Controlling spacing of individual systems
576 @subsection Controlling spacing of individual systems
577
578 It is also possible to change the distance between for each system
579 individually.  This is done by including the command
580
581 @example
582 \overrideProperty
583 #"Score.NonMusicalPaperColumn"
584 #'line-break-system-details
585 #'((fixed-alignment-extra-space . 15))
586 @end example
587
588 @noindent
589 at the line break before the system to be changed. The distance
590 @code{15} is distributed over all staves that have a fixed distance
591 alignment.  For example,
592
593 @lilypond[ragged-right, fragment, relative=2, staffsize=13]
594 \new PianoStaff <<
595   \new Staff {
596     c1\break
597   
598     \overrideProperty
599     #"Score.NonMusicalPaperColumn"
600     #'line-break-system-details
601     #'((fixed-alignment-extra-space . 15))
602
603     c\break
604   }
605   \new Staff { c c }
606 >>
607 @end lilypond
608
609 The distance for @code{fixed-alignment-extra-space} may also be
610 negative.
611
612
613
614 @node Horizontal spacing
615 @section Horizontal Spacing
616
617 @cindex horizontal spacing
618 @cindex spacing, horizontal
619
620 @menu
621 * Horizontal spacing overview::  
622 * New spacing area::            
623 * Changing horizontal spacing::  
624 * Line length::                 
625 @end menu
626
627
628 @node Horizontal spacing overview
629 @subsection Horizontal spacing overview
630
631 The spacing engine translates differences in durations into stretchable
632 distances (``springs'') of differring lengths.  Longer durations get
633 more space, shorter durations get less.  The shortest durations get a
634 fixed amount of space (which is controlled by
635 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
636 object).  The longer the duration, the more space it gets: doubling a
637 duration adds a fixed amount (this amount is controlled by
638 @code{spacing-increment}) of space to the note.
639
640 For example, the following piece contains lots of half, quarter, and
641 8th notes; the eighth note is followed by 1 note head width (NHW).
642 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
643
644 @lilypond[quote,fragment,verbatim,relative=1]
645 c2 c4. c8 c4. c8 c4. c8 c8
646 c8 c4 c4 c4
647 @end lilypond
648
649 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
650 approximately the width of a note head, and
651 @code{shortest-duration-space} is set to 2.0, meaning that the
652 shortest note gets 2.4 staff space (2.0 times the
653 @code{spacing-increment}) of horizontal space.  This space is counted
654 from the left edge of the symbol, so the shortest notes are generally
655 followed by one NHW of space.
656
657 If one would follow the above procedure exactly, then adding a single
658 32nd note to a score that uses 8th and 16th notes, would widen up the
659 entire score a lot.  The shortest note is no longer a 16th, but a 32nd,
660 thus adding 1 NHW to every note.  To prevent this, the shortest
661 duration for spacing is not the shortest note in the score, but rather
662 the one which occurs most frequently.
663
664
665 The most common shortest duration is determined as follows: in every
666 measure, the shortest duration is determined.  The most common shortest
667 duration is taken as the basis for the spacing, with the stipulation
668 that this shortest duration should always be equal to or shorter than
669 an 8th note.  The shortest duration is printed when you run
670 @code{lilypond} with the @code{--verbose} option.
671
672 These durations may also be customized.  If you set the
673 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
674 this sets the base duration for spacing.  The maximum duration for this
675 base (normally an 8th), is set through @code{base-shortest-duration}.
676
677 @funindex common-shortest-duration
678 @funindex base-shortest-duration
679 @funindex stem-spacing-correction
680 @funindex spacing
681
682 Notes that are even shorter than the common shortest note are
683 followed by a space that is proportional to their duration relative to
684 the common shortest note.  So if we were to add only a few 16th notes
685 to the example above, they would be followed by half a NHW:
686
687 @lilypond[quote,fragment,verbatim,relative=2]
688 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
689 @end lilypond
690
691
692 In the introduction (see @ref{Engraving}), it was explained that stem
693 directions influence spacing.  This is controlled with the
694 @code{stem-spacing-correction} property in the
695 @internalsref{NoteSpacing}, object.  These are generated for every
696 @internalsref{Voice} context.  The @code{StaffSpacing} object
697 (generated in @internalsref{Staff} context) contains the same property
698 for controlling the stem/bar line spacing.  The following example shows
699 these corrections, once with default settings, and once with
700 exaggerated corrections:
701
702 @lilypond[quote,ragged-right]
703 {
704   c'4 e''4 e'4 b'4 |
705   b'4 e''4 b'4 e''4|
706   \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
707   \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
708   c'4 e''4 e'4 b'4 |
709   b'4 e''4 b'4 e''4|
710 }
711 @end lilypond
712
713 Proportional notation is supported; see @ref{Proportional notation}.
714
715
716 @seealso
717
718 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
719 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
720 @internalsref{SeparatingGroupSpanner}.
721
722
723 @refbugs
724
725 There is no convenient mechanism to manually override spacing.  The
726 following work-around may be used to insert extra space into a score.
727 @example
728  \once \override Score.SeparationItem #'padding = #1
729 @end example
730
731 No work-around exists for decreasing the amount of space.
732
733
734 @node New spacing area
735 @subsection New spacing area
736
737 New sections with different spacing parameters can be started with
738 @code{newSpacingSection}.  This is useful when there are  
739 sections with a different notions of long and short notes.
740
741 In the following example, the time signature change introduces a new
742 section, and hence the 16ths notes are spaced wider.
743
744 @lilypond[relative,fragment,verbatim,quote]
745 \time 2/4
746 c4 c8 c 
747 c8 c c4 c16[ c c8] c4
748 \newSpacingSection
749 \time 4/16
750 c16[ c c8]
751 @end lilypond
752
753
754 @node Changing horizontal spacing
755 @subsection Changing horizontal spacing
756
757 Horizontal spacing may be altered with the
758 @code{base-shortest-duration} property.  Here
759 we compare the same music; once without altering
760 the property, and then altered.  Larger values
761 of @code{ly:make-moment} will produce smaller
762 music.
763
764 @lilypond[relative,verbatim,line-width=12\cm]
765 \score {
766   \relative c'' {
767     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
768     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
769     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
770     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
771   }
772 }
773 @end lilypond
774
775 @lilypond[relative,verbatim,line-width=12\cm]
776 \score {
777   \relative c'' {
778     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
779     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
780     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
781     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
782   }
783   \layout {
784     \context {
785       \Score
786       \override SpacingSpanner
787                 #'base-shortest-duration = #(ly:make-moment 1 4)
788     }
789   }
790 }
791 @end lilypond
792
793
794 @commonprop
795
796 By default, spacing in tuplets depends on various non-duration
797 factors (such as accidentals, clef changes, etc).  To disregard
798 such symbols and force uniform equal-duration spacing, use
799 @code{Score.SpacingSpanner #'uniform-stretching}.  This
800 property can only be changed at the beginning of a score,
801
802 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
803 \new Score \with {
804   \override SpacingSpanner #'uniform-stretching = ##t
805 } <<
806   \new Staff{
807     \times 4/5 {
808       c8 c8 c8 c8 c8
809     }
810     c8 c8 c8 c8
811   }
812   \new Staff{
813     c8 c8 c8 c8
814     \times 4/5 {
815       c8 c8 c8 c8 c8
816     }
817   }
818 >>
819 @end lilypond
820
821
822 When @code{strict-note-spacing} is set, notes are spaced without
823 regard for clefs, bar lines, and grace notes,
824
825 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
826 \override Score.SpacingSpanner #'strict-note-spacing = ##t
827 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c]  c32[ c32] }
828 @end lilypond
829
830
831 @node Line length
832 @subsection Line length
833
834 @cindex page breaks
835 @cindex breaking pages
836
837 @funindex indent
838 @funindex line-width
839 @funindex ragged-right
840 @funindex ragged-last
841
842 @c Although line-width can be set in \layout, it should be set in paper
843 @c block, to get page layout right.
844 @c Setting indent in \paper block makes not much sense, but it works.
845
846 @c Bit verbose and vague, use examples?
847 The most basic settings influencing the spacing are @code{indent} and
848 @code{line-width}.  They are set in the @code{\layout} block.  They
849 control the indentation of the first line of music, and the lengths of
850 the lines.
851
852 If @code{ragged-right} is set to true in the @code{\layout} block, then
853 systems ends at their natural horizontal length, instead of being spread
854 horizontally to fill the whole line.  This is useful for
855 short fragments, and for checking how tight the natural spacing is.
856
857 @cindex page layout
858 @cindex vertical spacing
859
860 The option @code{ragged-last} is similar to @code{ragged-right}, but
861 only affects the last line of the piece.  No restrictions are put on
862 that line.  The result is similar to formatting text paragraphs.  In a
863 paragraph, the last line simply takes its natural horizontal length.
864 @c Note that for text there are several options for the last line.
865 @c While Knuth TeX uses natural length, lead typesetters use the same
866 @c stretch as the previous line.  eTeX uses \lastlinefit to
867 @c interpolate between both these solutions.
868
869 @example
870 \layout @{
871   indent = #0
872   line-width = #150
873   ragged-last = ##t
874 @}
875 @end example
876
877
878 @node Breaks
879 @section Breaks
880
881 @menu
882 * Line breaking::               
883 * Page breaking::               
884 * Optimal page breaking::       
885 * Optimal page turning::        
886 @end menu
887
888 @node Line breaking
889 @subsection Line breaking
890
891 @cindex line breaks
892 @cindex breaking lines
893
894 Line breaks are normally computed automatically.  They are chosen so
895 that lines look neither cramped nor loose, and that consecutive lines
896 have similar density.
897
898 Occasionally you might want to override the automatic breaks; you can
899 do this by specifying @code{\break}.  This will force a line break at
900 this point.  Line breaks can only occur at places where there are bar
901 lines.  If you want to have a line break where there is no bar line,
902 you can force an invisible bar line by entering @code{\bar
903 ""}.  Similarly, @code{\noBreak} forbids a line break at a
904 point.
905
906
907 @cindex regular line breaks
908 @cindex four bar music.
909
910 For line breaks at regular intervals use @code{\break} separated by
911 skips and repeated with @code{\repeat}:
912 @example
913 << \repeat unfold 7 @{
914          s1 \noBreak s1 \noBreak
915          s1 \noBreak s1 \break @}
916    @emph{the real music}
917 >>
918 @end example
919
920 @noindent
921 This makes the following 28 measures (assuming 4/4 time) be broken every
922 4 measures, and only there.
923
924 @refcommands
925
926 @code{\break}, and @code{\noBreak}.
927 @funindex \break
928 @funindex \noBreak
929
930 @seealso
931
932 Internals: @internalsref{LineBreakEvent}.
933
934 A linebreaking configuration can now be saved as a @code{.ly} file
935 automatically.  This allows vertical alignments to be stretched to
936 fit pages in a second formatting run.  This is fairly new and
937 complicated; see @inputfileref{input/regression/,page-layout-twopass.ly}
938 for details.
939
940 @refbugs
941
942 Line breaks can only occur if there is a ``proper'' bar line.  A note
943 which is hanging over a bar line is not proper, such as
944
945 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
946 c4 c2 c2 \break   % this does nothing
947 c2 c4 |           % a break here would work
948 c4 c2 c4 ~ \break % as does this break
949 c4 c2 c4
950 @end lilypond
951
952
953 @node Page breaking
954 @subsection Page breaking
955
956 The default page breaking may be overriden by inserting
957 @code{\pageBreak} or @code{\noPageBreak} commands.  These commands are
958 analogous to @code{\break} and @code{\noBreak}.  They should be
959 inserted at a bar line.  These commands force and forbid a page-break
960 from happening.  Of course, the @code{\pageBreak} command also forces
961 a line break.
962
963 Page breaks are computed by the @code{page-breaking} function.
964 LilyPond provides two algorithms for computing page
965 breaks, @code{ly:optimal-breaking} and @code{ly:page-turn-breaking}. The
966 default is @code{ly:optimal-breaking}, but the value can be changed in
967 the @code{\paper} block:
968
969 @example
970 \paper@{
971   #(define page-breaking ly:page-turn-breaking)
972 @}
973 @end example
974
975 The old page breaking algorithm is called
976 @code{optimal-page-breaks}. If you are having trouble with the new page
977 breakers, you can enable the old one as a workaround.
978
979 @refcommands
980
981 @funindex \pageBreak
982 @code{\pageBreak}
983 @funindex \noPageBreak
984 @code{\noPageBreak}
985
986
987 @node Optimal page breaking
988 @subsection Optimal page breaking
989
990 @funindex ly:optimal-breaking
991
992 The @code{ly:optimal-breaking} function is LilyPond's default method of
993 determining page breaks. It attempts to find a page breaking that minimizes
994 cramping and stretching, both horizontally and vertically. Unlike
995 @code{ly:page-turn-breaking}, it has no concept of page turns.
996
997
998 @node Optimal page turning
999 @subsection Optimal page turning
1000
1001 @funindex ly:page-turn-breaking
1002
1003 Often it is necessary to find a page breaking configuration so that there is
1004 a rest at the end of every second page. This way, the musician can turn the
1005 page without having to miss notes. The @code{ly:page-turn-breaking} function
1006 attempts to find a page breaking minimizing cramping and stretching, but with
1007 the additional restriction that it is only allowed to introduce page turns
1008 in specified places.
1009
1010 There are two steps to using this page breaking function. First, you must
1011 enable it in the @code{\paper} block. Then, you must tell the function
1012 where you would like to allow page breaks.
1013
1014 There are two ways to achieve the second step. First, you can specify each
1015 potential page turn manually, by inserting @code{\allowPageTurn} into your
1016 input file at the appropriate places.
1017
1018 If this is too tedious, you can add a @code{Page_turn_engraver} to a Staff or
1019 Voice context. The @code{Page_turn_engraver} will scan the context for
1020 sections without notes (note that it does not scan for rests; it scans for
1021 the absence of notes. This is so that single-staff polyphony with rests in one
1022 of the parts does not throw off the @code{Page_turn_engraver}). When it finds
1023 a sufficiently long section without notes, the @code{Page_turn_engraver} will
1024 insert an @code{\allowPageTurn} at the final barline in that section, unless
1025 there is a ``special'' barline (such as a double bar), in which case the
1026 @code{\allowPageTurn} will be inserted at the final ``special'' barline in
1027 the section.
1028
1029 @funindex minimumPageTurnLength
1030 The @code{Page_turn_engraver} reads the context property
1031 @code{minimumPageTurnLength} to determine how long a note-free section must
1032 be before a page turn is considered. The default value for
1033 @code{minimumPageTurnLength} is @code{#(ly:make-moment 1 1)}. If you want
1034 to disable page turns, you can set it to something very large.
1035
1036 @example
1037 \new Staff \with @{ \consists "Page_turn_engraver" @}
1038 @{
1039   a4 b c d |
1040   R1 | % a page turn will be allowed here
1041   a4 b c d |
1042   \set Staff.minimumPageTurnLength = #(ly:make-moment 5 2)
1043   R1 | % a page turn will not be allowed here
1044   a4 b r2 |
1045   R1*2 | % a page turn will be allowed here
1046   a1
1047 @}
1048 @end example
1049
1050 @funindex minimumRepeatLengthForPageTurn
1051 The @code{Page_turn_engraver} detects volta repeats. It will only allow a page
1052 turn during the repeat if there is enough time at the beginning and end of the
1053 repeat to turn the page back. The @code{Page_turn_engraver} can also disable
1054 page turns if the repeat is very short. If you set the context property
1055 @code{minimumRepeatLengthForPageTurn} then the @code{Page_turn_engraver} will
1056 only allow turns in repeats whose duration is longer than this value.
1057
1058 @refbugs
1059
1060 The @code{Page_turn_engraver} does not respect time-scaled music. For example, the
1061 following example does not behave as expected:
1062
1063 @example
1064 \new Staff \with @{ \consists "Page_turn_engraver" @}
1065 @{
1066   a4 b c d |
1067   R1 | % a page turn will be allowed here
1068   a4 b \times 2/3 @{c d e@} |
1069   R1 | % a page turn will NOT be allowed here
1070   a1
1071 @}
1072 @end example
1073
1074 There should only be one @code{Page_turn_engraver} in a score. If there is more
1075 than one, they will interfere with each other.
1076
1077
1078 @node Displaying spacing
1079 @section Displaying spacing
1080
1081 @funindex annotate-spacing
1082 @cindex Spacing, display of properties
1083
1084 To graphically display the dimensions of vertical properties
1085 that may be altered for page formatting, use
1086
1087 @lilypond[verbatim]
1088 \paper { annotate-spacing = ##t }
1089 { c4 }
1090 @end lilypond
1091
1092 @noindent
1093 @c  FIXME: really bad vagueness due to bug in annotate-spacing.  -gp
1094 Some unit dimensions are measured in staff spaces, while others
1095 are measured in millimeters.
1096 The pairs
1097 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
1098 @var{b} the upper edge of the interval.
1099
1100