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