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