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