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::
25 * Collisions of objects::
30 @section Tweaking basics
33 * Introduction to tweaks::
34 * Objects and interfaces::
35 * Naming conventions of objects and properties::
39 @node Introduction to tweaks
40 @subsection Introduction to tweaks
42 @q{Tweaking} is a LilyPond term for the various methods available
43 to the user for modifying the actions taken during interpretation
44 of the input file and modifying the appearance of the printed
45 output. Some tweaks are very easy to use; others are more
46 complex. But taken together the methods available for tweaking
47 permit almost any desired appearance of the printed music to be
50 In this section we cover the basic concepts required to understand
51 tweaking. Later we give a variety of ready-made commands which can
52 simply be copied to obtain the same effect in your own scores, and
53 at the same time we show how these commands may be constructed so
54 that you may learn how to develop your own tweaks.
56 Before starting on this Chapter you may wish to review the section
57 @ref{Contexts and engravers}, as Contexts, Engravers, and the
58 Properties contained within them are fundamental to understanding
59 and constructing Tweaks.
61 @node Objects and interfaces
62 @subsection Objects and interfaces
68 @cindex properties, object
69 @cindex object properties
71 @cindex object, layout
74 Tweaking involves modifying the internal operation and structures
75 of the LilyPond program, so we must first introduce some terms
76 which are used to describe those internal operations and
79 The term @q{Object} is a generic term used to refer to the
80 multitude of internal structures built by LilyPond during the
81 processing of an input file. So when a command like @code{\new
82 Staff} is encountered a new object of type @code{Staff} is
83 constructed. That @code{Staff} object then holds all the
84 properties associated with that particular staff, for example, its
85 name and its key signature, together with details of the engravers
86 which have been assigned to operate within that staff's context.
87 Similarly, there are objects to hold the properties of all other
88 contexts, such as @code{Voice} objects, @code{Score} objects,
89 @code{Lyrics} objects, as well as objects to represent all
90 notational elements such as bar lines,
91 note heads, ties, dynamics, etc. Every object has its own set of
94 Some types of object are given special names. Objects which represent
95 items of notation on the printed output such as note heads, stems,
96 slurs, ties, fingering, clefs, etc are called @q{Layout objects},
97 often known as @q{Graphical Objects}, or @q{Grobs} for short. These
98 are still objects in the generic sense above, and so they too all have
99 properties associated with them, such as their position, size, color,
102 Some layout objects are still more specialized. Phrasing slurs,
103 crescendo hairpins, ottava marks, and many other grobs are not
104 localized in a single place -- they have a starting point, an
105 ending point, and maybe other properties concerned with their
106 shape. Objects with an extended shape like these are called
109 It remains to explain what @q{Interfaces} are. Many objects, even
110 though they are quite different, share common features which need to
111 be processed in the same way. For example, all grobs have a color, a
112 size, a position, etc, and all these properties are processed in the
113 same way during LilyPond's interpretation of the input file. To
114 simplify these internal operations these common actions and properties
115 are grouped together in an object called a @code{grob-interface}.
116 There are many other groupings of common properties like this, each
117 one given a name ending in @code{interface}. In total there are over
118 100 such interfaces. We shall see later why this is of interest and
121 These, then, are the main terms relating to objects which we
122 shall use in this chapter.
124 @node Naming conventions of objects and properties
125 @subsection Naming conventions of objects and properties
127 @cindex naming conventions for objects
128 @cindex naming conventions for properties
129 @cindex objects, naming conventions
130 @cindex properties, naming conventions
132 We met some object naming conventions previously, in
133 @ref{Contexts and engravers}. Here for reference is a list
134 of the most common object and property types together with
135 the conventions for naming them and a couple of examples of
136 some real names. We have used @q{A} to stand for any capitalized
137 alphabetic character and @q{aaa} to stand for any number of
138 lower-case alphabetic characters. Other characters are used
141 @multitable @columnfractions .33 .33 .33
142 @headitem Object/property type
143 @tab Naming convention
146 @tab Aaaa or AaaaAaaaAaaa
147 @tab Staff, GrandStaff
149 @tab Aaaa or AaaaAaaaAaaa
152 @tab Aaaa_aaa_engraver
153 @tab Clef_engraver, Note_heads_engraver
155 @tab aaa-aaa-interface
156 @tab grob-interface, break-aligned-interface
157 @item Context Properties
158 @tab aaa or aaaAaaaAaaa
159 @tab alignAboveContext, skipBars
160 @item Layout Object Properties
161 @tab aaa or aaa-aaa-aaa
162 @tab direction, beam-thickness
165 As we shall see shortly, the properties of different types of object are
166 modified by different commands, so it is useful to be able to recognize
167 the types of objects and properties from their names.
170 @node Tweaking methods
171 @subsection Tweaking methods
173 @cindex tweaking methods
176 * The \override command::
177 * The \revert command::
179 * The \overrideProperty command::
180 * The \tweak command::
183 @node The \override command
184 @unnumberedsubsubsec The @code{\override} command
186 @cindex override command
187 @cindex override syntax
192 We have already met the commands @code{\set} and @code{\with}, used to
193 change the properties of @strong{contexts} and to remove and add
194 @strong{engravers}, in @ref{Modifying context properties}, and
195 @ref{Adding and removing engravers}. We must now introduce some more
198 The command to change the properties of @strong{layout objects} is
199 @code{\override}. Because this command has to modify
200 internal properties deep within LilyPond its syntax is not
201 as simple as the commands you have used so far. It needs to
202 know precisely which property of which object in which context
203 has to be modified, and what its new value is to be. Let's see
206 The general syntax of this command is:
209 \override @var{Context}.@var{LayoutObject}.@var{layout-property} = #@var{value}
213 This will set the property with the name @var{layout-property} of the
214 layout object with the name @var{LayoutObject}, which is a member of
215 the @var{Context} context, to the value @var{value}.
217 The @var{Context} may be omitted (and usually is) when the
218 required context is unambiguously implied and is one of lowest
219 level contexts, i.e., @code{Voice}, @code{ChordNames} or
220 @code{Lyrics}, and we shall omit it in many of the following
221 examples. We shall see later when it must be specified.
223 Later sections deal comprehensively with properties and their
224 values, see @ref{Types of properties}. But in this section we shall
225 use just a few simple properties and values which are easily
226 understood in order to illustrate the format and use of these
229 LilyPond's primary expressions are musical items like notes,
230 durations, and markups. More basic expressions like numbers,
231 strings, and lists are processed in @q{Scheme mode}, which is
232 invoked by prefixing the value with @samp{#}. Although the
233 values may sometimes have a valid representation in LilyPond's
234 musical mode, this manual will always use @samp{#} for their
235 entry for the sake of consistency. For more information about
236 Scheme mode, see @rextend{LilyPond Scheme syntax}.
238 @code{\override} is the most common command used in tweaking, and
239 most of the rest of this chapter will be directed to presenting
240 examples of how it is used. Here is a simple example to change the
241 color of the note head:
243 @cindex color property, example
244 @cindex NoteHead, example of overriding
246 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
248 \override NoteHead.color = #red
250 \override NoteHead.color = #green
255 @node The \revert command
256 @unnumberedsubsubsec The @code{\revert} command
258 @cindex revert command
263 Once overridden, the property retains its new value until it is
264 overridden again or a @code{\revert} command is encountered.
265 The @code{\revert} command has the following syntax and causes
266 the value of the property to revert to its original default
267 value; note, not its previous value if several @code{\override}
268 commands have been issued.
271 \revert @var{Context}.@var{LayoutObject}.@var{layout-property}
274 Again, just like @var{Context} in the @code{\override} command,
275 @var{Context} is often not needed. It will be omitted
276 in many of the following examples. Here we revert the color
277 of the note head to the default value for the final two notes:
279 @cindex color property, example
280 @cindex NoteHead, example of overriding
282 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
284 \override NoteHead.color = #red
286 \override NoteHead.color = #green
288 \revert NoteHead.color
293 @node The \once prefix
294 @unnumberedsubsubsec The @code{\once} prefix
299 Both the @code{\override} and the @code{\set} commands may be prefixed
300 by @code{\once}. This causes the following @code{\override} or
301 @code{\set} command to be effective only during the current musical
302 moment before the property reverts back to its previous value (this can
303 be different from the default if another @code{\override} is still in
304 effect). Using the same example, we can change the color of a single
307 @cindex color property, example
308 @cindex NoteHead, example of overriding
310 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
312 \override NoteHead.color = #red
314 \once \override NoteHead.color = #green
316 \revert NoteHead.color
321 @node The \overrideProperty command
322 @unnumberedsubsubsec The @code{\overrideProperty} command
324 @cindex overrideProperty command
326 @funindex \overrideProperty
327 @funindex overrideProperty
329 There is another form of the override command,
330 @code{\overrideProperty}, which is occasionally required.
331 We mention it here for completeness, but for details see
332 @rextend{Difficult tweaks}.
333 @c Maybe explain in a later iteration -td
336 @node The \tweak command
337 @unnumberedsubsubsec The @code{\tweak} command
339 @cindex tweak command
344 The final tweaking command which is available is @code{\tweak}. This
345 should be used when several objects occur at the same musical moment,
346 but you only want to change the properties of selected ones, such as a
347 single note within a chord. Using @code{\override} would affect all the
348 notes within a chord, whereas @code{\tweak} affects just the following
349 item in the input stream.
351 Here's an example. Suppose we wish to change the size of the
352 middle note head (the E) in a C major chord. Let's first see what
353 @code{\once \override} would do:
355 @cindex font-size property, example
356 @cindex NoteHead, example of overriding
358 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
360 \once \override NoteHead.font-size = #-3
365 We see the override affects @emph{all} the note heads in the chord.
366 This is because all the notes of a chord occur at the same
367 @emph{musical moment}, and the action of @code{\once} is to
368 apply the override to all layout objects of the type specified
369 which occur at the same musical moment as the @code{\override}
372 The @code{\tweak} command operates in a different way. It acts on
373 the immediately following item in the input stream. In its simplest
374 form, it is effective only on objects which are created directly
375 from the following item, essentially note heads and articulations.
377 So to return to our example, the size of the middle note of
378 a chord would be changed in this way:
380 @cindex font-size property, example
381 @cindex @code{\tweak}, example
383 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
385 <c \tweak font-size #-3 e g>4
388 Note that the syntax of @code{\tweak} is different from that of the
389 @code{\override} command. The context should not be specified; in
390 fact, it would generate an error to do so. Both context and layout
391 object are implied by the following item in the input stream. Note
392 also that an equals sign should not be present. So the simple form
393 of the @code{\tweak} command is
396 \tweak @var{layout-property} #@var{value}
399 A @code{\tweak} command can also be used to modify just one in
400 a series of articulations, as shown here:
402 @cindex color property, example
403 @cindex @code{\tweak}, example
405 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
407 -\tweak color #red ^"Red"
408 -\tweak color #green _"Green"
412 Note that the @code{\tweak} command must be preceded by an articulation
413 mark since the tweaked expression needs to be applied as an articulation
414 itself. In case of multiple direction overrides (@code{^} or @code{_}),
415 the leftmost override wins since it is applied last.
417 @cindex @code{\tweak}, Accidental
418 @cindex @code{\tweak}, specific layout object
420 Objects such as stems and accidentals are created later, and not
421 directly from the following event. It is still possible to use
422 @code{\tweak} on such indirectly created objects by explicitly naming
423 the layout object, provided that LilyPond can trace its origin back to
426 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
427 <\tweak Accidental.color #red cis4
428 \tweak Accidental.color #green es
432 This long form of the @code{\tweak} command can be described as
435 \tweak @var{layout-object}.@var{layout-property} @var{value}
438 @cindex tuplets, nested
439 @cindex triplets, nested
440 @cindex bracket, tuplet
441 @cindex bracket, triplet
442 @cindex tuplet bracket
443 @cindex triplet bracket
445 @funindex TupletBracket
447 The @code{\tweak} command must also be used to change the
448 appearance of one of a set of nested tuplets which begin at the
449 same musical moment. In the following example, the long tuplet
450 bracket and the first of the three short brackets begin at the
451 same musical moment, so any @code{\override} command would apply
452 to both of them. In the example, @code{\tweak} is used to
453 distinguish between them. The first @code{\tweak} command
454 specifies that the long tuplet bracket is to be placed above the
455 notes and the second one specifies that the tuplet number is to be
456 printed in red on the first short tuplet bracket.
458 @cindex @code{\tweak}, example
459 @cindex direction property, example
460 @cindex color property, example
462 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
466 \times 2/3 { c8[ c c] }
467 \times 2/3 { c8[ c c] }
468 \times 2/3 { c8[ c c] }
472 If nested tuplets do not begin at the same moment, their
473 appearance may be modified in the usual way with
474 @code{\override} commands:
476 @cindex text property, example
477 @cindex tuplet-number function, example
478 @cindex transparent property, example
479 @cindex TupletNumber, example of overriding
481 @lilypond[quote,ragged-right,verbatim,fragment,relative=1]
482 \times 2/3 { c8[ c c] }
483 \once \override TupletNumber.text = #tuplet-number::calc-fraction-text
487 \once \override TupletNumber.transparent = ##t
488 \times 2/3 { c8[ c c] }
489 \times 2/3 { c8[ c c] }
496 @ruser{The tweak command}.
499 @node The Internals Reference manual
500 @section The Internals Reference manual
502 @cindex Internals Reference
505 * Properties of layout objects::
506 * Properties found in interfaces::
507 * Types of properties::
510 @node Properties of layout objects
511 @subsection Properties of layout objects
513 @cindex properties of layout objects
514 @cindex properties of grobs
515 @cindex grobs, properties of
516 @cindex layout objects, properties of
517 @cindex Internals Reference manual
519 Suppose you have a slur in a score which, to your mind,
520 appears too thin and you'd like to draw it a little heavier.
521 How do you go about doing this? You know from the statements
522 earlier about the flexibility of LilyPond that such a thing
523 should be possible, and you would probably guess that an
524 @code{\override} command would be needed. But is there a
525 heaviness property for a slur, and if there is, how might it
526 be modified? This is where the Internals Reference manual
527 comes in. It contains all the information you might need to
528 construct this and all other @code{\override} commands.
530 Before we look at the Internals Reference a word of warning.
531 This is a @strong{reference} document, which means there is
532 little or no explanation contained within it: its purpose is
533 to present information precisely and concisely. This
534 means it might look daunting at first sight. Don't worry!
535 The guidance and explanation presented here will enable you
536 to extract the information from the Internals Reference for
537 yourself with just a little practice.
539 @cindex override example
540 @cindex Internals Reference, example of using
541 @cindex @code{\addlyrics} example
543 Let's use a concrete example with a simple fragment of real
546 @c Mozart, Die Zauberflöte Nr.7 Duett
548 @lilypond[quote,verbatim,relative=2]
553 r4 bes8 bes[( g]) g |
554 g8[( es]) es d[( f]) as |
558 The man who | feels love's sweet e -- | mo -- tion
563 Suppose now that we decide we would like the slurs to be a
564 little heavier. Is this possible? The slur is certainly a
565 layout object, so the question is, @q{Is there a property
566 belonging to a slur which controls the heaviness?} To answer
567 this we must look in the Internals Reference, or IR for short.
569 The IR for the version of LilyPond you are using may be found
570 on the LilyPond website at @uref{http://lilypond.org}. Go to the
571 documentation page and click on the Internals Reference link.
572 For learning purposes you should use the standard HTML version,
573 not the @q{one big page} or the PDF. For the next few
574 paragraphs to make sense you will need to actually do this
577 Under the heading @strong{Top} you will see five links. Select
578 the link to the @emph{Backend}, which is where information about
579 layout objects is to be found. There, under the heading
580 @strong{Backend}, select the link to @emph{All layout objects}.
581 The page that appears lists all the layout objects used in your
582 version of LilyPond, in alphabetic order. Select the link to
583 Slur, and the properties of Slurs are listed.
585 An alternative way of finding this page is from the Notation
586 Reference. On one of the pages that deals with slurs you may find a
587 link to the Internals Reference. This link will take you directly to
588 this page, but if you have an idea about the name of the layout object
589 to be tweaked, it is easier to go straight to the IR and search there.
591 This Slur page in the IR tells us first that Slur objects are created
592 by the Slur_engraver. Then it lists the standard settings. Browse
593 through them looking for a property that might control the heaviness of
594 slurs, and you should find
597 @code{thickness} (number)
599 Line thickness, generally measured in @code{line-thickness}
602 This looks a good bet to change the heaviness. It tells us that
603 the value of @code{thickness} is a simple @emph{number},
604 that the default value is 1.2, and that the units are
605 in another property called @code{line-thickness}.
607 As we said earlier, there are few to no explanations in the IR,
608 but we already have enough information to try changing the
609 slur thickness. We see that the name of the layout object
610 is @code{Slur}, that the name of the property to change is
611 @code{thickness} and that the new value should be a number
612 somewhat larger than 1.2 if we are to make slurs thicker.
614 We can now construct the @code{\override} command by simply
615 substituting the values we have found for the names, omitting
616 the context. Let's use a very large value for the thickness
617 at first, so we can be sure the command is working. We get:
620 \override Slur.thickness = #5.0
623 Don't forget the@tie{}@code{#} preceding the new value!
625 The final question is, @q{Where should this command be
626 placed?} While you are unsure and learning, the best
627 answer is, @q{Within the music, before the first slur and
628 close to it.} Let's do that:
630 @cindex Slur example of overriding
631 @cindex thickness property, example
633 @lilypond[quote,verbatim,relative=2]
638 % Increase thickness of all following slurs from 1.2 to 5.0
639 \override Slur.thickness = #5.0
640 r4 bes8 bes[( g]) g |
641 g8[( es]) es d[( f]) as |
645 The man who | feels love's sweet e -- | mo -- tion
651 and we see that the slur is indeed heavier.
653 So this is the basic way of constructing @code{\override}
654 commands. There are a few more complications that we
655 shall meet in later sections, but you now know all the
656 essentials required to make up your own -- but you will
657 still need some practice. This is provided in the examples
660 @subsubsubheading Finding the context
662 @cindex context, finding
663 @cindex context, identifying correct
665 But first, what if we had needed to specify the Context?
666 What should it be? We could guess that slurs are in
667 the Voice context, as they are clearly closely associated
668 with individual lines of music, but can we be sure? To
669 find out, go back to the top of the IR page describing the
670 Slur, where it says @q{Slur objects are created by: Slur
671 engraver}. So slurs will be created in whichever context
672 the @code{Slur_engraver} is in. Follow the link to the
673 @code{Slur_engraver} page. At the very bottom it tells
674 us that @code{Slur_engraver} is part of seven Voice contexts,
675 including the standard voice context, @code{Voice}, so our
676 guess was correct. And because @code{Voice} is one of the
677 lowest level contexts which is implied unambiguously by
678 the fact that we are entering notes, we can omit it in this
681 @subsubsubheading Overriding once only
683 @cindex overriding once only
684 @cindex once override
689 As you can see, @emph{all} the slurs are thicker in the final example
690 above. But what if we wanted just the first slur to be thicker? This
691 is achieved with the @code{\once} command. Placed immediately before
692 the @code{\override} command it causes it to change only the slur
693 which begins on the @strong{immediately following} note. If the
694 immediately following note does not begin a slur the command has no
695 effect at all -- it is not remembered until a slur is encountered, it
696 is simply discarded. So the command with @code{\once} must be
697 repositioned as follows:
699 @cindex Slur, example of overriding
700 @cindex thickness property, example
702 @lilypond[quote,verbatim,relative=2]
708 % Increase thickness of immediately following slur only
709 \once \override Slur.thickness = #5.0
711 g8[( es]) es d[( f]) as |
715 The man who | feels love's sweet e -- | mo -- tion
721 Now only the first slur is made heavier.
723 The @code{\once} command can also be used before the @code{\set}
726 @subsubsubheading Reverting
729 @cindex default properties, reverting to
734 Finally, what if we wanted just the first two slurs to be
735 heavier? Well, we could use two commands, each preceded by
736 @code{\once} placed immediately before each of the notes where
739 @cindex Slur, example of overriding
740 @cindex thickness property, example
742 @lilypond[quote,verbatim,relative=2]
748 % Increase thickness of immediately following slur only
749 \once \override Slur.thickness = #5.0
751 % Increase thickness of immediately following slur only
752 \once \override Slur.thickness = #5.0
753 g8[( es]) es d[( f]) as |
757 The man who | feels love's sweet e -- | mo -- tion
763 or we could omit the @code{\once} command and use the @code{\revert}
764 command to return the @code{thickness} property to its default value
765 after the second slur:
767 @cindex Slur, example of overriding
768 @cindex thickness property, example
770 @lilypond[quote,verbatim,relative=2]
776 % Increase thickness of all following slurs from 1.2 to 5.0
777 \override Slur.thickness = #5.0
780 % Revert thickness of all following slurs to default of 1.2
781 \revert Slur.thickness
786 The man who | feels love's sweet e -- | mo -- tion
792 The @code{\revert} command can be used to return any property
793 changed with @code{\override} back to its default value.
794 You may use whichever method best suits what you want to do.
796 That concludes our introduction to the IR, and the basic
797 method of tweaking. Several examples follow in the later
798 sections of this Chapter, partly to introduce you to some of the
799 additional features of the IR, and partly to give you more
800 practice in extracting information from it. These examples will
801 contain progressively fewer words of guidance and explanation.
804 @node Properties found in interfaces
805 @subsection Properties found in interfaces
808 @cindex interface properties
809 @cindex properties in interfaces
811 Suppose now that we wish to print the lyrics in italics. What form of
812 @code{\override} command do we need to do this? We first look in the
813 IR page listing @q{All layout objects}, as before, and look for an
814 object that might control lyrics. We find @code{LyricText}, which
815 looks right. Clicking on this shows the settable properties for lyric
816 text. These include the @code{font-series} and @code{font-size}, but
817 nothing that might give an italic shape. This is because the shape
818 property is one that is common to all font objects, so, rather than
819 including it in every layout object, it is grouped together with other
820 similar common properties and placed in an @strong{Interface}, the
821 @code{font-interface}.
823 So now we need to learn how to find the properties of interfaces,
824 and to discover what objects use these interface properties.
826 Look again at the IR page which describes LyricText. At the bottom of
827 the page is a list of clickable interfaces which LyricText supports.
828 The list has several items, including @code{font-interface}. Clicking
829 on this brings up the properties associated with this interface, which
830 are also properties of all the objects which support it, including
833 Now we see all the user-settable properties which control fonts,
834 including @code{font-shape(symbol)}, where @code{symbol} can be
835 set to @code{upright}, @code{italics} or @code{caps}.
837 You will notice that @code{font-series} and @code{font-size} are also
838 listed there. This immediately raises the question: Why are the
839 common font properties @code{font-series} and @code{font-size} listed
840 under @code{LyricText} as well as under the interface
841 @code{font-interface} but @code{font-shape} is not? The answer is
842 that @code{font-series} and @code{font-size} are changed from their
843 global default values when a @code{LyricText} object is created, but
844 @code{font-shape} is not. The entries in @code{LyricText} then tell
845 you the values for those two properties which apply to
846 @code{LyricText}. Other objects which support @code{font-interface}
847 will set these properties differently when they are created.
849 Let's see if we can now construct the @code{\override} command
850 to change the lyrics to italics. The object is @code{LyricText},
851 the property is @code{font-shape} and the value is
852 @code{italic}. As before, we'll omit the context.
854 As an aside, although it is an important one, note that some
855 properties take values that are symbols, like @code{italic}, and
856 must be preceded by an apostrophe, @code{'}. Symbols are then
857 read internally by LilyPond. Note the distinction from arbitrary
858 text strings, which would appear as @code{"a text string"}; for
859 more details about symbols and strings, see @rextend{Scheme tutorial}.
861 So we see that the @code{\override} command needed to print the lyrics
865 \override LyricText.font-shape = #'italic
869 This should be placed just in front of the lyrics we wish to affect,
872 @cindex font-shape property, example
873 @cindex italic, example
874 @cindex LyricText, example of overriding
875 @cindex @code{\addlyrics}, example
877 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
882 r4 bes8 bes[( g]) g |
883 g8[( es]) es d[( f]) as |
887 \override LyricText.font-shape = #'italic
888 The man who | feels love's sweet e -- | mo -- tion
894 and the lyrics are all printed in italics.
896 @warning{In lyrics always leave whitespace between the final
897 syllable and the terminating brace.}
901 Extending: @rextend{Scheme tutorial}.
904 @node Types of properties
905 @subsection Types of properties
907 @cindex property types
909 So far we have seen two types of property: @code{number} and
910 @code{symbol}. To be valid, the value given to a property
911 must be of the correct type and obey the rules for that type.
912 The type of property is always shown in brackets after the
913 property name in the IR. Here is a list of the types you may
914 need, together with the rules for that type, and some examples.
915 You must always add a hash symbol, @code{#}, of course,
916 to the front of these values when they are entered in the
917 @code{\override} command.
919 @multitable @columnfractions .2 .45 .35
920 @headitem Property type
924 @tab Either True or False, represented by #t or #f
925 @tab @code{#t}, @code{#f}
926 @item Dimension (in staff space)
927 @tab A positive decimal number (in units of staff space)
928 @tab @code{2.5}, @code{0.34}
930 @tab A valid direction constant or its numerical equivalent (decimal
931 values between -1 and 1 are allowed)
932 @tab @code{LEFT}, @code{CENTER}, @code{UP},
933 @code{1}, @w{@code{-1}}
935 @tab A positive whole number
936 @tab @code{3}, @code{1}
938 @tab A set of values separated by spaces, enclosed in parentheses
939 and preceded by an apostrophe
940 @tab @code{'(left-edge staff-bar)}, @code{'(1)},
941 @code{'(1.0 0.25 0.5)}
943 @tab Any valid markup
944 @tab @code{\markup @{ \italic "cresc." @}}
946 @tab A fraction of a whole note constructed with the
948 @tab @code{(ly:make-moment 1 4)},
949 @code{(ly:make-moment 3 8)}
951 @tab Any positive or negative decimal value
952 @tab @code{3.5}, @w{@code{-2.45}}
953 @item Pair (of numbers)
954 @tab Two numbers separated by a @q{space . space} and enclosed
955 in brackets preceded by an apostrophe
956 @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
958 @tab Any of the set of permitted symbols for that property,
959 preceded by an apostrophe
960 @tab @code{'italic}, @code{'inside}
962 @tab A procedure, or @code{#f} to cause no action
963 @tab @code{bend::print}, @code{ly:text-interface::print},
966 @tab A list of three items enclosed in parentheses and preceded
967 by apostrophe-hash, @code{'#}.
968 @tab @code{'#(#t #t #f)}
973 Extending: @rextend{Scheme tutorial}.
976 @node Appearance of objects
977 @section Appearance of objects
979 Let us now put what we have learned into practice with a few
980 examples which show how tweaks may be used to change the
981 appearance of the printed music.
984 * Visibility and color of objects::
986 * Length and thickness of objects::
989 @node Visibility and color of objects
990 @subsection Visibility and color of objects
992 In the educational use of music we might wish to print a score
993 with certain elements omitted as an exercise for the student,
994 who is required to supply them. As a simple example,
995 let us suppose the exercise is to supply the missing bar lines
996 in a piece of music. But the bar lines are normally inserted
997 automatically. How do we prevent them printing?
999 Before we tackle this, let us remember that object properties are
1000 grouped in what are called @emph{interfaces} -- see @ref{Properties
1001 found in interfaces}. This is simply to group together those
1002 properties that may be used together to tweak a graphical object -- if
1003 one of them is allowed for an object, so are the others. Some objects
1004 then use the properties in some interfaces, others use them from other
1005 interfaces. The interfaces which contain the properties used by a
1006 particular grob are listed in the IR at the bottom of the page
1007 describing that grob, and those properties may be viewed by looking at
1010 We explained how to find information about grobs in @ref{Properties of
1011 layout objects}. Using the same approach, we go to the IR to find the
1012 layout object which prints bar lines. Going via @emph{Backend} and
1013 @emph{All layout objects} we find there is a layout object called
1014 @code{BarLine}. Its properties include two that control its
1015 visibility: @code{break-visibility} and @code{stencil}. Barline also
1016 supports a number of interfaces, including the @code{grob-interface},
1017 where we find the @code{transparent} and the @code{color} properties.
1018 All of these can affect the visibility of bar lines (and, of course,
1019 by extension, many other layout objects too.) Let's consider each of
1023 * The stencil property::
1024 * The break-visibility property::
1025 * The transparent property::
1026 * The color property::
1029 @node The stencil property
1030 @unnumberedsubsubsec The @code{stencil} property
1032 @cindex stencil property
1034 This property controls the appearance of the bar lines by specifying
1035 the symbol (glyph) which should be printed. In common
1036 with many other properties, it can be set to print nothing by
1037 setting its value to @code{#f}. Let's try it, as before, omitting
1038 the implied Context, @code{Voice}:
1040 @cindex BarLine, example of overriding
1041 @cindex stencil property, example
1043 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1046 \override BarLine.stencil = ##f
1048 g,8 a16 b8 c d4 e16 |
1053 The bar lines are still printed. What is wrong? Go back to the IR
1054 and look again at the page giving the properties of BarLine. At the
1055 top of the page it says @qq{Barline objects are created by:
1056 Bar_engraver}. Go to the @code{Bar_engraver} page. At the bottom it
1057 gives a list of Contexts in which the bar engraver operates. All of
1058 them are of the type @code{Staff}, so the reason the @code{\override}
1059 command failed to work as expected is because @code{Barline} is not in
1060 the default @code{Voice} context. If the context is specified
1061 incorrectly, the command simply does not work. No error message is
1062 produced, and nothing is logged in the log file. Let's try correcting
1063 it by adding the correct context:
1065 @cindex BarLine, example of overriding
1066 @cindex stencil property, example
1068 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1071 \override Staff.BarLine.stencil = ##f
1073 g,8 a16 b8 c d4 e16 |
1078 Now the bar lines have vanished. Setting the @code{stencil}
1079 property to @code{#f} is such a frequent operation that there is a
1080 shorthand for it called @code{\omit}:
1083 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1088 g,8 a16 b8 c d4 e16 |
1093 Note, though, that setting the @code{stencil} property to @code{#f}
1094 will cause errors when the dimensions of the object are required for
1095 correct processing. For example, errors will be generated if the
1096 @code{stencil} property of the @code{NoteHead} object is set to
1097 @code{#f}. If this is the case, you can instead use the
1098 @code{point-stencil} function, which sets the stencil to a object
1101 @lilypond[quote,verbatim,relative=2]
1104 \once \override NoteHead.stencil = #point-stencil
1109 @node The break-visibility property
1110 @unnumberedsubsubsec The @code{break-visibility} property
1112 @cindex break-visibility property
1114 We see from the @code{BarLine} properties in the IR that the
1115 @code{break-visibility} property requires a vector of three booleans.
1116 These control respectively whether bar lines are printed at the end of
1117 a line, in the middle of lines, and at the beginning of lines. For
1118 our example we want all bar lines to be suppressed, so the value we
1119 need is @code{#(#f #f #f)} (also available
1120 under the name @code{all-invisible}). Let's try that, remembering to include
1121 the @code{Staff} context. Note also that in writing this value we
1122 have @code{##} before the opening parenthesis. One @code{#} is required
1123 as part of vector constant syntax, and the first@tie{}@code{#} is
1124 required, as always, to precede the value itself in the
1125 @code{\override} command.
1127 @cindex BarLine, example of overriding
1128 @cindex break-visibility property, example
1130 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1133 \override Staff.BarLine.break-visibility = ##(#f #f #f)
1135 g,8 a16 b8 c d4 e16 |
1140 And we see this too removes all the bar lines.
1142 @node The transparent property
1143 @unnumberedsubsubsec The @code{transparent} property
1145 @cindex transparent property
1146 @cindex transparency
1148 We see from the properties specified in the @code{grob-interface} page
1149 in the IR that the @code{transparent} property is a boolean. This
1150 should be set to @code{#t} to make the grob transparent. In this next
1151 example let us make the time signature invisible rather than the bar
1152 lines. To do this we need to find the grob name for the time
1153 signature. Back to the @q{All layout objects} page in the IR to find
1154 the properties of the @code{TimeSignature} layout object. This is
1155 produced by the @code{Time_signature_engraver} which you can check
1156 also lives in the @code{Staff} context and also supports the
1157 @code{grob-interface}. So the command to make the time signature
1160 @cindex TimeSignature, example of overriding
1161 @cindex transparent property, example
1163 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1166 \override Staff.TimeSignature.transparent = ##t
1168 g,8 a16 b8 c d4 e16 |
1174 Again, setting the @code{transparent} property is a rather
1175 frequent operation, so we have a shorthand for it called
1179 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1182 \hide Staff.TimeSignature
1184 g,8 a16 b8 c d4 e16 |
1190 In either case, the time signature is gone, but this command
1192 the time signature should be. Maybe this is what is wanted for
1193 an exercise for the student to fill it in, but in other
1194 circumstances a gap might be undesirable. To remove it, the
1195 stencil for the time signature should be set to @code{#f}
1198 @cindex TimeSignature, example of overriding
1199 @cindex stencil property, example
1201 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1204 \omit Staff.TimeSignature
1206 g,8 a16 b8 c d4 e16 |
1212 and the difference is obvious: setting the stencil to @code{#f}
1213 (possibly via @code{\omit})
1214 removes the object entirely; making the object @code{transparent}
1215 (which can be done using @code{\hide})
1216 leaves it where it is, but makes it invisible.
1218 @node The color property
1219 @unnumberedsubsubsec The @code{color} property
1221 @cindex color property
1223 Finally let us try making the bar lines invisible by coloring
1224 them white. (There is a difficulty with this in that the
1225 white bar line may or may not blank out the staff lines where
1226 they cross. You may see in some of the examples below that this
1227 happens unpredictably. The details of why this is so and how to
1228 control it are covered in @ruser{Painting objects white}. But at
1229 the moment we are learning about color, so please just accept this
1230 limitation for now.)
1232 The @code{grob-interface} specifies that the
1233 color property value is a list, but there is no
1234 explanation of what that list should be. The list it
1235 requires is actually a list of values in internal units,
1236 but, to avoid having to know what these are, several ways
1237 are provided to specify colors. The first way is to use one
1238 of the @q{normal} colors listed in the first table in
1239 @ruser{List of colors}. To set the bar lines to white
1242 @cindex BarLine, example of overriding
1243 @cindex color property, example
1245 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1248 \override Staff.BarLine.color = #white
1250 g,8 a16 b8 c d4 e16 |
1256 and again, we see the bar lines are not visible. Note that
1257 @emph{white} is not preceded by an apostrophe -- it is not
1258 a symbol, but a @emph{variable}. When evaluated, it provides
1259 the list of internal values required to set the color to
1260 white. The other colors in the normal list are variables
1261 too. To convince yourself this is working you might like
1262 to change the color to one of the other variables in the
1270 The second way of changing the color is to use the list of
1271 X11 color names in the second list in @ruser{List of colors}.
1272 However, these are mapped to the actual values by the function
1273 @code{x11-color} which
1274 converts X11 color symbols into the list of internal values like this:
1276 @cindex BarLine, example of overriding
1277 @cindex color property, example
1279 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1282 \override Staff.BarLine.color = #(x11-color 'white)
1284 g,8 a16 b8 c d4 e16 |
1290 Note that in this case the function @code{x11-color} takes
1291 a symbol as an argument, so the symbol must be preceded by
1292 an apostrophe to keep it from being evaluated as a variable, and
1293 the whole function call has to be enclosed in parentheses.
1300 There is another function, one which converts RGB values into
1301 internal colors -- the @code{rgb-color} function. This takes
1302 three arguments giving the intensities of the red, green and
1303 blue colors. These take values in the range 0 to 1. So to
1304 set the color to red the value should be @code{(rgb-color 1 0 0)}
1305 and to white it should be @code{(rgb-color 1 1 1)}:
1307 @cindex BarLine, example of overriding
1308 @cindex color property, example
1310 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1313 \override Staff.BarLine.color = #(rgb-color 1 1 1)
1315 g,8 a16 b8 c d4 e16 |
1320 Finally, there is also a grey scale available as part of the
1321 X11 set of colors. These range from black, @code{'grey0},
1322 to white, @code{'grey100}, in steps of 1. Let's illustrate
1323 this by setting all the layout objects in our example to
1324 various shades of grey:
1326 @cindex StaffSymbol, example of overriding
1327 @cindex TimeSignature, example of overriding
1328 @cindex Clef, example of overriding
1329 @cindex NoteHead, example of overriding
1330 @cindex Stem, example of overriding
1331 @cindex BarLine, example of overriding
1332 @cindex color property, example
1333 @cindex x11-color, example of using
1335 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1338 \override Staff.StaffSymbol.color = #(x11-color 'grey30)
1339 \override Staff.TimeSignature.color = #(x11-color 'grey60)
1340 \override Staff.Clef.color = #(x11-color 'grey60)
1341 \override Voice.NoteHead.color = #(x11-color 'grey85)
1342 \override Voice.Stem.color = #(x11-color 'grey85)
1343 \override Staff.BarLine.color = #(x11-color 'grey10)
1345 g,8 a16 b8 c d4 e16 |
1351 Note the contexts associated with each of the layout objects.
1352 It is important to get these right, or the commands will not
1353 work! Remember, the context is the one in which the appropriate
1354 engraver is placed. The default context for engravers can be
1355 found by starting from the layout object, going from there to
1356 the engraver which produces it, and on the engraver page in the
1357 IR it tells you in which context the engraver will normally be
1361 @node Size of objects
1362 @subsection Size of objects
1364 @cindex changing size of objects
1365 @cindex size of objects
1366 @cindex objects, size of
1367 @cindex objects, changing size of
1369 Let us begin by looking again at the earlier example
1370 (see @ref{Nesting music expressions}) which showed
1371 how to introduce a new temporary staff, as in an @rglos{ossia}.
1373 @cindex alignAboveContext property, example
1374 @cindex @code{\with}, example
1376 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1377 \new Staff ="main" {
1384 alignAboveContext = #"main" }
1392 Ossia are normally written without clef and time signature, and
1393 are usually printed slightly smaller than the main staff. We
1394 already know now how to remove the clef and time signature --
1395 we simply set the stencil of each to @code{#f}, as follows:
1397 @cindex alignAboveContext property, example
1398 @cindex @code{\with}, example
1400 @cindex Clef, example of overriding
1401 @cindex TimeSignature, example of overriding
1403 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1404 \new Staff ="main" {
1411 alignAboveContext = #"main"
1415 \omit Staff.TimeSignature
1425 where the extra pair of braces after the @code{\with} clause are
1426 required to ensure the enclosed overrides and music are applied
1429 But what is the difference between modifying the staff context by
1430 using @code{\with} and modifying the stencils of the clef and the
1431 time signature with @code{\override}, or in this case
1433 The main difference is that
1434 changes made in a @code{\with} clause are made at the time the
1435 context is created, and remain in force as the @strong{default}
1436 values for the duration of that context, whereas
1437 @code{\set} or @code{\override} commands embedded in the
1438 music are dynamic -- they make changes synchronized with
1439 a particular point in the music. If changes are unset or
1440 reverted using @code{\unset} or @code{\revert} they return to
1441 their default values, which will be the ones set in the
1442 @code{\with} clause, or if none have been set there, the normal
1445 Some context properties can be modified only in @code{\with} clauses.
1446 These are those properties which cannot sensibly be changed after the
1447 context has been created. @code{alignAboveContext} and its partner,
1448 @code{alignBelowContext}, are two such properties -- once the staff
1449 has been created its alignment is decided and it would make no sense
1450 to try to change it later.
1452 The default values of layout object properties can also be set
1453 in @code{\with} clauses. Simply use the normal @code{\override}
1454 command leaving out the context name, since this is unambiguously
1455 defined as the context which the @code{\with} clause is modifying.
1456 If fact, an error will be generated if a context is specified
1459 So we could replace the example above with
1461 @cindex alignAboveContext property, example
1462 @cindex @code{\with}, example
1463 @cindex Clef, example of overriding
1464 @cindex TimeSignature, example of overriding
1466 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1467 \new Staff ="main" {
1474 alignAboveContext = #"main"
1475 % Don't print clefs in this staff
1476 \override Clef.stencil = ##f
1477 % Don't print time signatures in this staff
1478 \override TimeSignature.stencil = ##f
1487 It turns out that we can also employ the shorthands @code{\hide}
1488 and @code{\omit} for setting the @code{transparent} property and
1489 clearing the @code{stencil} here, leading to the result
1491 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1492 \new Staff ="main" {
1499 alignAboveContext = #"main"
1500 % Don't print clefs in this staff
1502 % Don't print time signatures in this staff
1512 Finally we come to changing the size of layout objects.
1514 Some layout objects are created as glyphs selected from a typeface
1515 font. These include note heads, accidentals, markup, clefs, time
1516 signatures, dynamics and lyrics. Their size is changed by modifying
1517 the @code{font-size} property, as we shall shortly see. Other layout
1518 objects such as slurs and ties -- in general, spanner objects -- are
1519 drawn individually, so there is no @code{font-size} associated with
1520 them. These objects generally derive their size from the objects to
1521 which they are attached, so usually there is no need to change their
1522 size manually. Still other properties such as the length of stems and
1523 bar lines, thickness of beams and other lines, and the separation of
1524 staff lines all need to be modified in special ways.
1526 Returning to the ossia example, let us first change the font-size.
1527 We can do this in two ways. We can either change the size of the
1528 fonts of each object type, like @code{NoteHead}s with commands
1532 \override NoteHead.font-size = #-2
1535 or we can change the size of all fonts by setting a special
1536 property, @code{fontSize}, using @code{\set}, or by including
1537 it in a @code{\with} clause (but without the @code{\set}).
1543 Both of these statements would cause the font size to be reduced
1544 by 2 steps from its previous value, where each
1545 step reduces or increases the size by approximately 12%.
1547 Let's try it in our ossia example:
1549 @cindex alignAboveContext property, example
1550 @cindex @code{\with}, example
1551 @cindex Clef, example of overriding
1552 @cindex TimeSignature, example of overriding
1553 @cindex fontSize property, example
1555 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1556 \new Staff ="main" {
1563 alignAboveContext = #"main"
1566 % Reduce all font sizes by ~24%
1576 This is still not quite right. The note heads and flags are
1577 smaller, but the stems are too long in proportion and the
1578 staff lines are spaced too widely apart. These need to be
1579 scaled down in proportion to the font reduction. The next
1580 sub-section discusses how this is done.
1582 @node Length and thickness of objects
1583 @subsection Length and thickness of objects
1589 @cindex size, changing
1590 @cindex stem length, changing
1591 @cindex staff line spacing, changing
1593 Distances and lengths in LilyPond are generally measured in
1594 staff-spaces, the distance between adjacent lines in the staff,
1595 (or occasionally half staff spaces) while most @code{thickness}
1596 properties are measured in units of an internal property called
1597 @code{line-thickness.} For example, by default, the lines of
1598 hairpins are given a thickness of 1 unit of @code{line-thickness},
1599 while the @code{thickness} of a note stem is 1.3. Note, though,
1600 that some thickness properties are different; for example, the
1601 thickness of beams is controlled by the value of the
1602 @code{beam-thickness} property, which is measured in staff-spaces.
1604 So how are lengths to be scaled in proportion to the font size?
1605 This can be done with the help of a special function called
1606 @code{magstep} provided for exactly this purpose. It takes
1607 one argument, the change in font size (#-2 in the example above)
1608 and returns a scaling factor suitable for reducing other
1609 objects in proportion. It is used like this:
1611 @cindex alignAboveContext property, example
1612 @cindex @code{\with}, example
1613 @cindex Clef, example of overriding
1614 @cindex TimeSignature, example of overriding
1615 @cindex fontSize property, example
1616 @cindex StaffSymbol, example of overriding
1617 @cindex magstep function, example of using
1618 @cindex staff-space property, example
1619 @cindex stencil property, example
1621 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1622 \new Staff ="main" {
1629 alignAboveContext = #"main"
1633 % Reduce stem length and line spacing to match
1634 \override StaffSymbol.staff-space = #(magstep -2)
1644 Since the length of stems and many other length-related properties are
1645 always calculated relative to the value of the @code{staff-space}
1646 property these are automatically scaled down in length too. Note that
1647 this affects only the vertical scale of the ossia -- the horizontal
1648 scale is determined by the layout of the main music in order to remain
1649 synchronized with it, so it is not affected by any of these changes in
1650 size. Of course, if the scale of all the main music were changed in
1651 this way then the horizontal spacing would be affected. This is
1652 discussed later in the layout section.
1654 This, then, completes the creation of an ossia. The sizes and
1655 lengths of all other objects may be modified in analogous ways.
1657 For small changes in scale, as in the example above, the
1658 thickness of the various drawn lines such as bar lines,
1659 beams, hairpins, slurs, etc does not usually require global
1660 adjustment. If the thickness of any particular layout object
1661 needs to be adjusted this can be best achieved by overriding its
1662 @code{thickness} property. An example of changing the thickness
1663 of slurs was shown above in @ref{Properties of layout objects}.
1664 The thickness of all drawn objects (i.e., those not produced
1665 from a font) may be changed in the same way.
1668 @node Placement of objects
1669 @section Placement of objects
1672 * Automatic behavior::
1673 * Within-staff objects::
1674 * Outside-staff objects::
1678 @node Automatic behavior
1679 @subsection Automatic behavior
1681 @cindex within-staff objects
1682 @cindex outside-staff objects
1683 @cindex objects, within-staff
1684 @cindex objects, outside-staff
1686 There are some objects in musical notation that belong to
1687 the staff and there are other objects that should be
1688 placed outside the staff. These are called within-staff
1689 objects and outside-staff objects respectively.
1691 Within-staff objects are those that are located on the staff
1692 -- note heads, stems, accidentals, etc. The positions of
1693 these are usually fixed by the music itself -- they are
1694 vertically positioned on specific lines of the staff or are
1695 tied to other objects that are so positioned. Collisions of
1696 note heads, stems and accidentals in closely set chords are
1697 normally avoided automatically. There are commands and
1698 overrides which can modify this automatic behavior, as we
1701 Objects belonging outside the staff include things such as
1702 rehearsal marks, text and dynamic markings. LilyPond's rule for
1703 the vertical placement of outside-staff objects is to place them
1704 as close to the staff as possible but not so close that they
1705 collide with any other object. LilyPond uses the
1706 @code{outside-staff-priority} property to determine the order in
1707 which the objects should be placed, as follows.
1709 First, LilyPond places all the within-staff objects.
1710 Then it sorts the outside-staff objects according to their
1711 @code{outside-staff-priority}. The outside-staff objects are
1712 taken one by one, beginning with the object with the lowest
1713 @code{outside-staff-priority}, and placed so that they do not
1714 collide with any objects that have already been placed. That is,
1715 if two outside-staff grobs are competing for the same space, the
1716 one with the lower @code{outside-staff-priority} will be placed
1717 closer to the staff. If two objects have the same
1718 @code{outside-staff-priority} the one encountered first will be
1719 placed closer to the staff.
1721 In the following example all the markup texts have the same
1722 priority (since it is not explicitly set). Note that @q{Text3}
1723 is automatically positioned close to the staff again, nestling
1726 @cindex markup example
1728 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1735 Staves are also positioned, by default, as closely together as
1736 possible (subject to a minimum separation). If notes project
1737 a long way towards an adjacent staff they will force the
1738 staves further apart only if an overlap of the notation
1739 would otherwise occur. The following example demonstrates
1740 this @q{nestling} of the notes on adjacent staves:
1742 @lilypond[quote,ragged-right,verbatim]
1745 \relative c' { c4 a, }
1748 \relative c'''' { c4 a, }
1754 @node Within-staff objects
1755 @subsection Within-staff objects
1757 We have already seen how the commands @code{\voiceXXX} affect the
1758 direction of slurs, ties, fingering and everything else which depends on
1759 the direction of the stems -- see @ref{Explicitly instantiating voices}.
1760 These commands are essential when writing polyphonic music to permit
1761 interweaving melodic lines to be distinguished. But occasionally it may
1762 be necessary to override this automatic behavior. This can be done for
1763 whole sections of music or even for an individual note. The property
1764 which controls this behavior is the @code{direction} property of each
1765 layout object. We first explain what this does, and then introduce a
1766 number of ready-made commands which avoid your having to code explicit
1767 overrides for the more common modifications.
1769 Some layout objects like slurs and ties curve, bend or point
1770 either up or down; others like stems and flags also move to
1771 right or left when they point up or down. This is controlled
1772 automatically when @code{direction} is set.
1775 * The direction property::
1779 @node The direction property
1780 @unnumberedsubsubsec The @code{direction} property
1787 The following example shows in bar 1 the default behavior of stems,
1788 with those on high notes pointing down and those on low notes pointing
1789 up, followed by four notes with all stems forced down, four notes with
1790 all stems forced up, and finally four notes reverted back to the
1793 @cindex Stem, example of overriding
1794 @cindex direction property, example
1796 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1798 \override Stem.direction = #DOWN
1800 \override Stem.direction = #UP
1802 \revert Stem.direction
1806 Here we use the constants @code{DOWN} and @code{UP}.
1807 These have the values @w{@code{-1}} and @code{+1} respectively, and
1808 these numerical values may be used instead. The value @code{0}
1809 may also be used in some cases. It is simply treated as meaning
1810 @code{UP} for stems, but for some objects it means @q{center}.
1811 There is a constant, @code{CENTER} which has the value @code{0}.
1813 However, these explicit overrides are not usually used, as there are
1814 simpler equivalent predefined commands available. Here is a table of
1815 the commonest. The meaning of each is stated where it is not obvious.
1817 @multitable @columnfractions .2 .2 .25 .35
1822 @item @code{\arpeggioArrowDown}
1823 @tab @code{\arpeggioArrowUp}
1824 @tab @code{\arpeggioNormal}
1825 @tab Arrow is at bottom, at top, or no arrow
1826 @item @code{\dotsDown}
1828 @tab @code{\dotsNeutral}
1829 @tab Direction of movement to avoid staff lines
1830 @item @code{\dynamicDown}
1831 @tab @code{\dynamicUp}
1832 @tab @code{\dynamicNeutral}
1834 @item @code{\phrasingSlurDown}
1835 @tab @code{\phrasingSlurUp}
1836 @tab @code{\phrasingSlurNeutral}
1837 @tab Note: distinct from slur commands
1838 @item @code{\slurDown}
1840 @tab @code{\slurNeutral}
1842 @item @code{\stemDown}
1844 @tab @code{\stemNeutral}
1846 @item @code{\textSpannerDown}
1847 @tab @code{\textSpannerUp}
1848 @tab @code{\textSpannerNeutral}
1849 @tab Text entered as spanner is below/above staff
1850 @item @code{\tieDown}
1852 @tab @code{\tieNeutral}
1854 @item @code{\tupletDown}
1855 @tab @code{\tupletUp}
1856 @tab @code{\tupletNeutral}
1857 @tab Tuplets are below/above notes
1860 The neutral/normal variants of these commands are implemented
1861 using @code{\revert} and may @strong{not} be
1862 preceded by @code{\once}. If you wish to limit the
1863 effect of the other commands (which are implemented using
1864 @code{\override}) to a single timestep, you can precede them with
1865 @code{\once} like you would do with explicit overrides.
1868 @unnumberedsubsubsec Fingering
1870 @cindex fingering, placement
1871 @cindex fingering, chords
1873 The placement of fingering on single notes can also be controlled
1874 by the @code{direction} property, but changing @code{direction}
1875 has no effect on chords. As we shall see, there are special
1876 commands which allow the fingering of individual notes
1877 of chords to be controlled, with the fingering being placed
1878 above, below, to the left or to the right of each note.
1880 First, here's the effect of @code{direction} on the fingering
1881 attached to single notes. The first bar shows the default
1882 behaviour, and the following two bars shows the effect of
1883 specifying @code{DOWN} and @code{UP}:
1885 @cindex Fingering, example of overriding
1886 @cindex direction property, example
1888 @lilypond[quote,verbatim,relative=2]
1890 \override Fingering.direction = #DOWN
1892 \override Fingering.direction = #UP
1896 However, overriding the @code{direction} property is not the
1897 easiest way of manually setting the fingering above or below
1898 the notes; using @code{_} or @code{^} instead of @code{-} before
1899 the fingering number is usually preferable. Here is the previous
1900 example using this method:
1902 @cindex fingering example
1904 @lilypond[quote,verbatim,relative=2]
1910 The @code{direction} property is ignored for chords, but the
1911 directional prefixes, @code{_} and @code{^} do work. By default,
1912 the fingering is automatically placed both above and below the
1913 notes of a chord, as shown:
1915 @cindex fingering example
1917 @lilypond[quote,verbatim,relative=2]
1924 but this may be overridden to manually force all or any of the
1925 individual fingering numbers above or below:
1927 @cindex fingering example
1929 @lilypond[quote,verbatim,relative=2]
1935 Even greater control over the placement of fingering of the
1936 individual notes in a chord is possible by using the
1937 @code{\set fingeringOrientations} command. The format of this
1941 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
1945 @code{\set} is used because @code{fingeringOrientations} is a
1946 property of the @code{Voice} context, created and used by the
1947 @code{New_fingering_engraver}.
1949 The property may be set to a list of one to three values.
1950 It controls whether fingerings may be placed above (if
1951 @code{up} appears in the list), below (if @code{down} appears),
1952 to the left (if @code{left} appears, or to the right
1953 (if @code{right} appears). Conversely, if a location is not
1954 listed, no fingering is placed there. LilyPond takes these
1955 constraints and works out the best placement for the fingering
1956 of the notes of the following chords. Note that @code{left} and
1957 @code{right} are mutually exclusive -- fingering may be placed
1958 only on one side or the other, not both.
1960 @warning{To control the placement of the fingering of a single
1961 note using this command it is necessary to write it as a single
1962 note chord by placing angle brackets round it.}
1964 Here are a few examples:
1966 @cindex fingering example
1967 @cindex @code{\set}, example of using
1968 @cindex fingeringOrientations property, example
1970 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1971 \set fingeringOrientations = #'(left)
1974 \set fingeringOrientations = #'(left)
1976 <c-1 e-2 g-3 b-5>4 |
1977 \set fingeringOrientations = #'(up left down)
1980 \set fingeringOrientations = #'(up left)
1982 <c-1 e-2 g-3 b-5>4 |
1983 \set fingeringOrientations = #'(right)
1989 If the fingering seems a little crowded the @code{font-size}
1990 could be reduced. The default value can be seen from the
1991 @code{Fingering} object in the IR to be @w{@code{-5}}, so let's
1994 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1995 \override Fingering.font-size = #-7
1996 \set fingeringOrientations = #'(left)
1999 \set fingeringOrientations = #'(left)
2001 <c-1 e-2 g-3 b-5>4 |
2002 \set fingeringOrientations = #'(up left down)
2005 \set fingeringOrientations = #'(up left)
2007 <c-1 e-2 g-3 b-5>4 |
2008 \set fingeringOrientations = #'(right)
2013 @node Outside-staff objects
2014 @subsection Outside-staff objects
2016 Outside-staff objects are automatically placed to avoid collisions.
2017 There are several ways to override the automatic placement if the
2018 positioning is not optimum.
2021 * The outside-staff-priority property::
2022 * The \textLengthOn command::
2023 * Dynamics placement::
2028 @node The outside-staff-priority property
2029 @unnumberedsubsubsec The @code{outside-staff-priority} property
2031 Objects with the lower value of the @code{outside-staff-priority}
2032 property are placed nearer to the staff, and other outside-staff
2033 objects are then raised as far as necessary to avoid collisions.
2034 The @code{outside-staff-priority} is defined in the
2035 @code{grob-interface} and so is a property of all layout objects.
2036 By default it is set to @code{#f} for all within-staff objects,
2037 and to a numerical value appropriate to each outside-staff object
2038 when the object is created. The following table shows the default
2039 numerical values for some of the commonest outside-staff objects.
2043 Note the unusual names for some of the objects: spanner objects
2044 are automatically created to control the vertical positioning of
2045 grobs which (might) start and end at different musical moments, so
2046 changing the @code{outside-staff-priority} of the underlying grob
2047 will have no effect. For example, changing
2048 @code{outside-staff-priority} of the @code{Hairpin} object will
2049 have no effect on the vertical positioning of hairpins -- you must
2050 change @code{outside-staff-priority} of the associated
2051 @code{DynamicLineSpanner} object instead. This override must be
2052 placed at the start of the spanner, which might include several
2053 linked hairpins and dynamics.
2055 @multitable @columnfractions .3 .3 .3
2056 @headitem Layout Object
2058 @tab Controls position of:
2059 @item @code{RehearsalMark}
2061 @tab Rehearsal marks
2062 @item @code{MetronomeMark}
2064 @tab Metronome marks
2065 @item @code{VoltaBracketSpanner}
2068 @item @code{TextScript}
2071 @item @code{MultiMeasureRestText}
2073 @tab Markup text over full-bar rests
2074 @item @code{OttavaBracket}
2076 @tab Ottava brackets
2077 @item @code{TextSpanner}
2080 @item @code{DynamicLineSpanner}
2082 @tab All dynamic markings
2083 @item @code{BarNumber}
2086 @item @code{TrillSpanner}
2088 @tab Spanning trills
2091 Here is an example showing the default placement of some of
2094 @cindex text spanner
2095 @cindex ottava bracket
2097 @funindex \startTextSpan
2098 @funindex startTextSpan
2099 @funindex \stopTextSpan
2100 @funindex stopTextSpan
2102 @cindex TextSpanner, example of overriding
2103 @cindex bound-details property, example
2105 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2106 % Set details for later Text Spanner
2107 \override TextSpanner.bound-details.left.text
2108 = \markup { \small \bold Slower }
2109 % Place dynamics above staff
2111 % Start Ottava Bracket
2114 % Add Dynamic Text and hairpin
2120 % Add Dynamic Text and terminate hairpin
2121 c4\ff c \stopTextSpan |
2122 % Stop Ottava Bracket
2127 This example also shows how to create Text Spanners --
2128 text with extender lines above a section of music. The
2129 spanner extends from the @code{\startTextSpan} command to
2130 the @code{\stopTextSpan} command, and the format of the
2131 text is defined by the @code{\override TextSpanner} command.
2132 For more details see @ruser{Text spanners}.
2134 It also shows how ottava brackets are created.
2136 @cindex tweaking bar number placement
2137 @cindex bar numbers, tweaking placement
2138 @cindex tweaking metronome mark placement
2139 @cindex metronome mark, tweaking placement
2140 @cindex tweaking rehearsal mark placement
2141 @cindex rehearsal marks, tweaking placement
2143 If the default values of @code{outside-staff-priority} do not give you
2144 the placing you want, the priority of any of the objects may be
2145 overridden. Suppose we would like the ottava bracket to be placed
2146 below the text spanner in the example above. All we need to do is to
2147 look up the priority of @code{OttavaBracket} in the IR or in the
2148 tables above, and reduce it to a value lower than that of a
2149 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
2150 in the @code{Staff} context:
2152 @cindex TextSpanner, example of overriding
2153 @cindex bound-details property, example
2155 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2156 % Set details for later Text Spanner
2157 \override TextSpanner.bound-details.left.text
2158 = \markup { \small \bold Slower }
2159 % Place dynamics above staff
2161 % Place following Ottava Bracket below Text Spanners
2162 \once \override Staff.OttavaBracket.outside-staff-priority = #340
2163 % Start Ottava Bracket
2168 % Add Dynamic Line Spanner
2174 c4\ff c \stopTextSpan |
2175 % Stop Ottava Bracket
2180 Note that some of these objects, in particular bar numbers,
2181 metronome marks and rehearsal marks, live by default in the
2182 @code{Score} context, so be sure to use the correct context
2183 when these are being overriden.
2185 @cindex slurs and outside-staff-priority
2186 @cindex slurs and articulations
2187 @cindex articulations and slurs
2189 Slurs by default are classed as within-staff objects, but
2190 they often appear above the staff if the notes to
2191 which they are attached are high on the staff. This can push
2192 outside-staff objects such as articulations too high, as the slur
2193 will be placed first. The @code{avoid-slur} property of the
2194 articulation can be set to @code{'inside} to bring the articulation
2195 inside the slur, but the @code{avoid-slur} property is effective
2196 only if the @code{outside-staff-priority} is also set to @code{#f}.
2197 Alternatively, the @code{outside-staff-priority} of the slur
2198 can be set to a numerical value to cause it to be placed along with
2199 other outside-staff objects according to that value. Here's an
2200 example showing the effect of the two methods:
2202 @lilypond[quote,verbatim,relative=2]
2203 c4( c^\markup { \tiny \sharp } d4.) c8 |
2205 \once \override TextScript.avoid-slur = #'inside
2206 \once \override TextScript.outside-staff-priority = ##f
2207 c4^\markup { \tiny \sharp } d4.) c8 |
2208 \once \override Slur.outside-staff-priority = #500
2209 c4( c^\markup { \tiny \sharp } d4.) c8 |
2212 Changing the @code{outside-staff-priority} can also be used to
2213 control the vertical placement of individual objects, although
2214 the results may not always be desirable. Suppose we would
2215 like @qq{Text3} to be placed above @qq{Text4} in the example
2216 under Automatic behavior, above (see @ref{Automatic behavior}).
2217 All we need to do is to look up the priority of @code{TextScript}
2218 in the IR or in the tables above, and increase the priority of
2219 @qq{Text3} to a higher value:
2221 @cindex TextScript, example of overriding
2222 @cindex outside-staff-priority property, example
2224 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2227 \once \override TextScript.outside-staff-priority = #500
2232 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2233 above @qq{Text2}, and @qq{Text4} now drops down. Perhaps this is not
2234 so good. What we would really like to do is to position all the
2235 annotation at the same distance above the staff. To do this, we
2236 clearly will need to space the notes out horizontally to make more
2237 room for the text. This is done using the @code{textLengthOn}
2240 @node The \textLengthOn command
2241 @unnumberedsubsubsec The @code{\textLengthOn} command
2243 @cindex notes, spreading out with text
2245 @funindex \textLengthOn
2246 @funindex textLengthOn
2247 @funindex \textLengthOff
2248 @funindex textLengthOff
2250 By default, text produced by markup takes up no horizontal space
2251 as far as laying out the music is concerned. The @code{\textLengthOn}
2252 command reverses this behavior, causing the notes to be spaced
2253 out as far as is necessary to accommodate the text:
2255 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2256 \textLengthOn % Cause notes to space out to accommodate text
2263 The command to revert to the default behavior is
2264 @code{\textLengthOff}. Remember @code{\once} only works with
2265 @code{\override}, @code{\set}, @code{\revert} or @code{\unset},
2266 so cannot be used with @code{\textLengthOn}.
2268 @cindex markup text, allowing collisions
2270 Markup text will also avoid notes which project above the staff.
2271 If this is not desired, the automatic displacement upwards may
2272 be turned off by setting the priority to @code{#f}. Here's an
2273 example to show how markup text interacts with such notes.
2275 @cindex TextScript, example of overriding
2276 @cindex outside-staff-priority property, example
2278 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2279 % This markup is short enough to fit without collision
2283 % This is too long to fit, so it is displaced upwards
2287 % Turn off collision avoidance
2288 \once \override TextScript.outside-staff-priority = ##f
2289 c,,2^"Long Text " c'' |
2292 % Turn off collision avoidance
2293 \once \override TextScript.outside-staff-priority = ##f
2294 \textLengthOn % and turn on textLengthOn
2295 c,,2^"Long Text " % Spaces at end are honored
2299 @node Dynamics placement
2300 @unnumberedsubsubsec Dynamics placement
2302 @cindex tweaking dynamics placement
2303 @cindex dynamics, tweaking placement
2305 Dynamic markings will normally be positioned beneath the
2306 staff, but may be positioned above with the @code{\dynamicUp}
2307 command. They will be positioned vertically relative to the
2308 note to which they are attached, and will float below (or above)
2309 all within-staff objects such as phrasing slurs and bar numbers.
2310 This can give quite acceptable results, as this example
2313 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2318 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2319 ees,2.~\)\mf ees4 r8 |
2322 However, if the notes and attached dynamics are close
2323 together the automatic placement will avoid collisions
2324 by displacing later dynamic markings further away, but this may
2325 not be the optimum placement, as this rather artificial example
2328 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2334 Should a similar situation arise in @q{real} music, it may be
2335 preferable to space out the notes a little further, so the dynamic
2336 markings can all fit at the same vertical distance from the staff. We
2337 were able to do this for markup text by using the @code{\textLengthOn}
2338 command, but there is no equivalent command for dynamic marks. So we
2339 shall have to work out how to do this using @code{\override} commands.
2342 @unnumberedsubsubsec Grob sizing
2345 @cindex sizing grobs
2347 First we must learn how grobs are sized. All grobs have a
2348 reference point defined within them which is used to position
2349 them relative to their parent object. This point in the grob
2350 is then positioned at a horizontal distance, @code{X-offset},
2351 and at a vertical distance, @code{Y-offset}, from its parent.
2352 The horizontal extent of the object is given by a pair of
2353 numbers, @code{X-extent}, which say where the left and right
2354 edges are relative to the reference point. The vertical extent
2355 is similarly defined by a pair of numbers, @code{Y-extent}.
2356 These are properties of all grobs which support the
2357 @code{grob-interface}.
2359 @cindex @code{extra-spacing-width}
2361 By default, outside-staff objects are given a width of zero so
2362 that they may overlap in the horizontal direction. This is done
2363 by the trick of adding infinity to the leftmost extent and
2364 minus infinity to the rightmost extent by setting the
2365 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}. So
2366 to ensure they do not overlap in the horizontal direction we
2367 must override this value of @code{extra-spacing-width} to
2368 @code{'(0 . 0)} so the true width shines through. This is
2369 the command to do this for dynamic text:
2372 \override DynamicText.extra-spacing-width = #'(0 . 0)
2376 Let's see if this works in our previous example:
2378 @cindex DynamicText, example of overriding
2379 @cindex extra-spacing-width property, example
2381 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2383 \override DynamicText.extra-spacing-width = #'(0 . 0)
2384 a4\f b\mf c\mp b\p |
2388 Well, it has certainly stopped the dynamic marks being
2389 displaced, but two problems remain. The marks should be
2390 spaced a little further apart and it would be better
2391 if they were all the same distance from the staff.
2392 We can solve the first problem easily. Instead of making
2393 the @code{extra-spacing-width} zero we could add a little
2394 more to it. The units are the space between two staff
2395 lines, so moving the left edge half a unit to the left and the
2396 right edge half a unit to the right should do it:
2398 @cindex DynamicText, example of overriding
2399 @cindex extra-spacing-width property, example
2401 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2403 % Extend width by 1 staff space
2404 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2409 This looks better, but maybe we would prefer the dynamic marks
2410 to be aligned along the same baseline rather than going up and
2411 down with the notes. The property to do this is
2412 @code{staff-padding} which is covered in the following section.
2415 @node Collisions of objects
2416 @section Collisions of objects
2420 * Fixing overlapping notation::
2421 * Real music example::
2424 @node Moving objects
2425 @subsection Moving objects
2427 @cindex moving overlapping objects
2428 @cindex moving colliding objects
2429 @cindex moving colliding grobs
2430 @cindex objects, moving colliding
2431 @cindex grobs, moving colliding
2433 This may come as a surprise, but LilyPond is not perfect. Some
2434 notation elements can overlap. This is unfortunate, but in fact
2435 rather rare. Usually the need to move objects is for clarity or
2436 aesthetic reasons -- they would look better with a little more
2437 or a little less space around them.
2439 There are three main approaches to resolving overlapping
2440 notation. They should be considered in the following order:
2444 The @strong{direction} of one of the overlapping objects may
2445 be changed using the predefined commands listed above for
2446 within-staff objects (see @ref{Within-staff objects}).
2447 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2448 repositioned easily in this way. The limitation is that you
2449 have a choice of only two positions, and neither may be
2453 The @strong{object properties}, which LilyPond uses when positioning
2454 layout objects, may be modified using @code{\override}. The
2455 advantages of making changes to this type of property are (a) that
2456 some other objects will be moved automatically if necessary to make
2457 room and (b) the single override can apply to all instances of the
2458 same type of object. Such properties include:
2465 This has already been covered in some detail -- see
2466 @ref{Within-staff objects}.
2469 @code{padding}, @code{right-padding}, @code{staff-padding}
2472 @cindex padding property
2473 @cindex right-padding property
2474 @cindex staff-padding property
2476 As an object is being positioned the value of its @code{padding}
2477 property specifies the gap that must be left between itself and the
2478 nearest edge of the object against which it is being positioned. Note
2479 that it is the @code{padding} value of the object @strong{being
2480 placed} that is used; the @code{padding} value of the object which is
2481 already placed is ignored. Gaps specified by @code{padding} can be
2482 applied to all objects which support the
2483 @code{side-position-interface}.
2485 Instead of @code{padding}, the placement of groups of accidentals
2486 is controlled by @code{right-padding}. This property is to be found
2487 in the @code{AccidentalPlacement} object which, note, lives in the
2488 @strong{Staff} context. In the typesetting process the note heads
2489 are typeset first and then the accidentals, if any, are added to the
2490 left of the note heads using the @code{right-padding} property to determine
2491 the separation from the note heads and between individual accidentals.
2492 So only the @code{right-padding} property of the @code{AccidentalPlacement}
2493 object has any effect on the placement of the accidentals.
2495 The @code{staff-padding} property is closely related to the
2496 @code{padding} property: @code{padding} controls the minimum amount of
2497 space between any object which supports the
2498 @code{side-position-interface} and the nearest other object (generally
2499 the note or the staff lines); @code{staff-padding} applies only to
2500 those objects which are always set outside the staff -- it controls
2501 the minimum amount of space that should be inserted between that
2502 object and the staff. Note that @code{staff-padding} has no effect on
2503 objects which are positioned relative to the note rather than the
2504 staff, even though it may be overridden without error for such objects
2505 -- it is simply ignored.
2507 To discover which padding property is required for the object you wish
2508 to reposition, you need to return to the IR and look up the object's
2509 properties. Be aware that the padding properties might not be located
2510 in the obvious object, so look in objects that appear to be related.
2512 All padding values are measured in staff spaces. For most
2513 objects, this value is set by default to be around 1.0 or less
2514 (it varies with each object). It may be overridden if a larger
2515 (or smaller) gap is required.
2518 @code{self-alignment-X}
2520 @cindex self-alignment-X property
2522 This property can be used to align the object to the left, to
2523 the right, or to center it with respect to the parent object's
2524 reference point. It may be used with all objects which support
2525 the @code{self-alignment-interface}. In general these are objects
2526 that contain text. The values are @code{LEFT}, @code{RIGHT}
2527 or @code{CENTER}. Alternatively, a numerical value between
2528 @w{@code{-1}} and @code{+1} may be specified, where @w{@code{-1}} is
2529 left-aligned, @code{+1} is right-aligned, and numbers in between
2530 move the text progressively from left-aligned to right-aligned.
2531 Numerical values greater than @code{1} may be specified to move
2532 the text even further to the left, or less than @w{@code{-1}} to
2533 move the text even further to the right. A change of @code{1}
2534 in the value corresponds to a movement of half the text's length.
2537 @code{extra-spacing-width}
2539 @cindex extra-spacing-width property
2541 This property is available for all objects which support the
2542 @code{item-interface}. It takes two numbers, the first is added
2543 to the leftmost extent and the second is added to the rightmost
2544 extent. Negative numbers move the edge to the left, positive to
2545 the right, so to widen an object the first number must be negative,
2546 the second positive. Note that not all objects honor both
2547 numbers. For example, the @code{Accidental} object only takes
2548 notice of the first (left edge) number.
2551 @code{staff-position}
2553 @cindex staff-position property
2555 @code{staff-position} is a property of the
2556 @code{staff-symbol-referencer-interface}, which is supported by
2557 objects which are positioned relative to the staff. It specifies
2558 the vertical position of the object relative to the center line
2559 of the staff in half staff-spaces. It is useful in resolving
2560 collisions between layout objects like multi-measure rests, ties
2561 and notes in different voices.
2566 @cindex force-hshift property
2568 Closely spaced notes in a chord, or notes occurring at the same
2569 time in different voices, are arranged in two, occasionally more,
2570 columns to prevent the note heads overlapping. These are called
2571 note columns, and an object called @code{NoteColumn} is created
2572 to lay out the notes in that column.
2574 The @code{force-hshift} property is a property of a @code{NoteColumn}
2575 (actually of the @code{note-column-interface}). Changing it permits a
2576 note column to be moved in units appropriate to a note column,
2577 viz. the note head width of the first voice note. It should be used
2578 in complex situations where the normal @code{\shiftOn} commands (see
2579 @ref{Explicitly instantiating voices}) do not resolve the note
2580 conflict. It is preferable to the @code{extra-offset} property for
2581 this purpose as there is no need to work out the distance in
2582 staff-spaces, and moving the notes into or out of a @code{NoteColumn}
2583 affects other actions such as merging note heads.
2588 Finally, when all else fails, objects may be manually repositioned
2589 relative to the staff center line vertically, or by displacing them by
2590 any distance to a new position. The disadvantages are that the
2591 correct values for the repositioning have to be worked out, often by
2592 trial and error, for every object individually, and, because the
2593 movement is done after LilyPond has placed all other objects, the user
2594 is responsible for avoiding any collisions that might ensue. But the
2595 main difficulty with this approach is that the repositioning values
2596 may need to be reworked if the music is later modified. The
2597 properties that can be used for this type of manual repositioning are:
2602 @cindex extra-offset property
2604 This property applies to any layout object supporting the
2605 @code{grob-interface}. It takes a pair of numbers which specify the
2606 extra displacement in the horizontal and vertical directions.
2607 Negative numbers move the object to the left or down. The units are
2608 staff-spaces. The extra displacement is made after the typesetting of
2609 objects is finished, so an object may be repositioned anywhere without
2610 affecting anything else.
2614 @cindex positions property
2616 This is most useful for manually adjusting the slope and height
2617 of beams, slurs, and tuplets. It takes a pair of numbers
2618 giving the position of the left and right ends of the beam, slur,
2619 etc. relative to the center line of the staff. Units are
2620 staff-spaces. Note, though, that slurs and phrasing slurs cannot
2621 be repositioned by arbitrarily large amounts. LilyPond first
2622 generates a list of possible positions for the slur and by default
2623 finds the slur that @qq{looks best}. If the @code{positions}
2624 property has been overridden the slur that is closest to the
2625 requested positions is selected from the list.
2630 A particular object may not have all of these properties.
2631 It is necessary to go to the IR to look up which properties
2632 are available for the object in question.
2634 Here is a list of the objects which are most likely to be
2635 involved in collisions, together with the name of the object which
2636 should be looked up in the IR in order to discover which properties
2637 should be used to move them.
2639 @multitable @columnfractions .5 .5
2640 @headitem Object type @tab Object name
2641 @item Articulations @tab @code{Script}
2642 @item Beams @tab @code{Beam}
2643 @item Dynamics (vertically) @tab @code{DynamicLineSpanner}
2644 @item Dynamics (horizontally) @tab @code{DynamicText}
2645 @item Fingerings @tab @code{Fingering}
2646 @item Rehearsal / Text marks @tab @code{RehearsalMark}
2647 @item Slurs @tab @code{Slur}
2648 @item Text e.g. @code{^"text"} @tab @code{TextScript}
2649 @item Ties @tab @code{Tie}
2650 @item Tuplets @tab @code{TupletBracket}
2654 @node Fixing overlapping notation
2655 @subsection Fixing overlapping notation
2657 Let's now see how the properties in the previous section can
2658 help to resolve overlapping notation.
2661 * The padding property::
2662 * The right-padding property::
2663 * The staff-padding property::
2664 * The self-alignment-X property::
2665 * The staff-position property::
2666 * The extra-offset property::
2667 * The positions property::
2668 * The force-hshift property::
2671 @node The padding property
2672 @unnumberedsubsubsec The @code{padding} property
2675 @cindex fixing overlapping notation
2676 @cindex overlapping notation
2678 The @code{padding} property can be set to increase
2679 (or decrease) the distance between symbols that are printed
2680 above or below notes.
2682 @cindex Script, example of overriding
2683 @cindex padding property, example
2685 @lilypond[quote,fragment,relative=1,verbatim]
2687 \override Script.padding = #3
2691 @cindex MetronomeMark, example of overriding
2692 @cindex padding property, example
2694 @lilypond[quote,fragment,relative=1,verbatim]
2695 % This will not work, see below
2696 \override MetronomeMark.padding = #3
2700 \override Score.MetronomeMark.padding = #3
2705 Note in the second example how important it is to figure out what
2706 context handles a certain object. Since the @code{MetronomeMark}
2707 object is handled in the @code{Score} context, property changes in the
2708 @code{Voice} context will not be noticed. For more details, see
2709 @ruser{Modifying properties}.
2711 If the @code{padding} property of an object is increased when that
2712 object is in a stack of objects being positioned according to
2713 their @code{outside-staff-priority}, then that object and all
2714 objects outside it are moved.
2717 @node The right-padding property
2718 @unnumberedsubsubsec The @code{right-padding} property
2720 @cindex right-padding property
2722 The @code{right-padding} property affects the spacing between the
2723 accidental and the note to which it applies. It is not often
2724 required, but the default spacing may be wrong for certain special
2725 accidental glyphs or combination of glyphs used in some microtonal
2726 music. These have to be entered by overriding the accidental
2727 stencil with a markup containing the desired symbol(s), like this:
2729 @cindex Accidental, example of overriding
2730 @cindex text property, example
2731 @cindex stencil property, example
2732 @cindex AccidentalPlacement, example of overriding
2733 @cindex right-padding property, example
2735 @lilypond[quote,ragged-right,verbatim]
2736 sesquisharp = \markup { \sesquisharp }
2739 % This prints a sesquisharp but the spacing is too small
2740 \once \override Accidental.stencil = #ly:text-interface::print
2741 \once \override Accidental.text = #sesquisharp
2743 % This improves the spacing
2744 \once \override Score.AccidentalPlacement.right-padding = #0.6
2745 \once \override Accidental.stencil = #ly:text-interface::print
2746 \once \override Accidental.text = #sesquisharp
2752 This necessarily uses an override for the accidental stencil which
2753 will not be covered until later. The stencil type must be a
2754 procedure, here changed to print the contents of the @code{text}
2755 property of @code{Accidental}, which itself is set to be a
2756 sesquisharp sign. This sign is then moved further away from the
2757 note head by overriding @code{right-padding}.
2761 @node The staff-padding property
2762 @unnumberedsubsubsec The @code{staff-padding} property
2764 @cindex aligning objects on a baseline
2765 @cindex objects, aligning on a baseline
2767 @code{staff-padding} can be used to align objects such as dynamics
2768 along a baseline at a fixed height above the staff, rather than at a
2769 height dependent on the position of the note to which they are
2770 attached. It is not a property of @code{DynamicText} but of
2771 @code{DynamicLineSpanner}. This is because the baseline should apply
2772 equally to @strong{all} dynamics, including those created as extended
2773 spanners. So this is the way to align the dynamic marks in the
2774 example taken from the previous section:
2776 @cindex DynamicText, example of overriding
2777 @cindex extra-spacing-width property, example
2778 @cindex DynamicLineSpanner, example of overriding
2779 @cindex staff-padding property, example
2781 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2783 % Extend width by 1 unit
2784 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2785 % Align dynamics to a base line 2 units above staff
2786 \override DynamicLineSpanner.staff-padding = #2
2791 @node The self-alignment-X property
2792 @unnumberedsubsubsec The @code{self-alignment-X} property
2794 The following example shows how this can resolve the collision
2795 of a string fingering object with a note's stem by aligning the
2796 right edge with the reference point of the parent note:
2798 @cindex StringNumber, example of overriding
2799 @cindex self-alignment-X property, example
2801 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
2804 \once \override StringNumber.self-alignment-X = #RIGHT
2808 @node The staff-position property
2809 @unnumberedsubsubsec The @code{staff-position} property
2811 @cindex object collision within a staff
2813 Multimeasure rests in one voice can collide with notes in another.
2814 Since these rests are typeset centered between the bar lines, it
2815 would require significant effort for LilyPond to figure out which
2816 other notes might collide with it, since all the current collision
2817 handling between notes and between notes and rests is done only
2818 for notes and rests that occur at the same time. Here's an
2819 example of a collision of this type:
2821 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2822 << { c4 c c c } \\ { R1 } >>
2825 The best solution here is to move the multimeasure rest down, since
2826 the rest is in voice two. The default in @code{\voiceTwo} (i.e. in
2827 the second voice of a @code{<<@{...@} \\ @{...@}>>} construct) is that
2828 @code{staff-position} is set to -4 for MultiMeasureRest, so we need to
2829 move it, say, four half-staff spaces down to @w{@code{-8}}.
2831 @cindex MultiMeasureRest, example of overriding
2832 @cindex staff-position property, example
2834 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2838 \override MultiMeasureRest.staff-position = #-8
2843 This is better than using, for example, @code{extra-offset},
2844 because the ledger line above the rest is inserted automatically.
2846 @node The extra-offset property
2847 @unnumberedsubsubsec The @code{extra-offset} property
2849 @cindex positioning objects
2850 @cindex positioning grobs
2851 @cindex objects, positioning
2852 @cindex grobs, positioning
2854 The @code{extra-offset} property provides complete control over the
2855 positioning of an object both horizontally and vertically.
2857 In the following example, the second fingering is moved a little to
2858 the left, and 1.8 staff space downwards:
2860 @cindex Fingering, example of overriding
2861 @cindex extra-offset property, example
2863 @lilypond[quote,fragment,relative=1,verbatim]
2866 \once \override Fingering.extra-offset = #'(-0.3 . -1.8)
2871 @node The positions property
2872 @unnumberedsubsubsec The @code{positions} property
2874 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
2875 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
2876 @cindex tuplet beams, controlling manually
2877 @cindex slurs, controlling manually
2878 @cindex phrasing slurs, controlling manually
2879 @cindex beams, controlling manually
2881 The @code{positions} property allows the position and slope of
2882 tuplets, slurs, phrasing slurs and beams to be controlled manually.
2883 Here's an example which has an ugly phrasing slur due to its trying to
2884 avoid the slur on the acciaccatura.
2886 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2887 r4 \acciaccatura e8\( d8 c~ c d c d\)
2891 We could simply move the phrasing slur above the notes, and this
2892 would be the preferred solution:
2894 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2897 \acciaccatura e8\( d8 c~ c d c d\)
2901 But if there were some reason why this could not be done the
2902 other alternative would be to move the left end of the phrasing
2903 slur down a little using the @code{positions} property. This
2904 also resolves the rather nasty shape.
2906 @cindex PhrasingSlur, example of overriding
2907 @cindex positions property, example
2909 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2911 \once \override PhrasingSlur.positions = #'(-4 . -3)
2912 \acciaccatura e8\( d8 c~ c d c d\)
2915 Here's a further example. We see that the beams
2916 collide with the ties:
2918 @lilypond[quote,verbatim,fragment,ragged-right]
2922 { c'1 ~ c'2. e'8 f' }
2924 { e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g'' }
2927 { c'1 ~ c'2. e'8 f' }
2929 { e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g'' }
2935 This can be resolved by manually moving both ends of the beam
2936 up from their position at 1.81 staff-spaces below the center line to,
2939 @cindex Beam, example of overriding
2940 @cindex positions property, example
2942 @lilypond[quote,verbatim,fragment,ragged-right]
2946 { c'1 ~ c'2. e'8 f' }
2949 \override Beam.positions = #'(-1 . -1)
2950 e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g''
2954 { c'1 ~ c'2. e'8 f' }
2956 { e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g'' }
2962 Note that the override continues to apply in the first voice of
2963 the second measure of eighth notes, but not to any of the beams in the
2966 @node The force-hshift property
2967 @unnumberedsubsubsec The @code{force-hshift property}
2969 We can now see how to apply the final corrections to the Chopin
2970 example introduced at the end of @ref{I'm hearing Voices}, which
2971 was left looking like this:
2973 @lilypond[quote,verbatim,fragment,ragged-right]
2974 \new Staff \relative c'' {
2989 The inner note of the first chord (i.e. the A-flat in the fourth
2990 Voice) need not be shifted away from the note column of the higher
2991 note. To correct this we set @code{force-hshift}, which is a property
2992 of @code{NoteColumn}, of this note to zero.
2994 In the second chord we prefer the F to line up with the A-flat and the
2995 lowest note to be positioned slightly right to avoid a collision of
2996 stems. We achieve this by setting @code{force-hshift} in the
2997 @code{NoteColumn} of the low D-flat to move it to the right by half
3000 Here's the final result:
3002 @cindex NoteColumn, example of overriding
3003 @cindex force-hshift property, example
3005 @lilypond[quote,verbatim,fragment,ragged-right]
3006 \new Staff \relative c'' {
3013 \once \override NoteColumn.force-hshift = #0.5
3019 \override NoteColumn.force-hshift = #0
3028 @node Real music example
3029 @subsection Real music example
3031 We end this section on Tweaks by showing the steps to be taken to
3032 deal with a tricky example which needs several tweaks to produce
3033 the desired output. The example has been deliberately chosen to
3034 illustrate the use of the Notation Reference to resolve unusual
3035 problems with notation. It is not representative of the more usual
3036 engraving process, so please do not let these difficulties put
3037 you off! Fortunately, difficulties like these are not very common!
3039 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
3040 9, the transition from the opening Lento to Moderato.
3041 Here, first, is what we want the output to look like, but to avoid
3042 over-complicating the example too much we have left out the
3043 dynamics, fingering and pedalling.
3045 @c The following should appear as music without code
3046 @c This example should not be indexed
3047 @c line-width ensures no break
3048 @lilypond[quote,ragged-right,line-width=6\in]
3049 rhMusic = \relative c'' {
3052 \once \override Tie.staff-position = #3.5
3056 \mergeDifferentlyHeadedOn
3057 \mergeDifferentlyDottedOn
3058 bes2.^\markup { \bold "Moderato" } r8
3064 % Reposition the c2 to the right of the merged note
3065 \once \override NoteColumn.force-hshift = #1.0
3066 % Move the c2 out of the main note column
3067 % so the merge will work
3074 % Stem on the d2 must be down to permit merging
3076 % Stem on the d2 should be invisible
3077 \tweak Stem.transparent ##t
3078 \tweak Flag.transparent ##t
3086 \mergeDifferentlyHeadedOff
3087 \mergeDifferentlyDottedOff
3092 lhMusic = \relative c' {
3094 <d g, d>1)\arpeggio |
3101 \new Staff = "RH" <<
3105 \new Staff = "LH" <<
3114 We note first that the right hand part in the third bar
3115 requires four voices. These are the five beamed eighth notes,
3116 the tied C, the half-note D which is merged with the eighth note
3117 D, and the dotted quarter note F-sharp, which is also merged with
3118 the eighth note at the same pitch. Everything else is in a single
3119 voice, so the easiest way is to introduce these extra three voices
3120 temporarily at the time they are needed. If you have forgotten
3121 how to do this, look at @ref{I'm hearing Voices} and @ref{Explicitly
3122 instantiating voices}. Here we choose to use explicitly instantiated
3123 voices for the polyphonic passage, as LilyPond is better able to
3124 avoid collisions if all voices are instantiated explicitly in this
3127 So let us begin by entering the notes as two variables, setting up
3128 the staff structure in a score block, and seeing what LilyPond
3129 produces by default:
3131 @c line-width ensures no break
3132 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3133 rhMusic = \relative c'' {
3139 % Start polyphonic section of four voices
3141 { c,8 d fis bes a } % continuation of main voice
3155 g2. % continuation of main voice
3159 lhMusic = \relative c' {
3168 \new Staff = "RH" <<
3172 \new Staff = "LH" <<
3181 All the notes are right, but the appearance is far from
3182 satisfactory. The tie collides with the change in time signature,
3183 some notes are not merged together, and several notation elements
3184 are missing. Let's first deal with the easier things. We can
3185 easily add the left hand slur and the right hand phrasing slur,
3186 since these were all covered in the Tutorial. Doing this gives:
3188 @c line-width ensures no break
3189 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3190 rhMusic = \relative c'' {
3196 % Start polyphonic section of four voices
3198 { c,8 d fis bes a } % continuation of main voice
3212 g2.\) % continuation of main voice
3216 lhMusic = \relative c' {
3225 \new Staff = "RH" <<
3229 \new Staff = "LH" <<
3238 The first bar is now correct. The second bar contains an arpeggio and
3239 is terminated by a double bar line. How do we do these, as they have
3240 not been mentioned in this Learning Manual? This is where we need to
3241 turn to the Notation Reference. Looking up @q{arpeggio} and @q{bar
3242 line} in the index quickly shows us that an arpeggio is produced by
3243 appending @code{\arpeggio} to a chord, and a double bar line is
3244 produced by the @code{\bar "||"} command. That's easily done. We
3245 next need to correct the collision of the tie with the time signature.
3246 This is best done by moving the tie upwards. Moving objects was
3247 covered earlier in @ref{Moving objects}, which says that objects
3248 positioned relative to the staff can be moved vertically by overriding
3249 their @code{staff-position} property, which is specified in half staff
3250 spaces relative to the center line of the staff. So the following
3251 override placed just before the first tied note would move the tie up
3252 to 3.5 half staff spaces above the center line:
3254 @code{\once \override Tie.staff-position = #3.5}
3256 This completes bar two, giving:
3258 @c line-width ensures no break
3259 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3260 rhMusic = \relative c'' {
3263 \once \override Tie.staff-position = #3.5
3268 % Start polyphonic section of four voices
3270 { c,8 d fis bes a } % continuation of main voice
3284 g2.\) % continuation of main voice
3288 lhMusic = \relative c' {
3290 <d g, d>1)\arpeggio |
3297 \new Staff = "RH" <<
3301 \new Staff = "LH" <<
3310 On to bar three and the start of the Moderato section. The tutorial
3311 showed how to add bold text with the @code{\markup} command, so
3312 adding @qq{Moderato} in bold is easy. But how do we merge notes in
3313 different voices together? This is where we need to turn again to
3314 the Notation Reference for help. A search for @qq{merge} in the
3315 Notation Reference index quickly leads us to the commands for merging
3316 differently headed and differently dotted notes in
3317 @ruser{Collision resolution}. In our example we need to merge both
3318 types of note for the duration of the polyphonic section in bar 3,
3319 so using the information we find in the Notation Reference we add
3322 \mergeDifferentlyHeadedOn
3323 \mergeDifferentlyDottedOn
3327 to the start of that section and
3330 \mergeDifferentlyHeadedOff
3331 \mergeDifferentlyDottedOff
3337 @c line-width ensures no break
3338 @lilypond[quote,ragged-right,line-width=6\in]
3339 rhMusic = \relative c'' {
3342 \once \override Tie.staff-position = #3.5
3346 bes2.^\markup { \bold "Moderato" } r8
3347 \mergeDifferentlyHeadedOn
3348 \mergeDifferentlyDottedOn
3349 % Start polyphonic section of four voices
3351 { c,8 d fis bes a } % continuation of main voice
3365 \mergeDifferentlyHeadedOff
3366 \mergeDifferentlyDottedOff
3367 g2.\) % continuation of main voice
3371 lhMusic = \relative c' {
3373 <d g, d>1)\arpeggio |
3380 \new Staff = "RH" <<
3384 \new Staff = "LH" <<
3393 These overrides have merged the two F-sharp notes, but not the two
3394 on D. Why not? The answer is there in the same section in the
3395 Notation Reference -- notes being merged must have stems in
3396 opposite directions and two notes cannot be merged successfully if
3397 there is a third note in the same note column. Here the two D's
3398 both have upward stems and there is a third note -- the C. We know
3399 how to change the stem direction using @code{\stemDown}, and
3400 the Notation Reference also says how to move the C -- apply a shift
3401 using one of the @code{\shift} commands. But which one?
3402 The C is in voice two which has shift off, and the two D's are in
3403 voices one and three, which have shift off and shift on,
3404 respectively. So we have to shift the C a further level still
3405 using @code{\shiftOnn} to avoid it interfering with the two D's.
3406 Applying these changes gives:
3408 @cindex Tie, example of overriding
3409 @cindex staff-position property, example
3411 @c line-width ensures no break
3412 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3413 rhMusic = \relative c'' {
3416 \once \override Tie.staff-position = #3.5
3420 bes2.^\markup { \bold "Moderato" } r8
3421 \mergeDifferentlyHeadedOn
3422 \mergeDifferentlyDottedOn
3423 % Start polyphonic section of four voices
3425 { c,8 d fis bes a } % continuation of main voice
3428 % Move the c2 out of the main note column
3429 % so the merge will work
3434 % Stem on the d2 must be down to permit merging
3442 \mergeDifferentlyHeadedOff
3443 \mergeDifferentlyDottedOff
3444 g2.\) % continuation of main voice
3448 lhMusic = \relative c' {
3450 <d g, d>1)\arpeggio |
3457 \new Staff = "RH" <<
3461 \new Staff = "LH" <<
3470 Nearly there. Only two problems remain: The downward stem on the
3471 merged D should not be there, and the C would be better positioned
3472 to the right of the D's. We know how to do both of these from the
3473 earlier tweaks: we make the stem transparent, and move the C with
3474 the @code{force-hshift} property. Here's the final result:
3476 @cindex NoteColumn, example of overriding
3477 @cindex force-hshift property, example
3478 @cindex Stem, example of overriding
3479 @cindex transparent property, example
3481 @c line-width ensures no break
3482 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3483 rhMusic = \relative c'' {
3486 \once \override Tie.staff-position = #3.5
3490 bes2.^\markup { \bold "Moderato" } r8
3491 \mergeDifferentlyHeadedOn
3492 \mergeDifferentlyDottedOn
3493 % Start polyphonic section of four voices
3495 { c,8 d fis bes a } % continuation of main voice
3499 % Reposition the c2 to the right of the merged note
3500 \once \override NoteColumn.force-hshift = #1.0
3501 % Move the c2 out of the main note column
3502 % so the merge will work
3509 % Stem on the d2 must be down to permit merging
3511 % Stem on the d2 should be invisible
3512 \tweak Stem.transparent ##t
3513 \tweak Flag.transparent ##t
3521 \mergeDifferentlyHeadedOff
3522 \mergeDifferentlyDottedOff
3523 g2.\) % continuation of main voice
3527 lhMusic = \relative c' {
3529 <d g, d>1)\arpeggio |
3536 \new Staff = "RH" <<
3540 \new Staff = "LH" <<
3550 @node Further tweaking
3551 @section Further tweaking
3554 * Other uses for tweaks::
3555 * Using variables for tweaks::
3557 * Other sources of information::
3558 * Advanced tweaks with Scheme::
3561 @node Other uses for tweaks
3562 @subsection Other uses for tweaks
3565 * Tying notes across voices::
3566 * Simulating a fermata in MIDI::
3569 @cindex transparent property, use of
3570 @cindex objects, making invisible
3571 @cindex removing objects
3572 @cindex objects, removing
3573 @cindex hiding objects
3574 @cindex objects, hiding
3575 @cindex invisible objects
3576 @cindex objects, invisible
3578 @node Tying notes across voices
3579 @unnumberedsubsubsec Tying notes across voices
3581 @cindex tying notes across voices
3583 The following example demonstrates how to connect notes in
3584 different voices using ties. Normally, only two notes in the
3585 same voice can be connected with ties. By using two voices,
3586 with the tied notes in one of them
3588 @lilypond[quote,fragment,relative=2]
3589 << { b8~ b\noBeam } \\ { b8[ g] } >>
3593 and blanking the first up-stem in that voice, the tie appears to
3596 @cindex Stem, example of overriding
3597 @cindex transparent property, example
3599 @lilypond[quote,fragment,relative=2,verbatim]
3602 \tweak Stem.transparent ##t
3603 \tweak Flag.transparent ##t
3611 To make sure that the just-blanked stem doesn't squeeze the tie
3612 too much, we can lengthen the stem by setting the
3613 @code{length} to @code{8},
3615 @lilypond[quote,fragment,relative=2,verbatim]
3618 \tweak Stem.transparent ##t
3619 \tweak Flag.transparent ##t
3620 \tweak Stem.length #8
3629 @cindex tweak, generated from override
3630 Now for @emph{overriding} the transparency of a graphical object,
3631 we could have used the shorthand @code{\hide} as explained above.
3632 Tweaking is a different operation, affecting only properties
3633 generated from a single music expression. It turns out that we
3634 can convert overrides into tweaks using @code{\single}, making it
3635 possible to rewrite the above example as
3637 @lilypond[quote,fragment,relative=2,verbatim]
3642 \tweak Stem.length #8
3650 In this particular case, the difference to @code{\once \hide} is
3651 not apparent. It is important when there are several objects at
3652 the same point in musical time (like noteheads in a chord). In
3653 that case, @code{\once} will affect all of those objects while
3654 @code{\single} will only affect a single one, the one generated by
3655 the immediately following music expression.
3657 @node Simulating a fermata in MIDI
3658 @unnumberedsubsubsec Simulating a fermata in MIDI
3660 @cindex stencil property, use of
3661 @cindex fermata, implementing in MIDI
3663 For outside-staff objects it is usually better to override the
3664 object's @code{stencil} property rather than its @code{transparent}
3665 property when you wish to remove it from the printed output.
3666 Setting the @code{stencil} property of an object to @code{#f} will
3667 remove that object entirely from the printed output. This means it
3668 has no effect on the placement of other objects placed relative to
3671 For example, if we wished to change the metronome setting in order
3672 to simulate a fermata in the MIDI output we would not want the
3673 metronome markings to appear in the printed output, and we would
3674 not want it to influence the spacing between the two systems or
3675 the positions of adjacent annotations on the staff. So setting
3676 its @code{stencil} property to @code{#f} would be the best way.
3677 We show here the effect of the two methods:
3679 @cindex MetronomeMark, example of overriding
3680 @cindex transparent property, example
3682 @lilypond[quote,verbatim,ragged-right]
3685 % Visible tempo marking
3688 \once \hide Score.MetronomeMark
3689 % Invisible tempo marking to lengthen fermata in MIDI
3692 % New tempo for next section
3701 @cindex MetronomeMark, example of overriding
3702 @cindex stencil property, example
3704 @lilypond[quote,verbatim,ragged-right]
3707 % Visible tempo marking
3710 \once \omit Score.MetronomeMark
3711 % Invisible tempo marking to lengthen fermata in MIDI
3714 % New tempo for next section
3724 Both methods remove the metronome mark which lengthens the fermata
3725 from the printed output, and both affect the MIDI timing as
3726 required, but the transparent metronome mark in the first line
3727 forces the following tempo indication too high while the
3728 second (with the stencil removed) does not.
3734 @node Using variables for tweaks
3735 @subsection Using variables for tweaks
3737 @cindex variables, using for tweaks
3738 @cindex using variables for tweaks
3739 @cindex tweaks, using variables for
3741 Override commands are often long and tedious to type, and they
3742 have to be absolutely correct. If the same overrides are to be
3743 used many times it may be worth defining variables to hold them.
3745 Suppose we wish to emphasize certain words in lyrics by printing
3746 them in bold italics. The @code{\italic} and @code{\bold}
3747 commands only work within lyrics if they are embedded, together with
3748 the word or words to be modified, within a @code{\markup} block,
3749 which makes them tedious to enter. The need to embed the words
3750 themselves prevents their use in simple variables. As an
3751 alternative can we use @code{\override} and @code{\revert} commands?
3754 @code{\override Lyrics.LyricText.font-shape = #'italic}
3755 @code{\override Lyrics.LyricText.font-series = #'bold}
3757 @code{\revert Lyrics.LyricText.font-shape}
3758 @code{\revert Lyrics.LyricText.font-series}
3761 These would also be extremely tedious to enter if there were many
3762 words requiring emphasis. But we @emph{can} define these as two
3763 variables and use those to bracket the words to be emphasized.
3764 Another advantage of using variables for these overrides is that
3765 the spaces around the dot are not necessary, since they are not
3766 being interpreted in @code{\lyricmode} directly. Here's an example
3767 of this, although in practice we would choose shorter names
3768 for the variables to make them quicker to type:
3770 @cindex LyricText, example of overriding
3771 @cindex font-shape property, example
3772 @cindex font-series property, example
3774 @lilypond[quote,verbatim]
3776 \override Lyrics.LyricText.font-shape = #'italic
3777 \override Lyrics.LyricText.font-series = #'bold
3781 \revert Lyrics.LyricText.font-shape
3782 \revert Lyrics.LyricText.font-series
3785 global = { \key c \major \time 4/4 \partial 4 }
3787 SopranoMusic = \relative c' { c4 | e4. e8 g4 g | a4 a g }
3788 AltoMusic = \relative c' { c4 | c4. c8 e4 e | f4 f e }
3789 TenorMusic = \relative c { e4 | g4. g8 c4. b8 | a8 b c d e4 }
3790 BassMusic = \relative c { c4 | c4. c8 c4 c | f8 g a b c4 }
3792 VerseOne = \lyrics {
3793 E -- | ter -- nal \emphasize Fa -- ther, | \normal strong to save,
3796 VerseTwo = \lyricmode {
3797 O | \once \emphasize Christ, whose voice the | wa -- ters heard,
3800 VerseThree = \lyricmode {
3801 O | \emphasize Ho -- ly Spi -- rit, | \normal who didst brood
3804 VerseFour = \lyricmode {
3805 O | \emphasize Tri -- ni -- ty \normal of | love and pow'r
3812 \new Voice = "Soprano" { \voiceOne \global \SopranoMusic }
3813 \new Voice = "Alto" { \voiceTwo \AltoMusic }
3814 \new Lyrics \lyricsto "Soprano" { \VerseOne }
3815 \new Lyrics \lyricsto "Soprano" { \VerseTwo }
3816 \new Lyrics \lyricsto "Soprano" { \VerseThree }
3817 \new Lyrics \lyricsto "Soprano" { \VerseFour }
3821 \new Voice = "Tenor" { \voiceOne \TenorMusic }
3822 \new Voice = "Bass" { \voiceTwo \BassMusic }
3830 @subsection Style sheets
3832 The output that LilyPond produces can be heavily modified; see
3833 @ref{Tweaking output}, for details. But what if you have many
3834 input files that you want to apply your tweaks to? Or what if you
3835 simply want to separate your tweaks from the actual music? This
3836 is quite easy to do.
3838 Let's look at an example. Don't worry if you don't understand
3839 the parts with all the @code{#()}. This is explained in
3840 @ref{Advanced tweaks with Scheme}.
3842 @lilypond[quote,verbatim,ragged-right]
3844 #(make-dynamic-script
3845 #{ \markup { \hspace #0
3846 \translate #'(5 . 0)
3847 \line { \dynamic "mp"
3848 \text \italic "dolce" } }
3852 #(define-music-function
3853 (parser location string)
3855 #{ ^\markup \bold \box #string #})
3859 a4.\mpdolce d8 cis4--\glissando a |
3863 g8(\! fis)-. e( d)-. cis2 |
3867 Let's do something about the @code{mpdolce} and @code{inst} definitions.
3868 They produce the output we desire, but we might want to use them in
3869 another piece. We could simply copy-and-paste them at the top of every
3870 file, but that's an annoyance. It also leaves those definitions in our
3871 input files, and I personally find all the @code{#()} somewhat ugly.
3872 Let's hide them in another file:
3875 %%% save this to a file called "definitions.ily"
3877 #(make-dynamic-script
3878 #@{ \markup @{ \hspace #0
3879 \translate #'(5 . 0)
3880 \line @{ \dynamic "mp"
3881 \text \italic "dolce" @} @}
3885 #(define-music-function
3886 (parser location string)
3888 #@{ ^\markup \bold \box #string #@})
3891 We will refer to this file using the @code{\include} command near
3892 the top of the music file. (The extension @file{.ily} is used to
3893 distinguish this included file, which is not meant to be compiled
3894 on its own, from the main file.)
3895 Now let's modify our music (let's save this file as @file{music.ly}).
3897 @c We have to do this awkward example/lilypond-non-verbatim
3898 @c because we can't do the \include stuff in the manual.
3901 \include "definitions.ily"
3905 a4.\mpdolce d8 cis4--\glissando a |
3909 g8(\! fis)-. e( d)-. cis2 |
3913 @lilypond[quote,ragged-right]
3915 #(make-dynamic-script
3916 #{ \markup { \hspace #0
3917 \translate #'(5 . 0)
3918 \line { \dynamic "mp"
3919 \text \italic "dolce" } }
3923 #(define-music-function
3924 (parser location string)
3926 #{ ^\markup \bold \box #string #})
3930 a4.\mpdolce d8 cis4--\glissando a |
3934 g8(\! fis)-. e( d)-. cis2 |
3938 That looks better, but let's make a few changes. The glissando is hard
3939 to see, so let's make it thicker and closer to the note heads. Let's
3940 put the metronome marking above the clef, instead of over the first
3941 note. And finally, my composition professor hates @q{C} time signatures,
3942 so we'd better make that @q{4/4} instead.
3944 Don't change @file{music.ly}, though. Replace our @file{definitions.ily}
3950 #(make-dynamic-script
3951 #@{ \markup @{ \hspace #0
3952 \translate #'(5 . 0)
3953 \line @{ \dynamic "mp"
3954 \text \italic "dolce" @} @}
3958 #(define-music-function
3959 (parser location string)
3961 #@{ ^\markup \bold \box #string #@})
3966 \override MetronomeMark.extra-offset = #'(-9 . 0)
3967 \override MetronomeMark.padding = #'3
3971 \override TimeSignature.style = #'numbered
3975 \override Glissando.thickness = #3
3976 \override Glissando.gap = #0.1
3981 @lilypond[quote,ragged-right]
3983 #(make-dynamic-script
3984 #{ \markup { \hspace #0
3985 \translate #'(5 . 0)
3986 \line { \dynamic "mp"
3987 \text \italic "dolce" } }
3991 #(define-music-function
3992 (parser location string)
3994 #{ ^\markup \bold \box #string #})
3999 \override MetronomeMark.extra-offset = #'(-9 . 0)
4000 \override MetronomeMark.padding = #'3
4004 \override TimeSignature.style = #'numbered
4008 \override Glissando.thickness = #3
4009 \override Glissando.gap = #0.1
4015 a4.\mpdolce d8 cis4--\glissando a |
4019 g8(\! fis)-. e( d)-. cis2 |
4023 That looks nicer! But now suppose that I want to publish this
4024 piece. My composition professor doesn't like @q{C} time
4025 signatures, but I'm somewhat fond of them. Let's copy the
4026 current @file{definitions.ily} to @file{web-publish.ily} and
4027 modify that. Since this music is aimed at producing a pdf which
4028 will be displayed on the screen, we'll also increase the
4029 overall size of the output.
4034 #(make-dynamic-script
4035 #@{ \markup @{ \hspace #0
4036 \translate #'(5 . 0)
4037 \line @{ \dynamic "mp"
4038 \text \italic "dolce" @} @}
4042 #(define-music-function
4043 (parser location string)
4045 #@{ ^\markup \bold \box #string #@})
4047 #(set-global-staff-size 23)
4052 \override MetronomeMark.extra-offset = #'(-9 . 0)
4053 \override MetronomeMark.padding = #'3
4060 \override Glissando.thickness = #3
4061 \override Glissando.gap = #0.1
4066 @lilypond[quote,ragged-right]
4068 #(make-dynamic-script
4069 #{ \markup { \hspace #0
4070 \translate #'(5 . 0)
4071 \line { \dynamic "mp"
4072 \text \italic "dolce" } }
4076 #(define-music-function
4077 (parser location string)
4079 #{ ^\markup \bold \box #string #})
4081 #(set-global-staff-size 23)
4085 \override MetronomeMark.extra-offset = #'(-9 . 0)
4086 \override MetronomeMark.padding = #'3
4089 \override Glissando.thickness = #3
4090 \override Glissando.gap = #0.1
4096 a4.\mpdolce d8 cis4--\glissando a |
4100 g8(\! fis)-. e( d)-. cis2 |
4104 Now in our music, I simply replace
4105 @code{\include "definitions.ily"} with
4106 @code{\include "web-publish.ily"}. Of course, we could make this
4107 even more convenient. We could make a @file{definitions.ily} file which
4108 contains only the definitions of @code{mpdolce} and @code{inst}, a
4109 @file{web-publish.ily} file which contains only the @code{\layout}
4110 section listed above, and a @file{university.ily} file which
4111 contains only the tweaks to produce the output that my professor
4112 prefers. The top of @file{music.ly} would then look like this:
4115 \include "definitions.ily"
4117 %%% Only uncomment one of these two lines!
4118 \include "web-publish.ily"
4119 %\include "university.ily"
4122 This approach can be useful even if you are only producing
4123 one set of parts. I use half a dozen different
4124 @q{style sheet} files for my projects. I begin every music
4125 file with @code{\include "../global.ily"}, which contains
4129 \version @w{"@version{}"}
4131 #(ly:set-option 'point-and-click #f)
4133 \include "../init/init-defs.ly"
4134 \include "../init/init-layout.ly"
4135 \include "../init/init-headers.ly"
4136 \include "../init/init-paper.ly"
4140 @node Other sources of information
4141 @subsection Other sources of information
4143 The Internals Reference documentation contains a lot of information
4144 about LilyPond, but even more information can be gathered by
4145 looking at the internal LilyPond files. To explore these, you must
4146 first find the directory appropriate to your system. The location
4147 of this directory depends (a) on whether you obtained LilyPond
4148 by downloading a precompiled binary from lilypond.org
4149 or whether you installed it from a package manager (i.e.
4150 distributed with GNU/Linux, or installed under fink or cygwin) or
4151 compiled it from source, and (b) on which operating system it is
4154 @subsubsubheading Downloaded from lilypond.org
4161 @file{@var{INSTALLDIR}/lilypond/usr/@/share/lilypond/current/}
4168 @file{@var{INSTALLDIR}/LilyPond.app/Contents/@/Resources/share/lilypond/current/}
4171 by either @code{cd}-ing into this directory from the
4172 Terminal, or control-clicking on the LilyPond application and
4173 selecting @q{Show Package Contents}.
4177 Using Windows Explorer, navigate to
4179 @file{@var{INSTALLDIR}/LilyPond/usr/@/share/lilypond/current/}
4184 @subsubsubheading Installed from a package manager or compiled from source
4187 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
4188 @var{PREFIX} is set by your package manager or @code{configure}
4189 script, and @var{X.Y.Z} is the LilyPond version number.
4193 Within this directory the two interesting subdirectories are
4196 @item @file{ly/} - contains files in LilyPond format
4197 @item @file{scm/} - contains files in Scheme format
4200 Let's begin by looking at some files in @file{ly/}.
4201 Open @file{ly/property-init.ly} in a text editor. The one
4202 you normally use for @code{.ly} files will be fine. This file
4203 contains the definitions of all the standard LilyPond predefined
4204 commands, such as @code{\stemUp} and @code{\slurDotted}. You will
4205 see that these are nothing more than definitions of variables
4206 containing one or a group of @code{\override} commands. For
4207 example, @code{/tieDotted} is defined to be:
4211 \override Tie.dash-period = #0.75
4212 \override Tie.dash-fraction = #0.1
4216 If you do not like the default values these predefined commands can
4217 be redefined easily, just like any other variable, at the
4218 head of your input file.
4220 The following are the most useful files to be found in
4223 @multitable @columnfractions .4 .6
4226 @item @file{ly/engraver-init.ly}
4227 @tab Definitions of engraver Contexts
4228 @item @file{ly/paper-defaults-init.ly}
4229 @tab Specifications of paper-related defaults
4230 @item @file{ly/performer-init.ly}
4231 @tab Definitions of performer Contexts
4232 @item @file{ly/property-init.ly}
4233 @tab Definitions of all common predefined commands
4234 @item @file{ly/spanner-init.ly}
4235 @tab Definitions of spanner-related predefined commands
4238 Other settings (such as the definitions of markup commands) are
4239 stored as @file{.scm} (Scheme) files. The Scheme programming
4240 language is used to provide a programmable interface into
4241 LilyPond internal operation. Further explanation of these files
4242 is currently outside the scope of this manual, as a knowledge of
4243 the Scheme language is required. Users should be warned that
4244 a substantial amount of technical knowledge or time is required
4245 to understand Scheme and these files (see @rextend{Scheme tutorial}).
4247 If you have this knowledge, the Scheme files which may be of
4250 @multitable @columnfractions .4 .6
4253 @item @file{scm/auto-beam.scm}
4254 @tab Sub-beaming defaults
4255 @item @file{scm/define-grobs.scm}
4256 @tab Default settings for grob properties
4257 @item @file{scm/define-markup-commands.scm}
4258 @tab Specify all markup commands
4259 @item @file{scm/midi.scm}
4260 @tab Default settings for MIDI output
4261 @item @file{scm/output-lib.scm}
4262 @tab Settings that affect appearance of frets, colors,
4263 accidentals, bar lines, etc
4264 @item @file{scm/parser-clef.scm}
4265 @tab Definitions of supported clefs
4266 @item @file{scm/script.scm}
4267 @tab Default settings for articulations
4271 @node Advanced tweaks with Scheme
4272 @subsection Advanced tweaks with Scheme
4274 Although many things are possible with the @code{\override} and
4275 @code{\tweak} commands, an even more powerful way of modifying
4276 the action of LilyPond is available through a programmable
4277 interface to the LilyPond internal operation. Code written in
4278 the Scheme programming language can be incorporated directly in
4279 the internal operation of LilyPond. Of course, at least a basic
4280 knowledge of programming in Scheme is required to do this, and an
4281 introduction is provided in the @rextend{Scheme tutorial}.
4283 As an illustration of one of the many possibilities, instead of
4284 setting a property to a constant it can be set to a Scheme
4285 procedure which is then called whenever that property is accessed
4286 by LilyPond. The property can then be set dynamically to a value
4287 determined by the procedure at the time it is called. In this
4288 example we color the note head in accordance with its position on
4291 @cindex x11-color function, example of using
4292 @cindex NoteHead, example of overriding
4293 @cindex color property, setting to Scheme procedure
4295 @lilypond[quote,verbatim,ragged-right]
4296 #(define (color-notehead grob)
4297 "Color the notehead according to its position on the staff."
4298 (let ((mod-position (modulo (ly:grob-property grob 'staff-position)
4301 ;; Return rainbow colors
4302 ((1) (x11-color 'red )) ; for C
4303 ((2) (x11-color 'orange )) ; for D
4304 ((3) (x11-color 'yellow )) ; for E
4305 ((4) (x11-color 'green )) ; for F
4306 ((5) (x11-color 'blue )) ; for G
4307 ((6) (x11-color 'purple )) ; for A
4308 ((0) (x11-color 'violet )) ; for B
4312 % Arrange to obtain color from color-notehead procedure
4313 \override NoteHead.color = #color-notehead
4314 a2 b | c2 d | e2 f | g2 a |
4318 Further examples showing the use of these programmable interfaces
4319 can be found in @rextend{Callback functions}.