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