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 * Advanced tweaks with Scheme::
19 @section Moving objects
21 This may come as a surprise, but LilyPond is not perfect. Some notation
22 elements can overlap. This is unfortunate, but (in most cases) is easily
25 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
26 e4^\markup{ \italic ritenuto } g b e
31 The easiest solution is to increase the distance between the object
32 (in this case text, but it could easily be fingerings or dynamics
33 instead) and the note. In LilyPond, this is called the
34 @code{padding} property; it is measured in staff spaces. For most
35 objects, this value is around 1.0 or less (it varies with each
36 object). We want to increase it, so let's try 1.5
38 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
39 \once \override TextScript #'padding = #1.5
40 e4^\markup{ \italic ritenuto } g b e
43 That looks better, but it isn't quite big enough. After experimenting
44 with a few values, we think 2.3 is the best number in this case. However,
45 this number is merely the result of experimentation and my personal
46 taste in notation. Try the above example with 2.3... but also try higher
47 (and lower) numbers. Which do you think looks the best?
49 The @code{staff-padding} property is closely related. @code{padding}
50 controls the minimum amount of space between an object and the nearest
51 other object (generally the note or the staff lines);
52 @code{staff-padding} controls the minimum amount of space between an
53 object and the staff. This is a subtle difference, but you can see
56 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
58 \once \override TextScript #'padding = #2.6
60 \once \override TextScript #'staff-padding = #2.6
61 c4^"piu mosso" fis a g
63 c,,4^"piu mosso" b a b
64 \once \override TextScript #'padding = #2.6
66 \once \override TextScript #'staff-padding = #2.6
67 c4^"piu mosso" fis a g
72 Another solution gives us complete control over placing the object -- we
73 can move it horizontally or vertically. This is done with the
74 @code{extra-offset} property. It is slightly more complicated and can
75 cause other problems. When we move objects with @code{extra-offset},
76 the movement is done after LilyPond has placed all other objects. This
78 that the result can overlap with other objects.
80 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
81 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
82 e4^\markup{ \italic ritenuto } g b e
85 With @code{extra-offset}, the first number controls the horizontal
86 movement (left is negative); the second number controls the vertical
87 movement (up is positive). After a bit of experimenting, we decided
88 that these values look good
90 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
91 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
92 e4^\markup{ \italic ritenuto } g b e
96 Again, these numbers are simply the result of a few experiments and
97 looking at the output. You might prefer the text to be slightly higher,
98 or to the left, or whatever. Try it and look at the result!
100 One final warning: in this section, we used
103 \once \override TextScript @dots{}
106 This tweaks the display of text for the next note. If the note has
107 no text, this tweak does nothing (and does @strong{not} wait until
108 the next bit of text). To change the behavior of everything after
109 the command, omit the @code{\once}. To stop this tweak, use a
110 @code{\revert}. This is explained in depth in
111 @ref{The \override command}.
113 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
115 \once \override TextScript #'padding = #2.6
118 \once \override TextScript #'padding = #2.6
122 \override TextScript #'padding = #2.6
125 \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, 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 @tab @code{DynamicLineSpanner}
168 @item Ties @tab @code{Tie}
169 @item Slurs @tab @code{Slur}
170 @item Articulations @tab @code{Script}
171 @item Fingerings @tab @code{Fingering}
172 @item Text e.g. @code{^"text"} @tab @code{TextScript}
173 @item Rehearsal / Text marks @tab @code{RehearsalMark}
178 @section Common tweaks
180 Some overrides are so common that predefined commands are provided as
181 short-cuts, such as @code{\slurUp} and @code{\stemDown}. These
182 commands are described in the Notation Reference under the appropriate
185 The complete list of modifications available for each type of
186 object (like slurs or beams) are documented in the Program
187 Reference. However, many layout objects share properties which can be
188 used to apply generic tweaks.
193 @item The @code{padding} property can be set to increase
194 (or decrease) the distance between symbols that are printed
195 above or below notes. This applies to all objects with
196 @code{side-position-interface}.
198 @lilypond[quote,fragment,relative=1,verbatim]
200 \override Script #'padding = #3
204 @lilypond[quote,fragment,relative=1,verbatim]
205 % This will not work, see below:
206 \override MetronomeMark #'padding = #3
210 \override Score.MetronomeMark #'padding = #3
215 Note in the second example how important it is to figure out what
216 context handles a certain object. Since the @code{MetronomeMark} object
217 is handled in the @code{Score} context, property changes in the
218 @code{Voice} context will not be noticed. For more details, see
219 @ref{Constructing a tweak}.
221 @funindex extra-offset
222 @item The @code{extra-offset} property moves objects around
223 in the output; it requires a pair of numbers. The first number
224 controls horizontal movement; a positive number will
225 move the object to the right. The second number controls vertical
226 movement; a positive number will move it higher. The
227 @code{extra-offset} property is a low-level feature: the
228 formatting engine is completely oblivious to these offsets.
230 In the following example, the second fingering is moved a little to
231 the left, and 1.8 staff space downwards:
233 @lilypond[quote,fragment,relative=1,verbatim]
236 \once \override Fingering
237 #'extra-offset = #'(-0.3 . -1.8)
242 Setting the @code{transparent} property will cause an object to be printed
243 in `invisible ink': the object is not printed, but all its other
244 behavior is retained. The object still takes up space, it takes part in
245 collisions, and slurs, ties, and beams can be attached to it.
247 @cindex transparent objects
248 @cindex removing objects
249 @cindex hiding objects
250 @cindex invisible objects
251 The following example demonstrates how to connect different voices
252 using ties. Normally, ties only connect two notes in the same
253 voice. By introducing a tie in a different voice,
255 @lilypond[quote,fragment,relative=2]
264 and blanking the first up-stem in that voice, the tie appears to cross
267 @lilypond[quote,fragment,relative=2,verbatim]
269 \once \override Stem #'transparent = ##t
278 @cindex Tweaks, distances
281 Distances in LilyPond are measured in staff-spaces, while most
282 thickness properties are measured in line-thickness. Some
283 properties are different; for example, the thickness of beams
284 are measured in staff-spaces. For more information, see the
285 relevant portion of the program reference.
289 @section Default files
291 The Program Reference documentation contains a lot of information
292 about LilyPond, but even more information can be gathered from
293 looking at the internal LilyPond files.
295 Some default settings (such as the definitions for
296 @code{\header@{@}}s) are stored as @code{.ly} files. Other
297 settings (such as the definitions of markup commands) are
298 stored as @code{.scm} (Scheme) files. Further explanation is
299 outside the scope of this manual; users should be warned that
300 a substantial amount of technical knowledge or time is required
301 to understand these files.
305 @item Linux: @file{@{INSTALLDIR@}/lilypond/usr/share/lilypond/current/}
308 @file{@{INSTALLDIR@}/LilyPond.app/Contents/Resources/share/lilypond/current/}.
309 To access this, either @code{cd} into this directory from
310 the Terminal, or control-click on the LilyPond application
311 and select "Show Package Contents".
313 @item Windows: @file{@{INSTALLDIR@}/LilyPond/usr/share/lilypond/current/}
317 The @file{ly/} and @file{scm/} directories will be of
318 particular interest. Files such as @file{ly/property-init.ly} and
319 @file{ly/declarations-init.ly} define all the common tweaks.
322 @node Advanced tweaks with Scheme
323 @section Advanced tweaks with Scheme
325 We have seen how LilyPond output can be heavily modified using
327 @code{\override TextScript #'extra-offset = ( 1 . -1)}. But
328 we have even more power if we use Scheme. For a full explantion
329 of this, see the @ref{Scheme tutorial} and
330 @ref{Interfaces for programmers}.
332 We can use Scheme to simply @code{\override} commands,
334 @lilypond[quote,verbatim,ragged-right]
335 padText = #(define-music-function (parser location padding) (number?)
337 \once \override TextScript #'padding = #$padding
345 c4^"piu mosso" fis a g
349 We can use it to create new commands,
351 @lilypond[quote,verbatim,ragged-right]
352 tempoMark = #(define-music-function (parser location padding marktext)
355 \once \override Score . RehearsalMark #'padding = $padding
356 \once \override Score . RehearsalMark #'no-spacing-rods = ##t
357 \mark \markup { \bold $marktext }
362 \tempoMark #3.0 #"Allegro"
367 Even music expressions can be passed in.
369 @lilypond[quote,verbatim,ragged-right]
370 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
377 \pattern {d16 dis} { ais16-> b\p }