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