]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
Merge branch 'hwn' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / Documentation / user / changing-defaults.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 Changing defaults
11 @chapter Changing defaults
12
13
14 The purpose of LilyPond's design is to provide the finest output
15 quality as a default.  Nevertheless, it may happen that you need to
16 change this default layout.  The layout is controlled through a large
17 number of proverbial @q{knobs and switches.}  This chapter does not
18 list each and every knob.  Rather, it outlines what groups of controls
19 are available and explains how to lookup which knob to use for a
20 particular effect.
21
22
23 @cindex Program reference
24
25 The controls available for tuning are described in a separate
26 document, the
27 @iftex
28 Program reference manual.
29 @end iftex
30 @ifnottex
31 @ref{Top,Program reference,,lilypond-internals}.
32 @end ifnottex
33 That manual
34 lists all different variables, functions and options available in
35 LilyPond.  It is written as a HTML document, which is available
36 @c leave the @uref as one long line.
37 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
38 but is also included with the LilyPond documentation package.
39
40 There are four areas where the default settings may be changed:
41
42 @itemize @bullet
43 @item
44 Automatic notation: changing the automatic creation of notation
45 elements.  For example, changing the beaming rules.
46
47 @item
48 Output: changing the appearance of individual
49 objects.  For example, changing stem directions or the location of
50 subscripts.
51
52 @item
53 Context: changing aspects of the translation from music events to
54 notation.  For example, giving each staff a separate time signature.
55
56 @item
57 Page layout: changing the appearance of the spacing, line
58 breaks, and page dimensions.  These modifications are discussed
59 in @ref{Non-musical notation} and @ref{Spacing issues}.
60 @end itemize
61
62 Internally, LilyPond uses Scheme (a LISP dialect) to provide
63 infrastructure.  Overriding layout decisions in effect accesses the
64 program internals, which requires Scheme input.  Scheme elements are
65 introduced in a @code{.ly} file with the hash mark
66 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
67 on entering numbers, lists, strings, and symbols in Scheme.}
68
69
70 @menu
71 * Automatic notation::          
72 * Interpretation contexts::     
73 * The \override command::       
74 @end menu
75
76
77 @node Automatic notation
78 @section Automatic notation
79
80 This section describes how to change the way that accidentals and
81 beams are automatically displayed.
82
83 @menu
84 * Automatic accidentals::       
85 * Setting automatic beam behavior::  
86 @end menu
87
88 @node Automatic accidentals
89 @subsection Automatic accidentals
90 @cindex Automatic accidentals
91
92 Common rules for typesetting accidentals have been placed in a
93 function.  This function is called as follows
94
95 @funindex set-accidental-style
96 @example
97 #(set-accidental-style 'STYLE #('CONTEXT#))
98 @end example
99
100 The function can take two arguments: the name of the accidental style,
101 and an optional argument that denotes the context that should be
102 changed.  If no context name is supplied, @code{Staff} is the default,
103 but you may wish to apply the accidental style to a single @code{Voice}
104 instead.
105
106 @c TODO: we should create a very clear example, and show every
107 @c accidental style on that example (with the example specially
108 @c constructed so that it illustrates all the differences).  -gp
109
110 The following accidental styles are supported
111 @table @code
112 @item default
113 This is the default typesetting behavior.  It corresponds
114 to 18th century common practice: Accidentals are
115 remembered to the end of the measure in which they occur and
116 only on their own octave.
117
118 @item voice
119 The normal behavior is to remember the accidentals on
120 Staff-level.  This variable, however, typesets accidentals
121 individually for each voice.  Apart from that, the rule is similar to
122 @code{default}.
123
124 As a result, accidentals from one voice do not get canceled in other
125 voices, which is often an unwanted result
126
127 @lilypond[quote,ragged-right,relative=1,fragment,verbatim]
128 \new Staff <<
129   #(set-accidental-style 'voice)
130   <<
131     { es g } \\
132     { c, e }
133 >> >>
134 @end lilypond
135
136 The @code{voice} option should be used if the voices
137 are to be read solely by individual musicians.  If the staff is to be
138 used by one musician (e.g., a conductor) then
139 @code{modern} or @code{modern-cautionary}
140 should be used instead.
141
142 @item modern
143 @funindex modern style accidentals
144 This rule corresponds to the common practice in the 20th century.  This rule
145 prints the same accidentals as @code{default}, but temporary
146 accidentals also are canceled in other octaves.  Furthermore,
147 in the same octave, they also get canceled in the following
148 measure
149
150 @lilypond[quote,ragged-right,fragment,verbatim]
151 #(set-accidental-style 'modern)
152 cis' c'' cis'2 | c'' c'
153 @end lilypond
154
155 @item @code{modern-cautionary}
156 @funindex modern-cautionary
157 This rule is similar to @code{modern}, but the @q{extra} accidentals
158 (the ones not typeset by @code{default}) are typeset as cautionary
159 accidentals.  They are printed in reduced size or with parentheses
160 @lilypond[quote,ragged-right,fragment,verbatim]
161 #(set-accidental-style 'modern-cautionary)
162 cis' c'' cis'2 | c'' c'
163 @end lilypond
164
165 @funindex modern-voice
166 @item modern-voice
167 This rule is used for multivoice accidentals to be read both by musicians
168 playing one voice and musicians playing all voices.  Accidentals are
169 typeset for each voice, but they @emph{are} canceled across voices in
170 the same @internalsref{Staff}.
171
172 @funindex modern-voice-cautionary
173 @item modern-voice-cautionary
174 This rule is the same as @code{modern-voice}, but with the extra
175 accidentals (the ones not typeset by @code{voice}) typeset
176 as cautionaries.  Even though all accidentals typeset by
177 @code{default} @emph{are} typeset by this variable,
178 some of them are typeset as cautionaries.
179
180 @item piano
181 @funindex piano accidentals
182 This rule reflects 20th century practice for piano notation.  Very similar to
183 @code{modern} but accidentals also get canceled
184 across the staves in the same @internalsref{GrandStaff} or
185 @internalsref{PianoStaff}.
186
187 @item piano-cautionary
188 @funindex #(set-accidental-style 'piano-cautionary)
189 Same as @code{#(set-accidental-style 'piano)} but with the extra
190 accidentals typeset as cautionaries.
191
192 @item no-reset
193 @funindex no-reset accidental style
194 This is the same as @code{default} but with accidentals lasting
195 @q{forever} and not only until the next measure
196 @lilypond[quote,ragged-right,fragment,verbatim,relative=1]
197 #(set-accidental-style 'no-reset)
198 c1 cis cis c
199 @end lilypond
200
201 @item forget
202 This is sort of the opposite of @code{no-reset}: Accidentals
203 are not remembered at all -- and hence all accidentals are
204 typeset relative to the key signature, regardless of what was
205 before in the music
206
207 @lilypond[quote,ragged-right,fragment,verbatim,relative=1]
208 #(set-accidental-style 'forget)
209 \key d\major c4 c cis cis d d dis dis
210 @end lilypond
211 @end table
212
213
214 @seealso
215
216 Program reference: @internalsref{Accidental_engraver},
217 @internalsref{Accidental}, and @internalsref{AccidentalPlacement}.
218
219
220 @refbugs
221
222 Simultaneous notes are considered to be entered in sequential
223 mode.  This means that in a chord the accidentals are typeset as if the
224 notes in the chord happen one at a time, in the order in which
225 they appear in the input file.  This is a problem when accidentals
226 in a chord depend on each other,
227 which does not happen for the default accidental style.  The problem
228 can be solved by manually inserting @code{!} and @code{?} for the
229 problematic notes.
230
231
232 @node Setting automatic beam behavior
233 @subsection Setting automatic beam behavior
234
235 @funindex autoBeamSettings
236 @funindex (end * * * *)
237 @funindex (begin * * * *)
238 @cindex automatic beams, tuning
239 @cindex tuning automatic beaming
240
241 @c [TODO: use \applyContext]
242
243 In normal time signatures, automatic beams can start on any note but can
244 only end in a few positions within the measure: beams can end on a beat,
245 or at durations specified by the properties in
246 @code{autoBeamSettings}.  The properties in @code{autoBeamSettings}
247 consist of a list of rules for where beams can begin and end.  The
248 default @code{autoBeamSettings} rules are defined in
249 @file{scm/@/auto@/-beam@/.scm}.
250
251 In order to add a rule to the list, use
252 @example
253 #(override-auto-beam-setting '(be p q n m) a b [context])
254 @end example
255
256 @itemize @bullet
257
258 @item @code{be} is either "begin" or "end".
259
260 @item @code{p/q} is the duration of the note for which you want
261 to add a rule.  A beam is considered to have the duration of its
262 shortest note.  Set @code{p} and @code{q} to @code{'*'} to
263 have this apply to any beam.
264
265 @item @code{n/m} is the time signature to which
266 this rule should apply.  Set @code{n} and @code{m} to @code{'*'}
267 to have this apply in any time signature.
268
269 @item @code{a/b} is the position in the bar at which the beam should
270 begin/end.
271
272 @item @code{context} is optional, and it specifies the context at which
273 the change should be made.  The default is @code{'Voice}.
274 @code{#(score-override-auto-beam-setting '(A B C D) E F)} is equivalent to
275 @code{#(override-auto-beam-setting '(A B C D) E F 'Score)}.
276
277 @end itemize
278
279 For example, if automatic beams should always end on the first quarter
280 note, use
281
282 @example
283 #(override-auto-beam-setting '(end * * * *) 1 4)
284 @end example
285
286 You can force the beam settings to only take effect on beams whose shortest
287 note is a certain duration
288
289 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
290 \time 2/4
291 #(override-auto-beam-setting '(end 1 16 * *) 1 16)
292 a16 a a a a a a a |
293 a32 a a a a16 a a a a a |
294 #(override-auto-beam-setting '(end 1 32 * *) 1 16)
295 a32 a a a a16 a a a a a |
296 @end lilypond
297
298 You can force the beam settings to only take effect in certain time
299 signatures
300
301 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
302 \time 5/8
303 #(override-auto-beam-setting '(end * * 5 8) 2 8)
304 c8 c d d d
305 \time 4/4
306 e8 e f f e e d d
307 \time 5/8
308 c8 c d d d
309 @end lilypond
310
311 You can also remove a previously set beam-ending rule by using
312
313 @example
314 #(revert-auto-beam-setting '(be p q n m) a b [context])
315 @end example
316
317 @noindent
318 be, p, q, n, m, a, b and context are the same as above.  Note that the
319 default rules are specified in @file{scm/@/auto@/-beam@/.scm},
320 so you can revert rules that you did not explicitly create.
321
322 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
323 \time 4/4
324 a16 a a a a a a a a a a a a a a a
325 #(revert-auto-beam-setting '(end 1 16 4 4) 1 4)
326 a16 a a a a a a a a a a a a a a a
327 @end lilypond
328
329 The rule in a revert-auto-beam-setting statement must exactly match the
330 original rule.  That is, no wildcard expansion is taken into account.
331
332 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
333 \time 1/4
334 #(override-auto-beam-setting '(end 1 16 1 4) 1 8)
335 a16 a a a
336 #(revert-auto-beam-setting '(end 1 16 * *) 1 8) % this won't revert it!
337 a a a a
338 #(revert-auto-beam-setting '(end 1 16 1 4) 1 8) % this will
339 a a a a
340 @end lilypond
341
342
343
344 @c TODO:  old material -- not covered by above stuff, I think.
345 If automatic beams should end on every quarter in 5/4 time, specify
346 all endings
347 @example
348 #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
349 #(override-auto-beam-setting '(end * * * *) 1 2 'Staff)
350 #(override-auto-beam-setting '(end * * * *) 3 4 'Staff)
351 #(override-auto-beam-setting '(end * * * *) 5 4 'Staff)
352 @dots{}
353 @end example
354
355 The same syntax can be used to specify beam starting points.  In this
356 example, automatic beams can only end on a dotted quarter note
357 @example
358 #(override-auto-beam-setting '(end * * * *) 3 8)
359 #(override-auto-beam-setting '(end * * * *) 1 2)
360 #(override-auto-beam-setting '(end * * * *) 7 8)
361 @end example
362 In 4/4 time signature, this means that automatic beams could end only on
363 3/8 and on the fourth beat of the measure (after 3/4, that is 2 times
364 3/8, has passed within the measure).
365
366 If any unexpected beam behaviour occurs, check the default automatic beam
367 settings in @file{scm/@/auto@/-beam@/.scm}
368 for possible interference, because the beam
369 endings defined there will still apply on top of your own overrides. Any
370 unwanted endings in the default vales must be reverted for your time
371 signature(s).
372
373 For example, to typeset @code{(3 4 3 2)}-beam endings in 12/8, begin
374 with
375
376 @example
377 %%% revert default values in scm/auto-beam.scm regarding 12/8 time
378 #(revert-auto-beam-setting '(end * * 12 8) 3 8)
379 #(revert-auto-beam-setting '(end * * 12 8) 3 4)
380 #(revert-auto-beam-setting '(end * * 12 8) 9 8)
381
382 %%% your new values
383 #(override-auto-beam-setting '(end 1 8 12 8) 3 8)
384 #(override-auto-beam-setting '(end 1 8 12 8) 7 8)
385 #(override-auto-beam-setting '(end 1 8 12 8) 10 8)
386 @end example
387
388 @cindex automatic beam generation
389 @cindex autobeam
390 @funindex autoBeaming
391 @cindex lyrics
392
393 If beams are used to indicate melismata in songs, then automatic
394 beaming should be switched off with @code{\autoBeamOff}.
395
396
397 @refcommands
398
399 @funindex \autoBeamOff
400 @code{\autoBeamOff},
401 @funindex \autoBeamOn
402 @code{\autoBeamOn}.
403
404 @commonprop
405
406 Beaming patterns may be altered with the @code{beatGrouping} property,
407
408 @lilypond[quote,verbatim,relative=2,fragment,ragged-right]
409 \time 5/16
410 \set beatGrouping = #'(2 3)
411 c8[^"(2+3)" c16 c8]
412 \set beatGrouping = #'(3 2)
413 c8[^"(3+2)" c16 c8]
414 @end lilypond
415
416
417 @refbugs
418
419 If a score ends while an automatic beam has not been ended and is
420 still accepting notes, this last beam will not be typeset at all.  The
421 same holds polyphonic voices, entered with @code{<< @dots{} \\ @dots{}
422 >>}.  If a polyphonic voice ends while an automatic beam is still
423 accepting notes, it is not typeset.
424
425
426 @node Interpretation contexts
427 @section Interpretation contexts
428
429 This section describes what contexts are, and how to modify them.
430
431 @menu
432 * Contexts explained::          
433 * Creating contexts::           
434 * Changing context properties on the fly::  
435 * Modifying context plug-ins::  
436 * Layout tunings within contexts::  
437 * Changing context default settings::  
438 * Defining new contexts::       
439 * Aligning contexts::           
440 @end menu
441
442
443 @node Contexts explained
444 @subsection Contexts explained
445
446 When music is printed, a lot of notational elements must be added to the
447 output.  For example, compare the input and output of the following example:
448
449 @lilypond[quote,verbatim,relative=2,fragment]
450 cis4 cis2. g4
451 @end lilypond
452
453 The input is rather sparse, but in the output, bar lines, accidentals,
454 clef, and time signature are added.  LilyPond @emph{interprets} the
455 input.  During this step, the musical information is inspected in time
456 order, similar to reading a score from left to right.  While reading
457 the input, the program remembers where measure boundaries are, and which
458 pitches require explicit accidentals.  This information can be presented on
459 several levels.  For example, the effect of an accidental is limited
460 to a single staff, while a bar line must be synchronized across the
461 entire score.
462
463 Within LilyPond, these rules and bits of information are grouped in
464 @emph{Contexts}.  Some examples of contexts are @context{Voice},
465 @context{Staff}, and @context{Score}.  They are hierarchical, for
466 example: a @context{Staff} can contain many @context{Voice}s, and a
467 @context{Score} can contain many @context{Staff} contexts.
468
469 @quotation
470 @image{context-example,5cm,,}
471 @end quotation
472
473 Each context has the responsibility for enforcing some notation rules,
474 creating some notation objects and maintaining the associated
475 properties.  For example, the @context{Voice} context may introduce an
476 accidental and then the @context{Staff} context maintains the rule to
477 show or suppress the accidental for the remainder of the measure.  The
478 synchronization of bar lines is handled at @context{Score} context.
479
480 However, in some music we may not want the bar lines to be
481 synchronized -- consider a polymetric score in 4/4 and 3/4 time.  In
482 such cases, we must modify the default settings of the @context{Score}
483 and @context{Staff} contexts.
484
485 For very simple scores, contexts are created implicitly, and you need
486 not be aware of them.  For larger pieces, such as anything with more
487 than one staff, they must be
488 created explicitly to make sure that you get as many staves as you
489 need, and that they are in the correct order.  For typesetting pieces
490 with specialized notation, it can be useful to modify existing or
491 to define new contexts.
492
493
494 A complete description of all available contexts is in the program
495 reference, see
496 @ifhtml
497 @internalsref{Contexts}.
498 @end ifhtml
499 @ifnothtml
500 Translation @arrow{} Context.
501 @end ifnothtml
502
503 @c [TODO: describe propagation]
504
505
506 @node Creating contexts
507 @subsection Creating contexts
508
509 For scores with only one voice and one staff, contexts are
510 created automatically.  For more complex scores, it is necessary to
511 create them by hand.  There are three commands that do this.
512
513 @itemize @bullet
514
515 @item
516 The easiest command is @code{\new}, and it also the quickest to type.
517 It is prepended to a music expression, for example
518
519 @funindex \new
520 @cindex new contexts
521 @cindex Context, creating
522
523 @example
524 \new @var{type} @var{music expression}
525 @end example
526
527 @noindent
528 where @var{type} is a context name (like @code{Staff} or
529 @code{Voice}).  This command creates a new context, and starts
530 interpreting the @var{music expression} with that.
531
532 A practical application of @code{\new} is a score with many
533 staves.  Each part that should be on its own staff, is preceded with
534 @code{\new Staff}.
535
536 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
537 <<
538   \new Staff { c4 c }
539   \new Staff { d4 d }
540 >>
541 @end lilypond
542
543 The @code{\new} command may also give a name to the context,
544
545 @example
546 \new @var{type} = @var{id} @var{music}
547 @end example
548 However, this user specified name is only used if there is no other
549 context already earlier with the same name.
550
551
552 @funindex \context
553
554 @item
555 Like @code{\new}, the @code{\context} command also directs a music
556 expression to a context object, but gives the context an explicit name.  The
557 syntax is
558
559 @example
560 \context @var{type} = @var{id} @var{music}
561 @end example
562
563 This form will search for an existing context of type @var{type}
564 called @var{id}.  If that context does not exist yet, a new
565 context with the specified name is created.  This is useful if
566 the context is referred to later on.  For example, when
567 setting lyrics the melody is in a named context
568
569 @example
570 \context Voice = "@b{tenor}" @var{music}
571 @end example
572
573 @noindent
574 so the texts can be properly aligned to its notes,
575
576 @example
577 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
578 @end example
579
580 @noindent
581
582 Another possible use of named contexts is funneling two different
583 music expressions into one context.  In the following example,
584 articulations and notes are entered separately,
585
586 @example
587 music = @{ c4 c4 @}
588 arts = @{ s4-. s4-> @}
589 @end example
590
591 They are combined by sending both to the same @context{Voice} context,
592
593 @example
594 <<
595   \new Staff \context Voice = "A" \music
596   \context Voice = "A" \arts
597 >>
598 @end example
599 @lilypond[quote,ragged-right]
600 music = { c4 c4 }
601 arts = { s4-. s4-> }
602 \relative c'' <<
603   \new Staff \context Voice = "A" \music
604   \context Voice = "A" \arts
605 >>
606 @end lilypond
607
608 With this mechanism, it is possible to define an Urtext (original
609 edition), with the option to put several distinct articulations on the
610 same notes.
611
612 @cindex creating contexts
613
614 @item
615 The third command for creating contexts is
616 @example
617 \context @var{type} @var{music}
618 @end example
619
620
621 @noindent
622 This is similar to @code{\context} with @code{= @var{id}}, but matches
623 any context of type @var{type}, regardless of its given name.
624
625 This variant is used with music expressions that can be interpreted at
626 several levels.  For example, the @code{\applyOutput} command (see
627 @ref{Running a function on all layout objects}).  Without an explicit
628 @code{\context}, it is usually applied to @context{Voice}
629
630 @example
631 \applyOutput #'@var{context} #@var{function}   % apply to Voice
632 @end example
633
634 To have it interpreted at the @context{Score} or @context{Staff} level use
635 these forms
636
637 @example
638 \applyOutput #'Score #@var{function}
639 \applyOutput #'Staff #@var{function}
640 @end example
641
642 @end itemize
643
644
645 @node Changing context properties on the fly
646 @subsection Changing context properties on the fly
647
648 @cindex properties
649 @funindex \set
650 @cindex changing properties
651
652 Each context can have different @emph{properties}, variables contained
653 in that context.  They can be changed during the interpretation step.
654 This is achieved by inserting the @code{\set} command in the music,
655
656 @example
657 \set @var{context}.@var{prop} = #@var{value}
658 @end example
659
660 For example,
661 @lilypond[quote,verbatim,relative=2,fragment]
662 R1*2
663 \set Score.skipBars = ##t
664 R1*2
665 @end lilypond
666
667 This command skips measures that have no notes.  The result is that
668 multi-rests are condensed.  The value assigned is a Scheme object.  In
669 this case, it is @code{#t}, the boolean True value.
670
671 If the @var{context} argument is left out, then the current bottom-most
672 context (typically @context{ChordNames}, @context{Voice}, or
673 @context{Lyrics}) is used.  In this example,
674
675 @lilypond[quote,verbatim,relative=2,fragment]
676 c8 c c c
677 \set autoBeaming = ##f
678 c8 c c c
679 @end lilypond
680
681 @noindent
682 the @var{context} argument to @code{\set} is left out, so automatic
683 beaming is switched off in the current @internalsref{Voice}.  Note that
684 the bottom-most context does not always contain the property that you
685 wish to change -- for example, attempting to set the @code{skipBars}
686 property (of the bottom-most context, in this case @code{Voice}) will
687 have no effect.
688
689 @lilypond[quote,verbatim,relative=2,fragment]
690 R1*2
691 \set skipBars = ##t
692 R1*2
693 @end lilypond
694
695 Contexts are hierarchical, so if a bigger context was specified, for
696 example @context{Staff}, then the change would also apply to all
697 @context{Voice}s in the current stave.  The change is applied
698 @q{on-the-fly}, during the music, so that the setting only affects the
699 second group of eighth notes.
700
701 @funindex \unset
702
703 There is also an @code{\unset} command,
704 @example
705 \unset @var{context}.@var{prop}
706 @end example
707
708 @noindent
709 which removes the definition of @var{prop}.  This command removes
710 the definition only if it is set in @var{context}, so
711
712 @example
713 \set Staff.autoBeaming = ##f
714 @end example
715
716 @noindent
717 introduces a property setting at @code{Staff} level.  The setting also
718 applies to the current @code{Voice}.  However,
719
720 @example
721 \unset Voice.autoBeaming
722 @end example
723
724 @noindent
725 does not have any effect.  To cancel this setting, the @code{\unset}
726 must be specified on the same level as the original @code{\set}.  In
727 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
728 requires
729 @example
730 \unset Staff.autoBeaming
731 @end example
732
733 Like @code{\set}, the @var{context} argument does not have to be
734 specified for a bottom context, so the two statements
735
736 @example
737 \set Voice.autoBeaming = ##t
738 \set autoBeaming = ##t
739 @end example
740
741 @noindent
742 are equivalent.
743
744
745 @cindex \once
746 Settings that should only apply to a single time-step can be entered
747 with @code{\once}, for example in
748
749 @lilypond[quote,verbatim,relative=2,fragment]
750 c4
751 \once \set fontSize = #4.7
752 c4
753 c4
754 @end lilypond
755
756 the property @code{fontSize} is unset automatically after the second
757 note.
758
759 A full description of all available context properties is in the
760 program reference, see
761 @ifhtml
762 @internalsref{Tunable context properties}.
763 @end ifhtml
764 @ifnothtml
765 Translation @arrow{} Tunable context properties.
766 @end ifnothtml
767
768
769 @node Modifying context plug-ins
770 @subsection Modifying context plug-ins
771
772 Notation contexts (like @code{Score} and @code{Staff}) not only
773 store properties,
774 they also contain plug-ins called @q{engravers} that create notation
775 elements.  For example, the @code{Voice} context contains a
776 @code{Note_head_engraver} and the @code{Staff} context contains a
777 @code{Key_signature_engraver}.
778
779 For a full a description of each plug-in, see
780 @ifhtml
781 @internalsref{Engravers}.
782 @end ifhtml
783 @ifnothtml
784 Program reference @arrow Translation @arrow{} Engravers.
785 @end ifnothtml
786 Every context described in
787 @ifhtml
788 @internalsref{Contexts}
789 @end ifhtml
790 @ifnothtml
791 Program reference @arrow Translation @arrow{} Context.
792 @end ifnothtml
793 lists the engravers used for that context.
794
795
796 It can be useful to shuffle around these plug-ins.  This is done by
797 starting a new context with @code{\new} or @code{\context}, and
798 modifying it,
799
800 @funindex \with
801
802 @example
803 \new @var{context} \with @{
804   \consists @dots{}
805   \consists @dots{}
806   \remove @dots{}
807   \remove @dots{}
808   @emph{etc.}
809 @}
810 @{
811   @emph{..music..}
812 @}
813 @end example
814
815 @noindent
816 where the @dots{} should be the name of an engraver.  Here is a simple
817 example which removes @code{Time_signature_engraver} and
818 @code{Clef_engraver} from a @code{Staff} context,
819
820 @lilypond[quote,relative=1,verbatim,fragment]
821 <<
822   \new Staff {
823     f2 g
824   }
825   \new Staff \with {
826      \remove "Time_signature_engraver"
827      \remove "Clef_engraver"
828   } {
829     f2 g2
830   }
831 >>
832 @end lilypond
833
834 In the second staff there are no time signature or clef symbols.  This
835 is a rather crude method of making objects disappear since it will affect
836 the entire staff.  This method also influences the spacing, which may or
837 may not be desirable.  A more
838 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
839
840 The next example shows a practical application.  Bar lines and time
841 signatures are normally synchronized across the score.  This is done
842 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
843 This plug-in keeps an administration of time signature, location
844 within the measure, etc.  By moving thes engraver from @code{Score} to
845 @code{Staff} context, we can have a score where each staff has its own
846 time signature.
847
848 @cindex polymetric scores
849 @cindex Time signatures, multiple
850
851 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
852 \new Score \with {
853   \remove "Timing_translator"
854   \remove "Default_bar_line_engraver"
855 } <<
856   \new Staff \with {
857     \consists "Timing_translator"
858     \consists "Default_bar_line_engraver"
859   } {
860       \time 3/4
861       c4 c c c c c
862   }
863   \new Staff \with {
864     \consists "Timing_translator"
865     \consists "Default_bar_line_engraver"
866   } {
867        \time 2/4
868        c4 c c c c c
869   }
870 >>
871 @end lilypond
872
873
874 @node Layout tunings within contexts
875 @subsection Layout tunings within contexts
876
877 Each context is responsible for creating certain types of graphical
878 objects.  The settings used for printing these objects are also stored by
879 context.  By changing these settings, the appearance of objects can be
880 altered.
881
882 The syntax for this is
883
884 @example
885 \override @var{context}.@var{name} #'@var{property} = #@var{value}
886 @end example
887
888 Here @var{name} is the name of a graphical object, like @code{Stem} or
889 @code{NoteHead}, and @var{property} is an internal variable of the
890 formatting system (@q{grob property} or @q{layout property}).  The latter is a
891 symbol, so it must be quoted.  The subsection @ref{Constructing a
892 tweak} explains what to fill in for @var{name}, @var{property}, and
893 @var{value}.  Here we only discuss the functionality of this command.
894
895 The command
896
897 @verbatim
898 \override Staff.Stem #'thickness = #4.0
899 @end verbatim
900
901 @noindent
902 makes stems thicker (the default is 1.3, with staff line thickness as a
903 unit).  Since the command specifies @context{Staff} as context, it only
904 applies to the current staff.  Other staves will keep their normal
905 appearance.  Here we see the command in action:
906
907 @lilypond[quote,verbatim,relative=2,fragment]
908 c4
909 \override Staff.Stem #'thickness = #4.0
910 c4
911 c4
912 c4
913 @end lilypond
914
915 The @code{\override} command changes the definition of the @code{Stem}
916 within the current @context{Staff}.  After the command is interpreted
917 all stems are thickened.
918
919 Analogous to @code{\set}, the @var{context} argument may be left out,
920 causing the default context @context{Voice} to be used.  Adding
921 @code{\once} applies the change during one timestep only.
922
923 @lilypond[quote,fragment,verbatim,relative=2]
924 c4
925 \once \override Stem #'thickness = #4.0
926 c4
927 c4
928 @end lilypond
929
930 The @code{\override} must be done before the object is
931 started.  Therefore, when altering @emph{Spanner} objects such as slurs
932 or beams, the @code{\override} command must be executed at the moment
933 when the object is created.  In this example,
934
935 @lilypond[quote,fragment,verbatim,relative=2]
936 \override Slur #'thickness = #3.0
937 c8[( c
938 \override Beam #'thickness = #0.6
939 c8 c])
940 @end lilypond
941
942 @noindent
943 the slur is fatter but the beam is not.  This is because the command for
944 @code{Beam} comes after the Beam is started, so it has no effect.
945
946 Analogous to @code{\unset}, the @code{\revert} command for a context
947 undoes an @code{\override} command; like with @code{\unset}, it only
948 affects settings that were made in the same context.  In other words, the
949 @code{\revert} in the next example does not do anything.
950
951 @example
952 \override Voice.Stem #'thickness = #4.0
953 \revert Staff.Stem #'thickness
954 @end example
955
956 Some tweakable options are called @q{subproperties} and reside inside
957 properties.  To tweak those, use commands of the form
958
959 @c leave this as a long long
960 @example
961 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
962 @end example
963
964 @noindent
965 such as
966
967 @example
968 \override Stem #'details #'beamed-lengths = #'(4 4 3)
969 @end example
970
971
972 @seealso
973
974 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
975 @internalsref{PropertySet}, @internalsref{Backend}, and
976 @internalsref{All layout objects}.
977
978
979 @refbugs
980
981 The back-end is not very strict in type-checking object properties.
982 Cyclic references in Scheme values for properties can cause hangs
983 or crashes, or both.
984
985
986 @node Changing context default settings
987 @subsection Changing context default settings
988
989 The adjustments of the previous subsections (@ref{Changing context
990 properties on the fly}, @ref{Modifying context plug-ins}, and
991 @ref{Layout tunings within contexts}) can also be entered separately
992 from the music in the @code{\layout} block,
993
994 @example
995 \layout @{
996   @dots{}
997   \context @{
998     \Staff
999
1000     \set fontSize = #-2
1001     \override Stem #'thickness = #4.0
1002     \remove "Time_signature_engraver"
1003   @}
1004 @}
1005 @end example
1006
1007 The @code{\Staff} command brings in the existing definition of the
1008 staff context so that it can be modified.
1009
1010 The statements
1011 @example
1012 \set fontSize = #-2
1013 \override Stem #'thickness = #4.0
1014 \remove "Time_signature_engraver"
1015 @end example
1016
1017 @noindent
1018 affect all staves in the score.  Other contexts can be modified
1019 analogously.
1020
1021 The @code{\set} keyword is optional within the @code{\layout} block, so
1022
1023 @example
1024 \context @{
1025   @dots{}
1026   fontSize = #-2
1027 @}
1028 @end example
1029
1030 @noindent
1031 will also work.
1032
1033
1034
1035 @refbugs
1036
1037 It is not possible to collect context changes in a variable and apply
1038 them to a @code{\context} definition by referring to that variable.
1039
1040 The @code{\RemoveEmptyStaffContext} will overwrite your current
1041 @code{\Staff} settings.  If you wish to change the defaults for a
1042 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
1043 after calling @code{\RemoveemptyStaffContext}, ie
1044
1045 @example
1046 \layout @{
1047   \context @{
1048     \RemoveEmptyStaffContext
1049
1050     \override Stem #'thickness = #4.0
1051   @}
1052 @}
1053 @end example
1054
1055
1056 @node Defining new contexts
1057 @subsection Defining new contexts
1058
1059 Specific contexts, like @context{Staff} and @code{Voice}, are made of
1060 simple building blocks.  It is possible to create new types of
1061 contexts with different combinations of engraver plug-ins.
1062
1063 The next example shows how to build a different type of
1064 @context{Voice} context from scratch.  It will be similar to
1065 @code{Voice}, but only prints centered slash noteheads.  It can be used
1066 to indicate improvisation in jazz pieces,
1067
1068 @lilypond[quote,ragged-right]
1069 \layout { \context {
1070   \name ImproVoice
1071   \type "Engraver_group"
1072   \consists "Note_heads_engraver"
1073   \consists "Text_engraver"
1074   \consists Pitch_squash_engraver
1075   squashedPosition = #0
1076   \override NoteHead #'style = #'slash
1077   \override Stem #'transparent = ##t
1078   \alias Voice
1079 }
1080 \context { \Staff
1081   \accepts "ImproVoice"
1082 }}
1083
1084 \relative c'' {
1085   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
1086    c4 c^"undress" c_"while playing :)" c }
1087   a1
1088 }
1089 @end lilypond
1090
1091
1092 These settings are defined within a @code{\context} block inside a
1093 @code{\layout} block,
1094
1095 @example
1096 \layout @{
1097   \context @{
1098     @dots{}
1099   @}
1100 @}
1101 @end example
1102
1103 In the following discussion, the example input shown should go in place
1104 of the @dots{} in the previous fragment.
1105
1106 First it is necessary to define a name for the new context:
1107
1108 @example
1109 \name ImproVoice
1110 @end example
1111
1112 Since it is similar to the @context{Voice}, we want commands that work
1113 on (existing) @context{Voice}s to remain working.  This is achieved by
1114 giving the new context an alias @context{Voice},
1115
1116 @example
1117 \alias Voice
1118 @end example
1119
1120 The context will print notes and instructive texts, so we need to add
1121 the engravers which provide this functionality,
1122
1123 @example
1124 \consists Note_heads_engraver
1125 \consists Text_engraver
1126 @end example
1127
1128 but we only need this on the center line,
1129
1130 @example
1131 \consists Pitch_squash_engraver
1132 squashedPosition = #0
1133 @end example
1134
1135 The @internalsref{Pitch_squash_engraver} modifies note heads (created
1136 by @internalsref{Note_heads_engraver}) and sets their vertical
1137 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
1138 the center line.
1139
1140 The notes look like a slash, and have no stem,
1141
1142 @example
1143 \override NoteHead #'style = #'slash
1144 \override Stem #'transparent = ##t
1145 @end example
1146
1147 All these plug-ins have to cooperate, and this is achieved with a
1148 special plug-in, which must be marked with the keyword @code{\type}.
1149 This should always be @internalsref{Engraver_group},
1150
1151 @example
1152 \type "Engraver_group"
1153 @end example
1154
1155 Put together, we get
1156
1157 @example
1158 \context @{
1159   \name ImproVoice
1160   \type "Engraver_group"
1161   \consists "Note_heads_engraver"
1162   \consists "Text_engraver"
1163   \consists Pitch_squash_engraver
1164   squashedPosition = #0
1165   \override NoteHead #'style = #'slash
1166   \override Stem #'transparent = ##t
1167   \alias Voice
1168 @}
1169 @end example
1170
1171 @funindex \accepts
1172 Contexts form hierarchies.  We want to hang the @context{ImproVoice}
1173 under @context{Staff}, just like normal @code{Voice}s.  Therefore, we
1174 modify the @code{Staff} definition with the @code{\accepts}
1175 command,
1176
1177 @example
1178 \context @{
1179   \Staff
1180   \accepts ImproVoice
1181 @}
1182 @end example
1183
1184 @funindex \denies
1185 The opposite of @code{\accepts} is @code{\denies},
1186 which is sometimes needed when reusing existing context definitions.
1187
1188 Putting both into a @code{\layout} block, like
1189
1190 @example
1191 \layout @{
1192   \context @{
1193     \name ImproVoice
1194     @dots{}
1195   @}
1196   \context @{
1197     \Staff
1198     \accepts "ImproVoice"
1199   @}
1200 @}
1201 @end example
1202
1203 Then the output at the start of this subsection can be entered as
1204
1205 @example
1206 \relative c'' @{
1207   a4 d8 bes8
1208   \new ImproVoice @{
1209     c4^"ad lib" c
1210     c4 c^"undress"
1211     c c_"while playing :)"
1212   @}
1213   a1
1214 @}
1215 @end example
1216
1217
1218 @node Aligning contexts
1219 @subsection Aligning contexts
1220
1221 New contexts may be aligned above or below exisiting contexts.  This
1222 could be useful in setting up a vocal staff (@ref{Vocal ensembles}) and
1223 in ossia,
1224
1225 @cindex ossia
1226 @findex alignAboveContext
1227 @findex alignBelowContext
1228
1229 @lilypond[quote,ragged-right]
1230 ossia = { f4 f f f }
1231 \score{
1232   \relative c' \new Staff = "main" {
1233     c4 c c c
1234     <<
1235       \new Staff \with {alignAboveContext=main} \ossia
1236       { d8 f d f d f d f }
1237     >>
1238   }
1239 }
1240 @end lilypond
1241
1242
1243
1244 @node The \override command
1245 @section The @code{\override} command
1246
1247 In the previous section, we have already touched on a command that
1248 changes layout details: the @code{\override} command.  In this section,
1249 we will look in more detail at how to use the command in practice.  The
1250 general syntax of this command is:
1251
1252 @example
1253 \override @var{context}.@var{layout_object} #'@var{layout_property} = #@var{value}
1254 @end example
1255
1256 This will set the @var{layout_property} of the specified @var{layout_object},
1257 which is a member of the @var{context}, to the @var{value}.
1258
1259 @menu
1260 * Constructing a tweak::        
1261 * Navigating the program reference::  
1262 * Layout interfaces::           
1263 * Determining the grob property::  
1264 * Objects connected to the input::  
1265 * Using Scheme code instead of \tweak::  
1266 * \set versus \override::          
1267 * Difficult tweaks::            
1268 @end menu
1269
1270
1271
1272 @node Constructing a tweak
1273 @subsection Constructing a tweak
1274
1275 Commands which change output generally look like
1276
1277 @example
1278 \override Voice.Stem #'thickness = #3.0
1279 @end example
1280
1281 @noindent
1282 To construct this tweak we must determine these bits of information:
1283
1284 @itemize
1285 @item the context: here @context{Voice}.
1286 @item the layout object: here @code{Stem}.
1287 @item the layout property: here @code{thickness}.
1288 @item a sensible value: here @code{3.0}.
1289 @end itemize
1290
1291 Some tweakable options are called @q{subproperties} and reside inside
1292 properties.  To tweak those, use commands in the form
1293
1294 @example
1295 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1296 @end example
1297
1298 @cindex internal documentation
1299 @cindex finding graphical objects
1300 @cindex graphical object descriptions
1301 @cindex tweaking
1302 @funindex \override
1303 @cindex internal documentation
1304
1305 For many properties, regardless of the data type of the property, setting the
1306 property to false ( @code{##f} ) will result in turning it off, causing
1307 Lilypond to ignore that property entirely.  This is particularly useful for
1308 turning off grob properties which may otherwise be causing problems.
1309
1310 We demonstrate how to glean this information from the notation manual
1311 and the program reference.
1312
1313
1314
1315
1316 @node Navigating the program reference
1317 @subsection Navigating the program reference
1318
1319 Suppose we want to move the fingering indication in the fragment
1320 below:
1321
1322 @lilypond[quote,fragment,relative=2,verbatim]
1323 c-2
1324 \stemUp
1325 f
1326 @end lilypond
1327
1328 If you visit the documentation on fingering instructions (in
1329 @ref{Fingering instructions}), you will notice:
1330
1331 @quotation
1332 @seealso
1333
1334 Program reference: @internalsref{Fingering}.
1335
1336 @end quotation
1337
1338
1339 @c  outdated info; probably will delete.
1340 @ignore
1341 This fragment points to two parts of the program reference: a page
1342 on @code{FingerEvent} and one on @code{Fingering}.
1343
1344 The page on @code{FingerEvent} describes the properties of the music
1345 expression for the input @code{-2}.  The page contains many links
1346 forward.  For example, it says
1347
1348 @quotation
1349 Accepted by: @internalsref{Fingering_engraver},
1350 @end quotation
1351
1352 @noindent
1353 That link brings us to the documentation for the Engraver, the
1354 plug-in, which says
1355
1356 @quotation
1357 This engraver creates the following layout objects: @internalsref{Fingering}.
1358 @end quotation
1359
1360 In other words, once the @code{FingerEvent}s are interpreted, the
1361 @code{Fingering_engraver} plug-in will process them.
1362 @end ignore
1363
1364 @ignore
1365 @c  I can't figure out what this is supposed to mean.  -gp
1366
1367 The @code{Fingering_engraver} is also listed to create
1368 @internalsref{Fingering} objects,
1369
1370 @c  old info?  it doesn't make any sense to me with our current docs.
1371 This is also the
1372 second bit of information listed under @b{See also} in the Notation
1373 manual.
1374 @end ignore
1375
1376 @ifnothtml
1377 The programmer's reference is available as an HTML document.  It is
1378 highly recommended that you read it in HTML form, either online or
1379 by downloading the HTML documentation.  This section will be much more
1380 difficult to understand if you are using the 
1381 PDF manual.
1382 @end ifnothtml
1383
1384 Follow the link to @internalsref{Fingering}.  At the top of the
1385 page, you will see
1386
1387 @quotation
1388 Fingering objects are created by: @internalsref{Fingering_engraver} and
1389 @internalsref{New_fingering_engraver}.
1390 @end quotation
1391
1392 By following related links inside the program reference, we can follow the
1393 flow of information within the program:
1394
1395 @itemize @bullet
1396
1397 @item @internalsref{Fingering}:
1398 @internalsref{Fingering} objects are created by:
1399 @internalsref{Fingering_engraver}
1400
1401 @item @internalsref{Fingering_engraver}:
1402 Music types accepted: @internalsref{fingering-event}
1403
1404 @item @internalsref{fingering-event}:
1405 Music event type @code{fingering-event} is in Music expressions named
1406 @internalsref{FingerEvent}
1407 @end itemize
1408
1409 This path goes against the flow of information in the program: it
1410 starts from the output, and ends at the input event.  You could
1411 also start at an input event, and read with the flow of
1412 information, eventually ending up at the output object(s).
1413
1414 The program reference can also be browsed like a normal document.  It
1415 contains chapters on
1416 @ifhtml
1417 @internalsref{Music definitions},
1418 @end ifhtml
1419 @ifnothtml
1420 @code{Music definitions}
1421 @end ifnothtml
1422 on @internalsref{Translation}, and the @internalsref{Backend}.  Every
1423 chapter lists all the definitions used and all properties that may be
1424 tuned.
1425
1426
1427 @node Layout interfaces
1428 @subsection Layout interfaces
1429
1430 @cindex interface, layout
1431 @cindex layout interface
1432 @cindex grob
1433
1434 The HTML page that we found in the previous section describes the
1435 layout object called @internalsref{Fingering}.  Such an object is a
1436 symbol within the score.  It has properties that store numbers (like
1437 thicknesses and directions), but also pointers to related objects.  A
1438 layout object is also called a @emph{Grob}, which is short for Graphical
1439 Object.  For more details about Grobs, see @internalsref{grob-interface}.
1440
1441 The page for @code{Fingering} lists the definitions for the
1442 @code{Fingering} object.  For example, the page says
1443
1444 @quotation
1445 @code{padding} (dimension, in staff space):
1446
1447 @code{0.5}
1448 @end quotation
1449
1450 @noindent
1451 which means that the number will be kept at a distance of at least 0.5
1452 of the note head.
1453
1454
1455 Each layout object may have several functions as a notational or
1456 typographical element.  For example, the Fingering object
1457 has the following aspects
1458
1459 @itemize @bullet
1460 @item
1461 Its size is independent of the horizontal spacing, unlike slurs or beams.
1462
1463 @item
1464 It is a piece of text.  Granted, it is usually a very short text.
1465
1466 @item
1467 That piece of text is typeset with a font, unlike slurs or beams.
1468
1469 @item
1470 Horizontally, the center of the symbol should be aligned to the
1471 center of the notehead.
1472
1473 @item
1474 Vertically, the symbol is placed next to the note and the staff.
1475
1476 @item
1477 The vertical position is also coordinated with other superscript
1478 and subscript symbols.
1479 @end itemize
1480
1481 Each of these aspects is captured in so-called @emph{interface}s,
1482 which are listed on the @internalsref{Fingering} page at the bottom
1483
1484 @quotation
1485 This object supports the following interfaces:
1486 @internalsref{item-interface},
1487 @internalsref{self-alignment-interface},
1488 @internalsref{side-position-interface}, @internalsref{text-interface},
1489 @internalsref{text-script-interface}, @internalsref{font-interface},
1490 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1491 @end quotation
1492
1493 Clicking any of the links will take you to the page of the respective
1494 object interface.  Each interface has a number of properties.  Some of
1495 them are not user-serviceable (@q{Internal properties}), but others
1496 can be modified.
1497
1498 We have been talking of @emph{the} @code{Fingering} object, but actually it
1499 does not amount to much.  The initialization file (see
1500 @ref{Default files})
1501 @file{scm/@/define@/-grobs@/.scm} shows the soul of the @q{object},
1502
1503 @example
1504 (Fingering
1505   . ((padding . 0.5)
1506      (avoid-slur . around)
1507      (slur-padding . 0.2)
1508      (staff-padding . 0.5)
1509      (self-alignment-X . 0)
1510      (self-alignment-Y . 0)
1511      (script-priority . 100)
1512      (stencil . ,ly:text-interface::print)
1513      (direction . ,ly:script-interface::calc-direction)
1514      (font-encoding . fetaNumber)
1515      (font-size . -5)           ; don't overlap when next to heads.
1516      (meta . ((class . Item)
1517      (interfaces . (finger-interface
1518                     font-interface
1519                     text-script-interface
1520                     text-interface
1521                     side-position-interface
1522                     self-alignment-interface
1523                     item-interface))))))
1524 @end example
1525
1526 @noindent
1527 As you can see, the @code{Fingering} object is nothing more than a
1528 bunch of variable settings, and the webpage in the Program Reference
1529 is directly generated from this definition.
1530
1531
1532 @node Determining the grob property
1533 @subsection Determining the grob property
1534
1535 Recall that we wanted to change the position of the @b{2} in
1536
1537 @lilypond[quote,fragment,relative=2,verbatim]
1538 c-2
1539 \stemUp
1540 f
1541 @end lilypond
1542
1543 Since the @b{2} is vertically positioned next to its note, we have to
1544 meddle with the interface associated with this positioning.  This is
1545 done using @code{side-position-interface}.  The page for this interface
1546 says
1547
1548 @quotation
1549 @code{side-position-interface}
1550
1551 Position a victim object (this one) next to other objects (the
1552 support).  The property @code{direction} signifies where to put the
1553 victim object relative to the support (left or right, up or down?)
1554 @end quotation
1555
1556 @cindex padding
1557 @noindent
1558 Below this description, the variable @code{padding} is described as
1559
1560 @quotation
1561 @table @code
1562 @item padding
1563 (dimension, in staff space)
1564
1565 Add this much extra space between objects that are next to each other.
1566 @end table
1567 @end quotation
1568
1569 By increasing the value of @code{padding}, we can move the
1570 fingering away from the notehead.  The following command inserts
1571 3 staff spaces of white
1572 between the note and the fingering:
1573 @example
1574 \once \override Voice.Fingering #'padding = #3
1575 @end example
1576
1577 Inserting this command before the Fingering object is created,
1578 i.e., before @code{c2}, yields the following result:
1579
1580 @lilypond[quote,relative=2,fragment,verbatim]
1581 \once \override Voice.Fingering #'padding = #3
1582 c-2
1583 \stemUp
1584 f
1585 @end lilypond
1586
1587
1588 In this case, the context for this tweak is @context{Voice}.  This
1589 fact can also be deduced from the program reference, for the page for
1590 the @internalsref{Fingering_engraver} plug-in says
1591
1592 @quotation
1593 Fingering_engraver is part of contexts: @dots{} @internalsref{Voice}
1594 @end quotation
1595
1596
1597 @node Objects connected to the input
1598 @subsection Objects connected to the input
1599
1600 @funindex \tweak
1601
1602 In some cases, it is possible to take a short-cut for tuning graphical
1603 objects.  For objects that result directly from a piece of the input,
1604 you can use the @code{\tweak} function, for example
1605
1606 @lilypond[relative=2,fragment,verbatim,ragged-right]
1607 <
1608   c
1609   \tweak #'color #red d
1610   g
1611   \tweak #'duration-log #1  a
1612 >4-\tweak #'padding #10 -.
1613 @end lilypond
1614
1615 As you can see, properties are set in the objects directly,
1616 without mentioning the grob name or context where this should be
1617 applied.
1618
1619 This technique only works for objects that are directly connected to
1620 an @internalsref{event} from the input, for example
1621
1622 @itemize @bullet
1623 @item note heads, caused by chord-pitch (i.e., notes inside a chord)
1624 @item articulation signs, caused by articulation instructions
1625 @end itemize
1626
1627 It notably does not work for stems and accidentals (these are caused
1628 by note heads, not by music events) or clefs (these are not caused by
1629 music inputs, but rather by the change of a property value).
1630
1631 There are very few objects which are @emph{directly} connected to
1632 output.  A normal note (like @code{c4}) is not directly connected
1633 to output, so
1634
1635 @example
1636 \tweak #'color #red c4
1637 @end example
1638
1639 @noindent
1640 does not change color.  See @ref{Displaying music expressions} for
1641 details.
1642
1643
1644 @node Using Scheme code instead of \tweak
1645 @subsection Using Scheme code instead of @code{\tweak}
1646
1647 The main disadvantage of @code{\tweak} is its syntactical
1648 inflexibility.  For example, the following produces a syntax error.
1649
1650 @example
1651 F = \tweak #'font-size #-3 -\flageolet
1652
1653 \relative c'' @{
1654   c4^\F c4_\F
1655 @}
1656 @end example
1657
1658 @noindent
1659 With other words, @code{\tweak} doesn't behave like an articulation
1660 regarding the syntax; in particular, it can't be attached with
1661 @samp{^} and @samp{_}.
1662
1663 Using Scheme, this problem can be circumvented.  The route to the
1664 result is given in @ref{Adding articulation to notes (example)},
1665 especially how to use @code{\displayMusic} as a helping guide.
1666
1667 @example
1668 F = #(let ((m (make-music 'ArticulationEvent
1669                           'articulation-type "flageolet")))
1670        (set! (ly:music-property m 'tweaks)
1671              (acons 'font-size -3
1672                     (ly:music-property m 'tweaks)))
1673        m)
1674  
1675 \relative c'' @{
1676   c4^\F c4_\F
1677 @}
1678 @end example
1679
1680 @noindent
1681 Here, the @code{tweaks} properties of the flageolet object
1682 @samp{m} (created with @code{make-music}) are extracted with
1683 @code{ly:music-property}, a new key-value pair to change the
1684 font size is prepended to the property list with the
1685 @code{acons} Scheme function, and the result is finally
1686 written back with @code{set!}.  The last element of the
1687 @code{let} block is the return value, @samp{m} itself.
1688
1689
1690 @node \set versus \override
1691 @subsection @code{\set} vs. @code{\override}
1692
1693 We have seen two methods of changing properties: @code{\set} and
1694 @code{\override}.  There are actually two different kinds of
1695 properties.
1696
1697 Contexts can have properties, which are usually named in
1698 @code{studlyCaps}.  They mostly control the translation from
1699 music to notatino, eg. @code{localKeySignature} (for determining
1700 whether to print accidentals), @code{measurePosition} (for
1701 determining when to print a barline).  Context properties can
1702 change value over time while interpreting a piece of music;
1703 @code{measurePosition} is an obvious example of
1704 this.  Context properties are modified with @code{\set}.
1705
1706 There is a special type of context property: the element
1707 description. These properties are named in @code{StudlyCaps}
1708 (starting with capital letters).  They contain the
1709 @q{default settings} for said graphical object as an
1710 association list.  See @file{scm/@/define@/-grobs@/.scm}
1711 to see what kind of settings there are.  Element descriptions
1712 may be modified with @code{\override}.
1713
1714 @code{\override} is actually a shorthand;
1715
1716 @example
1717 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1718 @end example
1719
1720 @noindent
1721 is more or less equivalent to
1722
1723 @c  leave this long line -gp
1724 @example
1725 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1726 @end example
1727
1728 The value of @code{context} (the alist) is used to initalize
1729 the properties of individual grobs.  Grobs also have
1730 properties, named in Scheme style, with
1731 @code{dashed-words}.  The values of grob properties change
1732 during the formatting process: formatting basically amounts
1733 to computing properties using callback functions.
1734
1735 @code{fontSize} is a special property: it is equivalent to
1736 entering @code{\override ... #'font-size} for all pertinent
1737 objects.  Since this is a common change, the special
1738 property (modified with @code{\set}) was created.
1739
1740
1741 @node Difficult tweaks
1742 @subsection Difficult tweaks
1743
1744 There are a few classes of difficult adjustments.
1745
1746 @itemize @bullet
1747
1748
1749 @item
1750 One type of difficult adjustment is the appearance of spanner objects,
1751 such as slur and tie.  Initially, only one of these objects is created,
1752 and they can be adjusted with the normal mechanism.  However, in some
1753 cases the spanners cross line breaks.  If this happens, these objects
1754 are cloned.  A separate object is created for every system that it is
1755 in.  These are clones of the original object and inherit all
1756 properties, including @code{\override}s.
1757
1758
1759 In other words, an @code{\override} always affects all pieces of a
1760 broken spanner.  To change only one part of a spanner at a line break,
1761 it is necessary to hook into the formatting process.  The
1762 @code{after-line-breaking} callback contains the Scheme procedure that
1763 is called after the line breaks have been determined, and layout
1764 objects have been split over different systems.
1765
1766 In the following example, we define a procedure
1767 @code{my-callback}.  This procedure
1768
1769 @itemize @bullet
1770 @item
1771 determines if we have been split across line breaks
1772 @item
1773 if yes, retrieves all the split objects
1774 @item
1775 checks if we are the last of the split objects
1776 @item
1777 if yes, it sets @code{extra-offset}.
1778 @end itemize
1779
1780 This procedure is installed into @internalsref{Tie}, so the last part
1781 of the broken tie is translated up.
1782
1783 @lilypond[quote,verbatim,ragged-right]
1784 #(define (my-callback grob)
1785   (let* (
1786          ; have we been split?
1787          (orig (ly:grob-original grob))
1788
1789          ; if yes, get the split pieces (our siblings)
1790          (siblings (if (ly:grob? orig)
1791                      (ly:spanner-broken-into orig) '() )))
1792
1793    (if (and (>= (length siblings) 2)
1794              (eq? (car (last-pair siblings)) grob))
1795      (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1796
1797 \relative c'' {
1798   \override Tie #'after-line-breaking =
1799   #my-callback
1800   c1 ~ \break c2 ~ c
1801 }
1802 @end lilypond
1803
1804 @noindent
1805 When applying this trick, the new @code{after-line-breaking} callback
1806 should also call the old one @code{after-line-breaking}, if there is
1807 one.  For example, if using this with @code{Hairpin},
1808 @code{ly:hairpin::after-line-breaking} should also be called.
1809
1810
1811 @item Some objects cannot be changed with @code{\override} for
1812 technical reasons. Examples of those are @code{NonMusicalPaperColumn}
1813 and @code{PaperColumn}.  They can be changed with the
1814 @code{\outputProperty} function, which works similar to @code{\once
1815 \override}, but uses a different syntax,
1816
1817 @example
1818 \outputProperty
1819 #"Score.NonMusicalPaperColumn"  % Grob name
1820 #'line-break-system-details     % Property name
1821 #'((next-padding . 20))         % Value
1822 @end example
1823
1824 @end itemize