]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tweaks.itely
Merge with master
[lilypond.git] / Documentation / user / tweaks.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 @node Tweaking output
11 @chapter Tweaking output
12
13 This chapter discusses how to modify output.  LilyPond is extremely
14 configurable; virtually every fragment of output may be changed.
15
16
17 @menu
18 * Moving objects::              
19 * Fixing overlapping notation::  
20 * Common tweaks::               
21 * Default files::               
22 * Fitting music onto fewer pages::  
23 * Advanced tweaks with Scheme::  
24 * Avoiding tweaks with slower processing::  
25 @end menu
26
27
28 @node Moving objects
29 @section Moving objects
30
31 This may come as a surprise, but LilyPond is not perfect.  Some notation
32 elements can overlap.  This is unfortunate, but (in most cases) is easily
33 solved.
34
35 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
36 e4^\markup{ \italic ritenuto } g b e
37 @end lilypond
38
39 @cindex padding
40
41 The easiest solution is to increase the distance between the object
42 (in this case text, but it could easily be fingerings or dynamics
43 instead) and the note.  In LilyPond, this is called the
44 @code{padding} property; it is measured in staff spaces.  For most
45 objects, this value is around 1.0 or less (it varies with each
46 object). We want to increase it, so let's try 1.5
47
48 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
49 \once \override TextScript #'padding = #1.5
50 e4^\markup{ \italic ritenuto } g b e
51 @end lilypond
52
53 That looks better, but it isn't quite big enough.  After experimenting
54 with a few values, we think 2.3 is the best number in this case.  However,
55 this number is merely the result of experimentation and my personal
56 taste in notation.  Try the above example with 2.3... but also try higher
57 (and lower) numbers.  Which do you think looks the best?
58
59 The @code{staff-padding} property is closely related.  @code{padding}
60 controls the minimum amount of space between an object and the nearest
61 other object (generally the note or the staff lines);
62 @code{staff-padding} controls the minimum amount of space between an
63 object and the staff.  This is a subtle difference, but you can see
64 the behavior here.
65
66 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
67 c4^"piu mosso" b a b
68 \once \override TextScript #'padding = #2.6
69 c4^"piu mosso" d e f
70 \once \override TextScript #'staff-padding = #2.6
71 c4^"piu mosso" fis a g
72 \break
73 c'4^"piu mosso" b a b
74 \once \override TextScript #'padding = #2.6
75 c4^"piu mosso" d e f
76 \once \override TextScript #'staff-padding = #2.6
77 c4^"piu mosso" fis a g
78 @end lilypond
79
80 @cindex extra-offset
81
82 Another solution gives us complete control over placing the object -- we
83 can move it horizontally or vertically.  This is done with the
84 @code{extra-offset} property.  It is slightly more complicated and can
85 cause other problems.  When we move objects with @code{extra-offset},
86 the movement is done after LilyPond has placed all other objects.  This
87 means
88 that the result can overlap with other objects.
89
90 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
91 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
92 e4^\markup{ \italic ritenuto } g b e
93 @end lilypond
94
95 With @code{extra-offset}, the first number controls the horizontal
96 movement (left is negative); the second number controls the vertical
97 movement (up is positive).  After a bit of experimenting, we decided
98 that these values look good
99
100 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
101 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
102 e4^\markup{ \italic ritenuto } g b e
103 @end lilypond
104
105 @noindent
106 Again, these numbers are simply the result of a few experiments and
107 looking at the output.  You might prefer the text to be slightly higher,
108 or to the left, or whatever.  Try it and look at the result!
109
110 One final warning: in this section, we used
111
112 @example
113 \once \override TextScript @dots{}
114 @end example
115
116 This tweaks the display of text for the next note.  If the note has
117 no text, this tweak does nothing (and does @strong{not} wait until
118 the next bit of text).  To change the behavior of everything after
119 the command, omit the @code{\once}.  To stop this tweak, use a
120 @code{\revert}.  This is explained in depth in
121 @ref{The \override command}.
122
123 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
124 c4^"piu mosso" b
125 \once \override TextScript #'padding = #2.6
126   a4 b
127 c4^"piu mosso" d e f
128 \once \override TextScript #'padding = #2.6
129 c4^"piu mosso" d e f
130 c4^"piu mosso" d e f
131 \break
132 \override TextScript #'padding = #2.6
133 c4^"piu mosso" d e f
134 c4^"piu mosso" d e f
135 \revert TextScript #'padding
136 c4^"piu mosso" d e f
137 @end lilypond
138
139 @seealso
140
141 This manual: @ref{The \override command}, @ref{Common tweaks}.
142
143
144 @node Fixing overlapping notation
145 @section Fixing overlapping notation
146
147 In @ref{Moving objects}, we saw how to move a @code{TextScript}
148 object.  The same mechanism can be used to move other types of
149 objects; simply replace @code{TextScript} with the name of
150 another object.
151
152 To find the object name, look at the @q{@strong{see also}} at
153 bottom of the relevant documentation page.  For example, at
154 the bottom of @ref{Dynamics}, we see
155
156 @quotation
157 @seealso
158
159 Program reference: @internalsref{DynamicText}, @internalsref{Hairpin}.
160 Vertical positioning of these symbols is handled by
161 @internalsref{DynamicLineSpanner}.
162 @end quotation
163
164 @noindent
165 So to move dynamics around vertically, we use
166
167 @example
168 \override DynamicLineSpanner #'padding = #2.0
169 @end example
170
171 We cannot list every object, but here is a list of the most
172 common objects.
173
174 @multitable @columnfractions .33 .66
175 @headitem Object type           @tab Object name
176 @item Dynamics (vertically)     @tab @code{DynamicLineSpanner}
177 @item Dynamics (horizontally)   @tab @code{DynamicText}
178 @item Ties                      @tab @code{Tie}
179 @item Slurs                     @tab @code{Slur}
180 @item Articulations             @tab @code{Script}
181 @item Fingerings                @tab @code{Fingering}
182 @item Text e.g. @code{^"text"}  @tab @code{TextScript}
183 @item Rehearsal / Text marks    @tab @code{RehearsalMark}
184 @end multitable
185
186
187 @node Common tweaks
188 @section Common tweaks
189
190 Some overrides are so common that predefined commands are provided as
191 short-cuts, such as @code{\slurUp} and @code{\stemDown}.  These
192 commands are described in the Notation Reference under the appropriate
193 sections.
194
195 The complete list of modifications available for each type of
196 object (like slurs or beams) are documented in the Program
197 Reference.  However, many layout objects share properties which can be
198 used to apply generic tweaks.
199
200 @itemize @bullet
201
202 @cindex padding
203
204 @item
205 The @code{padding} property can be set to increase
206 (or decrease) the distance between symbols that are printed
207 above or below notes.  This applies to all objects with
208 @code{side-position-interface}.
209
210 @lilypond[quote,fragment,relative=1,verbatim]
211 c2\fermata
212 \override Script #'padding = #3
213 b2\fermata
214 @end lilypond
215
216 @lilypond[quote,fragment,relative=1,verbatim]
217 % This will not work, see below:
218 \override MetronomeMark #'padding = #3
219 \tempo 4=120
220 c1
221 % This works:
222 \override Score.MetronomeMark #'padding = #3
223 \tempo 4=80
224 d1
225 @end lilypond
226
227 Note in the second example how important it is to figure out what
228 context handles a certain object.  Since the @code{MetronomeMark} object
229 is handled in the @code{Score} context, property changes in the
230 @code{Voice} context will not be noticed.  For more details, see
231 @ref{Constructing a tweak}.
232
233 @cindex extra-offset
234
235 @item
236 The @code{extra-offset} property moves objects around
237 in the output; it requires a pair of numbers.  The first number
238 controls horizontal movement; a positive number will
239 move the object to the right.  The second number controls vertical
240 movement; a positive number will move it higher.  The
241 @code{extra-offset} property is a low-level feature: the
242 formatting engine is completely oblivious to these offsets.
243
244 In the following example, the second fingering is moved a little to
245 the left, and 1.8 staff space downwards:
246
247 @lilypond[quote,fragment,relative=1,verbatim]
248 \stemUp
249 f-5
250 \once \override Fingering
251     #'extra-offset = #'(-0.3 . -1.8)
252 f-5
253 @end lilypond
254
255 @item
256 Setting the @code{transparent} property will cause an object to be printed
257 in @q{invisible ink}: the object is not printed, but all its other
258 behavior is retained.  The object still takes up space, it takes part in
259 collisions, and slurs, ties, and beams can be attached to it.
260
261 @cindex transparent objects
262 @cindex removing objects
263 @cindex hiding objects
264 @cindex invisible objects
265 The following example demonstrates how to connect different voices
266 using ties.  Normally, ties only connect two notes in the same
267 voice.  By introducing a tie in a different voice,
268
269 @lilypond[quote,fragment,relative=2]
270 << {
271   b8~ b8\noBeam
272 } \\ {
273   b[ g8]
274 } >>
275 @end lilypond
276
277 @noindent
278 and blanking the first up-stem in that voice, the tie appears to cross
279 voices:
280
281
282 @lilypond[quote,fragment,relative=2,verbatim]
283 << {
284   \once \override Stem #'transparent = ##t
285   b8~ b8\noBeam
286 } \\ {
287   b[ g8]
288 } >>
289 @end lilypond
290
291 To make sure that the just blanked stem doesn't sqeeuze the too much
292 tie, we also lengthen the stem, by setting the @code{length} to
293 @code{8},
294
295 @lilypond[quote,fragment,relative=2,verbatim]
296 << {
297   \once \override Stem #'transparent = ##t
298   \once \override Stem #'length = #8
299   b8~ b8\noBeam
300 } \\ {
301   b[ g8]
302 } >>
303 @end lilypond
304
305 @end itemize
306
307 @cindex Tweaks, distances
308 @cindex Distances
309
310 Distances in LilyPond are measured in staff-spaces, while most
311 thickness properties are measured in line-thickness.  Some
312 properties are different; for example, the thickness of beams
313 are measured in staff-spaces.  For more information, see the
314 relevant portion of the program reference.
315
316
317 @node Default files
318 @section Default files
319
320 The Program Reference documentation contains a lot of information
321 about LilyPond, but even more information can be gathered from
322 looking at the internal LilyPond files.
323
324 Some default settings (such as the definitions for
325 @code{\header@{@}}s) are stored as @code{.ly} files.  Other
326 settings (such as the definitions of markup commands) are
327 stored as @code{.scm} (Scheme) files.  Further explanation is
328 outside the scope of this manual; users should be warned that
329 a substantial amount of technical knowledge or time is required
330 to understand these files.
331
332 @itemize @bullet
333
334 @item Linux: @file{@var{installdir}/lilypond/usr/share/lilypond/current/}
335
336 @item OSX:
337 @file{@var{installdir}/LilyPond.app/Contents/Resources/share/lilypond/current/}.
338 To access this, either @code{cd} into this directory from the
339 Terminal, or control-click on the LilyPond application and select
340 "Show Package Contents".
341
342 @item Windows: @file{@var{installdir}/LilyPond/usr/share/lilypond/current/}
343
344 @end itemize
345
346 The @file{ly/} and @file{scm/} directories will be of
347 particular interest.  Files such as @file{ly/property-init.ly} and
348 @file{ly/declarations-init.ly} define all the common tweaks.
349
350
351 @node Fitting music onto fewer pages
352 @section Fitting music onto fewer pages
353
354 Sometimes you can end up with one or two staves on a second
355 (or third, or fourth...) page.  This is annoying, especially
356 if you look at previous pages and it looks like there is plenty
357 of room left on those.
358
359 When investigating layout issues, @code{annotate-spacing} is
360 an invaluable tool.  This command prints the values of various
361 layout spacing commands; see @ref{Displaying spacing} for more
362 details.  From the output of @code{annotate-spacing}, we can
363 see which margins we may wish to alter.
364
365 Other than margins, there are a few other options to save space:
366
367 @itemize
368 @item
369 You may tell LilyPond to place systems as close together as
370 possible (to fit as many systems as possible onto a page), but
371 then to space those systems out so that there is no blank
372 space at the bottom of the page.
373
374 @example
375 \paper @{
376 between-system-padding = #0.1
377 between-system-space = #0.1
378 ragged-last-bottom = ##f
379 ragged-bottom = ##f
380 @}
381 @end example
382
383 @item
384 You may force the number of systems (i.e., if LilyPond wants
385 to typeset some music with 11 systems, you could force it to
386 use 10).
387
388 @example
389 \paper @{
390 system-count = #10
391 @}
392 @end example
393
394 @item
395 Avoid (or reduce) objects which increase the vertical size of
396 a system.  For example, volta repeats (or alternate repeats)
397 require extra space.  If these repeats are spread over two
398 systems, they will take up more space than one system with
399 the volta repeats and another system without.
400
401 Another example is moving dynamics which @q{stick out} of
402 a system.
403
404 @lilypond[verbatim,quote,fragment]
405 \relative c' {
406   e4 c g\f c
407   \override DynamicLineSpanner #'padding = #-1.8
408   \override DynamicText #'extra-offset = #'( -2.1 . 0)
409   e4 c g\f c
410 }
411 @end lilypond
412
413 @item
414 Alter the horizontal spacing via @code{SpacingSpanner}.  See
415 @ref{Changing horizontal spacing} for more details.
416
417 @lilypond[verbatim,quote]
418 \score {
419   \relative c'' {
420     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
421     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
422     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
423     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
424   }
425   \layout {
426     \context {
427       \Score
428       \override SpacingSpanner
429                 #'base-shortest-duration = #(ly:make-moment 1 4)
430     }
431   }
432 }
433 @end lilypond
434
435 @end itemize
436
437
438 @node Advanced tweaks with Scheme
439 @section Advanced tweaks with Scheme
440
441 We have seen how LilyPond output can be heavily modified using
442 commands like
443 @code{\override TextScript #'extra-offset = ( 1 . -1)}.  But
444 we have even more power if we use Scheme.  For a full explantion
445 of this, see the @ref{Scheme tutorial} and
446 @ref{Interfaces for programmers}.
447
448 We can use Scheme to simply @code{\override} commands,
449
450 @lilypond[quote,verbatim,ragged-right]
451 padText = #(define-music-function (parser location padding) (number?)
452 #{
453   \once \override TextScript #'padding = #$padding
454 #})
455
456 \relative c''' {
457   c4^"piu mosso" b a b
458   \padText #1.8
459   c4^"piu mosso" d e f
460   \padText #2.6
461   c4^"piu mosso" fis a g
462 }
463 @end lilypond
464
465 We can use it to create new commands,
466
467 @lilypond[quote,verbatim,ragged-right]
468 tempoMark = #(define-music-function (parser location padding marktext)
469                                     (number? string?)
470 #{
471   \once \override Score . RehearsalMark #'padding = $padding
472   \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
473   \mark \markup { \bold $marktext }
474 #})
475
476 \relative c'' {
477 c2 e
478 \tempoMark #3.0 #"Allegro"
479 g c
480 }
481 @end lilypond
482
483 Even music expressions can be passed in.
484
485 @lilypond[quote,verbatim,ragged-right]
486 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
487 #{
488   $x e8 a b $y b a e
489 #})
490
491 \relative c''{
492   \pattern c8 c8\f
493   \pattern {d16 dis} { ais16-> b\p }
494 }
495 @end lilypond
496
497
498 @node Avoiding tweaks with slower processing
499 @section Avoiding tweaks with slower processing
500
501 LilyPond can perform extra checks while it processes files.  These
502 commands will take extra time, but the result may require fewer
503 manual tweaks.
504
505 @example
506 %%  makes sure text scripts and lyrics are within the paper margins
507 \override Score.PaperColumn #'keep-inside-line = ##t 
508 @end example
509
510
511