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