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 creating contexts
222 The third command for creating contexts is
224 \context @var{type} @var{music}
229 This is similar to @code{\context} with @code{= @var{id}}, but matches
230 any context of type @var{type}, regardless of its given name.
232 This variant is used with music expressions that can be interpreted at
233 several levels. For example, the @code{\applyoutput} command (see
234 @ref{Running a function on all layout objects}). Without an explicit
235 @code{\context}, it is usually applied to @context{Voice}
238 \applyoutput #@var{function} % apply to Voice
241 To have it interpreted at the @context{Score} or @context{Staff} level use
245 \context Score \applyoutput #@var{function}
246 \context Staff \applyoutput #@var{function}
250 @node Changing context properties on the fly
251 @subsection Changing context properties on the fly
255 @cindex changing properties
257 Each context can have different @emph{properties}, variables contained
258 in that context. They can be changed during the interpretation step.
259 This is achieved by inserting the @code{\set} command in the music,
262 \set @var{context}.@var{prop} = #@var{value}
266 @lilypond[quote,verbatim,relative=2,fragment]
268 \set Score.skipBars = ##t
272 This command skips measures that have no notes. The result is that
273 multi-rests are condensed. The value assigned is a Scheme object. In
274 this case, it is @code{#t}, the boolean True value.
276 If the @var{context} argument is left out, then the current bottom-most
277 context (typically @context{ChordNames}, @context{Voice}, or
278 @context{Lyrics}) is used. In this example,
280 @lilypond[quote,verbatim,relative=2,fragment]
282 \set autoBeaming = ##f
287 the @var{context} argument to @code{\set} is left out, so automatic
288 beaming is switched off in the current @internalsref{Voice}. Note that
289 the bottom-most context does not always contain the property that you
290 wish to change -- for example, attempting to set the @code{skipBars}
291 property (of the bottom-most context, in this case @code{Voice}) will
294 @lilypond[quote,verbatim,relative=2,fragment]
300 Contexts are hierarchical, so if a bigger context was specified, for
301 example @context{Staff}, then the change would also apply to all
302 @context{Voice}s in the current stave. The change is applied
303 `on-the-fly', during the music, so that the setting only affects the
304 second group of eighth notes.
306 @cindex @code{\unset}
308 There is also an @code{\unset} command,
310 \unset @var{context}.@var{prop}
314 which removes the definition of @var{prop}. This command removes
315 the definition only if it is set in @var{context}, so
318 \set Staff.autoBeaming = ##f
322 introduces a property setting at @code{Staff} level. The setting also
323 applies to the current @code{Voice}. However,
326 \unset Voice.autoBeaming
330 does not have any effect. To cancel this setting, the @code{\unset}
331 must be specified on the same level as the original @code{\set}. In
332 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
335 \unset Staff.autoBeaming
338 Like @code{\set}, the @var{context} argument does not have to be
339 specified for a bottom context, so the two statements
342 \set Voice.autoBeaming = ##t
343 \set autoBeaming = ##t
351 Settings that should only apply to a single time-step can be entered
352 with @code{\once}, for example in
354 @lilypond[quote,verbatim,relative=2,fragment]
356 \once \set fontSize = #4.7
361 the property @code{fontSize} is unset automatically after the second
364 A full description of all available context properties is in the
365 program reference, see
367 @internalsref{Tunable context properties}.
370 Translation @arrow{} Tunable context properties.
374 @node Modifying context plug-ins
375 @subsection Modifying context plug-ins
377 Notation contexts (like Score and Staff) not only store properties,
378 they also contain plug-ins, called ``engravers'' that create notation
379 elements. For example, the Voice context contains a
380 @code{Note_head_engraver} and the Staff context contains a
381 @code{Key_signature_engraver}.
383 For a full a description of each plug-in, see
385 @internalsref{Engravers}.
388 Program reference @arrow Translation @arrow{} Engravers.
390 Every context described in
392 @internalsref{Contexts}
395 Program reference @arrow Translation @arrow{} Context.
397 lists the engravers used for that context.
400 It can be useful to shuffle around these plug-ins. This is done by
401 starting a new context, with @code{\new} or @code{\context}, and
402 modifying it like this,
405 \new @var{context} \with @{
416 where the @dots{} should be the name of an engraver. Here is a simple
417 example which removes @code{Time_signature_engraver} and
418 @code{Clef_engraver} from a @code{Staff} context,
420 @lilypond[quote,relative=1,verbatim,fragment]
425 \remove "Time_signature_engraver"
426 \remove "Clef_engraver"
433 In the second staff there are no time signature or clef symbols. This
434 is a rather crude method of making objects disappear since it will affect
435 the entire staff. The spacing is adversely influenced too. A more
436 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
438 The next example shows a practical application. Bar lines and time
439 signatures are normally synchronized across the score. This is done
440 by the @code{Timing_engraver}. This plug-in keeps an administration of
441 time signature, location within the measure, etc. By moving the
442 @code{Timing_engraver} engraver from @code{Score} to @code{Staff}
443 context, we can have a score where each staff has its own time
446 @cindex polymetric scores
447 @cindex Time signatures, multiple
449 @lilypond[quote,relative=1,raggedright,verbatim,fragment]
451 \remove "Timing_engraver"
454 \consists "Timing_engraver"
460 \consists "Timing_engraver"
469 @node Layout tunings within contexts
470 @subsection Layout tunings within contexts
472 Each context is responsible for creating certain types of graphical
473 objects. The settings used for printing these objects are also stored by
474 context. By changing these settings, the appearance of objects can be
477 The syntax for this is
480 \override @var{context}.@var{name} #'@var{property} = #@var{value}
483 Here @var{name} is the name of a graphical object, like @code{Stem} or
484 @code{NoteHead}, and @var{property} is an internal variable of the
485 formatting system (`grob property' or `layout property'). The latter is a
486 symbol, so it must be quoted. The subsection @ref{Constructing a
487 tweak} explains what to fill in for @var{name}, @var{property}, and
488 @var{value}. Here we only discuss the functionality of this command.
493 \override Staff.Stem #'thickness = #4.0
497 makes stems thicker (the default is 1.3, with staff line thickness as a
498 unit). Since the command specifies @context{Staff} as context, it only
499 applies to the current staff. Other staves will keep their normal
500 appearance. Here we see the command in action:
502 @lilypond[quote,verbatim,relative=2,fragment]
504 \override Staff.Stem #'thickness = #4.0
510 The @code{\override} command changes the definition of the @code{Stem}
511 within the current @context{Staff}. After the command is interpreted
512 all stems are thickened.
514 Analogous to @code{\set}, the @var{context} argument may be left out,
515 causing it to default to @context{Voice}, and adding @code{\once} applies
516 the change during one timestep only
518 @lilypond[quote,fragment,verbatim,relative=2]
520 \once \override Stem #'thickness = #4.0
525 The @code{\override} must be done before the object is
526 started. Therefore, when altering @emph{Spanner} objects, like slurs or
527 beams, the @code{\override} command must be executed at the moment when
528 the object is created. In this example,
531 @lilypond[quote,fragment,verbatim,relative=2]
532 \override Slur #'thickness = #3.0
534 \override Beam #'thickness = #0.6
539 the slur is fatter but the beam is not. This is because the command for
540 @code{Beam} comes after the Beam is started. Therefore it has no effect.
542 Analogous to @code{\unset}, the @code{\revert} command for a context
543 undoes an @code{\override} command; like with @code{\unset}, it only
544 affects settings that were made in the same context. In other words, the
545 @code{\revert} in the next example does not do anything.
548 \override Voice.Stem #'thickness = #4.0
549 \revert Staff.Stem #'thickness
557 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
558 @internalsref{PropertySet}, @internalsref{Backend}, and
559 @internalsref{All layout objects}.
564 The back-end is not very strict in type-checking object properties.
565 Cyclic references in Scheme values for properties can cause hangs
569 @node Changing context default settings
570 @subsection Changing context default settings
572 The adjustments of the previous subsections (@ref{Changing context
573 properties on the fly}, @ref{Modifying context plug-ins}, and
574 @ref{Layout tunings within contexts}) can also be entered separately
575 from the music, in the @code{\layout} block,
584 \override Stem #'thickness = #4.0
585 \remove "Time_signature_engraver"
596 takes the existing definition for context @context{Staff} from the
597 identifier @code{\Staff}.
602 \override Stem #'thickness = #4.0
603 \remove "Time_signature_engraver"
607 affect all staves in the score.
609 Other contexts can be modified analogously.
611 The @code{\set} keyword is optional within the @code{\layout} block, so
627 It is not possible to collect context changes in a variable, and apply
628 them to one @code{\context} definition by referring to that variable.
630 The @code{\RemoveEmptyStaffContext} will override your current
631 @code{\Staff} variable. If you wish to change the defaults for a
632 staff that uses @code{\RemoveEmptyStaffContext}, you must do so
633 after calling @code{\RemoveemptyStaffContext}, ie
638 \RemoveEmptyStaffContext
640 \override Stem #'thickness = #4.0
646 @node Defining new contexts
647 @subsection Defining new contexts
649 Specific contexts, like @context{Staff} and @code{Voice}, are made of
650 simple building blocks, and it is possible to compose engraver
651 plug-ins in different combinations, thereby creating new types of
654 The next example shows how to build a different type of
655 @context{Voice} context from scratch. It will be similar to
656 @code{Voice}, but prints centered slash noteheads only. It can be used
657 to indicate improvisation in Jazz pieces,
659 @lilypond[quote,raggedright]
662 \type "Engraver_group_engraver"
663 \consists "Note_heads_engraver"
664 \consists "Text_engraver"
665 \consists Pitch_squash_engraver
666 squashedPosition = #0
667 \override NoteHead #'style = #'slash
668 \override Stem #'transparent = ##t
672 \accepts "ImproVoice"
676 a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
677 c4 c^"undress" c_"while playing :)" c }
683 These settings are again done within a @code{\context} block inside a
684 @code{\layout} block,
694 In the following discussion, the example input shown should go on the
695 @dots{} in the previous fragment.
697 First, the context gets a name. Instead of @context{Voice} it
698 will be called @context{ImproVoice},
704 Since it is similar to the @context{Voice}, we want commands that work
705 on (existing) @context{Voice}s to remain working. This is achieved by
706 giving the new context an alias @context{Voice},
712 The context will print notes, and instructive texts
715 \consists Note_heads_engraver
716 \consists Text_engraver
719 but only on the center line,
722 \consists Pitch_squash_engraver
723 squashedPosition = #0
726 The @internalsref{Pitch_squash_engraver} modifies note heads (created
727 by @internalsref{Note_heads_engraver}) and sets their vertical
728 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
731 The notes look like a slash, without a stem,
734 \override NoteHead #'style = #'slash
735 \override Stem #'transparent = ##t
739 All these plug-ins have to cooperate, and this is achieved with a
740 special plug-in, which must be marked with the keyword @code{\type}.
741 This should always be @internalsref{Engraver_group_engraver},
744 \type "Engraver_group_engraver"
752 \type "Engraver_group_engraver"
753 \consists "Note_heads_engraver"
754 \consists "Text_engraver"
755 \consists Pitch_squash_engraver
756 squashedPosition = #0
757 \override NoteHead #'style = #'slash
758 \override Stem #'transparent = ##t
763 Contexts form hierarchies. We want to hang the @context{ImproVoice}
764 under @context{Staff}, just like normal @code{Voice}s. Therefore, we
765 modify the @code{Staff} definition with the @code{\accepts}
766 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
767 which is sometimes needed when reusing existing context definitions.}
778 Putting both into a @code{\layout} block, like
788 \accepts "ImproVoice"
793 Then the output at the start of this subsection can be entered as
801 c c_"while playing :)"
810 @node The \override command
811 @section The \override command
813 In the previous section, we have already touched on a command that
814 changes layout details: the @code{\override} command. In this section,
815 we will look in more detail at how to use the command in practice.
816 First, we will give a few versatile commands that are sufficient
817 for many situations. The next section will discuss the general use of
823 * Constructing a tweak::
824 * Navigating the program reference::
825 * Layout interfaces::
826 * Determining the grob property::
833 @subsection Common tweaks
835 @c Should we point at ly/property-init.ly ? -gp
836 Some overrides are so common that predefined commands are provided as
837 short-cuts, for example, @code{\slurUp} and @code{\stemDown}. These
838 commands are described in
842 @c @ref{Notation manual},
845 under the sections for slurs and stems
848 The exact tuning possibilities for each type of layout object are
849 documented in the program reference of the respective
850 object. However, many layout objects share properties, which can be
851 used to apply generic tweaks. We mention a few of these:
854 @item The @code{extra-offset} property, which
855 @cindex @code{extra-offset}
856 has a pair of numbers as value, moves objects around in the printout.
857 The first number controls left-right movement; a positive number will
858 move the object to the right. The second number controls up-down
859 movement; a positive number will move it higher. The units of these
860 offsets are staff-spaces. The @code{extra-offset} property is a
861 low-level feature: the formatting engine is completely oblivious to
864 In the following example, the second fingering is moved a little to
865 the left, and 1.8 staff space downwards:
867 @cindex setting object properties
869 @lilypond[quote,fragment,relative=1,verbatim]
872 \once \override Fingering
873 #'extra-offset = #'(-0.3 . -1.8)
878 Setting the @code{transparent} property will cause an object to be printed
879 in `invisible ink': the object is not printed, but all its other
880 behavior is retained. The object still takes up space, it takes part in
881 collisions, and slurs, ties, and beams can be attached to it.
883 @cindex transparent objects
884 @cindex removing objects
885 @cindex hiding objects
886 @cindex invisible objects
887 The following example demonstrates how to connect different voices
888 using ties. Normally, ties only connect two notes in the same
889 voice. By introducing a tie in a different voice,
891 @lilypond[quote,fragment,relative=2]
900 and blanking the first up-stem in that voice, the tie appears to cross
903 @lilypond[quote,fragment,relative=2,verbatim]
905 \once \override Stem #'transparent = ##t
913 The @code{padding} property for objects with
914 @cindex @code{padding}
915 @code{side-position-interface} can be set to increase the distance between
916 symbols that are printed above or below notes. We provide two
917 examples; a more elaborate explanation is in @ref{Constructing a
920 @lilypond[quote,fragment,relative=1,verbatim]
922 \override Script #'padding = #3
926 @lilypond[quote,fragment,relative=1,verbatim]
927 % This will not work, see below:
928 \override MetronomeMark #'padding = #3
932 \override Score.MetronomeMark #'padding = #3
937 Note in the second example how important it is to figure out what
938 context handles a certain object. Since the @code{MetronomeMark} object
939 is handled in the Score context, property changes in the @code{Voice}
940 context will not be noticed.
944 More specific overrides are also possible. The next section
945 discusses in depth how to figure out these statements for yourself.
948 @node Constructing a tweak
949 @subsection Constructing a tweak
951 The general procedure of changing output, that is, entering
955 \override Voice.Stem #'thickness = #3.0
959 means that we have to determine these bits of information:
962 @item the context: here @context{Voice}.
963 @item the layout object: here @code{Stem}.
964 @item the layout property: here @code{thickness}
965 @item a sensible value: here @code{3.0}
969 @cindex internal documentation
970 @cindex finding graphical objects
971 @cindex graphical object descriptions
973 @cindex @code{\override}
974 @cindex internal documentation
976 We demonstrate how to glean this information from the notation manual
977 and the program reference.
979 @node Navigating the program reference
980 @subsection Navigating the program reference
982 Suppose we want to move the fingering indication in the fragment
985 @lilypond[quote,fragment,relative=2,verbatim]
991 If you visit the documentation on fingering instructions (in
992 @ref{Fingering instructions}), you will notice that there is written:
997 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
1003 This fragment points to two parts of the program reference: a page
1004 on @code{FingerEvent} and one on @code{Fingering}.
1006 The page on @code{FingerEvent} describes the properties of the music
1007 expression for the input @code{-2}. The page contains many links
1008 forward. For example, it says
1011 Accepted by: @internalsref{Fingering_engraver},
1015 That link brings us to the documentation for the Engraver, the
1019 This engraver creates the following layout objects: @internalsref{Fingering}.
1022 In other words, once the @code{FingerEvent}s are interpreted, the
1023 @code{Fingering_engraver} plug-in will process them.
1024 The @code{Fingering_engraver} is also listed to create
1025 @internalsref{Fingering} objects,
1028 Lo and behold, that is also the
1029 second bit of information listed under @b{See also} in the Notation
1030 manual. By clicking around in the program reference, we can follow the
1031 flow of information within the program, either forward (like we did
1032 here), or backwards, following links like this:
1036 @item @internalsref{Fingering}:
1037 @internalsref{Fingering} objects are created by:
1038 @b{@internalsref{Fingering_engraver}}
1040 @item @internalsref{Fingering_engraver}:
1041 Music types accepted: @b{@internalsref{fingering-event}}
1043 @item @internalsref{fingering-event}:
1044 Music event type @code{fingering-event} is in Music expressions named
1045 @b{@internalsref{FingerEvent}}
1048 This path goes against the flow of information in the program: it
1049 starts from the output, and ends at the input event.
1051 The program reference can also be browsed like a normal document. It
1052 contains a chapter on
1054 @internalsref{Music definitions},
1057 @code{Music definitions}
1059 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1060 chapter lists all the definitions used, and all properties that may be
1064 @node Layout interfaces
1065 @subsection Layout interfaces
1067 @cindex interface, layout
1068 @cindex layout interface
1070 The HTML page that we found in the previous section, describes the
1071 layout object called @internalsref{Fingering}. Such an object is a
1072 symbol within the score. It has properties that store numbers (like
1073 thicknesses and directions), but also pointers to related objects. A
1074 layout object is also called @emph{grob},
1076 which is short for Graphical Object.
1079 The page for @code{Fingering} lists the definitions for the
1080 @code{Fingering} object. For example, the page says
1083 @code{padding} (dimension, in staff space):
1089 which means that the number will be kept at a distance of at least 0.6
1093 Each layout object may have several functions as a notational or
1094 typographical element. For example, the Fingering object
1095 has the following aspects
1099 Its size is independent of the horizontal spacing, unlike slurs or beams.
1102 It is a piece of text. Granted, it is usually a very short text.
1105 That piece of text is typeset with a font, unlike slurs or beams.
1108 Horizontally, the center of the symbol should be aligned to the
1109 center of the notehead.
1112 Vertically, the symbol is placed next to the note and the staff.
1115 The vertical position is also coordinated with other super- and subscript
1119 Each of these aspects is captured in so-called @emph{interface}s,
1120 which are listed on the @internalsref{Fingering} page at the bottom
1123 This object supports the following interfaces:
1124 @internalsref{item-interface},
1125 @internalsref{self-alignment-interface},
1126 @internalsref{side-position-interface}, @internalsref{text-interface},
1127 @internalsref{text-script-interface}, @internalsref{font-interface},
1128 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1131 Clicking any of the links will take you to the page of the respective
1132 object interface. Each interface has a number of properties. Some of
1133 them are not user-serviceable (``Internal properties''), but others
1136 We have been talking of @emph{the} @code{Fingering} object, but actually it
1137 does not amount to much. The initialization file
1138 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1142 . ((print-function . ,Text_interface::print)
1144 (staff-padding . 0.6)
1145 (self-alignment-X . 0)
1146 (self-alignment-Y . 0)
1147 (script-priority . 100)
1149 (meta . ((interfaces . (finger-interface font-interface
1150 text-script-interface text-interface
1151 side-position-interface
1152 self-alignment-interface
1153 item-interface))))))
1157 As you can see, the @code{Fingering} object is nothing more than a
1158 bunch of variable settings, and the webpage in the Program Reference
1159 is directly generated from this definition.
1161 @node Determining the grob property
1162 @subsection Determining the grob property
1165 Recall that we wanted to change the position of the @b{2} in
1167 @lilypond[quote,fragment,relative=2,verbatim]
1173 Since the @b{2} is vertically positioned next to its note, we have to
1174 meddle with the interface associated with this positioning. This is
1175 done using @code{side-position-interface}. The page for this interface
1179 @code{side-position-interface}
1181 Position a victim object (this one) next to other objects (the
1182 support). The property @code{direction} signifies where to put the
1183 victim object relative to the support (left or right, up or down?)
1188 below this description, the variable @code{padding} is described as
1193 (dimension, in staff space)
1195 Add this much extra space between objects that are next to each other.
1199 By increasing the value of @code{padding}, we can move away the
1200 fingering. The following command inserts 3 staff spaces of white
1201 between the note and the fingering:
1203 \once \override Voice.Fingering #'padding = #3
1206 Inserting this command before the Fingering object is created,
1207 i.e., before @code{c2}, yields the following result:
1209 @lilypond[quote,relative=2,fragment,verbatim]
1210 \once \override Voice.Fingering #'padding = #3
1217 In this case, the context for this tweak is @context{Voice}. This
1218 fact can also be deduced from the program reference, for the page for
1219 the @internalsref{Fingering_engraver} plug-in says
1222 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1225 @node Difficult tweaks
1226 @subsection Difficult tweaks
1228 There are two classes of difficult adjustments. First, when there are
1229 several of the same objects at one point, and you want to adjust only
1230 one. For example, if you want to change only one note head in a chord.
1232 In this case, the @code{\applyoutput} function must be used. The
1233 next example defines a Scheme function @code{set-position-font-size}
1234 that sets the @code{font-size} property, but only
1235 on objects that have @internalsref{note-head-interface} and are at the
1238 @lilypond[quote,verbatim]
1239 #(define ((set-position-font-size pos size) grob origin current)
1241 ((interfaces (ly:grob-property grob 'interfaces))
1242 (position (ly:grob-property grob 'staff-position)))
1244 ; is this a note head?
1245 (memq 'note-head-interface interfaces)
1247 ; is the Y coordinate right?
1251 (set! (ly:grob-property grob 'font-size) size))))
1255 \applyoutput #(set-position-font-size -2 4)
1261 A similar technique can be used for accidentals. In that case, the
1262 function should check for @code{accidental-interface}.
1264 Another difficult adjustment is the appearance of spanner objects,
1265 such as slur and tie. Initially, only one of these objects is created,
1266 and they can be adjusted with the normal mechanism. However, in some
1267 cases the spanners cross line breaks. If this happens, these objects
1268 are cloned. A separate object is created for every system that it is
1269 in. These are clones of the original object and inherit all
1270 properties, including @code{\override}s.
1272 In other words, an @code{\override} always affects all pieces of a
1273 broken spanner. To change only one part of a spanner at a line break,
1274 it is necessary to hook into the formatting process. The
1275 @code{after-line-breaking-callback} property contains the Scheme procedure
1276 that is called after the line breaks have been determined, and layout
1277 objects have been split over different systems.
1279 In the following example, we define a procedure
1280 @code{my-callback}. This procedure
1284 determines if we have been split across line breaks
1286 if yes, retrieves all the split objects
1288 checks if we are the last of the split objects
1290 if yes, it sets @code{extra-offset}.
1293 This procedure is installed into @internalsref{Tie}, so the last part
1294 of the broken tie is translated up.
1297 @lilypond[quote,verbatim,raggedright]
1298 #(define (my-callback grob)
1300 ; have we been split?
1301 (orig (ly:grob-original grob))
1303 ; if yes, get the split pieces (our siblings)
1304 (siblings (if (ly:grob? orig)
1305 (ly:spanner-broken-into orig) '() )))
1307 (if (and (>= (length siblings) 2)
1308 (eq? (car (last-pair siblings)) grob))
1309 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1312 \override Tie #'after-line-breaking-callback =
1319 When applying this trick, the new @code{after-line-breaking-callback}
1320 should also call the old @code{after-line-breaking-callback}, if there
1321 is one. For example, if using this with @code{Slur},
1322 @code{Slur::after_line_breaking} should also be called.
1327 This section details the ways that the font can be changed.
1330 * Selecting font sizes::
1336 @node Selecting font sizes
1337 @subsection Selecting font sizes
1340 The easiest method of setting the font size of any context, is by
1341 setting the @code{fontSize} property.
1343 @lilypond[quote,fragment,relative=1,verbatim]
1352 It does not change the size of variable symbols, such as beams or
1355 Internally, the @code{fontSize} context property will cause the
1356 @code{font-size} property to be set in all layout objects. The value
1357 of @code{font-size} is a number indicating the size relative to the
1358 standard size for the current staff height. Each step up is an
1359 increase of approximately 12% of the font size. Six steps is exactly a
1360 factor two. The Scheme function @code{magstep} converts a
1361 @code{font-size} number to a scaling factor.
1363 @lilypond[quote,fragment,relative=1,verbatim]
1365 \override NoteHead #'font-size = #-4
1367 \override NoteHead #'font-size = #3
1371 LilyPond has fonts in different design sizes. The music fonts for
1372 smaller sizes are chubbier, while the text fonts are relatively wider.
1373 Font size changes are achieved by scaling the design size that is
1374 closest to the desired size. The standard font size (for
1375 @code{font-size} equals 0), depends on the standard staff height. For
1376 a 20pt staff, a 10pt font is selected.
1378 The @code{font-size} property can only be set on layout objects that
1379 use fonts. These are the ones supporting the
1380 @internalsref{font-interface} layout interface.
1384 The following commands set @code{fontSize} for the current voice:
1386 @cindex @code{\tiny}
1388 @cindex @code{\small}
1390 @cindex @code{\normalsize}
1395 @cindex magnification
1399 @node Font selection
1400 @subsection Font selection
1404 @cindex font selection
1405 @cindex font magnification
1406 @cindex @code{font-interface}
1408 By setting the object properties described below, you can select a
1409 font from the preconfigured font families. LilyPond has default
1410 support for the feta music fonts and @TeX{}'s Computer Modern text
1415 @item @code{font-encoding}
1416 is a symbol that sets layout of the glyphs. This should only be set to
1417 select different types of non-text fonts, eg.
1419 @code{fetaBraces} for piano staff braces, @code{fetaMusic} the
1420 standard music font, including ancient glyphs, @code{fetaDynamic} for
1421 dynamic signs and @code{fetaNumber} for the number font.
1423 @item @code{font-family}
1424 is a symbol indicating the general class of the typeface. Supported are
1425 @code{roman} (Computer Modern), @code{sans}, and @code{typewriter}.
1427 @item @code{font-shape}
1428 is a symbol indicating the shape of the font. There are typically
1429 several font shapes available for each font family. Choices are
1430 @code{italic}, @code{caps}, and @code{upright}.
1432 @item @code{font-series}
1433 is a symbol indicating the series of the font. There are typically
1434 several font series for each font family and shape. Choices are
1435 @code{medium} and @code{bold}.
1439 Fonts selected in the way sketched above come from a predefined style
1440 sheet. If you want to use a font from outside the style sheet,
1442 @code{font-name} property,
1444 @lilypond[fragment,verbatim]
1446 \override Staff.TimeSignature #'font-name = #"Times"
1447 \override Staff.TimeSignature #'font-size = #2
1450 \override #'(font-name . "Vera Bold")
1451 { This text is in Vera Bold }
1457 Any font can be used, as long as it is available to Pango/FontConfig.
1459 The size of the font may be set with the @code{font-size}
1460 property. The resulting size is taken relative to the
1461 @code{text-font-size} as defined in the @code{\paper} block.
1465 @cindex font magnification
1471 Init files: @file{ly/@/declarations@/-init@/.ly} contains hints how new
1472 fonts may be added to LilyPond.