]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tweaks.itely
ea839d1113ad333de5c44fb2a35095bd4dbe21d1
[lilypond.git] / Documentation / user / tweaks.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Tweaking output
3 @chapter Tweaking output
4
5 This chapter discusses how to modify output.  LilyPond is extremely
6 configurable; virtually every fragment of output may be changed.
7
8
9 @menu
10 * Moving objects::              
11 * Fixing overlapping notation::  
12 * Common tweaks::               
13 * Default files::               
14 * Fitting music onto fewer pages::  
15 * Advanced tweaks with Scheme::  
16 @end menu
17
18
19 @node Moving objects
20 @section Moving objects
21
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
24 solved.
25
26 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
27 e4^\markup{ \italic ritenuto } g b e
28 @end lilypond
29
30 @cindex padding
31
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
38
39 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
40 \once \override TextScript #'padding = #1.5
41 e4^\markup{ \italic ritenuto } g b e
42 @end lilypond
43
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?
49
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
55 the behavior here.
56
57 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
58 c4^"piu mosso" b a b
59 \once \override TextScript #'padding = #2.6
60 c4^"piu mosso" d e f
61 \once \override TextScript #'staff-padding = #2.6
62 c4^"piu mosso" fis a g
63 \break
64 c'4^"piu mosso" b a b
65 \once \override TextScript #'padding = #2.6
66 c4^"piu mosso" d e f
67 \once \override TextScript #'staff-padding = #2.6
68 c4^"piu mosso" fis a g
69 @end lilypond
70
71 @cindex extra-offset
72
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
78 means
79 that the result can overlap with other objects.
80
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
84 @end lilypond
85
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
90
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
94 @end lilypond
95
96 @noindent
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!
100
101 One final warning: in this section, we used
102
103 @example
104 \once \override TextScript @dots{}
105 @end example
106
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}.
113
114 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
115 c4^"piu mosso" b
116 \once \override TextScript #'padding = #2.6
117   a4 b
118 c4^"piu mosso" d e f
119 \once \override TextScript #'padding = #2.6
120 c4^"piu mosso" d e f
121 c4^"piu mosso" d e f
122 \break
123 \override TextScript #'padding = #2.6
124 c4^"piu mosso" d e f
125 c4^"piu mosso" d e f
126 \revert TextScript #'padding
127 c4^"piu mosso" d e f
128 @end lilypond
129
130 @seealso
131
132 This manual: @ref{The \override command}, @ref{Common tweaks}.
133
134
135 @node Fixing overlapping notation
136 @section Fixing overlapping notation
137
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
141 another object.
142
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
146
147 @quotation
148 @seealso
149
150 Program reference: @internalsref{DynamicText}, @internalsref{Hairpin}.
151 Vertical positioning of these symbols is handled by
152 @internalsref{DynamicLineSpanner}.
153 @end quotation
154
155 @noindent
156 So to move dynamics around vertically, we use
157
158 @example
159 \override DynamicLineSpanner #'padding = #2.0
160 @end example
161
162 We cannot list every object, but here is a list of the most
163 common objects.
164
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}
175 @end multitable
176
177
178 @node Common tweaks
179 @section Common tweaks
180
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
184 sections.
185
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.
190
191 @itemize @bullet
192
193 @cindex padding
194
195 @item
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}.
200
201 @lilypond[quote,fragment,relative=1,verbatim]
202 c2\fermata
203 \override Script #'padding = #3
204 b2\fermata
205 @end lilypond
206
207 @lilypond[quote,fragment,relative=1,verbatim]
208 % This will not work, see below:
209 \override MetronomeMark #'padding = #3
210 \tempo 4=120
211 c1
212 % This works:
213 \override Score.MetronomeMark #'padding = #3
214 \tempo 4=80
215 d1
216 @end lilypond
217
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}.
223
224 @cindex extra-offset
225
226 @item
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.
234
235 In the following example, the second fingering is moved a little to
236 the left, and 1.8 staff space downwards:
237
238 @lilypond[quote,fragment,relative=1,verbatim]
239 \stemUp
240 f-5
241 \once \override Fingering
242     #'extra-offset = #'(-0.3 . -1.8)
243 f-5
244 @end lilypond
245
246  @item
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.
251
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,
259
260 @lilypond[quote,fragment,relative=2]
261 << {
262   b8~ b8\noBeam
263 } \\ {
264   b[ g8]
265 } >>
266 @end lilypond
267
268 @noindent
269 and blanking the first up-stem in that voice, the tie appears to cross
270 voices:
271
272 @lilypond[quote,fragment,relative=2,verbatim]
273 << {
274   \once \override Stem #'transparent = ##t
275   b8~ b8\noBeam
276 } \\ {
277   b[ g8]
278 } >>
279 @end lilypond
280
281 @end itemize
282
283 @cindex Tweaks, distances
284 @cindex Distances
285
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.
291
292
293 @node Default files
294 @section Default files
295
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.
299
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.
307
308 @itemize @bullet
309
310 @item Linux: @file{@{INSTALLDIR@}/lilypond/usr/share/lilypond/current/}
311
312 @item OSX:
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".
317
318 @item Windows: @file{@{INSTALLDIR@}/LilyPond/usr/share/lilypond/current/}
319
320 @end itemize
321
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.
325
326
327 @node Fitting music onto fewer pages
328 @section Fitting music onto fewer pages
329
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.
334
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.
340
341 Other than margins, there are a few other options to save space:
342
343 @itemize
344 @item
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.
349
350 @example
351 \paper @{
352 between-system-padding = #0.1
353 between-system-space = #0.1
354 ragged-last-bottom = ##f
355 ragged-bottom = ##f
356 @}
357 @end example
358
359 @item
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
362 use 10).
363
364 @example
365 \paper @{
366 system-count = #10
367 @}
368 @end example
369
370 @item
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.
376
377 Another example is moving dynamics which ``stick out'' of
378 a system.
379
380 @lilypond[verbatim,quote,fragment]
381 \relative c' {
382   e4 c g\f c
383   \override DynamicLineSpanner #'padding = #-1.8
384   \override DynamicText #'extra-offset = #'( -2.1 . 0)
385   e4 c g\f c
386 }
387 @end lilypond
388
389 @item
390 Alter the horizontal spacing via @code{SpacingSpanner}.  See
391 @ref{Changing horizontal spacing} for more details.
392
393 @lilypond[verbatim,quote]
394 \score {
395   \relative c'' {
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 |
400   }
401   \layout {
402     \context {
403       \Score
404       \override SpacingSpanner
405                 #'base-shortest-duration = #(ly:make-moment 1 4)
406     }
407   }
408 }
409 @end lilypond
410
411 @end itemize
412
413
414 @node Advanced tweaks with Scheme
415 @section Advanced tweaks with Scheme
416
417 We have seen how LilyPond output can be heavily modified using
418 commands like
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}.
423
424 We can use Scheme to simply @code{\override} commands,
425
426 @lilypond[quote,verbatim,ragged-right]
427 padText = #(define-music-function (parser location padding) (number?)
428 #{
429   \once \override TextScript #'padding = #$padding
430 #})
431
432 \relative c''' {
433   c4^"piu mosso" b a b
434   \padText #1.8
435   c4^"piu mosso" d e f
436   \padText #2.6
437   c4^"piu mosso" fis a g
438 }
439 @end lilypond
440
441 We can use it to create new commands,
442
443 @lilypond[quote,verbatim,ragged-right]
444 tempoMark = #(define-music-function (parser location padding marktext)
445                                     (number? string?)
446 #{
447   \once \override Score . RehearsalMark #'padding = $padding
448   \once \override Score . RehearsalMark #'no-spacing-rods = ##t
449   \mark \markup { \bold $marktext }
450 #})
451
452 \relative c'' {
453 c2 e
454 \tempoMark #3.0 #"Allegro"
455 g c
456 }
457 @end lilypond
458
459 Even music expressions can be passed in.
460
461 @lilypond[quote,verbatim,ragged-right]
462 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
463 #{
464   $x e8 a b $y b a e
465 #})
466
467 \relative c''{
468   \pattern c8 c8\f
469   \pattern {d16 dis} { ais16-> b\p }
470 }
471 @end lilypond
472