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/@/lilypond@/-internals/,on@/-line},
29 but is also included with the LilyPond documentation package.
31 There are four areas where the default settings may be changed:
35 Automatic notation: changing the automatic creation of notation
36 elements. For example, changing the beaming rules.
39 Output: changing the appearance of individual
40 objects. For example, changing stem directions or the location of
44 Context: changing aspects of the translation from music events to
45 notation. For example, giving each staff a separate time signature.
48 Global layout: changing the appearance of the spacing, line
49 breaks, and page dimensions. These modifications are discussed
50 in @ref{Global issues}.
53 Internally, LilyPond uses Scheme (a LISP dialect) to provide
54 infrastructure. Overriding layout decisions in effect accesses the
55 program internals, which requires Scheme input. Scheme elements are
56 introduced in a @code{.ly} file with the hash mark
57 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
58 on entering numbers, lists, strings, and symbols in Scheme.}
62 * Automatic notation::
63 * Interpretation contexts::
64 * The \override command::
68 @node Automatic notation
69 @section Automatic notation
71 This section describes how to change the way that accidentals and
72 beams are automatically displayed.
75 * Automatic accidentals::
76 * Setting automatic beam behavior::
79 @node Automatic accidentals
80 @subsection Automatic accidentals
81 @cindex Automatic accidentals
83 Common rules for typesetting accidentals have been placed in a
84 function. This function is called as follows
86 @cindex @code{set-accidental-style}
88 #(set-accidental-style 'STYLE #('CONTEXT#))
91 The function can take two arguments: the name of the accidental style,
92 and an optional argument that denotes the context that should be
93 changed. If no context name is supplied, @code{Staff} is the default,
94 but you may wish to apply the accidental style to a single @code{Voice}
97 The following accidental styles are supported
100 This is the default typesetting behavior. It corresponds
101 to 18th century common practice: Accidentals are
102 remembered to the end of the measure in which they occur and
103 only on their own octave.
106 The normal behavior is to remember the accidentals on
107 Staff-level. This variable, however, typesets accidentals
108 individually for each voice. Apart from that, the rule is similar to
111 As a result, accidentals from one voice do not get canceled in other
112 voices, which is often an unwanted result
114 @lilypond[quote,ragged-right,relative=1,fragment,verbatim]
116 #(set-accidental-style 'voice)
123 The @code{voice} option should be used if the voices
124 are to be read solely by individual musicians. If the staff is to be
125 used by one musician (e.g., a conductor) then
126 @code{modern} or @code{modern-cautionary}
127 should be used instead.
130 @cindex @code{modern} style accidentals
131 This rule corresponds to the common practice in the 20th century. This rule
132 prints the same accidentals as @code{default}, but temporary
133 accidentals also are canceled in other octaves. Furthermore,
134 in the same octave, they also get canceled in the following
137 @lilypond[quote,ragged-right,fragment,verbatim]
138 #(set-accidental-style 'modern)
139 cis' c'' cis'2 | c'' c'
142 @item @code{modern-cautionary}
143 @cindex @code{modern-cautionary}
144 This rule is similar to @code{modern}, but the ``extra'' accidentals
145 (the ones not typeset by @code{default}) are typeset as cautionary
146 accidentals. They are printed in reduced size or with parentheses
147 @lilypond[quote,ragged-right,fragment,verbatim]
148 #(set-accidental-style 'modern-cautionary)
149 cis' c'' cis'2 | c'' c'
152 @cindex @code{modern-voice}
154 This rule is used for multivoice accidentals to be read both by musicians
155 playing one voice and musicians playing all voices. Accidentals are
156 typeset for each voice, but they @emph{are} canceled across voices in
157 the same @internalsref{Staff}.
159 @cindex @code{modern-voice-cautionary}
160 @item modern-voice-cautionary
161 This rule is the same as @code{modern-voice}, but with the extra
162 accidentals (the ones not typeset by @code{voice}) typeset
163 as cautionaries. Even though all accidentals typeset by
164 @code{default} @emph{are} typeset by this variable,
165 some of them are typeset as cautionaries.
168 @cindex @code{piano} accidentals
169 This rule reflects 20th century practice for piano notation. Very similar to
170 @code{modern} but accidentals also get canceled
171 across the staves in the same @internalsref{GrandStaff} or
172 @internalsref{PianoStaff}.
174 @item piano-cautionary
175 @cindex @code{#(set-accidental-style 'piano-cautionary)}
176 Same as @code{#(set-accidental-style 'piano)} but with the extra
177 accidentals typeset as cautionaries.
180 @cindex @code{no-reset} accidental style
181 This is the same as @code{default} but with accidentals lasting
182 ``forever'' and not only until the next measure
183 @lilypond[quote,ragged-right,fragment,verbatim,relative=1]
184 #(set-accidental-style 'no-reset)
189 This is sort of the opposite of @code{no-reset}: Accidentals
190 are not remembered at all---and hence all accidentals are
191 typeset relative to the key signature, regardless of what was
194 @lilypond[quote,ragged-right,fragment,verbatim,relative=1]
195 #(set-accidental-style 'forget)
196 \key d\major c4 c cis cis d d dis dis
203 Program reference: @internalsref{Accidental_engraver},
204 @internalsref{Accidental}, and @internalsref{AccidentalPlacement}.
209 Simultaneous notes are considered to be entered in sequential
210 mode. This means that in a chord the accidentals are typeset as if the
211 notes in the chord happen one at a time, in the order in which
212 they appear in the input file. This is a problem when accidentals
213 in a chord depend on each other,
214 which does not happen for the default accidental style. The problem
215 can be solved by manually inserting @code{!} and @code{?} for the
219 @node Setting automatic beam behavior
220 @subsection Setting automatic beam behavior
222 @cindex @code{autoBeamSettings}
223 @cindex @code{(end * * * *)}
224 @cindex @code{(begin * * * *)}
225 @cindex automatic beams, tuning
226 @cindex tuning automatic beaming
228 @c [TODO: use \applyContext]
230 In normal time signatures, automatic beams can start on any note but can
231 only end in a few positions within the measure: beams can end on a beat,
232 or at durations specified by the properties in
233 @code{autoBeamSettings}. The properties in @code{autoBeamSettings}
234 consist of a list of rules for where beams can begin and end. The
235 default @code{autoBeamSettings} rules are defined in
236 @file{scm/@/auto@/-beam@/.scm}.
238 In order to add a rule to the list, use
240 #(override-auto-beam-setting '(be p q n m) a b [context])
245 @item @code{be} is either "begin" or "end".
247 @item @code{p/q} is the duration of the note for which you want
248 to add a rule. A beam is considered to have the duration of its
249 shortest note. Set @code{p} and @code{q} to @code{'*'} to
250 have this apply to any beam.
252 @item @code{n/m} is the time signature to which
253 this rule should apply. Set @code{n} and @code{m} to @code{'*'}
254 to have this apply in any time signature.
256 @item @code{a/b} is the position in the bar at which the beam should begin/end.
258 @item @code{context} is optional, and it specifies the context at which
259 the change should be made. The default is @code{'Voice}.
260 @code{#(score-override-auto-beam-setting '(A B C D) E F)} is equivalent to
261 @code{#(override-auto-beam-setting '(A B C D) E F 'Score)}.
265 For example, if automatic beams should always end on the first quarter
269 #(override-auto-beam-setting '(end * * * *) 1 4)
272 You can force the beam settings to only take effect on beams whose shortest
273 note is a certain duration
275 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
277 #(override-auto-beam-setting '(end 1 16 * *) 1 16)
279 a32 a a a a16 a a a a a |
280 #(override-auto-beam-setting '(end 1 32 * *) 1 16)
281 a32 a a a a16 a a a a a |
284 You can force the beam settings to only take effect in certain time
287 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
289 #(override-auto-beam-setting '(end * * 5 8) 2 8)
297 You can also remove a previously set beam-ending rule by using
300 #(revert-auto-beam-setting '(be p q n m) a b [context])
304 be, p, q, n, m, a, b and context are the same as above. Note that the
305 default rules are specified in @file{scm/@/auto@/-beam@/.scm},
306 so you can revert rules that you did not explicitly create.
308 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
310 a16 a a a a a a a a a a a a a a a
311 #(revert-auto-beam-setting '(end 1 16 4 4) 1 4)
312 a16 a a a a a a a a a a a a a a a
315 The rule in a revert-auto-beam-setting statement must exactly match the
316 original rule. That is, no wildcard expansion is taken into account.
318 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
320 #(override-auto-beam-setting '(end 1 16 1 4) 1 8)
322 #(revert-auto-beam-setting '(end 1 16 * *) 1 8) % this won't revert it!
324 #(revert-auto-beam-setting '(end 1 16 1 4) 1 8) % this will
330 @c TODO: old material -- not covered by above stuff, I think.
331 If automatic beams should end on every quarter in 5/4 time, specify
334 #(override-auto-beam-setting '(end * * * *) 1 4 'Staff)
335 #(override-auto-beam-setting '(end * * * *) 1 2 'Staff)
336 #(override-auto-beam-setting '(end * * * *) 3 4 'Staff)
337 #(override-auto-beam-setting '(end * * * *) 5 4 'Staff)
341 The same syntax can be used to specify beam starting points. In this
342 example, automatic beams can only end on a dotted quarter note
344 #(override-auto-beam-setting '(end * * * *) 3 8)
345 #(override-auto-beam-setting '(end * * * *) 1 2)
346 #(override-auto-beam-setting '(end * * * *) 7 8)
348 In 4/4 time signature, this means that automatic beams could end only on
349 3/8 and on the fourth beat of the measure (after 3/4, that is 2 times
350 3/8, has passed within the measure).
352 @cindex automatic beam generation
354 @cindex @code{autoBeaming}
357 If beams are used to indicate melismata in songs, then automatic
358 beaming should be switched off with @code{\autoBeamOff}.
363 @cindex @code{\autoBeamOff}
365 @cindex @code{\autoBeamOn}
371 If a score ends while an automatic beam has not been ended and is
372 still accepting notes, this last beam will not be typeset at all. The
373 same holds polyphonic voices, entered with @code{<< @dots{} \\ @dots{}
374 >>}. If a polyphonic voice ends while an automatic beam is still
375 accepting notes, it is not typeset.
378 @node Interpretation contexts
379 @section Interpretation contexts
381 When music is printed, a lot of notational elements must be added to the
382 input. For example, compare the input and output of the following example:
384 @lilypond[quote,verbatim,relative=2,fragment]
388 The input is rather sparse, but in the output, bar lines, accidentals,
389 clef, and time signature are added. LilyPond @emph{interprets} the
390 input. During this step, the musical information is inspected in time
391 order, similar to reading a score from left to right. While reading
392 the input, the program remembers where measure boundaries are, and which
393 pitches require explicit accidentals. This information can be presented on
394 several levels. For example, the effect of an accidental is limited
395 to a single staff, while a bar line must be synchronized across the
398 Within LilyPond, these rules and bits of information are grouped in
399 @emph{Contexts}. Some examples of contexts are @context{Voice},
400 @context{Staff}, and @context{Score}. They are hierarchical, for
401 example: a @context{Staff} can contain many @context{Voice}s, and a
402 @context{Score} can contain many @context{Staff} contexts.
404 Each context has the responsibility for enforcing some notation rules,
405 creating some notation objects and maintaining the associated
406 properties. For example, the @context{Voice} context may introduce an
407 accidental and then the @context{Staff} context maintains the rule to
408 show or suppress the accidental for the remainder of the measure. The
409 synchronization of bar lines is handled at @context{Score} context.
411 However, in some music we may not want the bar lines to be
412 synchronized -- consider a polymetric score in 4/4 and 3/4 time. In
413 such cases, we must modify the default settings of the @context{Score}
414 and @context{Staff} contexts.
416 For very simple scores, contexts are created implicitly, and you need
417 not be aware of them. For larger pieces, such as anything with more
418 than one staff, they must be
419 created explicitly to make sure that you get as many staves as you
420 need, and that they are in the correct order. For typesetting pieces
421 with specialized notation, it can be useful to modify existing or
422 to define new contexts.
425 A complete description of all available contexts is in the program
428 @internalsref{Contexts}.
431 Translation @arrow{} Context.
434 @c [TODO: describe propagation]
438 * Creating contexts::
439 * Changing context properties on the fly::
440 * Modifying context plug-ins::
441 * Layout tunings within contexts::
442 * Changing context default settings::
443 * Defining new contexts::
446 @node Creating contexts
447 @subsection Creating contexts
449 For scores with only one voice and one staff, contexts are
450 created automatically. For more complex scores, it is necessary to
451 create them by hand. There are three commands that do this.
456 The easiest command is @code{\new}, and it also the quickest to type.
457 It is prepended to a music expression, for example
461 @cindex Context, creating
464 \new @var{type} @var{music expression}
468 where @var{type} is a context name (like @code{Staff} or
469 @code{Voice}). This command creates a new context, and starts
470 interpreting the @var{music expression} with that.
472 A practical application of @code{\new} is a score with many
473 staves. Each part that should be on its own staff, is preceded with
476 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
483 The @code{\new} command may also give a name to the context,
486 \new @var{type} = @var{id} @var{music}
488 However, this user specified name is only used if there is no other
489 context already earlier with the same name.
492 @cindex @code{\context}
494 Like @code{\new}, the @code{\context} command also directs a music
495 expression to a context object, but gives the context an explicit name. The
499 \context @var{type} = @var{id} @var{music}
502 This form will search for an existing context of type @var{type}
503 called @var{id}. If that context does not exist yet, a new
504 context with the specified name is created. This is useful if
505 the context is referred to later on. For example, when
506 setting lyrics the melody is in a named context
509 \context Voice = "@b{tenor}" @var{music}
513 so the texts can be properly aligned to its notes,
516 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
521 Another possible use of named contexts is funneling two different
522 music expressions into one context. In the following example,
523 articulations and notes are entered separately,
527 arts = @{ s4-. s4-> @}
530 They are combined by sending both to the same @context{Voice} context,
534 \new Staff \context Voice = "A" \music
535 \context Voice = "A" \arts
538 @lilypond[quote,ragged-right]
542 \new Staff \context Voice = "A" \music
543 \context Voice = "A" \arts
547 With this mechanism, it is possible to define an Urtext (original
548 edition), with the option to put several distinct articulations on the
551 @cindex creating contexts
554 The third command for creating contexts is
556 \context @var{type} @var{music}
561 This is similar to @code{\context} with @code{= @var{id}}, but matches
562 any context of type @var{type}, regardless of its given name.
564 This variant is used with music expressions that can be interpreted at
565 several levels. For example, the @code{\applyOutput} command (see
566 @ref{Running a function on all layout objects}). Without an explicit
567 @code{\context}, it is usually applied to @context{Voice}
570 \applyOutput #@var{function} % apply to Voice
573 To have it interpreted at the @context{Score} or @context{Staff} level use
577 \context Score \applyOutput #@var{function}
578 \context Staff \applyOutput #@var{function}
584 @node Changing context properties on the fly
585 @subsection Changing context properties on the fly
589 @cindex changing properties
591 Each context can have different @emph{properties}, variables contained
592 in that context. They can be changed during the interpretation step.
593 This is achieved by inserting the @code{\set} command in the music,
596 \set @var{context}.@var{prop} = #@var{value}
600 @lilypond[quote,verbatim,relative=2,fragment]
602 \set Score.skipBars = ##t
606 This command skips measures that have no notes. The result is that
607 multi-rests are condensed. The value assigned is a Scheme object. In
608 this case, it is @code{#t}, the boolean True value.
610 If the @var{context} argument is left out, then the current bottom-most
611 context (typically @context{ChordNames}, @context{Voice}, or
612 @context{Lyrics}) is used. In this example,
614 @lilypond[quote,verbatim,relative=2,fragment]
616 \set autoBeaming = ##f
621 the @var{context} argument to @code{\set} is left out, so automatic
622 beaming is switched off in the current @internalsref{Voice}. Note that
623 the bottom-most context does not always contain the property that you
624 wish to change -- for example, attempting to set the @code{skipBars}
625 property (of the bottom-most context, in this case @code{Voice}) will
628 @lilypond[quote,verbatim,relative=2,fragment]
634 Contexts are hierarchical, so if a bigger context was specified, for
635 example @context{Staff}, then the change would also apply to all
636 @context{Voice}s in the current stave. The change is applied
637 `on-the-fly', during the music, so that the setting only affects the
638 second group of eighth notes.
640 @cindex @code{\unset}
642 There is also an @code{\unset} command,
644 \unset @var{context}.@var{prop}
648 which removes the definition of @var{prop}. This command removes
649 the definition only if it is set in @var{context}, so
652 \set Staff.autoBeaming = ##f
656 introduces a property setting at @code{Staff} level. The setting also
657 applies to the current @code{Voice}. However,
660 \unset Voice.autoBeaming
664 does not have any effect. To cancel this setting, the @code{\unset}
665 must be specified on the same level as the original @code{\set}. In
666 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
669 \unset Staff.autoBeaming
672 Like @code{\set}, the @var{context} argument does not have to be
673 specified for a bottom context, so the two statements
676 \set Voice.autoBeaming = ##t
677 \set autoBeaming = ##t
685 Settings that should only apply to a single time-step can be entered
686 with @code{\once}, for example in
688 @lilypond[quote,verbatim,relative=2,fragment]
690 \once \set fontSize = #4.7
695 the property @code{fontSize} is unset automatically after the second
698 A full description of all available context properties is in the
699 program reference, see
701 @internalsref{Tunable context properties}.
704 Translation @arrow{} Tunable context properties.
708 @node Modifying context plug-ins
709 @subsection Modifying context plug-ins
711 Notation contexts (like Score and Staff) not only store properties,
712 they also contain plug-ins, called ``engravers'' that create notation
713 elements. For example, the Voice context contains a
714 @code{Note_head_engraver} and the Staff context contains a
715 @code{Key_signature_engraver}.
717 For a full a description of each plug-in, see
719 @internalsref{Engravers}.
722 Program reference @arrow Translation @arrow{} Engravers.
724 Every context described in
726 @internalsref{Contexts}
729 Program reference @arrow Translation @arrow{} Context.
731 lists the engravers used for that context.
734 It can be useful to shuffle around these plug-ins. This is done by
735 starting a new context, with @code{\new} or @code{\context}, and
736 modifying it like this,
741 \new @var{context} \with @{
752 where the @dots{} should be the name of an engraver. Here is a simple
753 example which removes @code{Time_signature_engraver} and
754 @code{Clef_engraver} from a @code{Staff} context,
756 @lilypond[quote,relative=1,verbatim,fragment]
762 \remove "Time_signature_engraver"
763 \remove "Clef_engraver"
770 In the second staff there are no time signature or clef symbols. This
771 is a rather crude method of making objects disappear since it will affect
772 the entire staff. This method also influences the spacing, which may or
773 may not be desirable. A more
774 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
776 The next example shows a practical application. Bar lines and time
777 signatures are normally synchronized across the score. This is done
778 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
779 This plug-in keeps an administration of time signature, location
780 within the measure, etc. By moving thes engraver from @code{Score} to
781 @code{Staff} context, we can have a score where each staff has its own
784 @cindex polymetric scores
785 @cindex Time signatures, multiple
787 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
789 \remove "Timing_translator"
790 \remove "Default_bar_line_engraver"
793 \consists "Timing_translator"
794 \consists "Default_bar_line_engraver"
800 \consists "Timing_translator"
801 \consists "Default_bar_line_engraver"
810 @node Layout tunings within contexts
811 @subsection Layout tunings within contexts
813 Each context is responsible for creating certain types of graphical
814 objects. The settings used for printing these objects are also stored by
815 context. By changing these settings, the appearance of objects can be
818 The syntax for this is
821 \override @var{context}.@var{name} #'@var{property} = #@var{value}
824 Here @var{name} is the name of a graphical object, like @code{Stem} or
825 @code{NoteHead}, and @var{property} is an internal variable of the
826 formatting system (`grob property' or `layout property'). The latter is a
827 symbol, so it must be quoted. The subsection @ref{Constructing a
828 tweak} explains what to fill in for @var{name}, @var{property}, and
829 @var{value}. Here we only discuss the functionality of this command.
834 \override Staff.Stem #'thickness = #4.0
838 makes stems thicker (the default is 1.3, with staff line thickness as a
839 unit). Since the command specifies @context{Staff} as context, it only
840 applies to the current staff. Other staves will keep their normal
841 appearance. Here we see the command in action:
843 @lilypond[quote,verbatim,relative=2,fragment]
845 \override Staff.Stem #'thickness = #4.0
851 The @code{\override} command changes the definition of the @code{Stem}
852 within the current @context{Staff}. After the command is interpreted
853 all stems are thickened.
855 Analogous to @code{\set}, the @var{context} argument may be left out,
856 causing it to default to @context{Voice}, and adding @code{\once} applies
857 the change during one timestep only
859 @lilypond[quote,fragment,verbatim,relative=2]
861 \once \override Stem #'thickness = #4.0
866 The @code{\override} must be done before the object is
867 started. Therefore, when altering @emph{Spanner} objects, like slurs or
868 beams, the @code{\override} command must be executed at the moment when
869 the object is created. In this example,
872 @lilypond[quote,fragment,verbatim,relative=2]
873 \override Slur #'thickness = #3.0
875 \override Beam #'thickness = #0.6
880 the slur is fatter but the beam is not. This is because the command for
881 @code{Beam} comes after the Beam is started. Therefore it has no effect.
883 Analogous to @code{\unset}, the @code{\revert} command for a context
884 undoes an @code{\override} command; like with @code{\unset}, it only
885 affects settings that were made in the same context. In other words, the
886 @code{\revert} in the next example does not do anything.
889 \override Voice.Stem #'thickness = #4.0
890 \revert Staff.Stem #'thickness
893 Some tweakable options are called ``subproperties'' and reside inside
894 properties. To tweak those, use
897 \override Stem #'details #'beamed-lengths = #'(4 4 3)
903 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
904 @internalsref{PropertySet}, @internalsref{Backend}, and
905 @internalsref{All layout objects}.
910 The back-end is not very strict in type-checking object properties.
911 Cyclic references in Scheme values for properties can cause hangs
915 @node Changing context default settings
916 @subsection Changing context default settings
918 The adjustments of the previous subsections (@ref{Changing context
919 properties on the fly}, @ref{Modifying context plug-ins}, and
920 @ref{Layout tunings within contexts}) can also be entered separately
921 from the music, in the @code{\layout} block,
930 \override Stem #'thickness = #4.0
931 \remove "Time_signature_engraver"
942 takes the existing definition for context @context{Staff} from the
943 identifier @code{\Staff}.
948 \override Stem #'thickness = #4.0
949 \remove "Time_signature_engraver"
953 affect all staves in the score.
955 Other contexts can be modified analogously.
957 The @code{\set} keyword is optional within the @code{\layout} block, so
973 It is not possible to collect context changes in a variable, and apply
974 them to one @code{\context} definition by referring to that variable.
976 The @code{\RemoveEmptyStaffContext} will override your current
977 @code{\Staff} variable. If you wish to change the defaults for a
978 staff that uses @code{\RemoveEmptyStaffContext}, you must do so
979 after calling @code{\RemoveemptyStaffContext}, ie
984 \RemoveEmptyStaffContext
986 \override Stem #'thickness = #4.0
992 @node Defining new contexts
993 @subsection Defining new contexts
995 Specific contexts, like @context{Staff} and @code{Voice}, are made of
996 simple building blocks, and it is possible to compose engraver
997 plug-ins in different combinations, thereby creating new types of
1000 The next example shows how to build a different type of
1001 @context{Voice} context from scratch. It will be similar to
1002 @code{Voice}, but prints centered slash noteheads only. It can be used
1003 to indicate improvisation in Jazz pieces,
1005 @lilypond[quote,ragged-right]
1006 \layout { \context {
1008 \type "Engraver_group"
1009 \consists "Note_heads_engraver"
1010 \consists "Text_engraver"
1011 \consists Pitch_squash_engraver
1012 squashedPosition = #0
1013 \override NoteHead #'style = #'slash
1014 \override Stem #'transparent = ##t
1018 \accepts "ImproVoice"
1022 a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
1023 c4 c^"undress" c_"while playing :)" c }
1029 These settings are again done within a @code{\context} block inside a
1030 @code{\layout} block,
1040 In the following discussion, the example input shown should go on the
1041 @dots{} in the previous fragment.
1043 First, the context gets a name. Instead of @context{Voice} it
1044 will be called @context{ImproVoice},
1050 Since it is similar to the @context{Voice}, we want commands that work
1051 on (existing) @context{Voice}s to remain working. This is achieved by
1052 giving the new context an alias @context{Voice},
1058 The context will print notes, and instructive texts
1061 \consists Note_heads_engraver
1062 \consists Text_engraver
1065 but only on the center line,
1068 \consists Pitch_squash_engraver
1069 squashedPosition = #0
1072 The @internalsref{Pitch_squash_engraver} modifies note heads (created
1073 by @internalsref{Note_heads_engraver}) and sets their vertical
1074 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
1077 The notes look like a slash, without a stem,
1080 \override NoteHead #'style = #'slash
1081 \override Stem #'transparent = ##t
1085 All these plug-ins have to cooperate, and this is achieved with a
1086 special plug-in, which must be marked with the keyword @code{\type}.
1087 This should always be @internalsref{Engraver_group},
1090 \type "Engraver_group"
1093 Put together, we get
1098 \type "Engraver_group"
1099 \consists "Note_heads_engraver"
1100 \consists "Text_engraver"
1101 \consists Pitch_squash_engraver
1102 squashedPosition = #0
1103 \override NoteHead #'style = #'slash
1104 \override Stem #'transparent = ##t
1109 Contexts form hierarchies. We want to hang the @context{ImproVoice}
1110 under @context{Staff}, just like normal @code{Voice}s. Therefore, we
1111 modify the @code{Staff} definition with the @code{\accepts}
1112 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
1113 which is sometimes needed when reusing existing context definitions.}
1124 Putting both into a @code{\layout} block, like
1134 \accepts "ImproVoice"
1139 Then the output at the start of this subsection can be entered as
1147 c c_"while playing :)"
1156 @node The \override command
1157 @section The \override command
1159 In the previous section, we have already touched on a command that
1160 changes layout details: the @code{\override} command. In this section,
1161 we will look in more detail at how to use the command in practice.
1162 First, we will give a few versatile commands that are sufficient
1163 for many situations. The next section will discuss the general use of
1168 * Constructing a tweak::
1169 * Navigating the program reference::
1170 * Layout interfaces::
1171 * Determining the grob property::
1172 * Objects connected to the input::
1173 * Difficult tweaks::
1178 @node Constructing a tweak
1179 @subsection Constructing a tweak
1181 The general procedure of changing output, that is, entering
1185 \override Voice.Stem #'thickness = #3.0
1189 means that we have to determine these bits of information:
1192 @item the context: here @context{Voice}.
1193 @item the layout object: here @code{Stem}.
1194 @item the layout property: here @code{thickness}
1195 @item a sensible value: here @code{3.0}
1198 Some tweakable options are called ``subproperties'' and reside inside
1199 properties. To tweak those, use
1202 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1205 @cindex internal documentation
1206 @cindex finding graphical objects
1207 @cindex graphical object descriptions
1209 @cindex @code{\override}
1210 @cindex internal documentation
1212 We demonstrate how to glean this information from the notation manual
1213 and the program reference.
1215 @node Navigating the program reference
1216 @subsection Navigating the program reference
1218 Suppose we want to move the fingering indication in the fragment
1221 @lilypond[quote,fragment,relative=2,verbatim]
1227 If you visit the documentation on fingering instructions (in
1228 @ref{Fingering instructions}), you will notice that there is written:
1233 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
1239 This fragment points to two parts of the program reference: a page
1240 on @code{FingerEvent} and one on @code{Fingering}.
1242 The page on @code{FingerEvent} describes the properties of the music
1243 expression for the input @code{-2}. The page contains many links
1244 forward. For example, it says
1247 Accepted by: @internalsref{Fingering_engraver},
1251 That link brings us to the documentation for the Engraver, the
1255 This engraver creates the following layout objects: @internalsref{Fingering}.
1258 In other words, once the @code{FingerEvent}s are interpreted, the
1259 @code{Fingering_engraver} plug-in will process them.
1262 @c I can't figure out what this is supposed to mean. -gp
1264 The @code{Fingering_engraver} is also listed to create
1265 @internalsref{Fingering} objects,
1267 @c old info? it doesn't make any sense to me with our current docs.
1269 second bit of information listed under @b{See also} in the Notation
1273 By clicking around in the program reference, we can follow the
1274 flow of information within the program, either forward (like we did
1275 here), or backwards, following links like this:
1279 @item @internalsref{Fingering}:
1280 @internalsref{Fingering} objects are created by:
1281 @b{@internalsref{Fingering_engraver}}
1283 @item @internalsref{Fingering_engraver}:
1284 Music types accepted: @b{@internalsref{fingering-event}}
1286 @item @internalsref{fingering-event}:
1287 Music event type @code{fingering-event} is in Music expressions named
1288 @b{@internalsref{FingerEvent}}
1291 This path goes against the flow of information in the program: it
1292 starts from the output, and ends at the input event.
1294 The program reference can also be browsed like a normal document. It
1295 contains a chapter on
1297 @internalsref{Music definitions},
1300 @code{Music definitions}
1302 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1303 chapter lists all the definitions used, and all properties that may be
1307 @node Layout interfaces
1308 @subsection Layout interfaces
1310 @cindex interface, layout
1311 @cindex layout interface
1314 The HTML page that we found in the previous section, describes the
1315 layout object called @internalsref{Fingering}. Such an object is a
1316 symbol within the score. It has properties that store numbers (like
1317 thicknesses and directions), but also pointers to related objects. A
1318 layout object is also called a @emph{Grob}, which is short for Graphical
1319 Object. For more details about Grobs, see @internalsref{grob-interface}.
1321 The page for @code{Fingering} lists the definitions for the
1322 @code{Fingering} object. For example, the page says
1325 @code{padding} (dimension, in staff space):
1331 which means that the number will be kept at a distance of at least 0.6
1335 Each layout object may have several functions as a notational or
1336 typographical element. For example, the Fingering object
1337 has the following aspects
1341 Its size is independent of the horizontal spacing, unlike slurs or beams.
1344 It is a piece of text. Granted, it is usually a very short text.
1347 That piece of text is typeset with a font, unlike slurs or beams.
1350 Horizontally, the center of the symbol should be aligned to the
1351 center of the notehead.
1354 Vertically, the symbol is placed next to the note and the staff.
1357 The vertical position is also coordinated with other super- and subscript
1361 Each of these aspects is captured in so-called @emph{interface}s,
1362 which are listed on the @internalsref{Fingering} page at the bottom
1365 This object supports the following interfaces:
1366 @internalsref{item-interface},
1367 @internalsref{self-alignment-interface},
1368 @internalsref{side-position-interface}, @internalsref{text-interface},
1369 @internalsref{text-script-interface}, @internalsref{font-interface},
1370 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1373 Clicking any of the links will take you to the page of the respective
1374 object interface. Each interface has a number of properties. Some of
1375 them are not user-serviceable (``Internal properties''), but others
1378 We have been talking of @emph{the} @code{Fingering} object, but actually it
1379 does not amount to much. The initialization file
1380 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1385 (avoid-slur . around)
1386 (slur-padding . 0.2)
1387 (staff-padding . 0.5)
1388 (self-alignment-X . 0)
1389 (self-alignment-Y . 0)
1390 (script-priority . 100)
1391 (stencil . ,ly:text-interface::print)
1392 (direction . ,ly:script-interface::calc-direction)
1393 (font-encoding . fetaNumber)
1394 (font-size . -5) ; don't overlap when next to heads.
1395 (meta . ((class . Item)
1396 (interfaces . (finger-interface
1398 text-script-interface
1400 side-position-interface
1401 self-alignment-interface
1402 item-interface))))))
1406 As you can see, the @code{Fingering} object is nothing more than a
1407 bunch of variable settings, and the webpage in the Program Reference
1408 is directly generated from this definition.
1410 @node Determining the grob property
1411 @subsection Determining the grob property
1414 Recall that we wanted to change the position of the @b{2} in
1416 @lilypond[quote,fragment,relative=2,verbatim]
1422 Since the @b{2} is vertically positioned next to its note, we have to
1423 meddle with the interface associated with this positioning. This is
1424 done using @code{side-position-interface}. The page for this interface
1428 @code{side-position-interface}
1430 Position a victim object (this one) next to other objects (the
1431 support). The property @code{direction} signifies where to put the
1432 victim object relative to the support (left or right, up or down?)
1437 below this description, the variable @code{padding} is described as
1442 (dimension, in staff space)
1444 Add this much extra space between objects that are next to each other.
1448 By increasing the value of @code{padding}, we can move away the
1449 fingering. The following command inserts 3 staff spaces of white
1450 between the note and the fingering:
1452 \once \override Voice.Fingering #'padding = #3
1455 Inserting this command before the Fingering object is created,
1456 i.e., before @code{c2}, yields the following result:
1458 @lilypond[quote,relative=2,fragment,verbatim]
1459 \once \override Voice.Fingering #'padding = #3
1466 In this case, the context for this tweak is @context{Voice}. This
1467 fact can also be deduced from the program reference, for the page for
1468 the @internalsref{Fingering_engraver} plug-in says
1471 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1474 @node Objects connected to the input
1475 @subsection Objects connected to the input
1477 @cindex @code{\tweak}
1479 In some cases, it is possible to take a short-cut for tuning graphical
1480 objects. For objects that result directly from a piece of the input,
1481 you can use the @code{\tweak} function, for example
1483 @lilypond[relative=2,fragment,verbatim,ragged-right]
1486 \tweak #'color #red d
1488 \tweak #'duration-log #1 a
1489 >4-\tweak #'padding #10 -.
1492 As you can see, properties are set directly in the objects directly,
1493 without mentioning the grob name or context where this should be
1496 This technique only works for objects that are directly connected to
1497 an @internalsref{event} from the input, for example
1500 @item note heads, caused by chord-pitch.
1501 @item articulation signs, caused by articulation instructions
1504 It notably does not work for stems and accidentals (these are caused
1505 by note heads, not by music events) or clefs (these are not caused by
1506 music inputs, but rather by the change of a property value).
1509 @node Difficult tweaks
1510 @subsection Difficult tweaks
1512 There are a few classes of difficult adjustments.
1518 One type of difficult adjustment is the appearance of spanner objects,
1519 such as slur and tie. Initially, only one of these objects is created,
1520 and they can be adjusted with the normal mechanism. However, in some
1521 cases the spanners cross line breaks. If this happens, these objects
1522 are cloned. A separate object is created for every system that it is
1523 in. These are clones of the original object and inherit all
1524 properties, including @code{\override}s.
1527 In other words, an @code{\override} always affects all pieces of a
1528 broken spanner. To change only one part of a spanner at a line break,
1529 it is necessary to hook into the formatting process. The
1530 @code{after-line-breaking} callback contains the Scheme procedure that
1531 is called after the line breaks have been determined, and layout
1532 objects have been split over different systems.
1534 In the following example, we define a procedure
1535 @code{my-callback}. This procedure
1539 determines if we have been split across line breaks
1541 if yes, retrieves all the split objects
1543 checks if we are the last of the split objects
1545 if yes, it sets @code{extra-offset}.
1548 This procedure is installed into @internalsref{Tie}, so the last part
1549 of the broken tie is translated up.
1551 @lilypond[quote,verbatim,ragged-right]
1552 #(define (my-callback grob)
1554 ; have we been split?
1555 (orig (ly:grob-original grob))
1557 ; if yes, get the split pieces (our siblings)
1558 (siblings (if (ly:grob? orig)
1559 (ly:spanner-broken-into orig) '() )))
1561 (if (and (>= (length siblings) 2)
1562 (eq? (car (last-pair siblings)) grob))
1563 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1566 \override Tie #'after-line-breaking =
1573 When applying this trick, the new @code{after-line-breaking} callback
1574 should also call the old one @code{after-line-breaking}, if there is
1575 one. For example, if using this with @code{Hairpin},
1576 @code{ly:hairpin::after-line-breaking} should also be called.
1579 @item Some objects cannot be changed with @code{\override} for
1580 technical reasons. Examples of those are @code{NonMusicalPaperColumn}
1581 and @code{PaperColumn}. They can be changed with the
1582 @code{\outputProperty} function, which works similar to @code{\once
1583 \override}, but uses a different syntax,
1587 #"Score.NonMusicalPaperColumn" % Grob name
1588 #'line-break-system-details % Property name
1589 #'((next-padding . 20)) % Value