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