1 @c -*- coding: utf-8; mode: texinfo; -*-
4 Translation of GIT committish: 12c6693055728e69dce5c4e5a4a2b5f71180a5e2
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 \tuplet 3/2 { c8[ c c] }
467 \tuplet 3/2 { c8[ c c] }
468 \tuplet 3/2 { 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 \tuplet 3/2 { c8[ c c] }
483 \once \override TupletNumber.text = #tuplet-number::calc-fraction-text
487 \once \override TupletNumber.transparent = ##t
488 \tuplet 3/2 { c8[ c c] }
489 \tuplet 3/2 { 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, even if the value itself already
918 starts with@tie{}@code{#}. We only give examples for constants
919 here: if you want to compute a value using Scheme, see
920 @rextend{Calculations in Scheme}.
922 @multitable @columnfractions .2 .45 .35
923 @headitem Property type
927 @tab Either True or False, represented by #t or #f
928 @tab @code{#t}, @code{#f}
929 @item Dimension (in staff space)
930 @tab A decimal number (in units of staff space)
931 @tab @code{2.5}, @code{0.34}
933 @tab A valid direction constant or its numerical equivalent
934 (@code{0} or @code{CENTER} indicate a neutral direction)
935 @tab @code{LEFT}, @code{CENTER}, @code{UP},
936 @code{1}, @w{@code{-1}}
939 @tab @code{3}, @code{-1}
941 @tab A sequence of constants or symbols separated by spaces, enclosed
943 and preceded by an apostrophe (quote mark)
944 @tab @code{'(left-edge staff-bar)}, @code{'(1)}, @code{'()},
945 @code{'(1.0 0.25 0.5)}
947 @tab Any valid markup
948 @tab @code{\markup @{ \italic "cresc." @}}, @code{"bagpipe"}
950 @tab A fraction of a whole note constructed with the
952 @tab @code{(ly:make-moment 1/4)},
953 @code{(ly:make-moment 3/8)}
955 @tab Any positive or negative, possibly decimal, value
956 @tab @code{3}, @w{@code{-2.45}}
957 @item Pair (of numbers)
958 @tab Two numbers separated by a @q{space . space} and enclosed
959 in brackets preceded by an apostrophe
960 @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
962 @tab Any of the set of permitted symbols for that property,
963 preceded by an apostrophe
964 @tab @code{'italic}, @code{'inside}
966 @tab A procedure, or @code{#f} to cause no action
967 @tab @code{bend::print}, @code{ly:text-interface::print},
971 enclosed in @code{#(}@dots{}@code{)}.
972 @tab @code{#(#t #t #f)}
977 Extending: @rextend{Scheme tutorial}.
980 @node Appearance of objects
981 @section Appearance of objects
983 Let us now put what we have learned into practice with a few
984 examples which show how tweaks may be used to change the
985 appearance of the printed music.
988 * Visibility and color of objects::
990 * Length and thickness of objects::
993 @node Visibility and color of objects
994 @subsection Visibility and color of objects
996 In the educational use of music we might wish to print a score
997 with certain elements omitted as an exercise for the student,
998 who is required to supply them. As a simple example,
999 let us suppose the exercise is to supply the missing bar lines
1000 in a piece of music. But the bar lines are normally inserted
1001 automatically. How do we prevent them printing?
1003 Before we tackle this, let us remember that object properties are
1004 grouped in what are called @emph{interfaces} -- see @ref{Properties
1005 found in interfaces}. This is simply to group together those
1006 properties that may be used together to tweak a graphical object -- if
1007 one of them is allowed for an object, so are the others. Some objects
1008 then use the properties in some interfaces, others use them from other
1009 interfaces. The interfaces which contain the properties used by a
1010 particular grob are listed in the IR at the bottom of the page
1011 describing that grob, and those properties may be viewed by looking at
1014 We explained how to find information about grobs in @ref{Properties of
1015 layout objects}. Using the same approach, we go to the IR to find the
1016 layout object which prints bar lines. Going via @emph{Backend} and
1017 @emph{All layout objects} we find there is a layout object called
1018 @code{BarLine}. Its properties include two that control its
1019 visibility: @code{break-visibility} and @code{stencil}. Barline also
1020 supports a number of interfaces, including the @code{grob-interface},
1021 where we find the @code{transparent} and the @code{color} properties.
1022 All of these can affect the visibility of bar lines (and, of course,
1023 by extension, many other layout objects too.) Let's consider each of
1027 * The stencil property::
1028 * The break-visibility property::
1029 * The transparent property::
1030 * The color property::
1033 @node The stencil property
1034 @unnumberedsubsubsec The @code{stencil} property
1036 @cindex stencil property
1038 This property controls the appearance of the bar lines by specifying
1039 the symbol (glyph) which should be printed. In common
1040 with many other properties, it can be set to print nothing by
1041 setting its value to @code{#f}. Let's try it, as before, omitting
1042 the implied Context, @code{Voice}:
1044 @cindex BarLine, example of overriding
1045 @cindex stencil property, example
1047 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1050 \override BarLine.stencil = ##f
1052 g,8 a16 b8 c d4 e16 |
1057 The bar lines are still printed. What is wrong? Go back to the IR
1058 and look again at the page giving the properties of BarLine. At the
1059 top of the page it says @qq{Barline objects are created by:
1060 Bar_engraver}. Go to the @code{Bar_engraver} page. At the bottom it
1061 gives a list of Contexts in which the bar engraver operates. All of
1062 them are of the type @code{Staff}, so the reason the @code{\override}
1063 command failed to work as expected is because @code{Barline} is not in
1064 the default @code{Voice} context. If the context is specified
1065 incorrectly, the command simply does not work. No error message is
1066 produced, and nothing is logged in the log file. Let's try correcting
1067 it by adding the correct context:
1069 @cindex BarLine, example of overriding
1070 @cindex stencil property, example
1072 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1075 \override Staff.BarLine.stencil = ##f
1077 g,8 a16 b8 c d4 e16 |
1082 Now the bar lines have vanished. Setting the @code{stencil}
1083 property to @code{#f} is such a frequent operation that there is a
1084 shorthand for it called @code{\omit}:
1087 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1092 g,8 a16 b8 c d4 e16 |
1097 Note, though, that setting the @code{stencil} property to @code{#f}
1098 will cause errors when the dimensions of the object are required for
1099 correct processing. For example, errors will be generated if the
1100 @code{stencil} property of the @code{NoteHead} object is set to
1101 @code{#f}. If this is the case, you can instead use the
1102 @code{point-stencil} function, which sets the stencil to a object
1105 @lilypond[quote,verbatim,relative=2]
1108 \once \override NoteHead.stencil = #point-stencil
1113 @node The break-visibility property
1114 @unnumberedsubsubsec The @code{break-visibility} property
1116 @cindex break-visibility property
1118 We see from the @code{BarLine} properties in the IR that the
1119 @code{break-visibility} property requires a vector of three booleans.
1120 These control respectively whether bar lines are printed at the end of
1121 a line, in the middle of lines, and at the beginning of lines. For
1122 our example we want all bar lines to be suppressed, so the value we
1123 need is @code{#(#f #f #f)} (also available
1124 under the name @code{all-invisible}). Let's try that, remembering to include
1125 the @code{Staff} context. Note also that in writing this value we
1126 have @code{##} before the opening parenthesis. One @code{#} is required
1127 as part of vector constant syntax, and the first@tie{}@code{#} is
1128 required, as always, to precede the value itself in the
1129 @code{\override} command.
1131 @cindex BarLine, example of overriding
1132 @cindex break-visibility property, example
1134 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1137 \override Staff.BarLine.break-visibility = ##(#f #f #f)
1139 g,8 a16 b8 c d4 e16 |
1144 And we see this too removes all the bar lines.
1146 @node The transparent property
1147 @unnumberedsubsubsec The @code{transparent} property
1149 @cindex transparent property
1150 @cindex transparency
1152 We see from the properties specified in the @code{grob-interface} page
1153 in the IR that the @code{transparent} property is a boolean. This
1154 should be set to @code{#t} to make the grob transparent. In this next
1155 example let us make the time signature invisible rather than the bar
1156 lines. To do this we need to find the grob name for the time
1157 signature. Back to the @q{All layout objects} page in the IR to find
1158 the properties of the @code{TimeSignature} layout object. This is
1159 produced by the @code{Time_signature_engraver} which you can check
1160 also lives in the @code{Staff} context and also supports the
1161 @code{grob-interface}. So the command to make the time signature
1164 @cindex TimeSignature, example of overriding
1165 @cindex transparent property, example
1167 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1170 \override Staff.TimeSignature.transparent = ##t
1172 g,8 a16 b8 c d4 e16 |
1178 Again, setting the @code{transparent} property is a rather
1179 frequent operation, so we have a shorthand for it called
1183 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1186 \hide Staff.TimeSignature
1188 g,8 a16 b8 c d4 e16 |
1194 In either case, the time signature is gone, but this command
1196 the time signature should be. Maybe this is what is wanted for
1197 an exercise for the student to fill it in, but in other
1198 circumstances a gap might be undesirable. To remove it, the
1199 stencil for the time signature should be set to @code{#f}
1202 @cindex TimeSignature, example of overriding
1203 @cindex stencil property, example
1205 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1208 \omit Staff.TimeSignature
1210 g,8 a16 b8 c d4 e16 |
1216 and the difference is obvious: setting the stencil to @code{#f}
1217 (possibly via @code{\omit})
1218 removes the object entirely; making the object @code{transparent}
1219 (which can be done using @code{\hide})
1220 leaves it where it is, but makes it invisible.
1222 @node The color property
1223 @unnumberedsubsubsec The @code{color} property
1225 @cindex color property
1227 Finally let us try making the bar lines invisible by coloring
1228 them white. (There is a difficulty with this in that the
1229 white bar line may or may not blank out the staff lines where
1230 they cross. You may see in some of the examples below that this
1231 happens unpredictably. The details of why this is so and how to
1232 control it are covered in @ruser{Painting objects white}. But at
1233 the moment we are learning about color, so please just accept this
1234 limitation for now.)
1236 The @code{grob-interface} specifies that the
1237 color property value is a list, but there is no
1238 explanation of what that list should be. The list it
1239 requires is actually a list of values in internal units,
1240 but, to avoid having to know what these are, several ways
1241 are provided to specify colors. The first way is to use one
1242 of the @q{normal} colors listed in the first table in
1243 @ruser{List of colors}. To set the bar lines to white
1246 @cindex BarLine, example of overriding
1247 @cindex color property, example
1249 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1252 \override Staff.BarLine.color = #white
1254 g,8 a16 b8 c d4 e16 |
1260 and again, we see the bar lines are not visible. Note that
1261 @emph{white} is not preceded by an apostrophe -- it is not
1262 a symbol, but a @emph{variable}. When evaluated, it provides
1263 the list of internal values required to set the color to
1264 white. The other colors in the normal list are variables
1265 too. To convince yourself this is working you might like
1266 to change the color to one of the other variables in the
1274 The second way of changing the color is to use the list of
1275 X11 color names in the second list in @ruser{List of colors}.
1276 However, these are mapped to the actual values by the function
1277 @code{x11-color} which
1278 converts X11 color symbols into the list of internal values like this:
1280 @cindex BarLine, example of overriding
1281 @cindex color property, example
1283 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1286 \override Staff.BarLine.color = #(x11-color 'white)
1288 g,8 a16 b8 c d4 e16 |
1294 Note that in this case the function @code{x11-color} takes
1295 a symbol as an argument, so the symbol must be preceded by
1296 an apostrophe to keep it from being evaluated as a variable, and
1297 the whole function call has to be enclosed in parentheses.
1304 There is another function, one which converts RGB values into
1305 internal colors -- the @code{rgb-color} function. This takes
1306 three arguments giving the intensities of the red, green and
1307 blue colors. These take values in the range 0 to 1. So to
1308 set the color to red the value should be @code{(rgb-color 1 0 0)}
1309 and to white it should be @code{(rgb-color 1 1 1)}:
1311 @cindex BarLine, example of overriding
1312 @cindex color property, example
1314 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1317 \override Staff.BarLine.color = #(rgb-color 1 1 1)
1319 g,8 a16 b8 c d4 e16 |
1324 Finally, there is also a grey scale available as part of the
1325 X11 set of colors. These range from black, @code{'grey0},
1326 to white, @code{'grey100}, in steps of 1. Let's illustrate
1327 this by setting all the layout objects in our example to
1328 various shades of grey:
1330 @cindex StaffSymbol, example of overriding
1331 @cindex TimeSignature, example of overriding
1332 @cindex Clef, example of overriding
1333 @cindex NoteHead, example of overriding
1334 @cindex Stem, example of overriding
1335 @cindex BarLine, example of overriding
1336 @cindex color property, example
1337 @cindex x11-color, example of using
1339 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1342 \override Staff.StaffSymbol.color = #(x11-color 'grey30)
1343 \override Staff.TimeSignature.color = #(x11-color 'grey60)
1344 \override Staff.Clef.color = #(x11-color 'grey60)
1345 \override Voice.NoteHead.color = #(x11-color 'grey85)
1346 \override Voice.Stem.color = #(x11-color 'grey85)
1347 \override Staff.BarLine.color = #(x11-color 'grey10)
1349 g,8 a16 b8 c d4 e16 |
1355 Note the contexts associated with each of the layout objects.
1356 It is important to get these right, or the commands will not
1357 work! Remember, the context is the one in which the appropriate
1358 engraver is placed. The default context for engravers can be
1359 found by starting from the layout object, going from there to
1360 the engraver which produces it, and on the engraver page in the
1361 IR it tells you in which context the engraver will normally be
1365 @node Size of objects
1366 @subsection Size of objects
1368 @cindex changing size of objects
1369 @cindex size of objects
1370 @cindex objects, size of
1371 @cindex objects, changing size of
1373 Let us begin by looking again at the earlier example
1374 (see @ref{Nesting music expressions}) which showed
1375 how to introduce a new temporary staff, as in an @rglos{ossia}.
1377 @cindex alignAboveContext property, example
1378 @cindex @code{\with}, example
1380 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1381 \new Staff ="main" {
1388 alignAboveContext = #"main" }
1396 Ossia are normally written without clef and time signature, and
1397 are usually printed slightly smaller than the main staff. We
1398 already know now how to remove the clef and time signature --
1399 we simply set the stencil of each to @code{#f}, as follows:
1401 @cindex alignAboveContext property, example
1402 @cindex @code{\with}, example
1404 @cindex Clef, example of overriding
1405 @cindex TimeSignature, example of overriding
1407 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1408 \new Staff ="main" {
1415 alignAboveContext = #"main"
1419 \omit Staff.TimeSignature
1429 where the extra pair of braces after the @code{\with} clause are
1430 required to ensure the enclosed overrides and music are applied
1433 But what is the difference between modifying the staff context by
1434 using @code{\with} and modifying the stencils of the clef and the
1435 time signature with @code{\override}, or in this case
1437 The main difference is that
1438 changes made in a @code{\with} clause are made at the time the
1439 context is created, and remain in force as the @strong{default}
1440 values for the duration of that context, whereas
1441 @code{\set} or @code{\override} commands embedded in the
1442 music are dynamic -- they make changes synchronized with
1443 a particular point in the music. If changes are unset or
1444 reverted using @code{\unset} or @code{\revert} they return to
1445 their default values, which will be the ones set in the
1446 @code{\with} clause, or if none have been set there, the normal
1449 Some context properties can be modified only in @code{\with} clauses.
1450 These are those properties which cannot sensibly be changed after the
1451 context has been created. @code{alignAboveContext} and its partner,
1452 @code{alignBelowContext}, are two such properties -- once the staff
1453 has been created its alignment is decided and it would make no sense
1454 to try to change it later.
1456 The default values of layout object properties can also be set
1457 in @code{\with} clauses. Simply use the normal @code{\override}
1458 command leaving out the context name, since this is unambiguously
1459 defined as the context which the @code{\with} clause is modifying.
1460 If fact, an error will be generated if a context is specified
1463 So we could replace the example above with
1465 @cindex alignAboveContext property, example
1466 @cindex @code{\with}, example
1467 @cindex Clef, example of overriding
1468 @cindex TimeSignature, example of overriding
1470 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1471 \new Staff ="main" {
1478 alignAboveContext = #"main"
1479 % Don't print clefs in this staff
1480 \override Clef.stencil = ##f
1481 % Don't print time signatures in this staff
1482 \override TimeSignature.stencil = ##f
1491 It turns out that we can also employ the shorthands @code{\hide}
1492 and @code{\omit} for setting the @code{transparent} property and
1493 clearing the @code{stencil} here, leading to the result
1495 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1496 \new Staff ="main" {
1503 alignAboveContext = #"main"
1504 % Don't print clefs in this staff
1506 % Don't print time signatures in this staff
1516 Finally we come to changing the size of layout objects.
1518 Some layout objects are created as glyphs selected from a typeface
1519 font. These include note heads, accidentals, markup, clefs, time
1520 signatures, dynamics and lyrics. Their size is changed by modifying
1521 the @code{font-size} property, as we shall shortly see. Other layout
1522 objects such as slurs and ties -- in general, spanner objects -- are
1523 drawn individually, so there is no @code{font-size} associated with
1524 them. These objects generally derive their size from the objects to
1525 which they are attached, so usually there is no need to change their
1526 size manually. Still other properties such as the length of stems and
1527 bar lines, thickness of beams and other lines, and the separation of
1528 staff lines all need to be modified in special ways.
1530 Returning to the ossia example, let us first change the font-size.
1531 We can do this in two ways. We can either change the size of the
1532 fonts of each object type, like @code{NoteHead}s with commands
1536 \override NoteHead.font-size = #-2
1539 or we can change the size of all fonts by setting a special
1540 property, @code{fontSize}, using @code{\set}, or by including
1541 it in a @code{\with} clause (but without the @code{\set}).
1547 Both of these statements would cause the font size to be reduced
1548 by 2 steps from its previous value, where each
1549 step reduces or increases the size by approximately 12%.
1551 Let's try it in our ossia example:
1553 @cindex alignAboveContext property, example
1554 @cindex @code{\with}, example
1555 @cindex Clef, example of overriding
1556 @cindex TimeSignature, example of overriding
1557 @cindex fontSize property, example
1559 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1560 \new Staff ="main" {
1567 alignAboveContext = #"main"
1570 % Reduce all font sizes by ~24%
1580 This is still not quite right. The note heads and flags are
1581 smaller, but the stems are too long in proportion and the
1582 staff lines are spaced too widely apart. These need to be
1583 scaled down in proportion to the font reduction. The next
1584 sub-section discusses how this is done.
1586 @node Length and thickness of objects
1587 @subsection Length and thickness of objects
1593 @cindex size, changing
1594 @cindex stem length, changing
1595 @cindex staff line spacing, changing
1597 Distances and lengths in LilyPond are generally measured in
1598 staff-spaces, the distance between adjacent lines in the staff,
1599 (or occasionally half staff spaces) while most @code{thickness}
1600 properties are measured in units of an internal property called
1601 @code{line-thickness.} For example, by default, the lines of
1602 hairpins are given a thickness of 1 unit of @code{line-thickness},
1603 while the @code{thickness} of a note stem is 1.3. Note, though,
1604 that some thickness properties are different; for example, the
1605 thickness of beams is controlled by the value of the
1606 @code{beam-thickness} property, which is measured in staff-spaces.
1608 So how are lengths to be scaled in proportion to the font size?
1609 This can be done with the help of a special function called
1610 @code{magstep} provided for exactly this purpose. It takes
1611 one argument, the change in font size (#-2 in the example above)
1612 and returns a scaling factor suitable for reducing other
1613 objects in proportion. It is used like this:
1615 @cindex alignAboveContext property, example
1616 @cindex @code{\with}, example
1617 @cindex Clef, example of overriding
1618 @cindex TimeSignature, example of overriding
1619 @cindex fontSize property, example
1620 @cindex StaffSymbol, example of overriding
1621 @cindex magstep function, example of using
1622 @cindex staff-space property, example
1623 @cindex stencil property, example
1625 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1626 \new Staff ="main" {
1633 alignAboveContext = #"main"
1637 % Reduce stem length and line spacing to match
1638 \override StaffSymbol.staff-space = #(magstep -2)
1648 Since the length of stems and many other length-related properties are
1649 always calculated relative to the value of the @code{staff-space}
1650 property these are automatically scaled down in length too. Note that
1651 this affects only the vertical scale of the ossia -- the horizontal
1652 scale is determined by the layout of the main music in order to remain
1653 synchronized with it, so it is not affected by any of these changes in
1654 size. Of course, if the scale of all the main music were changed in
1655 this way then the horizontal spacing would be affected. This is
1656 discussed later in the layout section.
1658 This, then, completes the creation of an ossia. The sizes and
1659 lengths of all other objects may be modified in analogous ways.
1661 For small changes in scale, as in the example above, the
1662 thickness of the various drawn lines such as bar lines,
1663 beams, hairpins, slurs, etc does not usually require global
1664 adjustment. If the thickness of any particular layout object
1665 needs to be adjusted this can be best achieved by overriding its
1666 @code{thickness} property. An example of changing the thickness
1667 of slurs was shown above in @ref{Properties of layout objects}.
1668 The thickness of all drawn objects (i.e., those not produced
1669 from a font) may be changed in the same way.
1672 @node Placement of objects
1673 @section Placement of objects
1676 * Automatic behavior::
1677 * Within-staff objects::
1678 * Outside-staff objects::
1682 @node Automatic behavior
1683 @subsection Automatic behavior
1685 @cindex within-staff objects
1686 @cindex outside-staff objects
1687 @cindex objects, within-staff
1688 @cindex objects, outside-staff
1690 There are some objects in musical notation that belong to
1691 the staff and there are other objects that should be
1692 placed outside the staff. These are called within-staff
1693 objects and outside-staff objects respectively.
1695 Within-staff objects are those that are located on the staff
1696 -- note heads, stems, accidentals, etc. The positions of
1697 these are usually fixed by the music itself -- they are
1698 vertically positioned on specific lines of the staff or are
1699 tied to other objects that are so positioned. Collisions of
1700 note heads, stems and accidentals in closely set chords are
1701 normally avoided automatically. There are commands and
1702 overrides which can modify this automatic behavior, as we
1705 Objects belonging outside the staff include things such as
1706 rehearsal marks, text and dynamic markings. LilyPond's rule for
1707 the vertical placement of outside-staff objects is to place them
1708 as close to the staff as possible but not so close that they
1709 collide with any other object. LilyPond uses the
1710 @code{outside-staff-priority} property to determine the order in
1711 which the objects should be placed, as follows.
1713 First, LilyPond places all the within-staff objects.
1714 Then it sorts the outside-staff objects according to their
1715 @code{outside-staff-priority}. The outside-staff objects are
1716 taken one by one, beginning with the object with the lowest
1717 @code{outside-staff-priority}, and placed so that they do not
1718 collide with any objects that have already been placed. That is,
1719 if two outside-staff grobs are competing for the same space, the
1720 one with the lower @code{outside-staff-priority} will be placed
1721 closer to the staff. If two objects have the same
1722 @code{outside-staff-priority} the one encountered first will be
1723 placed closer to the staff.
1725 In the following example all the markup texts have the same
1726 priority (since it is not explicitly set). Note that @q{Text3}
1727 is automatically positioned close to the staff again, nestling
1730 @cindex markup example
1732 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1739 Staves are also positioned, by default, as closely together as
1740 possible (subject to a minimum separation). If notes project
1741 a long way towards an adjacent staff they will force the
1742 staves further apart only if an overlap of the notation
1743 would otherwise occur. The following example demonstrates
1744 this @q{nestling} of the notes on adjacent staves:
1746 @lilypond[quote,ragged-right,verbatim]
1749 \relative c' { c4 a, }
1752 \relative c'''' { c4 a, }
1758 @node Within-staff objects
1759 @subsection Within-staff objects
1761 We have already seen how the commands @code{\voiceXXX} affect the
1762 direction of slurs, ties, fingering and everything else which depends on
1763 the direction of the stems -- see @ref{Explicitly instantiating voices}.
1764 These commands are essential when writing polyphonic music to permit
1765 interweaving melodic lines to be distinguished. But occasionally it may
1766 be necessary to override this automatic behavior. This can be done for
1767 whole sections of music or even for an individual note. The property
1768 which controls this behavior is the @code{direction} property of each
1769 layout object. We first explain what this does, and then introduce a
1770 number of ready-made commands which avoid your having to code explicit
1771 overrides for the more common modifications.
1773 Some layout objects like slurs and ties curve, bend or point
1774 either up or down; others like stems and flags also move to
1775 right or left when they point up or down. This is controlled
1776 automatically when @code{direction} is set.
1779 * The direction property::
1783 @node The direction property
1784 @unnumberedsubsubsec The @code{direction} property
1791 The following example shows in bar 1 the default behavior of stems,
1792 with those on high notes pointing down and those on low notes pointing
1793 up, followed by four notes with all stems forced down, four notes with
1794 all stems forced up, and finally four notes reverted back to the
1797 @cindex Stem, example of overriding
1798 @cindex direction property, example
1800 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1802 \override Stem.direction = #DOWN
1804 \override Stem.direction = #UP
1806 \revert Stem.direction
1810 Here we use the constants @code{DOWN} and @code{UP}.
1811 These have the values @w{@code{-1}} and @code{+1} respectively, and
1812 these numerical values may be used instead. The value @code{0}
1813 may also be used in some cases. It is simply treated as meaning
1814 @code{UP} for stems, but for some objects it means @q{center}.
1815 There is a constant, @code{CENTER} which has the value @code{0}.
1817 However, these explicit overrides are not usually used, as there are
1818 simpler equivalent predefined commands available. Here is a table of
1819 the commonest. The meaning of each is stated where it is not obvious.
1821 @multitable @columnfractions .2 .2 .25 .35
1826 @item @code{\arpeggioArrowDown}
1827 @tab @code{\arpeggioArrowUp}
1828 @tab @code{\arpeggioNormal}
1829 @tab Arrow is at bottom, at top, or no arrow
1830 @item @code{\dotsDown}
1832 @tab @code{\dotsNeutral}
1833 @tab Direction of movement to avoid staff lines
1834 @item @code{\dynamicDown}
1835 @tab @code{\dynamicUp}
1836 @tab @code{\dynamicNeutral}
1838 @item @code{\phrasingSlurDown}
1839 @tab @code{\phrasingSlurUp}
1840 @tab @code{\phrasingSlurNeutral}
1841 @tab Note: distinct from slur commands
1842 @item @code{\slurDown}
1844 @tab @code{\slurNeutral}
1846 @item @code{\stemDown}
1848 @tab @code{\stemNeutral}
1850 @item @code{\textSpannerDown}
1851 @tab @code{\textSpannerUp}
1852 @tab @code{\textSpannerNeutral}
1853 @tab Text entered as spanner is below/above staff
1854 @item @code{\tieDown}
1856 @tab @code{\tieNeutral}
1858 @item @code{\tupletDown}
1859 @tab @code{\tupletUp}
1860 @tab @code{\tupletNeutral}
1861 @tab Tuplets are below/above notes
1864 The neutral/normal variants of these commands are implemented
1865 using @code{\revert} and may @strong{not} be
1866 preceded by @code{\once}. If you wish to limit the
1867 effect of the other commands (which are implemented using
1868 @code{\override}) to a single timestep, you can precede them with
1869 @code{\once} like you would do with explicit overrides.
1872 @unnumberedsubsubsec Fingering
1874 @cindex fingering, placement
1875 @cindex fingering, chords
1877 The placement of fingering on single notes can also be controlled
1878 by the @code{direction} property, but changing @code{direction}
1879 has no effect on chords. As we shall see, there are special
1880 commands which allow the fingering of individual notes
1881 of chords to be controlled, with the fingering being placed
1882 above, below, to the left or to the right of each note.
1884 First, here's the effect of @code{direction} on the fingering
1885 attached to single notes. The first bar shows the default
1886 behaviour, and the following two bars shows the effect of
1887 specifying @code{DOWN} and @code{UP}:
1889 @cindex Fingering, example of overriding
1890 @cindex direction property, example
1892 @lilypond[quote,verbatim,relative=2]
1894 \override Fingering.direction = #DOWN
1896 \override Fingering.direction = #UP
1900 However, overriding the @code{direction} property is not the
1901 easiest way of manually setting the fingering above or below
1902 the notes; using @code{_} or @code{^} instead of @code{-} before
1903 the fingering number is usually preferable. Here is the previous
1904 example using this method:
1906 @cindex fingering example
1908 @lilypond[quote,verbatim,relative=2]
1914 The @code{direction} property is ignored for chords, but the
1915 directional prefixes, @code{_} and @code{^} do work. By default,
1916 the fingering is automatically placed both above and below the
1917 notes of a chord, as shown:
1919 @cindex fingering example
1921 @lilypond[quote,verbatim,relative=2]
1928 but this may be overridden to manually force all or any of the
1929 individual fingering numbers above or below:
1931 @cindex fingering example
1933 @lilypond[quote,verbatim,relative=2]
1939 Even greater control over the placement of fingering of the
1940 individual notes in a chord is possible by using the
1941 @code{\set fingeringOrientations} command. The format of this
1945 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
1949 @code{\set} is used because @code{fingeringOrientations} is a
1950 property of the @code{Voice} context, created and used by the
1951 @code{New_fingering_engraver}.
1953 The property may be set to a list of one to three values.
1954 It controls whether fingerings may be placed above (if
1955 @code{up} appears in the list), below (if @code{down} appears),
1956 to the left (if @code{left} appears, or to the right
1957 (if @code{right} appears). Conversely, if a location is not
1958 listed, no fingering is placed there. LilyPond takes these
1959 constraints and works out the best placement for the fingering
1960 of the notes of the following chords. Note that @code{left} and
1961 @code{right} are mutually exclusive -- fingering may be placed
1962 only on one side or the other, not both.
1964 @warning{To control the placement of the fingering of a single
1965 note using this command it is necessary to write it as a single
1966 note chord by placing angle brackets round it.}
1968 Here are a few examples:
1970 @cindex fingering example
1971 @cindex @code{\set}, example of using
1972 @cindex fingeringOrientations property, example
1974 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1975 \set fingeringOrientations = #'(left)
1978 \set fingeringOrientations = #'(left)
1980 <c-1 e-2 g-3 b-5>4 |
1981 \set fingeringOrientations = #'(up left down)
1984 \set fingeringOrientations = #'(up left)
1986 <c-1 e-2 g-3 b-5>4 |
1987 \set fingeringOrientations = #'(right)
1993 If the fingering seems a little crowded the @code{font-size}
1994 could be reduced. The default value can be seen from the
1995 @code{Fingering} object in the IR to be @w{@code{-5}}, so let's
1998 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1999 \override Fingering.font-size = #-7
2000 \set fingeringOrientations = #'(left)
2003 \set fingeringOrientations = #'(left)
2005 <c-1 e-2 g-3 b-5>4 |
2006 \set fingeringOrientations = #'(up left down)
2009 \set fingeringOrientations = #'(up left)
2011 <c-1 e-2 g-3 b-5>4 |
2012 \set fingeringOrientations = #'(right)
2017 @node Outside-staff objects
2018 @subsection Outside-staff objects
2020 Outside-staff objects are automatically placed to avoid collisions.
2021 There are several ways to override the automatic placement if the
2022 positioning is not optimum.
2025 * The outside-staff-priority property::
2026 * The \textLengthOn command::
2027 * Dynamics placement::
2032 @node The outside-staff-priority property
2033 @unnumberedsubsubsec The @code{outside-staff-priority} property
2035 Objects with the lower value of the @code{outside-staff-priority}
2036 property are placed nearer to the staff, and other outside-staff
2037 objects are then raised as far as necessary to avoid collisions.
2038 The @code{outside-staff-priority} is defined in the
2039 @code{grob-interface} and so is a property of all layout objects.
2040 By default it is set to @code{#f} for all within-staff objects,
2041 and to a numerical value appropriate to each outside-staff object
2042 when the object is created. The following table shows the default
2043 numerical values for some of the commonest outside-staff objects.
2047 Note the unusual names for some of the objects: spanner objects
2048 are automatically created to control the vertical positioning of
2049 grobs which (might) start and end at different musical moments, so
2050 changing the @code{outside-staff-priority} of the underlying grob
2051 will have no effect. For example, changing
2052 @code{outside-staff-priority} of the @code{Hairpin} object will
2053 have no effect on the vertical positioning of hairpins -- you must
2054 change @code{outside-staff-priority} of the associated
2055 @code{DynamicLineSpanner} object instead. This override must be
2056 placed at the start of the spanner, which might include several
2057 linked hairpins and dynamics.
2059 @multitable @columnfractions .3 .3 .3
2060 @headitem Layout Object
2062 @tab Controls position of:
2063 @item @code{RehearsalMark}
2065 @tab Rehearsal marks
2066 @item @code{MetronomeMark}
2068 @tab Metronome marks
2069 @item @code{VoltaBracketSpanner}
2072 @item @code{TextScript}
2075 @item @code{MultiMeasureRestText}
2077 @tab Markup text over full-bar rests
2078 @item @code{OttavaBracket}
2080 @tab Ottava brackets
2081 @item @code{TextSpanner}
2084 @item @code{DynamicLineSpanner}
2086 @tab All dynamic markings
2087 @item @code{BarNumber}
2090 @item @code{TrillSpanner}
2092 @tab Spanning trills
2095 Here is an example showing the default placement of some of
2098 @cindex text spanner
2099 @cindex ottava bracket
2101 @funindex \startTextSpan
2102 @funindex startTextSpan
2103 @funindex \stopTextSpan
2104 @funindex stopTextSpan
2106 @cindex TextSpanner, example of overriding
2107 @cindex bound-details property, example
2109 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2110 % Set details for later Text Spanner
2111 \override TextSpanner.bound-details.left.text
2112 = \markup { \small \bold Slower }
2113 % Place dynamics above staff
2115 % Start Ottava Bracket
2118 % Add Dynamic Text and hairpin
2124 % Add Dynamic Text and terminate hairpin
2125 c4\ff c \stopTextSpan |
2126 % Stop Ottava Bracket
2131 This example also shows how to create Text Spanners --
2132 text with extender lines above a section of music. The
2133 spanner extends from the @code{\startTextSpan} command to
2134 the @code{\stopTextSpan} command, and the format of the
2135 text is defined by the @code{\override TextSpanner} command.
2136 For more details see @ruser{Text spanners}.
2138 It also shows how ottava brackets are created.
2140 @cindex tweaking bar number placement
2141 @cindex bar numbers, tweaking placement
2142 @cindex tweaking metronome mark placement
2143 @cindex metronome mark, tweaking placement
2144 @cindex tweaking rehearsal mark placement
2145 @cindex rehearsal marks, tweaking placement
2147 If the default values of @code{outside-staff-priority} do not give you
2148 the placing you want, the priority of any of the objects may be
2149 overridden. Suppose we would like the ottava bracket to be placed
2150 below the text spanner in the example above. All we need to do is to
2151 look up the priority of @code{OttavaBracket} in the IR or in the
2152 tables above, and reduce it to a value lower than that of a
2153 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
2154 in the @code{Staff} context:
2156 @cindex TextSpanner, example of overriding
2157 @cindex bound-details property, example
2159 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2160 % Set details for later Text Spanner
2161 \override TextSpanner.bound-details.left.text
2162 = \markup { \small \bold Slower }
2163 % Place dynamics above staff
2165 % Place following Ottava Bracket below Text Spanners
2166 \once \override Staff.OttavaBracket.outside-staff-priority = #340
2167 % Start Ottava Bracket
2172 % Add Dynamic Line Spanner
2178 c4\ff c \stopTextSpan |
2179 % Stop Ottava Bracket
2184 Note that some of these objects, in particular bar numbers,
2185 metronome marks and rehearsal marks, live by default in the
2186 @code{Score} context, so be sure to use the correct context
2187 when these are being overriden.
2189 @cindex slurs and outside-staff-priority
2190 @cindex slurs and articulations
2191 @cindex articulations and slurs
2193 Slurs by default are classed as within-staff objects, but
2194 they often appear above the staff if the notes to
2195 which they are attached are high on the staff. This can push
2196 outside-staff objects such as articulations too high, as the slur
2197 will be placed first. The @code{avoid-slur} property of the
2198 articulation can be set to @code{'inside} to bring the articulation
2199 inside the slur, but the @code{avoid-slur} property is effective
2200 only if the @code{outside-staff-priority} is also set to @code{#f}.
2201 Alternatively, the @code{outside-staff-priority} of the slur
2202 can be set to a numerical value to cause it to be placed along with
2203 other outside-staff objects according to that value. Here's an
2204 example showing the effect of the two methods:
2206 @lilypond[quote,verbatim,relative=2]
2207 c4( c^\markup { \tiny \sharp } d4.) c8 |
2209 \once \override TextScript.avoid-slur = #'inside
2210 \once \override TextScript.outside-staff-priority = ##f
2211 c4^\markup { \tiny \sharp } d4.) c8 |
2212 \once \override Slur.outside-staff-priority = #500
2213 c4( c^\markup { \tiny \sharp } d4.) c8 |
2216 Changing the @code{outside-staff-priority} can also be used to
2217 control the vertical placement of individual objects, although
2218 the results may not always be desirable. Suppose we would
2219 like @qq{Text3} to be placed above @qq{Text4} in the example
2220 under Automatic behavior, above (see @ref{Automatic behavior}).
2221 All we need to do is to look up the priority of @code{TextScript}
2222 in the IR or in the tables above, and increase the priority of
2223 @qq{Text3} to a higher value:
2225 @cindex TextScript, example of overriding
2226 @cindex outside-staff-priority property, example
2228 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2231 \once \override TextScript.outside-staff-priority = #500
2236 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2237 above @qq{Text2}, and @qq{Text4} now drops down. Perhaps this is not
2238 so good. What we would really like to do is to position all the
2239 annotation at the same distance above the staff. To do this, we
2240 clearly will need to space the notes out horizontally to make more
2241 room for the text. This is done using the @code{textLengthOn}
2244 @node The \textLengthOn command
2245 @unnumberedsubsubsec The @code{\textLengthOn} command
2247 @cindex notes, spreading out with text
2249 @funindex \textLengthOn
2250 @funindex textLengthOn
2251 @funindex \textLengthOff
2252 @funindex textLengthOff
2254 By default, text produced by markup takes up no horizontal space
2255 as far as laying out the music is concerned. The @code{\textLengthOn}
2256 command reverses this behavior, causing the notes to be spaced
2257 out as far as is necessary to accommodate the text:
2259 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2260 \textLengthOn % Cause notes to space out to accommodate text
2267 The command to revert to the default behavior is
2268 @code{\textLengthOff}. Remember @code{\once} only works with
2269 @code{\override}, @code{\set}, @code{\revert} or @code{\unset},
2270 so cannot be used with @code{\textLengthOn}.
2272 @cindex markup text, allowing collisions
2274 Markup text will also avoid notes which project above the staff.
2275 If this is not desired, the automatic displacement upwards may
2276 be turned off by setting the priority to @code{#f}. Here's an
2277 example to show how markup text interacts with such notes.
2279 @cindex TextScript, example of overriding
2280 @cindex outside-staff-priority property, example
2282 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2283 % This markup is short enough to fit without collision
2287 % This is too long to fit, so it is displaced upwards
2291 % Turn off collision avoidance
2292 \once \override TextScript.outside-staff-priority = ##f
2293 c,,2^"Long Text " c'' |
2296 % Turn off collision avoidance
2297 \once \override TextScript.outside-staff-priority = ##f
2298 \textLengthOn % and turn on textLengthOn
2299 c,,2^"Long Text " % Spaces at end are honored
2303 @node Dynamics placement
2304 @unnumberedsubsubsec Dynamics placement
2306 @cindex tweaking dynamics placement
2307 @cindex dynamics, tweaking placement
2309 Dynamic markings will normally be positioned beneath the
2310 staff, but may be positioned above with the @code{\dynamicUp}
2311 command. They will be positioned vertically relative to the
2312 note to which they are attached, and will float below (or above)
2313 all within-staff objects such as phrasing slurs and bar numbers.
2314 This can give quite acceptable results, as this example
2317 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2322 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2323 ees,2.~\)\mf ees4 r8 |
2326 However, if the notes and attached dynamics are close
2327 together the automatic placement will avoid collisions
2328 by displacing later dynamic markings further away, but this may
2329 not be the optimum placement, as this rather artificial example
2332 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2338 Should a similar situation arise in @q{real} music, it may be
2339 preferable to space out the notes a little further, so the dynamic
2340 markings can all fit at the same vertical distance from the staff. We
2341 were able to do this for markup text by using the @code{\textLengthOn}
2342 command, but there is no equivalent command for dynamic marks. So we
2343 shall have to work out how to do this using @code{\override} commands.
2346 @unnumberedsubsubsec Grob sizing
2349 @cindex sizing grobs
2351 First we must learn how grobs are sized. All grobs have a
2352 reference point defined within them which is used to position
2353 them relative to their parent object. This point in the grob
2354 is then positioned at a horizontal distance, @code{X-offset},
2355 and at a vertical distance, @code{Y-offset}, from its parent.
2356 The horizontal extent of the object is given by a pair of
2357 numbers, @code{X-extent}, which say where the left and right
2358 edges are relative to the reference point. The vertical extent
2359 is similarly defined by a pair of numbers, @code{Y-extent}.
2360 These are properties of all grobs which support the
2361 @code{grob-interface}.
2363 @cindex @code{extra-spacing-width}
2365 By default, outside-staff objects are given a width of zero so
2366 that they may overlap in the horizontal direction. This is done
2367 by the trick of adding infinity to the leftmost extent and
2368 minus infinity to the rightmost extent by setting the
2369 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}. So
2370 to ensure they do not overlap in the horizontal direction we
2371 must override this value of @code{extra-spacing-width} to
2372 @code{'(0 . 0)} so the true width shines through. This is
2373 the command to do this for dynamic text:
2376 \override DynamicText.extra-spacing-width = #'(0 . 0)
2380 Let's see if this works in our previous example:
2382 @cindex DynamicText, example of overriding
2383 @cindex extra-spacing-width property, example
2385 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2387 \override DynamicText.extra-spacing-width = #'(0 . 0)
2388 a4\f b\mf c\mp b\p |
2392 Well, it has certainly stopped the dynamic marks being
2393 displaced, but two problems remain. The marks should be
2394 spaced a little further apart and it would be better
2395 if they were all the same distance from the staff.
2396 We can solve the first problem easily. Instead of making
2397 the @code{extra-spacing-width} zero we could add a little
2398 more to it. The units are the space between two staff
2399 lines, so moving the left edge half a unit to the left and the
2400 right edge half a unit to the right should do it:
2402 @cindex DynamicText, example of overriding
2403 @cindex extra-spacing-width property, example
2405 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2407 % Extend width by 1 staff space
2408 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2413 This looks better, but maybe we would prefer the dynamic marks
2414 to be aligned along the same baseline rather than going up and
2415 down with the notes. The property to do this is
2416 @code{staff-padding} which is covered in the following section.
2419 @node Collisions of objects
2420 @section Collisions of objects
2424 * Fixing overlapping notation::
2425 * Real music example::
2428 @node Moving objects
2429 @subsection Moving objects
2431 @cindex moving overlapping objects
2432 @cindex moving colliding objects
2433 @cindex moving colliding grobs
2434 @cindex objects, moving colliding
2435 @cindex grobs, moving colliding
2437 This may come as a surprise, but LilyPond is not perfect. Some
2438 notation elements can overlap. This is unfortunate, but in fact
2439 rather rare. Usually the need to move objects is for clarity or
2440 aesthetic reasons -- they would look better with a little more
2441 or a little less space around them.
2443 There are three main approaches to resolving overlapping
2444 notation. They should be considered in the following order:
2448 The @strong{direction} of one of the overlapping objects may
2449 be changed using the predefined commands listed above for
2450 within-staff objects (see @ref{Within-staff objects}).
2451 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2452 repositioned easily in this way. The limitation is that you
2453 have a choice of only two positions, and neither may be
2457 The @strong{object properties}, which LilyPond uses when positioning
2458 layout objects, may be modified using @code{\override}. The
2459 advantages of making changes to this type of property are (a) that
2460 some other objects will be moved automatically if necessary to make
2461 room and (b) the single override can apply to all instances of the
2462 same type of object. Such properties include:
2469 This has already been covered in some detail -- see
2470 @ref{Within-staff objects}.
2473 @code{padding}, @code{right-padding}, @code{staff-padding}
2476 @cindex padding property
2477 @cindex right-padding property
2478 @cindex staff-padding property
2480 As an object is being positioned the value of its @code{padding}
2481 property specifies the gap that must be left between itself and the
2482 nearest edge of the object against which it is being positioned. Note
2483 that it is the @code{padding} value of the object @strong{being
2484 placed} that is used; the @code{padding} value of the object which is
2485 already placed is ignored. Gaps specified by @code{padding} can be
2486 applied to all objects which support the
2487 @code{side-position-interface}.
2489 Instead of @code{padding}, the placement of groups of accidentals
2490 is controlled by @code{right-padding}. This property is to be found
2491 in the @code{AccidentalPlacement} object which, note, lives in the
2492 @strong{Staff} context. In the typesetting process the note heads
2493 are typeset first and then the accidentals, if any, are added to the
2494 left of the note heads using the @code{right-padding} property to determine
2495 the separation from the note heads and between individual accidentals.
2496 So only the @code{right-padding} property of the @code{AccidentalPlacement}
2497 object has any effect on the placement of the accidentals.
2499 The @code{staff-padding} property is closely related to the
2500 @code{padding} property: @code{padding} controls the minimum amount of
2501 space between any object which supports the
2502 @code{side-position-interface} and the nearest other object (generally
2503 the note or the staff lines); @code{staff-padding} applies only to
2504 those objects which are always set outside the staff -- it controls
2505 the minimum amount of space that should be inserted between that
2506 object and the staff. Note that @code{staff-padding} has no effect on
2507 objects which are positioned relative to the note rather than the
2508 staff, even though it may be overridden without error for such objects
2509 -- it is simply ignored.
2511 To discover which padding property is required for the object you wish
2512 to reposition, you need to return to the IR and look up the object's
2513 properties. Be aware that the padding properties might not be located
2514 in the obvious object, so look in objects that appear to be related.
2516 All padding values are measured in staff spaces. For most
2517 objects, this value is set by default to be around 1.0 or less
2518 (it varies with each object). It may be overridden if a larger
2519 (or smaller) gap is required.
2522 @code{self-alignment-X}
2524 @cindex self-alignment-X property
2526 This property can be used to align the object to the left, to
2527 the right, or to center it with respect to the parent object's
2528 reference point. It may be used with all objects which support
2529 the @code{self-alignment-interface}. In general these are objects
2530 that contain text. The values are @code{LEFT}, @code{RIGHT}
2531 or @code{CENTER}. Alternatively, a numerical value between
2532 @w{@code{-1}} and @code{+1} may be specified, where @w{@code{-1}} is
2533 left-aligned, @code{+1} is right-aligned, and numbers in between
2534 move the text progressively from left-aligned to right-aligned.
2535 Numerical values greater than @code{1} may be specified to move
2536 the text even further to the left, or less than @w{@code{-1}} to
2537 move the text even further to the right. A change of @code{1}
2538 in the value corresponds to a movement of half the text's length.
2541 @code{extra-spacing-width}
2543 @cindex extra-spacing-width property
2545 This property is available for all objects which support the
2546 @code{item-interface}. It takes two numbers, the first is added
2547 to the leftmost extent and the second is added to the rightmost
2548 extent. Negative numbers move the edge to the left, positive to
2549 the right, so to widen an object the first number must be negative,
2550 the second positive. Note that not all objects honor both
2551 numbers. For example, the @code{Accidental} object only takes
2552 notice of the first (left edge) number.
2555 @code{staff-position}
2557 @cindex staff-position property
2559 @code{staff-position} is a property of the
2560 @code{staff-symbol-referencer-interface}, which is supported by
2561 objects which are positioned relative to the staff. It specifies
2562 the vertical position of the object relative to the center line
2563 of the staff in half staff-spaces. It is useful in resolving
2564 collisions between layout objects like multi-measure rests, ties
2565 and notes in different voices.
2570 @cindex force-hshift property
2572 Closely spaced notes in a chord, or notes occurring at the same
2573 time in different voices, are arranged in two, occasionally more,
2574 columns to prevent the note heads overlapping. These are called
2575 note columns, and an object called @code{NoteColumn} is created
2576 to lay out the notes in that column.
2578 The @code{force-hshift} property is a property of a @code{NoteColumn}
2579 (actually of the @code{note-column-interface}). Changing it permits a
2580 note column to be moved in units appropriate to a note column,
2581 viz. the note head width of the first voice note. It should be used
2582 in complex situations where the normal @code{\shiftOn} commands (see
2583 @ref{Explicitly instantiating voices}) do not resolve the note
2584 conflict. It is preferable to the @code{extra-offset} property for
2585 this purpose as there is no need to work out the distance in
2586 staff-spaces, and moving the notes into or out of a @code{NoteColumn}
2587 affects other actions such as merging note heads.
2592 Finally, when all else fails, objects may be manually repositioned
2593 relative to the staff center line vertically, or by displacing them by
2594 any distance to a new position. The disadvantages are that the
2595 correct values for the repositioning have to be worked out, often by
2596 trial and error, for every object individually, and, because the
2597 movement is done after LilyPond has placed all other objects, the user
2598 is responsible for avoiding any collisions that might ensue. But the
2599 main difficulty with this approach is that the repositioning values
2600 may need to be reworked if the music is later modified. The
2601 properties that can be used for this type of manual repositioning are:
2606 @cindex extra-offset property
2608 This property applies to any layout object supporting the
2609 @code{grob-interface}. It takes a pair of numbers which specify the
2610 extra displacement in the horizontal and vertical directions.
2611 Negative numbers move the object to the left or down. The units are
2612 staff-spaces. The extra displacement is made after the typesetting of
2613 objects is finished, so an object may be repositioned anywhere without
2614 affecting anything else.
2618 @cindex positions property
2620 This is most useful for manually adjusting the slope and height
2621 of beams, slurs, and tuplets. It takes a pair of numbers
2622 giving the position of the left and right ends of the beam, slur,
2623 etc. relative to the center line of the staff. Units are
2624 staff-spaces. Note, though, that slurs and phrasing slurs cannot
2625 be repositioned by arbitrarily large amounts. LilyPond first
2626 generates a list of possible positions for the slur and by default
2627 finds the slur that @qq{looks best}. If the @code{positions}
2628 property has been overridden the slur that is closest to the
2629 requested positions is selected from the list.
2634 A particular object may not have all of these properties.
2635 It is necessary to go to the IR to look up which properties
2636 are available for the object in question.
2638 Here is a list of the objects which are most likely to be
2639 involved in collisions, together with the name of the object which
2640 should be looked up in the IR in order to discover which properties
2641 should be used to move them.
2643 @multitable @columnfractions .5 .5
2644 @headitem Object type @tab Object name
2645 @item Articulations @tab @code{Script}
2646 @item Beams @tab @code{Beam}
2647 @item Dynamics (vertically) @tab @code{DynamicLineSpanner}
2648 @item Dynamics (horizontally) @tab @code{DynamicText}
2649 @item Fingerings @tab @code{Fingering}
2650 @item Rehearsal / Text marks @tab @code{RehearsalMark}
2651 @item Slurs @tab @code{Slur}
2652 @item Text e.g. @code{^"text"} @tab @code{TextScript}
2653 @item Ties @tab @code{Tie}
2654 @item Tuplets @tab @code{TupletBracket}
2658 @node Fixing overlapping notation
2659 @subsection Fixing overlapping notation
2661 Let's now see how the properties in the previous section can
2662 help to resolve overlapping notation.
2665 * The padding property::
2666 * The right-padding property::
2667 * The staff-padding property::
2668 * The self-alignment-X property::
2669 * The staff-position property::
2670 * The extra-offset property::
2671 * The positions property::
2672 * The force-hshift property::
2675 @node The padding property
2676 @unnumberedsubsubsec The @code{padding} property
2679 @cindex fixing overlapping notation
2680 @cindex overlapping notation
2682 The @code{padding} property can be set to increase
2683 (or decrease) the distance between symbols that are printed
2684 above or below notes.
2686 @cindex Script, example of overriding
2687 @cindex padding property, example
2689 @lilypond[quote,fragment,relative=1,verbatim]
2691 \override Script.padding = #3
2695 @cindex MetronomeMark, example of overriding
2696 @cindex padding property, example
2698 @lilypond[quote,fragment,relative=1,verbatim]
2699 % This will not work, see below
2700 \override MetronomeMark.padding = #3
2704 \override Score.MetronomeMark.padding = #3
2709 Note in the second example how important it is to figure out what
2710 context handles a certain object. Since the @code{MetronomeMark}
2711 object is handled in the @code{Score} context, property changes in the
2712 @code{Voice} context will not be noticed. For more details, see
2713 @ruser{Modifying properties}.
2715 If the @code{padding} property of an object is increased when that
2716 object is in a stack of objects being positioned according to
2717 their @code{outside-staff-priority}, then that object and all
2718 objects outside it are moved.
2721 @node The right-padding property
2722 @unnumberedsubsubsec The @code{right-padding} property
2724 @cindex right-padding property
2726 The @code{right-padding} property affects the spacing between the
2727 accidental and the note to which it applies. It is not often
2728 required, but the default spacing may be wrong for certain special
2729 accidental glyphs or combination of glyphs used in some microtonal
2730 music. These have to be entered by overriding the accidental
2731 stencil with a markup containing the desired symbol(s), like this:
2733 @cindex Accidental, example of overriding
2734 @cindex text property, example
2735 @cindex stencil property, example
2736 @cindex AccidentalPlacement, example of overriding
2737 @cindex right-padding property, example
2739 @lilypond[quote,ragged-right,verbatim]
2740 sesquisharp = \markup { \sesquisharp }
2743 % This prints a sesquisharp but the spacing is too small
2744 \once \override Accidental.stencil = #ly:text-interface::print
2745 \once \override Accidental.text = #sesquisharp
2747 % This improves the spacing
2748 \once \override Score.AccidentalPlacement.right-padding = #0.6
2749 \once \override Accidental.stencil = #ly:text-interface::print
2750 \once \override Accidental.text = #sesquisharp
2756 This necessarily uses an override for the accidental stencil which
2757 will not be covered until later. The stencil type must be a
2758 procedure, here changed to print the contents of the @code{text}
2759 property of @code{Accidental}, which itself is set to be a
2760 sesquisharp sign. This sign is then moved further away from the
2761 note head by overriding @code{right-padding}.
2765 @node The staff-padding property
2766 @unnumberedsubsubsec The @code{staff-padding} property
2768 @cindex aligning objects on a baseline
2769 @cindex objects, aligning on a baseline
2771 @code{staff-padding} can be used to align objects such as dynamics
2772 along a baseline at a fixed height above the staff, rather than at a
2773 height dependent on the position of the note to which they are
2774 attached. It is not a property of @code{DynamicText} but of
2775 @code{DynamicLineSpanner}. This is because the baseline should apply
2776 equally to @strong{all} dynamics, including those created as extended
2777 spanners. So this is the way to align the dynamic marks in the
2778 example taken from the previous section:
2780 @cindex DynamicText, example of overriding
2781 @cindex extra-spacing-width property, example
2782 @cindex DynamicLineSpanner, example of overriding
2783 @cindex staff-padding property, example
2785 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2787 % Extend width by 1 unit
2788 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2789 % Align dynamics to a base line 2 units above staff
2790 \override DynamicLineSpanner.staff-padding = #2
2795 @node The self-alignment-X property
2796 @unnumberedsubsubsec The @code{self-alignment-X} property
2798 The following example shows how this can resolve the collision
2799 of a string fingering object with a note's stem by aligning the
2800 right edge with the reference point of the parent note:
2802 @cindex StringNumber, example of overriding
2803 @cindex self-alignment-X property, example
2805 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
2808 \once \override StringNumber.self-alignment-X = #RIGHT
2812 @node The staff-position property
2813 @unnumberedsubsubsec The @code{staff-position} property
2815 @cindex object collision within a staff
2817 Multimeasure rests in one voice can collide with notes in another.
2818 Since these rests are typeset centered between the bar lines, it
2819 would require significant effort for LilyPond to figure out which
2820 other notes might collide with it, since all the current collision
2821 handling between notes and between notes and rests is done only
2822 for notes and rests that occur at the same time. Here's an
2823 example of a collision of this type:
2825 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2826 << { c4 c c c } \\ { R1 } >>
2829 The best solution here is to move the multimeasure rest down, since
2830 the rest is in voice two. The default in @code{\voiceTwo} (i.e. in
2831 the second voice of a @code{<<@{...@} \\ @{...@}>>} construct) is that
2832 @code{staff-position} is set to -4 for MultiMeasureRest, so we need to
2833 move it, say, four half-staff spaces down to @w{@code{-8}}.
2835 @cindex MultiMeasureRest, example of overriding
2836 @cindex staff-position property, example
2838 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2842 \override MultiMeasureRest.staff-position = #-8
2847 This is better than using, for example, @code{extra-offset},
2848 because the ledger line above the rest is inserted automatically.
2850 @node The extra-offset property
2851 @unnumberedsubsubsec The @code{extra-offset} property
2853 @cindex positioning objects
2854 @cindex positioning grobs
2855 @cindex objects, positioning
2856 @cindex grobs, positioning
2858 The @code{extra-offset} property provides complete control over the
2859 positioning of an object both horizontally and vertically.
2861 In the following example, the second fingering is moved a little to
2862 the left, and 1.8 staff space downwards:
2864 @cindex Fingering, example of overriding
2865 @cindex extra-offset property, example
2867 @lilypond[quote,fragment,relative=1,verbatim]
2870 \once \override Fingering.extra-offset = #'(-0.3 . -1.8)
2875 @node The positions property
2876 @unnumberedsubsubsec The @code{positions} property
2878 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
2879 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
2880 @cindex tuplet beams, controlling manually
2881 @cindex slurs, controlling manually
2882 @cindex phrasing slurs, controlling manually
2883 @cindex beams, controlling manually
2885 The @code{positions} property allows the vertical position and hence
2886 the slope of tuplets, slurs, phrasing slurs and beams to be controlled
2889 Here's an example in which the phrasing slur and slur collide:
2891 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
2895 @cindex PhrasingSlur, example of overriding
2896 @cindex positions property, example
2899 One possibility would be to move the two ends of the phrasing slur
2900 higher. We can try setting the left end to 2.5 staff-spaces above the
2901 centre line and the right end to 4.5 above, and LilyPond will
2902 select the phrasing slur from the candidates it has found with its
2903 end points closest to these:
2905 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
2906 \once \override PhrasingSlur.positions = #'(2.5 . 4.5)
2910 This is an improvement, but why not lower the right end of the slur
2911 a little? If you try it you'll find it can't be done in this way.
2912 That's because there are no candidate slurs lower than the one
2913 already selected, and in this case the @code{positions} property has
2914 no effect. However, ties, slurs and phrasing slurs @emph{can} be
2915 positioned and shaped very precisely when necessary. To learn how to
2916 do this, see @ruser{Modifying ties and slurs}.
2918 Here's a further example. We see that the beams
2919 collide with the ties:
2921 @lilypond[quote,verbatim,fragment,ragged-right]
2925 { c'1 ~ c'2. e'8 f' }
2927 { e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g'' }
2930 { c'1 ~ c'2. e'8 f' }
2932 { e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g'' }
2938 This can be resolved by manually moving both ends of the beam
2939 up from their position at 1.81 staff-spaces below the center line to,
2942 @cindex Beam, example of overriding
2943 @cindex positions property, example
2945 @lilypond[quote,verbatim,fragment,ragged-right]
2949 { c'1 ~ c'2. e'8 f' }
2952 \override Beam.positions = #'(-1 . -1)
2953 e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g''
2957 { c'1 ~ c'2. e'8 f' }
2959 { e''8 e'' e'' e'' e'' e'' e'' e'' f''2 g'' }
2965 Note that the override continues to apply in the first voice of
2966 the second measure of eighth notes, but not to any of the beams in the
2969 @node The force-hshift property
2970 @unnumberedsubsubsec The @code{force-hshift property}
2972 We can now see how to apply the final corrections to the Chopin
2973 example introduced at the end of @ref{I'm hearing Voices}, which
2974 was left looking like this:
2976 @lilypond[quote,verbatim,fragment,ragged-right]
2977 \new Staff \relative c'' {
2992 The inner note of the first chord (i.e. the A-flat in the fourth
2993 Voice) need not be shifted away from the note column of the higher
2994 note. To correct this we set @code{force-hshift}, which is a property
2995 of @code{NoteColumn}, of this note to zero.
2997 In the second chord we prefer the F to line up with the A-flat and the
2998 lowest note to be positioned slightly right to avoid a collision of
2999 stems. We achieve this by setting @code{force-hshift} in the
3000 @code{NoteColumn} of the low D-flat to move it to the right by half
3003 Here's the final result:
3005 @cindex NoteColumn, example of overriding
3006 @cindex force-hshift property, example
3008 @lilypond[quote,verbatim,fragment,ragged-right]
3009 \new Staff \relative c'' {
3016 \once \override NoteColumn.force-hshift = #0.5
3022 \override NoteColumn.force-hshift = #0
3031 @node Real music example
3032 @subsection Real music example
3034 We end this section on Tweaks by showing the steps to be taken to
3035 deal with a tricky example which needs several tweaks to produce
3036 the desired output. The example has been deliberately chosen to
3037 illustrate the use of the Notation Reference to resolve unusual
3038 problems with notation. It is not representative of the more usual
3039 engraving process, so please do not let these difficulties put
3040 you off! Fortunately, difficulties like these are not very common!
3042 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
3043 9, the transition from the opening Lento to Moderato.
3044 Here, first, is what we want the output to look like, but to avoid
3045 over-complicating the example too much we have left out the
3046 dynamics, fingering and pedalling.
3048 @c The following should appear as music without code
3049 @c This example should not be indexed
3050 @c line-width ensures no break
3051 @lilypond[quote,ragged-right,line-width=6\in]
3052 rhMusic = \relative c'' {
3055 \once \override Tie.staff-position = #3.5
3059 \mergeDifferentlyHeadedOn
3060 \mergeDifferentlyDottedOn
3061 bes2.^\markup { \bold "Moderato" } r8
3067 % Reposition the c2 to the right of the merged note
3068 \once \override NoteColumn.force-hshift = #1.0
3069 % Move the c2 out of the main note column
3070 % so the merge will work
3077 % Stem on the d2 must be down to permit merging
3079 % Stem on the d2 should be invisible
3080 \tweak Stem.transparent ##t
3081 \tweak Flag.transparent ##t
3089 \mergeDifferentlyHeadedOff
3090 \mergeDifferentlyDottedOff
3095 lhMusic = \relative c' {
3097 <d g, d>1)\arpeggio |
3104 \new Staff = "RH" <<
3108 \new Staff = "LH" <<
3117 We note first that the right hand part in the third bar
3118 requires four voices. These are the five beamed eighth notes,
3119 the tied C, the half-note D which is merged with the eighth note
3120 D, and the dotted quarter note F-sharp, which is also merged with
3121 the eighth note at the same pitch. Everything else is in a single
3122 voice, so the easiest way is to introduce these extra three voices
3123 temporarily at the time they are needed. If you have forgotten
3124 how to do this, look at @ref{I'm hearing Voices} and @ref{Explicitly
3125 instantiating voices}. Here we choose to use explicitly instantiated
3126 voices for the polyphonic passage, as LilyPond is better able to
3127 avoid collisions if all voices are instantiated explicitly in this
3130 So let us begin by entering the notes as two variables, setting up
3131 the staff structure in a score block, and seeing what LilyPond
3132 produces by default:
3134 @c line-width ensures no break
3135 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3136 rhMusic = \relative c'' {
3142 % Start polyphonic section of four voices
3144 { c,8 d fis bes a } % continuation of main voice
3158 g2. % continuation of main voice
3162 lhMusic = \relative c' {
3171 \new Staff = "RH" <<
3175 \new Staff = "LH" <<
3184 All the notes are right, but the appearance is far from
3185 satisfactory. The tie collides with the change in time signature,
3186 some notes are not merged together, and several notation elements
3187 are missing. Let's first deal with the easier things. We can
3188 easily add the left hand slur and the right hand phrasing slur,
3189 since these were all covered in the Tutorial. Doing this gives:
3191 @c line-width ensures no break
3192 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3193 rhMusic = \relative c'' {
3199 % Start polyphonic section of four voices
3201 { c,8 d fis bes a } % continuation of main voice
3215 g2.\) % continuation of main voice
3219 lhMusic = \relative c' {
3228 \new Staff = "RH" <<
3232 \new Staff = "LH" <<
3241 The first bar is now correct. The second bar contains an arpeggio and
3242 is terminated by a double bar line. How do we do these, as they have
3243 not been mentioned in this Learning Manual? This is where we need to
3244 turn to the Notation Reference. Looking up @q{arpeggio} and @q{bar
3245 line} in the index quickly shows us that an arpeggio is produced by
3246 appending @code{\arpeggio} to a chord, and a double bar line is
3247 produced by the @code{\bar "||"} command. That's easily done. We
3248 next need to correct the collision of the tie with the time signature.
3249 This is best done by moving the tie upwards. Moving objects was
3250 covered earlier in @ref{Moving objects}, which says that objects
3251 positioned relative to the staff can be moved vertically by overriding
3252 their @code{staff-position} property, which is specified in half staff
3253 spaces relative to the center line of the staff. So the following
3254 override placed just before the first tied note would move the tie up
3255 to 3.5 half staff spaces above the center line:
3257 @code{\once \override Tie.staff-position = #3.5}
3259 This completes bar two, giving:
3261 @c line-width ensures no break
3262 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3263 rhMusic = \relative c'' {
3266 \once \override Tie.staff-position = #3.5
3271 % Start polyphonic section of four voices
3273 { c,8 d fis bes a } % continuation of main voice
3287 g2.\) % continuation of main voice
3291 lhMusic = \relative c' {
3293 <d g, d>1)\arpeggio |
3300 \new Staff = "RH" <<
3304 \new Staff = "LH" <<
3313 On to bar three and the start of the Moderato section. The tutorial
3314 showed how to add bold text with the @code{\markup} command, so
3315 adding @qq{Moderato} in bold is easy. But how do we merge notes in
3316 different voices together? This is where we need to turn again to
3317 the Notation Reference for help. A search for @qq{merge} in the
3318 Notation Reference index quickly leads us to the commands for merging
3319 differently headed and differently dotted notes in
3320 @ruser{Collision resolution}. In our example we need to merge both
3321 types of note for the duration of the polyphonic section in bar 3,
3322 so using the information we find in the Notation Reference we add
3325 \mergeDifferentlyHeadedOn
3326 \mergeDifferentlyDottedOn
3330 to the start of that section and
3333 \mergeDifferentlyHeadedOff
3334 \mergeDifferentlyDottedOff
3340 @c line-width ensures no break
3341 @lilypond[quote,ragged-right,line-width=6\in]
3342 rhMusic = \relative c'' {
3345 \once \override Tie.staff-position = #3.5
3349 bes2.^\markup { \bold "Moderato" } r8
3350 \mergeDifferentlyHeadedOn
3351 \mergeDifferentlyDottedOn
3352 % Start polyphonic section of four voices
3354 { c,8 d fis bes a } % continuation of main voice
3368 \mergeDifferentlyHeadedOff
3369 \mergeDifferentlyDottedOff
3370 g2.\) % continuation of main voice
3374 lhMusic = \relative c' {
3376 <d g, d>1)\arpeggio |
3383 \new Staff = "RH" <<
3387 \new Staff = "LH" <<
3396 These overrides have merged the two F-sharp notes, but not the two
3397 on D. Why not? The answer is there in the same section in the
3398 Notation Reference -- notes being merged must have stems in
3399 opposite directions and two notes cannot be merged successfully if
3400 there is a third note in the same note column. Here the two D's
3401 both have upward stems and there is a third note -- the C. We know
3402 how to change the stem direction using @code{\stemDown}, and
3403 the Notation Reference also says how to move the C -- apply a shift
3404 using one of the @code{\shift} commands. But which one?
3405 The C is in voice two which has shift off, and the two D's are in
3406 voices one and three, which have shift off and shift on,
3407 respectively. So we have to shift the C a further level still
3408 using @code{\shiftOnn} to avoid it interfering with the two D's.
3409 Applying these changes gives:
3411 @cindex Tie, example of overriding
3412 @cindex staff-position property, example
3414 @c line-width ensures no break
3415 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3416 rhMusic = \relative c'' {
3419 \once \override Tie.staff-position = #3.5
3423 bes2.^\markup { \bold "Moderato" } r8
3424 \mergeDifferentlyHeadedOn
3425 \mergeDifferentlyDottedOn
3426 % Start polyphonic section of four voices
3428 { c,8 d fis bes a } % continuation of main voice
3431 % Move the c2 out of the main note column
3432 % so the merge will work
3437 % Stem on the d2 must be down to permit merging
3445 \mergeDifferentlyHeadedOff
3446 \mergeDifferentlyDottedOff
3447 g2.\) % continuation of main voice
3451 lhMusic = \relative c' {
3453 <d g, d>1)\arpeggio |
3460 \new Staff = "RH" <<
3464 \new Staff = "LH" <<
3473 Nearly there. Only two problems remain: The downward stem on the
3474 merged D should not be there, and the C would be better positioned
3475 to the right of the D's. We know how to do both of these from the
3476 earlier tweaks: we make the stem transparent, and move the C with
3477 the @code{force-hshift} property. Here's the final result:
3479 @cindex NoteColumn, example of overriding
3480 @cindex force-hshift property, example
3481 @cindex Stem, example of overriding
3482 @cindex transparent property, example
3484 @c line-width ensures no break
3485 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3486 rhMusic = \relative c'' {
3489 \once \override Tie.staff-position = #3.5
3493 bes2.^\markup { \bold "Moderato" } r8
3494 \mergeDifferentlyHeadedOn
3495 \mergeDifferentlyDottedOn
3496 % Start polyphonic section of four voices
3498 { c,8 d fis bes a } % continuation of main voice
3502 % Reposition the c2 to the right of the merged note
3503 \once \override NoteColumn.force-hshift = #1.0
3504 % Move the c2 out of the main note column
3505 % so the merge will work
3512 % Stem on the d2 must be down to permit merging
3514 % Stem on the d2 should be invisible
3515 \tweak Stem.transparent ##t
3516 \tweak Flag.transparent ##t
3524 \mergeDifferentlyHeadedOff
3525 \mergeDifferentlyDottedOff
3526 g2.\) % continuation of main voice
3530 lhMusic = \relative c' {
3532 <d g, d>1)\arpeggio |
3539 \new Staff = "RH" <<
3543 \new Staff = "LH" <<
3553 @node Further tweaking
3554 @section Further tweaking
3557 * Other uses for tweaks::
3558 * Using variables for tweaks::
3560 * Other sources of information::
3561 * Advanced tweaks with Scheme::
3564 @node Other uses for tweaks
3565 @subsection Other uses for tweaks
3568 * Tying notes across voices::
3569 * Simulating a fermata in MIDI::
3572 @cindex transparent property, use of
3573 @cindex objects, making invisible
3574 @cindex removing objects
3575 @cindex objects, removing
3576 @cindex hiding objects
3577 @cindex objects, hiding
3578 @cindex invisible objects
3579 @cindex objects, invisible
3581 @node Tying notes across voices
3582 @unnumberedsubsubsec Tying notes across voices
3584 @cindex tying notes across voices
3586 The following example demonstrates how to connect notes in
3587 different voices using ties. Normally, only two notes in the
3588 same voice can be connected with ties. By using two voices,
3589 with the tied notes in one of them
3591 @lilypond[quote,fragment,relative=2]
3592 << { b8~ b\noBeam } \\ { b8[ g] } >>
3596 and blanking the first up-stem in that voice, the tie appears to
3599 @cindex Stem, example of overriding
3600 @cindex transparent property, example
3602 @lilypond[quote,fragment,relative=2,verbatim]
3605 \tweak Stem.transparent ##t
3606 \tweak Flag.transparent ##t
3614 To make sure that the just-blanked stem doesn't squeeze the tie
3615 too much, we can lengthen the stem by setting the
3616 @code{length} to @code{8},
3618 @lilypond[quote,fragment,relative=2,verbatim]
3621 \tweak Stem.transparent ##t
3622 \tweak Flag.transparent ##t
3623 \tweak Stem.length #8
3632 @cindex tweak, generated from override
3633 Now for @emph{overriding} the transparency of a graphical object,
3634 we could have used the shorthand @code{\hide} as explained above.
3635 Tweaking is a different operation, affecting only properties
3636 generated from a single music expression. It turns out that we
3637 can convert overrides into tweaks using @code{\single}, making it
3638 possible to rewrite the above example as
3640 @lilypond[quote,fragment,relative=2,verbatim]
3645 \tweak Stem.length #8
3653 In this particular case, the difference to @code{\once \hide} is
3654 not apparent. It is important when there are several objects at
3655 the same point in musical time (like noteheads in a chord). In
3656 that case, @code{\once} will affect all of those objects while
3657 @code{\single} will only affect a single one, the one generated by
3658 the immediately following music expression.
3660 @node Simulating a fermata in MIDI
3661 @unnumberedsubsubsec Simulating a fermata in MIDI
3663 @cindex stencil property, use of
3664 @cindex fermata, implementing in MIDI
3666 For outside-staff objects it is usually better to override the
3667 object's @code{stencil} property rather than its @code{transparent}
3668 property when you wish to remove it from the printed output.
3669 Setting the @code{stencil} property of an object to @code{#f} will
3670 remove that object entirely from the printed output. This means it
3671 has no effect on the placement of other objects placed relative to
3674 For example, if we wished to change the metronome setting in order
3675 to simulate a fermata in the MIDI output we would not want the
3676 metronome markings to appear in the printed output, and we would
3677 not want it to influence the spacing between the two systems or
3678 the positions of adjacent annotations on the staff. So setting
3679 its @code{stencil} property to @code{#f} would be the best way.
3680 We show here the effect of the two methods:
3682 @cindex MetronomeMark, example of overriding
3683 @cindex transparent property, example
3685 @lilypond[quote,verbatim,ragged-right]
3688 % Visible tempo marking
3691 \once \hide Score.MetronomeMark
3692 % Invisible tempo marking to lengthen fermata in MIDI
3695 % New tempo for next section
3704 @cindex MetronomeMark, example of overriding
3705 @cindex stencil property, example
3707 @lilypond[quote,verbatim,ragged-right]
3710 % Visible tempo marking
3713 \once \omit Score.MetronomeMark
3714 % Invisible tempo marking to lengthen fermata in MIDI
3717 % New tempo for next section
3727 Both methods remove the metronome mark which lengthens the fermata
3728 from the printed output, and both affect the MIDI timing as
3729 required, but the transparent metronome mark in the first line
3730 forces the following tempo indication too high while the
3731 second (with the stencil removed) does not.
3737 @node Using variables for tweaks
3738 @subsection Using variables for tweaks
3740 @cindex variables, using for tweaks
3741 @cindex using variables for tweaks
3742 @cindex tweaks, using variables for
3744 Override commands are often long and tedious to type, and they
3745 have to be absolutely correct. If the same overrides are to be
3746 used many times it may be worth defining variables to hold them.
3748 Suppose we wish to emphasize certain words in lyrics by printing
3749 them in bold italics. The @code{\italic} and @code{\bold}
3750 commands only work within lyrics if they are embedded, together with
3751 the word or words to be modified, within a @code{\markup} block,
3752 which makes them tedious to enter. The need to embed the words
3753 themselves prevents their use in simple variables. As an
3754 alternative can we use @code{\override} and @code{\revert} commands?
3757 @code{\override Lyrics.LyricText.font-shape = #'italic}
3758 @code{\override Lyrics.LyricText.font-series = #'bold}
3760 @code{\revert Lyrics.LyricText.font-shape}
3761 @code{\revert Lyrics.LyricText.font-series}
3764 These would also be extremely tedious to enter if there were many
3765 words requiring emphasis. But we @emph{can} define these as two
3766 variables and use those to bracket the words to be emphasized.
3767 Another advantage of using variables for these overrides is that
3768 the spaces around the dot are not necessary, since they are not
3769 being interpreted in @code{\lyricmode} directly. Here's an example
3770 of this, although in practice we would choose shorter names
3771 for the variables to make them quicker to type:
3773 @cindex LyricText, example of overriding
3774 @cindex font-shape property, example
3775 @cindex font-series property, example
3777 @lilypond[quote,verbatim]
3779 \override Lyrics.LyricText.font-shape = #'italic
3780 \override Lyrics.LyricText.font-series = #'bold
3784 \revert Lyrics.LyricText.font-shape
3785 \revert Lyrics.LyricText.font-series
3788 global = { \key c \major \time 4/4 \partial 4 }
3790 SopranoMusic = \relative c' { c4 | e4. e8 g4 g | a4 a g }
3791 AltoMusic = \relative c' { c4 | c4. c8 e4 e | f4 f e }
3792 TenorMusic = \relative c { e4 | g4. g8 c4. b8 | a8 b c d e4 }
3793 BassMusic = \relative c { c4 | c4. c8 c4 c | f8 g a b c4 }
3795 VerseOne = \lyrics {
3796 E -- | ter -- nal \emphasize Fa -- ther, | \normal strong to save,
3799 VerseTwo = \lyricmode {
3800 O | \once \emphasize Christ, whose voice the | wa -- ters heard,
3803 VerseThree = \lyricmode {
3804 O | \emphasize Ho -- ly Spi -- rit, | \normal who didst brood
3807 VerseFour = \lyricmode {
3808 O | \emphasize Tri -- ni -- ty \normal of | love and pow'r
3815 \new Voice = "Soprano" { \voiceOne \global \SopranoMusic }
3816 \new Voice = "Alto" { \voiceTwo \AltoMusic }
3817 \new Lyrics \lyricsto "Soprano" { \VerseOne }
3818 \new Lyrics \lyricsto "Soprano" { \VerseTwo }
3819 \new Lyrics \lyricsto "Soprano" { \VerseThree }
3820 \new Lyrics \lyricsto "Soprano" { \VerseFour }
3824 \new Voice = "Tenor" { \voiceOne \TenorMusic }
3825 \new Voice = "Bass" { \voiceTwo \BassMusic }
3833 @subsection Style sheets
3835 The output that LilyPond produces can be heavily modified; see
3836 @ref{Tweaking output}, for details. But what if you have many
3837 input files that you want to apply your tweaks to? Or what if you
3838 simply want to separate your tweaks from the actual music? This
3839 is quite easy to do.
3841 Let's look at an example. Don't worry if you don't understand
3842 the parts with all the @code{#()}. This is explained in
3843 @ref{Advanced tweaks with Scheme}.
3845 @lilypond[quote,verbatim,ragged-right]
3847 #(make-dynamic-script
3848 #{ \markup { \hspace #0
3849 \translate #'(5 . 0)
3850 \line { \dynamic "mp"
3851 \text \italic "dolce" } }
3855 #(define-music-function
3856 (parser location string)
3858 #{ <>^\markup \bold \box #string #})
3862 a4.\mpdolce d8 cis4--\glissando a |
3866 g8(\! fis)-. e( d)-. cis2 |
3870 Let's do something about the @code{mpdolce} and @code{inst} definitions.
3871 They produce the output we desire, but we might want to use them in
3872 another piece. We could simply copy-and-paste them at the top of every
3873 file, but that's an annoyance. It also leaves those definitions in our
3874 input files, and I personally find all the @code{#()} somewhat ugly.
3875 Let's hide them in another file:
3878 %%% save this to a file called "definitions.ily"
3880 #(make-dynamic-script
3881 #@{ \markup @{ \hspace #0
3882 \translate #'(5 . 0)
3883 \line @{ \dynamic "mp"
3884 \text \italic "dolce" @} @}
3888 #(define-music-function
3889 (parser location string)
3891 #@{ <>^\markup \bold \box #string #@})
3894 We will refer to this file using the @code{\include} command near
3895 the top of the music file. (The extension @file{.ily} is used to
3896 distinguish this included file, which is not meant to be compiled
3897 on its own, from the main file.)
3898 Now let's modify our music (let's save this file as @file{music.ly}).
3900 @c We have to do this awkward example/lilypond-non-verbatim
3901 @c because we can't do the \include stuff in the manual.
3904 \include "definitions.ily"
3908 a4.\mpdolce d8 cis4--\glissando a |
3912 g8(\! fis)-. e( d)-. cis2 |
3916 @lilypond[quote,ragged-right]
3918 #(make-dynamic-script
3919 #{ \markup { \hspace #0
3920 \translate #'(5 . 0)
3921 \line { \dynamic "mp"
3922 \text \italic "dolce" } }
3926 #(define-music-function
3927 (parser location string)
3929 #{ <>^\markup \bold \box #string #})
3933 a4.\mpdolce d8 cis4--\glissando a |
3937 g8(\! fis)-. e( d)-. cis2 |
3941 That looks better, but let's make a few changes. The glissando is hard
3942 to see, so let's make it thicker and closer to the note heads. Let's
3943 put the metronome marking above the clef, instead of over the first
3944 note. And finally, my composition professor hates @q{C} time signatures,
3945 so we'd better make that @q{4/4} instead.
3947 Don't change @file{music.ly}, though. Replace our @file{definitions.ily}
3953 #(make-dynamic-script
3954 #@{ \markup @{ \hspace #0
3955 \translate #'(5 . 0)
3956 \line @{ \dynamic "mp"
3957 \text \italic "dolce" @} @}
3961 #(define-music-function
3962 (parser location string)
3964 #@{ <>^\markup \bold \box #string #@})
3969 \override MetronomeMark.extra-offset = #'(-9 . 0)
3970 \override MetronomeMark.padding = #'3
3974 \override TimeSignature.style = #'numbered
3978 \override Glissando.thickness = #3
3979 \override Glissando.gap = #0.1
3984 @lilypond[quote,ragged-right]
3986 #(make-dynamic-script
3987 #{ \markup { \hspace #0
3988 \translate #'(5 . 0)
3989 \line { \dynamic "mp"
3990 \text \italic "dolce" } }
3994 #(define-music-function
3995 (parser location string)
3997 #{ <>^\markup \bold \box #string #})
4002 \override MetronomeMark.extra-offset = #'(-9 . 0)
4003 \override MetronomeMark.padding = #'3
4007 \override TimeSignature.style = #'numbered
4011 \override Glissando.thickness = #3
4012 \override Glissando.gap = #0.1
4018 a4.\mpdolce d8 cis4--\glissando a |
4022 g8(\! fis)-. e( d)-. cis2 |
4026 That looks nicer! But now suppose that I want to publish this
4027 piece. My composition professor doesn't like @q{C} time
4028 signatures, but I'm somewhat fond of them. Let's copy the
4029 current @file{definitions.ily} to @file{web-publish.ily} and
4030 modify that. Since this music is aimed at producing a pdf which
4031 will be displayed on the screen, we'll also increase the
4032 overall size of the output.
4037 #(make-dynamic-script
4038 #@{ \markup @{ \hspace #0
4039 \translate #'(5 . 0)
4040 \line @{ \dynamic "mp"
4041 \text \italic "dolce" @} @}
4045 #(define-music-function
4046 (parser location string)
4048 #@{ <>^\markup \bold \box #string #@})
4050 #(set-global-staff-size 23)
4055 \override MetronomeMark.extra-offset = #'(-9 . 0)
4056 \override MetronomeMark.padding = #'3
4063 \override Glissando.thickness = #3
4064 \override Glissando.gap = #0.1
4069 @lilypond[quote,ragged-right]
4071 #(make-dynamic-script
4072 #{ \markup { \hspace #0
4073 \translate #'(5 . 0)
4074 \line { \dynamic "mp"
4075 \text \italic "dolce" } }
4079 #(define-music-function
4080 (parser location string)
4082 #{ <>^\markup \bold \box #string #})
4084 #(set-global-staff-size 23)
4088 \override MetronomeMark.extra-offset = #'(-9 . 0)
4089 \override MetronomeMark.padding = #'3
4092 \override Glissando.thickness = #3
4093 \override Glissando.gap = #0.1
4099 a4.\mpdolce d8 cis4--\glissando a |
4103 g8(\! fis)-. e( d)-. cis2 |
4107 Now in our music, I simply replace
4108 @code{\include "definitions.ily"} with
4109 @code{\include "web-publish.ily"}. Of course, we could make this
4110 even more convenient. We could make a @file{definitions.ily} file which
4111 contains only the definitions of @code{mpdolce} and @code{inst}, a
4112 @file{web-publish.ily} file which contains only the @code{\layout}
4113 section listed above, and a @file{university.ily} file which
4114 contains only the tweaks to produce the output that my professor
4115 prefers. The top of @file{music.ly} would then look like this:
4118 \include "definitions.ily"
4120 %%% Only uncomment one of these two lines!
4121 \include "web-publish.ily"
4122 %\include "university.ily"
4125 This approach can be useful even if you are only producing
4126 one set of parts. I use half a dozen different
4127 @q{style sheet} files for my projects. I begin every music
4128 file with @code{\include "../global.ily"}, which contains
4132 \version @w{"@version{}"}
4134 #(ly:set-option 'point-and-click #f)
4136 \include "../init/init-defs.ly"
4137 \include "../init/init-layout.ly"
4138 \include "../init/init-headers.ly"
4139 \include "../init/init-paper.ly"
4143 @node Other sources of information
4144 @subsection Other sources of information
4146 The Internals Reference documentation contains a lot of information
4147 about LilyPond, but even more information can be gathered by
4148 looking at the internal LilyPond files. To explore these, you must
4149 first find the directory appropriate to your system. The location
4150 of this directory depends (a) on whether you obtained LilyPond
4151 by downloading a precompiled binary from lilypond.org
4152 or whether you installed it from a package manager (i.e.
4153 distributed with GNU/Linux, or installed under fink or cygwin) or
4154 compiled it from source, and (b) on which operating system it is
4157 @subsubsubheading Downloaded from lilypond.org
4164 @file{@var{INSTALLDIR}/lilypond/usr/@/share/lilypond/current/}
4171 @file{@var{INSTALLDIR}/LilyPond.app/Contents/@/Resources/share/lilypond/current/}
4174 by either @code{cd}-ing into this directory from the
4175 Terminal, or control-clicking on the LilyPond application and
4176 selecting @q{Show Package Contents}.
4180 Using Windows Explorer, navigate to
4182 @file{@var{INSTALLDIR}/LilyPond/usr/@/share/lilypond/current/}
4187 @subsubsubheading Installed from a package manager or compiled from source
4190 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
4191 @var{PREFIX} is set by your package manager or @code{configure}
4192 script, and @var{X.Y.Z} is the LilyPond version number.
4196 Within this directory the two interesting subdirectories are
4199 @item @file{ly/} - contains files in LilyPond format
4200 @item @file{scm/} - contains files in Scheme format
4203 Let's begin by looking at some files in @file{ly/}.
4204 Open @file{ly/property-init.ly} in a text editor. The one
4205 you normally use for @code{.ly} files will be fine. This file
4206 contains the definitions of all the standard LilyPond predefined
4207 commands, such as @code{\stemUp} and @code{\slurDotted}. You will
4208 see that these are nothing more than definitions of variables
4209 containing one or a group of @code{\override} commands. For
4210 example, @code{/tieDotted} is defined to be:
4214 \override Tie.dash-period = #0.75
4215 \override Tie.dash-fraction = #0.1
4219 If you do not like the default values these predefined commands can
4220 be redefined easily, just like any other variable, at the
4221 head of your input file.
4223 The following are the most useful files to be found in
4226 @multitable @columnfractions .4 .6
4229 @item @file{ly/engraver-init.ly}
4230 @tab Definitions of engraver Contexts
4231 @item @file{ly/paper-defaults-init.ly}
4232 @tab Specifications of paper-related defaults
4233 @item @file{ly/performer-init.ly}
4234 @tab Definitions of performer Contexts
4235 @item @file{ly/property-init.ly}
4236 @tab Definitions of all common predefined commands
4237 @item @file{ly/spanner-init.ly}
4238 @tab Definitions of spanner-related predefined commands
4241 Other settings (such as the definitions of markup commands) are
4242 stored as @file{.scm} (Scheme) files. The Scheme programming
4243 language is used to provide a programmable interface into
4244 LilyPond internal operation. Further explanation of these files
4245 is currently outside the scope of this manual, as a knowledge of
4246 the Scheme language is required. Users should be warned that
4247 a substantial amount of technical knowledge or time is required
4248 to understand Scheme and these files (see @rextend{Scheme tutorial}).
4250 If you have this knowledge, the Scheme files which may be of
4253 @multitable @columnfractions .4 .6
4256 @item @file{scm/auto-beam.scm}
4257 @tab Sub-beaming defaults
4258 @item @file{scm/define-grobs.scm}
4259 @tab Default settings for grob properties
4260 @item @file{scm/define-markup-commands.scm}
4261 @tab Specify all markup commands
4262 @item @file{scm/midi.scm}
4263 @tab Default settings for MIDI output
4264 @item @file{scm/output-lib.scm}
4265 @tab Settings that affect appearance of frets, colors,
4266 accidentals, bar lines, etc
4267 @item @file{scm/parser-clef.scm}
4268 @tab Definitions of supported clefs
4269 @item @file{scm/script.scm}
4270 @tab Default settings for articulations
4274 @node Advanced tweaks with Scheme
4275 @subsection Advanced tweaks with Scheme
4277 Although many things are possible with the @code{\override} and
4278 @code{\tweak} commands, an even more powerful way of modifying
4279 the action of LilyPond is available through a programmable
4280 interface to the LilyPond internal operation. Code written in
4281 the Scheme programming language can be incorporated directly in
4282 the internal operation of LilyPond. Of course, at least a basic
4283 knowledge of programming in Scheme is required to do this, and an
4284 introduction is provided in the @rextend{Scheme tutorial}.
4286 As an illustration of one of the many possibilities, instead of
4287 setting a property to a constant it can be set to a Scheme
4288 procedure which is then called whenever that property is accessed
4289 by LilyPond. The property can then be set dynamically to a value
4290 determined by the procedure at the time it is called. In this
4291 example we color the note head in accordance with its position on
4294 @cindex x11-color function, example of using
4295 @cindex NoteHead, example of overriding
4296 @cindex color property, setting to Scheme procedure
4298 @lilypond[quote,verbatim,ragged-right]
4299 #(define (color-notehead grob)
4300 "Color the notehead according to its position on the staff."
4301 (let ((mod-position (modulo (ly:grob-property grob 'staff-position)
4304 ;; Return rainbow colors
4305 ((1) (x11-color 'red )) ; for C
4306 ((2) (x11-color 'orange )) ; for D
4307 ((3) (x11-color 'yellow )) ; for E
4308 ((4) (x11-color 'green )) ; for F
4309 ((5) (x11-color 'blue )) ; for G
4310 ((6) (x11-color 'purple )) ; for A
4311 ((0) (x11-color 'violet )) ; for B
4315 % Arrange to obtain color from color-notehead procedure
4316 \override NoteHead.color = #color-notehead
4317 a2 b | c2 d | e2 f | g2 a |
4321 Further examples showing the use of these programmable interfaces
4322 can be found in @rextend{Callback functions}.