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
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.5/@/Documentation/@/user/@/out@/-www/@/lilypond@/-internals/,on@/-line},
29 but is also included with the LilyPond documentation package.
31 There are three areas where the default settings may be changed:
35 Output: changing the appearance of individual
36 objects. For example, changing stem directions or the location of
40 Context: changing aspects of the translation from music events to
41 notation. For example, giving each staff a separate time signature.
44 Global layout: changing the appearance of the spacing, line
45 breaks, and page dimensions.
48 Then there are separate systems for typesetting text (like
49 @emph{ritardando}) and selecting different fonts. This chapter also
52 Internally, LilyPond uses Scheme (a LISP dialect) to provide
53 infrastructure. Overriding layout decisions in effect accesses the
54 program internals, which requires Scheme input. Scheme elements are
55 introduced in a @code{.ly} file with the hash mark
56 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
57 on entering numbers, lists, strings, and symbols in Scheme.}
61 * Interpretation contexts::
62 * The \override command::
67 @node Interpretation contexts
68 @section Interpretation contexts
70 When music is printed, a lot of notational elements must be added to the
71 input, which is often bare bones. For example, compare the input and
72 output of the following example:
74 @lilypond[quote,verbatim,relative=2,fragment]
78 The input is rather sparse, but in the output, bar lines, accidentals,
79 clef, and time signature are added. LilyPond @emph{interprets} the
80 input. During this step, the musical information is inspected in time
81 order, similar to reading a score from left to right. While reading,
82 the input, the program remembers where measure boundaries are, and what
83 pitches need explicit accidentals. This information can be presented on
84 several levels. For example, the effect of an accidental is limited
85 to a single staff, while a bar line must be synchronized across the
88 Within LilyPond, these rules and bits of information are grouped in
89 so-called Contexts. Examples of context are @context{Voice},
90 @context{Staff}, and @context{Score}. They are hierarchical, for
91 example, a @context{Staff} can contain many @context{Voice}s, and a
92 @context{Score} can contain many @context{Staff} contexts.
94 Each context has the responsibility for enforcing some notation rules,
95 creating some notation objects and maintaining the associated
96 properties. So, the synchronization of bar lines is handled at
97 @context{Score} context. The @context{Voice} may introduce an
98 accidental and then the @context{Staff} context maintains the rule to
99 show or suppress the accidental for the remainder of the measure.
101 For simple scores, contexts are created implicitly, and you need not
102 be aware of them. For larger pieces, such as piano music, they must be
103 created explicitly to make sure that you get as many staves as you
104 need, and that they are in the correct order. For typesetting pieces
105 with specialized notation, it can be useful to modify existing or
106 to define new contexts.
109 A complete description of all available contexts is in the program
112 @internalsref{Contexts}.
115 Translation @arrow{} Context.
118 @c [TODO: describe propagation]
122 * Creating contexts::
123 * Changing context properties on the fly::
124 * Modifying context plug-ins::
125 * Layout tunings within contexts::
126 * Changing context default settings::
127 * Defining new contexts::
130 @node Creating contexts
131 @subsection Creating contexts
133 For scores with only one voice and one staff, correct contexts are
134 created automatically. For more complex scores, it is necessary to
135 create them by hand. There are three commands that do this.
137 The easiest command is @code{\new}, and it also the quickest to type.
138 It is prepended to a music expression, for example
142 @cindex Context, creating
145 \new @var{type} @var{music expression}
149 where @var{type} is a context name (like @code{Staff} or
150 @code{Voice}). This command creates a new context, and starts
151 interpreting the @var{music expression} with that.
153 A practical application of @code{\new} is a score with many
154 staves. Each part that should be on its own staff, is preceded with
157 @lilypond[quote,verbatim,relative=2,raggedright,fragment]
158 << \new Staff { c4 c }
163 @cindex @code{\context}
165 Like @code{\new}, the @code{\context} command also directs a music
166 expression to a context object, but gives the context an extra name. The
170 \context @var{type} = @var{id} @var{music}
173 This form will search for an existing context of type @var{type}
174 called @var{id}. If that context does not exist yet, it is created.
175 This is useful if the context is referred to later on. For example, when
176 setting lyrics the melody is in a named context
179 \CONtext Voice = "@b{tenor}" @var{music}
183 so the texts can be properly aligned to its notes,
186 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
191 Another possibility is funneling two different music expressions into
192 one context. In the following example, articulations and notes are
197 arts = @{ s4-. s4-> @}
200 They are combined by sending both to the same @context{Voice} context,
203 << \new Staff \context Voice = "A" \music
204 \context Voice = "A" \arts
207 @lilypond[quote,raggedright]
211 \new Staff \context Voice = "A" \music
212 \context Voice = "A" \arts
216 With this mechanism, it is possible to define an Urtext (original
217 edition), with the option to put several distinct articulations on the
220 @cindex @code{\context}
221 @cindex creating contexts
223 The third command for creating contexts is
225 \context @var{type} @var{music}
230 This is similar to @code{\context} with @code{= @var{id}}, but matches
231 any context of type @var{type}, regardless of its given name.
233 This variant is used with music expressions that can be interpreted at
234 several levels. For example, the @code{\applyoutput} command (see
235 @ref{Running a function on all layout objects}). Without an explicit
236 @code{\context}, it is usually applied to @context{Voice}
239 \applyoutput #@var{function} % apply to Voice
242 To have it interpreted at the @context{Score} or @context{Staff} level use
246 \context Score \applyoutput #@var{function}
247 \context Staff \applyoutput #@var{function}
251 @node Changing context properties on the fly
252 @subsection Changing context properties on the fly
256 @cindex changing properties
258 Each context can have different @emph{properties}, variables contained
259 in that context. They can be changed during the interpretation step.
260 This is achieved by inserting the @code{\set} command in the music,
263 \set @var{context}.@var{prop} = #@var{value}
267 @lilypond[quote,verbatim,relative=2,fragment]
269 \set Score.skipBars = ##t
273 This command skips measures that have no notes. The result is that
274 multi-rests are condensed. The value assigned is a Scheme object. In
275 this case, it is @code{#t}, the boolean True value.
277 If the @var{context} argument is left out, then the current bottom-most
278 context (typically @context{ChordNames}, @context{Voice}, or
279 @context{Lyrics}) is used. In this example,
281 @lilypond[quote,verbatim,relative=2,fragment]
283 \set autoBeaming = ##f
288 the @var{context} argument to @code{\set} is left out, so automatic
289 beaming is switched off in the current @internalsref{Voice}. Note that
290 the bottom-most context does not always contain the property that you
291 wish to change -- for example, attempting to set the @code{skipBars}
292 property (of the bottom-most context, in this case @code{Voice}) will
295 @lilypond[quote,verbatim,relative=2,fragment]
301 Contexts are hierarchical, so if a bigger context was specified, for
302 example @context{Staff}, then the change would also apply to all
303 @context{Voice}s in the current stave. The change is applied
304 `on-the-fly', during the music, so that the setting only affects the
305 second group of eighth notes.
307 @cindex @code{\unset}
309 There is also an @code{\unset} command,
311 \unset @var{context}.@var{prop}
315 which removes the definition of @var{prop}. This command removes
316 the definition only if it is set in @var{context}, so
319 \set Staff.autoBeaming = ##f
323 introduces a property setting at @code{Staff} level. The setting also
324 applies to the current @code{Voice}. However,
327 \unset Voice.autoBeaming
331 does not have any effect. To cancel this setting, the @code{\unset}
332 must be specified on the same level as the original @code{\set}. In
333 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
336 \unset Staff.autoBeaming
339 Like @code{\set}, the @var{context} argument does not have to be
340 specified for a bottom context, so the two statements
343 \set Voice.autoBeaming = ##t
344 \set autoBeaming = ##t
352 Settings that should only apply to a single time-step can be entered
353 with @code{\once}, for example in
355 @lilypond[quote,verbatim,relative=2,fragment]
357 \once \set fontSize = #4.7
362 the property @code{fontSize} is unset automatically after the second
365 A full description of all available context properties is in the
366 program reference, see
368 @internalsref{Tunable context properties}.
371 Translation @arrow{} Tunable context properties.
375 @node Modifying context plug-ins
376 @subsection Modifying context plug-ins
378 Notation contexts (like Score and Staff) not only store properties,
379 they also contain plug-ins, called ``engravers'' that create notation
380 elements. For example, the Voice context contains a
381 @code{Note_head_engraver} and the Staff context contains a
382 @code{Key_signature_engraver}.
384 For a full a description of each plug-in, see
386 @internalsref{Engravers}.
389 Program reference @arrow Translation @arrow{} Engravers.
391 Every context described in
393 @internalsref{Contexts}
396 Program reference @arrow Translation @arrow{} Context.
398 lists the engravers used for that context.
401 It can be useful to shuffle around these plug-ins. This is done by
402 starting a new context, with @code{\new} or @code{\context}, and
403 modifying it like this,
406 \new @var{context} \with @{
417 where the @dots{} should be the name of an engraver. Here is a simple
418 example which removes @code{Time_signature_engraver} and
419 @code{Clef_engraver} from a @code{Staff} context,
421 @lilypond[quote,relative=1,verbatim,fragment]
426 \remove "Time_signature_engraver"
427 \remove "Clef_engraver"
434 In the second staff there are no time signature or clef symbols. This
435 is a rather crude method of making objects disappear since it will affect
436 the entire staff. The spacing is adversely influenced too. A more
437 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
439 The next example shows a practical application. Bar lines and time
440 signatures are normally synchronized across the score. This is done
441 by the @code{Timing_engraver}. This plug-in keeps an administration of
442 time signature, location within the measure, etc. By moving the
443 @code{Timing_engraver} engraver from @code{Score} to @code{Staff}
444 context, we can have a score where each staff has its own time
447 @cindex polymetric scores
448 @cindex Time signatures, multiple
450 @lilypond[quote,relative=1,raggedright,verbatim,fragment]
452 \remove "Timing_engraver"
455 \consists "Timing_engraver"
461 \consists "Timing_engraver"
470 @node Layout tunings within contexts
471 @subsection Layout tunings within contexts
473 Each context is responsible for creating certain types of graphical
474 objects. The settings used for printing these objects are also stored by
475 context. By changing these settings, the appearance of objects can be
478 The syntax for this is
481 \override @var{context}.@var{name} #'@var{property} = #@var{value}
484 Here @var{name} is the name of a graphical object, like @code{Stem} or
485 @code{NoteHead}, and @var{property} is an internal variable of the
486 formatting system (`grob property' or `layout property'). The latter is a
487 symbol, so it must be quoted. The subsection @ref{Constructing a
488 tweak} explains what to fill in for @var{name}, @var{property}, and
489 @var{value}. Here we only discuss the functionality of this command.
494 \override Staff.Stem #'thickness = #4.0
498 makes stems thicker (the default is 1.3, with staff line thickness as a
499 unit). Since the command specifies @context{Staff} as context, it only
500 applies to the current staff. Other staves will keep their normal
501 appearance. Here we see the command in action:
503 @lilypond[quote,verbatim,relative=2,fragment]
505 \override Staff.Stem #'thickness = #4.0
511 The @code{\override} command changes the definition of the @code{Stem}
512 within the current @context{Staff}. After the command is interpreted
513 all stems are thickened.
515 Analogous to @code{\set}, the @var{context} argument may be left out,
516 causing it to default to @context{Voice}, and adding @code{\once} applies
517 the change during one timestep only
519 @lilypond[quote,fragment,verbatim,relative=2]
521 \once \override Stem #'thickness = #4.0
526 The @code{\override} must be done before the object is
527 started. Therefore, when altering @emph{Spanner} objects, like slurs or
528 beams, the @code{\override} command must be executed at the moment when
529 the object is created. In this example,
532 @lilypond[quote,fragment,verbatim,relative=2]
533 \override Slur #'thickness = #3.0
535 \override Beam #'thickness = #0.6
540 the slur is fatter but the beam is not. This is because the command for
541 @code{Beam} comes after the Beam is started. Therefore it has no effect.
543 Analogous to @code{\unset}, the @code{\revert} command for a context
544 undoes an @code{\override} command; like with @code{\unset}, it only
545 affects settings that were made in the same context. In other words, the
546 @code{\revert} in the next example does not do anything.
549 \override Voice.Stem #'thickness = #4.0
550 \revert Staff.Stem #'thickness
558 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
559 @internalsref{PropertySet}, @internalsref{Backend}, and
560 @internalsref{All layout objects}.
565 The back-end is not very strict in type-checking object properties.
566 Cyclic references in Scheme values for properties can cause hangs
570 @node Changing context default settings
571 @subsection Changing context default settings
573 The adjustments of the previous subsections (@ref{Changing context
574 properties on the fly}, @ref{Modifying context plug-ins}, and
575 @ref{Layout tunings within contexts}) can also be entered separately
576 from the music, in the @code{\layout} block,
585 \override Stem #'thickness = #4.0
586 \remove "Time_signature_engraver"
597 takes the existing definition for context @context{Staff} from the
598 identifier @code{\Staff}.
603 \override Stem #'thickness = #4.0
604 \remove "Time_signature_engraver"
608 affect all staves in the score.
610 Other contexts can be modified analogously.
612 The @code{\set} keyword is optional within the @code{\layout} block, so
628 It is not possible to collect context changes in a variable, and apply
629 them to one @code{\context} definition by referring to that variable.
631 The @code{\RemoveEmptyStaffContext} will override your current
632 @code{\Staff} variable. If you wish to change the defaults for a
633 staff that uses @code{\RemoveEmptyStaffContext}, you must do so
634 after calling @code{\RemoveemptyStaffContext}, ie
639 \RemoveEmptyStaffContext
641 \override Stem #'thickness = #4.0
647 @node Defining new contexts
648 @subsection Defining new contexts
650 Specific contexts, like @context{Staff} and @code{Voice}, are made of
651 simple building blocks, and it is possible to compose engraver
652 plug-ins in different combinations, thereby creating new types of
655 The next example shows how to build a different type of
656 @context{Voice} context from scratch. It will be similar to
657 @code{Voice}, but prints centered slash noteheads only. It can be used
658 to indicate improvisation in Jazz pieces,
660 @lilypond[quote,raggedright]
663 \type "Engraver_group_engraver"
664 \consists "Note_heads_engraver"
665 \consists "Text_engraver"
666 \consists Pitch_squash_engraver
667 squashedPosition = #0
668 \override NoteHead #'style = #'slash
669 \override Stem #'transparent = ##t
673 \accepts "ImproVoice"
677 a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
678 c4 c^"undress" c_"while playing :)" c }
684 These settings are again done within a @code{\context} block inside a
685 @code{\layout} block,
695 In the following discussion, the example input shown should go on the
696 @dots{} in the previous fragment.
698 First, the context gets a name. Instead of @context{Voice} it
699 will be called @context{ImproVoice},
705 Since it is similar to the @context{Voice}, we want commands that work
706 on (existing) @context{Voice}s to remain working. This is achieved by
707 giving the new context an alias @context{Voice},
713 The context will print notes, and instructive texts
716 \consists Note_heads_engraver
717 \consists Text_engraver
720 but only on the center line,
723 \consists Pitch_squash_engraver
724 squashedPosition = #0
727 The @internalsref{Pitch_squash_engraver} modifies note heads (created
728 by @internalsref{Note_heads_engraver}) and sets their vertical
729 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
732 The notes look like a slash, without a stem,
735 \override NoteHead #'style = #'slash
736 \override Stem #'transparent = ##t
740 All these plug-ins have to cooperate, and this is achieved with a
741 special plug-in, which must be marked with the keyword @code{\type}.
742 This should always be @internalsref{Engraver_group_engraver},
745 \type "Engraver_group_engraver"
753 \type "Engraver_group_engraver"
754 \consists "Note_heads_engraver"
755 \consists "Text_engraver"
756 \consists Pitch_squash_engraver
757 squashedPosition = #0
758 \override NoteHead #'style = #'slash
759 \override Stem #'transparent = ##t
764 Contexts form hierarchies. We want to hang the @context{ImproVoice}
765 under @context{Staff}, just like normal @code{Voice}s. Therefore, we
766 modify the @code{Staff} definition with the @code{\accepts}
767 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
768 which is sometimes needed when reusing existing context definitions.}
779 Putting both into a @code{\layout} block, like
789 \accepts "ImproVoice"
794 Then the output at the start of this subsection can be entered as
802 c c_"while playing :)"
811 @node The \override command
812 @section The \override command
814 In the previous section, we have already touched on a command that
815 changes layout details: the @code{\override} command. In this section,
816 we will look in more detail at how to use the command in practice.
817 First, we will give a few versatile commands that are sufficient
818 for many situations. The next section will discuss the general use of
824 * Constructing a tweak::
825 * Navigating the program reference::
826 * Layout interfaces::
827 * Determining the grob property::
834 @subsection Common tweaks
836 @c Should we point at ly/property-init.ly ? -gp
837 Some overrides are so common that predefined commands are provided as
838 short-cuts, for example, @code{\slurUp} and @code{\stemDown}. These
839 commands are described in
843 @c @ref{Notation manual},
846 under the sections for slurs and stems
849 The exact tuning possibilities for each type of layout object are
850 documented in the program reference of the respective
851 object. However, many layout objects share properties, which can be
852 used to apply generic tweaks. We mention a few of these:
855 @item The @code{extra-offset} property, which
856 @cindex @code{extra-offset}
857 has a pair of numbers as value, moves objects around in the printout.
858 The first number controls left-right movement; a positive number will
859 move the object to the right. The second number controls up-down
860 movement; a positive number will move it higher. The units of these
861 offsets are staff-spaces. The @code{extra-offset} property is a
862 low-level feature: the formatting engine is completely oblivious to
865 In the following example, the second fingering is moved a little to
866 the left, and 1.8 staff space downwards:
868 @cindex setting object properties
870 @lilypond[quote,fragment,relative=1,verbatim]
873 \once \override Fingering
874 #'extra-offset = #'(-0.3 . -1.8)
879 Setting the @code{transparent} property will cause an object to be printed
880 in `invisible ink': the object is not printed, but all its other
881 behavior is retained. The object still takes up space, it takes part in
882 collisions, and slurs, ties, and beams can be attached to it.
884 @cindex transparent objects
885 @cindex removing objects
886 @cindex hiding objects
887 @cindex invisible objects
888 The following example demonstrates how to connect different voices
889 using ties. Normally, ties only connect two notes in the same
890 voice. By introducing a tie in a different voice,
892 @lilypond[quote,fragment,relative=2]
901 and blanking the first up-stem in that voice, the tie appears to cross
904 @lilypond[quote,fragment,relative=2,verbatim]
906 \once \override Stem #'transparent = ##t
914 The @code{padding} property for objects with
915 @cindex @code{padding}
916 @code{side-position-interface} can be set to increase the distance between
917 symbols that are printed above or below notes. We provide two
918 examples; a more elaborate explanation is in @ref{Constructing a
921 @lilypond[quote,fragment,relative=1,verbatim]
923 \override Script #'padding = #3
927 @lilypond[quote,fragment,relative=1,verbatim]
928 % This will not work, see below:
929 \override MetronomeMark #'padding = #3
933 \override Score.MetronomeMark #'padding = #3
938 Note in the second example how important it is to figure out what
939 context handles a certain object. Since the @code{MetronomeMark} object
940 is handled in the Score context, property changes in the @code{Voice}
941 context will not be noticed.
945 More specific overrides are also possible. The next section
946 discusses in depth how to figure out these statements for yourself.
949 @node Constructing a tweak
950 @subsection Constructing a tweak
952 The general procedure of changing output, that is, entering
956 \override Voice.Stem #'thickness = #3.0
960 means that we have to determine these bits of information:
963 @item the context: here @context{Voice}.
964 @item the layout object: here @code{Stem}.
965 @item the layout property: here @code{thickness}
966 @item a sensible value: here @code{3.0}
970 @cindex internal documentation
971 @cindex finding graphical objects
972 @cindex graphical object descriptions
974 @cindex @code{\override}
975 @cindex internal documentation
977 We demonstrate how to glean this information from the notation manual
978 and the program reference.
980 @node Navigating the program reference
981 @subsection Navigating the program reference
983 Suppose we want to move the fingering indication in the fragment
986 @lilypond[quote,fragment,relative=2,verbatim]
992 If you visit the documentation on fingering instructions (in
993 @ref{Fingering instructions}), you will notice that there is written:
998 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
1004 This fragment points to two parts of the program reference: a page
1005 on @code{FingerEvent} and one on @code{Fingering}.
1007 The page on @code{FingerEvent} describes the properties of the music
1008 expression for the input @code{-2}. The page contains many links
1009 forward. For example, it says
1012 Accepted by: @internalsref{Fingering_engraver},
1016 That link brings us to the documentation for the Engraver, the
1020 This engraver creates the following layout objects: @internalsref{Fingering}.
1023 In other words, once the @code{FingerEvent}s are interpreted, the
1024 @code{Fingering_engraver} plug-in will process them.
1025 The @code{Fingering_engraver} is also listed to create
1026 @internalsref{Fingering} objects,
1029 Lo and behold, that is also the
1030 second bit of information listed under @b{See also} in the Notation
1031 manual. By clicking around in the program reference, we can follow the
1032 flow of information within the program, either forward (like we did
1033 here), or backwards, following links like this:
1037 @item @internalsref{Fingering}:
1038 @internalsref{Fingering} objects are created by:
1039 @b{@internalsref{Fingering_engraver}}
1041 @item @internalsref{Fingering_engraver}:
1042 Music types accepted: @b{@internalsref{fingering-event}}
1044 @item @internalsref{fingering-event}:
1045 Music event type @code{fingering-event} is in Music expressions named
1046 @b{@internalsref{FingerEvent}}
1049 This path goes against the flow of information in the program: it
1050 starts from the output, and ends at the input event.
1052 The program reference can also be browsed like a normal document. It
1053 contains a chapter on
1055 @internalsref{Music definitions},
1058 @code{Music definitions}
1060 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1061 chapter lists all the definitions used, and all properties that may be
1065 @node Layout interfaces
1066 @subsection Layout interfaces
1068 @cindex interface, layout
1069 @cindex layout interface
1071 The HTML page that we found in the previous section, describes the
1072 layout object called @internalsref{Fingering}. Such an object is a
1073 symbol within the score. It has properties that store numbers (like
1074 thicknesses and directions), but also pointers to related objects. A
1075 layout object is also called @emph{grob},
1077 which is short for Graphical Object.
1080 The page for @code{Fingering} lists the definitions for the
1081 @code{Fingering} object. For example, the page says
1084 @code{padding} (dimension, in staff space):
1090 which means that the number will be kept at a distance of at least 0.6
1094 Each layout object may have several functions as a notational or
1095 typographical element. For example, the Fingering object
1096 has the following aspects
1100 Its size is independent of the horizontal spacing, unlike slurs or beams.
1103 It is a piece of text. Granted, it is usually a very short text.
1106 That piece of text is typeset with a font, unlike slurs or beams.
1109 Horizontally, the center of the symbol should be aligned to the
1110 center of the notehead.
1113 Vertically, the symbol is placed next to the note and the staff.
1116 The vertical position is also coordinated with other super- and subscript
1120 Each of these aspects is captured in so-called @emph{interface}s,
1121 which are listed on the @internalsref{Fingering} page at the bottom
1124 This object supports the following interfaces:
1125 @internalsref{item-interface},
1126 @internalsref{self-alignment-interface},
1127 @internalsref{side-position-interface}, @internalsref{text-interface},
1128 @internalsref{text-script-interface}, @internalsref{font-interface},
1129 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1132 Clicking any of the links will take you to the page of the respective
1133 object interface. Each interface has a number of properties. Some of
1134 them are not user-serviceable (``Internal properties''), but others
1137 We have been talking of @emph{the} @code{Fingering} object, but actually it
1138 does not amount to much. The initialization file
1139 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1143 . ((print-function . ,Text_interface::print)
1145 (staff-padding . 0.6)
1146 (self-alignment-X . 0)
1147 (self-alignment-Y . 0)
1148 (script-priority . 100)
1150 (meta . ((interfaces . (finger-interface font-interface
1151 text-script-interface text-interface
1152 side-position-interface
1153 self-alignment-interface
1154 item-interface))))))
1158 As you can see, the @code{Fingering} object is nothing more than a
1159 bunch of variable settings, and the webpage in the Program Reference
1160 is directly generated from this definition.
1162 @node Determining the grob property
1163 @subsection Determining the grob property
1166 Recall that we wanted to change the position of the @b{2} in
1168 @lilypond[quote,fragment,relative=2,verbatim]
1174 Since the @b{2} is vertically positioned next to its note, we have to
1175 meddle with the interface associated with this positioning. This is
1176 done using @code{side-position-interface}. The page for this interface
1180 @code{side-position-interface}
1182 Position a victim object (this one) next to other objects (the
1183 support). The property @code{direction} signifies where to put the
1184 victim object relative to the support (left or right, up or down?)
1189 below this description, the variable @code{padding} is described as
1194 (dimension, in staff space)
1196 Add this much extra space between objects that are next to each other.
1200 By increasing the value of @code{padding}, we can move away the
1201 fingering. The following command inserts 3 staff spaces of white
1202 between the note and the fingering:
1204 \once \override Voice.Fingering #'padding = #3
1207 Inserting this command before the Fingering object is created,
1208 i.e., before @code{c2}, yields the following result:
1210 @lilypond[quote,relative=2,fragment,verbatim]
1211 \once \override Voice.Fingering #'padding = #3
1218 In this case, the context for this tweak is @context{Voice}. This
1219 fact can also be deduced from the program reference, for the page for
1220 the @internalsref{Fingering_engraver} plug-in says
1223 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1226 @node Difficult tweaks
1227 @subsection Difficult tweaks
1229 There are two classes of difficult adjustments. First, when there are
1230 several of the same objects at one point, and you want to adjust only
1231 one. For example, if you want to change only one note head in a chord.
1233 In this case, the @code{\applyoutput} function must be used. The
1234 next example defines a Scheme function @code{set-position-font-size}
1235 that sets the @code{font-size} property, but only
1236 on objects that have @internalsref{note-head-interface} and are at the
1239 @lilypond[quote,verbatim]
1240 #(define ((set-position-font-size pos size) grob origin current)
1242 ((interfaces (ly:grob-property grob 'interfaces))
1243 (position (ly:grob-property grob 'staff-position)))
1245 ; is this a note head?
1246 (memq 'note-head-interface interfaces)
1248 ; is the Y coordinate right?
1252 (set! (ly:grob-property grob 'font-size) size))))
1256 \applyoutput #(set-position-font-size -2 4)
1262 A similar technique can be used for accidentals. In that case, the
1263 function should check for @code{accidental-interface}.
1265 Another difficult adjustment is the appearance of spanner objects,
1266 such as slur and tie. Initially, only one of these objects is created,
1267 and they can be adjusted with the normal mechanism. However, in some
1268 cases the spanners cross line breaks. If this happens, these objects
1269 are cloned. A separate object is created for every system that it is
1270 in. These are clones of the original object and inherit all
1271 properties, including @code{\override}s.
1273 In other words, an @code{\override} always affects all pieces of a
1274 broken spanner. To change only one part of a spanner at a line break,
1275 it is necessary to hook into the formatting process. The
1276 @code{after-line-breaking-callback} property contains the Scheme procedure
1277 that is called after the line breaks have been determined, and layout
1278 objects have been split over different systems.
1280 In the following example, we define a procedure
1281 @code{my-callback}. This procedure
1285 determines if we have been split across line breaks
1287 if yes, retrieves all the split objects
1289 checks if we are the last of the split objects
1291 if yes, it sets @code{extra-offset}.
1294 This procedure is installed into @internalsref{Tie}, so the last part
1295 of the broken tie is translated up.
1298 @lilypond[quote,verbatim,raggedright]
1299 #(define (my-callback grob)
1301 ; have we been split?
1302 (orig (ly:grob-original grob))
1304 ; if yes, get the split pieces (our siblings)
1305 (siblings (if (ly:grob? orig)
1306 (ly:spanner-broken-into orig) '() )))
1308 (if (and (>= (length siblings) 2)
1309 (eq? (car (last-pair siblings)) grob))
1310 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1313 \override Tie #'after-line-breaking-callback =
1320 When applying this trick, the new @code{after-line-breaking-callback}
1321 should also call the old @code{after-line-breaking-callback}, if there
1322 is one. For example, if using this with @code{Slur},
1323 @code{Slur::after_line_breaking} should also be called.
1328 This section details the ways that the font can be changed.
1331 * Selecting font sizes::
1337 @node Selecting font sizes
1338 @subsection Selecting font sizes
1341 The easiest method of setting the font size of any context, is by
1342 setting the @code{fontSize} property.
1344 @lilypond[quote,fragment,relative=1,verbatim]
1353 It does not change the size of variable symbols, such as beams or
1356 Internally, the @code{fontSize} context property will cause the
1357 @code{font-size} property to be set in all layout objects. The value
1358 of @code{font-size} is a number indicating the size relative to the
1359 standard size for the current staff height. Each step up is an
1360 increase of approximately 12% of the font size. Six steps is exactly a
1361 factor two. The Scheme function @code{magstep} converts a
1362 @code{font-size} number to a scaling factor.
1364 @lilypond[quote,fragment,relative=1,verbatim]
1366 \override NoteHead #'font-size = #-4
1368 \override NoteHead #'font-size = #3
1372 LilyPond has fonts in different design sizes. The music fonts for
1373 smaller sizes are chubbier, while the text fonts are relatively wider.
1374 Font size changes are achieved by scaling the design size that is
1375 closest to the desired size. The standard font size (for
1376 @code{font-size} equals 0), depends on the standard staff height. For
1377 a 20pt staff, a 10pt font is selected.
1379 The @code{font-size} property can only be set on layout objects that
1380 use fonts. These are the ones supporting the
1381 @internalsref{font-interface} layout interface.
1385 The following commands set @code{fontSize} for the current voice:
1387 @cindex @code{\tiny}
1389 @cindex @code{\small}
1391 @cindex @code{\normalsize}
1396 @cindex magnification
1400 @node Font selection
1401 @subsection Font selection
1405 @cindex font selection
1406 @cindex font magnification
1407 @cindex @code{font-interface}
1409 By setting the object properties described below, you can select a
1410 font from the preconfigured font families. LilyPond has default
1411 support for the feta music fonts and @TeX{}'s Computer Modern text
1416 @item @code{font-encoding}
1417 is a symbol that sets layout of the glyphs. This should only be set to
1418 select different types of non-text fonts, eg.
1420 @code{fetaBraces} for piano staff braces, @code{fetaMusic} the
1421 standard music font, including ancient glyphs, @code{fetaDynamic} for
1422 dynamic signs and @code{fetaNumber} for the number font.
1424 @item @code{font-family}
1425 is a symbol indicating the general class of the typeface. Supported are
1426 @code{roman} (Computer Modern), @code{sans}, and @code{typewriter}.
1428 @item @code{font-shape}
1429 is a symbol indicating the shape of the font. There are typically
1430 several font shapes available for each font family. Choices are
1431 @code{italic}, @code{caps}, and @code{upright}.
1433 @item @code{font-series}
1434 is a symbol indicating the series of the font. There are typically
1435 several font series for each font family and shape. Choices are
1436 @code{medium} and @code{bold}.
1440 Fonts selected in the way sketched above come from a predefined style
1441 sheet. If you want to use a font from outside the style sheet,
1443 @code{font-name} property,
1445 @lilypond[fragment,verbatim]
1447 \override Staff.TimeSignature #'font-name = #"Times"
1448 \override Staff.TimeSignature #'font-size = #2
1451 \override #'(font-name . "Vera Bold")
1452 { This text is in Vera Bold }
1458 Any font can be used, as long as it is available to Pango/FontConfig.
1460 The size of the font may be set with the @code{font-size}
1461 property. The resulting size is taken relative to the
1462 @code{text-font-size} as defined in the @code{\paper} block.
1466 @cindex font magnification
1472 Init files: @file{ly/@/declarations@/-init@/.ly} contains hints how new
1473 fonts may be added to LilyPond.