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
18 document, the @internalsref{Program reference} manual. That manual
19 lists all different variables, functions and options available in
20 LilyPond. It is written as a HTML document, which is available
21 @uref{http://@/lilypond@/.org/@/doc/@/Documentation/@/user/@/out@/-www/@/lilypond@/-internals/,on@/-line},
22 but is also included with the LilyPond documentation package.
24 There are three areas where the default settings may be changed:
28 Output: changing the appearance of individual
29 objects. For example, changing stem directions or the location of
33 Context: changing aspects of the translation from music events to
34 notation. For example, giving each staff a separate time signature.
37 Global layout: changing the appearance of the spacing, line
38 breaks, and page dimensions.
41 Then there are separate systems for typesetting text (like
42 @emph{ritardando}) and selecting different fonts. This chapter also
45 Internally, LilyPond uses Scheme (a LISP dialect) to provide
46 infrastructure. Overriding layout decisions in effect accesses the
47 program internals, which requires Scheme input. Scheme elements are
48 introduced in a @code{.ly} file with the hash mark
49 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
50 on entering numbers, lists, strings, and symbols in Scheme.}
54 * Interpretation contexts::
55 * The \override command::
61 @node Interpretation contexts
62 @section Interpretation contexts
64 When music is printed, a lot of notational elements must be added to the
65 input, which is often bare bones. For example, compare the input and
66 output of the following example:
68 @lilypond[quote,verbatim,relative=2,fragment]
72 The input is rather sparse, but in the output, bar lines, accidentals,
73 clef, and time signature are added. LilyPond @emph{interprets} the
74 input. During this step, the musical information is inspected in time
75 order, similar to reading a score from left to right. While reading,
76 the input, the program remembers where measure boundaries are, and what
77 pitches need explicit accidentals. This information can be presented on
78 several levels. For example, the effect of an accidental is limited
79 to a single staff, while a bar line must be synchronized across the
82 Within LilyPond, these rules and bits of information are grouped in
83 so-called Contexts. Examples of context are @context{Voice},
84 @context{Staff}, and @context{Score}. They are hierarchical, for
85 example, a @context{Staff} can contain many @context{Voice}s, and a
86 @context{Score} can contain many @context{Staff} contexts.
88 Each context has the responsibility for enforcing some notation rules,
89 creating some notation objects and maintaining the associated
90 properties. So, the synchronization of bar lines is handled at
91 @context{Score} context. The @context{Voice} may introduce an
92 accidental and then the @context{Staff} context maintains the rule to
93 show or suppress the accidental for the remainder of the measure.
95 For simple scores, contexts are created implicitly, and you need not
96 be aware of them. For larger pieces, such as piano music, they must be
97 created explicitly to make sure that you get as many staves as you
98 need, and that they are in the correct order. For typesetting pieces
99 with specialized notation, it can be useful to modify existing or
100 to define new contexts.
103 A complete description of all available contexts is in the program
106 @internalsref{Contexts}.
109 Translation @arrow{} Context.
112 @c [TODO: describe propagation]
116 * Creating contexts::
117 * Changing context properties on the fly::
118 * Modifying context plug-ins::
119 * Layout tunings within contexts::
120 * Changing context default settings::
121 * Defining new contexts::
124 @node Creating contexts
125 @subsection Creating contexts
127 For scores with only one voice and one staff, correct contexts are
128 created automatically. For more complex scores, it is necessary to
129 create them by hand. There are three commands that do this.
131 The easiest command is @code{\new}, and it also the quickest to type.
132 It is prepended to a music expression, for example
136 @cindex Context, creating
139 \new @var{type} @var{music expression}
143 where @var{type} is a context name (like @code{Staff} or
144 @code{Voice}). This command creates a new context, and starts
145 interpreting the @var{music expression} with that.
147 A practical application of @code{\new} is a score with many
148 staves. Each part that should be on its own staff, is preceded with
151 @lilypond[quote,verbatim,relative=2,raggedright,fragment]
152 << \new Staff { c4 c }
157 @cindex @code{\context}
159 Like @code{\new}, the @code{\context} command also directs a music
160 expression to a context object, but gives the context an extra name. The
164 \context @var{type} = @var{id} @var{music}
167 This form will search for an existing context of type @var{type}
168 called @var{id}. If that context does not exist yet, it is created.
169 This is useful if the context is referred to later on. For example, when
170 setting lyrics the melody is in a named context
173 \CONtext Voice = "@b{tenor}" @var{music}
177 so the texts can be properly aligned to its notes,
180 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
185 Another possibility is funneling two different music expressions into
186 one context. In the following example, articulations and notes are
191 arts = @{ s4-. s4-> @}
194 They are combined by sending both to the same @context{Voice} context,
197 << \new Staff \context Voice = "A" \music
198 \context Voice = "A" \arts
201 @lilypond[quote,raggedright]
205 \new Staff \context Voice = "A" \music
206 \context Voice = "A" \arts
210 With this mechanism, it is possible to define an Urtext (original
211 edition), with the option to put several distinct articulations on the
214 @cindex @code{\context}
215 @cindex creating contexts
217 The third command for creating contexts is
219 \context @var{type} @var{music}
224 This is similar to @code{\context} with @code{= @var{id}}, but matches
225 any context of type @var{type}, regardless of its given name.
227 This variant is used with music expressions that can be interpreted at
228 several levels. For example, the @code{\applyoutput} command (see
229 @ref{Running a function on all layout objects}). Without an explicit
230 @code{\context}, it is usually applied to @context{Voice}
233 \applyoutput #@var{function} % apply to Voice
236 To have it interpreted at the @context{Score} or @context{Staff} level use
240 \context Score \applyoutput #@var{function}
241 \context Staff \applyoutput #@var{function}
245 @node Changing context properties on the fly
246 @subsection Changing context properties on the fly
250 @cindex changing properties
252 Each context can have different @emph{properties}, variables contained
253 in that context. They can be changed during the interpretation step.
254 This is achieved by inserting the @code{\set} command in the music,
257 \set @var{context}.@var{prop} = #@var{value}
261 @lilypond[quote,verbatim,relative=2,fragment]
263 \set Score.skipBars = ##t
267 This command skips measures that have no notes. The result is that
268 multi-rests are condensed. The value assigned is a Scheme object. In
269 this case, it is @code{#t}, the boolean True value.
271 If the @var{context} argument is left out, then the current bottom-most
272 context (typically @context{ChordNames}, @context{Voice}, or
273 @context{Lyrics}) is used. In this example,
275 @lilypond[quote,verbatim,relative=2,fragment]
277 \set autoBeaming = ##f
282 the @var{context} argument to @code{\set} is left out, so automatic
283 beaming is switched off in the current @internalsref{Voice}. Note that
284 the bottom-most context does not always contain the property that you
285 wish to change -- for example, attempting to set the @code{skipBars}
286 property (of the bottom-most context, in this case @code{Voice}) will
289 @lilypond[quote,verbatim,relative=2,fragment]
295 Contexts are hierarchical, so if a bigger context was specified, for
296 example @context{Staff}, then the change would also apply to all
297 @context{Voice}s in the current stave. The change is applied
298 `on-the-fly', during the music, so that the setting only affects the
299 second group of eighth notes.
301 @cindex @code{\unset}
303 There is also an @code{\unset} command,
305 \unset @var{context}.@var{prop}
309 which removes the definition of @var{prop}. This command removes
310 the definition only if it is set in @var{context}, so
313 \set Staff.autoBeaming = ##f
317 introduces a property setting at @code{Staff} level. The setting also
318 applies to the current @code{Voice}. However,
321 \unset Voice.autoBeaming
325 does not have any effect. To cancel this setting, the @code{\unset}
326 must be specified on the same level as the original @code{\set}. In
327 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
330 \unset Staff.autoBeaming
333 Like @code{\set}, the @var{context} argument does not have to be
334 specified for a bottom context, so the two statements
337 \set Voice.autoBeaming = ##t
338 \set autoBeaming = ##t
346 Settings that should only apply to a single time-step can be entered
347 with @code{\once}, for example in
349 @lilypond[quote,verbatim,relative=2,fragment]
351 \once \set fontSize = #4.7
356 the property @code{fontSize} is unset automatically after the second
359 A full description of all available context properties is in the
360 program reference, see
362 @internalsref{Tunable context properties}.
365 Translation @arrow{} Tunable context properties.
369 @node Modifying context plug-ins
370 @subsection Modifying context plug-ins
372 Notation contexts (like Score and Staff) not only store properties,
373 they also contain plug-ins, called ``engravers'' that create notation
374 elements. For example, the Voice context contains a
375 @code{Note_head_engraver} and the Staff context contains a
376 @code{Key_signature_engraver}.
378 For a full a description of each plug-in, see
380 @internalsref{Engravers}.
383 Program reference @arrow Translation @arrow{} Engravers.
385 Every context described in
387 @internalsref{Contexts}
390 Program reference @arrow Translation @arrow{} Context.
392 lists the engravers used for that context.
395 It can be useful to shuffle around these plug-ins. This is done by
396 starting a new context, with @code{\new} or @code{\context}, and
397 modifying it like this,
400 \new @var{context} \with @{
411 where the @dots{} should be the name of an engraver. Here is a simple
412 example which removes @code{Time_signature_engraver} and
413 @code{Clef_engraver} from a @code{Staff} context,
415 @lilypond[quote,relative=1,verbatim,fragment]
420 \remove "Time_signature_engraver"
421 \remove "Clef_engraver"
428 In the second staff there are no time signature or clef symbols. This
429 is a rather crude method of making objects disappear since it will affect
430 the entire staff. The spacing is adversely influenced too. A more
431 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
433 The next example shows a practical application. Bar lines and time
434 signatures are normally synchronized across the score. This is done
435 by the @code{Timing_engraver}. This plug-in keeps an administration of
436 time signature, location within the measure, etc. By moving the
437 @code{Timing_engraver} engraver from @code{Score} to @code{Staff}
438 context, we can have a score where each staff has its own time
441 @cindex polymetric scores
442 @cindex Time signatures, multiple
444 @lilypond[quote,relative=1,raggedright,verbatim,fragment]
446 \remove "Timing_engraver"
449 \consists "Timing_engraver"
455 \consists "Timing_engraver"
464 @node Layout tunings within contexts
465 @subsection Layout tunings within contexts
467 Each context is responsible for creating certain types of graphical
468 objects. The settings used for printing these objects are also stored by
469 context. By changing these settings, the appearance of objects can be
472 The syntax for this is
475 \override @var{context}.@var{name} #'@var{property} = #@var{value}
478 Here @var{name} is the name of a graphical object, like @code{Stem} or
479 @code{NoteHead}, and @var{property} is an internal variable of the
480 formatting system (`grob property' or `layout property'). The latter is a
481 symbol, so it must be quoted. The subsection @ref{Constructing a
482 tweak} explains what to fill in for @var{name}, @var{property}, and
483 @var{value}. Here we only discuss the functionality of this command.
488 \override Staff.Stem #'thickness = #4.0
492 makes stems thicker (the default is 1.3, with staff line thickness as a
493 unit). Since the command specifies @context{Staff} as context, it only
494 applies to the current staff. Other staves will keep their normal
495 appearance. Here we see the command in action:
497 @lilypond[quote,verbatim,relative=2,fragment]
499 \override Staff.Stem #'thickness = #4.0
505 The @code{\override} command changes the definition of the @code{Stem}
506 within the current @context{Staff}. After the command is interpreted
507 all stems are thickened.
509 Analogous to @code{\set}, the @var{context} argument may be left out,
510 causing it to default to @context{Voice}, and adding @code{\once} applies
511 the change during one timestep only
513 @lilypond[quote,fragment,verbatim,relative=2]
515 \once \override Stem #'thickness = #4.0
520 The @code{\override} must be done before the object is
521 started. Therefore, when altering @emph{Spanner} objects, like slurs or
522 beams, the @code{\override} command must be executed at the moment when
523 the object is created. In this example,
526 @lilypond[quote,fragment,verbatim,relative=2]
527 \override Slur #'thickness = #3.0
529 \override Beam #'thickness = #0.6
534 the slur is fatter but the beam is not. This is because the command for
535 @code{Beam} comes after the Beam is started. Therefore it has no effect.
537 Analogous to @code{\unset}, the @code{\revert} command for a context
538 undoes an @code{\override} command; like with @code{\unset}, it only
539 affects settings that were made in the same context. In other words, the
540 @code{\revert} in the next example does not do anything.
543 \override Voice.Stem #'thickness = #4.0
544 \revert Staff.Stem #'thickness
552 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
553 @internalsref{PropertySet}, @internalsref{All-backend-properties}, and
554 @internalsref{All layout objects}.
559 The back-end is not very strict in type-checking object properties.
560 Cyclic references in Scheme values for properties can cause hangs
564 @node Changing context default settings
565 @subsection Changing context default settings
567 The adjustments of the previous subsections (@ref{Changing context
568 properties on the fly}, @ref{Modifying context plug-ins}, and
569 @ref{Layout tunings within contexts}) can also be entered separately
570 from the music, in the @code{\layout} block,
579 \override Stem #'thickness = #4.0
580 \remove "Time_signature_engraver"
591 takes the existing definition for context @context{Staff} from the
592 identifier @code{\Staff}.
597 \override Stem #'thickness = #4.0
598 \remove "Time_signature_engraver"
602 affect all staves in the score.
604 Other contexts can be modified analogously.
606 The @code{\set} keyword is optional within the @code{\layout} block, so
622 It is not possible to collect context changes in a variable, and apply
623 them to one @code{\context} definition by referring to that variable.
625 The @code{\RemoveEmptyStaffContext} will override your current
626 @code{\Staff} variable. If you wish to change the defaults for a
627 staff that uses @code{\RemoveEmptyStaffContext}, you must do so
628 after calling @code{\RemoveemptyStaffContext}, ie
633 \RemoveEmptyStaffContext
635 \override Stem #'thickness = #4.0
641 @node Defining new contexts
642 @subsection Defining new contexts
644 Specific contexts, like @context{Staff} and @code{Voice}, are made of
645 simple building blocks, and it is possible to compose engraver
646 plug-ins in different combinations, thereby creating new types of
649 The next example shows how to build a different type of
650 @context{Voice} context from scratch. It will be similar to
651 @code{Voice}, but prints centered slash noteheads only. It can be used
652 to indicate improvisation in Jazz pieces,
654 @lilypond[quote,raggedright]
657 \type "Engraver_group_engraver"
658 \consists "Note_heads_engraver"
659 \consists "Text_engraver"
660 \consists Pitch_squash_engraver
661 squashedPosition = #0
662 \override NoteHead #'style = #'slash
663 \override Stem #'transparent = ##t
667 \accepts "ImproVoice"
671 a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
672 c4 c^"undress" c_"while playing :)" c }
678 These settings are again done within a @code{\context} block inside a
679 @code{\layout} block,
689 In the following discussion, the example input shown should go on the
690 @dots{} in the previous fragment.
692 First, the context gets a name. Instead of @context{Voice} it
693 will be called @context{ImproVoice},
699 Since it is similar to the @context{Voice}, we want commands that work
700 on (existing) @context{Voice}s to remain working. This is achieved by
701 giving the new context an alias @context{Voice},
707 The context will print notes, and instructive texts
710 \consists Note_heads_engraver
711 \consists Text_engraver
714 but only on the center line,
717 \consists Pitch_squash_engraver
718 squashedPosition = #0
721 The @internalsref{Pitch_squash_engraver} modifies note heads (created
722 by @internalsref{Note_heads_engraver}) and sets their vertical
723 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
726 The notes look like a slash, without a stem,
729 \override NoteHead #'style = #'slash
730 \override Stem #'transparent = ##t
734 All these plug-ins have to cooperate, and this is achieved with a
735 special plug-in, which must be marked with the keyword @code{\type}.
736 This should always be @internalsref{Engraver_group_engraver},
739 \type "Engraver_group_engraver"
747 \type "Engraver_group_engraver"
748 \consists "Note_heads_engraver"
749 \consists "Text_engraver"
750 \consists Pitch_squash_engraver
751 squashedPosition = #0
752 \override NoteHead #'style = #'slash
753 \override Stem #'transparent = ##t
758 Contexts form hierarchies. We want to hang the @context{ImproVoice}
759 under @context{Staff}, just like normal @code{Voice}s. Therefore, we
760 modify the @code{Staff} definition with the @code{\accepts}
761 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
762 which is sometimes needed when reusing existing context definitions.}
773 Putting both into a @code{\layout} block, like
783 \accepts "ImproVoice"
788 Then the output at the start of this subsection can be entered as
796 c c_"while playing :)"
805 @node The \override command
806 @section The \override command
808 In the previous section, we have already touched on a command that
809 changes layout details: the @code{\override} command. In this section,
810 we will look in more detail at how to use the command in practice.
811 First, we will give a few versatile commands that are sufficient
812 for many situations. The next section will discuss the general use of
818 * Constructing a tweak::
819 * Navigating the program reference::
820 * Layout interfaces::
821 * Determining the grob property::
828 @subsection Common tweaks
830 @c Should we point at ly/property-init.ly ? -gp
831 Some overrides are so common that predefined commands are provided as
832 short-cuts, for example, @code{\slurUp} and @code{\stemDown}. These
833 commands are described in
837 @c @ref{Notation manual},
840 under the sections for slurs and stems
843 The exact tuning possibilities for each type of layout object are
844 documented in the program reference of the respective
845 object. However, many layout objects share properties, which can be
846 used to apply generic tweaks. We mention a few of these:
849 @item The @code{extra-offset} property, which
850 @cindex @code{extra-offset}
851 has a pair of numbers as value, moves objects around in the printout.
852 The first number controls left-right movement; a positive number will
853 move the object to the right. The second number controls up-down
854 movement; a positive number will move it higher. The units of these
855 offsets are staff-spaces. The @code{extra-offset} property is a
856 low-level feature: the formatting engine is completely oblivious to
859 In the following example, the second fingering is moved a little to
860 the left, and 1.8 staff space downwards:
862 @cindex setting object properties
864 @lilypond[quote,fragment,relative=1,verbatim]
867 \once \override Fingering
868 #'extra-offset = #'(-0.3 . -1.8)
873 Setting the @code{transparent} property will cause an object to be printed
874 in `invisible ink': the object is not printed, but all its other
875 behavior is retained. The object still takes up space, it takes part in
876 collisions, and slurs, ties, and beams can be attached to it.
878 @cindex transparent objects
879 @cindex removing objects
880 @cindex hiding objects
881 @cindex invisible objects
882 The following example demonstrates how to connect different voices
883 using ties. Normally, ties only connect two notes in the same
884 voice. By introducing a tie in a different voice,
886 @lilypond[quote,fragment,relative=2]
895 and blanking the first up-stem in that voice, the tie appears to cross
898 @lilypond[quote,fragment,relative=2,verbatim]
900 \once \override Stem #'transparent = ##t
908 The @code{padding} property for objects with
909 @cindex @code{padding}
910 @code{side-position-interface} can be set to increase the distance between
911 symbols that are printed above or below notes. We only give an
912 example; a more elaborate explanation is in @ref{Constructing a
915 @lilypond[quote,fragment,relative=1,verbatim]
917 \override Script #'padding = #3
923 More specific overrides are also possible. The next section
924 discusses in depth how to figure out these statements for yourself.
927 @node Constructing a tweak
928 @subsection Constructing a tweak
930 The general procedure of changing output, that is, entering
934 \override Voice.Stem #'thickness = #3.0
938 means that we have to determine these bits of information:
941 @item the context: here @context{Voice}.
942 @item the layout object: here @code{Stem}.
943 @item the layout property: here @code{thickness}
944 @item a sensible value: here @code{3.0}
948 @cindex internal documentation
949 @cindex finding graphical objects
950 @cindex graphical object descriptions
952 @cindex @code{\override}
953 @cindex internal documentation
955 We demonstrate how to glean this information from the notation manual
956 and the program reference.
958 @node Navigating the program reference
959 @subsection Navigating the program reference
961 Suppose we want to move the fingering indication in the fragment
964 @lilypond[quote,fragment,relative=2,verbatim]
970 If you visit the documentation on fingering instructions (in
971 @ref{Fingering instructions}), you will notice that there is written:
976 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
982 This fragment points to two parts of the program reference: a page
983 on @code{FingerEvent} and one on @code{Fingering}.
985 The page on @code{FingerEvent} describes the properties of the music
986 expression for the input @code{-2}. The page contains many links
987 forward. For example, it says
990 Accepted by: @internalsref{Fingering_engraver},
994 That link brings us to the documentation for the Engraver, the
998 This engraver creates the following layout objects: @internalsref{Fingering}.
1001 In other words, once the @code{FingerEvent}s are interpreted, the
1002 @code{Fingering_engraver} plug-in will process them.
1003 The @code{Fingering_engraver} is also listed to create
1004 @internalsref{Fingering} objects,
1007 Lo and behold, that is also the
1008 second bit of information listed under @b{See also} in the Notation
1009 manual. By clicking around in the program reference, we can follow the
1010 flow of information within the program, either forward (like we did
1011 here), or backwards, following links like this:
1015 @item @internalsref{Fingering}:
1016 @internalsref{Fingering} objects are created by:
1017 @b{@internalsref{Fingering_engraver}}
1019 @item @internalsref{Fingering_engraver}:
1020 Music types accepted: @b{@internalsref{fingering-event}}
1022 @item @internalsref{fingering-event}:
1023 Music event type @code{fingering-event} is in Music expressions named
1024 @b{@internalsref{FingerEvent}}
1027 This path goes against the flow of information in the program: it
1028 starts from the output, and ends at the input event.
1030 The program reference can also be browsed like a normal document. It
1031 contains a chapter on
1033 @internalsref{Music definitions},
1036 @code{Music definitions}
1038 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1039 chapter lists all the definitions used, and all properties that may be
1043 @node Layout interfaces
1044 @subsection Layout interfaces
1046 @cindex interface, layout
1047 @cindex layout interface
1049 The HTML page that we found in the previous section, describes the
1050 layout object called @internalsref{Fingering}. Such an object is a
1051 symbol within the score. It has properties that store numbers (like
1052 thicknesses and directions), but also pointers to related objects. A
1053 layout object is also called @emph{grob},
1055 which is short for Graphical Object.
1058 The page for @code{Fingering} lists the definitions for the
1059 @code{Fingering} object. For example, the page says
1062 @code{padding} (dimension, in staff space):
1068 which means that the number will be kept at a distance of at least 0.6
1072 Each layout object may have several functions as a notational or
1073 typographical element. For example, the Fingering object
1074 has the following aspects
1078 Its size is independent of the horizontal spacing, unlike slurs or beams.
1081 It is a piece of text. Granted, it is usually a very short text.
1084 That piece of text is typeset with a font, unlike slurs or beams.
1087 Horizontally, the center of the symbol should be aligned to the
1088 center of the notehead.
1091 Vertically, the symbol is placed next to the note and the staff.
1094 The vertical position is also coordinated with other super- and subscript
1098 Each of these aspects is captured in so-called @emph{interface}s,
1099 which are listed on the @internalsref{Fingering} page at the bottom
1102 This object supports the following interfaces:
1103 @internalsref{item-interface},
1104 @internalsref{self-alignment-interface},
1105 @internalsref{side-position-interface}, @internalsref{text-interface},
1106 @internalsref{text-script-interface}, @internalsref{font-interface},
1107 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1110 Clicking any of the links will take you to the page of the respective
1111 object interface. Each interface has a number of properties. Some of
1112 them are not user-serviceable (``Internal properties''), but others
1115 We have been talking of @emph{the} @code{Fingering} object, but actually it
1116 does not amount to much. The initialization file
1117 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1121 . ((print-function . ,Text_interface::print)
1123 (staff-padding . 0.6)
1124 (self-alignment-X . 0)
1125 (self-alignment-Y . 0)
1126 (script-priority . 100)
1128 (meta . ((interfaces . (finger-interface font-interface
1129 text-script-interface text-interface
1130 side-position-interface
1131 self-alignment-interface
1132 item-interface))))))
1136 As you can see, the @code{Fingering} object is nothing more than a
1137 bunch of variable settings, and the webpage in the Program Reference
1138 is directly generated from this definition.
1140 @node Determining the grob property
1141 @subsection Determining the grob property
1144 Recall that we wanted to change the position of the @b{2} in
1146 @lilypond[quote,fragment,relative=2,verbatim]
1152 Since the @b{2} is vertically positioned next to its note, we have to
1153 meddle with the interface associated with this positioning. This is
1154 done using @code{side-position-interface}. The page for this interface
1158 @code{side-position-interface}
1160 Position a victim object (this one) next to other objects (the
1161 support). The property @code{direction} signifies where to put the
1162 victim object relative to the support (left or right, up or down?)
1167 below this description, the variable @code{padding} is described as
1172 (dimension, in staff space)
1174 Add this much extra space between objects that are next to each other.
1178 By increasing the value of @code{padding}, we can move away the
1179 fingering. The following command inserts 3 staff spaces of white
1180 between the note and the fingering:
1182 \once \override Voice.Fingering #'padding = #3
1185 Inserting this command before the Fingering object is created,
1186 i.e., before @code{c2}, yields the following result:
1188 @lilypond[quote,relative=2,fragment,verbatim]
1189 \once \override Voice.Fingering #'padding = #3
1196 In this case, the context for this tweak is @context{Voice}. This
1197 fact can also be deduced from the program reference, for the page for
1198 the @internalsref{Fingering_engraver} plug-in says
1201 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1204 @node Difficult tweaks
1205 @subsection Difficult tweaks
1207 There are two classes of difficult adjustments. First, when there are
1208 several of the same objects at one point, and you want to adjust only
1209 one. For example, if you want to change only one note head in a chord.
1211 In this case, the @code{\applyoutput} function must be used. The
1212 next example defines a Scheme function @code{set-position-font-size}
1213 that sets the @code{font-size} property, but only
1214 on objects that have @internalsref{note-head-interface} and are at the
1217 @lilypond[quote,verbatim]
1218 #(define ((set-position-font-size pos size) grob origin current)
1220 ((interfaces (ly:grob-property grob 'interfaces))
1221 (position (ly:grob-property grob 'staff-position)))
1223 ; is this a note head?
1224 (memq 'note-head-interface interfaces)
1226 ; is the Y coordinate right?
1230 (set! (ly:grob-property grob 'font-size) size))))
1234 \applyoutput #(set-position-font-size -2 4)
1240 A similar technique can be used for accidentals. In that case, the
1241 function should check for @code{accidental-interface}.
1243 Another difficult adjustment is the appearance of spanner objects,
1244 such as slur and tie. Initially, only one of these objects is created,
1245 and they can be adjusted with the normal mechanism. However, in some
1246 cases the spanners cross line breaks. If this happens, these objects
1247 are cloned. A separate object is created for every system that it is
1248 in. These are clones of the original object and inherit all
1249 properties, including @code{\override}s.
1251 In other words, an @code{\override} always affects all pieces of a
1252 broken spanner. To change only one part of a spanner at a line break,
1253 it is necessary to hook into the formatting process. The
1254 @code{after-line-breaking-callback} property contains the Scheme procedure
1255 that is called after the line breaks have been determined, and layout
1256 objects have been split over different systems.
1258 In the following example, we define a procedure
1259 @code{my-callback}. This procedure
1263 determines if we have been split across line breaks
1265 if yes, retrieves all the split objects
1267 checks if we are the last of the split objects
1269 if yes, it sets @code{extra-offset}.
1272 This procedure is installed into @internalsref{Tie}, so the last part
1273 of the broken tie is translated up.
1276 @lilypond[quote,verbatim,raggedright]
1277 #(define (my-callback grob)
1279 ; have we been split?
1280 (orig (ly:grob-original grob))
1282 ; if yes, get the split pieces (our siblings)
1283 (siblings (if (ly:grob? orig)
1284 (ly:spanner-broken-into orig) '() )))
1286 (if (and (>= (length siblings) 2)
1287 (eq? (car (last-pair siblings)) grob))
1288 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1291 \override Tie #'after-line-breaking-callback =
1298 When applying this trick, the new @code{after-line-breaking-callback}
1299 should also call the old @code{after-line-breaking-callback}, if there
1300 is one. For example, if using this with @code{Slur},
1301 @code{Slur::after_line_breaking} should also be called.
1306 This section details the ways that the font can be changed.
1309 * Selecting font sizes::
1315 @node Selecting font sizes
1316 @subsection Selecting font sizes
1319 The easiest method of setting the font size of any context, is by
1320 setting the @code{fontSize} property.
1322 @lilypond[quote,fragment,relative=1,verbatim]
1331 It does not change the size of variable symbols, such as beams or
1334 Internally, the @code{fontSize} context property will cause the
1335 @code{font-size} property to be set in all layout objects. The value
1336 of @code{font-size} is a number indicating the size relative to the
1337 standard size for the current staff height. Each step up is an
1338 increase of approximately 12% of the font size. Six steps is exactly a
1339 factor two. The Scheme function @code{magstep} converts a
1340 @code{font-size} number to a scaling factor.
1342 @lilypond[quote,fragment,relative=1,verbatim]
1344 \override NoteHead #'font-size = #-4
1346 \override NoteHead #'font-size = #3
1350 LilyPond has fonts in different design sizes. The music fonts for
1351 smaller sizes are chubbier, while the text fonts are relatively wider.
1352 Font size changes are achieved by scaling the design size that is
1353 closest to the desired size. The standard font size (for
1354 @code{font-size} equals 0), depends on the standard staff height. For
1355 a 20pt staff, a 10pt font is selected.
1357 The @code{font-size} mechanism does not work for fonts selected
1358 through @code{font-name}. These may be scaled with
1359 @code{font-magnification}. The @code{font-size} property can only be
1360 set on layout objects that use fonts; these are the ones supporting
1361 the @internalsref{font-interface} layout interface.
1365 The following commands set @code{fontSize} for the current voice:
1367 @cindex @code{\tiny}
1369 @cindex @code{\small}
1371 @cindex @code{\normalsize}
1376 @cindex magnification
1380 @node Font selection
1381 @subsection Font selection
1385 @cindex font selection
1386 @cindex font magnification
1387 @cindex @code{font-interface}
1389 By setting the object properties described below, you can select a
1390 font from the preconfigured font families. LilyPond has default
1391 support for the feta music fonts and @TeX{}'s Computer Modern text
1396 @item @code{font-encoding}
1397 is a symbol that sets layout of the glyphs. This should only be set to
1398 select different types of non-text fonts, eg.
1400 @code{fetaBraces} for piano staff braces, @code{fetaMusic} the
1401 standard music font, including ancient glyphs, @code{fetaDynamic} for
1402 dynamic signs and @code{fetaNumber} for the number font.
1404 @item @code{font-family}
1405 is a symbol indicating the general class of the typeface. Supported are
1406 @code{roman} (Computer Modern), @code{sans}, and @code{typewriter}.
1408 @item @code{font-shape}
1409 is a symbol indicating the shape of the font. There are typically
1410 several font shapes available for each font family. Choices are
1411 @code{italic}, @code{caps}, and @code{upright}.
1413 @item @code{font-series}
1414 is a symbol indicating the series of the font. There are typically
1415 several font series for each font family and shape. Choices are
1416 @code{medium} and @code{bold}.
1420 Fonts selected in the way sketched above come from a predefined style
1423 The font used for printing a object can be selected by setting
1424 @code{font-name}, e.g.,
1426 \override Staff.TimeSignature
1427 #'font-name = #"cmr17"
1431 Any font can be used, as long as it is available to @TeX{}. Possible
1432 fonts include foreign fonts or fonts that do not belong to the
1433 Computer Modern font family. The size of fonts selected in this way
1434 can be changed with the @code{font-magnification} property. For
1435 example, @code{2.0} blows up all letters by a factor 2 in both
1439 @cindex font magnification
1445 Init files: @file{ly/@/declarations@/-init@/.ly} contains hints how new
1446 fonts may be added to LilyPond.
1451 @section Text markup
1456 @cindex typeset text
1458 The internal mechanism to typeset texts is accessed with the keyword
1459 @code{\markup}. Within markup mode, you can enter texts similar to
1460 lyrics. They are simply entered, while commands use the backslash @code{\}.
1463 @lilypond[quote,verbatim,fragment,relative=1]
1464 c1^\markup { hello }
1465 c1_\markup { hi there }
1466 c1^\markup { hi \bold there, is \italic anyone home? }
1469 @cindex font switching
1471 The markup in the example demonstrates font switching commands. The
1472 command @code{\bold} and @code{\italic} apply to the first following
1473 word only; enclose a set of texts with braces to apply a command
1476 \markup @{ \bold @{ hi there @} @}
1480 For clarity, you can also do this for single arguments, e.g.,
1483 \markup @{ is \italic @{ anyone @} home @}
1486 @cindex font size, texts
1489 In markup mode you can compose expressions, similar to mathematical
1490 expressions, XML documents, and music expressions. You can stack
1491 expressions grouped vertically with the command @code{\column}.
1492 Similarly, @code{\center-align} aligns texts by their center lines:
1494 @lilypond[quote,verbatim,fragment,relative=1]
1495 c1^\markup { \column { a bbbb \line { c d } } }
1496 c1^\markup { \center-align { a bbbb c } }
1497 c1^\markup { \line { a b c } }
1501 Markups can be stored in variables and these variables
1502 may be attached to notes, like
1504 allegro = \markup @{ \bold \large @{ Allegro @} @}
1505 @{ a^\allegro b c d @}
1509 Some objects have alignment procedures of their own, which cancel out
1510 any effects of alignments applied to their markup arguments as a
1511 whole. For example, the @internalsref{RehearsalMark} is horizontally
1512 centered, so using @code{\mark \markup @{ \left-align .. @}} has no
1515 Similarly, for moving whole texts over notes with
1516 @code{\raise}, use the following trick:
1517 @lilypond[quote,verbatim]
1519 c'^\markup { \raise #0.5 not-raised }
1520 c'^\markup { "" \raise #0.5 raised }
1524 On the second note, the text @code{raised} is moved relative to the
1525 empty string @code{""} which is not visible. Alternatively, complete
1526 objects can be moved with layout properties such as @code{padding} and
1527 @code{extra-offset}.
1534 Init files: @file{scm/@/new@/-markup@/.scm}.
1539 Kerning or generation of ligatures is only done when the @TeX{}
1540 backend is used. In this case, LilyPond does not account for them so
1541 texts will be spaced slightly too wide.
1543 Syntax errors for markup mode are confusing.
1549 * Overview of text markup commands::
1550 * New dynamic marks::
1551 * Other text markup issues::
1555 @subsection Text encoding
1557 LilyPond uses the Pango library to format multi-lingual texts, and
1558 does not perform any input-encoding conversions. This means that any
1559 text, be it title, lyric text, or musical instruction containing
1560 non-ASCII characters, must be utf-8. Easiest to enter such texts is
1561 by using a Unicode-aware editor, and save using utf-8 encoding. Most
1562 popular modern editors have utf-8 support, for example, vim, Emacs,
1563 jEdit, and GEdit do.
1565 Depending on the fonts installed, the following fragment shows Hebrew
1566 and Cyrillic lyrics,
1572 @lilypondfile[fontload]{utf8.ly}
1575 The @TeX{} backend does not handle encoding specially at all. Strings
1576 in the input are put in the output as-is. Extents of text items in the
1577 @TeX{} backend, are determined by reading a file created via the
1578 @file{texstr} backend,
1581 lilypond -b texstr input/les-nereides.ly
1582 latex les-nereides.texstr
1585 The last command produces @file{les-nereides.textmetrics}, which is
1586 read when you execute
1589 lilypond -b tex input/les-nereides.ly
1592 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
1593 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
1594 interpreting non-ASCII strings.
1598 @inputfileref{input/regression,utf8.ly}
1602 @subsection Nested scores
1604 It is possible to nest music inside markups, by adding a @code{\score}
1605 block to a markup expression. Such a score must contain a @code{\layout}
1608 @lilypond[quote,verbatim,raggedright]
1612 \relative { c4 d e f }
1622 @node Overview of text markup commands
1623 @subsection Overview of text markup commands
1625 The following commands can all be used inside @code{\markup @{ @}}.
1627 @include markup-commands.tely
1630 @node New dynamic marks
1631 @subsection New dynamic marks
1633 It is possible to print new dynamic marks or text that should be aligned
1634 with dynamics. Use @code{make-dynamic-script} to create these marks.
1636 @cindex make-dynamic-script
1638 @lilypond[quote,verbatim,raggedright]
1639 sfzp = #(make-dynamic-script "sfzp")
1645 @cindex Dynamics, editorial
1646 @cindex Dynamics, parenthesis
1648 It is also possible to print dynamics in round parenthesis or square
1649 brackets. These are often used for adding editorial dynamics.
1651 @lilypond[quote,verbatim,raggedright]
1653 rndf = \markup{ \center-align {\line { \bold{\italic (}
1654 \dynamic f \bold{\italic )} }} }
1655 boxf = \markup{ \bracket { \dynamic f } }
1656 { c'1_\rndf c'1_\boxf }
1660 @node Other text markup issues
1661 @subsection Other text markup issues
1663 To use a normal font within a title, you must define it manually
1666 #(def-markup-command (normal-font layout props arg) (markup?)
1667 "Switch to normal text font"
1668 (interpret-markup layout (cons '((font-series . 'medium) (font-shape . 'upright)) props) arg))
1671 title = \markup@{ ABCD \normal-font ABCD @}