1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
12 @node Changing defaults
13 @chapter Changing defaults
16 The purpose of LilyPond's design is to provide the finest output
17 quality as a default. Nevertheless, it may happen that you need to
18 change this default layout. The layout is controlled through a large
19 number of proverbial @q{knobs and switches.} This chapter does not
20 list each and every knob. Rather, it outlines what groups of controls
21 are available and explains how to lookup which knob to use for a
25 @cindex Internals Reference
27 The controls available for tuning are described in a separate
30 Internals Reference manual.
33 @ref{Top,Internals Reference,,lilypond-internals}.
36 lists all different variables, functions and options available in
37 LilyPond. It is written as a HTML document, which is available
38 @c leave the @uref as one long line.
39 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
40 but is also included with the LilyPond documentation package.
42 There are four areas where the default settings may be changed:
46 Automatic notation: changing the automatic creation of notation
47 elements. For example, changing the beaming rules.
50 Output: changing the appearance of individual
51 objects. For example, changing stem directions or the location of
55 Context: changing aspects of the translation from music events to
56 notation. For example, giving each staff a separate time signature.
59 Page layout: changing the appearance of the spacing, line
60 breaks, and page dimensions. These modifications are discussed
61 in @ref{Non-musical notation}, and @ref{Spacing issues}.
64 Internally, LilyPond uses Scheme (a LISP dialect) to provide
65 infrastructure. Overriding layout decisions in effect accesses the
66 program internals, which requires Scheme input. Scheme elements are
67 introduced in a @code{.ly} file with the hash mark
68 @code{#}.@footnote{@rlearning{Scheme tutorial}, contains a short tutorial
69 on entering numbers, lists, strings, and symbols in Scheme.}
73 * Interpretation contexts::
74 * The \override command::
75 * Discussion of specific tweaks::
79 @node Interpretation contexts
80 @section Interpretation contexts
82 This section describes what contexts are, and how to modify them.
85 * Contexts explained::
87 * Changing context properties on the fly::
88 * Modifying context plug-ins::
89 * Layout tunings within contexts::
90 * Changing context default settings::
91 * Defining new contexts::
93 * Vertical grouping of grobs::
97 @node Contexts explained
98 @subsection Contexts explained
100 When music is printed, a lot of notational elements must be added to the
101 output. For example, compare the input and output of the following example:
103 @lilypond[quote,verbatim,relative=2,fragment]
107 The input is rather sparse, but in the output, bar lines, accidentals,
108 clef, and time signature are added. LilyPond @emph{interprets} the
109 input. During this step, the musical information is inspected in time
110 order, similar to reading a score from left to right. While reading
111 the input, the program remembers where measure boundaries are, and which
112 pitches require explicit accidentals. This information can be presented on
113 several levels. For example, the effect of an accidental is limited
114 to a single staff, while a bar line must be synchronized across the
117 Within LilyPond, these rules and bits of information are grouped in
118 @emph{Contexts}. Some examples of contexts are @code{Voice},
119 @code{Staff}, and @code{Score}. They are hierarchical, for
120 example: a @code{Staff} can contain many @code{Voice}s, and a
121 @code{Score} can contain many @code{Staff} contexts.
124 @sourceimage{context-example,5cm,,}
127 Each context has the responsibility for enforcing some notation rules,
128 creating some notation objects and maintaining the associated
129 properties. For example, the @code{Voice} context may introduce an
130 accidental and then the @code{Staff} context maintains the rule to
131 show or suppress the accidental for the remainder of the measure. The
132 synchronization of bar lines is handled at @code{Score} context.
134 However, in some music we may not want the bar lines to be
135 synchronized -- consider a polymetric score in 4/4 and 3/4 time. In
136 such cases, we must modify the default settings of the @code{Score}
137 and @code{Staff} contexts.
139 For very simple scores, contexts are created implicitly, and you need
140 not be aware of them. For larger pieces, such as anything with more
141 than one staff, they must be
142 created explicitly to make sure that you get as many staves as you
143 need, and that they are in the correct order. For typesetting pieces
144 with specialized notation, it can be useful to modify existing or
145 to define new contexts.
148 A complete description of all available contexts is in the program
151 @internalsref{Contexts}.
154 Translation @expansion{} Context.
157 @c [TODO: describe propagation]
160 @node Creating contexts
161 @subsection Creating contexts
163 For scores with only one voice and one staff, contexts are
164 created automatically. For more complex scores, it is necessary to
165 create them by hand. There are three commands that do this.
170 The easiest command is @code{\new}, and it also the quickest to type.
171 It is prepended to a music expression, for example
175 @cindex Context, creating
178 \new @var{type} @var{music expression}
182 where @var{type} is a context name (like @code{Staff} or
183 @code{Voice}). This command creates a new context, and starts
184 interpreting the @var{music expression} with that.
186 A practical application of @code{\new} is a score with many
187 staves. Each part that should be on its own staff, is preceded with
190 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
197 The @code{\new} command may also give a name to the context,
200 \new @var{type} = @var{id} @var{music}
202 However, this user specified name is only used if there is no other
203 context already earlier with the same name.
209 Like @code{\new}, the @code{\context} command also directs a music
210 expression to a context object, but gives the context an explicit name. The
214 \context @var{type} = @var{id} @var{music}
217 This form will search for an existing context of type @var{type}
218 called @var{id}. If that context does not exist yet, a new
219 context with the specified name is created. This is useful if
220 the context is referred to later on. For example, when
221 setting lyrics the melody is in a named context
224 \context Voice = "@b{tenor}" @var{music}
228 so the texts can be properly aligned to its notes,
231 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
236 Another possible use of named contexts is funneling two different
237 music expressions into one context. In the following example,
238 articulations and notes are entered separately,
242 arts = @{ s4-. s4-> @}
245 They are combined by sending both to the same @code{Voice} context,
249 \new Staff \context Voice = "A" \music
250 \context Voice = "A" \arts
253 @lilypond[quote,ragged-right]
257 \new Staff \context Voice = "A" \music
258 \context Voice = "A" \arts
262 With this mechanism, it is possible to define an Urtext (original
263 edition), with the option to put several distinct articulations on the
266 @cindex creating contexts
269 The third command for creating contexts is
271 \context @var{type} @var{music}
276 This is similar to @code{\context} with @code{= @var{id}}, but matches
277 any context of type @var{type}, regardless of its given name.
279 This variant is used with music expressions that can be interpreted at
280 several levels. For example, the @code{\applyOutput} command (see
281 @ref{Running a function on all layout objects}). Without an explicit
282 @code{\context}, it is usually applied to @code{Voice}
285 \applyOutput #'@var{context} #@var{function} % apply to Voice
288 To have it interpreted at the @code{Score} or @code{Staff} level use
292 \applyOutput #'Score #@var{function}
293 \applyOutput #'Staff #@var{function}
299 @node Changing context properties on the fly
300 @subsection Changing context properties on the fly
304 @cindex changing properties
306 Each context can have different @emph{properties}, variables contained
307 in that context. They can be changed during the interpretation step.
308 This is achieved by inserting the @code{\set} command in the music,
311 \set @var{context}.@var{prop} = #@var{value}
315 @lilypond[quote,verbatim,relative=2,fragment]
317 \set Score.skipBars = ##t
321 This command skips measures that have no notes. The result is that
322 multi-rests are condensed. The value assigned is a Scheme object. In
323 this case, it is @code{#t}, the boolean True value.
325 If the @var{context} argument is left out, then the current bottom-most
326 context (typically @code{ChordNames}, @code{Voice}, or
327 @code{Lyrics}) is used. In this example,
329 @lilypond[quote,verbatim,relative=2,fragment]
331 \set autoBeaming = ##f
336 the @var{context} argument to @code{\set} is left out, so automatic
337 beaming is switched off in the current @internalsref{Voice}. Note that
338 the bottom-most context does not always contain the property that you
339 wish to change -- for example, attempting to set the @code{skipBars}
340 property (of the bottom-most context, in this case @code{Voice}) will
343 @lilypond[quote,verbatim,relative=2,fragment]
349 Contexts are hierarchical, so if a bigger context was specified, for
350 example @code{Staff}, then the change would also apply to all
351 @code{Voice}s in the current stave. The change is applied
352 @q{on-the-fly}, during the music, so that the setting only affects the
353 second group of eighth notes.
357 There is also an @code{\unset} command,
359 \unset @var{context}.@var{prop}
363 which removes the definition of @var{prop}. This command removes
364 the definition only if it is set in @var{context}, so
367 \set Staff.autoBeaming = ##f
371 introduces a property setting at @code{Staff} level. The setting also
372 applies to the current @code{Voice}. However,
375 \unset Voice.autoBeaming
379 does not have any effect. To cancel this setting, the @code{\unset}
380 must be specified on the same level as the original @code{\set}. In
381 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
384 \unset Staff.autoBeaming
387 Like @code{\set}, the @var{context} argument does not have to be
388 specified for a bottom context, so the two statements
391 \set Voice.autoBeaming = ##t
392 \set autoBeaming = ##t
400 Settings that should only apply to a single time-step can be entered
401 with @code{\once}, for example in
403 @lilypond[quote,verbatim,relative=2,fragment]
405 \once \set fontSize = #4.7
410 the property @code{fontSize} is unset automatically after the second
413 A full description of all available context properties is in the
414 program reference, see
416 @internalsref{Tunable context properties}.
419 Translation @expansion{} Tunable context properties.
423 @node Modifying context plug-ins
424 @subsection Modifying context plug-ins
426 Notation contexts (like @code{Score} and @code{Staff}) not only
428 they also contain plug-ins called @q{engravers} that create notation
429 elements. For example, the @code{Voice} context contains a
430 @code{Note_head_engraver} and the @code{Staff} context contains a
431 @code{Key_signature_engraver}.
433 For a full a description of each plug-in, see
435 @internalsref{Engravers and Performers}.
438 Internals Reference @expansion{} Translation @expansion{} Engravers.
440 Every context described in
442 @internalsref{Contexts}
445 Internals Reference @expansion{} Translation @expansion{} Context.
447 lists the engravers used for that context.
450 It can be useful to shuffle around these plug-ins. This is done by
451 starting a new context with @code{\new} or @code{\context}, and
457 \new @var{context} \with @{
470 where the @dots{} should be the name of an engraver. Here is a simple
471 example which removes @code{Time_signature_engraver} and
472 @code{Clef_engraver} from a @code{Staff} context,
474 @lilypond[quote,relative=1,verbatim,fragment]
480 \remove "Time_signature_engraver"
481 \remove "Clef_engraver"
488 In the second staff there are no time signature or clef symbols. This
489 is a rather crude method of making objects disappear since it will affect
490 the entire staff. This method also influences the spacing, which may or
491 may not be desirable. More sophisticated methods of blanking objects
492 are shown in @rlearning{Visibility and color of objects}.
494 The next example shows a practical application. Bar lines and time
495 signatures are normally synchronized across the score. This is done
496 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
497 This plug-in keeps an administration of time signature, location
498 within the measure, etc. By moving these engraver from @code{Score} to
499 @code{Staff} context, we can have a score where each staff has its own
502 @cindex polymetric scores
503 @cindex Time signatures, multiple
505 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
507 \remove "Timing_translator"
508 \remove "Default_bar_line_engraver"
511 \consists "Timing_translator"
512 \consists "Default_bar_line_engraver"
518 \consists "Timing_translator"
519 \consists "Default_bar_line_engraver"
528 @node Layout tunings within contexts
529 @subsection Layout tunings within contexts
531 Each context is responsible for creating certain types of graphical
532 objects. The settings used for printing these objects are also stored by
533 context. By changing these settings, the appearance of objects can be
536 The syntax for this is
539 \override @var{context}.@var{name} #'@var{property} = #@var{value}
542 Here @var{name} is the name of a graphical object, like @code{Stem} or
543 @code{NoteHead}, and @var{property} is an internal variable of the
544 formatting system (@q{grob property} or @q{layout property}). The latter is a
545 symbol, so it must be quoted. The subsection @ref{Constructing a
546 tweak}, explains what to fill in for @var{name}, @var{property}, and
547 @var{value}. Here we only discuss the functionality of this command.
552 \override Staff.Stem #'thickness = #4.0
556 makes stems thicker (the default is 1.3, with staff line thickness as a
557 unit). Since the command specifies @code{Staff} as context, it only
558 applies to the current staff. Other staves will keep their normal
559 appearance. Here we see the command in action:
561 @lilypond[quote,verbatim,relative=2,fragment]
563 \override Staff.Stem #'thickness = #4.0
569 The @code{\override} command changes the definition of the @code{Stem}
570 within the current @code{Staff}. After the command is interpreted
571 all stems are thickened.
573 Analogous to @code{\set}, the @var{context} argument may be left out,
574 causing the default context @code{Voice} to be used. Adding
575 @code{\once} applies the change during one timestep only.
577 @lilypond[quote,fragment,verbatim,relative=2]
579 \once \override Stem #'thickness = #4.0
584 The @code{\override} must be done before the object is
585 started. Therefore, when altering @emph{Spanner} objects such as slurs
586 or beams, the @code{\override} command must be executed at the moment
587 when the object is created. In this example,
589 @lilypond[quote,fragment,verbatim,relative=2]
590 \override Slur #'thickness = #3.0
592 \override Beam #'thickness = #0.6
597 the slur is fatter but the beam is not. This is because the command for
598 @code{Beam} comes after the Beam is started, so it has no effect.
600 Analogous to @code{\unset}, the @code{\revert} command for a context
601 undoes an @code{\override} command; like with @code{\unset}, it only
602 affects settings that were made in the same context. In other words, the
603 @code{\revert} in the next example does not do anything.
606 \override Voice.Stem #'thickness = #4.0
607 \revert Staff.Stem #'thickness
610 Some tweakable options are called @q{subproperties} and reside inside
611 properties. To tweak those, use commands of the form
613 @c leave this as a long long
615 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
622 \override Stem #'details #'beamed-lengths = #'(4 4 3)
628 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
629 @internalsref{PropertySet}, @internalsref{Backend}, and
630 @internalsref{All layout objects}.
635 The back-end is not very strict in type-checking object properties.
636 Cyclic references in Scheme values for properties can cause hangs
640 @node Changing context default settings
641 @subsection Changing context default settings
643 The adjustments of the previous subsections (@ref{Changing context
644 properties on the fly}, @ref{Modifying context plug-ins}, and
645 @ref{Layout tunings within contexts}) can also be entered separately
646 from the music in the @code{\layout} block,
655 \override Stem #'thickness = #4.0
656 \remove "Time_signature_engraver"
661 The @code{\Staff} command brings in the existing definition of the
662 staff context so that it can be modified.
667 \override Stem #'thickness = #4.0
668 \remove "Time_signature_engraver"
672 affect all staves in the score. Other contexts can be modified
675 The @code{\set} keyword is optional within the @code{\layout} block, so
691 It is not possible to collect context changes in a variable and apply
692 them to a @code{\context} definition by referring to that variable.
694 The @code{\RemoveEmptyStaffContext} will overwrite your current
695 @code{\Staff} settings. If you wish to change the defaults for a
696 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
697 after calling @code{\RemoveEmptyStaffContext}, ie
702 \RemoveEmptyStaffContext
704 \override Stem #'thickness = #4.0
710 @node Defining new contexts
711 @subsection Defining new contexts
713 Specific contexts, like @code{Staff} and @code{Voice}, are made of
714 simple building blocks. It is possible to create new types of
715 contexts with different combinations of engraver plug-ins.
717 The next example shows how to build a different type of
718 @code{Voice} context from scratch. It will be similar to
719 @code{Voice}, but only prints centered slash note heads. It can be used
720 to indicate improvisation in jazz pieces,
722 @lilypond[quote,ragged-right]
725 \type "Engraver_group"
726 \consists "Note_heads_engraver"
727 \consists "Text_engraver"
728 \consists Pitch_squash_engraver
729 squashedPosition = #0
730 \override NoteHead #'style = #'slash
731 \override Stem #'transparent = ##t
735 \accepts "ImproVoice"
739 a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
740 c4 c^"undress" c_"while playing :)" c }
746 These settings are defined within a @code{\context} block inside a
747 @code{\layout} block,
757 In the following discussion, the example input shown should go in place
758 of the @dots{} in the previous fragment.
760 First it is necessary to define a name for the new context:
766 Since it is similar to the @code{Voice}, we want commands that work
767 on (existing) @code{Voice}s to remain working. This is achieved by
768 giving the new context an alias @code{Voice},
774 The context will print notes and instructive texts, so we need to add
775 the engravers which provide this functionality,
778 \consists Note_heads_engraver
779 \consists Text_engraver
782 but we only need this on the center line,
785 \consists Pitch_squash_engraver
786 squashedPosition = #0
789 The @internalsref{Pitch_squash_engraver} modifies note heads (created
790 by @internalsref{Note_heads_engraver}) and sets their vertical
791 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
794 The notes look like a slash, and have no stem,
797 \override NoteHead #'style = #'slash
798 \override Stem #'transparent = ##t
801 All these plug-ins have to cooperate, and this is achieved with a
802 special plug-in, which must be marked with the keyword @code{\type}.
803 This should always be @internalsref{Engraver_group},
806 \type "Engraver_group"
814 \type "Engraver_group"
815 \consists "Note_heads_engraver"
816 \consists "Text_engraver"
817 \consists Pitch_squash_engraver
818 squashedPosition = #0
819 \override NoteHead #'style = #'slash
820 \override Stem #'transparent = ##t
826 Contexts form hierarchies. We want to hang the @code{ImproVoice}
827 under @code{Staff}, just like normal @code{Voice}s. Therefore, we
828 modify the @code{Staff} definition with the @code{\accepts}
839 The opposite of @code{\accepts} is @code{\denies},
840 which is sometimes needed when reusing existing context definitions.
842 Putting both into a @code{\layout} block, like
852 \accepts "ImproVoice"
857 Then the output at the start of this subsection can be entered as
865 c c_"while playing :)"
872 @node Aligning contexts
873 @subsection Aligning contexts
875 New contexts may be aligned above or below existing contexts. This
876 could be useful in setting up a vocal staff (@rlearning{Vocal ensembles}) and
879 FIXME: this section doesn't work in pdf. (?)
882 @findex alignAboveContext
883 @findex alignBelowContext
885 @lilypond[quote,ragged-right]
888 \relative c' \new Staff = "main" {
891 \new Staff \with {alignAboveContext=main} \ossia
899 @node Vertical grouping of grobs
900 @subsection Vertical grouping of grobs
902 The VerticalAlignment and VerticalAxisGroup grobs work together.
903 VerticalAxisGroup groups together different grobs like Staff, Lyrics,
904 etc. VerticalAlignment then vertically aligns the different grobs
905 grouped together by VerticalAxisGroup. There is usually only one
906 VerticalAlignment per score but every Staff, Lyrics, etc. has its own
910 @node The \override command
911 @section The @code{\override} command
913 In the previous section, we have already touched on a command that
914 changes layout details: the @code{\override} command. In this section,
915 we will look in more detail at how to use the command in practice. The
916 general syntax of this command is:
919 \override @var{context}.@var{layout_object} #'@var{layout_property} = #@var{value}
922 This will set the @var{layout_property} of the specified @var{layout_object},
923 which is a member of the @var{context}, to the @var{value}.
926 * Constructing a tweak::
927 * Navigating the program reference::
928 * Layout interfaces::
929 * Determining the grob property::
930 * Objects connected to the input::
931 * Using Scheme code instead of \tweak::
932 * \set versus \override::
938 @node Constructing a tweak
939 @subsection Constructing a tweak
941 Commands which change output generally look like
944 \override Voice.Stem #'thickness = #3.0
948 To construct this tweak we must determine these bits of information:
951 @item the context: here @code{Voice}.
952 @item the layout object: here @code{Stem}.
953 @item the layout property: here @code{thickness}.
954 @item a sensible value: here @code{3.0}.
957 Some tweakable options are called @q{subproperties} and reside inside
958 properties. To tweak those, use commands in the form
961 \override Stem #'details #'beamed-lengths = #'(4 4 3)
964 @cindex internal documentation
965 @cindex finding graphical objects
966 @cindex graphical object descriptions
969 @cindex internal documentation
971 For many properties, regardless of the data type of the property, setting the
972 property to false ( @code{##f} ) will result in turning it off, causing
973 LilyPond to ignore that property entirely. This is particularly useful for
974 turning off grob properties which may otherwise be causing problems.
976 We demonstrate how to glean this information from the notation manual
977 and the program reference.
982 @node Navigating the program reference
983 @subsection Navigating the program reference
985 Suppose we want to move the fingering indication in the fragment
988 @lilypond[quote,fragment,relative=2,verbatim]
994 If you visit the documentation on fingering instructions (in
995 @ref{Fingering instructions}), you will notice:
1000 Internals Reference: @internalsref{Fingering}.
1005 @c outdated info; probably will delete.
1007 This fragment points to two parts of the program reference: a page
1008 on @code{FingerEvent} and one on @code{Fingering}.
1010 The page on @code{FingerEvent} describes the properties of the music
1011 expression for the input @code{-2}. The page contains many links
1012 forward. For example, it says
1015 Accepted by: @internalsref{Fingering_engraver},
1019 That link brings us to the documentation for the Engraver, the
1023 This engraver creates the following layout objects: @internalsref{Fingering}.
1026 In other words, once the @code{FingerEvent}s are interpreted, the
1027 @code{Fingering_engraver} plug-in will process them.
1031 @c I can't figure out what this is supposed to mean. -gp
1033 The @code{Fingering_engraver} is also listed to create
1034 @internalsref{Fingering} objects,
1036 @c old info? it doesn't make any sense to me with our current docs.
1038 second bit of information listed under @b{See also} in the Notation
1043 The programmer's reference is available as an HTML document. It is
1044 highly recommended that you read it in HTML form, either online or
1045 by downloading the HTML documentation. This section will be much more
1046 difficult to understand if you are using the
1050 Follow the link to @internalsref{Fingering}. At the top of the
1054 Fingering objects are created by: @internalsref{Fingering_engraver} and
1055 @internalsref{New_fingering_engraver}.
1058 By following related links inside the program reference, we can follow the
1059 flow of information within the program:
1063 @item @internalsref{Fingering}:
1064 @internalsref{Fingering} objects are created by:
1065 @internalsref{Fingering_engraver}
1067 @item @internalsref{Fingering_engraver}:
1068 Music types accepted: @internalsref{fingering-event}
1070 @item @internalsref{fingering-event}:
1071 Music event type @code{fingering-event} is in Music expressions named
1072 @internalsref{FingerEvent}
1075 This path goes against the flow of information in the program: it
1076 starts from the output, and ends at the input event. You could
1077 also start at an input event, and read with the flow of
1078 information, eventually ending up at the output object(s).
1080 The program reference can also be browsed like a normal document. It
1081 contains chapters on
1083 @internalsref{Music definitions},
1086 @code{Music definitions}
1088 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1089 chapter lists all the definitions used and all properties that may be
1093 @node Layout interfaces
1094 @subsection Layout interfaces
1096 @cindex interface, layout
1097 @cindex layout interface
1100 The HTML page that we found in the previous section describes the
1101 layout object called @internalsref{Fingering}. Such an object is a
1102 symbol within the score. It has properties that store numbers (like
1103 thicknesses and directions), but also pointers to related objects. A
1104 layout object is also called a @emph{Grob}, which is short for Graphical
1105 Object. For more details about Grobs, see @internalsref{grob-interface}.
1107 The page for @code{Fingering} lists the definitions for the
1108 @code{Fingering} object. For example, the page says
1111 @code{padding} (dimension, in staff space):
1117 which means that the number will be kept at a distance of at least 0.5
1121 Each layout object may have several functions as a notational or
1122 typographical element. For example, the Fingering object
1123 has the following aspects
1127 Its size is independent of the horizontal spacing, unlike slurs or beams.
1130 It is a piece of text. Granted, it is usually a very short text.
1133 That piece of text is typeset with a font, unlike slurs or beams.
1136 Horizontally, the center of the symbol should be aligned to the
1137 center of the note head.
1140 Vertically, the symbol is placed next to the note and the staff.
1143 The vertical position is also coordinated with other superscript
1144 and subscript symbols.
1147 Each of these aspects is captured in so-called @emph{interface}s,
1148 which are listed on the @internalsref{Fingering} page at the bottom
1151 This object supports the following interfaces:
1152 @internalsref{item-interface},
1153 @internalsref{self-alignment-interface},
1154 @internalsref{side-position-interface}, @internalsref{text-interface},
1155 @internalsref{text-script-interface}, @internalsref{font-interface},
1156 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1159 Clicking any of the links will take you to the page of the respective
1160 object interface. Each interface has a number of properties. Some of
1161 them are not user-serviceable (@q{Internal properties}), but others
1164 We have been talking of @emph{the} @code{Fingering} object, but actually it
1165 does not amount to much. The initialization file (see
1166 @rlearning{Other sources of information})
1167 @file{scm/@/define@/-grobs@/.scm} shows the soul of the @q{object},
1172 (avoid-slur . around)
1173 (slur-padding . 0.2)
1174 (staff-padding . 0.5)
1175 (self-alignment-X . 0)
1176 (self-alignment-Y . 0)
1177 (script-priority . 100)
1178 (stencil . ,ly:text-interface::print)
1179 (direction . ,ly:script-interface::calc-direction)
1180 (font-encoding . fetaNumber)
1181 (font-size . -5) ; don't overlap when next to heads.
1182 (meta . ((class . Item)
1183 (interfaces . (finger-interface
1185 text-script-interface
1187 side-position-interface
1188 self-alignment-interface
1189 item-interface))))))
1193 As you can see, the @code{Fingering} object is nothing more than a
1194 bunch of variable settings, and the webpage in the Internals Reference
1195 is directly generated from this definition.
1198 @node Determining the grob property
1199 @subsection Determining the grob property
1201 Recall that we wanted to change the position of the @b{2} in
1203 @lilypond[quote,fragment,relative=2,verbatim]
1209 Since the @b{2} is vertically positioned next to its note, we have to
1210 meddle with the interface associated with this positioning. This is
1211 done using @code{side-position-interface}. The page for this interface
1215 @code{side-position-interface}
1217 Position a victim object (this one) next to other objects (the
1218 support). The property @code{direction} signifies where to put the
1219 victim object relative to the support (left or right, up or down?)
1224 Below this description, the variable @code{padding} is described as
1229 (dimension, in staff space)
1231 Add this much extra space between objects that are next to each other.
1235 By increasing the value of @code{padding}, we can move the
1236 fingering away from the note head. The following command inserts
1237 3 staff spaces of white
1238 between the note and the fingering:
1240 \once \override Voice.Fingering #'padding = #3
1243 Inserting this command before the Fingering object is created,
1244 i.e., before @code{c2}, yields the following result:
1246 @lilypond[quote,relative=2,fragment,verbatim]
1247 \once \override Voice.Fingering #'padding = #3
1254 In this case, the context for this tweak is @code{Voice}. This
1255 fact can also be deduced from the program reference, for the page for
1256 the @internalsref{Fingering_engraver} plug-in says
1259 Fingering_engraver is part of contexts: @dots{} @internalsref{Voice}
1263 @node Objects connected to the input
1264 @subsection Objects connected to the input
1268 In some cases, it is possible to take a short-cut for tuning graphical
1269 objects. For objects that result directly from a piece of the input,
1270 you can use the @code{\tweak} function, for example
1272 @lilypond[relative=2,fragment,verbatim,ragged-right]
1275 \tweak #'color #red d
1277 \tweak #'duration-log #1 a
1278 >4-\tweak #'padding #10 -.
1281 As you can see, properties are set in the objects directly,
1282 without mentioning the grob name or context where this should be
1285 This technique only works for objects that are directly connected to
1286 an @internalsref{Event} from the input, for example
1289 @item note heads, caused by chord-pitch (i.e., notes inside a chord)
1290 @item articulation signs, caused by articulation instructions
1293 It notably does not work for stems and accidentals (these are caused
1294 by note heads, not by music events) or clefs (these are not caused by
1295 music inputs, but rather by the change of a property value).
1297 There are very few objects which are @emph{directly} connected to
1298 output. A normal note (like @code{c4}) is not directly connected
1302 \tweak #'color #red c4
1306 does not change color. See @ref{Displaying music expressions}, for
1310 @node Using Scheme code instead of \tweak
1311 @subsection Using Scheme code instead of @code{\tweak}
1313 The main disadvantage of @code{\tweak} is its syntactical
1314 inflexibility. For example, the following produces a syntax error.
1317 F = \tweak #'font-size #-3 -\flageolet
1325 With other words, @code{\tweak} doesn't behave like an articulation
1326 regarding the syntax; in particular, it can't be attached with
1327 @code{^} and @code{_}.
1329 Using Scheme, this problem can be circumvented. The route to the
1330 result is given in @ref{Adding articulation to notes (example)},
1331 especially how to use @code{\displayMusic} as a helping guide.
1334 F = #(let ((m (make-music 'ArticulationEvent
1335 'articulation-type "flageolet")))
1336 (set! (ly:music-property m 'tweaks)
1337 (acons 'font-size -3
1338 (ly:music-property m 'tweaks)))
1347 Here, the @code{tweaks} properties of the flageolet object
1348 @code{m} (created with @code{make-music}) are extracted with
1349 @code{ly:music-property}, a new key-value pair to change the
1350 font size is prepended to the property list with the
1351 @code{acons} Scheme function, and the result is finally
1352 written back with @code{set!}. The last element of the
1353 @code{let} block is the return value, @code{m} itself.
1356 @node \set versus \override
1357 @subsection @code{\set} vs. @code{\override}
1359 We have seen two methods of changing properties: @code{\set} and
1360 @code{\override}. There are actually two different kinds of
1363 Contexts can have properties, which are usually named in
1364 @code{studlyCaps}. They mostly control the translation from
1365 music to notation, eg. @code{localKeySignature} (for determining
1366 whether to print accidentals), @code{measurePosition} (for
1367 determining when to print a bar line). Context properties can
1368 change value over time while interpreting a piece of music;
1369 @code{measurePosition} is an obvious example of
1370 this. Context properties are modified with @code{\set}.
1372 There is a special type of context property: the element
1373 description. These properties are named in @code{StudlyCaps}
1374 (starting with capital letters). They contain the
1375 @q{default settings} for said graphical object as an
1376 association list. See @file{scm/@/define@/-grobs@/.scm}
1377 to see what kind of settings there are. Element descriptions
1378 may be modified with @code{\override}.
1380 @code{\override} is actually a shorthand;
1383 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1387 is more or less equivalent to
1389 @c leave this long line -gp
1391 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1394 The value of @code{context} (the alist) is used to initialize
1395 the properties of individual grobs. Grobs also have
1396 properties, named in Scheme style, with
1397 @code{dashed-words}. The values of grob properties change
1398 during the formatting process: formatting basically amounts
1399 to computing properties using callback functions.
1401 @code{fontSize} is a special property: it is equivalent to
1402 entering @code{\override ... #'font-size} for all pertinent
1403 objects. Since this is a common change, the special
1404 property (modified with @code{\set}) was created.
1407 @node Difficult tweaks
1408 @subsection Difficult tweaks
1410 There are a few classes of difficult adjustments.
1416 One type of difficult adjustment is the appearance of spanner objects,
1417 such as slur and tie. Initially, only one of these objects is created,
1418 and they can be adjusted with the normal mechanism. However, in some
1419 cases the spanners cross line breaks. If this happens, these objects
1420 are cloned. A separate object is created for every system that it is
1421 in. These are clones of the original object and inherit all
1422 properties, including @code{\override}s.
1425 In other words, an @code{\override} always affects all pieces of a
1426 broken spanner. To change only one part of a spanner at a line break,
1427 it is necessary to hook into the formatting process. The
1428 @code{after-line-breaking} callback contains the Scheme procedure that
1429 is called after the line breaks have been determined, and layout
1430 objects have been split over different systems.
1432 In the following example, we define a procedure
1433 @code{my-callback}. This procedure
1437 determines if we have been split across line breaks
1439 if yes, retrieves all the split objects
1441 checks if we are the last of the split objects
1443 if yes, it sets @code{extra-offset}.
1446 This procedure is installed into @internalsref{Tie}, so the last part
1447 of the broken tie is translated up.
1449 @lilypond[quote,verbatim,ragged-right]
1450 #(define (my-callback grob)
1452 ; have we been split?
1453 (orig (ly:grob-original grob))
1455 ; if yes, get the split pieces (our siblings)
1456 (siblings (if (ly:grob? orig)
1457 (ly:spanner-broken-into orig) '() )))
1459 (if (and (>= (length siblings) 2)
1460 (eq? (car (last-pair siblings)) grob))
1461 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1464 \override Tie #'after-line-breaking =
1471 When applying this trick, the new @code{after-line-breaking} callback
1472 should also call the old one @code{after-line-breaking}, if there is
1473 one. For example, if using this with @code{Hairpin},
1474 @code{ly:hairpin::after-line-breaking} should also be called.
1477 @item Some objects cannot be changed with @code{\override} for
1478 technical reasons. Examples of those are @code{NonMusicalPaperColumn}
1479 and @code{PaperColumn}. They can be changed with the
1480 @code{\overrideProperty} function, which works similar to @code{\once
1481 \override}, but uses a different syntax.
1485 #"Score.NonMusicalPaperColumn" % Grob name
1486 #'line-break-system-details % Property name
1487 #'((next-padding . 20)) % Value
1490 Note, however, that @code{\override}, applied to
1491 @code{NoteMusicalPaperColumn} and @code{PaperColumn}, still works as
1492 expected within @code{\context} blocks.
1501 @node Discussion of specific tweaks
1502 @section Discussion of specific tweaks
1506 * Controlling visibility of objects::
1510 @subsection Line styles
1512 @c TODO: split the following explanations between expressive marks and
1513 @c text-related stuff. Perhaps create a new subsection named
1514 @c "Spanner limits", "Spanner boundaries"? -vv
1516 Some performance indications, e.g., @i{rallentando} and
1517 @i{accelerando} and @i{trills} are written as text and are
1518 extended over many measures with lines, sometimes dotted or wavy.
1520 These all use the same routines as the glissando for drawing the
1521 texts and the lines, and tuning their behavior is therefore also
1522 done in the same way. It is done with a spanner, and the routine
1523 responsible for drawing the spanners is
1524 @code{ly:line-interface::print}. This routine determines the
1525 exact location of the two @i{span points} and draws a line in
1526 between, in the style requested.
1528 Here is an example of the different line styles available, and how
1531 @lilypond[relative=2,ragged-right,verbatim,fragment]
1533 \once \override Glissando #'style = #'dashed-line
1535 \override Glissando #'style = #'dotted-line
1537 \override Glissando #'style = #'zigzag
1539 \override Glissando #'style = #'trill
1543 The information that determines the end-points is computed
1544 on-the-fly for every graphic object, but it is possible to
1547 @lilypond[relative=2,ragged-right,verbatim,fragment]
1549 \once \override Glissando #'bound-details #'right #'Y = #-2
1553 The @code{Glissando} object, like any other using the
1554 @code{ly:line-interface::print} routine, carries a nested
1555 association list. In the above statement, the value for @code{Y}
1556 is set to @code{-2} for the association list corresponding to the
1557 right end point. Of course, it is also possible to adjust the
1558 left side with @code{left} instead of @code{right}.
1560 If @code{Y} is not set, the value is computed from the vertical
1561 position of right attachment point of the spanner.
1563 In case of a line break, the values for the span-points are
1564 extended with contents of the @code{left-broken} and
1565 @code{right-broken} sublists, for example
1567 @lilypond[relative=2,ragged-right,verbatim,fragment]
1568 \override Glissando #'breakable = ##T
1569 \override Glissando #'bound-details #'right-broken #'Y = #-3
1570 c1 \glissando \break
1574 The following properties can be used for the
1578 This sets the Y-coordinate of the end point, in staff space. By
1579 default, it is the center of the bound object, so for a glissando
1580 it points to the vertical center of the note head.
1582 For horizontal spanners, such as text spanner and trill spanners,
1583 it is hardcoded to 0.
1586 This determines where the line starts and ends in X-direction,
1587 relative to the bound object. So, a value of @code{-1} (or
1588 @code{LEFT}) makes the line start/end at the left side of the note
1589 head it is attached to.
1592 This is the absolute coordinate of the end point. It is usually
1593 computed on the fly, and there is little use in overriding it.
1596 Line spanners may have symbols at the beginning or end, which is
1597 contained in this sub-property. This is for internal use, it is
1598 recommended to use @code{text}.
1601 This is a markup that is evaluated to yield stencil. It is used
1602 to put @i{cresc.} and @i{tr} on horizontal spanners.
1604 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
1605 \override TextSpanner #'bound-details #'left #'text
1606 = \markup { \small \bold Slower }
1607 c2\startTextSpan b c a\stopTextSpan
1610 @item stencil-align-dir-y
1611 @item stencil-offset
1612 Without setting this, the stencil is simply put there at the
1613 end-point, as defined by the @code{X} and @code{Y} sub properties.
1614 Setting either @code{stencil-align-dir-y} or @code{stencil-offset}
1615 will move the symbol at the edge relative to the end point of the
1618 @lilypond[relative=1,fragment,verbatim]
1619 \override TextSpanner #'bound-details
1620 #'left #'stencil-align-dir-y = #DOWN
1621 \override TextSpanner #'bound-details
1622 #'right #'stencil-align-dir-y = #UP
1624 \override TextSpanner #'bound-details
1625 #'left #'text = #"gggg"
1626 \override TextSpanner #'bound-details
1627 #'right #'text = #"hhhh"
1628 c4^\startTextSpan c c c \stopTextSpan
1632 Setting this sub property to @code{#t} produce an arrowhead at the
1636 This sub property controls the space between the specified
1637 end-point of the line and the actual end. Without padding, a
1638 glissando would start and end in the center of each note head.
1642 FIXME: should this be in NR 3?
1644 The music function \endSpanners terminates spanners and hairpins
1645 after exactly one note.
1647 @lilypond[verbatim,quote,ragged-right,relative=2,fragment]
1649 c2 \startTextSpan c2
1653 When using \endSpanners it is not necessary to close
1654 \startTextSpan with \stopTextSpan, nor is it necessary to close
1661 Internals Reference: @internalsref{TextSpanner},
1662 @internalsref{Glissando}, @internalsref{VoiceFollower},
1663 @internalsref{TrillSpanner},
1664 @internalsref{line-spanner-interface}.
1668 @node Controlling visibility of objects
1669 @subsection Controlling visibility of objects
1671 stuff about #'break-visibility