]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
Misc editing, rearranging.
[lilypond.git] / Documentation / user / changing-defaults.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Changing defaults
3 @chapter Changing defaults
4
5
6 The purpose of LilyPond's design is to provide the finest output
7 quality as a default.  Nevertheless, it may happen that you need to
8 change this default layout.  The layout is controlled through a large
9 number of proverbial ``knobs and switches.''  This chapter does not
10 list each and every knob.  Rather, it outlines what groups of controls
11 are available and explains how to lookup which knob to use for a
12 particular effect.
13
14
15 @cindex Program reference
16
17 The controls available for tuning are described in a separate
18 document, the
19 @iftex
20 Program reference
21 @end iftex
22 @ifnottex
23 @ref{Top,Program reference,,lilypond-internals}.
24 @end ifnottex
25 manual.  That manual
26 lists all different variables, functions and options available in
27 LilyPond.  It is written as a HTML document, which is available
28 @uref{http://@/lilypond@/.org/@/doc/@/v2.5/@/Documentation/@/user/@/out@/-www/@/lilypond@/-internals/,on@/-line},
29 but is also included with the LilyPond documentation package.
30
31 There are three areas where the default settings may be changed:
32
33 @itemize @bullet
34 @item
35 Output: changing the appearance of individual
36 objects.  For example, changing stem directions or the location of
37 subscripts.
38   
39 @item
40 Context: changing aspects of the translation from music events to
41 notation.  For example, giving each staff a separate time signature. 
42   
43 @item
44 Global layout: changing the appearance of the spacing, line
45 breaks, and page dimensions.
46 @end itemize
47
48 Then there are separate systems for typesetting text (like
49 @emph{ritardando}) and selecting different fonts.  This chapter also
50 discusses these.
51
52 Internally, LilyPond uses Scheme (a LISP dialect) to provide
53 infrastructure.  Overriding layout decisions in effect accesses the
54 program internals, which requires Scheme input.  Scheme elements are
55 introduced in a @code{.ly} file with the hash mark
56 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
57 on entering numbers, lists, strings, and symbols in Scheme.}
58
59
60 @menu
61 * Interpretation contexts::     
62 * The \override command::       
63 @end menu
64
65  
66 @node Interpretation contexts
67 @section Interpretation contexts
68
69 When music is printed, a lot of notational elements must be added to the
70 input, which is often bare bones.  For example, compare the input and
71 output of the following example:
72
73 @lilypond[quote,verbatim,relative=2,fragment]
74 cis4 cis2. g4
75 @end lilypond
76
77 The input is rather sparse, but in the output, bar lines, accidentals,
78 clef, and time signature are added.  LilyPond @emph{interprets} the
79 input.  During this step, the musical information is inspected in time
80 order, similar to reading a score from left to right.  While reading,
81 the input, the program remembers where measure boundaries are, and what
82 pitches need explicit accidentals.  This information can be presented on
83 several levels.  For example, the effect of an accidental is limited
84 to a single staff, while a bar line must be synchronized across the
85 entire score.
86
87 Within LilyPond, these rules and bits of information are grouped in
88 so-called Contexts.  Examples of context are @context{Voice},
89 @context{Staff}, and @context{Score}.  They are hierarchical, for
90 example, a @context{Staff} can contain many @context{Voice}s, and a
91 @context{Score} can contain many @context{Staff} contexts.
92
93 Each context has the responsibility for enforcing some notation rules,
94 creating some notation objects and maintaining the associated
95 properties.  So, the synchronization of bar lines is handled at
96 @context{Score} context.  The @context{Voice} may introduce an
97 accidental and then the @context{Staff} context maintains the rule to
98 show or suppress the accidental for the remainder of the measure.
99
100 For simple scores, contexts are created implicitly, and you need not
101 be aware of them.  For larger pieces, such as piano music, they must be
102 created explicitly to make sure that you get as many staves as you
103 need, and that they are in the correct order.  For typesetting pieces
104 with specialized notation, it can be useful to modify existing or
105 to define new contexts.
106
107
108 A complete description of all available contexts is in the program
109 reference, see
110 @ifhtml
111 @internalsref{Contexts}.
112 @end ifhtml
113 @ifnothtml 
114 Translation @arrow{} Context.
115 @end ifnothtml
116
117 @c [TODO: describe propagation]
118
119
120 @menu
121 * Creating contexts::           
122 * Changing context properties on the fly::  
123 * Modifying context plug-ins::  
124 * Layout tunings within contexts::  
125 * Changing context default settings::  
126 * Defining new contexts::       
127 @end menu
128
129 @node Creating contexts
130 @subsection Creating contexts
131
132 For scores with only one voice and one staff, correct contexts are
133 created automatically.  For more complex scores, it is necessary to
134 create them by hand.  There are three commands that do this.
135
136 The easiest command is @code{\new}, and it also the quickest to type.
137 It is prepended to a music expression, for example
138
139 @cindex @code{\new}
140 @cindex new contexts
141 @cindex Context, creating
142
143 @example
144 \new @var{type} @var{music expression}
145 @end example
146
147 @noindent
148 where @var{type} is a context name (like @code{Staff} or
149 @code{Voice}).  This command creates a new context, and starts
150 interpreting the @var{music expression} with that.
151
152 A practical application of @code{\new} is a score with many
153 staves.  Each part that should be on its own staff, is preceded with 
154 @code{\new Staff}.
155
156 @lilypond[quote,verbatim,relative=2,raggedright,fragment]
157 << \new Staff { c4 c }
158    \new Staff { d4 d }
159 >>
160 @end lilypond
161
162 @cindex @code{\context}
163
164 Like @code{\new}, the @code{\context} command also directs a music
165 expression to a context object, but gives the context an extra name.  The
166 syntax is
167
168 @example
169 \context @var{type} = @var{id} @var{music}
170 @end example
171
172 This form will search for an existing context of type @var{type}
173 called @var{id}.  If that context does not exist yet, it is created.
174 This is useful if the context is referred to later on.  For example, when
175 setting lyrics the melody is in a named context
176
177 @example
178 \context Voice = "@b{tenor}" @var{music}
179 @end example
180
181 @noindent
182 so the texts can be properly aligned to its notes,
183
184 @example
185 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics} 
186 @end example
187
188 @noindent
189
190 Another possibility is funneling two different music expressions into
191 one context.  In the following example, articulations and notes are
192 entered separately,
193
194 @example
195 music = @{ c4 c4 @}
196 arts = @{ s4-. s4-> @}
197 @end example
198
199 They are combined by sending both to the same @context{Voice} context,
200
201 @example
202 << \new Staff \context Voice = "A" \music
203    \context Voice = "A" \arts
204 >>
205 @end example
206 @lilypond[quote,raggedright]
207 music = { c4 c4 }
208 arts = { s4-. s4-> }
209 \relative c'' <<
210   \new Staff \context Voice = "A" \music
211   \context Voice = "A" \arts
212 >>
213 @end lilypond
214
215 With this mechanism, it is possible to define an Urtext (original
216 edition), with the option to put several distinct articulations on the
217 same notes.
218
219 @cindex creating contexts
220
221 The third command for creating contexts is
222 @example
223 \context @var{type} @var{music}
224 @end example
225
226
227 @noindent
228 This is similar to @code{\context} with @code{= @var{id}}, but matches
229 any context of type @var{type}, regardless of its given name.
230
231 This variant is used with music expressions that can be interpreted at
232 several levels.  For example, the @code{\applyoutput} command (see
233 @ref{Running a function on all layout objects}).  Without an explicit
234 @code{\context}, it is usually applied to @context{Voice}
235
236 @example
237 \applyoutput #@var{function}   % apply to Voice
238 @end example
239
240 To have it interpreted at the @context{Score} or @context{Staff} level use
241 these forms
242
243 @example
244 \context Score \applyoutput #@var{function}
245 \context Staff \applyoutput #@var{function}
246 @end example
247
248
249 @node Changing context properties on the fly
250 @subsection Changing context properties on the fly
251
252 @cindex properties
253 @cindex @code{\set}
254 @cindex changing properties
255
256 Each context can have different @emph{properties}, variables contained
257 in that context.  They can be changed during the interpretation step.
258 This is achieved by inserting the @code{\set} command in the music,
259
260 @example
261 \set @var{context}.@var{prop} = #@var{value}
262 @end example
263
264 For example,
265 @lilypond[quote,verbatim,relative=2,fragment]
266 R1*2 
267 \set Score.skipBars = ##t
268 R1*2
269 @end lilypond
270
271 This command skips measures that have no notes.  The result is that
272 multi-rests are condensed.  The value assigned is a Scheme object.  In
273 this case, it is @code{#t}, the boolean True value.
274
275 If the @var{context} argument is left out, then the current bottom-most
276 context (typically @context{ChordNames}, @context{Voice}, or
277 @context{Lyrics}) is used.  In this example,
278
279 @lilypond[quote,verbatim,relative=2,fragment]
280 c8 c c c
281 \set autoBeaming = ##f
282 c8 c c c
283 @end lilypond
284
285 @noindent
286 the @var{context} argument to @code{\set} is left out, so automatic
287 beaming is switched off in the current @internalsref{Voice}.  Note that
288 the bottom-most context does not always contain the property that you
289 wish to change -- for example, attempting to set the @code{skipBars}
290 property (of the bottom-most context, in this case @code{Voice}) will
291 have no effect.
292
293 @lilypond[quote,verbatim,relative=2,fragment]
294 R1*2 
295 \set skipBars = ##t
296 R1*2
297 @end lilypond
298
299 Contexts are hierarchical, so if a bigger context was specified, for
300 example @context{Staff}, then the change would also apply to all
301 @context{Voice}s in the current stave.  The change is applied
302 `on-the-fly', during the music, so that the setting only affects the
303 second group of eighth notes.
304
305 @cindex @code{\unset} 
306
307 There is also an @code{\unset} command,
308 @example
309 \unset @var{context}.@var{prop}
310 @end example
311
312 @noindent
313 which removes the definition of @var{prop}.  This command removes
314 the definition only if it is set in @var{context}, so
315
316 @example
317 \set Staff.autoBeaming = ##f
318 @end example
319
320 @noindent
321 introduces a property setting at @code{Staff} level.  The setting also
322 applies to the current @code{Voice}.  However,
323
324 @example
325 \unset Voice.autoBeaming
326 @end example
327
328 @noindent
329 does not have any effect.  To cancel this setting, the @code{\unset}
330 must be specified on the same level as the original @code{\set}.  In
331 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
332 requires
333 @example
334 \unset Staff.autoBeaming
335 @end example
336
337 Like @code{\set}, the @var{context} argument does not have to be
338 specified for a bottom context, so the two statements
339
340 @example
341 \set Voice.autoBeaming = ##t 
342 \set autoBeaming = ##t 
343 @end example 
344
345 @noindent
346 are equivalent.
347
348
349 @cindex \once
350 Settings that should only apply to a single time-step can be entered
351 with @code{\once}, for example in
352
353 @lilypond[quote,verbatim,relative=2,fragment]
354 c4
355 \once \set fontSize = #4.7
356 c4
357 c4
358 @end lilypond
359
360 the property @code{fontSize} is unset automatically after the second
361 note.
362
363 A full description of all available context properties is in the
364 program reference, see
365 @ifhtml
366 @internalsref{Tunable context properties}.
367 @end ifhtml
368 @ifnothtml
369 Translation @arrow{} Tunable context properties.
370 @end ifnothtml
371
372
373 @node Modifying context plug-ins
374 @subsection Modifying context plug-ins
375
376 Notation contexts (like Score and Staff) not only store properties,
377 they also contain plug-ins, called ``engravers'' that create notation
378 elements.  For example, the Voice context contains a
379 @code{Note_head_engraver} and the Staff context contains a
380 @code{Key_signature_engraver}.
381
382 For a full a description of each plug-in, see 
383 @ifhtml
384 @internalsref{Engravers}.
385 @end ifhtml
386 @ifnothtml
387 Program reference @arrow Translation @arrow{} Engravers.
388 @end ifnothtml
389 Every context described in
390 @ifhtml
391 @internalsref{Contexts}
392 @end ifhtml
393 @ifnothtml 
394 Program reference @arrow Translation @arrow{} Context.
395 @end ifnothtml
396 lists the engravers used for that context.
397
398
399 It can be useful to shuffle around these plug-ins.  This is done by
400 starting a new context, with @code{\new} or @code{\context}, and
401 modifying it like this, 
402
403 @example
404 \new @var{context} \with @{
405   \consists @dots{}
406   \consists @dots{}
407   \remove @dots{}
408   \remove @dots{}
409   @emph{etc.}
410 @}
411 @emph{..music..}
412 @end example
413
414 @noindent
415 where the @dots{} should be the name of an engraver.  Here is a simple
416 example which removes @code{Time_signature_engraver} and
417 @code{Clef_engraver} from a @code{Staff} context,
418
419 @lilypond[quote,relative=1,verbatim,fragment]
420 << \new Staff {
421     f2 g
422   }
423   \new Staff \with {
424      \remove "Time_signature_engraver"
425      \remove "Clef_engraver"
426   } {
427     f2 g2
428   }
429 >>
430 @end lilypond
431
432 In the second staff there are no time signature or clef symbols.  This
433 is a rather crude method of making objects disappear since it will affect
434 the entire staff.  The spacing is adversely influenced too.  A more
435 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
436
437 The next example shows a practical application.  Bar lines and time
438 signatures are normally synchronized across the score.  This is done
439 by the @code{Timing_engraver}.  This plug-in keeps an administration of
440 time signature, location within the measure, etc.  By moving the
441 @code{Timing_engraver} engraver from @code{Score} to @code{Staff}
442 context, we can have a score where each staff has its own time
443 signature.
444
445 @cindex polymetric scores
446 @cindex Time signatures, multiple
447
448 @lilypond[quote,relative=1,raggedright,verbatim,fragment]
449 \new Score \with {
450   \remove "Timing_engraver"
451 } <<
452   \new Staff \with {
453     \consists "Timing_engraver"
454   } {
455       \time 3/4
456       c4 c c c c c
457   }
458   \new Staff \with {
459     \consists "Timing_engraver"
460   } {
461        \time 2/4
462        c4 c c c c c
463   }
464 >>
465 @end lilypond
466
467
468 @node Layout tunings within contexts
469 @subsection Layout tunings within contexts
470
471 Each context is responsible for creating certain types of graphical
472 objects.  The settings used for printing these objects are also stored by
473 context.  By changing these settings, the appearance of objects can be
474 altered.
475  
476 The syntax for this is
477
478 @example
479 \override @var{context}.@var{name} #'@var{property} = #@var{value}
480 @end example
481
482 Here @var{name} is the name of a graphical object, like @code{Stem} or
483 @code{NoteHead}, and @var{property} is an internal variable of the
484 formatting system (`grob property' or `layout property').  The latter is a
485 symbol, so it must be quoted.  The subsection @ref{Constructing a
486 tweak} explains what to fill in for @var{name}, @var{property}, and
487 @var{value}.  Here we only discuss the functionality of this command.
488
489 The command
490
491 @verbatim
492 \override Staff.Stem #'thickness = #4.0 
493 @end verbatim
494
495 @noindent
496 makes stems thicker (the default is 1.3, with staff line thickness as a
497 unit).  Since the command specifies @context{Staff} as context, it only
498 applies to the current staff.  Other staves will keep their normal
499 appearance.  Here we see the command in action:
500
501 @lilypond[quote,verbatim,relative=2,fragment]
502 c4
503 \override Staff.Stem #'thickness = #4.0 
504 c4
505 c4
506 c4
507 @end lilypond
508
509 The @code{\override} command changes the definition of the @code{Stem}
510 within the current @context{Staff}.  After the command is interpreted
511 all stems are thickened.
512
513 Analogous to @code{\set}, the @var{context} argument may be left out,
514 causing it to default to @context{Voice}, and adding @code{\once} applies
515 the change during one timestep only 
516
517 @lilypond[quote,fragment,verbatim,relative=2]
518 c4
519 \once \override Stem #'thickness = #4.0 
520 c4
521 c4 
522 @end lilypond
523
524 The @code{\override} must be done before the object is
525 started.  Therefore, when altering @emph{Spanner} objects, like slurs or
526 beams, the @code{\override} command must be executed at the moment when
527 the object is created.  In this example,
528
529
530 @lilypond[quote,fragment,verbatim,relative=2]
531 \override Slur #'thickness = #3.0
532 c8[( c
533 \override Beam #'thickness = #0.6
534 c8 c]) 
535 @end lilypond
536
537 @noindent
538 the slur is fatter but the beam is not.  This is because the command for
539 @code{Beam} comes after the Beam is started.  Therefore it has no effect.
540
541 Analogous to @code{\unset}, the @code{\revert} command for a context
542 undoes an @code{\override} command; like with @code{\unset}, it only
543 affects settings that were made in the same context.  In other words, the
544 @code{\revert} in the next example does not do anything.
545
546 @example
547 \override Voice.Stem #'thickness = #4.0
548 \revert Staff.Stem #'thickness
549 @end example
550
551
552
553
554 @seealso
555
556 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
557 @internalsref{PropertySet}, @internalsref{Backend}, and
558 @internalsref{All layout objects}.
559
560
561 @refbugs
562
563 The back-end is not very strict in type-checking object properties.
564 Cyclic references in Scheme values for properties can cause hangs
565 or crashes, or both.
566
567
568 @node Changing context default settings
569 @subsection Changing context default settings
570
571 The adjustments of the previous subsections (@ref{Changing context
572 properties on the fly}, @ref{Modifying context plug-ins}, and
573 @ref{Layout tunings within contexts}) can also be entered separately
574 from the music, in the @code{\layout} block,
575
576 @example
577 \layout @{
578   @dots{}
579   \context @{
580     \Staff
581
582     \set fontSize = #-2
583     \override Stem #'thickness = #4.0
584     \remove "Time_signature_engraver"
585   @}
586 @}
587 @end example
588
589 Here
590 @example
591 \Staff
592 @end example
593
594 @noindent
595 takes the existing definition for context @context{Staff} from the
596 identifier @code{\Staff}. 
597
598 The statements
599 @example
600 \set fontSize = #-2
601 \override Stem #'thickness = #4.0
602 \remove "Time_signature_engraver"
603 @end example
604
605 @noindent
606 affect all staves in the score.
607
608 Other contexts can be modified analogously.
609
610 The @code{\set} keyword is optional within the @code{\layout} block, so
611
612 @example
613 \context @{
614   @dots{}
615   fontSize = #-2
616 @}
617 @end example
618
619 @noindent
620 will also work.
621
622
623
624 @refbugs
625
626 It is not possible to collect context changes in a variable, and apply
627 them to one @code{\context} definition by referring to that variable.
628
629 The @code{\RemoveEmptyStaffContext} will override your current
630 @code{\Staff} variable.  If you wish to change the defaults for a
631 staff that uses @code{\RemoveEmptyStaffContext}, you must do so
632 after calling @code{\RemoveemptyStaffContext}, ie
633
634 @example
635 \layout @{
636   \context @{
637     \RemoveEmptyStaffContext
638
639     \override Stem #'thickness = #4.0
640   @}
641 @}
642 @end example
643
644
645 @node Defining new contexts
646 @subsection Defining new contexts
647
648 Specific contexts, like @context{Staff} and @code{Voice}, are made of
649 simple building blocks, and it is possible to compose engraver
650 plug-ins in different combinations, thereby creating new types of
651 contexts.
652
653 The next example shows how to build a different type of
654 @context{Voice} context from scratch.  It will be similar to
655 @code{Voice}, but prints centered slash noteheads only.  It can be used
656 to indicate improvisation in Jazz pieces,
657
658 @lilypond[quote,raggedright]
659 \layout { \context {
660   \name ImproVoice
661   \type "Engraver_group_engraver"
662   \consists "Note_heads_engraver"
663   \consists "Text_engraver"
664   \consists Pitch_squash_engraver
665   squashedPosition = #0
666   \override NoteHead #'style = #'slash
667   \override Stem #'transparent = ##t
668   \alias Voice
669 }
670 \context { \Staff
671   \accepts "ImproVoice"
672 }}
673
674 \relative c'' {
675   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c 
676    c4 c^"undress" c_"while playing :)" c } 
677   a1 
678 }
679 @end lilypond
680
681
682 These settings are again done within a @code{\context} block inside a
683 @code{\layout} block,
684
685 @example
686 \layout @{
687   \context @{
688     @dots{}
689   @}
690 @}
691 @end example
692
693 In the following discussion, the example input shown should go on the
694 @dots{} in the previous fragment.
695
696 First, the context gets a name.  Instead of @context{Voice} it
697 will be called @context{ImproVoice},
698
699 @example
700 \name ImproVoice
701 @end example
702
703 Since it is similar to the @context{Voice}, we want commands that work
704 on (existing) @context{Voice}s to remain working.  This is achieved by
705 giving the new context an alias @context{Voice},
706
707 @example
708 \alias Voice
709 @end example
710
711 The context will print notes, and instructive texts
712
713 @example
714 \consists Note_heads_engraver
715 \consists Text_engraver
716 @end example
717
718 but only on the center line,
719
720 @example
721 \consists Pitch_squash_engraver
722 squashedPosition = #0
723 @end example
724
725 The @internalsref{Pitch_squash_engraver} modifies note heads (created
726 by @internalsref{Note_heads_engraver}) and sets their vertical
727 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
728 the center line.
729
730 The notes look like a slash, without a stem,
731
732 @example
733 \override NoteHead #'style = #'slash
734 \override Stem #'transparent = ##t
735 @end example
736
737
738 All these plug-ins have to cooperate, and this is achieved with a
739 special plug-in, which must be marked with the keyword @code{\type}.
740 This should always be @internalsref{Engraver_group_engraver},
741
742 @example
743 \type "Engraver_group_engraver"
744 @end example
745
746 Put together, we get
747
748 @example
749 \context @{
750   \name ImproVoice
751   \type "Engraver_group_engraver"
752   \consists "Note_heads_engraver"
753   \consists "Text_engraver"
754   \consists Pitch_squash_engraver
755   squashedPosition = #0
756   \override NoteHead #'style = #'slash
757   \override Stem #'transparent = ##t
758   \alias Voice
759 @}
760 @end example
761
762 Contexts form hierarchies.  We want to hang the @context{ImproVoice}
763 under @context{Staff}, just like normal @code{Voice}s.  Therefore, we
764 modify the @code{Staff} definition with the @code{\accepts}
765 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
766 which is sometimes needed when reusing existing context definitions.}
767
768
769
770 @example
771 \context @{
772   \Staff
773   \accepts ImproVoice    
774 @}
775 @end example
776
777 Putting both into a @code{\layout} block, like
778
779 @example
780 \layout @{
781   \context @{
782     \name ImproVoice
783     @dots{}
784   @}
785   \context @{
786     \Staff
787     \accepts "ImproVoice"
788   @}
789 @}
790 @end example
791
792 Then the output at the start of this subsection can be entered as
793
794 @example
795 \relative c'' @{
796   a4 d8 bes8
797   \new ImproVoice @{
798     c4^"ad lib" c 
799     c4 c^"undress"
800     c c_"while playing :)"
801   @}
802   a1
803 @}
804 @end example
805   
806
807     
808
809 @node The \override command
810 @section The \override command
811
812 In the previous section, we have already touched on a command that
813 changes layout details: the @code{\override} command.  In this section,
814 we will look in more detail at how to use the command in practice.
815 First, we will give a few versatile commands that are sufficient
816 for many situations.  The next section will discuss the general use of
817 @code{\override}.
818
819
820 @menu
821 * Common tweaks::               
822 * Constructing a tweak::        
823 * Navigating the program reference::  
824 * Layout interfaces::           
825 * Determining the grob property::  
826 * Difficult tweaks::            
827 @end menu
828
829
830
831 @node Common tweaks
832 @subsection Common tweaks
833
834 @c  Should we point at ly/property-init.ly ?  -gp
835 Some overrides are so common that predefined commands are provided as
836 short-cuts, for example, @code{\slurUp} and @code{\stemDown}.  These
837 commands are described in
838 @ifhtml
839 the
840 @end ifhtml
841 @c @ref{Notation manual},
842 Notation manual
843 @c FIXME 
844 under the sections for slurs and stems
845 respectively.
846
847 The exact tuning possibilities for each type of layout object are
848 documented in the program reference of the respective
849 object.  However, many layout objects share properties, which can be
850 used to apply generic tweaks.  We mention a few of these:
851
852 @itemize @bullet
853 @item The @code{extra-offset} property, which
854 @cindex @code{extra-offset}
855 has a pair of numbers as value, moves objects around in the printout.
856 The first number controls left-right movement; a positive number will
857 move the object to the right.  The second number controls up-down
858 movement; a positive number will move it higher.  The units of these
859 offsets are staff-spaces.  The @code{extra-offset} property is a
860 low-level feature: the formatting engine is completely oblivious to
861 these offsets.
862
863 In the following example, the second fingering is moved a little to
864 the left, and 1.8 staff space downwards:
865
866 @cindex setting object properties
867
868 @lilypond[quote,fragment,relative=1,verbatim]
869 \stemUp
870 f-5
871 \once \override Fingering
872     #'extra-offset = #'(-0.3 . -1.8) 
873 f-5
874 @end lilypond
875
876 @item
877 Setting the @code{transparent} property will cause an object to be printed
878 in `invisible ink': the object is not printed, but all its other
879 behavior is retained.  The object still takes up space, it takes part in
880 collisions, and slurs, ties, and beams can be attached to it.
881
882 @cindex transparent objects
883 @cindex removing objects
884 @cindex hiding objects
885 @cindex invisible objects
886 The following example demonstrates how to connect different voices
887 using ties.  Normally, ties only connect two notes in the same
888 voice.  By introducing a tie in a different voice,
889
890 @lilypond[quote,fragment,relative=2]
891 << {
892   b8~ b8\noBeam
893 } \\ {
894   b[ g8]
895 } >>
896 @end lilypond
897
898 @noindent
899 and blanking the first up-stem in that voice, the tie appears to cross
900 voices:
901
902 @lilypond[quote,fragment,relative=2,verbatim]
903 << {
904   \once \override Stem #'transparent = ##t
905   b8~ b8\noBeam
906 } \\ {
907   b[ g8]
908 } >>
909 @end lilypond
910
911 @item
912 The @code{padding} property for objects with
913 @cindex @code{padding}
914 @code{side-position-interface} can be set to increase the distance between
915 symbols that are printed above or below notes.  We provide two
916 examples; a more elaborate explanation is in @ref{Constructing a
917 tweak}:
918
919 @lilypond[quote,fragment,relative=1,verbatim]
920 c2\fermata
921 \override Script #'padding = #3
922 b2\fermata
923 @end lilypond
924
925 @lilypond[quote,fragment,relative=1,verbatim]
926 % This will not work, see below:
927 \override MetronomeMark #'padding = #3
928 \tempo 4=120
929 c1
930 % This works:
931 \override Score.MetronomeMark #'padding = #3
932 \tempo 4=80
933 d1
934 @end lilypond
935
936 Note in the second example how important it is to figure out what
937 context handles a certain object. Since the @code{MetronomeMark} object
938 is handled in the Score context, property changes in the @code{Voice}
939 context will not be noticed. 
940
941 @end itemize
942
943 More specific overrides are also possible.  The next section
944 discusses in depth how to figure out these statements for yourself.
945
946
947 @node Constructing a tweak
948 @subsection Constructing a tweak
949
950 The general procedure of changing output, that is, entering
951 a command like
952
953 @example
954 \override Voice.Stem #'thickness = #3.0
955 @end example
956
957 @noindent
958 means that we have to determine these bits of information:
959
960 @itemize
961 @item the context: here @context{Voice}.
962 @item the layout object: here @code{Stem}.
963 @item the layout property: here @code{thickness}
964 @item a sensible value: here @code{3.0}
965 @end itemize  
966
967
968 @cindex internal documentation
969 @cindex finding graphical objects
970 @cindex graphical object descriptions 
971 @cindex tweaking
972 @cindex @code{\override}
973 @cindex internal documentation
974
975 We demonstrate how to glean this information from the notation manual
976 and the program reference.
977
978 @node Navigating the program reference
979 @subsection Navigating the program reference
980
981 Suppose we want to move the fingering indication in the fragment
982 below:
983
984 @lilypond[quote,fragment,relative=2,verbatim]
985 c-2
986 \stemUp
987 f
988 @end lilypond
989
990 If you visit the documentation on fingering instructions (in
991 @ref{Fingering instructions}), you will notice that there is written:
992
993 @quotation
994 @seealso
995
996 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
997
998 @end quotation
999
1000
1001
1002 This fragment points to two parts of the program reference: a page
1003 on @code{FingerEvent} and one on @code{Fingering}.
1004
1005 The page on @code{FingerEvent} describes the properties of the music
1006 expression for the input @code{-2}.  The page contains many links
1007 forward.  For example, it says
1008
1009 @quotation
1010 Accepted by: @internalsref{Fingering_engraver},
1011 @end quotation 
1012
1013 @noindent
1014 That link brings us to the documentation for the Engraver, the
1015 plug-in, which says
1016
1017 @quotation
1018 This engraver creates the following layout objects: @internalsref{Fingering}.
1019 @end quotation
1020
1021 In other words, once the @code{FingerEvent}s are interpreted, the
1022 @code{Fingering_engraver} plug-in will process them.
1023 The @code{Fingering_engraver} is also listed to create
1024 @internalsref{Fingering} objects,
1025
1026
1027 Lo and behold, that is also the
1028 second bit of information listed under @b{See also} in the Notation
1029 manual.  By clicking around in the program reference, we can follow the
1030 flow of information within the program, either forward (like we did
1031 here), or backwards, following links like this:
1032
1033 @itemize @bullet
1034
1035 @item @internalsref{Fingering}:
1036 @internalsref{Fingering} objects are created by:
1037 @b{@internalsref{Fingering_engraver}}
1038
1039 @item @internalsref{Fingering_engraver}:
1040 Music types accepted: @b{@internalsref{fingering-event}}
1041
1042 @item @internalsref{fingering-event}:
1043 Music event type @code{fingering-event} is in Music expressions named
1044 @b{@internalsref{FingerEvent}}
1045 @end itemize
1046
1047 This path goes against the flow of information in the program: it
1048 starts from the output, and ends at the input event.
1049
1050 The program reference can also be browsed like a normal document.  It
1051 contains a chapter on
1052 @ifhtml
1053 @internalsref{Music definitions},
1054 @end ifhtml
1055 @ifnothtml
1056 @code{Music definitions}
1057 @end ifnothtml
1058 on @internalsref{Translation}, and the @internalsref{Backend}.  Every
1059 chapter lists all the definitions used, and all properties that may be
1060 tuned.
1061
1062  
1063 @node Layout interfaces
1064 @subsection Layout interfaces
1065
1066 @cindex interface, layout
1067 @cindex layout interface
1068
1069 The HTML page that we found in the previous section, describes the
1070 layout object called @internalsref{Fingering}.  Such an object is a
1071 symbol within the score.  It has properties that store numbers (like
1072 thicknesses and directions), but also pointers to related objects.  A
1073 layout object is also called @emph{grob},
1074 @cindex grob
1075 which is short for Graphical Object.
1076
1077
1078 The page for @code{Fingering} lists the definitions for the
1079 @code{Fingering} object.  For example, the page says
1080
1081 @quotation
1082 @code{padding} (dimension, in staff space):
1083   
1084 @code{0.6}
1085 @end quotation
1086
1087 @noindent
1088 which means that the number will be kept at a distance of at least 0.6
1089 of the note head.
1090
1091
1092 Each layout object may have several functions as a notational or
1093 typographical element.  For example, the Fingering object
1094 has the following aspects
1095
1096 @itemize @bullet
1097 @item
1098 Its size is independent of the horizontal spacing, unlike slurs or beams.
1099
1100 @item
1101 It is a piece of text.  Granted, it is usually a very short text.
1102
1103 @item
1104 That piece of text is typeset with a font, unlike slurs or beams.
1105
1106 @item
1107 Horizontally, the center of the symbol should be aligned to the
1108 center of the notehead.
1109
1110 @item
1111 Vertically, the symbol is placed next to the note and the staff.
1112
1113 @item
1114 The vertical position is also coordinated with other super- and subscript
1115 symbols.
1116 @end itemize
1117
1118 Each of these aspects is captured in so-called @emph{interface}s,
1119 which are listed on the @internalsref{Fingering} page at the bottom
1120
1121 @quotation
1122 This object supports the following interfaces:
1123 @internalsref{item-interface},
1124 @internalsref{self-alignment-interface},
1125 @internalsref{side-position-interface}, @internalsref{text-interface},
1126 @internalsref{text-script-interface}, @internalsref{font-interface},
1127 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1128 @end quotation
1129
1130 Clicking any of the links will take you to the page of the respective
1131 object interface.  Each interface has a number of properties.  Some of
1132 them are not user-serviceable (``Internal properties''), but others
1133 are.
1134
1135 We have been talking of @emph{the} @code{Fingering} object, but actually it
1136 does not amount to much.  The initialization file
1137 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1138
1139 @example
1140 (Fingering
1141   . ((print-function . ,Text_interface::print)
1142      (padding . 0.6)
1143      (staff-padding . 0.6)
1144      (self-alignment-X . 0)
1145      (self-alignment-Y . 0)
1146      (script-priority . 100)
1147      (font-size . -5)
1148      (meta . ((interfaces . (finger-interface font-interface
1149                              text-script-interface text-interface
1150                              side-position-interface
1151                              self-alignment-interface
1152                              item-interface))))))
1153 @end example
1154
1155 @noindent
1156 As you can see, the @code{Fingering} object is nothing more than a
1157 bunch of variable settings, and the webpage in the Program Reference
1158 is directly generated from this definition.
1159
1160 @node Determining the grob property
1161 @subsection Determining the grob property
1162
1163
1164 Recall that we wanted to change the position of the @b{2} in 
1165
1166 @lilypond[quote,fragment,relative=2,verbatim]
1167 c-2
1168 \stemUp
1169 f
1170 @end lilypond
1171
1172 Since the @b{2} is vertically positioned next to its note, we have to
1173 meddle with the interface associated with this positioning.  This is
1174 done using @code{side-position-interface}.  The page for this interface 
1175 says
1176
1177 @quotation
1178 @code{side-position-interface}
1179
1180 Position a victim object (this one) next to other objects (the
1181 support).  The property @code{direction} signifies where to put the
1182 victim object relative to the support (left or right, up or down?)
1183 @end quotation
1184
1185 @cindex padding
1186 @noindent
1187 below this description, the variable @code{padding} is described as
1188
1189 @quotation
1190 @table @code
1191 @item padding
1192 (dimension, in staff space)
1193
1194 Add this much extra space between objects that are next to each other. 
1195 @end table
1196 @end quotation
1197
1198 By increasing the value of @code{padding}, we can move away the
1199 fingering.  The following command inserts 3 staff spaces of white
1200 between the note and the fingering:
1201 @example
1202 \once \override Voice.Fingering #'padding = #3
1203 @end example
1204
1205 Inserting this command before the Fingering object is created,
1206 i.e., before @code{c2}, yields the following result:
1207
1208 @lilypond[quote,relative=2,fragment,verbatim]
1209 \once \override Voice.Fingering #'padding = #3
1210 c-2
1211 \stemUp
1212 f
1213 @end lilypond
1214
1215
1216 In this case, the context for this tweak is @context{Voice}.  This
1217 fact can also be deduced from the program reference, for the page for
1218 the @internalsref{Fingering_engraver} plug-in says
1219
1220 @quotation
1221 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1222 @end quotation
1223
1224 @node Difficult tweaks
1225 @subsection Difficult tweaks
1226
1227 There are two classes of difficult adjustments.  First, when there are
1228 several of the same objects at one point, and you want to adjust only
1229 one.  For example, if you want to change only one note head in a chord.
1230
1231 In this case, the @code{\applyoutput} function must be used.  The
1232 next example defines a Scheme function @code{set-position-font-size}
1233 that sets the @code{font-size} property, but only  
1234 on objects that have @internalsref{note-head-interface} and are at the
1235 right Y-position.
1236
1237 @lilypond[quote,verbatim]
1238 #(define ((set-position-font-size pos size) grob origin current)
1239   (let*
1240       ((interfaces (ly:grob-property grob 'interfaces))
1241        (position (ly:grob-property grob 'staff-position)))
1242    (if (and
1243         ; is this a note head?
1244         (memq 'note-head-interface interfaces)
1245
1246         ; is the Y coordinate right?
1247         (= pos position))
1248
1249       ; then do it.
1250       (set! (ly:grob-property grob 'font-size) size))))
1251
1252 \relative {
1253   c
1254   \applyoutput #(set-position-font-size -2 4)
1255   <c e g>
1256 }
1257 @end lilypond
1258
1259 @noindent
1260 A similar technique can be used for accidentals.  In that case, the
1261 function should check for @code{accidental-interface}.
1262
1263 Another difficult adjustment is the appearance of spanner objects,
1264 such as slur and tie.  Initially, only one of these objects is created,
1265 and they can be adjusted with the normal mechanism.  However, in some
1266 cases the spanners cross line breaks.  If this happens, these objects
1267 are cloned.  A separate object is created for every system that it is
1268 in.  These are clones of the original object and inherit all
1269 properties, including @code{\override}s.
1270
1271 In other words, an @code{\override} always affects all pieces of a
1272 broken spanner.  To change only one part of a spanner at a line break,
1273 it is necessary to hook into the formatting process.  The
1274 @code{after-line-breaking-callback} property contains the Scheme procedure
1275 that is called after the line breaks have been determined, and layout
1276 objects have been split over different systems.
1277
1278 In the following example, we define a procedure
1279 @code{my-callback}.  This procedure
1280  
1281 @itemize @bullet
1282 @item
1283 determines if we have been split across line breaks
1284 @item
1285 if yes, retrieves all the split objects
1286 @item
1287 checks if we are the last of the split objects
1288 @item
1289 if yes, it sets @code{extra-offset}.
1290 @end itemize
1291
1292 This procedure is installed into @internalsref{Tie}, so the last part
1293 of the broken tie is translated up.
1294
1295
1296 @lilypond[quote,verbatim,raggedright]
1297 #(define (my-callback grob)
1298   (let* (
1299          ; have we been split? 
1300          (orig (ly:grob-original grob))
1301
1302          ; if yes, get the split pieces (our siblings)
1303          (siblings (if (ly:grob? orig)
1304                      (ly:spanner-broken-into orig) '() )))
1305
1306    (if (and (>= (length siblings) 2)
1307              (eq? (car (last-pair siblings)) grob))
1308      (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1309
1310 \relative c'' { 
1311   \override Tie #'after-line-breaking-callback =
1312   #my-callback
1313   c1 ~ \break c2 ~ c
1314 }
1315 @end lilypond
1316
1317 @noindent
1318 When applying this trick, the new @code{after-line-breaking-callback}
1319 should also call the old @code{after-line-breaking-callback}, if there
1320 is one.  For example, if using this with @code{Slur},
1321 @code{Slur::after_line_breaking} should also be called.
1322