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