1 @c -*- coding: utf-8; mode: texinfo; -*-
3 @chapter Tweaking output
5 This chapter discusses how to modify output. LilyPond is extremely
6 configurable; virtually every fragment of output may be changed.
11 * Fixing overlapping notation::
14 * Fitting music onto fewer pages::
15 * Advanced tweaks with Scheme::
20 @section Moving objects
22 This may come as a surprise, but LilyPond is not perfect. Some notation
23 elements can overlap. This is unfortunate, but (in most cases) is easily
26 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
27 e4^\markup{ \italic ritenuto } g b e
32 The easiest solution is to increase the distance between the object
33 (in this case text, but it could easily be fingerings or dynamics
34 instead) and the note. In LilyPond, this is called the
35 @code{padding} property; it is measured in staff spaces. For most
36 objects, this value is around 1.0 or less (it varies with each
37 object). We want to increase it, so let's try 1.5
39 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
40 \once \override TextScript #'padding = #1.5
41 e4^\markup{ \italic ritenuto } g b e
44 That looks better, but it isn't quite big enough. After experimenting
45 with a few values, we think 2.3 is the best number in this case. However,
46 this number is merely the result of experimentation and my personal
47 taste in notation. Try the above example with 2.3... but also try higher
48 (and lower) numbers. Which do you think looks the best?
50 The @code{staff-padding} property is closely related. @code{padding}
51 controls the minimum amount of space between an object and the nearest
52 other object (generally the note or the staff lines);
53 @code{staff-padding} controls the minimum amount of space between an
54 object and the staff. This is a subtle difference, but you can see
57 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
59 \once \override TextScript #'padding = #2.6
61 \once \override TextScript #'staff-padding = #2.6
62 c4^"piu mosso" fis a g
65 \once \override TextScript #'padding = #2.6
67 \once \override TextScript #'staff-padding = #2.6
68 c4^"piu mosso" fis a g
73 Another solution gives us complete control over placing the object -- we
74 can move it horizontally or vertically. This is done with the
75 @code{extra-offset} property. It is slightly more complicated and can
76 cause other problems. When we move objects with @code{extra-offset},
77 the movement is done after LilyPond has placed all other objects. This
79 that the result can overlap with other objects.
81 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
82 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
83 e4^\markup{ \italic ritenuto } g b e
86 With @code{extra-offset}, the first number controls the horizontal
87 movement (left is negative); the second number controls the vertical
88 movement (up is positive). After a bit of experimenting, we decided
89 that these values look good
91 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
92 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
93 e4^\markup{ \italic ritenuto } g b e
97 Again, these numbers are simply the result of a few experiments and
98 looking at the output. You might prefer the text to be slightly higher,
99 or to the left, or whatever. Try it and look at the result!
101 One final warning: in this section, we used
104 \once \override TextScript @dots{}
107 This tweaks the display of text for the next note. If the note has
108 no text, this tweak does nothing (and does @strong{not} wait until
109 the next bit of text). To change the behavior of everything after
110 the command, omit the @code{\once}. To stop this tweak, use a
111 @code{\revert}. This is explained in depth in
112 @ref{The \override command}.
114 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
116 \once \override TextScript #'padding = #2.6
119 \once \override TextScript #'padding = #2.6
123 \override TextScript #'padding = #2.6
126 \revert TextScript #'padding
132 This manual: @ref{The \override command}, @ref{Common tweaks}.
135 @node Fixing overlapping notation
136 @section Fixing overlapping notation
138 In @ref{Moving objects}, we saw how to move a @code{TextScript}
139 object. The same mechanism can be used to move other types of
140 objects; simply replace @code{TextScript} with the name of
143 To find the object name, look at the ``@strong{see also}'' at
144 bottom of the relevant documentation page. For example, at
145 the bottom of @ref{Dynamics}, we see
150 Program reference: @internalsref{DynamicText}, @internalsref{Hairpin}.
151 Vertical positioning of these symbols is handled by
152 @internalsref{DynamicLineSpanner}.
156 So to move dynamics around vertically, we use
159 \override DynamicLineSpanner #'padding = #2.0
162 We cannot list every object, but here is a list of the most
165 @multitable @columnfractions .33 .66
166 @headitem Object type @tab Object name
167 @item Dynamics (vertically) @tab @code{DynamicLineSpanner}
168 @item Dynamics (horizontally) @tab @code{DynamicText}
169 @item Ties @tab @code{Tie}
170 @item Slurs @tab @code{Slur}
171 @item Articulations @tab @code{Script}
172 @item Fingerings @tab @code{Fingering}
173 @item Text e.g. @code{^"text"} @tab @code{TextScript}
174 @item Rehearsal / Text marks @tab @code{RehearsalMark}
179 @section Common tweaks
181 Some overrides are so common that predefined commands are provided as
182 short-cuts, such as @code{\slurUp} and @code{\stemDown}. These
183 commands are described in the Notation Reference under the appropriate
186 The complete list of modifications available for each type of
187 object (like slurs or beams) are documented in the Program
188 Reference. However, many layout objects share properties which can be
189 used to apply generic tweaks.
196 The @code{padding} property can be set to increase
197 (or decrease) the distance between symbols that are printed
198 above or below notes. This applies to all objects with
199 @code{side-position-interface}.
201 @lilypond[quote,fragment,relative=1,verbatim]
203 \override Script #'padding = #3
207 @lilypond[quote,fragment,relative=1,verbatim]
208 % This will not work, see below:
209 \override MetronomeMark #'padding = #3
213 \override Score.MetronomeMark #'padding = #3
218 Note in the second example how important it is to figure out what
219 context handles a certain object. Since the @code{MetronomeMark} object
220 is handled in the @code{Score} context, property changes in the
221 @code{Voice} context will not be noticed. For more details, see
222 @ref{Constructing a tweak}.
227 The @code{extra-offset} property moves objects around
228 in the output; it requires a pair of numbers. The first number
229 controls horizontal movement; a positive number will
230 move the object to the right. The second number controls vertical
231 movement; a positive number will move it higher. The
232 @code{extra-offset} property is a low-level feature: the
233 formatting engine is completely oblivious to these offsets.
235 In the following example, the second fingering is moved a little to
236 the left, and 1.8 staff space downwards:
238 @lilypond[quote,fragment,relative=1,verbatim]
241 \once \override Fingering
242 #'extra-offset = #'(-0.3 . -1.8)
247 Setting the @code{transparent} property will cause an object to be printed
248 in `invisible ink': the object is not printed, but all its other
249 behavior is retained. The object still takes up space, it takes part in
250 collisions, and slurs, ties, and beams can be attached to it.
252 @cindex transparent objects
253 @cindex removing objects
254 @cindex hiding objects
255 @cindex invisible objects
256 The following example demonstrates how to connect different voices
257 using ties. Normally, ties only connect two notes in the same
258 voice. By introducing a tie in a different voice,
260 @lilypond[quote,fragment,relative=2]
269 and blanking the first up-stem in that voice, the tie appears to cross
272 @lilypond[quote,fragment,relative=2,verbatim]
274 \once \override Stem #'transparent = ##t
283 @cindex Tweaks, distances
286 Distances in LilyPond are measured in staff-spaces, while most
287 thickness properties are measured in line-thickness. Some
288 properties are different; for example, the thickness of beams
289 are measured in staff-spaces. For more information, see the
290 relevant portion of the program reference.
294 @section Default files
296 The Program Reference documentation contains a lot of information
297 about LilyPond, but even more information can be gathered from
298 looking at the internal LilyPond files.
300 Some default settings (such as the definitions for
301 @code{\header@{@}}s) are stored as @code{.ly} files. Other
302 settings (such as the definitions of markup commands) are
303 stored as @code{.scm} (Scheme) files. Further explanation is
304 outside the scope of this manual; users should be warned that
305 a substantial amount of technical knowledge or time is required
306 to understand these files.
310 @item Linux: @file{@{INSTALLDIR@}/lilypond/usr/share/lilypond/current/}
313 @file{@{INSTALLDIR@}/LilyPond.app/Contents/Resources/share/lilypond/current/}.
314 To access this, either @code{cd} into this directory from
315 the Terminal, or control-click on the LilyPond application
316 and select "Show Package Contents".
318 @item Windows: @file{@{INSTALLDIR@}/LilyPond/usr/share/lilypond/current/}
322 The @file{ly/} and @file{scm/} directories will be of
323 particular interest. Files such as @file{ly/property-init.ly} and
324 @file{ly/declarations-init.ly} define all the common tweaks.
327 @node Fitting music onto fewer pages
328 @section Fitting music onto fewer pages
330 Sometimes you can end up with one or two staves on a second
331 (or third, or fourth...) page. This is annoying, especially
332 if you look at previous pages and it looks like there is plenty
333 of room left on those.
335 When investigating layout issues, @code{annotate-spacing} is
336 an invaluable tool. This command prints the values of various
337 layout spacing commands; see @ref{Displaying spacing} for more
338 details. From the output of @code{annotate-spacing}, we can
339 see which margins we may wish to alter.
341 Other than margins, there are a few other options to save space:
345 You may tell LilyPond to place systems as close together as
346 possible (to fit as many systems as possible onto a page), but
347 then to space those systems out so that there is no blank
348 space at the bottom of the page.
352 between-system-padding = #0.1
353 between-system-space = #0.1
354 ragged-last-bottom = ##f
360 You may force the number of systems (i.e., if LilyPond wants
361 to typeset some music with 11 systems, you could force it to
371 Avoid (or reduce) objects which increase the vertical size of
372 a system. For example, volta repeats (or alternate repeats)
373 require extra space. If these repeats are spread over two
374 systems, they will take up more space than one system with
375 the volta repeats and another system without.
377 Another example is moving dynamics which ``stick out'' of
380 @lilypond[verbatim,quote,fragment]
383 \override DynamicLineSpanner #'padding = #-1.8
384 \override DynamicText #'extra-offset = #'( -2.1 . 0)
390 Alter the horizontal spacing via @code{SpacingSpanner}. See
391 @ref{Changing horizontal spacing} for more details.
393 @lilypond[verbatim,quote]
396 g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
397 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
398 d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
399 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
404 \override SpacingSpanner
405 #'base-shortest-duration = #(ly:make-moment 1 4)
414 @node Advanced tweaks with Scheme
415 @section Advanced tweaks with Scheme
417 We have seen how LilyPond output can be heavily modified using
419 @code{\override TextScript #'extra-offset = ( 1 . -1)}. But
420 we have even more power if we use Scheme. For a full explantion
421 of this, see the @ref{Scheme tutorial} and
422 @ref{Interfaces for programmers}.
424 We can use Scheme to simply @code{\override} commands,
426 @lilypond[quote,verbatim,ragged-right]
427 padText = #(define-music-function (parser location padding) (number?)
429 \once \override TextScript #'padding = #$padding
437 c4^"piu mosso" fis a g
441 We can use it to create new commands,
443 @lilypond[quote,verbatim,ragged-right]
444 tempoMark = #(define-music-function (parser location padding marktext)
447 \once \override Score . RehearsalMark #'padding = $padding
448 \once \override Score . RehearsalMark #'no-spacing-rods = ##t
449 \mark \markup { \bold $marktext }
454 \tempoMark #3.0 #"Allegro"
459 Even music expressions can be passed in.
461 @lilypond[quote,verbatim,ragged-right]
462 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
469 \pattern {d16 dis} { ais16-> b\p }