1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Changing defaults
3 @chapter Changing defaults
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
15 @cindex Program reference
17 The controls available for tuning are described in a separate
20 Program reference manual.
23 @ref{Top,Program reference,,lilypond-internals}.
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.
32 There are four areas where the default settings may be changed:
36 Automatic notation: changing the automatic creation of notation
37 elements. For example, changing the beaming rules.
40 Output: changing the appearance of individual
41 objects. For example, changing stem directions or the location of
45 Context: changing aspects of the translation from music events to
46 notation. For example, giving each staff a separate time signature.
49 Global layout: changing the appearance of the spacing, line
50 breaks, and page dimensions. These modifications are discussed
51 in @ref{Global issues}.
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.}
63 * Automatic notation::
64 * Interpretation contexts::
65 * The \override command::
69 @node Automatic notation
70 @section Automatic notation
72 This section describes how to change the way that accidentals and
73 beams are automatically displayed.
76 * Automatic accidentals::
77 * Setting automatic beam behavior::
80 @node Automatic accidentals
81 @subsection Automatic accidentals
82 @cindex Automatic accidentals
84 Common rules for typesetting accidentals have been placed in a
85 function. This function is called as follows
87 @cindex @code{set-accidental-style}
89 #(set-accidental-style 'STYLE #('CONTEXT#))
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}
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
102 The following accidental styles are supported
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.
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
116 As a result, accidentals from one voice do not get canceled in other
117 voices, which is often an unwanted result
119 @lilypond[quote,ragged-right,relative=1,fragment,verbatim]
121 #(set-accidental-style 'voice)
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.
135 @cindex @code{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
142 @lilypond[quote,ragged-right,fragment,verbatim]
143 #(set-accidental-style 'modern)
144 cis' c'' cis'2 | c'' c'
147 @item @code{modern-cautionary}
148 @cindex @code{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'
157 @cindex @code{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}.
164 @cindex @code{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.
173 @cindex @code{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}.
179 @item piano-cautionary
180 @cindex @code{#(set-accidental-style 'piano-cautionary)}
181 Same as @code{#(set-accidental-style 'piano)} but with the extra
182 accidentals typeset as cautionaries.
185 @cindex @code{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)
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
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
208 Program reference: @internalsref{Accidental_engraver},
209 @internalsref{Accidental}, and @internalsref{AccidentalPlacement}.
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
224 @node Setting automatic beam behavior
225 @subsection Setting automatic beam behavior
227 @cindex @code{autoBeamSettings}
228 @cindex @code{(end * * * *)}
229 @cindex @code{(begin * * * *)}
230 @cindex automatic beams, tuning
231 @cindex tuning automatic beaming
233 @c [TODO: use \applyContext]
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}.
243 In order to add a rule to the list, use
245 #(override-auto-beam-setting '(be p q n m) a b [context])
250 @item @code{be} is either "begin" or "end".
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.
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.
261 @item @code{a/b} is the position in the bar at which the beam should
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)}.
271 For example, if automatic beams should always end on the first quarter
275 #(override-auto-beam-setting '(end * * * *) 1 4)
278 You can force the beam settings to only take effect on beams whose shortest
279 note is a certain duration
281 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
283 #(override-auto-beam-setting '(end 1 16 * *) 1 16)
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 |
290 You can force the beam settings to only take effect in certain time
293 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
295 #(override-auto-beam-setting '(end * * 5 8) 2 8)
303 You can also remove a previously set beam-ending rule by using
306 #(revert-auto-beam-setting '(be p q n m) a b [context])
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.
314 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
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
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.
324 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
326 #(override-auto-beam-setting '(end 1 16 1 4) 1 8)
328 #(revert-auto-beam-setting '(end 1 16 * *) 1 8) % this won't revert it!
330 #(revert-auto-beam-setting '(end 1 16 1 4) 1 8) % this will
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
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)
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
350 #(override-auto-beam-setting '(end * * * *) 3 8)
351 #(override-auto-beam-setting '(end * * * *) 1 2)
352 #(override-auto-beam-setting '(end * * * *) 7 8)
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).
358 @cindex automatic beam generation
360 @cindex @code{autoBeaming}
363 If beams are used to indicate melismata in songs, then automatic
364 beaming should be switched off with @code{\autoBeamOff}.
369 @cindex @code{\autoBeamOff}
371 @cindex @code{\autoBeamOn}
377 If a score ends while an automatic beam has not been ended and is
378 still accepting notes, this last beam will not be typeset at all. The
379 same holds polyphonic voices, entered with @code{<< @dots{} \\ @dots{}
380 >>}. If a polyphonic voice ends while an automatic beam is still
381 accepting notes, it is not typeset.
384 @node Interpretation contexts
385 @section Interpretation contexts
387 When music is printed, a lot of notational elements must be added to the
388 input. For example, compare the input and output of the following example:
390 @lilypond[quote,verbatim,relative=2,fragment]
394 The input is rather sparse, but in the output, bar lines, accidentals,
395 clef, and time signature are added. LilyPond @emph{interprets} the
396 input. During this step, the musical information is inspected in time
397 order, similar to reading a score from left to right. While reading
398 the input, the program remembers where measure boundaries are, and which
399 pitches require explicit accidentals. This information can be presented on
400 several levels. For example, the effect of an accidental is limited
401 to a single staff, while a bar line must be synchronized across the
404 Within LilyPond, these rules and bits of information are grouped in
405 @emph{Contexts}. Some examples of contexts are @context{Voice},
406 @context{Staff}, and @context{Score}. They are hierarchical, for
407 example: a @context{Staff} can contain many @context{Voice}s, and a
408 @context{Score} can contain many @context{Staff} contexts.
410 Each context has the responsibility for enforcing some notation rules,
411 creating some notation objects and maintaining the associated
412 properties. For example, the @context{Voice} context may introduce an
413 accidental and then the @context{Staff} context maintains the rule to
414 show or suppress the accidental for the remainder of the measure. The
415 synchronization of bar lines is handled at @context{Score} context.
417 However, in some music we may not want the bar lines to be
418 synchronized -- consider a polymetric score in 4/4 and 3/4 time. In
419 such cases, we must modify the default settings of the @context{Score}
420 and @context{Staff} contexts.
422 For very simple scores, contexts are created implicitly, and you need
423 not be aware of them. For larger pieces, such as anything with more
424 than one staff, they must be
425 created explicitly to make sure that you get as many staves as you
426 need, and that they are in the correct order. For typesetting pieces
427 with specialized notation, it can be useful to modify existing or
428 to define new contexts.
431 A complete description of all available contexts is in the program
434 @internalsref{Contexts}.
437 Translation @arrow{} Context.
440 @c [TODO: describe propagation]
444 * Creating contexts::
445 * Changing context properties on the fly::
446 * Modifying context plug-ins::
447 * Layout tunings within contexts::
448 * Changing context default settings::
449 * Defining new contexts::
452 @node Creating contexts
453 @subsection Creating contexts
455 For scores with only one voice and one staff, contexts are
456 created automatically. For more complex scores, it is necessary to
457 create them by hand. There are three commands that do this.
462 The easiest command is @code{\new}, and it also the quickest to type.
463 It is prepended to a music expression, for example
467 @cindex Context, creating
470 \new @var{type} @var{music expression}
474 where @var{type} is a context name (like @code{Staff} or
475 @code{Voice}). This command creates a new context, and starts
476 interpreting the @var{music expression} with that.
478 A practical application of @code{\new} is a score with many
479 staves. Each part that should be on its own staff, is preceded with
482 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
489 The @code{\new} command may also give a name to the context,
492 \new @var{type} = @var{id} @var{music}
494 However, this user specified name is only used if there is no other
495 context already earlier with the same name.
498 @cindex @code{\context}
501 Like @code{\new}, the @code{\context} command also directs a music
502 expression to a context object, but gives the context an explicit name. The
506 \context @var{type} = @var{id} @var{music}
509 This form will search for an existing context of type @var{type}
510 called @var{id}. If that context does not exist yet, a new
511 context with the specified name is created. This is useful if
512 the context is referred to later on. For example, when
513 setting lyrics the melody is in a named context
516 \context Voice = "@b{tenor}" @var{music}
520 so the texts can be properly aligned to its notes,
523 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
528 Another possible use of named contexts is funneling two different
529 music expressions into one context. In the following example,
530 articulations and notes are entered separately,
534 arts = @{ s4-. s4-> @}
537 They are combined by sending both to the same @context{Voice} context,
541 \new Staff \context Voice = "A" \music
542 \context Voice = "A" \arts
545 @lilypond[quote,ragged-right]
549 \new Staff \context Voice = "A" \music
550 \context Voice = "A" \arts
554 With this mechanism, it is possible to define an Urtext (original
555 edition), with the option to put several distinct articulations on the
558 @cindex creating contexts
561 The third command for creating contexts is
563 \context @var{type} @var{music}
568 This is similar to @code{\context} with @code{= @var{id}}, but matches
569 any context of type @var{type}, regardless of its given name.
571 This variant is used with music expressions that can be interpreted at
572 several levels. For example, the @code{\applyOutput} command (see
573 @ref{Running a function on all layout objects}). Without an explicit
574 @code{\context}, it is usually applied to @context{Voice}
577 \applyOutput #@var{function} % apply to Voice
580 To have it interpreted at the @context{Score} or @context{Staff} level use
584 \context Score \applyOutput #@var{function}
585 \context Staff \applyOutput #@var{function}
591 @node Changing context properties on the fly
592 @subsection Changing context properties on the fly
596 @cindex changing properties
598 Each context can have different @emph{properties}, variables contained
599 in that context. They can be changed during the interpretation step.
600 This is achieved by inserting the @code{\set} command in the music,
603 \set @var{context}.@var{prop} = #@var{value}
607 @lilypond[quote,verbatim,relative=2,fragment]
609 \set Score.skipBars = ##t
613 This command skips measures that have no notes. The result is that
614 multi-rests are condensed. The value assigned is a Scheme object. In
615 this case, it is @code{#t}, the boolean True value.
617 If the @var{context} argument is left out, then the current bottom-most
618 context (typically @context{ChordNames}, @context{Voice}, or
619 @context{Lyrics}) is used. In this example,
621 @lilypond[quote,verbatim,relative=2,fragment]
623 \set autoBeaming = ##f
628 the @var{context} argument to @code{\set} is left out, so automatic
629 beaming is switched off in the current @internalsref{Voice}. Note that
630 the bottom-most context does not always contain the property that you
631 wish to change -- for example, attempting to set the @code{skipBars}
632 property (of the bottom-most context, in this case @code{Voice}) will
635 @lilypond[quote,verbatim,relative=2,fragment]
641 Contexts are hierarchical, so if a bigger context was specified, for
642 example @context{Staff}, then the change would also apply to all
643 @context{Voice}s in the current stave. The change is applied
644 `on-the-fly', during the music, so that the setting only affects the
645 second group of eighth notes.
647 @cindex @code{\unset}
649 There is also an @code{\unset} command,
651 \unset @var{context}.@var{prop}
655 which removes the definition of @var{prop}. This command removes
656 the definition only if it is set in @var{context}, so
659 \set Staff.autoBeaming = ##f
663 introduces a property setting at @code{Staff} level. The setting also
664 applies to the current @code{Voice}. However,
667 \unset Voice.autoBeaming
671 does not have any effect. To cancel this setting, the @code{\unset}
672 must be specified on the same level as the original @code{\set}. In
673 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
676 \unset Staff.autoBeaming
679 Like @code{\set}, the @var{context} argument does not have to be
680 specified for a bottom context, so the two statements
683 \set Voice.autoBeaming = ##t
684 \set autoBeaming = ##t
692 Settings that should only apply to a single time-step can be entered
693 with @code{\once}, for example in
695 @lilypond[quote,verbatim,relative=2,fragment]
697 \once \set fontSize = #4.7
702 the property @code{fontSize} is unset automatically after the second
705 A full description of all available context properties is in the
706 program reference, see
708 @internalsref{Tunable context properties}.
711 Translation @arrow{} Tunable context properties.
715 @node Modifying context plug-ins
716 @subsection Modifying context plug-ins
718 Notation contexts (like @code{Score} and @code{Staff}) not only
720 they also contain plug-ins called ``engravers'' that create notation
721 elements. For example, the @code{Voice} context contains a
722 @code{Note_head_engraver} and the @code{Staff} context contains a
723 @code{Key_signature_engraver}.
725 For a full a description of each plug-in, see
727 @internalsref{Engravers}.
730 Program reference @arrow Translation @arrow{} Engravers.
732 Every context described in
734 @internalsref{Contexts}
737 Program reference @arrow Translation @arrow{} Context.
739 lists the engravers used for that context.
742 It can be useful to shuffle around these plug-ins. This is done by
743 starting a new context with @code{\new} or @code{\context}, and
749 \new @var{context} \with @{
762 where the @dots{} should be the name of an engraver. Here is a simple
763 example which removes @code{Time_signature_engraver} and
764 @code{Clef_engraver} from a @code{Staff} context,
766 @lilypond[quote,relative=1,verbatim,fragment]
772 \remove "Time_signature_engraver"
773 \remove "Clef_engraver"
780 In the second staff there are no time signature or clef symbols. This
781 is a rather crude method of making objects disappear since it will affect
782 the entire staff. This method also influences the spacing, which may or
783 may not be desirable. A more
784 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
786 The next example shows a practical application. Bar lines and time
787 signatures are normally synchronized across the score. This is done
788 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
789 This plug-in keeps an administration of time signature, location
790 within the measure, etc. By moving thes engraver from @code{Score} to
791 @code{Staff} context, we can have a score where each staff has its own
794 @cindex polymetric scores
795 @cindex Time signatures, multiple
797 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
799 \remove "Timing_translator"
800 \remove "Default_bar_line_engraver"
803 \consists "Timing_translator"
804 \consists "Default_bar_line_engraver"
810 \consists "Timing_translator"
811 \consists "Default_bar_line_engraver"
820 @node Layout tunings within contexts
821 @subsection Layout tunings within contexts
823 Each context is responsible for creating certain types of graphical
824 objects. The settings used for printing these objects are also stored by
825 context. By changing these settings, the appearance of objects can be
828 The syntax for this is
831 \override @var{context}.@var{name} #'@var{property} = #@var{value}
834 Here @var{name} is the name of a graphical object, like @code{Stem} or
835 @code{NoteHead}, and @var{property} is an internal variable of the
836 formatting system (`grob property' or `layout property'). The latter is a
837 symbol, so it must be quoted. The subsection @ref{Constructing a
838 tweak} explains what to fill in for @var{name}, @var{property}, and
839 @var{value}. Here we only discuss the functionality of this command.
844 \override Staff.Stem #'thickness = #4.0
848 makes stems thicker (the default is 1.3, with staff line thickness as a
849 unit). Since the command specifies @context{Staff} as context, it only
850 applies to the current staff. Other staves will keep their normal
851 appearance. Here we see the command in action:
853 @lilypond[quote,verbatim,relative=2,fragment]
855 \override Staff.Stem #'thickness = #4.0
861 The @code{\override} command changes the definition of the @code{Stem}
862 within the current @context{Staff}. After the command is interpreted
863 all stems are thickened.
865 Analogous to @code{\set}, the @var{context} argument may be left out,
866 causing it to default to @context{Voice}, and adding @code{\once} applies
867 the change during one timestep only
869 @lilypond[quote,fragment,verbatim,relative=2]
871 \once \override Stem #'thickness = #4.0
876 The @code{\override} must be done before the object is
877 started. Therefore, when altering @emph{Spanner} objects such as slurs
878 or beams, the @code{\override} command must be executed at the moment
879 when the object is created. In this example,
881 @lilypond[quote,fragment,verbatim,relative=2]
882 \override Slur #'thickness = #3.0
884 \override Beam #'thickness = #0.6
889 the slur is fatter but the beam is not. This is because the command for
890 @code{Beam} comes after the Beam is started, so it has no effect.
892 Analogous to @code{\unset}, the @code{\revert} command for a context
893 undoes an @code{\override} command; like with @code{\unset}, it only
894 affects settings that were made in the same context. In other words, the
895 @code{\revert} in the next example does not do anything.
898 \override Voice.Stem #'thickness = #4.0
899 \revert Staff.Stem #'thickness
902 Some tweakable options are called ``subproperties'' and reside inside
903 properties. To tweak those, use commands of the form
905 @c leave this as a long long
907 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
914 \override Stem #'details #'beamed-lengths = #'(4 4 3)
920 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
921 @internalsref{PropertySet}, @internalsref{Backend}, and
922 @internalsref{All layout objects}.
927 The back-end is not very strict in type-checking object properties.
928 Cyclic references in Scheme values for properties can cause hangs
932 @node Changing context default settings
933 @subsection Changing context default settings
935 The adjustments of the previous subsections (@ref{Changing context
936 properties on the fly}, @ref{Modifying context plug-ins}, and
937 @ref{Layout tunings within contexts}) can also be entered separately
938 from the music in the @code{\layout} block,
947 \override Stem #'thickness = #4.0
948 \remove "Time_signature_engraver"
953 Here @code{\Staff} takes the existing definition for context @context{Staff} from the
954 identifier @code{\Staff}.
959 \override Stem #'thickness = #4.0
960 \remove "Time_signature_engraver"
964 affect all staves in the score. Other contexts can be modified
967 The @code{\set} keyword is optional within the @code{\layout} block, so
983 It is not possible to collect context changes in a variable and apply
984 them to a @code{\context} definition by referring to that variable.
986 The @code{\RemoveEmptyStaffContext} will overwrite your current
987 @code{\Staff} settings. If you wish to change the defaults for a
988 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
989 after calling @code{\RemoveemptyStaffContext}, ie
994 \RemoveEmptyStaffContext
996 \override Stem #'thickness = #4.0
1002 @node Defining new contexts
1003 @subsection Defining new contexts
1005 Specific contexts, like @context{Staff} and @code{Voice}, are made of
1006 simple building blocks. It is possible to create new types of
1007 contexts with different combinations of engraver plug-ins.
1009 The next example shows how to build a different type of
1010 @context{Voice} context from scratch. It will be similar to
1011 @code{Voice}, but only prints centered slash noteheads. It can be used
1012 to indicate improvisation in jazz pieces,
1014 @lilypond[quote,ragged-right]
1015 \layout { \context {
1017 \type "Engraver_group"
1018 \consists "Note_heads_engraver"
1019 \consists "Text_engraver"
1020 \consists Pitch_squash_engraver
1021 squashedPosition = #0
1022 \override NoteHead #'style = #'slash
1023 \override Stem #'transparent = ##t
1027 \accepts "ImproVoice"
1031 a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
1032 c4 c^"undress" c_"while playing :)" c }
1038 These settings are defined within a @code{\context} block inside a
1039 @code{\layout} block,
1049 In the following discussion, the example input shown should go on the
1050 @dots{} in the previous fragment.
1052 First the context's name is defined. Instead of @context{Voice} it
1053 will be called @context{ImproVoice},
1059 Since it is similar to the @context{Voice}, we want commands that work
1060 on (existing) @context{Voice}s to remain working. This is achieved by
1061 giving the new context an alias @context{Voice},
1067 The context will print notes, and instructive texts
1070 \consists Note_heads_engraver
1071 \consists Text_engraver
1074 but only on the center line,
1077 \consists Pitch_squash_engraver
1078 squashedPosition = #0
1081 The @internalsref{Pitch_squash_engraver} modifies note heads (created
1082 by @internalsref{Note_heads_engraver}) and sets their vertical
1083 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
1086 The notes look like a slash, and have no stem,
1089 \override NoteHead #'style = #'slash
1090 \override Stem #'transparent = ##t
1093 All these plug-ins have to cooperate, and this is achieved with a
1094 special plug-in, which must be marked with the keyword @code{\type}.
1095 This should always be @internalsref{Engraver_group},
1098 \type "Engraver_group"
1101 Put together, we get
1106 \type "Engraver_group"
1107 \consists "Note_heads_engraver"
1108 \consists "Text_engraver"
1109 \consists Pitch_squash_engraver
1110 squashedPosition = #0
1111 \override NoteHead #'style = #'slash
1112 \override Stem #'transparent = ##t
1117 @cindex @code{\accepts}
1118 Contexts form hierarchies. We want to hang the @context{ImproVoice}
1119 under @context{Staff}, just like normal @code{Voice}s. Therefore, we
1120 modify the @code{Staff} definition with the @code{\accepts}
1130 @cindex @code{\denies}
1131 The opposite of @code{\accepts} is @code{\denies},
1132 which is sometimes needed when reusing existing context definitions.
1134 Putting both into a @code{\layout} block, like
1144 \accepts "ImproVoice"
1149 Then the output at the start of this subsection can be entered as
1157 c c_"while playing :)"
1166 @node The \override command
1167 @section The \override command
1169 In the previous section, we have already touched on a command that
1170 changes layout details: the @code{\override} command. In this section,
1171 we will look in more detail at how to use the command in practice.
1175 * Constructing a tweak::
1176 * Navigating the program reference::
1177 * Layout interfaces::
1178 * Determining the grob property::
1179 * Objects connected to the input::
1180 * \set vs. \override::
1181 * Difficult tweaks::
1186 @node Constructing a tweak
1187 @subsection Constructing a tweak
1189 Commands which change output generally look like
1192 \override Voice.Stem #'thickness = #3.0
1196 This means that we must determine these bits of information:
1199 @item the context: here @context{Voice}.
1200 @item the layout object: here @code{Stem}.
1201 @item the layout property: here @code{thickness}.
1202 @item a sensible value: here @code{3.0}.
1205 Some tweakable options are called ``subproperties'' and reside inside
1206 properties. To tweak those, use commands in the form
1209 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1212 @cindex internal documentation
1213 @cindex finding graphical objects
1214 @cindex graphical object descriptions
1216 @cindex @code{\override}
1217 @cindex internal documentation
1219 We demonstrate how to glean this information from the notation manual
1220 and the program reference.
1223 @node Navigating the program reference
1224 @subsection Navigating the program reference
1226 Suppose we want to move the fingering indication in the fragment
1229 @lilypond[quote,fragment,relative=2,verbatim]
1235 If you visit the documentation on fingering instructions (in
1236 @ref{Fingering instructions}), you will notice:
1241 Program reference: @internalsref{Fingering}.
1246 @c outdated info; probably will delete.
1248 This fragment points to two parts of the program reference: a page
1249 on @code{FingerEvent} and one on @code{Fingering}.
1251 The page on @code{FingerEvent} describes the properties of the music
1252 expression for the input @code{-2}. The page contains many links
1253 forward. For example, it says
1256 Accepted by: @internalsref{Fingering_engraver},
1260 That link brings us to the documentation for the Engraver, the
1264 This engraver creates the following layout objects: @internalsref{Fingering}.
1267 In other words, once the @code{FingerEvent}s are interpreted, the
1268 @code{Fingering_engraver} plug-in will process them.
1272 @c I can't figure out what this is supposed to mean. -gp
1274 The @code{Fingering_engraver} is also listed to create
1275 @internalsref{Fingering} objects,
1277 @c old info? it doesn't make any sense to me with our current docs.
1279 second bit of information listed under @b{See also} in the Notation
1283 Follow the link to @internalsref{Fingering}. At the top of the
1287 Fingering objects are created by: @internalsref{Fingering_engraver} and
1288 @internalsref{New_fingering_engraver}.
1291 By clicking around in the program reference, we can follow the
1292 flow of information within the program, following links like this:
1296 @item @internalsref{Fingering}:
1297 @internalsref{Fingering} objects are created by:
1298 @b{@internalsref{Fingering_engraver}}
1300 @item @internalsref{Fingering_engraver}:
1301 Music types accepted: @b{@internalsref{fingering-event}}
1303 @item @internalsref{fingering-event}:
1304 Music event type @code{fingering-event} is in Music expressions named
1305 @b{@internalsref{FingerEvent}}
1308 This path goes against the flow of information in the program: it
1309 starts from the output, and ends at the input event. You could
1310 also start at an input event, and read with the flow of
1311 information, eventually ending up at the output object(s).
1313 The program reference can also be browsed like a normal document. It
1314 contains chapters on
1316 @internalsref{Music definitions},
1319 @code{Music definitions}
1321 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1322 chapter lists all the definitions used and all properties that may be
1326 @node Layout interfaces
1327 @subsection Layout interfaces
1329 @cindex interface, layout
1330 @cindex layout interface
1333 The HTML page that we found in the previous section describes the
1334 layout object called @internalsref{Fingering}. Such an object is a
1335 symbol within the score. It has properties that store numbers (like
1336 thicknesses and directions), but also pointers to related objects. A
1337 layout object is also called a @emph{Grob}, which is short for Graphical
1338 Object. For more details about Grobs, see @internalsref{grob-interface}.
1340 The page for @code{Fingering} lists the definitions for the
1341 @code{Fingering} object. For example, the page says
1344 @code{padding} (dimension, in staff space):
1350 which means that the number will be kept at a distance of at least 0.6
1354 Each layout object may have several functions as a notational or
1355 typographical element. For example, the Fingering object
1356 has the following aspects
1360 Its size is independent of the horizontal spacing, unlike slurs or beams.
1363 It is a piece of text. Granted, it is usually a very short text.
1366 That piece of text is typeset with a font, unlike slurs or beams.
1369 Horizontally, the center of the symbol should be aligned to the
1370 center of the notehead.
1373 Vertically, the symbol is placed next to the note and the staff.
1376 The vertical position is also coordinated with other superscript
1377 and subscript symbols.
1380 Each of these aspects is captured in so-called @emph{interface}s,
1381 which are listed on the @internalsref{Fingering} page at the bottom
1384 This object supports the following interfaces:
1385 @internalsref{item-interface},
1386 @internalsref{self-alignment-interface},
1387 @internalsref{side-position-interface}, @internalsref{text-interface},
1388 @internalsref{text-script-interface}, @internalsref{font-interface},
1389 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1392 Clicking any of the links will take you to the page of the respective
1393 object interface. Each interface has a number of properties. Some of
1394 them are not user-serviceable (``Internal properties''), but others
1397 We have been talking of @emph{the} @code{Fingering} object, but actually it
1398 does not amount to much. The initialization file (see
1399 @ref{Default files})
1400 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1405 (avoid-slur . around)
1406 (slur-padding . 0.2)
1407 (staff-padding . 0.5)
1408 (self-alignment-X . 0)
1409 (self-alignment-Y . 0)
1410 (script-priority . 100)
1411 (stencil . ,ly:text-interface::print)
1412 (direction . ,ly:script-interface::calc-direction)
1413 (font-encoding . fetaNumber)
1414 (font-size . -5) ; don't overlap when next to heads.
1415 (meta . ((class . Item)
1416 (interfaces . (finger-interface
1418 text-script-interface
1420 side-position-interface
1421 self-alignment-interface
1422 item-interface))))))
1426 As you can see, the @code{Fingering} object is nothing more than a
1427 bunch of variable settings, and the webpage in the Program Reference
1428 is directly generated from this definition.
1431 @node Determining the grob property
1432 @subsection Determining the grob property
1434 Recall that we wanted to change the position of the @b{2} in
1436 @lilypond[quote,fragment,relative=2,verbatim]
1442 Since the @b{2} is vertically positioned next to its note, we have to
1443 meddle with the interface associated with this positioning. This is
1444 done using @code{side-position-interface}. The page for this interface
1448 @code{side-position-interface}
1450 Position a victim object (this one) next to other objects (the
1451 support). The property @code{direction} signifies where to put the
1452 victim object relative to the support (left or right, up or down?)
1457 Below this description, the variable @code{padding} is described as
1462 (dimension, in staff space)
1464 Add this much extra space between objects that are next to each other.
1468 By increasing the value of @code{padding}, we can move the
1469 fingering away from the notehead. The following command inserts
1470 3 staff spaces of white
1471 between the note and the fingering:
1473 \once \override Voice.Fingering #'padding = #3
1476 Inserting this command before the Fingering object is created,
1477 i.e., before @code{c2}, yields the following result:
1479 @lilypond[quote,relative=2,fragment,verbatim]
1480 \once \override Voice.Fingering #'padding = #3
1487 In this case, the context for this tweak is @context{Voice}. This
1488 fact can also be deduced from the program reference, for the page for
1489 the @internalsref{Fingering_engraver} plug-in says
1492 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1496 @node Objects connected to the input
1497 @subsection Objects connected to the input
1499 @cindex @code{\tweak}
1501 In some cases, it is possible to take a short-cut for tuning graphical
1502 objects. For objects that result directly from a piece of the input,
1503 you can use the @code{\tweak} function, for example
1505 @lilypond[relative=2,fragment,verbatim,ragged-right]
1508 \tweak #'color #red d
1510 \tweak #'duration-log #1 a
1511 >4-\tweak #'padding #10 -.
1514 As you can see, properties are set directly in the objects directly,
1515 without mentioning the grob name or context where this should be
1518 This technique only works for objects that are directly connected to
1519 an @internalsref{event} from the input, for example
1522 @item note heads, caused by chord-pitch (i.e., notes inside a chord).
1523 @item articulation signs, caused by articulation instructions.
1526 It notably does not work for stems and accidentals (these are caused
1527 by note heads, not by music events) or clefs (these are not caused by
1528 music inputs, but rather by the change of a property value).
1530 There are very few objects which are @emph{directly} connected to
1531 output. A normal note (like @code{c4}) is not directly connected
1535 \tweak #'color #red c4
1539 will not change color. See @ref{Displaying music expressions} for
1543 @node \set vs. \override
1544 @subsection \set vs. \override
1546 We have seen two methods of changing properties: @code{\set} and
1547 @code{\override}. There are actually two different kinds of
1550 Contexts can have properties, which are usually named in
1551 @code{studlyCaps}. They mostly control the translation from
1552 music to notatino, eg. @code{localKeySignature} (for determining
1553 whether to print accidentals), @code{measurePosition} (for
1554 determining when to print a barline). Context properties can
1555 change value over time while interpreting a piece of music;
1556 @code{measurePosition} is an obvious example of
1557 this. Context properties are modified with @code{\set}.
1559 There is a special type of context property: the element
1560 description. These properties are named in @code{StudlyCaps}
1561 (starting with capital letters). They contain the
1562 ``default settings'' for said graphical object as an
1563 association list. See @file{scm/@/define@/-grobs@/.scm}
1564 to see what kind of settings there are. Element descriptions
1565 may be modified with @code{\override}.
1567 @code{\override} is actually a shorthand;
1570 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1574 is more or less equivalent to
1576 @c leave this long line -gp
1578 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1581 The value of @code{context} (the alist) is used to initalize
1582 the properties of individual grobs. Grobs also have
1583 properties, named in scheme style, with
1584 @code{dashed-words}. The values of grob properties change
1585 during the formatting process: formatting basically amounts
1586 to computing properties using callback functions.
1588 @code{fontSize} is a special property: it is equivalent to
1589 entering @code{\override ... #'font-size} for all pertinent
1590 objects. Since this is a common change, the special
1591 property (modified with @code{\set}) was created.
1594 @node Difficult tweaks
1595 @subsection Difficult tweaks
1597 There are a few classes of difficult adjustments.
1603 One type of difficult adjustment is the appearance of spanner objects,
1604 such as slur and tie. Initially, only one of these objects is created,
1605 and they can be adjusted with the normal mechanism. However, in some
1606 cases the spanners cross line breaks. If this happens, these objects
1607 are cloned. A separate object is created for every system that it is
1608 in. These are clones of the original object and inherit all
1609 properties, including @code{\override}s.
1612 In other words, an @code{\override} always affects all pieces of a
1613 broken spanner. To change only one part of a spanner at a line break,
1614 it is necessary to hook into the formatting process. The
1615 @code{after-line-breaking} callback contains the Scheme procedure that
1616 is called after the line breaks have been determined, and layout
1617 objects have been split over different systems.
1619 In the following example, we define a procedure
1620 @code{my-callback}. This procedure
1624 determines if we have been split across line breaks
1626 if yes, retrieves all the split objects
1628 checks if we are the last of the split objects
1630 if yes, it sets @code{extra-offset}.
1633 This procedure is installed into @internalsref{Tie}, so the last part
1634 of the broken tie is translated up.
1636 @lilypond[quote,verbatim,ragged-right]
1637 #(define (my-callback grob)
1639 ; have we been split?
1640 (orig (ly:grob-original grob))
1642 ; if yes, get the split pieces (our siblings)
1643 (siblings (if (ly:grob? orig)
1644 (ly:spanner-broken-into orig) '() )))
1646 (if (and (>= (length siblings) 2)
1647 (eq? (car (last-pair siblings)) grob))
1648 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1651 \override Tie #'after-line-breaking =
1658 When applying this trick, the new @code{after-line-breaking} callback
1659 should also call the old one @code{after-line-breaking}, if there is
1660 one. For example, if using this with @code{Hairpin},
1661 @code{ly:hairpin::after-line-breaking} should also be called.
1664 @item Some objects cannot be changed with @code{\override} for
1665 technical reasons. Examples of those are @code{NonMusicalPaperColumn}
1666 and @code{PaperColumn}. They can be changed with the
1667 @code{\outputProperty} function, which works similar to @code{\once
1668 \override}, but uses a different syntax,
1672 #"Score.NonMusicalPaperColumn" % Grob name
1673 #'line-break-system-details % Property name
1674 #'((next-padding . 20)) % Value