]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/spacing.itely
Remove info about properties that have (or will) be removed.
[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 * Breaks::                      
35 * Vertical spacing::            
36 * Horizontal spacing::          
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 Breaks
475 @section Breaks
476
477 @menu
478 * Line breaking::               
479 * Page breaking::               
480 * Optimal page breaking::       
481 * Optimal page turning::        
482 * Explicit breaks::             
483 * Using an extra voice for breaks::  
484 @end menu
485
486 @node Line breaking
487 @subsection Line breaking
488
489 @cindex line breaks
490 @cindex breaking lines
491
492 Line breaks are normally computed automatically.  They are chosen so
493 that lines look neither cramped nor loose, and that consecutive lines
494 have similar density.
495
496 Occasionally you might want to override the automatic breaks; you can
497 do this by specifying @code{\break}.  This will force a line break at
498 this point.  Line breaks can only occur at places where there are bar
499 lines.  If you want to have a line break where there is no bar line,
500 you can force an invisible bar line by entering @code{\bar
501 ""}.  Similarly, @code{\noBreak} forbids a line break at a
502 point.
503
504
505 @cindex regular line breaks
506 @cindex four bar music.
507
508 For line breaks at regular intervals use @code{\break} separated by
509 skips and repeated with @code{\repeat}:
510 @example
511 << \repeat unfold 7 @{
512          s1 \noBreak s1 \noBreak
513          s1 \noBreak s1 \break @}
514    @emph{the real music}
515 >>
516 @end example
517
518 @noindent
519 This makes the following 28 measures (assuming 4/4 time) be broken every
520 4 measures, and only there.
521
522 @refcommands
523
524 @code{\break}, and @code{\noBreak}.
525 @funindex \break
526 @funindex \noBreak
527
528 @seealso
529
530 Internals: @internalsref{LineBreakEvent}.
531
532 A linebreaking configuration can now be saved as a @code{.ly} file
533 automatically.  This allows vertical alignments to be stretched to
534 fit pages in a second formatting run.  This is fairly new and
535 complicated.  More details are available in
536 @lsrdir{spacing}
537
538
539 @refbugs
540
541 Line breaks can only occur if there is a @q{proper} bar line.  A note
542 which is hanging over a bar line is not proper, such as
543
544 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
545 c4 c2 c2 \break   % this does nothing
546 c2 c4 |           % a break here would work
547 c4 c2 c4 ~ \break % as does this break
548 c4 c2 c4
549 @end lilypond
550
551 To allow line breaks on such bar lines, the
552 @code{Forbid_line_break_engraver} can be removed from @code{Voice}
553 context, like so
554
555
556 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
557 \new Voice \with {
558   \remove "Forbid_line_break_engraver"
559 } {
560   c4 c2 c2 \break   % now the break is allowed
561   c2 c4
562 }
563 @end lilypond
564
565
566
567 @node Page breaking
568 @subsection Page breaking
569
570 The default page breaking may be overriden by inserting
571 @code{\pageBreak} or @code{\noPageBreak} commands.  These commands are
572 analogous to @code{\break} and @code{\noBreak}.  They should be
573 inserted at a bar line.  These commands force and forbid a page-break
574 from happening.  Of course, the @code{\pageBreak} command also forces
575 a line break.
576
577 Page breaks are computed by the @code{page-breaking} function.
578 LilyPond provides two algorithms for computing page
579 breaks, @code{ly:optimal-breaking} and @code{ly:page-turn-breaking}. The
580 default is @code{ly:optimal-breaking}, but the value can be changed in
581 the @code{\paper} block:
582
583 @example
584 \paper@{
585   #(define page-breaking ly:page-turn-breaking)
586 @}
587 @end example
588
589 The old page breaking algorithm is called
590 @code{optimal-page-breaks}. If you are having trouble with the new page
591 breakers, you can enable the old one as a workaround.
592
593 @refcommands
594
595 @funindex \pageBreak
596 @code{\pageBreak}
597 @funindex \noPageBreak
598 @code{\noPageBreak}
599
600
601 @node Optimal page breaking
602 @subsection Optimal page breaking
603
604 @funindex ly:optimal-breaking
605
606 The @code{ly:optimal-breaking} function is LilyPond's default method of
607 determining page breaks. It attempts to find a page breaking that minimizes
608 cramping and stretching, both horizontally and vertically. Unlike
609 @code{ly:page-turn-breaking}, it has no concept of page turns.
610
611
612 @node Optimal page turning
613 @subsection Optimal page turning
614
615 @funindex ly:page-turn-breaking
616
617 Often it is necessary to find a page breaking configuration so that there is
618 a rest at the end of every second page. This way, the musician can turn the
619 page without having to miss notes. The @code{ly:page-turn-breaking} function
620 attempts to find a page breaking minimizing cramping and stretching, but with
621 the additional restriction that it is only allowed to introduce page turns
622 in specified places.
623
624 There are two steps to using this page breaking function. First, you must
625 enable it in the @code{\paper} block. Then, you must tell the function
626 where you would like to allow page breaks.
627
628 There are two ways to achieve the second step. First, you can specify each
629 potential page turn manually, by inserting @code{\allowPageTurn} into your
630 input file at the appropriate places.
631
632 If this is too tedious, you can add a @code{Page_turn_engraver} to a Staff or
633 Voice context. The @code{Page_turn_engraver} will scan the context for
634 sections without notes (note that it does not scan for rests; it scans for
635 the absence of notes. This is so that single-staff polyphony with rests in one
636 of the parts does not throw off the @code{Page_turn_engraver}). When it finds
637 a sufficiently long section without notes, the @code{Page_turn_engraver} will
638 insert an @code{\allowPageTurn} at the final barline in that section, unless
639 there is a @q{special} barline (such as a double bar), in which case the
640 @code{\allowPageTurn} will be inserted at the final @q{special} barline in
641 the section.
642
643 @funindex minimumPageTurnLength
644 The @code{Page_turn_engraver} reads the context property
645 @code{minimumPageTurnLength} to determine how long a note-free section must
646 be before a page turn is considered. The default value for
647 @code{minimumPageTurnLength} is @code{#(ly:make-moment 1 1)}. If you want
648 to disable page turns, you can set it to something very large.
649
650 @example
651 \new Staff \with @{ \consists "Page_turn_engraver" @}
652 @{
653   a4 b c d |
654   R1 | % a page turn will be allowed here
655   a4 b c d |
656   \set Staff.minimumPageTurnLength = #(ly:make-moment 5 2)
657   R1 | % a page turn will not be allowed here
658   a4 b r2 |
659   R1*2 | % a page turn will be allowed here
660   a1
661 @}
662 @end example
663
664 @funindex minimumRepeatLengthForPageTurn
665 The @code{Page_turn_engraver} detects volta repeats. It will only allow a page
666 turn during the repeat if there is enough time at the beginning and end of the
667 repeat to turn the page back. The @code{Page_turn_engraver} can also disable
668 page turns if the repeat is very short. If you set the context property
669 @code{minimumRepeatLengthForPageTurn} then the @code{Page_turn_engraver} will
670 only allow turns in repeats whose duration is longer than this value.
671
672 @refbugs
673
674 There should only be one @code{Page_turn_engraver} in a score. If there is more
675 than one, they will interfere with each other.
676
677
678 @node Explicit breaks
679 @subsection Explicit breaks
680
681 Lily sometimes rejects explicit @code{\break} and @code{\pageBreak}
682 commands.  There are two commands to override this behavior:
683
684 @example
685 \override NonMusicalPaperColumn #'line-break-permission = ##f
686 \override NonMusicalPaperColumn #'page-break-permission = ##f
687 @end example
688
689 When @code{line-break-permission} is overriden to false, Lily will insert
690 line breaks at explicit @code{\break} commands and nowhere else.  When
691 @code{page-break-permission} is overriden to false, Lily will insert
692 page breaks at explicit @code{\pageBreak} commands and nowhere else.
693
694 @lilypond[quote,verbatim]
695 \paper {
696   indent = #0
697   ragged-right = ##t
698   ragged-bottom = ##t
699 }
700
701 \score {
702   \new Score \with {
703     \override NonMusicalPaperColumn #'line-break-permission = ##f
704     \override NonMusicalPaperColumn #'page-break-permission = ##f
705   } {
706     \new Staff {
707       \repeat unfold 2 { c'8 c'8 c'8 c'8 } \break
708       \repeat unfold 4 { c'8 c'8 c'8 c'8 } \break
709       \repeat unfold 6 { c'8 c'8 c'8 c'8 } \break
710       \repeat unfold 8 { c'8 c'8 c'8 c'8 } \pageBreak
711       \repeat unfold 8 { c'8 c'8 c'8 c'8 } \break
712       \repeat unfold 6 { c'8 c'8 c'8 c'8 } \break
713       \repeat unfold 4 { c'8 c'8 c'8 c'8 } \break
714       \repeat unfold 2 { c'8 c'8 c'8 c'8 }
715     }
716   }
717 }
718 @end lilypond
719
720
721 @node Using an extra voice for breaks
722 @subsection Using an extra voice for breaks
723
724 Line- and page-breaking information usually appears within note entry directly.
725
726 @example
727 \new Score @{
728   \new Staff @{
729     \repeat unfold 2 @{ c'4 c'4 c'4 c'4 @}
730     \break
731     \repeat unfold 3 @{ c'4 c'4 c'4 c'4 @}
732   @}
733 @}
734 @end example
735
736 This makes @code{\break} and @code{\pageBreak} commands easy to enter but mixes
737 music entry with information that specifies how music should lay out
738 on the page.  You can keep music entry and line- and page-breaking
739 information in two separate places by introducing an extra voice to 
740 contain the  breaks.  This extra voice
741 contains only skips together with @code{\break}, @code{pageBreak} and other
742 breaking layout information.
743
744 @lilypond[quote,verbatim]
745 \new Score {
746   \new Staff <<
747      \new Voice {
748         s1 * 2 \break
749         s1 * 3 \break
750         s1 * 6 \break
751         s1 * 5 \break
752      }
753      \new Voice {
754         \repeat unfold 2 { c'4 c'4 c'4 c'4 }
755         \repeat unfold 3 { c'4 c'4 c'4 c'4 }
756         \repeat unfold 6 { c'4 c'4 c'4 c'4 }
757         \repeat unfold 5 { c'4 c'4 c'4 c'4 }
758      }
759   >>
760 }
761 @end lilypond
762
763 This pattern becomes especially helpful when overriding
764 @code{line-break-system-details} and the other useful but long properties of
765 @code{NonMusicalPaperColumnGrob}, as explained in @ref{Vertical spacing}.
766
767 @lilypond[quote,verbatim]
768 \new Score {
769   \new Staff <<
770      \new Voice {
771
772         \overrideProperty "Score.NonMusicalPaperColumn"
773         #'line-break-system-details #'((Y-offset . 0))
774         s1 * 2 \break
775
776         \overrideProperty "Score.NonMusicalPaperColumn"
777         #'line-break-system-details #'((Y-offset . 35))
778         s1 * 3 \break
779
780         \overrideProperty "Score.NonMusicalPaperColumn"
781         #'line-break-system-details #'((Y-offset . 70))
782         s1 * 6 \break
783
784         \overrideProperty "Score.NonMusicalPaperColumn"
785         #'line-break-system-details #'((Y-offset . 105))
786         s1 * 5 \break
787      }
788      \new Voice {
789         \repeat unfold 2 { c'4 c'4 c'4 c'4 }
790         \repeat unfold 3 { c'4 c'4 c'4 c'4 }
791         \repeat unfold 6 { c'4 c'4 c'4 c'4 }
792         \repeat unfold 5 { c'4 c'4 c'4 c'4 }
793      }
794   >>
795 }
796 @end lilypond
797
798
799 @node Vertical spacing
800 @section Vertical spacing
801
802 @cindex vertical spacing
803 @cindex spacing, vertical
804
805 Vertical spacing is controlled by three things: the amount of
806 space available (i.e., paper size and margins), the amount of
807 space between systems, and the amount of space between
808 staves inside a system.
809
810 @menu
811 * Vertical spacing inside a system::  
812 * Vertical spacing between systems::  
813 * Explicit staff and system positioning::  
814 * Two-pass vertical spacing::   
815 @end menu
816
817
818 @node Vertical spacing inside a system
819 @subsection Vertical spacing inside a system
820
821 @cindex distance between staves
822 @cindex staff distance
823 @cindex space between staves
824 @cindex space inside systems
825
826 The height of each system is determined automatically.  To prevent
827 staves from bumping into each other, some minimum distances are set.
828 By changing these, you can put staves closer together.  This
829 reduces the amount of space each system requires, and may result
830 in having more systems per page.
831
832 Normally staves are stacked vertically.  To make staves maintain a
833 distance, their vertical size is padded.  This is done with the
834 property @code{minimum-Y-extent}.  When applied to a
835 @internalsref{VerticalAxisGroup}, it controls the size of a horizontal
836 line, such as a staff or a line of lyrics.  @code{minimum-Y-extent}
837 takes a pair of numbers, so
838 if you want to make it smaller than its default @code{#'(-4 . 4)}
839 then you could set
840
841 @example
842 \override Staff.VerticalAxisGroup #'minimum-Y-extent = #'(-3 . 3)
843 @end example
844
845 @noindent
846 This sets the vertical size of the current staff to 3 staff spaces on
847 either side of the center staff line.  The value @code{(-3 . 3)} is
848 interpreted as an interval, where the center line is the 0, so the
849 first number is generally negative.  The numbers need not match;
850 for example, the staff can be made larger at the bottom by setting
851 it to @code{(-6 . 4)}.
852
853
854 @seealso
855
856 Internals: Vertical alignment of staves is handled by the
857 @internalsref{VerticalAlignment} object. The context parameters
858 specifying the vertical extent are described in connection with
859 the @internalsref{Axis_group_engraver}.
860
861 Example files: @lsr{spacing,page-spacing.ly},
862 @lsr{spacing,alignment-vertical-spacing.ly}.
863
864
865 @node Vertical spacing between systems
866 @subsection Vertical spacing between systems
867
868 Space between systems are controlled by four @code{\paper} variables,
869
870 @example
871 \paper @{
872   between-system-space = 1.5\cm
873   between-system-padding = #1
874   ragged-bottom=##f
875   ragged-last-bottom=##f
876 @}
877 @end example
878
879
880 @node Explicit staff and system positioning
881 @subsection Explicit staff and system positioning
882
883 One way to understand the @code{VerticalAxisGroup} and @code{\paper}
884 settings explained in the previous two sections is as a collection of
885 different settings that primarily concern the amount of vertical padding
886 different staves and systems running down the page.
887
888 It is possible to approach vertical spacing in a different way using
889 @code{NonMusicalPaperColumn #'line-break-system-details}.  Where
890 @code{VerticalAxisGroup} and @code{\paper} settings specify vertical padding,
891 @code{NonMusicalPaperColumn #'line-break-system-details} specifies exact
892 vertical positions on the page.
893
894 @code{NonMusicalPaperColumn #'line-break-system-details} accepts an associative
895 list of five different settings:
896
897 @itemize 
898 @item @code{X-offset}
899 @item @code{Y-offset}
900 @item @code{alignment-offsets}
901 @item @code{alignment-extra-space}
902 @item @code{fixed-alignment-extra-space}
903 @end itemize
904
905 Grob overrides, including the overrides for @code{NonMusicalPaperColumn}
906 below, can occur in any of three different places in an input file:
907
908 @itemize
909 @item in the middle of note entry directly
910 @item in a @code{\context} block
911 @item in the @code{\with} block
912 @end itemize
913
914 When we override @code{NonMusicalPaperColumn}, we use the usual
915 @code{\override} command in @code{\context} blocks and in the
916 @code{\with} block.  On the other hand, when we override
917 @code{NonMusicalPaperColumn} in the middle of note entry,
918 use the special @code{\overrideProperty} command.  Here are some
919 example @code{NonMusicalPaperColumn} overrides with the special
920 @code{\overrideProperty} command:
921
922 @example
923 \overrideProperty NonMusicalPaperColumn
924   #'line-break-system-details #'((X-offset . 20))
925
926 \overrideProperty NonMusicalPaperColumn
927   #'line-break-system-details #'((Y-offset . 40))
928
929 \overrideProperty NonMusicalPaperColumn
930   #'line-break-system-details #'((X-offset . 20) (Y-offset . 40))
931
932 \override NonMusicalPaperColumn
933   #'line-break-system-details #'((alignment-offsets . (0 -15)))
934
935 \override NonMusicalPaperColumn
936   #'line-break-system-details #'((X-offset . 20) (Y-offset . 40)
937                                  (alignment-offsets . (0 -15)))
938 @end example
939
940 To understand how each of these different settings work, we begin
941 by looking at an example that includes no overrides at all.
942
943 @lilypond[quote,ragged-right]
944 \new Score <<
945   \new Staff <<
946     \new Voice {
947       s1 * 6 \break
948       s1 * 6 \break
949       s1 * 6 \break
950     }
951     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
952   >>
953   \new Staff {
954     \repeat unfold 18 { d'4 d'4 d'4 d'4 }
955   }
956 >>
957 @end lilypond
958
959 This score isolates line- and page-breaking information in a dedicated
960 voice. This technique of creating a breaks voice will help keep layout
961 separate from music entry as our example becomes more complicated.
962 See @ref{Using an extra voice for breaks}.
963
964 Explicit @code{\breaks} evenly divide the music into six measures per
965 line.  Vertical spacing results from LilyPond's defaults.  To set
966 the vertical startpoint of each system explicitly, we can set
967 the @code{Y-offset} pair in the @code{line-break-system-details}
968 attribute of the @code{NonMusicalPaperColumn} grob:
969
970 @lilypond[quote,ragged-right]
971 \new Score <<
972   \new Staff <<
973     \new Voice {
974       \overrideProperty #"Score.NonMusicalPaperColumn"
975         #'line-break-system-details #'((Y-offset . 0))
976       s1 * 6 \break
977       \overrideProperty #"Score.NonMusicalPaperColumn"
978         #'line-break-system-details #'((Y-offset . 40))
979       s1 * 6 \break
980       \overrideProperty #"Score.NonMusicalPaperColumn"
981         #'line-break-system-details #'((Y-offset . 80))
982       s1 * 6 \break
983     }
984     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
985   >>
986   \new Staff {
987     \repeat unfold 18 { d'4 d'4 d'4 d'4 }
988   }
989 >>
990 @end lilypond
991
992 Note that @code{line-break-system-details} takes an associative list of
993 potentially many values, but that we set only one value here.  Note,
994 too, that the @code{Y-offset} property here determines the exact vertical
995 position on the page at which each new system will render.
996
997 Now that we have set the vertical startpoint of each system
998 explicitly, we can also set the vertical startpoint of each staff
999 within each system manually.  We do this using the @code{alignment-offsets}
1000 subproperty of @code{line-break-system-details}.
1001
1002 @lilypond[quote,ragged-right]
1003 \new Score <<
1004   \new Staff <<
1005     \new Voice {
1006       \overrideProperty #"Score.NonMusicalPaperColumn"
1007         #'line-break-system-details #'((Y-offset . 20)
1008           (alignment-offsets . (0 -15)))
1009       s1 * 6 \break
1010       \overrideProperty #"Score.NonMusicalPaperColumn"
1011         #'line-break-system-details #'((Y-offset . 60)
1012           (alignment-offsets . (0 -15)))
1013       s1 * 6 \break
1014       \overrideProperty #"Score.NonMusicalPaperColumn"
1015         #'line-break-system-details #'((Y-offset . 100)
1016           (alignment-offsets . (0 -15)))
1017       s1 * 6 \break
1018     }
1019     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
1020   >>
1021   \new Staff {
1022     \repeat unfold 18 { d'4 d'4 d'4 d'4 }
1023   }
1024 >>
1025 @end lilypond
1026
1027 Note that here we assign two different values to the
1028 @code{line-break-system-details} attribute of the
1029 @code{NonMusicalPaperColumn} grob.  Though the
1030 @code{line-break-system-details} attribute alist accepts many
1031 additional spacing parameters (including, for example, a corresponding
1032 @code{X-offset} pair), we need only set the @code{Y-offset} and
1033 @code{alignment-offsets} pairs to control the vertical startpoint of
1034 every system and every staff.  Finally, note that @code{alignment-offsets}
1035 specifies the vertical positioning of staves but not of staff groups.
1036
1037 @lilypond[quote,ragged-right]
1038 \new Score <<
1039   \new Staff <<
1040     \new Voice {
1041       \overrideProperty #"Score.NonMusicalPaperColumn"
1042       #'line-break-system-details #'((Y-offset . 0)
1043         (alignment-offsets . (0 -30 -40)))
1044       s1 * 6 \break
1045       \overrideProperty #"Score.NonMusicalPaperColumn"
1046       #'line-break-system-details #'((Y-offset . 60)
1047         (alignment-offsets . (0 -10 -20)))
1048       s1 * 6 \break
1049       \overrideProperty #"Score.NonMusicalPaperColumn"
1050       #'line-break-system-details #'((Y-offset . 100)
1051         (alignment-offsets . (0 -10, -40)))
1052       s1 * 6 \break
1053     }
1054     \new Voice { \repeat unfold 18 { c'4 c'4 c'4 c'4 } }
1055   >>
1056   \new StaffGroup <<
1057     \new Staff {
1058       \repeat unfold 18 { d'4 d'4 d'4 d'4 }
1059     }
1060     \new Staff {
1061       \repeat unfold 18 { e'4 e'4 e'4 e'4 }
1062     }
1063   >>
1064 >>
1065 @end lilypond
1066
1067 Some points to consider:
1068
1069 @itemize
1070 @item When using @code{alignment-offsets}, lyrics count as a staff.
1071
1072 @item The units of the numbers passed to @code{X-offset},
1073 @code{Y-offset} and @code{alignment-offsets} are interpreted as multiples
1074 of the distance between adjacent staff lines.  Positive values move staves
1075 and lyrics up, negative values move staves and lyrics down.
1076
1077 @item Because the @code{NonMusicalPaperColumn #'line-break-system-details}
1078 settings given here allow the positioning of staves and systems anywhere
1079 on the page, it is possible to violate paper or margin boundaries or even
1080 to print staves or systems on top of one another.  Reasonable values
1081 passed to these different settings will avoid this.
1082 @end itemize
1083
1084
1085 @node Two-pass vertical spacing
1086 @subsection Two-pass vertical spacing
1087
1088 In order to automatically stretch systems so that they should fill the
1089 space left on a page, a two-pass technique can be used:
1090
1091 @enumerate
1092 @item In the first pass, the amount of vertical space used to increase
1093 the height of each system is computed and dumped to a file.
1094 @item In the second pass, spacing inside the systems are
1095 stretched according to the data in the page layout file.
1096 @end enumerate
1097
1098 The @code{ragged-bottom} property adds space between systems, while
1099 the two-pass technique adds space between staffs inside a system.
1100
1101 To allow this behaviour, a @code{tweak-key} variable has to be set in
1102 each score @code{\layout} block, and the tweaks included in each score
1103 music, using the @code{\scoreTweak} music function.
1104
1105 @quotation
1106 @verbatim
1107 %% include the generated page layout file:
1108 \includePageLayoutFile
1109
1110 \score {
1111   \new StaffGroup <<
1112     \new Staff <<
1113       %% Include this score tweaks:
1114       \scoreTweak "scoreA"
1115       { \clef french c''1 \break c''1 } 
1116     >>
1117     \new Staff { \clef soprano g'1 g'1 }
1118     \new Staff { \clef mezzosoprano e'1 e'1 }
1119     \new Staff { \clef alto g1 g1 }
1120     \new Staff { \clef bass c1 c1 }
1121   >>
1122   \header {
1123     piece = "Score with tweaks"
1124   }
1125   %% Define how to name the tweaks for this score:
1126   \layout { #(define tweak-key "scoreA") }
1127 }
1128 @end verbatim
1129 @end quotation
1130
1131 For the first pass, the @code{dump-tweaks} option should be set to
1132 generate the page layout file.
1133
1134 @example
1135 lilypond -dbackend=null -d dump-tweaks <file>.ly
1136 lilypond <file>.ly
1137 @end example
1138
1139 @node Horizontal spacing
1140 @section Horizontal Spacing
1141
1142 @cindex horizontal spacing
1143 @cindex spacing, horizontal
1144
1145 @menu
1146 * Horizontal spacing overview::  
1147 * New spacing area::            
1148 * Changing horizontal spacing::  
1149 * Line length::                 
1150 @end menu
1151
1152
1153 @node Horizontal spacing overview
1154 @subsection Horizontal spacing overview
1155
1156 The spacing engine translates differences in durations into stretchable
1157 distances (@q{springs}) of differring lengths.  Longer durations get
1158 more space, shorter durations get less.  The shortest durations get a
1159 fixed amount of space (which is controlled by
1160 @code{shortest-duration-space} in the @internalsref{SpacingSpanner}
1161 object).  The longer the duration, the more space it gets: doubling a
1162 duration adds a fixed amount (this amount is controlled by
1163 @code{spacing-increment}) of space to the note.
1164
1165 For example, the following piece contains lots of half, quarter, and
1166 8th notes; the eighth note is followed by 1 note head width (NHW).
1167 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
1168
1169 @lilypond[quote,fragment,verbatim,relative=1]
1170 c2 c4. c8 c4. c8 c4. c8 c8
1171 c8 c4 c4 c4
1172 @end lilypond
1173
1174 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
1175 approximately the width of a note head, and
1176 @code{shortest-duration-space} is set to 2.0, meaning that the
1177 shortest note gets 2.4 staff space (2.0 times the
1178 @code{spacing-increment}) of horizontal space.  This space is counted
1179 from the left edge of the symbol, so the shortest notes are generally
1180 followed by one NHW of space.
1181
1182 If one would follow the above procedure exactly, then adding a single
1183 32nd note to a score that uses 8th and 16th notes, would widen up the
1184 entire score a lot.  The shortest note is no longer a 16th, but a 32nd,
1185 thus adding 1 NHW to every note.  To prevent this, the shortest
1186 duration for spacing is not the shortest note in the score, but rather
1187 the one which occurs most frequently.
1188
1189
1190 The most common shortest duration is determined as follows: in every
1191 measure, the shortest duration is determined.  The most common shortest
1192 duration is taken as the basis for the spacing, with the stipulation
1193 that this shortest duration should always be equal to or shorter than
1194 an 8th note.  The shortest duration is printed when you run
1195 @code{lilypond} with the @code{--verbose} option.
1196
1197 These durations may also be customized.  If you set the
1198 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
1199 this sets the base duration for spacing.  The maximum duration for this
1200 base (normally an 8th), is set through @code{base-shortest-duration}.
1201
1202 @funindex common-shortest-duration
1203 @funindex base-shortest-duration
1204 @funindex stem-spacing-correction
1205 @funindex spacing
1206
1207 Notes that are even shorter than the common shortest note are
1208 followed by a space that is proportional to their duration relative to
1209 the common shortest note.  So if we were to add only a few 16th notes
1210 to the example above, they would be followed by half a NHW:
1211
1212 @lilypond[quote,fragment,verbatim,relative=2]
1213 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
1214 @end lilypond
1215
1216
1217 In the introduction (see @ref{Engraving}), it was explained that stem
1218 directions influence spacing.  This is controlled with the
1219 @code{stem-spacing-correction} property in the
1220 @internalsref{NoteSpacing}, object.  These are generated for every
1221 @internalsref{Voice} context.  The @code{StaffSpacing} object
1222 (generated in @internalsref{Staff} context) contains the same property
1223 for controlling the stem/bar line spacing.  The following example shows
1224 these corrections, once with default settings, and once with
1225 exaggerated corrections:
1226
1227 @lilypond[quote,ragged-right]
1228 {
1229   c'4 e''4 e'4 b'4 |
1230   b'4 e''4 b'4 e''4|
1231   \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
1232   \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
1233   c'4 e''4 e'4 b'4 |
1234   b'4 e''4 b'4 e''4|
1235 }
1236 @end lilypond
1237
1238 Proportional notation is supported; see @ref{Proportional notation}.
1239
1240
1241 @seealso
1242
1243 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
1244 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
1245 @internalsref{SeparatingGroupSpanner}.
1246
1247
1248 @refbugs
1249
1250 There is no convenient mechanism to manually override spacing.  The
1251 following work-around may be used to insert extra space into a score.
1252 @example
1253  \once \override Score.SeparationItem #'padding = #1
1254 @end example
1255
1256 No work-around exists for decreasing the amount of space.
1257
1258
1259 @node New spacing area
1260 @subsection New spacing area
1261
1262 New sections with different spacing parameters can be started with
1263 @code{newSpacingSection}.  This is useful when there are  
1264 sections with a different notions of long and short notes.
1265
1266 In the following example, the time signature change introduces a new
1267 section, and hence the 16ths notes are spaced wider.
1268
1269 @lilypond[relative,fragment,verbatim,quote]
1270 \time 2/4
1271 c4 c8 c 
1272 c8 c c4 c16[ c c8] c4
1273 \newSpacingSection
1274 \time 4/16
1275 c16[ c c8]
1276 @end lilypond
1277
1278
1279 The @code{\newSpacingSection} command creates a new
1280 @internalsref{SpacingSpanner} object, and hence new @code{\override}s
1281 may be used in that location.
1282
1283
1284 @node Changing horizontal spacing
1285 @subsection Changing horizontal spacing
1286
1287 Horizontal spacing may be altered with the
1288 @code{base-shortest-duration} property.  Here
1289 we compare the same music; once without altering
1290 the property, and then altered.  Larger values
1291 of @code{ly:make-moment} will produce smaller
1292 music.  Note that @code{ly:make-moment} constructs
1293 a duration, so @code{1 4} is a longer duration
1294 than @code{1 16}.
1295
1296 @lilypond[relative,verbatim,line-width=12\cm]
1297 \score {
1298   \relative c'' {
1299     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
1300     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1301     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
1302     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1303   }
1304 }
1305 @end lilypond
1306
1307 @lilypond[relative,verbatim,line-width=12\cm]
1308 \score {
1309   \relative c'' {
1310     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
1311     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1312     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
1313     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
1314   }
1315   \layout {
1316     \context {
1317       \Score
1318       \override SpacingSpanner
1319                 #'base-shortest-duration = #(ly:make-moment 1 16)
1320     }
1321   }
1322 }
1323 @end lilypond
1324
1325
1326 @commonprop
1327
1328 By default, spacing in tuplets depends on various non-duration
1329 factors (such as accidentals, clef changes, etc).  To disregard
1330 such symbols and force uniform equal-duration spacing, use
1331 @code{Score.SpacingSpanner #'uniform-stretching}.  This
1332 property can only be changed at the beginning of a score,
1333
1334 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1335 \new Score \with {
1336   \override SpacingSpanner #'uniform-stretching = ##t
1337 } <<
1338   \new Staff{
1339     \times 4/5 {
1340       c8 c8 c8 c8 c8
1341     }
1342     c8 c8 c8 c8
1343   }
1344   \new Staff{
1345     c8 c8 c8 c8
1346     \times 4/5 {
1347       c8 c8 c8 c8 c8
1348     }
1349   }
1350 >>
1351 @end lilypond
1352
1353
1354 When @code{strict-note-spacing} is set, notes are spaced without
1355 regard for clefs, bar lines, and grace notes,
1356
1357 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1358 \override Score.SpacingSpanner #'strict-note-spacing = ##t
1359 \new Staff { c8[ c \clef alto c \grace { c16[ c] } c8 c c]  c32[ c32] }
1360 @end lilypond
1361
1362
1363 @node Line length
1364 @subsection Line length
1365
1366 @cindex page breaks
1367 @cindex breaking pages
1368
1369 @funindex indent
1370 @funindex line-width
1371 @funindex ragged-right
1372 @funindex ragged-last
1373
1374 @c Although line-width can be set in \layout, it should be set in paper
1375 @c block, to get page layout right.
1376 @c Setting indent in \paper block makes not much sense, but it works.
1377
1378 @c Bit verbose and vague, use examples?
1379 The most basic settings influencing the spacing are @code{indent} and
1380 @code{line-width}.  They are set in the @code{\layout} block.  They
1381 control the indentation of the first line of music, and the lengths of
1382 the lines.
1383
1384 If @code{ragged-right} is set to true in the @code{\layout} block, then
1385 systems ends at their natural horizontal length, instead of being spread
1386 horizontally to fill the whole line.  This is useful for
1387 short fragments, and for checking how tight the natural spacing is.
1388
1389 @cindex page layout
1390 @cindex vertical spacing
1391
1392 The option @code{ragged-last} is similar to @code{ragged-right}, but
1393 only affects the last line of the piece.  No restrictions are put on
1394 that line.  The result is similar to formatting text paragraphs.  In a
1395 paragraph, the last line simply takes its natural horizontal length.
1396 @c Note that for text there are several options for the last line.
1397 @c While Knuth TeX uses natural length, lead typesetters use the same
1398 @c stretch as the previous line.  eTeX uses \lastlinefit to
1399 @c interpolate between both these solutions.
1400
1401 @example
1402 \layout @{
1403   indent = #0
1404   line-width = #150
1405   ragged-last = ##t
1406 @}
1407 @end example
1408
1409
1410 @node Displaying spacing
1411 @section Displaying spacing
1412
1413 @funindex annotate-spacing
1414 @cindex Spacing, display of properties
1415
1416 To graphically display the dimensions of vertical properties that may
1417 be altered for page formatting, set @code{annotate-spacing} in the
1418 @code{\paper} block, like this
1419
1420
1421 @lilypond[verbatim]
1422 #(set-default-paper-size "a6" 'landscape)
1423
1424 \book {
1425   \score { { c4 } }
1426   \paper { annotate-spacing = ##t }
1427 }
1428 @end lilypond
1429
1430 @c need to have \book{} otherwise we get  the separate systems. -hwn
1431
1432 @noindent
1433 @c  FIXME: really bad vagueness due to bug in annotate-spacing.  -gp
1434 Some unit dimensions are measured in staff spaces, while others
1435 are measured in millimeters.
1436 The pairs
1437 (@var{a},@var{b}) are intervals, where @var{a} is the lower edge and
1438 @var{b} the upper edge of the interval.
1439
1440
1441 @node Vertical collision avoidance
1442 @section Vertical collision avoidance
1443
1444 @funindex outside-staff-priority
1445 @funindex outside-staff-padding
1446 @funindex outside-staff-horizontal-padding
1447
1448 Intuitively, there are some objects in musical notation that belong
1449 to the staff and there are other objects that should be placed outside
1450 the staff.  Objects belonging outside the staff include things such as
1451 rehearsal marks, text and dynamic markings (from now on, these will
1452 be called outside-staff objects).  LilyPond's rule for the
1453 vertical placement of outside-staff objects is to place them as close
1454 to the staff as possible but not so close that they collide with
1455 another object.
1456
1457 LilyPond uses the @code{outside-staff-priority} property to determine
1458 whether a grob is an outside-staff object: if @code{outside-staff-priority}
1459 is a number, the grob is an outside-staff object.  In addition,
1460 @code{outside-staff-priority} tells LilyPond in which order the objects
1461 should be placed.
1462
1463 First, LilyPond places all the objects that do not belong outside
1464 the staff.  Then it sorts the outside-staff objects according to their
1465 @code{outside-staff-priority} (in increasing order).  One by one, LilyPond
1466 takes the outside-staff objects and places them so that they do
1467 not collide with any objects that have already been placed.  That
1468 is, if two outside-staff grobs are competing for the same space, the one
1469 with the lower @code{outside-staff-priority} will be placed closer to
1470 the staff.
1471
1472 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1473 c4_"Text"\pp
1474 r2.
1475 \once \override TextScript #'outside-staff-priority = #1
1476 c4_"Text"\pp % this time the text will be closer to the staff
1477 r2.
1478 % by setting outside-staff-priority to a non-number, we
1479 % disable the automatic collision avoidance
1480 \once \override TextScript #'outside-staff-priority = ##f
1481 \once \override DynamicLineSpanner #'outside-staff-priority = ##f
1482 c4_"Text"\pp % now they will collide
1483 @end lilypond
1484
1485 The vertical padding between an outside-staff object and the
1486 previously-positioned grobs can be controlled with
1487 @code{outside-staff-padding}.
1488
1489 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1490 \once \override TextScript #'outside-staff-padding = #0
1491 a'^"This text is placed very close to the note"
1492 \once \override TextScript #'outside-staff-padding = #3
1493 c^"This text is padded away from the previous text"
1494 c^"This text is placed close to the previous text"
1495 @end lilypond
1496
1497 By default, outside-staff objects are placed without regard to
1498 their horizontal distance from the previously-posititioned grobs.  This
1499 can lead to situations in which objects are placed very close to each
1500 other horizontally.  Setting @code{outside-staff-horizontal-padding}
1501 causes an object to be offset vertically so that such a situation
1502 doesn't occur.
1503
1504 @lilypond[quote,ragged-right,relative=2,fragment,verbatim]
1505 % the markup is too close to the following note
1506 c2^"Text"
1507 c''2
1508 % setting outside-staff-horizontal-padding fixes this
1509 R1
1510 \once \override TextScript #'outside-staff-horizontal-padding = #1
1511 c,,2^"Text"
1512 c''2
1513 @end lilypond