1 @c -*- coding: utf-8; mode: texinfo; -*-
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. For details, see the Contributors'
8 Guide, node Updating translation committishes..
14 @chapter Tweaking output
16 This chapter discusses how to modify output. LilyPond is extremely
17 configurable; virtually every fragment of output may be changed.
22 * The Internals Reference manual::
23 * Appearance of objects::
24 * Placement of objects::
26 * Collisions of objects::
31 @section Tweaking basics
34 * Introduction to tweaks::
35 * Objects and interfaces::
36 * Naming conventions of objects and properties::
40 @node Introduction to tweaks
41 @subsection Introduction to tweaks
43 @q{Tweaking} is a LilyPond term for the various methods available
44 to the user for modifying the actions taken during interpretation
45 of the input file and modifying the appearance of the printed
46 output. Some tweaks are very easy to use; others are more
47 complex. But taken together the methods available for tweaking
48 permit almost any desired appearance of the printed music to be
51 In this section we cover the basic concepts required to understand
52 tweaking. Later we give a variety of ready-made commands which can
53 simply be copied to obtain the same effect in your own scores, and
54 at the same time we show how these commands may be constructed so
55 that you may learn how to develop your own tweaks.
57 Before starting on this Chapter you may wish to review the section
58 @ref{Contexts and engravers}, as Contexts, Engravers, and the
59 Properties contained within them are fundamental to understanding
60 and constructing Tweaks.
62 @node Objects and interfaces
63 @subsection Objects and interfaces
69 @cindex properties, object
70 @cindex object properties
72 @cindex object, layout
75 Tweaking involves modifying the internal operation and structures
76 of the LilyPond program, so we must first introduce some terms
77 which are used to describe those internal operations and
80 The term @q{Object} is a generic term used to refer to the
81 multitude of internal structures built by LilyPond during the
82 processing of an input file. So when a command like @code{\new
83 Staff} is encountered a new object of type @code{Staff} is
84 constructed. That @code{Staff} object then holds all the
85 properties associated with that particular staff, for example, its
86 name and its key signature, together with details of the engravers
87 which have been assigned to operate within that staff's context.
88 Similarly, there are objects to hold the properties of all other
89 contexts, such as @code{Voice} objects, @code{Score} objects,
90 @code{Lyrics} objects, as well as objects to represent all
91 notational elements such as bar lines,
92 note heads, ties, dynamics, etc. Every object has its own set of
95 Some types of object are given special names. Objects which represent
96 items of notation on the printed output such as note heads, stems,
97 slurs, ties, fingering, clefs, etc are called @q{Layout objects},
98 often known as @q{Graphical Objects}, or @q{Grobs} for short. These
99 are still objects in the generic sense above, and so they too all have
100 properties associated with them, such as their position, size, color,
103 Some layout objects are still more specialized. Phrasing slurs,
104 crescendo hairpins, ottava marks, and many other grobs are not
105 localized in a single place -- they have a starting point, an
106 ending point, and maybe other properties concerned with their
107 shape. Objects with an extended shape like these are called
110 Spanners cannot be tweaked after their creation. This includes both
111 @code{StaffSymbol} and @code{LedgerLineSpanner} which continue
112 throughout the score, except if they are terminated by the
113 @code{\stopStaff} command and then recreated using @code{\startStaff}
116 What is more, there are @q{abstract} grobs which do not print
117 anything of their own, but rather collect, position and manage
118 other grobs. Common examples for this are
119 @code{DynamicLineSpanner}, @code{BreakAlignment},
120 @code{NoteColumn}, @code{VerticalAxisGroup},
121 @code{NonMusicalPaperColumn} and similar. We will see how some of
122 these are used later.
124 It remains to explain what @q{Interfaces} are. Many objects, even
125 though they are quite different, share common features which need to
126 be processed in the same way. For example, all grobs have a color, a
127 size, a position, etc, and all these properties are processed in the
128 same way during LilyPond's interpretation of the input file. To
129 simplify these internal operations these common actions and properties
130 are grouped together in an object called a @code{grob-interface}.
131 There are many other groupings of common properties like this, each
132 one given a name ending in @code{interface}. In total there are over
133 100 such interfaces. We shall see later why this is of interest and
136 These, then, are the main terms relating to objects which we
137 shall use in this chapter.
139 @node Naming conventions of objects and properties
140 @subsection Naming conventions of objects and properties
142 @cindex naming conventions for objects
143 @cindex naming conventions for properties
144 @cindex objects, naming conventions
145 @cindex properties, naming conventions
147 We met some object naming conventions previously, in
148 @ref{Contexts and engravers}. Here for reference is a list
149 of the most common object and property types together with
150 the conventions for naming them and a couple of examples of
151 some real names. We have used @q{A} to stand for any capitalized
152 alphabetic character and @q{aaa} to stand for any number of
153 lower-case alphabetic characters. Other characters are used
156 @multitable @columnfractions .33 .33 .33
157 @headitem Object/property type
158 @tab Naming convention
161 @tab Aaaa or AaaaAaaaAaaa
162 @tab Staff, GrandStaff
164 @tab Aaaa or AaaaAaaaAaaa
167 @tab Aaaa_aaa_engraver
168 @tab Clef_engraver, Note_heads_engraver
170 @tab aaa-aaa-interface
171 @tab grob-interface, break-aligned-interface
172 @item Context Properties
173 @tab aaa or aaaAaaaAaaa
174 @tab alignAboveContext, skipBars
175 @item Layout Object Properties
176 @tab aaa or aaa-aaa-aaa
177 @tab direction, beam-thickness
180 As we shall see shortly, the properties of different types of object are
181 modified by different commands, so it is useful to be able to recognize
182 the types of objects and properties from their names.
186 @ruser{Modifying properties}.
189 @node Tweaking methods
190 @subsection Tweaking methods
192 @cindex tweaking methods
195 * The override command::
196 * The revert command::
198 * The overrideProperty command::
199 * The tweak command::
200 * The single prefix::
203 @node The override command
204 @unnumberedsubsubsec The @code{@bs{}override} command
206 @cindex override command
207 @cindex override syntax
212 We have already met the commands @code{\set} and @code{\with}, used to
213 change the properties of @strong{contexts} and to remove and add
214 @strong{engravers}, in @ref{Modifying context properties}, and
215 @ref{Adding and removing engravers}. We must now introduce some more
218 The command to change the properties of @strong{layout objects} is
219 @code{\override}. Because this command has to modify
220 internal properties deep within LilyPond its syntax is not
221 as simple as the commands you have used so far. It needs to
222 know precisely which property of which object in which context
223 has to be modified, and what its new value is to be. Let's see
226 The general syntax of this command is:
229 \override @var{Context}.@var{LayoutObject}.@var{layout-property} = #@var{value}
233 This will set the property with the name @var{layout-property} of the
234 layout object with the name @var{LayoutObject}, which is a member of
235 the @var{Context} context, to the value @var{value}.
237 The @var{Context} may be omitted (and usually is) when the
238 required context is unambiguously implied and is one of lowest
239 level contexts, i.e., @code{Voice}, @code{ChordNames} or
240 @code{Lyrics}, and we shall omit it in many of the following
241 examples. We shall see later when it must be specified.
243 Later sections deal comprehensively with properties and their
244 values, see @ref{Types of properties}. But in this section we shall
245 use just a few simple properties and values which are easily
246 understood in order to illustrate the format and use of these
249 LilyPond's primary expressions are musical items like notes,
250 durations, and markups. More basic expressions like numbers,
251 strings, and lists are processed in @q{Scheme mode}, which is
252 invoked by prefixing the value with @samp{#}. Although the
253 values may sometimes have a valid representation in LilyPond's
254 musical mode, this manual will always use @samp{#} for their
255 entry for the sake of consistency. For more information about
256 Scheme mode, see @rextend{LilyPond Scheme syntax}.
258 @code{\override} is the most common command used in tweaking, and
259 most of the rest of this chapter will be directed to presenting
260 examples of how it is used. Here is a simple example to change the
261 color of the note head:
263 @cindex color property, example
264 @cindex NoteHead, example of overriding
266 @lilypond[quote,ragged-right,verbatim]
269 \override NoteHead.color = #red
271 \override NoteHead.color = #green
277 @node The revert command
278 @unnumberedsubsubsec The @code{@bs{}revert} command
280 @cindex revert command
285 Once overridden, the property retains its new value until it is
286 overridden again or a @code{\revert} command is encountered.
287 The @code{\revert} command has the following syntax and causes
288 the value of the property to revert to its original default
289 value; note, not its previous value if several @code{\override}
290 commands have been issued.
293 \revert @var{Context}.@var{LayoutObject}.@var{layout-property}
296 Again, just like @var{Context} in the @code{\override} command,
297 @var{Context} is often not needed. It will be omitted
298 in many of the following examples. Here we revert the color
299 of the note head to the default value for the final two notes:
301 @cindex color property, example
302 @cindex NoteHead, example of overriding
304 @lilypond[quote,ragged-right,verbatim]
307 \override NoteHead.color = #red
309 \override NoteHead.color = #green
311 \revert NoteHead.color
317 @node The once prefix
318 @unnumberedsubsubsec The @code{@bs{}once} prefix
323 @code{\override}, @code{\revert}. @code{\set}, and @code{\unset}
324 commands may be prefixed with @code{\once}. This causes such a
325 command to be effective only during the current musical
326 moment before the property reverts back to its previous value (this can
327 be different from the default if another @code{\override} is still in
328 effect). Using the same example, we can change the color of a single
331 @cindex color property, example
332 @cindex NoteHead, example of overriding
334 @lilypond[quote,verbatim]
337 \override NoteHead.color = #red
339 \once \override NoteHead.color = #green
341 \once \revert NoteHead.color
343 \revert NoteHead.color
348 The @code{\once} prefix may also be used in front of many
349 predefined commands to limit their effect to one musical moment:
351 @lilypond[quote,verbatim]
362 @node The overrideProperty command
363 @unnumberedsubsubsec The @code{@bs{}overrideProperty} command
365 @cindex overrideProperty command
367 @funindex \overrideProperty
368 @funindex overrideProperty
370 There is another form of the override command,
371 @code{\overrideProperty}, which is occasionally required.
372 We mention it here for completeness, but for details see
373 @rextend{Difficult tweaks}.
374 @c Maybe explain in a later iteration -td
377 @node The tweak command
378 @unnumberedsubsubsec The @code{@bs{}tweak} command
380 @cindex tweak command
385 The final tweaking command which is available is @code{\tweak}. This
386 should be used when several objects occur at the same musical moment,
387 but you only want to change the properties of selected ones, such as a
388 single note within a chord. Using @code{\override} would affect all the
389 notes within a chord, whereas @code{\tweak} affects just the following
390 item in the input stream.
392 Here's an example. Suppose we wish to change the size of the
393 middle note head (the E) in a C major chord. Let's first see what
394 @code{\once \override} would do:
396 @cindex font-size property, example
397 @cindex NoteHead, example of overriding
399 @lilypond[quote,ragged-right,verbatim]
402 \once \override NoteHead.font-size = #-3
408 We see the override affects @emph{all} the note heads in the chord.
409 This is because all the notes of a chord occur at the same
410 @emph{musical moment}, and the action of @code{\once} is to
411 apply the override to all layout objects of the type specified
412 which occur at the same musical moment as the @code{\override}
415 The @code{\tweak} command operates in a different way. It acts on
416 the immediately following item in the input stream. In its simplest
417 form, it is effective only on objects which are created directly
418 from the following item, essentially note heads and articulations.
420 So to return to our example, the size of the middle note of
421 a chord would be changed in this way:
423 @cindex font-size property, example
424 @cindex @code{\tweak}, example
426 @lilypond[quote,ragged-right,verbatim]
429 <c \tweak font-size #-3 e g>4
433 Note that the syntax of @code{\tweak} is different from that of the
434 @code{\override} command. The context should not be specified; in
435 fact, it would generate an error to do so. Both context and layout
436 object are implied by the following item in the input stream. Note
437 also that an equals sign should not be present. So the simple form
438 of the @code{\tweak} command is
441 \tweak @var{layout-property} #@var{value}
444 A @code{\tweak} command can also be used to modify just one in
445 a series of articulations, as shown here:
447 @cindex color property, example
448 @cindex @code{\tweak}, example
450 @lilypond[quote,fragment,ragged-right,verbatim]
452 -\tweak color #red ^"Red"
453 -\tweak color #green _"Green"
457 Note that the @code{\tweak} command must be preceded by an articulation
458 mark since the tweaked expression needs to be applied as an articulation
459 itself. In case of multiple direction overrides (@code{^} or @code{_}),
460 the leftmost override wins since it is applied last.
462 @cindex @code{\tweak}, Accidental
463 @cindex @code{\tweak}, specific layout object
465 Objects such as stems and accidentals are created later, and not
466 directly from the following event. It is still possible to use
467 @code{\tweak} on such indirectly created objects by explicitly naming
468 the layout object, provided that LilyPond can trace its origin back to
471 @lilypond[quote,fragment,ragged-right,verbatim]
472 <\tweak Accidental.color #red cis''4
473 \tweak Accidental.color #green es''
477 This long form of the @code{\tweak} command can be described as
480 \tweak @var{LayoutObject}.@var{layout-property} #@var{value}
483 @cindex tuplets, nested
484 @cindex triplets, nested
485 @cindex bracket, tuplet
486 @cindex bracket, triplet
487 @cindex tuplet bracket
488 @cindex triplet bracket
490 @funindex TupletBracket
492 The @code{\tweak} command must also be used to change the
493 appearance of one of a set of nested tuplets which begin at the
494 same musical moment. In the following example, the long tuplet
495 bracket and the first of the three short brackets begin at the
496 same musical moment, so any @code{\override} command would apply
497 to both of them. In the example, @code{\tweak} is used to
498 distinguish between them. The first @code{\tweak} command
499 specifies that the long tuplet bracket is to be placed above the
500 notes and the second one specifies that the tuplet number is to be
501 printed in red on the first short tuplet bracket.
503 @cindex @code{\tweak}, example
504 @cindex direction property, example
505 @cindex color property, example
507 @lilypond[quote,ragged-right,verbatim]
512 \tuplet 3/2 { c8[ c c] }
513 \tuplet 3/2 { c8[ c c] }
514 \tuplet 3/2 { c8[ c c] }
519 If nested tuplets do not begin at the same moment, their
520 appearance may be modified in the usual way with
521 @code{\override} commands:
523 @cindex text property, example
524 @cindex tuplet-number function, example
525 @cindex transparent property, example
526 @cindex TupletNumber, example of overriding
528 @lilypond[quote,ragged-right,verbatim]
530 \tuplet 3/2 { c'8[ c c] }
531 \once \override TupletNumber.text = #tuplet-number::calc-fraction-text
535 \once \override TupletNumber.transparent = ##t
536 \tuplet 3/2 { c8[ c c] }
537 \tuplet 3/2 { c8[ c c] }
545 @ruser{The tweak command}.
547 @node The single prefix
548 @unnumberedsubsubsec The @code{@bs{}single} prefix
551 @cindex tweak, generated from override
553 Suppose we wanted to emphasize particular note heads by coloring them
554 red and increasing their size, and to make it easy suppose also we
555 have defined a function to do this:
557 @lilypond[quote,verbatim]
559 \override NoteHead.color = #red
560 \override NoteHead.font-size = 2
563 c''4 a \once \emphNoteHead f d |
567 The @code{\once} prefix works fine to emphasize single notes or
568 complete chords, but it cannot be used to emphasize a single note
569 @emph{within} a chord. Earlier we have seen how @code{\tweak} can
570 be used to do this, see
571 @ref{The tweak command,,The @code{@bs{}tweak} command}. But
572 @code{\tweak} cannot be used with a function; that's where
573 @code{\single} comes in:
575 @lilypond[quote,verbatim]
577 \override NoteHead.color = #red
578 \override NoteHead.font-size = 2
581 <c'' a \single \emphNoteHead f d>4
585 In summary, @code{\single} converts overrides into tweaks so when
586 there are several objects at the same point in musical time (like
587 noteheads in a chord), @code{\single} will only affect a single one,
588 the one generated by the immediately following music expression, in
589 contrast to @code{\once} which will affect all of those objects.
591 By using @code{\single} in this way any shorthand function
592 containing just overrides may be applied to individual notes in a
593 chord. However, @code{\single} does not convert @code{\revert},
594 @code{\set} or @code{\unset} into tweaks.
598 @ref{The tweak command,,The @code{@bs{}tweak} command},
599 @ref{Using variables for layout adjustments}.
602 @node The Internals Reference manual
603 @section The Internals Reference manual
605 @cindex Internals Reference
608 * Properties of layout objects::
609 * Properties found in interfaces::
610 * Types of properties::
613 @node Properties of layout objects
614 @subsection Properties of layout objects
616 @cindex properties of layout objects
617 @cindex properties of grobs
618 @cindex grobs, properties of
619 @cindex layout objects, properties of
620 @cindex Internals Reference manual
622 Suppose you have a slur in a score which, to your mind,
623 appears too thin and you'd like to draw it a little heavier.
624 How do you go about doing this? You know from the statements
625 earlier about the flexibility of LilyPond that such a thing
626 should be possible, and you would probably guess that an
627 @code{\override} command would be needed. But is there a
628 heaviness property for a slur, and if there is, how might it
629 be modified? This is where the Internals Reference manual
630 comes in. It contains all the information you might need to
631 construct this and all other @code{\override} commands.
633 Before we look at the Internals Reference a word of warning.
634 This is a @strong{reference} document, which means there is
635 little or no explanation contained within it: its purpose is
636 to present information precisely and concisely. This
637 means it might look daunting at first sight. Don't worry!
638 The guidance and explanation presented here will enable you
639 to extract the information from the Internals Reference for
640 yourself with just a little practice.
642 @cindex override example
643 @cindex Internals Reference, example of using
644 @cindex @code{\addlyrics} example
646 Let's use a concrete example with a simple fragment of real
649 @c Mozart, Die Zauberflöte Nr.7 Duett
651 @lilypond[quote,verbatim]
656 r4 bes'8 bes[( g]) g |
657 g8[( es]) es d[( f]) as |
661 The man who | feels love's sweet e -- | mo -- tion
666 Suppose now that we decide we would like the slurs to be a
667 little heavier. Is this possible? The slur is certainly a
668 layout object, so the question is, @q{Is there a property
669 belonging to a slur which controls the heaviness?} To answer
670 this we must look in the Internals Reference, or IR for short.
672 The IR for the version of LilyPond you are using may be found
673 on the LilyPond website at @uref{http://lilypond.org}. Go to the
674 documentation page and click on the Internals Reference link.
675 For learning purposes you should use the standard HTML version,
676 not the @q{one big page} or the PDF. For the next few
677 paragraphs to make sense you will need to actually do this
680 Under the heading @strong{Top} you will see five links. Select
681 the link to the @emph{Backend}, which is where information about
682 layout objects is to be found. There, under the heading
683 @strong{Backend}, select the link to @emph{All layout objects}.
684 The page that appears lists all the layout objects used in your
685 version of LilyPond, in alphabetic order. Select the link to
686 Slur, and the properties of Slurs are listed.
688 An alternative way of finding this page is from the Notation
689 Reference. On one of the pages that deals with slurs you may find a
690 link to the Internals Reference. This link will take you directly to
691 this page, but if you have an idea about the name of the layout object
692 to be tweaked, it is easier to go straight to the IR and search there.
694 This Slur page in the IR tells us first that Slur objects are created
695 by the Slur_engraver. Then it lists the standard settings. Browse
696 through them looking for a property that might control the heaviness of
697 slurs, and you should find
700 @code{thickness} (number)
702 Line thickness, generally measured in @code{line-thickness}
705 This looks a good bet to change the heaviness. It tells us that
706 the value of @code{thickness} is a simple @emph{number},
707 that the default value is 1.2, and that the units are
708 in another property called @code{line-thickness}.
710 As we said earlier, there are few to no explanations in the IR,
711 but we already have enough information to try changing the
712 slur thickness. We see that the name of the layout object
713 is @code{Slur}, that the name of the property to change is
714 @code{thickness} and that the new value should be a number
715 somewhat larger than 1.2 if we are to make slurs thicker.
717 We can now construct the @code{\override} command by simply
718 substituting the values we have found for the names, omitting
719 the context. Let's use a very large value for the thickness
720 at first, so we can be sure the command is working. We get:
723 \override Slur.thickness = #5.0
726 Don't forget the@tie{}@code{#} preceding the new value!
728 The final question is, @q{Where should this command be
729 placed?} While you are unsure and learning, the best
730 answer is, @q{Within the music, before the first slur and
731 close to it.} Let's do that:
733 @cindex Slur example of overriding
734 @cindex thickness property, example
736 @lilypond[quote,verbatim]
741 % Increase thickness of all following slurs from 1.2 to 5.0
742 \override Slur.thickness = #5.0
743 r4 bes'8 bes[( g]) g |
744 g8[( es]) es d[( f]) as |
748 The man who | feels love's sweet e -- | mo -- tion
754 and we see that the slur is indeed heavier.
756 So this is the basic way of constructing @code{\override}
757 commands. There are a few more complications that we
758 shall meet in later sections, but you now know all the
759 essentials required to make up your own -- but you will
760 still need some practice. This is provided in the examples
763 @subsubsubheading Finding the context
765 @cindex context, finding
766 @cindex context, identifying correct
768 But first, what if we had needed to specify the Context?
769 What should it be? We could guess that slurs are in
770 the Voice context, as they are clearly closely associated
771 with individual lines of music, but can we be sure? To
772 find out, go back to the top of the IR page describing the
773 Slur, where it says @q{Slur objects are created by: Slur
774 engraver}. So slurs will be created in whichever context
775 the @code{Slur_engraver} is in. Follow the link to the
776 @code{Slur_engraver} page. At the very bottom it tells
777 us that @code{Slur_engraver} is part of seven Voice contexts,
778 including the standard voice context, @code{Voice}, so our
779 guess was correct. And because @code{Voice} is one of the
780 lowest level contexts which is implied unambiguously by
781 the fact that we are entering notes, we can omit it in this
784 @subsubsubheading Overriding once only
786 @cindex overriding once only
787 @cindex once override
792 As you can see, @emph{all} the slurs are thicker in the final example
793 above. But what if we wanted just the first slur to be thicker? This
794 is achieved with the @code{\once} command. Placed immediately before
795 the @code{\override} command it causes it to change only the slur
796 which begins on the @strong{immediately following} note. If the
797 immediately following note does not begin a slur the command has no
798 effect at all -- it is not remembered until a slur is encountered, it
799 is simply discarded. So the command with @code{\once} must be
800 repositioned as follows:
802 @cindex Slur, example of overriding
803 @cindex thickness property, example
805 @lilypond[quote,verbatim]
811 % Increase thickness of immediately following slur only
812 \once \override Slur.thickness = #5.0
814 g8[( es]) es d[( f]) as |
818 The man who | feels love's sweet e -- | mo -- tion
824 Now only the first slur is made heavier.
826 The @code{\once} command can also be used before the @code{\set}
829 @subsubsubheading Reverting
832 @cindex default properties, reverting to
837 Finally, what if we wanted just the first two slurs to be
838 heavier? Well, we could use two commands, each preceded by
839 @code{\once} placed immediately before each of the notes where
842 @cindex Slur, example of overriding
843 @cindex thickness property, example
845 @lilypond[quote,verbatim]
851 % Increase thickness of immediately following slur only
852 \once \override Slur.thickness = #5.0
854 % Increase thickness of immediately following slur only
855 \once \override Slur.thickness = #5.0
856 g8[( es]) es d[( f]) as |
860 The man who | feels love's sweet e -- | mo -- tion
866 or we could omit the @code{\once} command and use the @code{\revert}
867 command to return the @code{thickness} property to its default value
868 after the second slur:
870 @cindex Slur, example of overriding
871 @cindex thickness property, example
873 @lilypond[quote,verbatim]
879 % Increase thickness of all following slurs from 1.2 to 5.0
880 \override Slur.thickness = #5.0
883 % Revert thickness of all following slurs to default of 1.2
884 \revert Slur.thickness
889 The man who | feels love's sweet e -- | mo -- tion
895 The @code{\revert} command can be used to return any property
896 changed with @code{\override} back to its default value.
897 You may use whichever method best suits what you want to do.
899 That concludes our introduction to the IR, and the basic
900 method of tweaking. Several examples follow in the later
901 sections of this Chapter, partly to introduce you to some of the
902 additional features of the IR, and partly to give you more
903 practice in extracting information from it. These examples will
904 contain progressively fewer words of guidance and explanation.
907 @node Properties found in interfaces
908 @subsection Properties found in interfaces
911 @cindex interface properties
912 @cindex properties in interfaces
914 Suppose now that we wish to print the lyrics in italics. What form of
915 @code{\override} command do we need to do this? We first look in the
916 IR page listing @q{All layout objects}, as before, and look for an
917 object that might control lyrics. We find @code{LyricText}, which
918 looks right. Clicking on this shows the settable properties for lyric
919 text. These include the @code{font-series} and @code{font-size}, but
920 nothing that might give an italic shape. This is because the shape
921 property is one that is common to all font objects, so, rather than
922 including it in every layout object, it is grouped together with other
923 similar common properties and placed in an @strong{Interface}, the
924 @code{font-interface}.
926 So now we need to learn how to find the properties of interfaces,
927 and to discover what objects use these interface properties.
929 Look again at the IR page which describes LyricText. At the bottom of
930 the page is a list of clickable interfaces which LyricText supports.
931 The list has several items, including @code{font-interface}. Clicking
932 on this brings up the properties associated with this interface, which
933 are also properties of all the objects which support it, including
936 Now we see all the user-settable properties which control fonts,
937 including @code{font-shape(symbol)}, where @code{symbol} can be
938 set to @code{upright}, @code{italics} or @code{caps}.
940 You will notice that @code{font-series} and @code{font-size} are also
941 listed there. This immediately raises the question: Why are the
942 common font properties @code{font-series} and @code{font-size} listed
943 under @code{LyricText} as well as under the interface
944 @code{font-interface} but @code{font-shape} is not? The answer is
945 that @code{font-series} and @code{font-size} are changed from their
946 global default values when a @code{LyricText} object is created, but
947 @code{font-shape} is not. The entries in @code{LyricText} then tell
948 you the values for those two properties which apply to
949 @code{LyricText}. Other objects which support @code{font-interface}
950 will set these properties differently when they are created.
952 Let's see if we can now construct the @code{\override} command
953 to change the lyrics to italics. The object is @code{LyricText},
954 the property is @code{font-shape} and the value is
955 @code{italic}. As before, we'll omit the context.
957 As an aside, although it is an important one, note that some
958 properties take values that are symbols, like @code{italic}, and
959 must be preceded by an apostrophe, @code{'}. Symbols are then
960 read internally by LilyPond. Note the distinction from arbitrary
961 text strings, which would appear as @code{"a text string"}; for
962 more details about symbols and strings, see @rextend{Scheme tutorial}.
964 So we see that the @code{\override} command needed to print the lyrics
968 \override LyricText.font-shape = #'italic
972 This should be placed just in front of the lyrics we wish to affect,
975 @cindex font-shape property, example
976 @cindex italic, example
977 @cindex LyricText, example of overriding
978 @cindex @code{\addlyrics}, example
980 @lilypond[quote,ragged-right,verbatim]
985 r4 bes'8 bes[( g]) g |
986 g8[( es]) es d[( f]) as |
990 \override LyricText.font-shape = #'italic
991 The man who | feels love's sweet e -- | mo -- tion
997 and the lyrics are all printed in italics.
999 @warning{In lyrics always leave whitespace between the final
1000 syllable and the terminating brace.}
1004 Extending: @rextend{Scheme tutorial}.
1007 @node Types of properties
1008 @subsection Types of properties
1010 @cindex property types
1012 So far we have seen two types of property: @code{number} and
1013 @code{symbol}. To be valid, the value given to a property
1014 must be of the correct type and obey the rules for that type.
1015 The type of property is always shown in brackets after the
1016 property name in the IR. Here is a list of the types you may
1017 need, together with the rules for that type, and some examples.
1018 You must always add a hash symbol, @code{#}, of course,
1019 to the front of these values when they are entered in the
1020 @code{\override} command, even if the value itself already
1021 starts with@tie{}@code{#}. We only give examples for constants
1022 here: if you want to compute a value using Scheme, see
1023 @rextend{Calculations in Scheme}.
1025 @multitable @columnfractions .2 .45 .35
1026 @headitem Property type
1030 @tab Either True or False, represented by #t or #f
1031 @tab @code{#t}, @code{#f}
1032 @item Dimension (in staff space)
1033 @tab A decimal number (in units of staff space)
1034 @tab @code{2.5}, @code{0.34}
1036 @tab A valid direction constant or its numerical equivalent
1037 (@code{0} or @code{CENTER} indicate a neutral direction)
1038 @tab @code{LEFT}, @code{CENTER}, @code{UP},
1039 @code{1}, @w{@code{-1}}
1042 @tab @code{3}, @code{-1}
1044 @tab A sequence of constants or symbols separated by spaces, enclosed
1046 and preceded by an apostrophe (quote mark)
1047 @tab @code{'(left-edge staff-bar)}, @code{'(1)}, @code{'()},
1048 @code{'(1.0 0.25 0.5)}
1050 @tab Any valid markup
1051 @tab @code{\markup @{ \italic "cresc." @}}, @code{"bagpipe"}
1053 @tab A fraction of a whole note constructed with the
1054 make-moment function
1055 @tab @code{(ly:make-moment 1/4)},
1056 @code{(ly:make-moment 3/8)}
1058 @tab Any positive or negative, possibly decimal, value
1059 @tab @code{3}, @w{@code{-2.45}}
1060 @item Pair (of numbers)
1061 @tab Two numbers separated by a @q{space . space} and enclosed
1062 in brackets preceded by an apostrophe
1063 @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
1065 @tab Any of the set of permitted symbols for that property,
1066 preceded by an apostrophe
1067 @tab @code{'italic}, @code{'inside}
1069 @tab A procedure, or @code{#f} to cause no action
1070 @tab @code{bend::print}, @code{ly:text-interface::print},
1074 enclosed in @code{#(}@dots{}@code{)}.
1075 @tab @code{#(#t #t #f)}
1080 Extending: @rextend{Scheme tutorial}.
1083 @node Appearance of objects
1084 @section Appearance of objects
1086 Let us now put what we have learned into practice with a few
1087 examples which show how tweaks may be used to change the
1088 appearance of the printed music.
1091 * Visibility and color of objects::
1093 * Length and thickness of objects::
1096 @node Visibility and color of objects
1097 @subsection Visibility and color of objects
1099 In the educational use of music we might wish to print a score
1100 with certain elements omitted as an exercise for the student,
1101 who is required to supply them. As a simple example,
1102 let us suppose the exercise is to supply the missing bar lines
1103 in a piece of music. But the bar lines are normally inserted
1104 automatically. How do we prevent them printing?
1106 Before we tackle this, let us remember that object properties are
1107 grouped in what are called @emph{interfaces} -- see @ref{Properties
1108 found in interfaces}. This is simply to group together those
1109 properties that may be used together to tweak a graphical object -- if
1110 one of them is allowed for an object, so are the others. Some objects
1111 then use the properties in some interfaces, others use them from other
1112 interfaces. The interfaces which contain the properties used by a
1113 particular grob are listed in the IR at the bottom of the page
1114 describing that grob, and those properties may be viewed by looking at
1117 We explained how to find information about grobs in @ref{Properties of
1118 layout objects}. Using the same approach, we go to the IR to find the
1119 layout object which prints bar lines. Going via @emph{Backend} and
1120 @emph{All layout objects} we find there is a layout object called
1121 @code{BarLine}. Its properties include two that control its
1122 visibility: @code{break-visibility} and @code{stencil}. Barline also
1123 supports a number of interfaces, including the @code{grob-interface},
1124 where we find the @code{transparent} and the @code{color} properties.
1125 All of these can affect the visibility of bar lines (and, of course,
1126 by extension, many other layout objects too.) Let's consider each of
1130 * The stencil property::
1131 * The break-visibility property::
1132 * The transparent property::
1133 * The color property::
1136 @node The stencil property
1137 @unnumberedsubsubsec The @code{stencil} property
1139 @cindex stencil property
1141 This property controls the appearance of the bar lines by specifying
1142 the symbol (glyph) which should be printed. In common
1143 with many other properties, it can be set to print nothing by
1144 setting its value to @code{#f}. Let's try it, as before, omitting
1145 the implied Context, @code{Voice}:
1147 @cindex BarLine, example of overriding
1148 @cindex stencil property, example
1150 @lilypond[quote,ragged-right,verbatim]
1153 \override BarLine.stencil = ##f
1154 c''4 b8 c d16 c d8 |
1155 g,8 a16 b8 c d4 e16 |
1160 The bar lines are still printed. What is wrong? Go back to the IR
1161 and look again at the page giving the properties of BarLine. At the
1162 top of the page it says @qq{Barline objects are created by:
1163 Bar_engraver}. Go to the @code{Bar_engraver} page. At the bottom it
1164 gives a list of Contexts in which the bar engraver operates. All of
1165 them are of the type @code{Staff}, so the reason the @code{\override}
1166 command failed to work as expected is because @code{Barline} is not in
1167 the default @code{Voice} context. If the context is specified
1168 incorrectly, the command simply does not work. No error message is
1169 produced, and nothing is logged in the log file. Let's try correcting
1170 it by adding the correct context:
1172 @cindex BarLine, example of overriding
1173 @cindex stencil property, example
1175 @lilypond[quote,ragged-right,verbatim]
1178 \override Staff.BarLine.stencil = ##f
1179 c''4 b8 c d16 c d8 |
1180 g,8 a16 b8 c d4 e16 |
1185 Now the bar lines have vanished. Setting the @code{stencil}
1186 property to @code{#f} is such a frequent operation that there is a
1187 shorthand for it called @code{\omit}:
1190 @lilypond[quote,ragged-right,verbatim]
1194 c''4 b8 c d16 c d8 |
1195 g,8 a16 b8 c d4 e16 |
1200 Note, though, that setting the @code{stencil} property to @code{#f}
1201 will cause errors when the dimensions of the object are required for
1202 correct processing. For example, errors will be generated if the
1203 @code{stencil} property of the @code{NoteHead} object is set to
1204 @code{#f}. If this is the case, you can instead use the
1205 @code{point-stencil} function, which sets the stencil to an object
1208 @lilypond[quote,verbatim]
1211 \once \override NoteHead.stencil = #point-stencil
1216 @node The break-visibility property
1217 @unnumberedsubsubsec The @code{break-visibility} property
1219 @cindex break-visibility property
1221 We see from the @code{BarLine} properties in the IR that the
1222 @code{break-visibility} property requires a vector of three booleans.
1223 These control respectively whether bar lines are printed at the end of
1224 a line, in the middle of lines, and at the beginning of lines. For
1225 our example we want all bar lines to be suppressed, so the value we
1226 need is @code{#(#f #f #f)} (also available
1227 under the name @code{all-invisible}). Let's try that, remembering to include
1228 the @code{Staff} context. Note also that in writing this value we
1229 have @code{##} before the opening parenthesis. One @code{#} is required
1230 as part of vector constant syntax, and the first@tie{}@code{#} is
1231 required, as always, to precede the value itself in the
1232 @code{\override} command.
1234 @cindex BarLine, example of overriding
1235 @cindex break-visibility property, example
1237 @lilypond[quote,ragged-right,verbatim]
1240 \override Staff.BarLine.break-visibility = ##(#f #f #f)
1241 c''4 b8 c d16 c d8 |
1242 g,8 a16 b8 c d4 e16 |
1247 And we see this too removes all the bar lines.
1249 @node The transparent property
1250 @unnumberedsubsubsec The @code{transparent} property
1252 @cindex transparent property
1253 @cindex transparency
1255 We see from the properties specified in the @code{grob-interface} page
1256 in the IR that the @code{transparent} property is a boolean. This
1257 should be set to @code{#t} to make the grob transparent. In this next
1258 example let us make the time signature invisible rather than the bar
1259 lines. To do this we need to find the grob name for the time
1260 signature. Back to the @q{All layout objects} page in the IR to find
1261 the properties of the @code{TimeSignature} layout object. This is
1262 produced by the @code{Time_signature_engraver} which you can check
1263 also lives in the @code{Staff} context and also supports the
1264 @code{grob-interface}. So the command to make the time signature
1267 @cindex TimeSignature, example of overriding
1268 @cindex transparent property, example
1270 @lilypond[quote,ragged-right,verbatim]
1273 \override Staff.TimeSignature.transparent = ##t
1274 c''4 b8 c d16 c d8 |
1275 g,8 a16 b8 c d4 e16 |
1281 Again, setting the @code{transparent} property is a rather
1282 frequent operation, so we have a shorthand for it called
1286 @lilypond[quote,ragged-right,verbatim]
1289 \hide Staff.TimeSignature
1290 c''4 b8 c d16 c d8 |
1291 g,8 a16 b8 c d4 e16 |
1297 In either case, the time signature is gone, but this command
1299 the time signature should be. Maybe this is what is wanted for
1300 an exercise for the student to fill it in, but in other
1301 circumstances a gap might be undesirable. To remove it, the
1302 stencil for the time signature should be set to @code{#f}
1305 @cindex TimeSignature, example of overriding
1306 @cindex stencil property, example
1308 @lilypond[quote,ragged-right,verbatim]
1311 \omit Staff.TimeSignature
1312 c''4 b8 c d16 c d8 |
1313 g,8 a16 b8 c d4 e16 |
1319 and the difference is obvious: setting the stencil to @code{#f}
1320 (possibly via @code{\omit})
1321 removes the object entirely; making the object @code{transparent}
1322 (which can be done using @code{\hide})
1323 leaves it where it is, but makes it invisible.
1325 @node The color property
1326 @unnumberedsubsubsec The @code{color} property
1328 @cindex color property
1330 Finally let us try making the bar lines invisible by coloring
1331 them white. (There is a difficulty with this in that the
1332 white bar line may or may not blank out the staff lines where
1333 they cross. You may see in some of the examples below that this
1334 happens unpredictably. The details of why this is so and how to
1335 control it are covered in @ruser{Painting objects white}. But at
1336 the moment we are learning about color, so please just accept this
1337 limitation for now.)
1339 The @code{grob-interface} specifies that the
1340 color property value is a list, but there is no
1341 explanation of what that list should be. The list it
1342 requires is actually a list of values in internal units,
1343 but, to avoid having to know what these are, several ways
1344 are provided to specify colors. The first way is to use one
1345 of the @q{normal} colors listed in the first table in
1346 @ruser{List of colors}. To set the bar lines to white
1349 @cindex BarLine, example of overriding
1350 @cindex color property, example
1352 @lilypond[quote,ragged-right,verbatim]
1355 \override Staff.BarLine.color = #white
1356 c''4 b8 c d16 c d8 |
1357 g,8 a16 b8 c d4 e16 |
1363 and again, we see the bar lines are not visible. Note that
1364 @emph{white} is not preceded by an apostrophe -- it is not
1365 a symbol, but a @emph{variable}. When evaluated, it provides
1366 the list of internal values required to set the color to
1367 white. The other colors in the normal list are variables
1368 too. To convince yourself this is working you might like
1369 to change the color to one of the other variables in the
1377 The second way of changing the color is to use the list of
1378 X11 color names in the second list in @ruser{List of colors}.
1379 However, these are mapped to the actual values by the function
1380 @code{x11-color} which
1381 converts X11 color symbols into the list of internal values like this:
1383 @cindex BarLine, example of overriding
1384 @cindex color property, example
1386 @lilypond[quote,ragged-right,verbatim]
1389 \override Staff.BarLine.color = #(x11-color 'white)
1390 c''4 b8 c d16 c d8 |
1391 g,8 a16 b8 c d4 e16 |
1397 Note that in this case the function @code{x11-color} takes
1398 a symbol as an argument, so the symbol must be preceded by
1399 an apostrophe to keep it from being evaluated as a variable, and
1400 the whole function call has to be enclosed in parentheses.
1407 There is another function, one which converts RGB values into
1408 internal colors -- the @code{rgb-color} function. This takes
1409 three arguments giving the intensities of the red, green and
1410 blue colors. These take values in the range 0 to 1. So to
1411 set the color to red the value should be @code{(rgb-color 1 0 0)}
1412 and to white it should be @code{(rgb-color 1 1 1)}:
1414 @cindex BarLine, example of overriding
1415 @cindex color property, example
1417 @lilypond[quote,ragged-right,verbatim]
1420 \override Staff.BarLine.color = #(rgb-color 1 1 1)
1421 c''4 b8 c d16 c d8 |
1422 g,8 a16 b8 c d4 e16 |
1427 Finally, there is also a grey scale available as part of the
1428 X11 set of colors. These range from black, @code{'grey0},
1429 to white, @code{'grey100}, in steps of 1. Let's illustrate
1430 this by setting all the layout objects in our example to
1431 various shades of grey:
1433 @cindex StaffSymbol, example of overriding
1434 @cindex TimeSignature, example of overriding
1435 @cindex Clef, example of overriding
1436 @cindex NoteHead, example of overriding
1437 @cindex Stem, example of overriding
1438 @cindex BarLine, example of overriding
1439 @cindex color property, example
1440 @cindex x11-color, example of using
1442 @lilypond[quote,ragged-right,verbatim]
1445 \override Staff.StaffSymbol.color = #(x11-color 'grey30)
1446 \override Staff.TimeSignature.color = #(x11-color 'grey60)
1447 \override Staff.Clef.color = #(x11-color 'grey60)
1448 \override Voice.NoteHead.color = #(x11-color 'grey85)
1449 \override Voice.Stem.color = #(x11-color 'grey85)
1450 \override Staff.BarLine.color = #(x11-color 'grey10)
1451 c''4 b8 c d16 c d8 |
1452 g,8 a16 b8 c d4 e16 |
1458 Note the contexts associated with each of the layout objects.
1459 It is important to get these right, or the commands will not
1460 work! Remember, the context is the one in which the appropriate
1461 engraver is placed. The default context for engravers can be
1462 found by starting from the layout object, going from there to
1463 the engraver which produces it, and on the engraver page in the
1464 IR it tells you in which context the engraver will normally be
1468 @node Size of objects
1469 @subsection Size of objects
1471 @cindex changing size of objects
1472 @cindex size of objects
1473 @cindex objects, size of
1474 @cindex objects, changing size of
1476 Let us begin by looking again at the earlier example
1477 (see @ref{Nesting music expressions}) which showed
1478 how to introduce a new temporary staff, as in an @rglos{ossia}.
1480 @cindex alignAboveContext property, example
1481 @cindex @code{\with}, example
1483 @lilypond[quote,ragged-right,verbatim]
1484 \new Staff ="main" {
1491 alignAboveContext = #"main" }
1499 Ossia are normally written without clef and time signature, and
1500 are usually printed slightly smaller than the main staff. We
1501 already know now how to remove the clef and time signature --
1502 we simply set the stencil of each to @code{#f}, as follows:
1504 @cindex alignAboveContext property, example
1505 @cindex @code{\with}, example
1507 @cindex Clef, example of overriding
1508 @cindex TimeSignature, example of overriding
1510 @lilypond[quote,ragged-right,verbatim]
1511 \new Staff ="main" {
1518 alignAboveContext = #"main"
1522 \omit Staff.TimeSignature
1532 where the extra pair of braces after the @code{\with} clause are
1533 required to ensure the enclosed overrides and music are applied
1536 But what is the difference between modifying the staff context by
1537 using @code{\with} and modifying the stencils of the clef and the
1538 time signature with @code{\override}, or in this case
1540 The main difference is that
1541 changes made in a @code{\with} clause are made at the time the
1542 context is created, and remain in force as the @strong{default}
1543 values for the duration of that context, whereas
1544 @code{\set} or @code{\override} commands embedded in the
1545 music are dynamic -- they make changes synchronized with
1546 a particular point in the music. If changes are unset or
1547 reverted using @code{\unset} or @code{\revert} they return to
1548 their default values, which will be the ones set in the
1549 @code{\with} clause, or if none have been set there, the normal
1552 Some context properties can be modified only in @code{\with} clauses.
1553 These are those properties which cannot sensibly be changed after the
1554 context has been created. @code{alignAboveContext} and its partner,
1555 @code{alignBelowContext}, are two such properties -- once the staff
1556 has been created its alignment is decided and it would make no sense
1557 to try to change it later.
1559 The default values of layout object properties can also be set
1560 in @code{\with} clauses. Simply use the normal @code{\override}
1561 command leaving out the context name, since this is unambiguously
1562 defined as the context which the @code{\with} clause is modifying.
1563 If fact, an error will be generated if a context is specified
1566 So we could replace the example above with
1568 @cindex alignAboveContext property, example
1569 @cindex @code{\with}, example
1570 @cindex Clef, example of overriding
1571 @cindex TimeSignature, example of overriding
1573 @lilypond[quote,ragged-right,verbatim]
1574 \new Staff ="main" {
1581 alignAboveContext = #"main"
1582 % Don't print clefs in this staff
1583 \override Clef.stencil = ##f
1584 % Don't print time signatures in this staff
1585 \override TimeSignature.stencil = ##f
1594 It turns out that we can also employ the shorthands @code{\hide}
1595 and @code{\omit} for setting the @code{transparent} property and
1596 clearing the @code{stencil} here, leading to the result
1598 @lilypond[quote,ragged-right,verbatim]
1599 \new Staff ="main" {
1606 alignAboveContext = #"main"
1607 % Don't print clefs in this staff
1609 % Don't print time signatures in this staff
1619 Finally we come to changing the size of layout objects.
1621 Some layout objects are created as glyphs selected from a typeface
1622 font. These include note heads, accidentals, markup, clefs, time
1623 signatures, dynamics and lyrics. Their size is changed by modifying
1624 the @code{font-size} property, as we shall shortly see. Other layout
1625 objects such as slurs and ties -- in general, spanner objects -- are
1626 drawn individually, so there is no @code{font-size} associated with
1627 them. These objects generally derive their size from the objects to
1628 which they are attached, so usually there is no need to change their
1629 size manually. Still other properties such as the length of stems and
1630 bar lines, thickness of beams and other lines, and the separation of
1631 staff lines all need to be modified in special ways.
1633 Returning to the ossia example, let us first change the font-size.
1634 We can do this in two ways. We can either change the size of the
1635 fonts of each object type, like @code{NoteHead}s with commands
1639 \override NoteHead.font-size = #-2
1642 or we can change the size of all fonts by setting a special
1643 property, @code{fontSize}, using @code{\set}, or by including
1644 it in a @code{\with} clause (but without the @code{\set}).
1650 Both of these statements would cause the font size to be reduced
1651 by 2 steps from its previous value, where each
1652 step reduces or increases the size by approximately 12%.
1654 Let's try it in our ossia example:
1656 @cindex alignAboveContext property, example
1657 @cindex @code{\with}, example
1658 @cindex Clef, example of overriding
1659 @cindex TimeSignature, example of overriding
1660 @cindex fontSize property, example
1662 @lilypond[quote,ragged-right,verbatim]
1663 \new Staff ="main" {
1670 alignAboveContext = #"main"
1673 % Reduce all font sizes by ~24%
1683 This is still not quite right. The note heads and flags are
1684 smaller, but the stems are too long in proportion and the
1685 staff lines are spaced too widely apart. These need to be
1686 scaled down in proportion to the font reduction. The next
1687 sub-section discusses how this is done.
1689 @node Length and thickness of objects
1690 @subsection Length and thickness of objects
1696 @cindex size, changing
1697 @cindex stem length, changing
1698 @cindex staff line spacing, changing
1700 Distances and lengths in LilyPond are generally measured in
1701 staff-spaces, the distance between adjacent lines in the staff,
1702 (or occasionally half staff spaces) while most @code{thickness}
1703 properties are measured in units of an internal property called
1704 @code{line-thickness.} For example, by default, the lines of
1705 hairpins are given a thickness of 1 unit of @code{line-thickness},
1706 while the @code{thickness} of a note stem is 1.3. Note, though,
1707 that some thickness properties are different; for example, the
1708 thickness of beams is controlled by the value of the
1709 @code{beam-thickness} property, which is measured in staff-spaces.
1711 So how are lengths to be scaled in proportion to the font size?
1712 This can be done with the help of a special function called
1713 @code{magstep} provided for exactly this purpose. It takes
1714 one argument, the change in font size (#-2 in the example above)
1715 and returns a scaling factor suitable for reducing other
1716 objects in proportion. It is used like this:
1718 @cindex alignAboveContext property, example
1719 @cindex @code{\with}, example
1720 @cindex Clef, example of overriding
1721 @cindex TimeSignature, example of overriding
1722 @cindex fontSize property, example
1723 @cindex StaffSymbol, example of overriding
1724 @cindex magstep function, example of using
1725 @cindex staff-space property, example
1726 @cindex stencil property, example
1728 @lilypond[quote,ragged-right,verbatim]
1729 \new Staff ="main" {
1736 alignAboveContext = #"main"
1740 % Reduce stem length and line spacing to match
1741 \override StaffSymbol.staff-space = #(magstep -2)
1751 Since the length of stems and many other length-related properties are
1752 always calculated relative to the value of the @code{staff-space}
1753 property these are automatically scaled down in length too. Note that
1754 this affects only the vertical scale of the ossia -- the horizontal
1755 scale is determined by the layout of the main music in order to remain
1756 synchronized with it, so it is not affected by any of these changes in
1757 size. Of course, if the scale of all the main music were changed in
1758 this way then the horizontal spacing would be affected. This is
1759 discussed later in the layout section.
1761 This, then, completes the creation of an ossia. The sizes and
1762 lengths of all other objects may be modified in analogous ways.
1764 For small changes in scale, as in the example above, the
1765 thickness of the various drawn lines such as bar lines,
1766 beams, hairpins, slurs, etc does not usually require global
1767 adjustment. If the thickness of any particular layout object
1768 needs to be adjusted this can be best achieved by overriding its
1769 @code{thickness} property. An example of changing the thickness
1770 of slurs was shown above in @ref{Properties of layout objects}.
1771 The thickness of all drawn objects (i.e., those not produced
1772 from a font) may be changed in the same way.
1775 @node Placement of objects
1776 @section Placement of objects
1779 * Automatic behavior::
1780 * Within-staff objects::
1781 * Outside-staff objects::
1785 @node Automatic behavior
1786 @subsection Automatic behavior
1788 @cindex within-staff objects
1789 @cindex outside-staff objects
1790 @cindex objects, within-staff
1791 @cindex objects, outside-staff
1793 There are some objects in musical notation that belong to
1794 the staff and there are other objects that should be
1795 placed outside the staff. These are called within-staff
1796 objects and outside-staff objects respectively.
1798 Within-staff objects are those that are located on the staff
1799 -- note heads, stems, accidentals, etc. The positions of
1800 these are usually fixed by the music itself -- they are
1801 vertically positioned on specific lines of the staff or are
1802 tied to other objects that are so positioned. Collisions of
1803 note heads, stems and accidentals in closely set chords are
1804 normally avoided automatically. There are commands and
1805 overrides which can modify this automatic behavior, as we
1808 Objects belonging outside the staff include things such as
1809 rehearsal marks, text and dynamic markings. LilyPond's rule for
1810 the vertical placement of outside-staff objects is to place them
1811 as close to the staff as possible but not so close that they
1812 collide with any other object. LilyPond uses the
1813 @code{outside-staff-priority} property to determine the order in
1814 which the objects should be placed, as follows.
1816 First, LilyPond places all the within-staff objects.
1817 Then it sorts the outside-staff objects according to their
1818 @code{outside-staff-priority}. The outside-staff objects are
1819 taken one by one, beginning with the object with the lowest
1820 @code{outside-staff-priority}, and placed so that they do not
1821 collide with any objects that have already been placed. That is,
1822 if two outside-staff grobs are competing for the same space, the
1823 one with the lower @code{outside-staff-priority} will be placed
1824 closer to the staff. If two objects have the same
1825 @code{outside-staff-priority} the one encountered first will be
1826 placed closer to the staff.
1828 In the following example all the markup texts have the same
1829 priority (since it is not explicitly set). Note that @q{Text3}
1830 is automatically positioned close to the staff again, nestling
1833 @cindex markup example
1835 @lilypond[quote,fragment,ragged-right,verbatim]
1842 Staves are also positioned, by default, as closely together as
1843 possible (subject to a minimum separation). If notes project
1844 a long way towards an adjacent staff they will force the
1845 staves further apart only if an overlap of the notation
1846 would otherwise occur. The following example demonstrates
1847 this @q{nestling} of the notes on adjacent staves:
1849 @lilypond[quote,ragged-right,verbatim]
1852 \relative { c'4 a, }
1855 \relative { c''''4 a, }
1861 @node Within-staff objects
1862 @subsection Within-staff objects
1864 We have already seen how the commands @code{\voiceXXX} affect the
1865 direction of slurs, ties, fingering and everything else which depends on
1866 the direction of the stems -- see @ref{Explicitly instantiating voices}.
1867 These commands are essential when writing polyphonic music to permit
1868 interweaving melodic lines to be distinguished. But occasionally it may
1869 be necessary to override this automatic behavior. This can be done for
1870 whole sections of music or even for an individual note. The property
1871 which controls this behavior is the @code{direction} property of each
1872 layout object. We first explain what this does, and then introduce a
1873 number of ready-made commands which avoid your having to code explicit
1874 overrides for the more common modifications.
1876 Some layout objects like slurs and ties curve, bend or point
1877 either up or down; others like stems and flags also move to
1878 right or left when they point up or down. This is controlled
1879 automatically when @code{direction} is set.
1882 * The direction property::
1886 @node The direction property
1887 @unnumberedsubsubsec The @code{direction} property
1894 The following example shows the default positioning of slurs in the
1895 first bar, with slurs starting on high notes positioned above the notes
1896 and those starting on low notes positioned below, followed by a bar
1897 with both slurs forced down, a bar with both slurs forced up, and
1898 finally a bar with both slurs reverted back to the default behavior.
1900 @cindex Slur, example of overriding
1901 @cindex direction property, example
1903 @lilypond[quote,fragment,verbatim]
1905 \override Slur.direction = #DOWN
1907 \override Slur.direction = #UP
1909 \revert Slur.direction
1913 Here we have used the constants @code{DOWN} and @code{UP}.
1914 These have the values @w{@code{-1}} and @code{+1} respectively, and
1915 these numerical values may be used instead. The value @code{0}
1916 may also be used in some cases. It is simply treated as meaning
1917 @code{UP} for slurs, but for some objects it means @q{center}.
1918 There is a constant, @code{CENTER} which has the value @code{0}.
1920 However, these explicit overrides are not usually used, as there are
1921 simpler equivalent predefined commands available. Here is a table of
1922 the commonest. The meaning of each is stated where it is not obvious.
1924 @multitable @columnfractions .2 .2 .25 .35
1929 @item @code{\arpeggioArrowDown}
1930 @tab @code{\arpeggioArrowUp}
1931 @tab @code{\arpeggioNormal}
1932 @tab Arrow is at bottom, at top, or no arrow
1933 @item @code{\dotsDown}
1935 @tab @code{\dotsNeutral}
1936 @tab Direction of movement to avoid staff lines
1937 @item @code{\dynamicDown}
1938 @tab @code{\dynamicUp}
1939 @tab @code{\dynamicNeutral}
1941 @item @code{\phrasingSlurDown}
1942 @tab @code{\phrasingSlurUp}
1943 @tab @code{\phrasingSlurNeutral}
1944 @tab Note: distinct from slur commands
1945 @item @code{\slurDown}
1947 @tab @code{\slurNeutral}
1949 @item @code{\stemDown}
1951 @tab @code{\stemNeutral}
1953 @item @code{\textSpannerDown}
1954 @tab @code{\textSpannerUp}
1955 @tab @code{\textSpannerNeutral}
1956 @tab Text entered as spanner is below/above staff
1957 @item @code{\tieDown}
1959 @tab @code{\tieNeutral}
1961 @item @code{\tupletDown}
1962 @tab @code{\tupletUp}
1963 @tab @code{\tupletNeutral}
1964 @tab Tuplets are below/above notes
1967 The neutral/normal variants of these commands are implemented
1968 using @code{\revert} and these may @strong{not} be
1969 preceded by @code{\once}. If you wish to limit the
1970 effect of the other commands (which are implemented using
1971 @code{\override}) to a single timestep, you can precede them with
1972 @code{\once} like you would do with explicit overrides.
1974 Or, if just a single layout object needs to be forced up or down, the
1975 direction indicators, @code{^} or @code{_}, may be used:
1977 @lilypond[quote,fragment,verbatim]
1979 a'4^( g') c''_( a') |
1983 @unnumberedsubsubsec Fingering
1985 @cindex fingering, placement
1986 @cindex fingering, chords
1988 The placement of fingering on single notes can also be controlled
1989 by the @code{direction} property, but changing @code{direction}
1990 has no effect on chords. As we shall see, there are special
1991 commands which allow the fingering of individual notes
1992 of chords to be controlled, with the fingering being placed
1993 above, below, to the left or to the right of each note.
1995 First, here's the effect of @code{direction} on the fingering
1996 attached to single notes. The first bar shows the default
1997 behaviour, and the following two bars shows the effect of
1998 specifying @code{DOWN} and @code{UP}:
2000 @cindex Fingering, example of overriding
2001 @cindex direction property, example
2003 @lilypond[quote,verbatim]
2005 c''4-5 a-3 f-1 c'-5 |
2006 \override Fingering.direction = #DOWN
2008 \override Fingering.direction = #UP
2013 However, overriding the @code{direction} property is not the
2014 easiest way of manually setting the fingering above or below
2015 the notes; using @code{_} or @code{^} instead of @code{-} before
2016 the fingering number is usually preferable. Here is the previous
2017 example using this method:
2019 @cindex fingering example
2021 @lilypond[quote,verbatim]
2023 c''4-5 a-3 f-1 c'-5 |
2029 The @code{direction} property is ignored for chords, but the
2030 directional prefixes, @code{_} and @code{^} do work. By default,
2031 the fingering is automatically placed both above and below the
2032 notes of a chord, as shown:
2034 @cindex fingering example
2036 @lilypond[quote,verbatim]
2045 but this may be overridden to manually force all or any of the
2046 individual fingering numbers above or below:
2048 @cindex fingering example
2050 @lilypond[quote,verbatim]
2052 <c''-5 g-3 e-2 c-1>4
2058 Even greater control over the placement of fingering of the
2059 individual notes in a chord is possible by using the
2060 @code{\set fingeringOrientations} command. The format of this
2064 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
2068 @code{\set} is used because @code{fingeringOrientations} is a
2069 property of the @code{Voice} context, created and used by the
2070 @code{New_fingering_engraver}.
2072 The property may be set to a list of one to three values.
2073 It controls whether fingerings may be placed above (if
2074 @code{up} appears in the list), below (if @code{down} appears),
2075 to the left (if @code{left} appears, or to the right
2076 (if @code{right} appears). Conversely, if a location is not
2077 listed, no fingering is placed there. LilyPond takes these
2078 constraints and works out the best placement for the fingering
2079 of the notes of the following chords. Note that @code{left} and
2080 @code{right} are mutually exclusive -- fingering may be placed
2081 only on one side or the other, not both.
2083 @warning{To control the placement of the fingering of a single
2084 note using this command it is necessary to write it as a single
2085 note chord by placing angle brackets round it.}
2087 Here are a few examples:
2089 @cindex fingering example
2090 @cindex @code{\set}, example of using
2091 @cindex fingeringOrientations property, example
2093 @lilypond[quote,ragged-right,verbatim]
2095 \set fingeringOrientations = #'(left)
2098 \set fingeringOrientations = #'(left)
2100 <c-1 e-2 g-3 b-5>4 |
2101 \set fingeringOrientations = #'(up left down)
2104 \set fingeringOrientations = #'(up left)
2106 <c-1 e-2 g-3 b-5>4 |
2107 \set fingeringOrientations = #'(right)
2114 If the fingering seems a little crowded the @code{font-size}
2115 could be reduced. The default value can be seen from the
2116 @code{Fingering} object in the IR to be @w{@code{-5}}, so let's
2119 @lilypond[quote,ragged-right,verbatim]
2121 \override Fingering.font-size = #-7
2122 \set fingeringOrientations = #'(left)
2125 \set fingeringOrientations = #'(left)
2127 <c-1 e-2 g-3 b-5>4 |
2128 \set fingeringOrientations = #'(up left down)
2131 \set fingeringOrientations = #'(up left)
2133 <c-1 e-2 g-3 b-5>4 |
2134 \set fingeringOrientations = #'(right)
2140 @node Outside-staff objects
2141 @subsection Outside-staff objects
2143 Outside-staff objects are automatically placed to avoid collisions.
2144 There are several ways to override the automatic placement if the
2145 positioning is not optimum.
2148 * The outside-staff-priority property::
2149 * The textLengthOn command::
2150 * Dynamics placement::
2155 @node The outside-staff-priority property
2156 @unnumberedsubsubsec The @code{outside-staff-priority} property
2158 Objects with the lower value of the @code{outside-staff-priority}
2159 property are placed nearer to the staff, and other outside-staff
2160 objects are then raised as far as necessary to avoid collisions.
2161 The @code{outside-staff-priority} is defined in the
2162 @code{grob-interface} and so is a property of all layout objects.
2163 By default it is set to @code{#f} for all within-staff objects,
2164 and to a numerical value appropriate to each outside-staff object
2165 when the object is created. The following table shows the default
2166 numerical values for some of the commonest outside-staff objects.
2170 Note the unusual names for some of the objects: spanner objects
2171 are automatically created to control the vertical positioning of
2172 grobs which (might) start and end at different musical moments, so
2173 changing the @code{outside-staff-priority} of the underlying grob
2174 will have no effect. For example, changing
2175 @code{outside-staff-priority} of the @code{Hairpin} object will
2176 have no effect on the vertical positioning of hairpins -- you must
2177 change @code{outside-staff-priority} of the associated
2178 @code{DynamicLineSpanner} object instead. This override must be
2179 placed at the start of the spanner, which might include several
2180 linked hairpins and dynamics.
2182 @multitable @columnfractions .3 .15 .45
2183 @headitem Layout Object
2185 @tab Controls position of:
2186 @item @code{RehearsalMark}
2188 @tab Rehearsal marks
2189 @item @code{MetronomeMark}
2191 @tab Metronome marks
2192 @item @code{SostenutoPedalLineSpanner}
2194 @tab Pedal indication
2195 @item @code{SustainPedalLineSpanner}
2198 @item @code{UnaCordaPedalLineSpanner}
2201 @item @code{MeasureCounter}
2204 @item @code{VoltaBracketSpanner}
2207 @item @code{InstrumentSwitch}
2209 @tab Instrument switch text
2210 @item @code{TextScript}
2213 @item @code{MultiMeasureRestText}
2215 @tab Markup text over multimeasure rests
2216 @item @code{CombineTextScript}
2218 @tab Part-combine text
2219 @item @code{OttavaBracket}
2221 @tab Ottava brackets
2222 @item @code{TextSpanner}
2225 @item @code{DynamicLineSpanner}
2227 @tab All dynamic markings
2228 @item @code{BarNumber}
2231 @item @code{TrillSpanner}
2233 @tab Spanning trills
2234 @item @code{AccidentalSuggestion}
2236 @tab Annotational accidentals
2239 Here is an example showing the default placement of some of
2242 @cindex text spanner
2243 @cindex ottava bracket
2245 @funindex \startTextSpan
2246 @funindex startTextSpan
2247 @funindex \stopTextSpan
2248 @funindex stopTextSpan
2250 @cindex TextSpanner, example of overriding
2251 @cindex bound-details property, example
2253 @lilypond[quote,fragment,ragged-right,verbatim]
2254 % Set details for later Text Spanner
2255 \override TextSpanner.bound-details.left.text
2256 = \markup { \small \bold Slower }
2257 % Place dynamics above staff
2259 % Start Ottava Bracket
2262 % Add Dynamic Text and hairpin
2268 % Add Dynamic Text and terminate hairpin
2269 c''4\ff c'' \stopTextSpan |
2270 % Stop Ottava Bracket
2275 This example also shows how to create Text Spanners --
2276 text with extender lines above a section of music. The
2277 spanner extends from the @code{\startTextSpan} command to
2278 the @code{\stopTextSpan} command, and the format of the
2279 text is defined by the @code{\override TextSpanner} command.
2280 For more details see @ruser{Text spanners}.
2282 It also shows how ottava brackets are created.
2284 @cindex tweaking bar number placement
2285 @cindex bar numbers, tweaking placement
2286 @cindex tweaking metronome mark placement
2287 @cindex metronome mark, tweaking placement
2288 @cindex tweaking rehearsal mark placement
2289 @cindex rehearsal marks, tweaking placement
2291 If the default values of @code{outside-staff-priority} do not give you
2292 the placing you want, the priority of any of the objects may be
2293 overridden. Suppose we would like the ottava bracket to be placed
2294 below the text spanner in the example above. All we need to do is to
2295 look up the priority of @code{OttavaBracket} in the IR or in the
2296 table above, and reduce it to a value lower than that of a
2297 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
2298 in the @code{Staff} context:
2300 @cindex TextSpanner, example of overriding
2301 @cindex bound-details property, example
2303 @lilypond[quote,fragment,ragged-right,verbatim]
2304 % Set details for later Text Spanner
2305 \override TextSpanner.bound-details.left.text
2306 = \markup { \small \bold Slower }
2307 % Place dynamics above staff
2309 % Place following Ottava Bracket below Text Spanners
2310 \once \override Staff.OttavaBracket.outside-staff-priority = #340
2311 % Start Ottava Bracket
2316 % Add Dynamic Line Spanner
2322 c''4\ff c'' \stopTextSpan |
2323 % Stop Ottava Bracket
2328 Note that some of these objects, in particular bar numbers,
2329 metronome marks and rehearsal marks, live by default in the
2330 @code{Score} context, so be sure to use the correct context
2331 when these are being overriden.
2333 @cindex slurs and outside-staff-priority
2334 @cindex slurs and articulations
2335 @cindex articulations and slurs
2337 Slurs by default are classed as within-staff objects, but
2338 they often appear above the staff if the notes to
2339 which they are attached are high on the staff. This can push
2340 outside-staff objects such as articulations too high, as the slur
2341 will be placed first. The @code{avoid-slur} property of the
2342 articulation can be set to @code{'inside} to bring the articulation
2343 inside the slur, but the @code{avoid-slur} property is effective
2344 only if the @code{outside-staff-priority} is also set to @code{#f}.
2345 Alternatively, the @code{outside-staff-priority} of the slur
2346 can be set to a numerical value to cause it to be placed along with
2347 other outside-staff objects according to that value. Here's an
2348 example showing the effect of the two methods:
2350 @lilypond[quote,verbatim]
2352 c4( c^\markup { \tiny \sharp } d4.) c8 |
2354 \once \override TextScript.avoid-slur = #'inside
2355 \once \override TextScript.outside-staff-priority = ##f
2356 c4^\markup { \tiny \sharp } d4.) c8 |
2357 \once \override Slur.outside-staff-priority = #500
2358 c4( c^\markup { \tiny \sharp } d4.) c8 |
2362 Changing the @code{outside-staff-priority} can also be used to
2363 control the vertical placement of individual objects, although
2364 the results may not always be desirable. Suppose we would
2365 like @qq{Text3} to be placed above @qq{Text4} in the example
2366 under Automatic behavior, above (see @ref{Automatic behavior}).
2367 All we need to do is to look up the priority of @code{TextScript}
2368 in the IR or in the tables above, and increase the priority of
2369 @qq{Text3} to a higher value:
2371 @cindex TextScript, example of overriding
2372 @cindex outside-staff-priority property, example
2374 @lilypond[quote,fragment,ragged-right,verbatim]
2377 \once \override TextScript.outside-staff-priority = #500
2382 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2383 above @qq{Text2}, and @qq{Text4} now drops down. Perhaps this is not
2384 so good. What we would really like to do is to position all the
2385 annotation at the same distance above the staff. To do this, we
2386 clearly will need to space the notes out horizontally to make more
2387 room for the text. This is done using the @code{textLengthOn}
2390 @node The textLengthOn command
2391 @unnumberedsubsubsec The @code{@bs{}textLengthOn} command
2393 @cindex notes, spreading out with text
2395 @funindex \textLengthOn
2396 @funindex textLengthOn
2397 @funindex \textLengthOff
2398 @funindex textLengthOff
2400 By default, text produced by markup takes up no horizontal space
2401 as far as laying out the music is concerned. The @code{\textLengthOn}
2402 command reverses this behavior, causing the notes to be spaced
2403 out as far as is necessary to accommodate the text:
2405 @lilypond[quote,fragment,ragged-right,verbatim]
2406 \textLengthOn % Cause notes to space out to accommodate text
2413 The command to revert to the default behavior is
2414 @code{\textLengthOff}. Alternatively, @code{\once} may be used
2415 with @code{\textLengthOn} if the effect is to be limited to just a
2416 single musical moment.
2417 The corresponding spacing behavior for rehearsal marks and tempo
2418 indications is independently controlled with the commands
2419 @code{\markLengthOn} and @code{\markLengthOff}.
2421 @cindex markup text, allowing collisions
2423 Markup text will also avoid notes which project above the staff.
2424 If this is not desired, the automatic displacement upwards may
2425 be turned off by setting the priority to @code{#f}. Here's an
2426 example to show how markup text interacts with such notes.
2428 @cindex TextScript, example of overriding
2429 @cindex outside-staff-priority property, example
2431 @lilypond[quote,ragged-right,verbatim]
2433 % This markup is short enough to fit without collision
2437 % This is too long to fit, so it is displaced upwards
2441 % Turn off collision avoidance
2442 \once \override TextScript.outside-staff-priority = ##f
2443 c,,2^"Long Text " c'' |
2446 % Turn off collision avoidance
2447 \once \override TextScript.outside-staff-priority = ##f
2448 \textLengthOn % and turn on textLengthOn
2449 c,,2^"Long Text " % Spaces at end are honored
2454 @node Dynamics placement
2455 @unnumberedsubsubsec Dynamics placement
2457 @cindex tweaking dynamics placement
2458 @cindex dynamics, tweaking placement
2460 Dynamic markings will normally be positioned beneath the
2461 staff, but may be positioned above with the @code{\dynamicUp}
2462 command. They will be positioned vertically relative to the
2463 note to which they are attached, and will float below (or above)
2464 all within-staff objects such as phrasing slurs and bar numbers.
2465 This can give quite acceptable results, as this example
2468 @lilypond[quote,ragged-right,verbatim]
2474 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2475 ees,2.~\)\mf ees4 r8 |
2479 However, if the notes and attached dynamics are close
2480 together the automatic placement will avoid collisions
2481 by displacing later dynamic markings further away, but this may
2482 not be the optimum placement, as this rather artificial example
2485 @lilypond[quote,ragged-right,verbatim,fragment]
2487 \relative { a'4\f b\mf a\mp b\p }
2491 Should a similar situation arise in @q{real} music, it may be
2492 preferable to space out the notes a little further, so the dynamic
2493 markings can all fit at the same vertical distance from the staff. We
2494 were able to do this for markup text by using the @code{\textLengthOn}
2495 command, but there is no equivalent command for dynamic marks. So we
2496 shall have to work out how to do this using @code{\override} commands.
2499 @unnumberedsubsubsec Grob sizing
2502 @cindex sizing grobs
2504 First we must learn how grobs are sized. All grobs have a
2505 reference point defined within them which is used to position
2506 them relative to their parent object. This point in the grob
2507 is then positioned at a horizontal distance, @code{X-offset},
2508 and at a vertical distance, @code{Y-offset}, from its parent.
2509 The horizontal extent of the object is given by a pair of
2510 numbers, @code{X-extent}, which say where the left and right
2511 edges are relative to the reference point. The vertical extent
2512 is similarly defined by a pair of numbers, @code{Y-extent}.
2513 These are properties of all grobs which support the
2514 @code{grob-interface}.
2516 @cindex @code{extra-spacing-width}
2518 By default, outside-staff objects are given a width of zero so
2519 that they may overlap in the horizontal direction. This is done
2520 by the trick of making the leftmost extent infinity and
2521 the rightmost extent minus infinity by setting the
2522 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}. To
2523 ensure they do not overlap in the horizontal direction we
2524 must override this value of @code{extra-spacing-width} to give them
2525 a little extra spacing. The units are the space between two staff
2526 lines, so moving the left edge half a unit to the left and the
2527 right edge half a unit to the right should do it:
2530 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2534 Let's see if this works in our previous example:
2536 @cindex DynamicText, example of overriding
2537 @cindex extra-spacing-width property, example
2540 @lilypond[quote,ragged-right,verbatim,fragment]
2542 % Extend width by 1 staff space
2543 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2544 \relative { a'4\f b\mf a\mp b\p }
2548 This looks better, but maybe we would prefer the dynamic marks
2549 to be aligned along the same baseline rather than going up and
2550 down with the notes. The property to do this is
2551 @code{staff-padding} which is covered in the section on collisions
2552 (see @ref{Collisions of objects}).
2555 @node Vertical spacing
2556 @section Vertical spacing
2558 As a rule, LilyPond's vertical spacing of musical objects is pretty
2559 good. Let's see how it does with a simple song, with 2 voices and
2560 piano accompaniment:
2562 @lilypond[quote,fragment,ragged-right]
2567 \new Voice = "music" {
2573 Here are some lyrics
2576 \clef bass e'2 f e c
2591 There's nothing wrong with the default vertical spacing. However, let's
2592 assume that you're working with a publisher with some specific
2593 requirements for vertical spacing of staves and lyrics: they want
2594 the lyrics spaced away from any notes, they want the piano
2595 accompaniment spaced away from the vocal line and they want the two
2596 piano staves pushed together tightly. Let's start with the lyrics.
2598 Lyrics sit within a system, and therefore the commands to space them
2599 are found in @ruser{Flexible vertical spacing within systems}. It
2600 tells us that lyrics are @code{non-staff lines} and therefore the
2601 command to change their spacing will refer to the @code{nonstaff}
2602 property. Spacing them away from the staff to which they relate
2603 (the top line) will use the @code{relatedstaff} property. Spacing
2604 them from the lower line will use the @code{unrelatedstaff} property.
2605 The vocal parts are part of a @code{VerticalAxisGroup}, so we need to
2606 adjust its properties. Let's try it and see if it works.
2608 @lilypond[quote,fragment,ragged-right,verbatim]
2613 \new Voice = "music" {
2618 \override VerticalAxisGroup.
2619 nonstaff-relatedstaff-spacing.padding = #5
2620 \override VerticalAxisGroup.
2621 nonstaff-unrelatedstaff-spacing.padding = #5
2624 Here are some lyrics
2627 \clef bass e'2 f e c
2642 Well - yes it does, but perhaps too well. When we set the
2643 @code{padding} to 5, LilyPond adds 5 staff spaces to the distance
2644 between objects, which is too much for us here. We'll use 2.
2646 Next, let's move the piano music away from the vocal parts. The
2647 vocal music is a @code{ChoirStaff}, so we need to increase the
2648 spacing between that group of staves and the piano staff below.
2649 We'll do this by changing the @code{basic-distance} of the
2650 @code{StaffGrouper}'s @code{staffgroup-staff-spacing}.
2652 @lilypond[quote,fragment,ragged-right,verbatim]
2654 \new ChoirStaff \with {
2655 \override StaffGrouper.
2656 staffgroup-staff-spacing.basic-distance = #15
2660 \new Voice = "music" {
2665 \override VerticalAxisGroup.
2666 nonstaff-relatedstaff-spacing.padding = #2
2667 \override VerticalAxisGroup.
2668 nonstaff-unrelatedstaff-spacing.padding = #2
2671 Here are some lyrics
2674 \clef bass e'2 f e c
2689 Excellent. Now just for the last requirement to make the piano staves
2690 closer together. To do this, we again alter the properties of the
2691 @code{StaffGrouper}, but this time we're going to reduce both
2692 the @code{basic-distance} and the @code{padding}. We can do this
2695 @lilypond[quote,fragment,ragged-right,verbatim]
2697 \new ChoirStaff \with {
2698 \override StaffGrouper.
2699 staffgroup-staff-spacing.basic-distance = #15
2703 \new Voice = "music" {
2708 \override VerticalAxisGroup.
2709 nonstaff-relatedstaff-spacing.padding = #2
2710 \override VerticalAxisGroup.
2711 nonstaff-unrelatedstaff-spacing.padding = #2
2714 Here are some lyrics
2717 \clef bass e'2 f e c
2720 \new PianoStaff \with {
2721 \override StaffGrouper.staff-staff-spacing = #'(
2722 (basic-distance . 0)
2736 That's put them really close together -- but it's what
2737 the publisher wanted. They could be moved further
2738 apart by altering the @code{padding} or @code{basic-distance}
2741 There are many ways of altering vertical spacing. A key point
2742 to remember is that the spacing between objects in a
2743 @code{StaffGroup} (like @code{GrandStaff} or
2744 @code{PianoStaff} groups) is controlled by the spacing variables
2745 of the @code{StaffGrouper}. Spacing from ungrouped staves
2746 (like @code{Lyrics} and @code{Staff}) is controlled by the
2747 variables of the @code{VerticalAxisGroup}. See the
2748 @ruser{Flexible vertical spacing paper variables} and
2749 @ruser{Flexible vertical spacing within systems} for more
2752 @node Collisions of objects
2753 @section Collisions of objects
2757 * Fixing overlapping notation::
2758 * Real music example::
2761 @node Moving objects
2762 @subsection Moving objects
2764 @cindex moving overlapping objects
2765 @cindex moving colliding objects
2766 @cindex moving colliding grobs
2767 @cindex objects, moving colliding
2768 @cindex grobs, moving colliding
2770 This may come as a surprise, but LilyPond is not perfect. Some
2771 notation elements can overlap. This is unfortunate, but in fact
2772 rather rare. Usually the need to move objects is for clarity or
2773 aesthetic reasons -- they would look better with a little more
2774 or a little less space around them.
2776 There are three main approaches to resolving overlapping
2777 notation. They should be considered in the following order:
2781 The @strong{direction} of one of the overlapping objects may
2782 be changed using the predefined commands listed above for
2783 within-staff objects (see @ref{Within-staff objects}).
2784 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2785 repositioned easily in this way. The limitation is that you
2786 have a choice of only two positions, and neither may be
2790 The @strong{object properties}, which LilyPond uses when positioning
2791 layout objects, may be modified using @code{\override}. The
2792 advantages of making changes to this type of property are (a) that
2793 some other objects will be moved automatically if necessary to make
2794 room and (b) the single override can apply to all instances of the
2795 same type of object. Such properties include:
2802 This has already been covered in some detail -- see
2803 @ref{Within-staff objects}.
2806 @code{padding}, @code{right-padding}, @code{staff-padding}
2809 @cindex padding property
2810 @cindex right-padding property
2811 @cindex staff-padding property
2813 As an object is being positioned the value of its @code{padding}
2814 property specifies the gap that must be left between itself and the
2815 nearest edge of the object against which it is being positioned. Note
2816 that it is the @code{padding} value of the object @strong{being
2817 placed} that is used; the @code{padding} value of the object which is
2818 already placed is ignored. Gaps specified by @code{padding} can be
2819 applied to all objects which support the
2820 @code{side-position-interface}.
2822 Instead of @code{padding}, the placement of groups of accidentals
2823 is controlled by @code{right-padding}. This property is to be found
2824 in the @code{AccidentalPlacement} object which, note, lives in the
2825 @strong{Staff} context. In the typesetting process the note heads
2826 are typeset first and then the accidentals, if any, are added to the
2827 left of the note heads using the @code{right-padding} property to determine
2828 the separation from the note heads and between individual accidentals.
2829 So only the @code{right-padding} property of the @code{AccidentalPlacement}
2830 object has any effect on the placement of the accidentals.
2832 The @code{staff-padding} property is closely related to the
2833 @code{padding} property: @code{padding} controls the minimum amount of
2834 space between any object which supports the
2835 @code{side-position-interface} and the nearest other object (generally
2836 the note or the staff lines); @code{staff-padding} applies only to
2837 those objects which are always set outside the staff -- it controls
2838 the minimum distance from the staff to the outside-staff object.
2839 Note that @code{staff-padding} has no effect on
2840 objects that are positioned relative to the note rather than the
2841 staff, even though it may be overridden without error for such objects
2842 -- it is simply ignored.
2844 To discover which padding property is required for the object you wish
2845 to reposition, you need to return to the IR and look up the object's
2846 properties. Be aware that the padding properties might not be located
2847 in the obvious object, so look in objects that appear to be related.
2849 All padding values are measured in staff spaces. For most
2850 objects, this value is set by default to be around 1.0 or less
2851 (it varies with each object). It may be overridden if a larger
2852 (or smaller) gap is required.
2855 @code{self-alignment-X}
2857 @cindex self-alignment-X property
2859 This property can be used to align the object to the left, to
2860 the right, or to center it with respect to the parent object's
2861 reference point. It may be used with all objects which support
2862 the @code{self-alignment-interface}. In general these are objects
2863 that contain text. The values are @code{LEFT}, @code{RIGHT}
2864 or @code{CENTER}. Alternatively, a numerical value between
2865 @w{@code{-1}} and @code{+1} may be specified, where @w{@code{-1}} is
2866 left-aligned, @code{+1} is right-aligned, and numbers in between
2867 move the text progressively from left-aligned to right-aligned.
2868 Numerical values greater than @code{1} may be specified to move
2869 the text even further to the left, or less than @w{@code{-1}} to
2870 move the text even further to the right. A change of @code{1}
2871 in the value corresponds to a movement of half the text's length.
2874 @code{extra-spacing-width}
2876 @cindex extra-spacing-width property
2878 This property is available for all objects which support the
2879 @code{item-interface}. It takes two numbers, the first is added
2880 to the leftmost extent and the second is added to the rightmost
2881 extent. Negative numbers move the edge to the left, positive to
2882 the right, so to widen an object the first number must be negative,
2883 the second positive. Note that not all objects honor both
2884 numbers. For example, the @code{Accidental} object only takes
2885 notice of the first (left edge) number.
2888 @code{staff-position}
2890 @cindex staff-position property
2892 @code{staff-position} is a property of the
2893 @code{staff-symbol-referencer-interface}, which is supported by
2894 objects which are positioned relative to the staff. It specifies
2895 the vertical position of the object relative to the center line
2896 of the staff in half staff-spaces. It is useful in resolving
2897 collisions between layout objects like multi-measure rests, ties
2898 and notes in different voices.
2901 @code{horizontal-shift}
2903 @cindex horizontal-shift property
2905 @cindex note collisions
2906 @cindex collisions, notes
2907 @cindex shift commands
2914 @funindex \shiftOnnn
2917 Within a voice, all the notes occuring at the same musical moment are
2918 grouped into a note column, and a @code{NoteColumn} object is created
2919 to control the horizontal positioning of that group of notes (see
2920 @qq{Note columns} in @ref{Explicitly instantiating voices}). If
2921 @emph{and only if} two or more note columns within a single Staff
2922 context, both with stems in the same direction, occur at the same
2923 musical moment, the values of their @code{horizontal-shift} properties
2924 are used to rank them and the columns in the higher ranks are
2925 progessively offset to avoid collisions of the noteheads. This
2926 property is set by the @code{\voiceXXX} commands and may be overridden
2927 directly with an @code{\override} command or, more usually, by the
2928 @code{\shiftOn} commands. Note that this property is used to
2929 @emph{rank} the note columns for off-setting - it does not specify the
2930 magnitude of the offset, which is progressively increased in steps
2931 based on the note head's width for each rank. The steps are usually
2932 of half a note head's width, but may be a full note head's width when
2933 a closely spaced group of notes is involved.
2938 @cindex force-hshift property
2940 The @code{force-hshift} property is a property of a @code{NoteColumn}
2941 (actually of the @code{note-column-interface}). Changing it permits a
2942 note column to be moved in situations where the note columns overlap.
2943 Note that it has no effect on note columns that do not overlap.
2944 It is specified in units appropriate to a note column, viz. the note
2945 head width of the first voice note. It should be used in complex
2946 situations where the normal @code{\shiftOn} commands (see
2947 @ref{Explicitly instantiating voices}) do not resolve the note
2948 conflict satisfactorily. It is preferable to the @code{extra-offset}
2949 property for this purpose as there is no need to work out the distance
2950 in staff-spaces, and moving the notes into or out of a
2951 @code{NoteColumn} affects other actions such as merging note heads.
2956 Finally, when all else fails, objects may be manually repositioned
2957 relative to the staff center line vertically, or by displacing them by
2958 any distance to a new position. The disadvantages are that the
2959 correct values for the repositioning have to be worked out, often by
2960 trial and error, for every object individually, and, because the
2961 movement is done after LilyPond has placed all other objects, the user
2962 is responsible for avoiding any collisions that might ensue. But the
2963 main difficulty with this approach is that the repositioning values
2964 may need to be reworked if the music is later modified. The
2965 properties that can be used for this type of manual repositioning are:
2970 @cindex extra-offset property
2972 This property applies to any layout object supporting the
2973 @code{grob-interface}. It takes a pair of numbers which specify the
2974 extra displacement in the horizontal and vertical directions.
2975 Negative numbers move the object to the left or down. The units are
2976 staff-spaces. The extra displacement is made after the typesetting of
2977 objects is finished, so an object may be repositioned anywhere without
2978 affecting anything else.
2982 @cindex positions property
2984 This is most useful for manually adjusting the slope and height
2985 of beams, slurs, and tuplets. It takes a pair of numbers
2986 giving the position of the left and right ends of the beam, slur,
2987 etc. relative to the center line of the staff. Units are
2988 staff-spaces. Note, though, that slurs and phrasing slurs cannot
2989 be repositioned by arbitrarily large amounts. LilyPond first
2990 generates a list of possible positions for the slur and by default
2991 finds the slur that @qq{looks best}. If the @code{positions}
2992 property has been overridden the slur that is closest to the
2993 requested positions is selected from the list.
2998 A particular object may not have all of these properties.
2999 It is necessary to go to the IR to look up which properties
3000 are available for the object in question.
3002 Here is a list of the objects which are most likely to be
3003 involved in collisions, together with the name of the object which
3004 should be looked up in the IR in order to discover which properties
3005 should be used to move them.
3007 @multitable @columnfractions .5 .5
3008 @headitem Object type @tab Object name
3009 @item Articulations @tab @code{Script}
3010 @item Beams @tab @code{Beam}
3011 @item Dynamics (vertically) @tab @code{DynamicLineSpanner}
3012 @item Dynamics (horizontally) @tab @code{DynamicText}
3013 @item Fingerings @tab @code{Fingering}
3014 @item Rehearsal / Text marks @tab @code{RehearsalMark}
3015 @item Slurs @tab @code{Slur}
3016 @item Text e.g. @code{^"text"} @tab @code{TextScript}
3017 @item Ties @tab @code{Tie}
3018 @item Tuplets @tab @code{TupletBracket}
3022 @node Fixing overlapping notation
3023 @subsection Fixing overlapping notation
3025 Let's now see how the properties in the previous section can
3026 help to resolve overlapping notation.
3029 * The padding property::
3030 * The right-padding property::
3031 * The staff-padding property::
3032 * The self-alignment-X property::
3033 * The staff-position property::
3034 * The extra-offset property::
3035 * The positions property::
3036 * The force-hshift property::
3039 @node The padding property
3040 @unnumberedsubsubsec The @code{padding} property
3043 @cindex fixing overlapping notation
3044 @cindex overlapping notation
3046 The @code{padding} property can be set to increase
3047 (or decrease) the distance between symbols that are printed
3048 above or below notes.
3050 @cindex Script, example of overriding
3051 @cindex padding property, example
3053 @lilypond[quote,fragment,verbatim]
3055 \override Script.padding = #3
3059 @cindex MetronomeMark, example of overriding
3060 @cindex padding property, example
3062 @lilypond[quote,fragment,verbatim]
3063 % This will not work, see below
3064 \override MetronomeMark.padding = #3
3068 \override Score.MetronomeMark.padding = #3
3073 Note in the second example how important it is to figure out what
3074 context handles a certain object. Since the @code{MetronomeMark}
3075 object is handled in the @code{Score} context, property changes in the
3076 @code{Voice} context will not be noticed. For more details, see
3077 @ruser{Modifying properties}.
3079 If the @code{padding} property of an object is increased when that
3080 object is in a stack of objects being positioned according to
3081 their @code{outside-staff-priority}, then that object and all
3082 objects outside it are moved.
3085 @node The right-padding property
3086 @unnumberedsubsubsec The @code{right-padding} property
3088 @cindex right-padding property
3090 The @code{right-padding} property affects the spacing between the
3091 accidental and the note to which it applies. It is not often
3092 required, but the default spacing may be wrong for certain special
3093 accidental glyphs or combination of glyphs used in some microtonal
3094 music. These have to be entered by overriding the accidental
3095 stencil with a markup containing the desired symbol(s), like this:
3097 @cindex Accidental, example of overriding
3098 @cindex text property, example
3099 @cindex stencil property, example
3100 @cindex AccidentalPlacement, example of overriding
3101 @cindex right-padding property, example
3103 @lilypond[quote,ragged-right,verbatim]
3104 sesquisharp = \markup { \sesquisharp }
3107 % This prints a sesquisharp but the spacing is too small
3108 \once \override Accidental.stencil = #ly:text-interface::print
3109 \once \override Accidental.text = #sesquisharp
3111 % This improves the spacing
3112 \once \override Score.AccidentalPlacement.right-padding = #0.6
3113 \once \override Accidental.stencil = #ly:text-interface::print
3114 \once \override Accidental.text = #sesquisharp
3120 This necessarily uses an override for the accidental stencil which
3121 will not be covered until later. The stencil type must be a
3122 procedure, here changed to print the contents of the @code{text}
3123 property of @code{Accidental}, which itself is set to be a
3124 sesquisharp sign. This sign is then moved further away from the
3125 note head by overriding @code{right-padding}.
3129 @node The staff-padding property
3130 @unnumberedsubsubsec The @code{staff-padding} property
3132 @cindex aligning objects on a baseline
3133 @cindex objects, aligning on a baseline
3135 @code{staff-padding} can be used to align objects such as dynamics
3136 along a baseline at a fixed distance from the staff, when no other
3137 notation forces them further from the staff.
3138 It is not a property of @code{DynamicText} but of
3139 @code{DynamicLineSpanner}. This is because the baseline should apply
3140 equally to @strong{all} dynamics, including those created as extended
3141 spanners. So this is the way to align the dynamic marks in the
3142 example taken from the previous section:
3144 @cindex DynamicText, example of overriding
3145 @cindex extra-spacing-width property, example
3146 @cindex DynamicLineSpanner, example of overriding
3147 @cindex staff-padding property, example
3149 @lilypond[quote,fragment,ragged-right,verbatim]
3150 \override DynamicLineSpanner.staff-padding = #3
3151 \relative { a'4\f b\mf a\p b\mp }
3155 @node The self-alignment-X property
3156 @unnumberedsubsubsec The @code{self-alignment-X} property
3158 The following example shows how to adjust the position
3159 of a string fingering object relative to a note's stem by aligning the
3160 right edge with the reference point of the parent note:
3162 @cindex StringNumber, example of overriding
3163 @cindex self-alignment-X property, example
3165 @lilypond[quote,fragment,ragged-right,verbatim]
3168 \once \override StringNumber.self-alignment-X = #RIGHT
3172 @node The staff-position property
3173 @unnumberedsubsubsec The @code{staff-position} property
3175 @cindex object collision within a staff
3177 Multimeasure rests in one voice can collide with notes in another.
3178 Since these rests are typeset centered between the bar lines, it
3179 would require significant effort for LilyPond to figure out which
3180 other notes might collide with it, since all the current collision
3181 handling between notes and between notes and rests is done only
3182 for notes and rests that occur at the same time. Here's an
3183 example of a collision of this type:
3185 @lilypond[quote,verbatim,ragged-right]
3186 << \relative { c'4 c c c } \\ { R1 } >>
3189 The best solution here is to move the multimeasure rest down, since the
3190 rest is in voice two. The default in @code{\voiceTwo} (i.e. in the
3191 second voice of a @code{<<@{@dots{}@} \\ @{@dots{}@}>>} construct) is
3192 that @code{staff-position} is set to -4 for MultiMeasureRest, so we need
3193 to move it, say, four half-staff spaces down to @w{@code{-8}}.
3195 @cindex MultiMeasureRest, example of overriding
3196 @cindex staff-position property, example
3198 @lilypond[quote,verbatim,ragged-right]
3200 \relative { c'4 c c c }
3202 \override MultiMeasureRest.staff-position = #-8
3207 This is better than using, for example, @code{extra-offset},
3208 because the ledger line above the rest is inserted automatically.
3210 @node The extra-offset property
3211 @unnumberedsubsubsec The @code{extra-offset} property
3213 @cindex positioning objects
3214 @cindex positioning grobs
3215 @cindex objects, positioning
3216 @cindex grobs, positioning
3218 The @code{extra-offset} property provides complete control over the
3219 positioning of an object both horizontally and vertically.
3221 In the following example, the second fingering is moved a little to
3222 the left, and 1.8 staff space downwards:
3224 @cindex Fingering, example of overriding
3225 @cindex extra-offset property, example
3227 @lilypond[quote,fragment,verbatim]
3229 \once \override Fingering.extra-offset = #'(-0.3 . -1.8)
3234 @node The positions property
3235 @unnumberedsubsubsec The @code{positions} property
3237 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
3238 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
3239 @cindex tuplet beams, controlling manually
3240 @cindex slurs, controlling manually
3241 @cindex phrasing slurs, controlling manually
3242 @cindex beams, controlling manually
3244 The @code{positions} property allows the vertical position and hence
3245 the slope of tuplets, slurs, phrasing slurs and beams to be controlled
3248 Here's an example in which the phrasing slur and slur collide:
3250 @lilypond[quote,verbatim,ragged-right]
3251 \relative { a'8 \( ( a'16 ) a \) }
3254 @cindex PhrasingSlur, example of overriding
3255 @cindex positions property, example
3258 One possibility would be to move the two ends of the phrasing slur
3259 higher. We can try setting the left end to 2.5 staff-spaces above the
3260 centre line and the right end to 4.5 above, and LilyPond will
3261 select the phrasing slur from the candidates it has found with its
3262 end points closest to these:
3264 @lilypond[quote,verbatim,fragment,ragged-right]
3265 \once \override PhrasingSlur.positions = #'(2.5 . 4.5)
3266 a'8 \( ( a''16 ) a'' \)
3269 This is an improvement, but why not lower the right end of the slur
3270 a little? If you try it you'll find it can't be done in this way.
3271 That's because there are no candidate slurs lower than the one
3272 already selected, and in this case the @code{positions} property has
3273 no effect. However, ties, slurs and phrasing slurs @emph{can} be
3274 positioned and shaped very precisely when necessary. To learn how to
3275 do this, see @ruser{Modifying ties and slurs}.
3277 Here's a further example. We see that the beams
3278 collide with the ties:
3280 @lilypond[quote,verbatim,ragged-right]
3284 \relative { c'1~ 2. e8 f }
3293 \relative { c'1~ 2. e8 f }
3305 This can be resolved by manually moving both ends of the beam
3306 up from their position at 1.81 staff-spaces below the center line to,
3309 @cindex Beam, example of overriding
3310 @cindex positions property, example
3312 @lilypond[quote,verbatim,ragged-right]
3316 \relative { c'1~ 2. e8 f }
3319 \override Beam.positions = #'(-1 . -1)
3326 \relative { c'1~ 2. e8 f }
3332 \revert Beam.positions
3339 Note that the override continues to apply in the second voice of
3340 the second measure of eighth notes, but not to any of the beams in the
3341 first voice, even those in the later second measure. As soon as the
3342 override should no longer apply it should be reverted, as shown.
3344 @node The force-hshift property
3345 @unnumberedsubsubsec The @code{force-hshift} property
3347 We can now see how to apply the final corrections to the Chopin
3348 example introduced at the end of @ref{I'm hearing Voices}, which
3349 was left looking like this:
3351 @lilypond[quote,verbatim,fragment,ragged-right]
3352 \new Staff \relative {
3367 The inner note of the first chord (i.e. the A-flat in the fourth
3368 Voice) need not be shifted away from the note column of the higher
3369 note, so we use @code{\shiftOff}.
3371 In the second chord we prefer the F to line up with the A-flat and
3372 the lowest note to be positioned slightly right to avoid a collision
3373 of stems. We achieve this by setting @code{force-hshift} in the
3374 @code{NoteColumn} of the low D-flat to move it to the right by half
3375 a staff-space, and setting @code{force-hshift} for the F to zero.
3376 Note that we use @code{\once} to avoid the settings propagating
3377 beyond the immediate musical moment, although in this small example
3378 the @code{\once} and the second @code{\override} in Voice four could
3379 be omitted. This would not be good practice.
3381 Here's the final result:
3383 @cindex NoteColumn, example of overriding
3384 @cindex force-hshift property, example
3386 @lilypond[quote,verbatim,fragment,ragged-right]
3387 \new Staff \relative {
3392 { <ees, c>2 \once \override NoteColumn.force-hshift = 0.5 des }
3395 { \once \shiftOff aes'2 \once \shiftOff f4 fes }
3402 @node Real music example
3403 @subsection Real music example
3405 We end this section on Tweaks by showing the steps to be taken to
3406 deal with a tricky example which needs several tweaks to produce
3407 the desired output. The example has been deliberately chosen to
3408 illustrate the use of the Notation Reference to resolve unusual
3409 problems with notation. It is not representative of the more usual
3410 engraving process, so please do not let these difficulties put
3411 you off! Fortunately, difficulties like these are not very common!
3413 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
3414 9, the transition from the opening Lento to Moderato.
3415 Here, first, is what we want the output to look like, but to avoid
3416 over-complicating the example too much we have left out the
3417 dynamics, fingering and pedalling.
3419 @c The following should appear as music without code
3420 @c This example should not be indexed
3421 @c line-width ensures no break
3422 @lilypond[quote,ragged-right,line-width=6\in]
3423 rhMusic = \relative {
3426 \once \override Tie.staff-position = #3.5
3430 \mergeDifferentlyHeadedOn
3431 \mergeDifferentlyDottedOn
3432 bes2.\tempo "Moderato" r8
3438 % Reposition the c2 to the right of the merged note
3439 \once \override NoteColumn.force-hshift = #1.0
3440 % Move the c2 out of the main note column
3441 % so the merge will work
3448 % Stem on the d2 must be down to permit merging
3450 % Stem on the d2 should be invisible
3451 \tweak Stem.transparent ##t
3459 \mergeDifferentlyHeadedOff
3460 \mergeDifferentlyDottedOff
3465 lhMusic = \relative {
3467 <d g, d>1)\arpeggio |
3474 \new Staff = "RH" <<
3478 \new Staff = "LH" <<
3487 We note first that the right hand part in the third bar
3488 requires four voices. These are the five beamed eighth notes,
3489 the tied C, the half-note D which is merged with the eighth note
3490 D, and the dotted quarter note F-sharp, which is also merged with
3491 the eighth note at the same pitch. Everything else is in a single
3492 voice, so the easiest way is to introduce these extra three voices
3493 temporarily at the time they are needed. If you have forgotten
3494 how to do this, look at @ref{I'm hearing Voices} and @ref{Explicitly
3495 instantiating voices}. Here we choose to use explicitly instantiated
3496 voices for the polyphonic passage, as LilyPond is better able to
3497 avoid collisions if all voices are instantiated explicitly in this
3500 So let us begin by entering the notes as two variables, setting up
3501 the staff structure in a score block, and seeing what LilyPond
3502 produces by default:
3504 @c line-width ensures no break
3505 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3506 rhMusic = \relative {
3512 % Start polyphonic section of four voices
3514 { c,8 d fis bes a } % continuation of main voice
3528 g2. % continuation of main voice
3532 lhMusic = \relative {
3541 \new Staff = "RH" <<
3545 \new Staff = "LH" <<
3554 All the notes are right, but the appearance is far from
3555 satisfactory. The tie collides with the change in time signature,
3556 some notes are not merged together, and several notation elements
3557 are missing. Let's first deal with the easier things. We can
3558 easily add the left hand slur and the right hand phrasing slur,
3559 since these were all covered in the Tutorial. Doing this gives:
3561 @c line-width ensures no break
3562 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3563 rhMusic = \relative {
3569 % Start polyphonic section of four voices
3571 { c,8 d fis bes a } % continuation of main voice
3585 g2.\) % continuation of main voice
3589 lhMusic = \relative {
3598 \new Staff = "RH" <<
3602 \new Staff = "LH" <<
3611 The first bar is now correct. The second bar contains an arpeggio and
3612 is terminated by a double bar line. How do we do these, as they have
3613 not been mentioned in this Learning Manual? This is where we need to
3614 turn to the Notation Reference. Looking up @q{arpeggio} and @q{bar
3615 line} in the index quickly shows us that an arpeggio is produced by
3616 appending @code{\arpeggio} to a chord, and a double bar line is
3617 produced by the @code{\bar "||"} command. That's easily done. We
3618 next need to correct the collision of the tie with the time signature.
3619 This is best done by moving the tie upwards. Moving objects was
3620 covered earlier in @ref{Moving objects}, which says that objects
3621 positioned relative to the staff can be moved vertically by overriding
3622 their @code{staff-position} property, which is specified in half staff
3623 spaces relative to the center line of the staff. So the following
3624 override placed just before the first tied note would move the tie up
3625 to 3.5 half staff spaces above the center line:
3627 @code{\once \override Tie.staff-position = #3.5}
3629 This completes bar two, giving:
3631 @c line-width ensures no break
3632 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3633 rhMusic = \relative {
3636 \once \override Tie.staff-position = #3.5
3641 % Start polyphonic section of four voices
3643 { c,8 d fis bes a } % continuation of main voice
3657 g2.\) % continuation of main voice
3661 lhMusic = \relative {
3663 <d g, d>1)\arpeggio |
3670 \new Staff = "RH" <<
3674 \new Staff = "LH" <<
3683 On to bar three and the start of the Moderato section. The tutorial
3684 showed how to add a tempo indication with the @code{\tempo} command, so
3685 adding @qq{Moderato} is easy. But how do we merge notes in
3686 different voices together? This is where we need to turn again to
3687 the Notation Reference for help. A search for @qq{merge} in the
3688 Notation Reference index quickly leads us to the commands for merging
3689 differently headed and differently dotted notes in
3690 @ruser{Collision resolution}. In our example we need to merge both
3691 types of note for the duration of the polyphonic section in bar 3,
3692 so using the information we find in the Notation Reference we add
3695 \mergeDifferentlyHeadedOn
3696 \mergeDifferentlyDottedOn
3700 to the start of that section and
3703 \mergeDifferentlyHeadedOff
3704 \mergeDifferentlyDottedOff
3710 @c line-width ensures no break
3711 @lilypond[quote,ragged-right,line-width=6\in]
3712 rhMusic = \relative {
3715 \once \override Tie.staff-position = #3.5
3719 bes2.\tempo "Moderato" r8
3720 \mergeDifferentlyHeadedOn
3721 \mergeDifferentlyDottedOn
3722 % Start polyphonic section of four voices
3724 { c,8 d fis bes a } % continuation of main voice
3738 \mergeDifferentlyHeadedOff
3739 \mergeDifferentlyDottedOff
3740 g2.\) % continuation of main voice
3744 lhMusic = \relative {
3746 <d g, d>1)\arpeggio |
3753 \new Staff = "RH" <<
3757 \new Staff = "LH" <<
3766 These overrides have merged the two F-sharp notes, but not the two
3767 on D. Why not? The answer is there in the same section in the
3768 Notation Reference -- notes being merged must have stems in
3769 opposite directions and two notes cannot be merged successfully if
3770 there is a third note in the same note column. Here the two D's
3771 both have upward stems and there is a third note -- the C. We know
3772 how to change the stem direction using @code{\stemDown}, and
3773 the Notation Reference also says how to move the C -- apply a shift
3774 using one of the @code{\shift} commands. But which one?
3775 The C is in voice two which has shift off, and the two D's are in
3776 voices one and three, which have shift off and shift on,
3777 respectively. So we have to shift the C a further level still
3778 using @code{\shiftOnn} to avoid it interfering with the two D's.
3779 Applying these changes gives:
3781 @cindex Tie, example of overriding
3782 @cindex staff-position property, example
3784 @c line-width ensures no break
3785 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3786 rhMusic = \relative {
3789 \once \override Tie.staff-position = #3.5
3793 bes2.\tempo "Moderato" r8
3794 \mergeDifferentlyHeadedOn
3795 \mergeDifferentlyDottedOn
3796 % Start polyphonic section of four voices
3798 { c,8 d fis bes a } % continuation of main voice
3801 % Move the c2 out of the main note column
3802 % so the merge will work
3807 % Stem on the d2 must be down to permit merging
3815 \mergeDifferentlyHeadedOff
3816 \mergeDifferentlyDottedOff
3817 g2.\) % continuation of main voice
3821 lhMusic = \relative {
3823 <d g, d>1)\arpeggio |
3830 \new Staff = "RH" <<
3834 \new Staff = "LH" <<
3843 Nearly there. Only two problems remain: The downward stem on the
3844 merged D should not be there, and the C would be better positioned
3845 to the right of the D's. We know how to do both of these from the
3846 earlier tweaks: we make the stem transparent, and move the C with
3847 the @code{force-hshift} property. Here's the final result:
3849 @cindex NoteColumn, example of overriding
3850 @cindex force-hshift property, example
3851 @cindex Stem, example of overriding
3852 @cindex transparent property, example
3854 @c line-width ensures no break
3855 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3856 rhMusic = \relative {
3859 \once \override Tie.staff-position = #3.5
3863 bes2.\tempo "Moderato" r8
3864 \mergeDifferentlyHeadedOn
3865 \mergeDifferentlyDottedOn
3866 % Start polyphonic section of four voices
3868 { c,8 d fis bes a } % continuation of main voice
3872 % Reposition the c2 to the right of the merged note
3873 \once \override NoteColumn.force-hshift = #1.0
3874 % Move the c2 out of the main note column
3875 % so the merge will work
3882 % Stem on the d2 must be down to permit merging
3884 % Stem on the d2 should be invisible
3885 \tweak Stem.transparent ##t
3893 \mergeDifferentlyHeadedOff
3894 \mergeDifferentlyDottedOff
3895 g2.\) % continuation of main voice
3899 lhMusic = \relative {
3901 <d g, d>1)\arpeggio |
3908 \new Staff = "RH" <<
3912 \new Staff = "LH" <<
3922 @node Further tweaking
3923 @section Further tweaking
3926 * Other uses for tweaks::
3927 * Using variables for layout adjustments::
3929 * Other sources of information::
3930 * Advanced tweaks with Scheme::
3933 @node Other uses for tweaks
3934 @subsection Other uses for tweaks
3937 * Tying notes across voices::
3938 * Simulating a fermata in MIDI::
3941 @cindex removing objects
3942 @cindex objects, removing
3944 @node Tying notes across voices
3945 @unnumberedsubsubsec Tying notes across voices
3947 @cindex tying notes across voices
3949 The following example demonstrates how to connect notes in different
3950 voices using ties. Normally, only notes in the same voice can be
3951 connected with ties. By using two voices, with the tied notes in one
3955 << { b'8~ 8\noBeam } \\ { b'8[ g'] } >>
3959 and removing the first up-stem and its flag in that voice, the tie
3960 appears to cross voices:
3963 @cindex Stem, example of removing
3964 @cindex Flag, example of removing
3965 @cindex @code{\omit}, example
3966 @cindex example of @code{\omit}
3968 @lilypond[quote,verbatim]
3982 @ref{The once prefix,,The @code{@bs{}once} prefix},
3983 @ref{The stencil property}.
3986 @node Simulating a fermata in MIDI
3987 @unnumberedsubsubsec Simulating a fermata in MIDI
3989 @cindex stencil property, use of
3990 @cindex fermata, implementing in MIDI
3992 For outside-staff objects it is usually better to override the
3993 object's @code{stencil} property rather than its @code{transparent}
3994 property when you wish to remove it from the printed output.
3995 Setting the @code{stencil} property of an object to @code{#f} will
3996 remove that object entirely from the printed output. This means it
3997 has no effect on the placement of other objects placed relative to
4000 For example, if we wished to change the metronome setting in order
4001 to simulate a fermata in the MIDI output we would not want the
4002 metronome markings to appear in the printed output, and we would
4003 not want it to influence the spacing between the two systems or
4004 the positions of adjacent annotations on the staff. So setting
4005 its @code{stencil} property to @code{#f} would be the best way.
4006 We show here the effect of the two methods:
4008 @cindex MetronomeMark, example of overriding
4009 @cindex transparent property, example
4011 @lilypond[quote,verbatim,ragged-right]
4014 % Visible tempo marking
4017 \once \hide Score.MetronomeMark
4018 % Invisible tempo marking to lengthen fermata in MIDI
4021 % New tempo for next section
4030 @cindex MetronomeMark, example of overriding
4031 @cindex stencil property, example
4033 @lilypond[quote,verbatim,ragged-right]
4036 % Visible tempo marking
4039 \once \omit Score.MetronomeMark
4040 % Invisible tempo marking to lengthen fermata in MIDI
4043 % New tempo for next section
4053 Both methods remove the metronome mark which lengthens the fermata
4054 from the printed output, and both affect the MIDI timing as
4055 required, but the transparent metronome mark in the first line
4056 forces the following tempo indication too high while the
4057 second (with the stencil removed) does not.
4063 @node Using variables for layout adjustments
4064 @subsection Using variables for layout adjustments
4066 @cindex variables, using for overrides
4067 @cindex overrides, using variables for
4068 @cindex adjustments, using variables for
4069 @cindex layout adjustments, using variables for
4071 Override commands are often long and tedious to type, and they
4072 have to be absolutely correct. If the same overrides are to be
4073 used many times it may be worth defining variables to hold them.
4075 Suppose we wish to emphasize certain words in lyrics by printing
4076 them in bold italics. The @code{\italic} and @code{\bold}
4077 commands only work within lyrics if they are embedded, together with
4078 the word or words to be modified, within a @code{\markup} block,
4079 which makes them tedious to enter. The need to embed the words
4080 themselves prevents their use in simple variables. As an
4081 alternative can we use @code{\override} and @code{\revert} commands?
4084 @code{\override Lyrics.LyricText.font-shape = #'italic}
4085 @code{\override Lyrics.LyricText.font-series = #'bold}
4087 @code{\revert Lyrics.LyricText.font-shape}
4088 @code{\revert Lyrics.LyricText.font-series}
4091 These would also be extremely tedious to enter if there were many
4092 words requiring emphasis. But we @emph{can} define these as two
4093 variables and use those to bracket the words to be emphasized.
4094 Another advantage of using variables for these overrides is that
4095 the spaces around the dot are not necessary, since they are not
4096 being interpreted in @code{\lyricmode} directly. Here's an example
4097 of this, although in practice we would choose shorter names
4098 for the variables to make them quicker to type:
4100 @cindex LyricText, example of overriding
4101 @cindex font-shape property, example
4102 @cindex font-series property, example
4104 @lilypond[quote,verbatim]
4106 \override Lyrics.LyricText.font-shape = #'italic
4107 \override Lyrics.LyricText.font-series = #'bold
4111 \revert Lyrics.LyricText.font-shape
4112 \revert Lyrics.LyricText.font-series
4115 global = { \key c \major \time 4/4 \partial 4 }
4117 SopranoMusic = \relative { c'4 | e4. e8 g4 g | a4 a g }
4118 AltoMusic = \relative { c'4 | c4. c8 e4 e | f4 f e }
4119 TenorMusic = \relative { e4 | g4. g8 c4. b8 | a8 b c d e4 }
4120 BassMusic = \relative { c4 | c4. c8 c4 c | f8 g a b c4 }
4122 VerseOne = \lyrics {
4123 E -- | ter -- nal \emphasize Fa -- ther, | \normal strong to save,
4126 VerseTwo = \lyricmode {
4127 O | \once \emphasize Christ, whose voice the | wa -- ters heard,
4130 VerseThree = \lyricmode {
4131 O | \emphasize Ho -- ly Spi -- rit, | \normal who didst brood
4134 VerseFour = \lyricmode {
4135 O | \emphasize Tri -- ni -- ty \normal of | love and pow'r
4142 \new Voice = "Soprano" { \voiceOne \global \SopranoMusic }
4143 \new Voice = "Alto" { \voiceTwo \AltoMusic }
4144 \new Lyrics \lyricsto "Soprano" { \VerseOne }
4145 \new Lyrics \lyricsto "Soprano" { \VerseTwo }
4146 \new Lyrics \lyricsto "Soprano" { \VerseThree }
4147 \new Lyrics \lyricsto "Soprano" { \VerseFour }
4151 \new Voice = "Tenor" { \voiceOne \TenorMusic }
4152 \new Voice = "Bass" { \voiceTwo \BassMusic }
4160 @subsection Style sheets
4162 The output that LilyPond produces can be heavily modified; see
4163 @ref{Tweaking output}, for details. But what if you have many
4164 input files that you want to apply your tweaks to? Or what if you
4165 simply want to separate your tweaks from the actual music? This
4166 is quite easy to do.
4168 Let's look at an example. Don't worry if you don't understand
4169 the parts with all the @code{#()}. This is explained in
4170 @ref{Advanced tweaks with Scheme}.
4172 @lilypond[quote,verbatim,ragged-right]
4174 \tweak self-alignment-X #-0.6
4175 #(make-dynamic-script
4176 #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4179 #(define-music-function
4182 #{ <>^\markup \bold \box #string #})
4186 a'4.\mpdolce d8 cis4--\glissando a |
4190 g8(\! fis)-. e( d)-. cis2 |
4194 Let's do something about the @code{mpdolce} and @code{inst} definitions.
4195 They produce the output we desire, but we might want to use them in
4196 another piece. We could simply copy-and-paste them at the top of every
4197 file, but that's an annoyance. It also leaves those definitions in our
4198 input files, and I personally find all the @code{#()} somewhat ugly.
4199 Let's hide them in another file:
4202 %%% save this to a file called "definitions.ily"
4204 \tweak self-alignment-X #-0.6
4205 #(make-dynamic-script
4206 #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4209 #(define-music-function
4212 #@{ <>^\markup \bold \box #string #@})
4215 We will refer to this file using the @code{\include} command near
4216 the top of the music file. (The extension @file{.ily} is used to
4217 distinguish this included file, which is not meant to be compiled
4218 on its own, from the main file.)
4219 Now let's modify our music (let's save this file as @file{music.ly}).
4221 @c We have to do this awkward example/lilypond-non-verbatim
4222 @c because we can't do the \include stuff in the manual.
4225 \include "definitions.ily"
4229 a'4.\mpdolce d8 cis4--\glissando a |
4233 g8(\! fis)-. e( d)-. cis2 |
4237 @lilypond[quote,ragged-right]
4239 \tweak self-alignment-X #-0.6
4240 #(make-dynamic-script
4241 #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4244 #(define-music-function
4247 #{ <>^\markup \bold \box #string #})
4251 a'4.\mpdolce d8 cis4--\glissando a |
4255 g8(\! fis)-. e( d)-. cis2 |
4259 That looks better, but let's make a few changes. The glissando is hard
4260 to see, so let's make it thicker and closer to the note heads. Let's
4261 put the metronome marking above the clef, instead of over the first
4262 note. And finally, my composition professor hates @q{C} time signatures,
4263 so we'd better make that @q{4/4} instead.
4265 Don't change @file{music.ly}, though. Replace our @file{definitions.ily}
4271 \tweak self-alignment-X #-0.6
4272 #(make-dynamic-script
4273 #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4276 #(define-music-function
4279 #@{ <>^\markup \bold \box #string #@})
4284 \override MetronomeMark.extra-offset = #'(-5 . 0)
4285 \override MetronomeMark.padding = #'3
4289 \override TimeSignature.style = #'numbered
4293 \override Glissando.thickness = #3
4294 \override Glissando.gap = #0.1
4299 @lilypond[quote,ragged-right]
4301 \tweak self-alignment-X #-0.6
4302 #(make-dynamic-script
4303 #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4306 #(define-music-function
4309 #{ <>^\markup \bold \box #string #})
4314 \override MetronomeMark.extra-offset = #'(-5 . 0)
4315 \override MetronomeMark.padding = #'3
4319 \override TimeSignature.style = #'numbered
4323 \override Glissando.thickness = #3
4324 \override Glissando.gap = #0.1
4330 a'4.\mpdolce d8 cis4--\glissando a |
4334 g8(\! fis)-. e( d)-. cis2 |
4338 That looks nicer! But now suppose that I want to publish this
4339 piece. My composition professor doesn't like @q{C} time
4340 signatures, but I'm somewhat fond of them. Let's copy the
4341 current @file{definitions.ily} to @file{web-publish.ily} and
4342 modify that. Since this music is aimed at producing a pdf which
4343 will be displayed on the screen, we'll also increase the
4344 overall size of the output.
4349 \tweak self-alignment-X #-0.6
4350 #(make-dynamic-script
4351 #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4354 #(define-music-function
4357 #@{ <>^\markup \bold \box #string #@})
4359 #(set-global-staff-size 23)
4364 \override MetronomeMark.extra-offset = #'(-5 . 0)
4365 \override MetronomeMark.padding = #'3
4372 \override Glissando.thickness = #3
4373 \override Glissando.gap = #0.1
4378 @lilypond[quote,ragged-right]
4380 \tweak self-alignment-X #-0.6
4381 #(make-dynamic-script
4382 #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4385 #(define-music-function
4388 #{ <>^\markup \bold \box #string #})
4390 #(set-global-staff-size 23)
4394 \override MetronomeMark.extra-offset = #'(-5 . 0)
4395 \override MetronomeMark.padding = #'3
4398 \override Glissando.thickness = #3
4399 \override Glissando.gap = #0.1
4405 a'4.\mpdolce d8 cis4--\glissando a |
4409 g8(\! fis)-. e( d)-. cis2 |
4413 Now in our music, I simply replace
4414 @code{\include "definitions.ily"} with
4415 @code{\include "web-publish.ily"}. Of course, we could make this
4416 even more convenient. We could make a @file{definitions.ily} file which
4417 contains only the definitions of @code{mpdolce} and @code{inst}, a
4418 @file{web-publish.ily} file which contains only the @code{\layout}
4419 section listed above, and a @file{university.ily} file which
4420 contains only the tweaks to produce the output that my professor
4421 prefers. The top of @file{music.ly} would then look like this:
4424 \include "definitions.ily"
4426 %%% Only uncomment one of these two lines!
4427 \include "web-publish.ily"
4428 %\include "university.ily"
4431 This approach can be useful even if you are only producing
4432 one set of parts. I use half a dozen different
4433 @q{style sheet} files for my projects. I begin every music
4434 file with @code{\include "../global.ily"}, which contains
4438 \version @w{"@version{}"}
4440 #(ly:set-option 'point-and-click #f)
4442 \include "../init/init-defs.ly"
4443 \include "../init/init-layout.ly"
4444 \include "../init/init-headers.ly"
4445 \include "../init/init-paper.ly"
4449 @node Other sources of information
4450 @subsection Other sources of information
4452 The Internals Reference documentation contains a lot of information
4453 about LilyPond, but even more information can be gathered by
4454 looking at the internal LilyPond files. To explore these, you must
4455 first find the directory appropriate to your system. The location
4456 of this directory depends (a) on whether you obtained LilyPond
4457 by downloading a precompiled binary from lilypond.org
4458 or whether you installed it from a package manager (i.e.
4459 distributed with GNU/Linux, or installed under fink or cygwin) or
4460 compiled it from source, and (b) on which operating system it is
4463 @subsubsubheading Downloaded from lilypond.org
4470 @file{@var{INSTALLDIR}/lilypond/usr/@/share/lilypond/current/}
4477 @file{@var{INSTALLDIR}/LilyPond.app/Contents/@/Resources/share/lilypond/current/}
4480 by either @code{cd}-ing into this directory from the
4481 Terminal, or control-clicking on the LilyPond application and
4482 selecting @q{Show Package Contents}.
4486 Using Windows Explorer, navigate to
4488 @file{@var{INSTALLDIR}/LilyPond/usr/@/share/lilypond/current/}
4493 @subsubsubheading Installed from a package manager or compiled from source
4496 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
4497 @var{PREFIX} is set by your package manager or @code{configure}
4498 script, and @var{X.Y.Z} is the LilyPond version number.
4502 Within this directory the two interesting subdirectories are
4505 @item @file{ly/} - contains files in LilyPond format
4506 @item @file{scm/} - contains files in Scheme format
4509 Let's begin by looking at some files in @file{ly/}.
4510 Open @file{ly/property-init.ly} in a text editor. The one
4511 you normally use for @code{.ly} files will be fine. This file
4512 contains the definitions of all the standard LilyPond predefined
4513 commands, such as @code{\tieUp} and @code{\slurDotted}. You will
4514 see that these are nothing more than definitions of variables
4515 containing one or a group of @code{\override} commands. For
4516 example, @code{\tieDotted} is defined to be:
4520 \override Tie.dash-period = #0.75
4521 \override Tie.dash-fraction = #0.1
4525 If you do not like the default values these predefined commands can
4526 be redefined easily, just like any other variable, at the
4527 head of your input file.
4529 The following are the most useful files to be found in
4532 @multitable @columnfractions .4 .6
4535 @item @file{ly/engraver-init.ly}
4536 @tab Definitions of engraver Contexts
4537 @item @file{ly/paper-defaults-init.ly}
4538 @tab Specifications of paper-related defaults
4539 @item @file{ly/performer-init.ly}
4540 @tab Definitions of performer Contexts
4541 @item @file{ly/property-init.ly}
4542 @tab Definitions of all common predefined commands
4543 @item @file{ly/spanner-init.ly}
4544 @tab Definitions of spanner-related predefined commands
4547 Other settings (such as the definitions of markup commands) are
4548 stored as @file{.scm} (Scheme) files. The Scheme programming
4549 language is used to provide a programmable interface into
4550 LilyPond internal operation. Further explanation of these files
4551 is currently outside the scope of this manual, as a knowledge of
4552 the Scheme language is required. Users should be warned that
4553 a substantial amount of technical knowledge or time is required
4554 to understand Scheme and these files (see @rextend{Scheme tutorial}).
4556 If you have this knowledge, the Scheme files which may be of
4559 @multitable @columnfractions .4 .6
4562 @item @file{scm/auto-beam.scm}
4563 @tab Sub-beaming defaults
4564 @item @file{scm/define-grobs.scm}
4565 @tab Default settings for grob properties
4566 @item @file{scm/define-markup-commands.scm}
4567 @tab Specify all markup commands
4568 @item @file{scm/midi.scm}
4569 @tab Default settings for MIDI output
4570 @item @file{scm/output-lib.scm}
4571 @tab Settings that affect appearance of frets, colors,
4572 accidentals, bar lines, etc
4573 @item @file{scm/parser-clef.scm}
4574 @tab Definitions of supported clefs
4575 @item @file{scm/script.scm}
4576 @tab Default settings for articulations
4580 @node Advanced tweaks with Scheme
4581 @subsection Advanced tweaks with Scheme
4583 Although many things are possible with the @code{\override} and
4584 @code{\tweak} commands, an even more powerful way of modifying
4585 the action of LilyPond is available through a programmable
4586 interface to the LilyPond internal operation. Code written in
4587 the Scheme programming language can be incorporated directly in
4588 the internal operation of LilyPond. Of course, at least a basic
4589 knowledge of programming in Scheme is required to do this, and an
4590 introduction is provided in the @rextend{Scheme tutorial}.
4592 As an illustration of one of the many possibilities, instead of
4593 setting a property to a constant it can be set to a Scheme
4594 procedure which is then called whenever that property is accessed
4595 by LilyPond. The property can then be set dynamically to a value
4596 determined by the procedure at the time it is called. In this
4597 example we color the note head in accordance with its position on
4600 @cindex x11-color function, example of using
4601 @cindex NoteHead, example of overriding
4602 @cindex color property, setting to Scheme procedure
4604 @lilypond[quote,verbatim,ragged-right]
4605 #(define (color-notehead grob)
4606 "Color the notehead according to its position on the staff."
4607 (let ((mod-position (modulo (ly:grob-property grob 'staff-position)
4610 ;; Return rainbow colors
4611 ((1) (x11-color 'red )) ; for C
4612 ((2) (x11-color 'orange )) ; for D
4613 ((3) (x11-color 'yellow )) ; for E
4614 ((4) (x11-color 'green )) ; for F
4615 ((5) (x11-color 'blue )) ; for G
4616 ((6) (x11-color 'purple )) ; for A
4617 ((0) (x11-color 'violet )) ; for B
4621 % Arrange to obtain color from color-notehead procedure
4622 \override NoteHead.color = #color-notehead
4623 a2 b | c2 d | e2 f | g2 a |
4627 Further examples showing the use of these programmable interfaces
4628 can be found in @rextend{Callback functions}.