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.
10 @node Changing defaults
11 @chapter Changing defaults
14 The purpose of LilyPond's design is to provide the finest output
15 quality as a default. Nevertheless, it may happen that you need to
16 change this default layout. The layout is controlled through a large
17 number of proverbial @q{knobs and switches.} This chapter does not
18 list each and every knob. Rather, it outlines what groups of controls
19 are available and explains how to lookup which knob to use for a
23 @cindex Internals Reference
25 The controls available for tuning are described in a separate
28 Internals Reference manual.
31 @ref{Top,Internals Reference,,lilypond-internals}.
34 lists all different variables, functions and options available in
35 LilyPond. It is written as a HTML document, which is available
36 @c leave the @uref as one long line.
37 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
38 but is also included with the LilyPond documentation package.
40 There are four areas where the default settings may be changed:
44 Automatic notation: changing the automatic creation of notation
45 elements. For example, changing the beaming rules.
48 Output: changing the appearance of individual
49 objects. For example, changing stem directions or the location of
53 Context: changing aspects of the translation from music events to
54 notation. For example, giving each staff a separate time signature.
57 Page layout: changing the appearance of the spacing, line
58 breaks, and page dimensions. These modifications are discussed
59 in @ref{Non-musical notation}, and @ref{Spacing issues}.
62 Internally, LilyPond uses Scheme (a LISP dialect) to provide
63 infrastructure. Overriding layout decisions in effect accesses the
64 program internals, which requires Scheme input. Scheme elements are
65 introduced in a @code{.ly} file with the hash mark
66 @code{#}.@footnote{@rlearning{Scheme tutorial}, contains a short tutorial
67 on entering numbers, lists, strings, and symbols in Scheme.}
71 * Interpretation contexts::
72 * The \override command::
73 * Discussion of specific tweaks::
77 @node Interpretation contexts
78 @section Interpretation contexts
80 This section describes what contexts are, and how to modify them.
83 * Contexts explained::
85 * Changing context properties on the fly::
86 * Modifying context plug-ins::
87 * Layout tunings within contexts::
88 * Changing context default settings::
89 * Defining new contexts::
91 * Vertical grouping of grobs::
95 @node Contexts explained
96 @subsection Contexts explained
98 When music is printed, a lot of notational elements must be added to the
99 output. For example, compare the input and output of the following example:
101 @lilypond[quote,verbatim,relative=2,fragment]
105 The input is rather sparse, but in the output, bar lines, accidentals,
106 clef, and time signature are added. LilyPond @emph{interprets} the
107 input. During this step, the musical information is inspected in time
108 order, similar to reading a score from left to right. While reading
109 the input, the program remembers where measure boundaries are, and which
110 pitches require explicit accidentals. This information can be presented on
111 several levels. For example, the effect of an accidental is limited
112 to a single staff, while a bar line must be synchronized across the
115 Within LilyPond, these rules and bits of information are grouped in
116 @emph{Contexts}. Some examples of contexts are @code{Voice},
117 @code{Staff}, and @code{Score}. They are hierarchical, for
118 example: a @code{Staff} can contain many @code{Voice}s, and a
119 @code{Score} can contain many @code{Staff} contexts.
122 @sourceimage{context-example,5cm,,}
125 Each context has the responsibility for enforcing some notation rules,
126 creating some notation objects and maintaining the associated
127 properties. For example, the @code{Voice} context may introduce an
128 accidental and then the @code{Staff} context maintains the rule to
129 show or suppress the accidental for the remainder of the measure. The
130 synchronization of bar lines is handled at @code{Score} context.
132 However, in some music we may not want the bar lines to be
133 synchronized -- consider a polymetric score in 4/4 and 3/4 time. In
134 such cases, we must modify the default settings of the @code{Score}
135 and @code{Staff} contexts.
137 For very simple scores, contexts are created implicitly, and you need
138 not be aware of them. For larger pieces, such as anything with more
139 than one staff, they must be
140 created explicitly to make sure that you get as many staves as you
141 need, and that they are in the correct order. For typesetting pieces
142 with specialized notation, it can be useful to modify existing or
143 to define new contexts.
146 A complete description of all available contexts is in the program
149 @internalsref{Contexts}.
152 Translation @expansion{} Context.
155 @c [TODO: describe propagation]
158 @node Creating contexts
159 @subsection Creating contexts
161 For scores with only one voice and one staff, contexts are
162 created automatically. For more complex scores, it is necessary to
163 create them by hand. There are three commands that do this.
168 The easiest command is @code{\new}, and it also the quickest to type.
169 It is prepended to a music expression, for example
173 @cindex Context, creating
176 \new @var{type} @var{music expression}
180 where @var{type} is a context name (like @code{Staff} or
181 @code{Voice}). This command creates a new context, and starts
182 interpreting the @var{music expression} with that.
184 A practical application of @code{\new} is a score with many
185 staves. Each part that should be on its own staff, is preceded with
188 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
195 The @code{\new} command may also give a name to the context,
198 \new @var{type} = @var{id} @var{music}
200 However, this user specified name is only used if there is no other
201 context already earlier with the same name.
207 Like @code{\new}, the @code{\context} command also directs a music
208 expression to a context object, but gives the context an explicit name. The
212 \context @var{type} = @var{id} @var{music}
215 This form will search for an existing context of type @var{type}
216 called @var{id}. If that context does not exist yet, a new
217 context with the specified name is created. This is useful if
218 the context is referred to later on. For example, when
219 setting lyrics the melody is in a named context
222 \context Voice = "@b{tenor}" @var{music}
226 so the texts can be properly aligned to its notes,
229 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
234 Another possible use of named contexts is funneling two different
235 music expressions into one context. In the following example,
236 articulations and notes are entered separately,
240 arts = @{ s4-. s4-> @}
243 They are combined by sending both to the same @code{Voice} context,
247 \new Staff \context Voice = "A" \music
248 \context Voice = "A" \arts
251 @lilypond[quote,ragged-right]
255 \new Staff \context Voice = "A" \music
256 \context Voice = "A" \arts
260 With this mechanism, it is possible to define an Urtext (original
261 edition), with the option to put several distinct articulations on the
264 @cindex creating contexts
267 The third command for creating contexts is
269 \context @var{type} @var{music}
274 This is similar to @code{\context} with @code{= @var{id}}, but matches
275 any context of type @var{type}, regardless of its given name.
277 This variant is used with music expressions that can be interpreted at
278 several levels. For example, the @code{\applyOutput} command (see
279 @ref{Running a function on all layout objects}). Without an explicit
280 @code{\context}, it is usually applied to @code{Voice}
283 \applyOutput #'@var{context} #@var{function} % apply to Voice
286 To have it interpreted at the @code{Score} or @code{Staff} level use
290 \applyOutput #'Score #@var{function}
291 \applyOutput #'Staff #@var{function}
297 @node Changing context properties on the fly
298 @subsection Changing context properties on the fly
302 @cindex changing properties
304 Each context can have different @emph{properties}, variables contained
305 in that context. They can be changed during the interpretation step.
306 This is achieved by inserting the @code{\set} command in the music,
309 \set @var{context}.@var{prop} = #@var{value}
313 @lilypond[quote,verbatim,relative=2,fragment]
315 \set Score.skipBars = ##t
319 This command skips measures that have no notes. The result is that
320 multi-rests are condensed. The value assigned is a Scheme object. In
321 this case, it is @code{#t}, the boolean True value.
323 If the @var{context} argument is left out, then the current bottom-most
324 context (typically @code{ChordNames}, @code{Voice}, or
325 @code{Lyrics}) is used. In this example,
327 @lilypond[quote,verbatim,relative=2,fragment]
329 \set autoBeaming = ##f
334 the @var{context} argument to @code{\set} is left out, so automatic
335 beaming is switched off in the current @internalsref{Voice}. Note that
336 the bottom-most context does not always contain the property that you
337 wish to change -- for example, attempting to set the @code{skipBars}
338 property (of the bottom-most context, in this case @code{Voice}) will
341 @lilypond[quote,verbatim,relative=2,fragment]
347 Contexts are hierarchical, so if a bigger context was specified, for
348 example @code{Staff}, then the change would also apply to all
349 @code{Voice}s in the current stave. The change is applied
350 @q{on-the-fly}, during the music, so that the setting only affects the
351 second group of eighth notes.
355 There is also an @code{\unset} command,
357 \unset @var{context}.@var{prop}
361 which removes the definition of @var{prop}. This command removes
362 the definition only if it is set in @var{context}, so
365 \set Staff.autoBeaming = ##f
369 introduces a property setting at @code{Staff} level. The setting also
370 applies to the current @code{Voice}. However,
373 \unset Voice.autoBeaming
377 does not have any effect. To cancel this setting, the @code{\unset}
378 must be specified on the same level as the original @code{\set}. In
379 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
382 \unset Staff.autoBeaming
385 Like @code{\set}, the @var{context} argument does not have to be
386 specified for a bottom context, so the two statements
389 \set Voice.autoBeaming = ##t
390 \set autoBeaming = ##t
398 Settings that should only apply to a single time-step can be entered
399 with @code{\once}, for example in
401 @lilypond[quote,verbatim,relative=2,fragment]
403 \once \set fontSize = #4.7
408 the property @code{fontSize} is unset automatically after the second
411 A full description of all available context properties is in the
412 program reference, see
414 @internalsref{Tunable context properties}.
417 Translation @expansion{} Tunable context properties.
421 @node Modifying context plug-ins
422 @subsection Modifying context plug-ins
424 Notation contexts (like @code{Score} and @code{Staff}) not only
426 they also contain plug-ins called @q{engravers} that create notation
427 elements. For example, the @code{Voice} context contains a
428 @code{Note_head_engraver} and the @code{Staff} context contains a
429 @code{Key_signature_engraver}.
431 For a full a description of each plug-in, see
433 @internalsref{Engravers and Performers}.
436 Internals Reference @expansion{} Translation @expansion{} Engravers.
438 Every context described in
440 @internalsref{Contexts}
443 Internals Reference @expansion{} Translation @expansion{} Context.
445 lists the engravers used for that context.
448 It can be useful to shuffle around these plug-ins. This is done by
449 starting a new context with @code{\new} or @code{\context}, and
455 \new @var{context} \with @{
468 where the @dots{} should be the name of an engraver. Here is a simple
469 example which removes @code{Time_signature_engraver} and
470 @code{Clef_engraver} from a @code{Staff} context,
472 @lilypond[quote,relative=1,verbatim,fragment]
478 \remove "Time_signature_engraver"
479 \remove "Clef_engraver"
486 In the second staff there are no time signature or clef symbols. This
487 is a rather crude method of making objects disappear since it will affect
488 the entire staff. This method also influences the spacing, which may or
489 may not be desirable. A more
490 sophisticated method of blanking objects is shown in @rlearning{Common tweaks}.
492 The next example shows a practical application. Bar lines and time
493 signatures are normally synchronized across the score. This is done
494 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
495 This plug-in keeps an administration of time signature, location
496 within the measure, etc. By moving these engraver from @code{Score} to
497 @code{Staff} context, we can have a score where each staff has its own
500 @cindex polymetric scores
501 @cindex Time signatures, multiple
503 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
505 \remove "Timing_translator"
506 \remove "Default_bar_line_engraver"
509 \consists "Timing_translator"
510 \consists "Default_bar_line_engraver"
516 \consists "Timing_translator"
517 \consists "Default_bar_line_engraver"
526 @node Layout tunings within contexts
527 @subsection Layout tunings within contexts
529 Each context is responsible for creating certain types of graphical
530 objects. The settings used for printing these objects are also stored by
531 context. By changing these settings, the appearance of objects can be
534 The syntax for this is
537 \override @var{context}.@var{name} #'@var{property} = #@var{value}
540 Here @var{name} is the name of a graphical object, like @code{Stem} or
541 @code{NoteHead}, and @var{property} is an internal variable of the
542 formatting system (@q{grob property} or @q{layout property}). The latter is a
543 symbol, so it must be quoted. The subsection @ref{Constructing a
544 tweak}, explains what to fill in for @var{name}, @var{property}, and
545 @var{value}. Here we only discuss the functionality of this command.
550 \override Staff.Stem #'thickness = #4.0
554 makes stems thicker (the default is 1.3, with staff line thickness as a
555 unit). Since the command specifies @code{Staff} as context, it only
556 applies to the current staff. Other staves will keep their normal
557 appearance. Here we see the command in action:
559 @lilypond[quote,verbatim,relative=2,fragment]
561 \override Staff.Stem #'thickness = #4.0
567 The @code{\override} command changes the definition of the @code{Stem}
568 within the current @code{Staff}. After the command is interpreted
569 all stems are thickened.
571 Analogous to @code{\set}, the @var{context} argument may be left out,
572 causing the default context @code{Voice} to be used. Adding
573 @code{\once} applies the change during one timestep only.
575 @lilypond[quote,fragment,verbatim,relative=2]
577 \once \override Stem #'thickness = #4.0
582 The @code{\override} must be done before the object is
583 started. Therefore, when altering @emph{Spanner} objects such as slurs
584 or beams, the @code{\override} command must be executed at the moment
585 when the object is created. In this example,
587 @lilypond[quote,fragment,verbatim,relative=2]
588 \override Slur #'thickness = #3.0
590 \override Beam #'thickness = #0.6
595 the slur is fatter but the beam is not. This is because the command for
596 @code{Beam} comes after the Beam is started, so it has no effect.
598 Analogous to @code{\unset}, the @code{\revert} command for a context
599 undoes an @code{\override} command; like with @code{\unset}, it only
600 affects settings that were made in the same context. In other words, the
601 @code{\revert} in the next example does not do anything.
604 \override Voice.Stem #'thickness = #4.0
605 \revert Staff.Stem #'thickness
608 Some tweakable options are called @q{subproperties} and reside inside
609 properties. To tweak those, use commands of the form
611 @c leave this as a long long
613 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
620 \override Stem #'details #'beamed-lengths = #'(4 4 3)
626 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
627 @internalsref{PropertySet}, @internalsref{Backend}, and
628 @internalsref{All layout objects}.
633 The back-end is not very strict in type-checking object properties.
634 Cyclic references in Scheme values for properties can cause hangs
638 @node Changing context default settings
639 @subsection Changing context default settings
641 The adjustments of the previous subsections (@ref{Changing context
642 properties on the fly}, @ref{Modifying context plug-ins}, and
643 @ref{Layout tunings within contexts}) can also be entered separately
644 from the music in the @code{\layout} block,
653 \override Stem #'thickness = #4.0
654 \remove "Time_signature_engraver"
659 The @code{\Staff} command brings in the existing definition of the
660 staff context so that it can be modified.
665 \override Stem #'thickness = #4.0
666 \remove "Time_signature_engraver"
670 affect all staves in the score. Other contexts can be modified
673 The @code{\set} keyword is optional within the @code{\layout} block, so
689 It is not possible to collect context changes in a variable and apply
690 them to a @code{\context} definition by referring to that variable.
692 The @code{\RemoveEmptyStaffContext} will overwrite your current
693 @code{\Staff} settings. If you wish to change the defaults for a
694 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
695 after calling @code{\RemoveEmptyStaffContext}, ie
700 \RemoveEmptyStaffContext
702 \override Stem #'thickness = #4.0
708 @node Defining new contexts
709 @subsection Defining new contexts
711 Specific contexts, like @code{Staff} and @code{Voice}, are made of
712 simple building blocks. It is possible to create new types of
713 contexts with different combinations of engraver plug-ins.
715 The next example shows how to build a different type of
716 @code{Voice} context from scratch. It will be similar to
717 @code{Voice}, but only prints centered slash note heads. It can be used
718 to indicate improvisation in jazz pieces,
720 @lilypond[quote,ragged-right]
723 \type "Engraver_group"
724 \consists "Note_heads_engraver"
725 \consists "Text_engraver"
726 \consists Pitch_squash_engraver
727 squashedPosition = #0
728 \override NoteHead #'style = #'slash
729 \override Stem #'transparent = ##t
733 \accepts "ImproVoice"
737 a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
738 c4 c^"undress" c_"while playing :)" c }
744 These settings are defined within a @code{\context} block inside a
745 @code{\layout} block,
755 In the following discussion, the example input shown should go in place
756 of the @dots{} in the previous fragment.
758 First it is necessary to define a name for the new context:
764 Since it is similar to the @code{Voice}, we want commands that work
765 on (existing) @code{Voice}s to remain working. This is achieved by
766 giving the new context an alias @code{Voice},
772 The context will print notes and instructive texts, so we need to add
773 the engravers which provide this functionality,
776 \consists Note_heads_engraver
777 \consists Text_engraver
780 but we only need this on the center line,
783 \consists Pitch_squash_engraver
784 squashedPosition = #0
787 The @internalsref{Pitch_squash_engraver} modifies note heads (created
788 by @internalsref{Note_heads_engraver}) and sets their vertical
789 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
792 The notes look like a slash, and have no stem,
795 \override NoteHead #'style = #'slash
796 \override Stem #'transparent = ##t
799 All these plug-ins have to cooperate, and this is achieved with a
800 special plug-in, which must be marked with the keyword @code{\type}.
801 This should always be @internalsref{Engraver_group},
804 \type "Engraver_group"
812 \type "Engraver_group"
813 \consists "Note_heads_engraver"
814 \consists "Text_engraver"
815 \consists Pitch_squash_engraver
816 squashedPosition = #0
817 \override NoteHead #'style = #'slash
818 \override Stem #'transparent = ##t
824 Contexts form hierarchies. We want to hang the @code{ImproVoice}
825 under @code{Staff}, just like normal @code{Voice}s. Therefore, we
826 modify the @code{Staff} definition with the @code{\accepts}
837 The opposite of @code{\accepts} is @code{\denies},
838 which is sometimes needed when reusing existing context definitions.
840 Putting both into a @code{\layout} block, like
850 \accepts "ImproVoice"
855 Then the output at the start of this subsection can be entered as
863 c c_"while playing :)"
870 @node Aligning contexts
871 @subsection Aligning contexts
873 New contexts may be aligned above or below existing contexts. This
874 could be useful in setting up a vocal staff (@rlearning{Vocal ensembles}) and
877 FIXME: this section doesn't work in pdf. (?)
880 @findex alignAboveContext
881 @findex alignBelowContext
883 @lilypond[quote,ragged-right]
886 \relative c' \new Staff = "main" {
889 \new Staff \with {alignAboveContext=main} \ossia
897 @node Vertical grouping of grobs
898 @subsection Vertical grouping of grobs
900 The VerticalAlignment and VerticalAxisGroup grobs work together.
901 VerticalAxisGroup groups together different grobs like Staff, Lyrics,
902 etc. VerticalAlignment then vertically aligns the different grobs
903 grouped together by VerticalAxisGroup. There is usually only one
904 VerticalAlignment per score but every Staff, Lyrics, etc. has its own
908 @node The \override command
909 @section The @code{\override} command
911 In the previous section, we have already touched on a command that
912 changes layout details: the @code{\override} command. In this section,
913 we will look in more detail at how to use the command in practice. The
914 general syntax of this command is:
917 \override @var{context}.@var{layout_object} #'@var{layout_property} = #@var{value}
920 This will set the @var{layout_property} of the specified @var{layout_object},
921 which is a member of the @var{context}, to the @var{value}.
924 * Constructing a tweak::
925 * Navigating the program reference::
926 * Layout interfaces::
927 * Determining the grob property::
928 * Objects connected to the input::
929 * Using Scheme code instead of \tweak::
930 * \set versus \override::
936 @node Constructing a tweak
937 @subsection Constructing a tweak
939 Commands which change output generally look like
942 \override Voice.Stem #'thickness = #3.0
946 To construct this tweak we must determine these bits of information:
949 @item the context: here @code{Voice}.
950 @item the layout object: here @code{Stem}.
951 @item the layout property: here @code{thickness}.
952 @item a sensible value: here @code{3.0}.
955 Some tweakable options are called @q{subproperties} and reside inside
956 properties. To tweak those, use commands in the form
959 \override Stem #'details #'beamed-lengths = #'(4 4 3)
962 @cindex internal documentation
963 @cindex finding graphical objects
964 @cindex graphical object descriptions
967 @cindex internal documentation
969 For many properties, regardless of the data type of the property, setting the
970 property to false ( @code{##f} ) will result in turning it off, causing
971 LilyPond to ignore that property entirely. This is particularly useful for
972 turning off grob properties which may otherwise be causing problems.
974 We demonstrate how to glean this information from the notation manual
975 and the program reference.
980 @node Navigating the program reference
981 @subsection Navigating the program reference
983 Suppose we want to move the fingering indication in the fragment
986 @lilypond[quote,fragment,relative=2,verbatim]
992 If you visit the documentation on fingering instructions (in
993 @ref{Fingering instructions}), you will notice:
998 Internals Reference: @internalsref{Fingering}.
1003 @c outdated info; probably will delete.
1005 This fragment points to two parts of the program reference: a page
1006 on @code{FingerEvent} and one on @code{Fingering}.
1008 The page on @code{FingerEvent} describes the properties of the music
1009 expression for the input @code{-2}. The page contains many links
1010 forward. For example, it says
1013 Accepted by: @internalsref{Fingering_engraver},
1017 That link brings us to the documentation for the Engraver, the
1021 This engraver creates the following layout objects: @internalsref{Fingering}.
1024 In other words, once the @code{FingerEvent}s are interpreted, the
1025 @code{Fingering_engraver} plug-in will process them.
1029 @c I can't figure out what this is supposed to mean. -gp
1031 The @code{Fingering_engraver} is also listed to create
1032 @internalsref{Fingering} objects,
1034 @c old info? it doesn't make any sense to me with our current docs.
1036 second bit of information listed under @b{See also} in the Notation
1041 The programmer's reference is available as an HTML document. It is
1042 highly recommended that you read it in HTML form, either online or
1043 by downloading the HTML documentation. This section will be much more
1044 difficult to understand if you are using the
1048 Follow the link to @internalsref{Fingering}. At the top of the
1052 Fingering objects are created by: @internalsref{Fingering_engraver} and
1053 @internalsref{New_fingering_engraver}.
1056 By following related links inside the program reference, we can follow the
1057 flow of information within the program:
1061 @item @internalsref{Fingering}:
1062 @internalsref{Fingering} objects are created by:
1063 @internalsref{Fingering_engraver}
1065 @item @internalsref{Fingering_engraver}:
1066 Music types accepted: @internalsref{fingering-event}
1068 @item @internalsref{fingering-event}:
1069 Music event type @code{fingering-event} is in Music expressions named
1070 @internalsref{FingerEvent}
1073 This path goes against the flow of information in the program: it
1074 starts from the output, and ends at the input event. You could
1075 also start at an input event, and read with the flow of
1076 information, eventually ending up at the output object(s).
1078 The program reference can also be browsed like a normal document. It
1079 contains chapters on
1081 @internalsref{Music definitions},
1084 @code{Music definitions}
1086 on @internalsref{Translation}, and the @internalsref{Backend}. Every
1087 chapter lists all the definitions used and all properties that may be
1091 @node Layout interfaces
1092 @subsection Layout interfaces
1094 @cindex interface, layout
1095 @cindex layout interface
1098 The HTML page that we found in the previous section describes the
1099 layout object called @internalsref{Fingering}. Such an object is a
1100 symbol within the score. It has properties that store numbers (like
1101 thicknesses and directions), but also pointers to related objects. A
1102 layout object is also called a @emph{Grob}, which is short for Graphical
1103 Object. For more details about Grobs, see @internalsref{grob-interface}.
1105 The page for @code{Fingering} lists the definitions for the
1106 @code{Fingering} object. For example, the page says
1109 @code{padding} (dimension, in staff space):
1115 which means that the number will be kept at a distance of at least 0.5
1119 Each layout object may have several functions as a notational or
1120 typographical element. For example, the Fingering object
1121 has the following aspects
1125 Its size is independent of the horizontal spacing, unlike slurs or beams.
1128 It is a piece of text. Granted, it is usually a very short text.
1131 That piece of text is typeset with a font, unlike slurs or beams.
1134 Horizontally, the center of the symbol should be aligned to the
1135 center of the note head.
1138 Vertically, the symbol is placed next to the note and the staff.
1141 The vertical position is also coordinated with other superscript
1142 and subscript symbols.
1145 Each of these aspects is captured in so-called @emph{interface}s,
1146 which are listed on the @internalsref{Fingering} page at the bottom
1149 This object supports the following interfaces:
1150 @internalsref{item-interface},
1151 @internalsref{self-alignment-interface},
1152 @internalsref{side-position-interface}, @internalsref{text-interface},
1153 @internalsref{text-script-interface}, @internalsref{font-interface},
1154 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1157 Clicking any of the links will take you to the page of the respective
1158 object interface. Each interface has a number of properties. Some of
1159 them are not user-serviceable (@q{Internal properties}), but others
1162 We have been talking of @emph{the} @code{Fingering} object, but actually it
1163 does not amount to much. The initialization file (see
1164 @rlearning{Default files})
1165 @file{scm/@/define@/-grobs@/.scm} shows the soul of the @q{object},
1170 (avoid-slur . around)
1171 (slur-padding . 0.2)
1172 (staff-padding . 0.5)
1173 (self-alignment-X . 0)
1174 (self-alignment-Y . 0)
1175 (script-priority . 100)
1176 (stencil . ,ly:text-interface::print)
1177 (direction . ,ly:script-interface::calc-direction)
1178 (font-encoding . fetaNumber)
1179 (font-size . -5) ; don't overlap when next to heads.
1180 (meta . ((class . Item)
1181 (interfaces . (finger-interface
1183 text-script-interface
1185 side-position-interface
1186 self-alignment-interface
1187 item-interface))))))
1191 As you can see, the @code{Fingering} object is nothing more than a
1192 bunch of variable settings, and the webpage in the Internals Reference
1193 is directly generated from this definition.
1196 @node Determining the grob property
1197 @subsection Determining the grob property
1199 Recall that we wanted to change the position of the @b{2} in
1201 @lilypond[quote,fragment,relative=2,verbatim]
1207 Since the @b{2} is vertically positioned next to its note, we have to
1208 meddle with the interface associated with this positioning. This is
1209 done using @code{side-position-interface}. The page for this interface
1213 @code{side-position-interface}
1215 Position a victim object (this one) next to other objects (the
1216 support). The property @code{direction} signifies where to put the
1217 victim object relative to the support (left or right, up or down?)
1222 Below this description, the variable @code{padding} is described as
1227 (dimension, in staff space)
1229 Add this much extra space between objects that are next to each other.
1233 By increasing the value of @code{padding}, we can move the
1234 fingering away from the note head. The following command inserts
1235 3 staff spaces of white
1236 between the note and the fingering:
1238 \once \override Voice.Fingering #'padding = #3
1241 Inserting this command before the Fingering object is created,
1242 i.e., before @code{c2}, yields the following result:
1244 @lilypond[quote,relative=2,fragment,verbatim]
1245 \once \override Voice.Fingering #'padding = #3
1252 In this case, the context for this tweak is @code{Voice}. This
1253 fact can also be deduced from the program reference, for the page for
1254 the @internalsref{Fingering_engraver} plug-in says
1257 Fingering_engraver is part of contexts: @dots{} @internalsref{Voice}
1261 @node Objects connected to the input
1262 @subsection Objects connected to the input
1266 In some cases, it is possible to take a short-cut for tuning graphical
1267 objects. For objects that result directly from a piece of the input,
1268 you can use the @code{\tweak} function, for example
1270 @lilypond[relative=2,fragment,verbatim,ragged-right]
1273 \tweak #'color #red d
1275 \tweak #'duration-log #1 a
1276 >4-\tweak #'padding #10 -.
1279 As you can see, properties are set in the objects directly,
1280 without mentioning the grob name or context where this should be
1283 This technique only works for objects that are directly connected to
1284 an @internalsref{Event} from the input, for example
1287 @item note heads, caused by chord-pitch (i.e., notes inside a chord)
1288 @item articulation signs, caused by articulation instructions
1291 It notably does not work for stems and accidentals (these are caused
1292 by note heads, not by music events) or clefs (these are not caused by
1293 music inputs, but rather by the change of a property value).
1295 There are very few objects which are @emph{directly} connected to
1296 output. A normal note (like @code{c4}) is not directly connected
1300 \tweak #'color #red c4
1304 does not change color. See @ref{Displaying music expressions}, for
1308 @node Using Scheme code instead of \tweak
1309 @subsection Using Scheme code instead of @code{\tweak}
1311 The main disadvantage of @code{\tweak} is its syntactical
1312 inflexibility. For example, the following produces a syntax error.
1315 F = \tweak #'font-size #-3 -\flageolet
1323 With other words, @code{\tweak} doesn't behave like an articulation
1324 regarding the syntax; in particular, it can't be attached with
1325 @code{^} and @code{_}.
1327 Using Scheme, this problem can be circumvented. The route to the
1328 result is given in @ref{Adding articulation to notes (example)},
1329 especially how to use @code{\displayMusic} as a helping guide.
1332 F = #(let ((m (make-music 'ArticulationEvent
1333 'articulation-type "flageolet")))
1334 (set! (ly:music-property m 'tweaks)
1335 (acons 'font-size -3
1336 (ly:music-property m 'tweaks)))
1345 Here, the @code{tweaks} properties of the flageolet object
1346 @code{m} (created with @code{make-music}) are extracted with
1347 @code{ly:music-property}, a new key-value pair to change the
1348 font size is prepended to the property list with the
1349 @code{acons} Scheme function, and the result is finally
1350 written back with @code{set!}. The last element of the
1351 @code{let} block is the return value, @code{m} itself.
1354 @node \set versus \override
1355 @subsection @code{\set} vs. @code{\override}
1357 We have seen two methods of changing properties: @code{\set} and
1358 @code{\override}. There are actually two different kinds of
1361 Contexts can have properties, which are usually named in
1362 @code{studlyCaps}. They mostly control the translation from
1363 music to notation, eg. @code{localKeySignature} (for determining
1364 whether to print accidentals), @code{measurePosition} (for
1365 determining when to print a bar line). Context properties can
1366 change value over time while interpreting a piece of music;
1367 @code{measurePosition} is an obvious example of
1368 this. Context properties are modified with @code{\set}.
1370 There is a special type of context property: the element
1371 description. These properties are named in @code{StudlyCaps}
1372 (starting with capital letters). They contain the
1373 @q{default settings} for said graphical object as an
1374 association list. See @file{scm/@/define@/-grobs@/.scm}
1375 to see what kind of settings there are. Element descriptions
1376 may be modified with @code{\override}.
1378 @code{\override} is actually a shorthand;
1381 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1385 is more or less equivalent to
1387 @c leave this long line -gp
1389 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1392 The value of @code{context} (the alist) is used to initialize
1393 the properties of individual grobs. Grobs also have
1394 properties, named in Scheme style, with
1395 @code{dashed-words}. The values of grob properties change
1396 during the formatting process: formatting basically amounts
1397 to computing properties using callback functions.
1399 @code{fontSize} is a special property: it is equivalent to
1400 entering @code{\override ... #'font-size} for all pertinent
1401 objects. Since this is a common change, the special
1402 property (modified with @code{\set}) was created.
1405 @node Difficult tweaks
1406 @subsection Difficult tweaks
1408 There are a few classes of difficult adjustments.
1414 One type of difficult adjustment is the appearance of spanner objects,
1415 such as slur and tie. Initially, only one of these objects is created,
1416 and they can be adjusted with the normal mechanism. However, in some
1417 cases the spanners cross line breaks. If this happens, these objects
1418 are cloned. A separate object is created for every system that it is
1419 in. These are clones of the original object and inherit all
1420 properties, including @code{\override}s.
1423 In other words, an @code{\override} always affects all pieces of a
1424 broken spanner. To change only one part of a spanner at a line break,
1425 it is necessary to hook into the formatting process. The
1426 @code{after-line-breaking} callback contains the Scheme procedure that
1427 is called after the line breaks have been determined, and layout
1428 objects have been split over different systems.
1430 In the following example, we define a procedure
1431 @code{my-callback}. This procedure
1435 determines if we have been split across line breaks
1437 if yes, retrieves all the split objects
1439 checks if we are the last of the split objects
1441 if yes, it sets @code{extra-offset}.
1444 This procedure is installed into @internalsref{Tie}, so the last part
1445 of the broken tie is translated up.
1447 @lilypond[quote,verbatim,ragged-right]
1448 #(define (my-callback grob)
1450 ; have we been split?
1451 (orig (ly:grob-original grob))
1453 ; if yes, get the split pieces (our siblings)
1454 (siblings (if (ly:grob? orig)
1455 (ly:spanner-broken-into orig) '() )))
1457 (if (and (>= (length siblings) 2)
1458 (eq? (car (last-pair siblings)) grob))
1459 (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1462 \override Tie #'after-line-breaking =
1469 When applying this trick, the new @code{after-line-breaking} callback
1470 should also call the old one @code{after-line-breaking}, if there is
1471 one. For example, if using this with @code{Hairpin},
1472 @code{ly:hairpin::after-line-breaking} should also be called.
1475 @item Some objects cannot be changed with @code{\override} for
1476 technical reasons. Examples of those are @code{NonMusicalPaperColumn}
1477 and @code{PaperColumn}. They can be changed with the
1478 @code{\overrideProperty} function, which works similar to @code{\once
1479 \override}, but uses a different syntax.
1483 #"Score.NonMusicalPaperColumn" % Grob name
1484 #'line-break-system-details % Property name
1485 #'((next-padding . 20)) % Value
1488 Note, however, that @code{\override}, applied to
1489 @code{NoteMusicalPaperColumn} and @code{PaperColumn}, still works as
1490 expected within @code{\context} blocks.
1499 @node Discussion of specific tweaks
1500 @section Discussion of specific tweaks
1504 * Controlling visibility of objects::
1508 @subsection Line styles
1510 Valentin: write stuff here.
1513 @node Controlling visibility of objects
1514 @subsection Controlling visibility of objects
1516 stuff about #'break-visibility