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 @ref{Notation manual}, under the sections for slurs and stems
840 The exact tuning possibilities for each type of layout object are
841 documented in the program reference of the respective
842 object. However, many layout objects share properties, which can be
843 used to apply generic tweaks. We mention a few of these:
846 @item The @code{extra-offset} property, which
847 @cindex @code{extra-offset}
848 has a pair of numbers as value, moves objects around in the printout.
849 The first number controls left-right movement; a positive number will
850 move the object to the right. The second number controls up-down
851 movement; a positive number will move it higher. The units of these
852 offsets are staff-spaces. The @code{extra-offset} property is a
853 low-level feature: the formatting engine is completely oblivious to
856 In the following example, the second fingering is moved a little to
857 the left, and 1.8 staff space downwards:
859 @cindex setting object properties
861 @lilypond[quote,fragment,relative=1,verbatim]
864 \once \override Fingering
865 #'extra-offset = #'(-0.3 . -1.8)
870 Setting the @code{transparent} property will cause an object to be printed
871 in `invisible ink': the object is not printed, but all its other
872 behavior is retained. The object still takes up space, it takes part in
873 collisions, and slurs, ties, and beams can be attached to it.
875 @cindex transparent objects
876 @cindex removing objects
877 @cindex hiding objects
878 @cindex invisible objects
879 The following example demonstrates how to connect different voices
880 using ties. Normally, ties only connect two notes in the same
881 voice. By introducing a tie in a different voice,
883 @lilypond[quote,fragment,relative=2]
892 and blanking the first up-stem in that voice, the tie appears to cross
895 @lilypond[quote,fragment,relative=2,verbatim]
897 \once \override Stem #'transparent = ##t
905 The @code{padding} property for objects with
906 @cindex @code{padding}
907 @code{side-position-interface} can be set to increase the distance between
908 symbols that are printed above or below notes. We only give an
909 example; a more elaborate explanation is in @ref{Constructing a
912 @lilypond[quote,fragment,relative=1,verbatim]
914 \override Script #'padding = #3
920 More specific overrides are also possible. The next section
921 discusses in depth how to figure out these statements for yourself.
924 @node Constructing a tweak
925 @subsection Constructing a tweak
927 The general procedure of changing output, that is, entering
931 \override Voice.Stem #'thickness = #3.0
935 means that we have to determine these bits of information:
938 @item the context: here @context{Voice}.
939 @item the layout object: here @code{Stem}.
940 @item the layout property: here @code{thickness}
941 @item a sensible value: here @code{3.0}
945 @cindex internal documentation
946 @cindex finding graphical objects
947 @cindex graphical object descriptions
949 @cindex @code{\override}
950 @cindex internal documentation
952 We demonstrate how to glean this information from the notation manual
953 and the program reference.
955 @node Navigating the program reference
956 @subsection Navigating the program reference
958 Suppose we want to move the fingering indication in the fragment
961 @lilypond[quote,fragment,relative=2,verbatim]
967 If you visit the documentation on fingering instructions (in
968 @ref{Fingering instructions}), you will notice that there is written:
973 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
979 This fragment points to two parts of the program reference: a page
980 on @code{FingerEvent} and one on @code{Fingering}.
982 The page on @code{FingerEvent} describes the properties of the music
983 expression for the input @code{-2}. The page contains many links
984 forward. For example, it says
987 Accepted by: @internalsref{Fingering_engraver},
991 That link brings us to the documentation for the Engraver, the
995 This engraver creates the following layout objects: @internalsref{Fingering}.
998 In other words, once the @code{FingerEvent}s are interpreted, the
999 @code{Fingering_engraver} plug-in will process them.
1000 The @code{Fingering_engraver} is also listed to create
1001 @internalsref{Fingering} objects,
1004 Lo and behold, that is also the
1005 second bit of information listed under @b{See also} in the Notation
1006 manual. By clicking around in the program reference, we can follow the
1007 flow of information within the program, either forward (like we did
1008 here), or backwards, following links like this:
1012 @item @internalsref{Fingering}:
1013 @internalsref{Fingering} objects are created by:
1014 @b{@internalsref{Fingering_engraver}}
1016 @item @internalsref{Fingering_engraver}:
1017 Music types accepted: @b{@internalsref{fingering-event}}
1019 @item @internalsref{fingering-event}:
1020 Music event type @code{fingering-event} is in Music expressions named
1021 @b{@internalsref{FingerEvent}}
1024 This path goes against the flow of information in the program: it
1025 starts from the output, and ends at the input event.
1027 The program reference can also be browsed like a normal document. It
1028 contains a chapter on
1030 @internalsref{Music definitions},
1033 @code{Music definitions}
1035 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1036 chapter lists all the definitions used, and all properties that may be
1040 @node Layout interfaces
1041 @subsection Layout interfaces
1043 @cindex interface, layout
1044 @cindex layout interface
1046 The HTML page that we found in the previous section, describes the
1047 layout object called @internalsref{Fingering}. Such an object is a
1048 symbol within the score. It has properties that store numbers (like
1049 thicknesses and directions), but also pointers to related objects. A
1050 layout object is also called @emph{grob},
1052 which is short for Graphical Object.
1055 The page for @code{Fingering} lists the definitions for the
1056 @code{Fingering} object. For example, the page says
1059 @code{padding} (dimension, in staff space):
1065 which means that the number will be kept at a distance of at least 0.6
1069 Each layout object may have several functions as a notational or
1070 typographical element. For example, the Fingering object
1071 has the following aspects
1075 Its size is independent of the horizontal spacing, unlike slurs or beams.
1078 It is a piece of text. Granted, it is usually a very short text.
1081 That piece of text is typeset with a font, unlike slurs or beams.
1084 Horizontally, the center of the symbol should be aligned to the
1085 center of the notehead.
1088 Vertically, the symbol is placed next to the note and the staff.
1091 The vertical position is also coordinated with other super- and subscript
1095 Each of these aspects is captured in so-called @emph{interface}s,
1096 which are listed on the @internalsref{Fingering} page at the bottom
1099 This object supports the following interfaces:
1100 @internalsref{item-interface},
1101 @internalsref{self-alignment-interface},
1102 @internalsref{side-position-interface}, @internalsref{text-interface},
1103 @internalsref{text-script-interface}, @internalsref{font-interface},
1104 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1107 Clicking any of the links will take you to the page of the respective
1108 object interface. Each interface has a number of properties. Some of
1109 them are not user-serviceable (``Internal properties''), but others
1112 We have been talking of @emph{the} @code{Fingering} object, but actually it
1113 does not amount to much. The initialization file
1114 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1118 . ((print-function . ,Text_interface::print)
1120 (staff-padding . 0.6)
1121 (self-alignment-X . 0)
1122 (self-alignment-Y . 0)
1123 (script-priority . 100)
1125 (meta . ((interfaces . (finger-interface font-interface
1126 text-script-interface text-interface
1127 side-position-interface
1128 self-alignment-interface
1129 item-interface))))))
1133 As you can see, the @code{Fingering} object is nothing more than a
1134 bunch of variable settings, and the webpage in the Program Reference
1135 is directly generated from this definition.
1137 @node Determining the grob property
1138 @subsection Determining the grob property
1141 Recall that we wanted to change the position of the @b{2} in
1143 @lilypond[quote,fragment,relative=2,verbatim]
1149 Since the @b{2} is vertically positioned next to its note, we have to
1150 meddle with the interface associated with this positioning. This is
1151 done using @code{side-position-interface}. The page for this interface
1155 @code{side-position-interface}
1157 Position a victim object (this one) next to other objects (the
1158 support). The property @code{direction} signifies where to put the
1159 victim object relative to the support (left or right, up or down?)
1164 below this description, the variable @code{padding} is described as
1169 (dimension, in staff space)
1171 Add this much extra space between objects that are next to each other.
1175 By increasing the value of @code{padding}, we can move away the
1176 fingering. The following command inserts 3 staff spaces of white
1177 between the note and the fingering:
1179 \once \override Voice.Fingering #'padding = #3
1182 Inserting this command before the Fingering object is created,
1183 i.e., before @code{c2}, yields the following result:
1185 @lilypond[quote,relative=2,fragment,verbatim]
1186 \once \override Voice.Fingering #'padding = #3
1193 In this case, the context for this tweak is @context{Voice}. This
1194 fact can also be deduced from the program reference, for the page for
1195 the @internalsref{Fingering_engraver} plug-in says
1198 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1201 @node Difficult tweaks
1202 @subsection Difficult tweaks
1204 There are two classes of difficult adjustments. First, when there are
1205 several of the same objects at one point, and you want to adjust only
1206 one. For example, if you want to change only one note head in a chord.
1208 In this case, the @code{\applyoutput} function must be used. The
1209 next example defines a Scheme function @code{set-position-font-size}
1210 that sets the @code{font-size} property, but only
1211 on objects that have @internalsref{note-head-interface} and are at the
1214 @lilypond[quote,verbatim]
1215 #(define ((set-position-font-size pos size) grob origin current)
1217 ((interfaces (ly:grob-property grob 'interfaces))
1218 (position (ly:grob-property grob 'staff-position)))
1220 ; is this a note head?
1221 (memq 'note-head-interface interfaces)
1223 ; is the Y coordinate right?
1227 (set! (ly:grob-property grob 'font-size) size))))
1231 \applyoutput #(set-position-font-size -2 4)
1237 A similar technique can be used for accidentals. In that case, the
1238 function should check for @code{accidental-interface}.
1240 Another difficult adjustment is the appearance of spanner objects,
1241 such as slur and tie. Initially, only one of these objects is created,
1242 and they can be adjusted with the normal mechanism. However, in some
1243 cases the spanners cross line breaks. If this happens, these objects
1244 are cloned. A separate object is created for every system that it is
1245 in. These are clones of the original object and inherit all
1246 properties, including @code{\override}s.
1248 In other words, an @code{\override} always affects all pieces of a
1249 broken spanner. To change only one part of a spanner at a line break,
1250 it is necessary to hook into the formatting process. The
1251 @code{after-line-breaking-callback} property contains the Scheme procedure
1252 that is called after the line breaks have been determined, and layout
1253 objects have been split over different systems.
1255 In the following example, we define a procedure
1256 @code{my-callback}. This procedure
1260 determines if we have been split across line breaks
1262 if yes, retrieves all the split objects
1264 checks if we are the last of the split objects
1266 if yes, it sets @code{extra-offset}.
1269 This procedure is installed into @internalsref{Tie}, so the last part
1270 of the broken tie is translated up.
1273 @lilypond[quote,verbatim,raggedright]
1274 #(define (my-callback grob)
1276 ; have we been split?
1277 (orig (ly:grob-original grob))
1279 ; if yes, get the split pieces (our siblings)
1280 (siblings (if (ly:grob? orig)
1281 (ly:spanner-broken-into orig) '() )))
1283 (if (and (>= (length siblings) 2)
1284 (eq? (car (last-pair siblings)) grob))
1285 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1288 \override Tie #'after-line-breaking-callback =
1295 When applying this trick, the new @code{after-line-breaking-callback}
1296 should also call the old @code{after-line-breaking-callback}, if there
1297 is one. For example, if using this with @code{Slur},
1298 @code{Slur::after_line_breaking} should also be called.
1303 This section details the ways that the font can be changed.
1306 * Selecting font sizes::
1312 @node Selecting font sizes
1313 @subsection Selecting font sizes
1316 The easiest method of setting the font size of any context, is by
1317 setting the @code{fontSize} property.
1319 @lilypond[quote,fragment,relative=1,verbatim]
1328 It does not change the size of variable symbols, such as beams or
1331 Internally, the @code{fontSize} context property will cause the
1332 @code{font-size} property to be set in all layout objects. The value
1333 of @code{font-size} is a number indicating the size relative to the
1334 standard size for the current staff height. Each step up is an
1335 increase of approximately 12% of the font size. Six steps is exactly a
1336 factor two. The Scheme function @code{magstep} converts a
1337 @code{font-size} number to a scaling factor.
1339 @lilypond[quote,fragment,relative=1,verbatim]
1341 \override NoteHead #'font-size = #-4
1343 \override NoteHead #'font-size = #3
1347 LilyPond has fonts in different design sizes. The music fonts for
1348 smaller sizes are chubbier, while the text fonts are relatively wider.
1349 Font size changes are achieved by scaling the design size that is
1350 closest to the desired size. The standard font size (for
1351 @code{font-size} equals 0), depends on the standard staff height. For
1352 a 20pt staff, a 10pt font is selected.
1354 The @code{font-size} mechanism does not work for fonts selected
1355 through @code{font-name}. These may be scaled with
1356 @code{font-magnification}. The @code{font-size} property can only be
1357 set on layout objects that use fonts; these are the ones supporting
1358 the @internalsref{font-interface} layout interface.
1362 The following commands set @code{fontSize} for the current voice:
1364 @cindex @code{\tiny}
1366 @cindex @code{\small}
1368 @cindex @code{\normalsize}
1373 @cindex magnification
1377 @node Font selection
1378 @subsection Font selection
1382 @cindex font selection
1383 @cindex font magnification
1384 @cindex @code{font-interface}
1386 By setting the object properties described below, you can select a
1387 font from the preconfigured font families. LilyPond has default
1388 support for the feta music fonts and @TeX{}'s Computer Modern text
1393 @item @code{font-encoding}
1394 is a symbol that sets layout of the glyphs. This should only be set to
1395 select different types of non-text fonts, eg.
1397 @code{fetaBraces} for piano staff braces, @code{fetaMusic} the
1398 standard music font, including ancient glyphs, @code{fetaDynamic} for
1399 dynamic signs and @code{fetaNumber} for the number font.
1401 @item @code{font-family}
1402 is a symbol indicating the general class of the typeface. Supported are
1403 @code{roman} (Computer Modern), @code{sans}, and @code{typewriter}.
1405 @item @code{font-shape}
1406 is a symbol indicating the shape of the font. There are typically
1407 several font shapes available for each font family. Choices are
1408 @code{italic}, @code{caps}, and @code{upright}.
1410 @item @code{font-series}
1411 is a symbol indicating the series of the font. There are typically
1412 several font series for each font family and shape. Choices are
1413 @code{medium} and @code{bold}.
1417 Fonts selected in the way sketched above come from a predefined style
1420 The font used for printing a object can be selected by setting
1421 @code{font-name}, e.g.,
1423 \override Staff.TimeSignature
1424 #'font-name = #"cmr17"
1428 Any font can be used, as long as it is available to @TeX{}. Possible
1429 fonts include foreign fonts or fonts that do not belong to the
1430 Computer Modern font family. The size of fonts selected in this way
1431 can be changed with the @code{font-magnification} property. For
1432 example, @code{2.0} blows up all letters by a factor 2 in both
1436 @cindex font magnification
1442 Init files: @file{ly/@/declarations@/-init@/.ly} contains hints how new
1443 fonts may be added to LilyPond.
1448 @section Text markup
1453 @cindex typeset text
1455 The internal mechanism to typeset texts is accessed with the keyword
1456 @code{\markup}. Within markup mode, you can enter texts similar to
1457 lyrics. They are simply entered, while commands use the backslash @code{\}.
1460 @lilypond[quote,verbatim,fragment,relative=1]
1461 c1^\markup { hello }
1462 c1_\markup { hi there }
1463 c1^\markup { hi \bold there, is \italic anyone home? }
1466 @cindex font switching
1468 The markup in the example demonstrates font switching commands. The
1469 command @code{\bold} and @code{\italic} apply to the first following
1470 word only; enclose a set of texts with braces to apply a command
1473 \markup @{ \bold @{ hi there @} @}
1477 For clarity, you can also do this for single arguments, e.g.,
1480 \markup @{ is \italic @{ anyone @} home @}
1483 @cindex font size, texts
1486 In markup mode you can compose expressions, similar to mathematical
1487 expressions, XML documents, and music expressions. You can stack
1488 expressions grouped vertically with the command @code{\column}.
1489 Similarly, @code{\center-align} aligns texts by their center lines:
1491 @lilypond[quote,verbatim,fragment,relative=1]
1492 c1^\markup { \column { a bbbb \line { c d } } }
1493 c1^\markup { \center-align { a bbbb c } }
1494 c1^\markup { \line { a b c } }
1498 Markups can be stored in variables and these variables
1499 may be attached to notes, like
1501 allegro = \markup @{ \bold \large @{ Allegro @} @}
1502 @{ a^\allegro b c d @}
1506 Some objects have alignment procedures of their own, which cancel out
1507 any effects of alignments applied to their markup arguments as a
1508 whole. For example, the @internalsref{RehearsalMark} is horizontally
1509 centered, so using @code{\mark \markup @{ \left-align .. @}} has no
1512 Similarly, for moving whole texts over notes with
1513 @code{\raise}, use the following trick:
1514 @lilypond[quote,verbatim]
1516 c'^\markup { \raise #0.5 not-raised }
1517 c'^\markup { "" \raise #0.5 raised }
1521 On the second note, the text @code{raised} is moved relative to the
1522 empty string @code{""} which is not visible. Alternatively, complete
1523 objects can be moved with layout properties such as @code{padding} and
1524 @code{extra-offset}.
1531 Init files: @file{scm/@/new@/-markup@/.scm}.
1536 Kerning or generation of ligatures is only done when the @TeX{}
1537 backend is used. In this case, LilyPond does not account for them so
1538 texts will be spaced slightly too wide.
1540 Syntax errors for markup mode are confusing.
1546 * Overview of text markup commands::
1547 * New dynamic marks::
1551 @subsection Text encoding
1553 LilyPond uses the Pango library to format multi-lingual texts, and
1554 does not perform any input-encoding conversions. This means that any
1555 text, be it title, lyric text, or musical instruction containing
1556 non-ASCII characters, must be utf-8. Easiest to enter such texts is
1557 by using a Unicode-aware editor, and save using utf-8 encoding. Most
1558 popular modern editors have utf-8 support, for example, vim, Emacs,
1559 jEdit, and GEdit do.
1561 Depending on the fonts installed, the following fragment shows Hebrew
1562 and Cyrillic lyrics,
1568 @lilypondfile[fontload]{utf8.ly}
1571 The @TeX{} backend does not handle encoding specially at all. Strings
1572 in the input are put in the output as-is. Extents of text items in the
1573 @TeX{} backend, are determined by reading a file created via the
1574 @file{texstr} backend,
1577 lilypond -b texstr input/les-nereides.ly
1578 latex les-nereides.texstr
1581 The last command produces @file{les-nereides.textmetrics}, which is
1582 read when you execute
1585 lilypond -b tex input/les-nereides.ly
1588 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
1589 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
1590 interpreting non-ASCII strings.
1594 @inputfileref{input/regression,utf8.ly}
1598 @subsection Nested scores
1600 It is possible to nest music inside markups, by adding a @code{\score}
1601 block to a markup expression. Such a score must contain a @code{\layout}
1604 @lilypond[quote,verbatim,raggedright]
1608 \relative { c4 d e f }
1618 @node Overview of text markup commands
1619 @subsection Overview of text markup commands
1621 The following commands can all be used inside @code{\markup @{ @}}.
1623 @include markup-commands.tely
1626 @node New dynamic marks
1627 @subsection New dynamic marks
1629 It is possible to print new dynamic marks or text that should be aligned
1630 with dynamics. Use @code{make-dynamic-script} to create these marks.
1632 @cindex make-dynamic-script
1634 @lilypond[quote,verbatim,raggedright]
1635 sfzp = #(make-dynamic-script "sfzp")
1641 @cindex Dynamics, editorial
1642 @cindex Dynamics, parenthesis
1644 It is also possible to print dynamics in round parenthesis or square
1645 brackets. These are often used for adding editorial dynamics.
1647 @lilypond[quote,verbatim,raggedright]
1649 rndf = \markup{ \center-align {\line { \bold{\italic (}
1650 \dynamic f \bold{\italic )} }} }
1651 boxf = \markup{ \bracket { \dynamic f } }
1652 { c'1_\rndf c'1_\boxf }