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