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