1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond-learning.tely
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. See TRANSLATION for details.
13 @chapter Tweaking output
15 This chapter discusses how to modify output. LilyPond is extremely
16 configurable; virtually every fragment of output may be changed.
21 * The Internals Reference manual::
22 * Appearance of objects::
23 * Placement of objects::
24 * Collisions of objects::
29 @section Tweaking basics
32 * Introduction to tweaks::
33 * Objects and interfaces::
34 * Naming conventions of objects and properties::
38 @node Introduction to tweaks
39 @subsection Introduction to tweaks
41 @q{Tweaking} is a LilyPond term for the various methods available
42 to the user for modifying the actions taken during interpretation
43 of the input file and modifying the appearance of the printed
44 output. Some tweaks are very easy to use; others are more
45 complex. But taken together the methods available for tweaking
46 permit almost any desired appearance of the printed music to be
49 In this section we cover the basic concepts required to understand
50 tweaking. Later we give a variety of ready-made commands which can
51 simply be copied to obtain the same effect in your own scores, and
52 at the same time we show how these commands may be constructed so
53 that you may learn how to develop your own tweaks.
55 Before starting on this Chapter you may wish to review the section
56 @ref{Contexts and engravers}, as Contexts, Engravers, and the
57 Properties contained within them are fundamental to understanding
58 and constructing Tweaks.
60 @node Objects and interfaces
61 @subsection Objects and interfaces
67 @cindex properties, object
68 @cindex object properties
70 @cindex object, layout
73 Tweaking involves modifying the internal operation and structures
74 of the LilyPond program, so we must first introduce some terms
75 which are used to describe those internal operations and
78 The term @q{Object} is a generic term used to refer to the
79 multitude of internal structures built by LilyPond during the
80 processing of an input file. So when a command like @code{\new
81 Staff} is encountered a new object of type @code{Staff} is
82 constructed. That @code{Staff} object then holds all the
83 properties associated with that particular staff, for example, its
84 name and its key signature, together with details of the engravers
85 which have been assigned to operate within that staff's context.
86 Similarly, there are objects to hold the properties of all other
87 contexts, such as @code{Voice} objects, @code{Score} objects,
88 @code{Lyrics} objects, as well as objects to represent all
89 notational elements such as bar lines,
90 note heads, ties, dynamics, etc. Every object has its own set of
93 Some types of object are given special names. Objects which represent
94 items of notation on the printed output such as note heads, stems,
95 slurs, ties, fingering, clefs, etc are called @q{Layout objects},
96 often known as @q{Graphical Objects}, or @q{Grobs} for short. These
97 are still objects in the generic sense above, and so they too all have
98 properties associated with them, such as their position, size, color,
101 Some layout objects are still more specialized. Phrasing slurs,
102 crescendo hairpins, ottava marks, and many other grobs are not
103 localized in a single place -- they have a starting point, an
104 ending point, and maybe other properties concerned with their
105 shape. Objects with an extended shape like these are called
108 It remains to explain what @q{Interfaces} are. Many objects, even
109 though they are quite different, share common features which need to
110 be processed in the same way. For example, all grobs have a color, a
111 size, a position, etc, and all these properties are processed in the
112 same way during LilyPond's interpretation of the input file. To
113 simplify these internal operations these common actions and properties
114 are grouped together in an object called a @code{grob-interface}.
115 There are many other groupings of common properties like this, each
116 one given a name ending in @code{interface}. In total there are over
117 100 such interfaces. We shall see later why this is of interest and
120 These, then, are the main terms relating to objects which we
121 shall use in this chapter.
123 @node Naming conventions of objects and properties
124 @subsection Naming conventions of objects and properties
126 @cindex naming conventions for objects
127 @cindex naming conventions for properties
128 @cindex objects, naming conventions
129 @cindex properties, naming conventions
131 We met some object naming conventions previously, in
132 @ref{Contexts and engravers}. Here for reference is a list
133 of the most common object and property types together with
134 the conventions for naming them and a couple of examples of
135 some real names. We have used @q{A} to stand for any capitalized
136 alphabetic character and @q{aaa} to stand for any number of
137 lower-case alphabetic characters. Other characters are used
140 @multitable @columnfractions .33 .33 .33
141 @headitem Object/property type
142 @tab Naming convention
145 @tab Aaaa or AaaaAaaaAaaa
146 @tab Staff, GrandStaff
148 @tab Aaaa or AaaaAaaaAaaa
151 @tab Aaaa_aaa_engraver
152 @tab Clef_engraver, Note_heads_engraver
154 @tab aaa-aaa-interface
155 @tab grob-interface, break-aligned-interface
156 @item Context Properties
157 @tab aaa or aaaAaaaAaaa
158 @tab alignAboveContext, skipBars
159 @item Layout Object Properties
160 @tab aaa or aaa-aaa-aaa
161 @tab direction, beam-thickness
164 As we shall see shortly, the properties of different types of
165 object are modified by different commands, so it is useful to
166 be able to recognize the type of object from the names of its
170 @node Tweaking methods
171 @subsection Tweaking methods
173 @cindex tweaking methods
175 @strong{\override command}
177 @cindex override command
178 @cindex override syntax
183 We have already met the commands @code{\set} and @code{\with}, used to
184 change the properties of @strong{contexts} and to remove and add
185 @strong{engravers}, in @ref{Modifying context properties}, and
186 @ref{Adding and removing engravers}. We now must meet some more
189 The command to change the properties of @strong{layout objects} is
190 @code{\override}. Because this command has to modify
191 internal properties deep within LilyPond its syntax is not
192 as simple as the commands you have met so far. It needs to
193 know precisely which property of which object in which context
194 has to be modified, and what its new value is to be. Let's see
197 The general syntax of this command is:
200 \override @var{Context}.@var{LayoutObject} #'@var{layout-property} =
205 This will set the property with the name @var{layout-property} of the
206 layout object with the name @var{LayoutObject}, which is a member of
207 the @var{Context} context, to the value @var{value}.
209 The @var{Context} can be omitted (and usually is) when the
210 required context is unambiguously implied and is one of lowest
211 level contexts, i.e., @code{Voice}, @code{ChordNames} or
212 @code{Lyrics}, and we shall omit it in many of the following
213 examples. We shall see later when it must be specified.
215 Later sections deal comprehensively with properties and their
216 values, but to illustrate the format and use of these commands
217 we shall use just a few simple properties and values which are
220 For now, don't worry about the @code{#'}, which must precede the
221 layout property, and the @code{#}, which must precede the value.
222 These must always be present in exactly this form. This is the
223 most common command used in tweaking, and most of the rest of
224 this chapter will be directed to presenting examples of how it is
225 used. Here is a simple example to change the color of the
228 @cindex color property, example
229 @cindex NoteHead, example of overriding
231 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
233 \override NoteHead #'color = #red
235 \override NoteHead #'color = #green
239 @strong{\revert command}
241 @cindex revert command
246 Once overridden, the property retains its new value until it is
247 overridden again or a @code{\revert} command is encountered.
248 The @code{\revert} command has the following syntax and causes
249 the value of the property to revert to its original default
250 value; note, not its previous value if several @code{\override}
251 commands have been issued.
254 \revert @var{Context}.@var{LayoutObject} #'@var{layout-property}
257 Again, just like @var{Context} in the @code{\override} command,
258 @var{Context} is often not needed. It will be omitted
259 in many of the following examples. Here we revert the color
260 of the note head to the default value for the final two notes:
262 @cindex color property, example
263 @cindex NoteHead, example of overriding
265 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
267 \override NoteHead #'color = #red
269 \override NoteHead #'color = #green
271 \revert NoteHead #'color
275 @strong{\once prefix}
280 Both the @code{\override} and the @code{\set} commands may be
281 prefixed by @code{\once}. This causes the following
282 @code{\override} or @code{\set} command to be effective only
283 during the current musical moment before the property reverts
284 back to its default value. Using the same example, we can
285 change the color of a single note like this:
287 @cindex color property, example
288 @cindex NoteHead, example of overriding
290 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
292 \once \override NoteHead #'color = #red
294 \once \override NoteHead #'color = #green
298 @strong{\overrideProperty command}
300 @cindex overrideProperty command
302 @funindex \overrideProperty
303 @funindex overrideProperty
305 There is another form of the override command,
306 @code{\overrideProperty}, which is occasionally required.
307 We mention it here for completeness, but for details see
308 @ruser{Difficult tweaks}.
309 @c Maybe explain in a later iteration -td
311 @strong{\tweak command}
313 @cindex tweak command
318 The final tweaking command which is available is @code{\tweak}.
319 This should be used to change the properties of objects which
320 occur at the same musical moment, such as the notes within a
321 chord. Using @code{\override} would affect all the notes
322 within a chord, whereas @code{\tweak} affects just the following
323 item in the input stream.
325 Here's an example. Suppose we wish to change the size of the
326 middle note head (the E) in a C major chord. Let's first see what
327 @code{\once \override} would do:
329 @cindex font-size property, example
330 @cindex NoteHead, example of overriding
332 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
334 \once \override NoteHead #'font-size = #-3
339 We see the override affects @emph{all} the note heads in the chord.
340 This is because all the notes of a chord occur at the same
341 @emph{musical moment}, and the action of @code{\once} is to
342 apply the override to all layout objects of the type specified
343 which occur at the same musical moment as the @code{\override}
346 The @code{\tweak} command operates in a different way. It acts
347 on the immediately following item in the input stream. However,
348 it is effective only on objects which are created directly from
349 the input stream, essentially note heads and articulations;
350 objects such as stems and accidentals are created later and
351 cannot be tweaked in this way. Furthermore, when it is applied
352 to note heads these @emph{must} be within a chord, i.e., within
353 single angle brackets, so to tweak a single note the @code{\tweak}
354 command must be placed inside single angle brackets with the
357 So to return to our example, the size of the middle note of
358 a chord would be changed in this way:
360 @cindex font-size property, example
361 @cindex @code{\tweak}, example
363 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
365 <c \tweak #'font-size #-3 e g>4
368 Note that the syntax of @code{\tweak} is different from that
369 of the @code{\override} command. Neither the context nor the
370 layout object should be specified; in fact, it would generate
371 an error to do so. These are both implied by the following
372 item in the input stream. So the general syntax of the
373 @code{\tweak} command is simply
376 \tweak #'@var{layout-property} = #@var{value}
379 A @code{\tweak} command can also be used to modify just one in
380 a series of articulations, as shown here:
382 @cindex color property, example
383 @cindex @code{\tweak}, example
385 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
387 -\tweak #'color #red ^Red
388 -\tweak #'color #green _Green
392 Note that the @code{\tweak} command must be preceded by an
393 articulation mark as if it were an articulation itself.
395 @cindex tuplets, nested
396 @cindex triplets, nested
397 @cindex bracket, tuplet
398 @cindex bracket, triplet
399 @cindex tuplet bracket
400 @cindex triplet bracket
402 @funindex TupletBracket
404 The @code{\tweak} command must also be used to change the
405 appearance of one of a set of nested tuplets which begin at the
406 same musical moment. In the following example, the long tuplet
407 bracket and the first of the three short brackets begin at the
408 same musical moment, so any @code{\override} command would apply
409 to both of them. In the example, @code{\tweak} is used to
410 distinguish between them. The first @code{\tweak} command
411 specifies that the long tuplet bracket is to be placed above the
412 notes and the second one specifies that the tuplet number is to be
413 printed in red on the first short tuplet bracket.
415 @cindex @code{\tweak}, example
416 @cindex direction property, example
417 @cindex color property, example
419 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
420 \tweak #'direction #up
423 \times 2/3 { c8[ c8 c8] }
424 \times 2/3 { c8[ c8 c8] }
425 \times 2/3 { c8[ c8 c8] }
429 If nested tuplets do not begin at the same moment, their
430 appearance may be modified in the usual way with
431 @code{\override} commands:
433 @cindex text property, example
434 @cindex tuplet-number function, example
435 @cindex transparent property, example
436 @cindex TupletNumber, example of overriding
438 @c NOTE Tuplet brackets collide if notes are high on staff
440 @lilypond[quote,ragged-right,verbatim,fragment,relative=1]
441 \times 2/3 { c8[ c c]}
442 \once \override TupletNumber
443 #'text = #tuplet-number::calc-fraction-text
447 \once \override TupletNumber #'transparent = ##t
448 \times 2/3 { c8[ c c] }
449 \times 2/3 { c8[ c c]}
456 @ruser{The tweak command}.
459 @node The Internals Reference manual
460 @section The Internals Reference manual
462 @cindex Internals Reference
465 * Properties of layout objects::
466 * Properties found in interfaces::
467 * Types of properties::
470 @node Properties of layout objects
471 @subsection Properties of layout objects
473 @cindex properties of layout objects
474 @cindex properties of grobs
475 @cindex grobs, properties of
476 @cindex layout objects, properties of
477 @cindex Internals Reference manual
479 Suppose you have a slur in a score which, to your mind,
480 appears too thin and you'd like to draw it a little heavier.
481 How do you go about doing this? You know from the statements
482 earlier about the flexibility of LilyPond that such a thing
483 should be possible, and you would probably guess that an
484 @code{\override} command would be needed. But is there a
485 heaviness property for a slur, and if there is, how might it
486 be modified? This is where the Internals Reference manual
487 comes in. It contains all the information you might need to
488 construct this and all other @code{\override} commands.
490 Before we look at the Internals Reference a word of warning.
491 This is a @strong{reference} document, which means there is
492 little or no explanation contained within it: its purpose is
493 to present information precisely and concisely. This
494 means it might look daunting at first sight. Don't worry!
495 The guidance and explanation presented here will enable you
496 to extract the information from the Internals Reference for
497 yourself with just a little practice.
499 @cindex override example
500 @cindex Internals Reference, example of using
501 @cindex @code{\addlyrics} example
503 Let's use a concrete example with a simple fragment of real
506 @lilypond[quote,verbatim,relative=2]
511 g[( e]) e d[( f]) a |
515 The man who feels love's sweet e -- mo -- tion
520 Suppose now that we decide we would like the slurs to be a
521 little heavier. Is this possible? The slur is certainly a
522 layout object, so the question is, @q{Is there a property
523 belonging to a slur which controls the heaviness?} To answer
524 this we must look in the Internals Reference, or IR for short.
526 The IR for the version of LilyPond you are using may be found
527 on the LilyPond website at @uref{http://lilypond.org}. Go to the
528 documentation page and click on the Internals Reference link.
529 For learning purposes you should use the standard HTML version,
530 not the @q{one big page} or the PDF. For the next few
531 paragraphs to make sense you will need to actually do this
534 Under the heading @strong{Top} you will see five links. Select
535 the link to the @emph{Backend}, which is where information about
536 layout objects is to be found. There, under the heading
537 @strong{Backend}, select the link to @emph{All layout objects}.
538 The page that appears lists all the layout objects used in your
539 version of LilyPond, in alphabetic order. Select the link to
540 Slur, and the properties of Slurs are listed.
542 An alternative way of finding this page is from the Notation
543 Reference. On one of the pages that deals with slurs you may find a
544 link to the Internals Reference. This link will take you directly to
545 this page, but if you have an idea about the name of the layout object
546 to be tweaked, it is easier to go straight to the IR and search there.
548 This Slur page in the IR tells us first that Slur objects are created
549 by the Slur_engraver. Then it lists the standard settings. Note
550 these are @strong{not} in alphabetic order. Browse down them looking
551 for a property that might control the heaviness of slurs, and you
555 @code{thickness} (number)
557 Line thickness, generally measured in @code{line-thickness}
560 This looks a good bet to change the heaviness. It tells us that
561 the value of @code{thickness} is a simple @emph{number},
562 that the default value is 1.2, and that the units are
563 in another property called @code{line-thickness}.
565 As we said earlier, there are few to no explanations in the IR,
566 but we already have enough information to try changing the
567 slur thickness. We see that the name of the layout object
568 is @code{Slur}, that the name of the property to change is
569 @code{thickness} and that the new value should be a number
570 somewhat larger than 1.2 if we are to make slurs thicker.
572 We can now construct the @code{\override} command by simply
573 substituting the values we have found for the names, omitting
574 the context. Let's use a very large value for the thickness
575 at first, so we can be sure the command is working. We get:
578 \override Slur #'thickness = #5.0
581 Don't forget the @code{#'} preceding the
582 property name and a @code{#} preceding the new value!
584 The final question is, @q{Where should this command be
585 placed?} While you are unsure and learning, the best
586 answer is, @q{Within the music, before the first slur and
587 close to it.} Let's do that:
589 @cindex Slur example of overriding
590 @cindex thickness property, example
592 @lilypond[quote,verbatim,relative=2]
596 % Increase thickness of all following slurs from 1.2 to 5.0
597 \override Slur #'thickness = #5.0
599 g[( e]) e d[( f]) a |
603 The man who feels love's sweet e -- mo -- tion
609 and we see that the slur is indeed heavier.
611 So this is the basic way of constructing @code{\override}
612 commands. There are a few more complications that we
613 shall meet in later sections, but you now know all the
614 essentials required to make up your own -- but you will
615 still need some practice. This is provided in the examples
618 @subheading Finding the context
620 @cindex context, finding
621 @cindex context, identifying correct
623 But first, what if we had needed to specify the Context?
624 What should it be? We could guess that slurs are in
625 the Voice context, as they are clearly closely associated
626 with individual lines of music, but can we be sure? To
627 find out, go back to the top of the IR page describing the
628 Slur, where it says @q{Slur objects are created by: Slur
629 engraver}. So slurs will be created in whichever context
630 the @code{Slur_engraver} is in. Follow the link to the
631 @code{Slur_engraver} page. At the very bottom it tells
632 us that @code{Slur_engraver} is part of five Voice contexts,
633 including the standard voice context, @code{Voice}, so our
634 guess was correct. And because @code{Voice} is one of the
635 lowest level contexts which is implied unambiguously by
636 the fact that we are entering notes, we can omit it in this
639 @subheading Overriding once only
641 @cindex overriding once only
642 @cindex once override
647 As you can see, @emph{all} the slurs are thicker in the final example
648 above. But what if we wanted just the first slur to be thicker? This
649 is achieved with the @code{\once} command. Placed immediately before
650 the @code{\override} command it causes it to change only the slur
651 which begins on the @strong{immediately following} note. If the
652 immediately following note does not begin a slur the command has no
653 effect at all -- it is not remembered until a slur is encountered, it
654 is simply discarded. So the command with @code{\once} must be
655 repositioned as follows:
657 @cindex Slur, example of overriding
658 @cindex thickness property, example
660 @lilypond[quote,verbatim,relative=2]
665 % Increase thickness of immediately following slur only
666 \once \override Slur #'thickness = #5.0
668 g[( e]) e d[( f]) a |
672 The man who feels love's sweet e -- mo -- tion
678 Now only the first slur is made heavier.
680 The @code{\once} command can also be used before the @code{\set}
683 @subheading Reverting
686 @cindex default properties, reverting to
691 Finally, what if we wanted just the first two slurs to be
692 heavier? Well, we could use two commands, each preceded by
693 @code{\once} placed immediately before each of the notes where
696 @cindex Slur, example of overriding
697 @cindex thickness property, example
699 @lilypond[quote,verbatim,relative=2]
704 % Increase thickness of immediately following slur only
705 \once \override Slur #'thickness = #5.0
707 % Increase thickness of immediately following slur only
708 \once \override Slur #'thickness = #5.0
709 g[( e]) e d[( f]) a |
713 The man who feels love's sweet e -- mo -- tion
719 or we could omit the @code{\once} command and use the @code{\revert}
720 command to return the @code{thickness} property to its default value
721 after the second slur:
723 @cindex Slur, example of overriding
724 @cindex thickness property, example
726 @lilypond[quote,verbatim,relative=2]
731 % Increase thickness of all following slurs from 1.2 to 5.0
732 \override Slur #'thickness = #5.0
735 % Revert thickness of all following slurs to default of 1.2
736 \revert Slur #'thickness
741 The man who feels love's sweet e -- mo -- tion
747 The @code{\revert} command can be used to return any property
748 changed with @code{\override} back to its default value.
749 You may use whichever method best suits what you want to do.
751 That concludes our introduction to the IR, and the basic
752 method of tweaking. Several examples follow in the later
753 sections of this Chapter, partly to introduce you to some of the
754 additional features of the IR, and partly to give you more
755 practice in extracting information from it. These examples will
756 contain progressively fewer words of guidance and explanation.
759 @node Properties found in interfaces
760 @subsection Properties found in interfaces
763 @cindex interface properties
764 @cindex properties in interfaces
766 Suppose now that we wish to print the lyrics in italics. What form of
767 @code{\override} command do we need to do this? We first look in the
768 IR page listing @q{All layout objects}, as before, and look for an
769 object that might control lyrics. We find @code{LyricText}, which
770 looks right. Clicking on this shows the settable properties for lyric
771 text. These include the @code{font-series} and @code{font-size}, but
772 nothing that might give an italic shape. This is because the shape
773 property is one that is common to all font objects, so, rather than
774 including it in every layout object, it is grouped together with other
775 similar common properties and placed in an @strong{Interface}, the
776 @code{font-interface}.
778 So now we need to learn how to find the properties of interfaces,
779 and to discover what objects use these interface properties.
781 Look again at the IR page which describes LyricText. At the bottom of
782 the page is a list of clickable interfaces which LyricText supports.
783 The list has several items, including @code{font-interface}. Clicking
784 on this brings up the properties associated with this interface, which
785 are also properties of all the objects which support it, including
788 Now we see all the user-settable properties which control fonts,
789 including @code{font-shape(symbol)}, where @code{symbol} can be
790 set to @code{upright}, @code{italics} or @code{caps}.
792 You will notice that @code{font-series} and @code{font-size} are also
793 listed there. This immediately raises the question: Why are the
794 common font properties @code{font-series} and @code{font-size} listed
795 under @code{LyricText} as well as under the interface
796 @code{font-interface} but @code{font-shape} is not? The answer is
797 that @code{font-series} and @code{font-size} are changed from their
798 global default values when a @code{LyricText} object is created, but
799 @code{font-shape} is not. The entries in @code{LyricText} then tell
800 you the values for those two properties which apply to
801 @code{LyricText}. Other objects which support @code{font-interface}
802 will set these properties differently when they are created.
804 Let's see if we can now construct the @code{\override} command
805 to change the lyrics to italics. The object is @code{LyricText},
806 the property is @code{font-shape} and the value is
807 @code{italic}. As before, we'll omit the context.
809 As an aside, although it is an important one, note that because the
810 values of @code{font-shape} are symbols they must be introduced with a
811 single apostrophe, @code{'}. That is why apostrophes are needed
812 before @code{thickness} in the earlier example and @code{font-shape}.
813 These are both symbols too. Symbols are then read internally by
814 LilyPond. Some of them are the names of properties, like
815 @code{thickness} or @code{font-shape}, others are used as values that
816 can be given to properties, like @code{italic}. Note the distinction
817 from arbitrary text strings, which would appear as @code{"a text
818 string"}; for more details about symbols and strings, see @ref{Scheme
821 Ok, so the @code{\override} command we need to print the lyrics
825 \override LyricText #'font-shape = #'italic
829 and this should be placed just in front of and close to the
830 lyrics which it should affect, like this:
832 @cindex font-shape property, example
833 @cindex italic, example
834 @cindex LyricText, example of overriding
835 @cindex @code{\addlyrics}, example
837 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
842 g[( e]) e d[( f]) a |
846 \override LyricText #'font-shape = #'italic
847 The man who feels love's sweet e -- mo -- tion
853 and the lyrics are all printed in italics.
855 @subheading Specifying the context in lyric mode
857 @cindex context, specifying in lyric mode
858 @cindex lyric mode, specifying context
860 In the case of lyrics, if you try specifying the context in the
861 format given earlier the command will fail. A syllable
862 entered in lyricmode is terminated by either a space,
863 a newline or a digit. All other characters are included
864 as part of the syllable. For this reason a space or newline
865 must appear before the terminating @code{@}} to prevent it being
866 included as part of the final syllable. Similarly,
867 spaces must be inserted before and after the
868 period or dot, @q{.}, separating the context name from the
869 object name, as otherwise the two names are run together and
870 the interpreter cannot recognize them. So the command should be:
873 \override Lyrics . LyricText #'font-shape = #'italic
876 @warning{In lyrics always leave whitespace between the final
877 syllable and the terminating brace.}
879 @warning{In overrides in lyrics always place spaces around
880 the dot between the context name and the object name.}
884 Learning Manual: @ref{Scheme tutorial}.
887 @node Types of properties
888 @subsection Types of properties
890 @cindex property types
892 So far we have seen two types of property: @code{number} and
893 @code{symbol}. To be valid, the value given to a property
894 must be of the correct type and obey the rules for that type.
895 The type of property is always shown in brackets after the
896 property name in the IR. Here is a list of the types you may
897 need, together with the rules for that type, and some examples.
898 You must always add a hash symbol, @code{#}, of course,
899 to the front of these values when they are entered in the
900 @code{\override} command.
902 @multitable @columnfractions .2 .45 .35
903 @headitem Property type
907 @tab Either True or False, represented by #t or #f
908 @tab @code{#t}, @code{#f}
909 @item Dimension (in staff space)
910 @tab A positive decimal number (in units of staff space)
911 @tab @code{2.5}, @code{0.34}
913 @tab A valid direction constant or its numerical equivalent (decimal
914 values between -1 and 1 are allowed)
915 @tab @code{LEFT}, @code{CENTER}, @code{UP},
918 @tab A positive whole number
919 @tab @code{3}, @code{1}
921 @tab A set of values separated by spaces, enclosed in parentheses
922 and preceded by an apostrophe
923 @tab @code{'(left-edge staff-bar)}, @code{'(1)},
924 @code{'(1.0 0.25 0.5)}
926 @tab Any valid markup
927 @tab @code{\markup @{ \italic "cresc." @}}
929 @tab A fraction of a whole note constructed with the
931 @tab @code{(ly:make-moment 1 4)},
932 @code{(ly:make-moment 3 8)}
934 @tab Any positive or negative decimal value
935 @tab @code{3.5}, @code{-2.45}
936 @item Pair (of numbers)
937 @tab Two numbers separated by a @q{space . space} and enclosed
938 in brackets preceded by an apostrophe
939 @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
941 @tab Any of the set of permitted symbols for that property,
942 preceded by an apostrophe
943 @tab @code{'italic}, @code{'inside}
945 @tab A procedure, or @code{#f} to cause no action
946 @tab @code{bend::print}, @code{ly:text-interface::print},
949 @tab A list of three items enclosed in parentheses and preceded
950 by apostrophe-hash, @code{'#}.
951 @tab @code{'#(#t #t #f)}
956 Learning Manual: @ref{Scheme tutorial}.
959 @node Appearance of objects
960 @section Appearance of objects
962 Let us now put what we have learned into practice with a few
963 examples which show how tweaks may be used to change the
964 appearance of the printed music.
967 * Visibility and color of objects::
969 * Length and thickness of objects::
972 @node Visibility and color of objects
973 @subsection Visibility and color of objects
975 In the educational use of music we might wish to print a score
976 with certain elements omitted as an exercise for the student,
977 who is required to supply them. As a simple example,
978 let us suppose the exercise is to supply the missing bar lines
979 in a piece of music. But the bar lines are normally inserted
980 automatically. How do we prevent them printing?
982 Before we tackle this, let us remember that object properties are
983 grouped in what are called @emph{interfaces} -- see @ref{Properties
984 found in interfaces}. This is simply to group together those
985 properties that may be used together to tweak a graphical object -- if
986 one of them is allowed for an object, so are the others. Some objects
987 then use the properties in some interfaces, others use them from other
988 interfaces. The interfaces which contain the properties used by a
989 particular grob are listed in the IR at the bottom of the page
990 describing that grob, and those properties may be viewed by looking at
993 We explained how to find information about grobs in @ref{Properties of
994 layout objects}. Using the same approach, we go to the IR to find the
995 layout object which prints bar lines. Going via @emph{Backend} and
996 @emph{All layout objects} we find there is a layout object called
997 @code{BarLine}. Its properties include two that control its
998 visibility: @code{break-visibility} and @code{stencil}. Barline also
999 supports a number of interfaces, including the @code{grob-interface},
1000 where we find the @code{transparent} and the @code{color} properties.
1001 All of these can affect the visibility of bar lines (and, of course,
1002 by extension, many other layout objects too.) Let's consider each of
1007 @cindex stencil property
1009 This property controls the appearance of the bar lines by specifying
1010 the symbol (glyph) which should be printed. In common
1011 with many other properties, it can be set to print nothing by
1012 setting its value to @code{#f}. Let's try it, as before, omitting
1013 the implied Context, @code{Voice}:
1015 @cindex BarLine, example of overriding
1016 @cindex stencil property, example
1018 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1021 \override BarLine #'stencil = ##f
1023 g, a16 b8 c d4 e16 |
1028 The bar lines are still printed. What is wrong? Go back to the IR
1029 and look again at the page giving the properties of BarLine. At the
1030 top of the page it says @qq{Barline objects are created by:
1031 Bar_engraver}. Go to the @code{Bar_engraver} page. At the bottom it
1032 gives a list of Contexts in which the bar engraver operates. All of
1033 them are of the type @code{Staff}, so the reason the @code{\override}
1034 command failed to work as expected is because @code{Barline} is not in
1035 the default @code{Voice} context. If the context is specified
1036 wrongly, the command simply does not work. No error message is
1037 produced, and nothing is logged in the log file. Let's try correcting
1038 it by adding the correct context:
1040 @cindex BarLine, example of overriding
1041 @cindex stencil property, example
1043 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1046 \override Staff.BarLine #'stencil = ##f
1048 g, a16 b8 c d4 e16 |
1053 Now the bar lines have vanished.
1055 @subheading break-visibility
1057 @cindex break-visibility property
1059 We see from the @code{BarLine} properties in the IR that the
1060 @code{break-visibility} property requires a vector of three booleans.
1061 These control respectively whether bar lines are printed at the end of
1062 a line, in the middle of lines, and at the beginning of lines. For
1063 our example we want all bar lines to be suppressed, so the value we
1064 need is @code{'#(#f #f #f)}. Let's try that, remembering to include
1065 the @code{Staff} context. Note also that in writing this value we
1066 have @code{#'#} before the opening bracket. The @code{'#} is required
1067 as part of the value to introduce a vector, and the first @code{#} is
1068 required, as always, to precede the value itself in the
1069 @code{\override} command.
1071 @cindex BarLine, example of overriding
1072 @cindex break-visibility property, example
1074 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1077 \override Staff.BarLine #'break-visibility = #'#(#f #f #f)
1079 g, a16 b8 c d4 e16 |
1084 And we see this too removes all the bar lines.
1086 @subheading transparent
1088 @cindex transparent property
1089 @cindex transparency
1091 We see from the properties specified in the @code{grob-interface} page
1092 in the IR that the @code{transparent} property is a boolean. This
1093 should be set to @code{#t} to make the grob transparent. In this next
1094 example let us make the time signature invisible rather than the bar
1095 lines. To do this we need to find the grob name for the time
1096 signature. Back to the @q{All layout objects} page in the IR to find
1097 the properties of the @code{TimeSignature} layout object. This is
1098 produced by the @code{Time_signature_engraver} which you can check
1099 also lives in the @code{Staff} context and also supports the
1100 @code{grob-interface}. So the command to make the time signature
1103 @cindex TimeSignature, example of overriding
1104 @cindex transparent property, example
1106 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1109 \override Staff.TimeSignature #'transparent = ##t
1111 g, a16 b8 c d4 e16 |
1117 The time signature is gone, but this command leaves a gap where
1118 the time signature should be. Maybe this is what is wanted for
1119 an exercise for the student to fill it in, but in other
1120 circumstances a gap might be undesirable. To remove it, the
1121 stencil for the time signature should be set to @code{#f}
1124 @cindex TimeSignature, example of overriding
1125 @cindex stencil property, example
1127 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1130 \override Staff.TimeSignature #'stencil = ##f
1132 g, a16 b8 c d4 e16 |
1138 and the difference is obvious: setting the stencil to @code{#f}
1139 removes the object entirely; making the object @code{transparent}
1140 leaves it where it is, but makes it invisible.
1144 @cindex color property
1146 Finally let us try making the bar lines invisible by coloring
1147 them white. (There is a difficulty with this in that the
1148 white bar line may or may not blank out the staff lines where
1149 they cross. You may see in some of the examples below that this
1150 happens unpredictably. The details of why this is so and how to
1151 control it are covered in @ruser{Painting objects white}. But at
1152 the moment we are learning about color, so please just accept this
1153 limitation for now.)
1155 The @code{grob-interface} specifies that the
1156 color property value is a list, but there is no
1157 explanation of what that list should be. The list it
1158 requires is actually a list of values in internal units,
1159 but, to avoid having to know what these are, several ways
1160 are provided to specify colors. The first way is to use one
1161 of the @q{normal} colors listed in the first table in
1162 @ruser{List of colors}. To set the bar lines to white
1165 @cindex BarLine, example of overriding
1166 @cindex color property, example
1168 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1171 \override Staff.BarLine #'color = #white
1173 g, a16 b8 c d4 e16 |
1179 and again, we see the bar lines are not visible. Note that
1180 @emph{white} is not preceded by an apostrophe -- it is not
1181 a symbol, but a @emph{function}. When called, it provides
1182 the list of internal values required to set the color to
1183 white. The other colors in the normal list are functions
1184 too. To convince yourself this is working you might like
1185 to change the color to one of the other functions in the
1193 The second way of changing the color is to use the list of
1194 X11 color names in the second list in @ruser{List of colors}.
1195 However, these must be preceded by another function, which
1196 converts X11 color names into the list of internal values,
1197 @code{x11-color}, like this:
1199 @cindex BarLine, example of overriding
1200 @cindex color property, example
1202 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1205 \override Staff.BarLine #'color = #(x11-color 'white)
1207 g, a16 b8 c d4 e16 |
1213 Note that in this case the function @code{x11-color} takes
1214 a symbol as an argument, so the symbol must be preceded by
1215 an apostrophe and the two enclosed in brackets.
1222 There is yet a third function, one which converts RGB values into
1223 internal colors -- the @code{rgb-color} function. This takes
1224 three arguments giving the intensities of the red, green and
1225 blue colors. These take values in the range 0 to 1. So to
1226 set the color to red the value should be @code{(rgb-color 1 0 0)}
1227 and to white it should be @code{(rgb-color 1 1 1)}:
1229 @cindex BarLine, example of overriding
1230 @cindex color property, example
1232 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1235 \override Staff.BarLine #'color = #(rgb-color 1 1 1)
1237 g, a16 b8 c d4 e16 |
1242 Finally, there is also a grey scale available as part of the
1243 X11 set of colors. These range from black, @code{'grey0'},
1244 to white, @code{'grey100}, in steps of 1. Let's illustrate
1245 this by setting all the layout objects in our example to
1246 various shades of grey:
1248 @cindex StaffSymbol, example of overriding
1249 @cindex TimeSignature, example of overriding
1250 @cindex Clef, example of overriding
1251 @cindex NoteHead, example of overriding
1252 @cindex Stem, example of overriding
1253 @cindex BarLine, example of overriding
1254 @cindex color property, example
1255 @cindex x11-color, example of using
1257 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1260 \override Staff.StaffSymbol #'color = #(x11-color 'grey30)
1261 \override Staff.TimeSignature #'color = #(x11-color 'grey60)
1262 \override Staff.Clef #'color = #(x11-color 'grey60)
1263 \override Voice.NoteHead #'color = #(x11-color 'grey85)
1264 \override Voice.Stem #'color = #(x11-color 'grey85)
1265 \override Staff.BarLine #'color = #(x11-color 'grey10)
1267 g, a16 b8 c d4 e16 |
1273 Note the contexts associated with each of the layout objects.
1274 It is important to get these right, or the commands will not
1275 work! Remember, the context is the one in which the appropriate
1276 engraver is placed. The default context for engravers can be
1277 found by starting from the layout object, going from there to
1278 the engraver which produces it, and on the engraver page in the
1279 IR it tells you in which context the engraver will normally be
1283 @node Size of objects
1284 @subsection Size of objects
1286 @cindex changing size of objects
1287 @cindex size of objects
1288 @cindex objects, size of
1289 @cindex objects, changing size of
1291 Let us begin by looking again at the earlier example
1292 see @ref{Nesting music expressions}) which showed
1293 how to introduce a new temporary staff, as in an @rglos{ossia}.
1295 @cindex alignAboveContext property, example
1296 @cindex @code{\with}, example
1298 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1299 \new Staff ="main" {
1306 alignAboveContext = "main" }
1314 Ossia are normally written without clef and time signature, and
1315 are usually printed slightly smaller than the main staff. We
1316 already know now how to remove the clef and time signature --
1317 we simply set the stencil of each to @code{#f}, as follows:
1319 @cindex alignAboveContext property, example
1320 @cindex @code{\with}, example
1321 @cindex stencil property, example
1322 @cindex Clef, example of overriding
1323 @cindex TimeSignature, example of overriding
1325 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1326 \new Staff ="main" {
1333 alignAboveContext = "main"
1336 \override Staff.Clef #'stencil = ##f
1337 \override Staff.TimeSignature #'stencil = ##f
1347 where the extra pair of braces after the @code{\with} clause are
1348 required to ensure the enclosed overrides and music are applied
1351 But what is the difference between modifying the staff context by
1352 using @code{\with} and modifying the stencils of the clef and the
1353 time signature with \override? The main difference is that
1354 changes made in a @code{\with} clause are made at the time the
1355 context is created, and remain in force as the @strong{default}
1356 values for the duration of that context, whereas
1357 @code{\set} or @code{\override} commands embedded in the
1358 music are dynamic -- they make changes synchronized with
1359 a particular point in the music. If changes are unset or
1360 reverted using @code{\unset} or @code{\revert} they return to
1361 their default values, which will be the ones set in the
1362 @code{\with} clause, or if none have been set there, the normal
1365 Some context properties can be modified only in @code{\with} clauses.
1366 These are those properties which cannot sensibly be changed after the
1367 context has been created. @code{alignAboveContext} and its partner,
1368 @code{alignBelowContext}, are two such properties -- once the staff
1369 has been created its alignment is decided and it would make no sense
1370 to try to change it later.
1372 The default values of layout object properties can also be set
1373 in @code{\with} clauses. Simply use the normal @code{\override}
1374 command leaving out the context name, since this is unambiguously
1375 defined as the context which the @code{\with} clause is modifying.
1376 If fact, an error will be generated if a context is specified
1379 So we could replace the example above with
1381 @cindex alignAboveContext property, example
1382 @cindex @code{\with}, example
1383 @cindex Clef, example of overriding
1384 @cindex TimeSignature, example of overriding
1386 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1387 \new Staff ="main" {
1394 alignAboveContext = "main"
1395 % Don't print clefs in this staff
1396 \override Clef #'stencil = ##f
1397 % Don't print time signatures in this staff
1398 \override TimeSignature #'stencil = ##f
1407 Finally we come to changing the size of layout objects.
1409 Some layout objects are created as glyphs selected from a typeface
1410 font. These include note heads, accidentals, markup, clefs, time
1411 signatures, dynamics and lyrics. Their size is changed by modifying
1412 the @code{font-size} property, as we shall shortly see. Other layout
1413 objects such as slurs and ties -- in general, spanner objects -- are
1414 drawn individually, so there is no @code{font-size} associated with
1415 them. These objects generally derive their size from the objects to
1416 which they are attached, so usually there is no need to change their
1417 size manually. Still other properties such as the length of stems and
1418 bar lines, thickness of beams and other lines, and the separation of
1419 staff lines all need to be modified in special ways.
1421 Returning to the ossia example, let us first change the font-size.
1422 We can do this in two ways. We can either change the size of the
1423 fonts of each object type, like @code{NoteHead}s with commands
1427 \override NoteHead #'font-size = #-2
1430 or we can change the size of all fonts by setting a special
1431 property, @code{fontSize}, using @code{\set}, or by including
1432 it in a @code{\with} clause (but without the @code{\set}).
1438 Both of these statements would cause the font size to be reduced
1439 by 2 steps from its previous value, where each
1440 step reduces or increases the size by approximately 12%.
1442 Let's try it in our ossia example:
1444 @cindex alignAboveContext property, example
1445 @cindex @code{\with}, example
1446 @cindex Clef, example of overriding
1447 @cindex TimeSignature, example of overriding
1448 @cindex fontSize property, example
1450 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1451 \new Staff ="main" {
1458 alignAboveContext = "main"
1459 \override Clef #'stencil = ##f
1460 \override TimeSignature #'stencil = ##f
1461 % Reduce all font sizes by ~24%
1471 This is still not quite right. The note heads and flags are
1472 smaller, but the stems are too long in proportion and the
1473 staff lines are spaced too widely apart. These need to be
1474 scaled down in proportion to the font reduction. The next
1475 sub-section discusses how this is done.
1477 @node Length and thickness of objects
1478 @subsection Length and thickness of objects
1484 @cindex size, changing
1485 @cindex stem length, changing
1486 @cindex staff line spacing, changing
1488 Distances and lengths in LilyPond are generally measured in
1489 staff-spaces, the distance between adjacent lines in the staff,
1490 (or occasionally half staff spaces) while most @code{thickness}
1491 properties are measured in units of an internal property called
1492 @code{line-thickness.} For example, by default, the lines of
1493 hairpins are given a thickness of 1 unit of @code{line-thickness},
1494 while the @code{thickness} of a note stem is 1.3. Note, though,
1495 that some thickness properties are different; for example, the
1496 thickness of beams is measured in staff-spaces.
1498 So how are lengths to be scaled in proportion to the font size?
1499 This can be done with the help of a special function called
1500 @code{magstep} provided for exactly this purpose. It takes
1501 one argument, the change in font size (#-2 in the example above)
1502 and returns a scaling factor suitable for reducing other
1503 objects in proportion. It is used like this:
1505 @cindex alignAboveContext property, example
1506 @cindex @code{\with}, example
1507 @cindex Clef, example of overriding
1508 @cindex TimeSignature, example of overriding
1509 @cindex fontSize property, example
1510 @cindex StaffSymbol, example of overriding
1511 @cindex magstep function, example of using
1512 @cindex staff-space property, example
1513 @cindex stencil property, example
1515 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1516 \new Staff ="main" {
1523 alignAboveContext = "main"
1524 \override Clef #'stencil = ##f
1525 \override TimeSignature #'stencil = ##f
1527 % Reduce stem length and line spacing to match
1528 \override StaffSymbol #'staff-space = #(magstep -2)
1538 Since the length of stems and many other length-related properties are
1539 always calculated relative to the value of the @code{staff-space}
1540 property these are automatically scaled down in length too. Note that
1541 this affects only the vertical scale of the ossia -- the horizontal
1542 scale is determined by the layout of the main music in order to remain
1543 synchronized with it, so it is not affected by any of these changes in
1544 size. Of course, if the scale of all the main music were changed in
1545 this way then the horizontal spacing would be affected. This is
1546 discussed later in the layout section.
1548 This, then, completes the creation of an ossia. The sizes and
1549 lengths of all other objects may be modified in analogous ways.
1551 For small changes in scale, as in the example above, the
1552 thickness of the various drawn lines such as bar lines,
1553 beams, hairpins, slurs, etc does not usually require global
1554 adjustment. If the thickness of any particular layout object
1555 needs to be adjusted this can be best achieved by overriding its
1556 @code{thickness} property. An example of changing the thickness
1557 of slurs was shown above in @ref{Properties of layout objects}.
1558 The thickness of all drawn objects (i.e., those not produced
1559 from a font) may be changed in the same way.
1562 @node Placement of objects
1563 @section Placement of objects
1566 * Automatic behavior::
1567 * Within-staff objects::
1568 * Outside-staff objects::
1572 @node Automatic behavior
1573 @subsection Automatic behavior
1575 @cindex within-staff objects
1576 @cindex outside-staff objects
1577 @cindex objects, within-staff
1578 @cindex objects, outside-staff
1580 There are some objects in musical notation that belong to
1581 the staff and there are other objects that should be
1582 placed outside the staff. These are called within-staff
1583 objects and outside-staff objects respectively.
1585 Within-staff objects are those that are located on the staff
1586 -- note heads, stems, accidentals, etc. The positions of
1587 these are usually fixed by the music itself -- they are
1588 vertically positioned on specific lines of the staff or are
1589 tied to other objects that are so positioned. Collisions of
1590 note heads, stems and accidentals in closely set chords are
1591 normally avoided automatically. There are commands and
1592 overrides which can modify this automatic behavior, as we
1595 Objects belonging outside the staff include things such as
1596 rehearsal marks, text and dynamic markings. LilyPond's rule for
1597 the vertical placement of outside-staff objects is to place them
1598 as close to the staff as possible but not so close that they
1599 collide with any other object. LilyPond uses the
1600 @code{outside-staff-priority} property to determine the order in
1601 which the objects should be placed, as follows.
1603 First, LilyPond places all the within-staff objects.
1604 Then it sorts the outside-staff objects according to their
1605 @code{outside-staff-priority}. The outside-staff objects are
1606 taken one by one, beginning with the object with the lowest
1607 @code{outside-staff-priority}, and placed so that they do not
1608 collide with any objects that have already been placed. That is,
1609 if two outside-staff grobs are competing for the same space, the
1610 one with the lower @code{outside-staff-priority} will be placed
1611 closer to the staff. If two objects have the same
1612 @code{outside-staff-priority} the one encountered first will be
1613 placed closer to the staff.
1615 In the following example all the markup texts have the same
1616 priority (since it is not explicitly set). Note that @q{Text3}
1617 is automatically positioned close to the staff again, nestling
1620 @cindex markup example
1622 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1629 Staves are also positioned, by default, as closely together as
1630 possible (subject to a minimum separation). If notes project
1631 a long way towards an adjacent staff they will force the
1632 staves further apart only if an overlap of the notation
1633 would otherwise occur. The following example demonstrates
1634 this @q{nestling} of the notes on adjacent staves:
1636 @lilypond[quote,ragged-right,verbatim]
1639 \relative c' { c a, }
1642 \relative c'''' { c a, }
1648 @node Within-staff objects
1649 @subsection Within-staff objects
1651 We have already seen how the commands @code{\voiceXXX} affect
1652 the direction of slurs, ties, fingering and
1653 everything else which depends on the direction of the stems.
1654 These commands are essential when writing polyphonic music to
1655 permit interweaving melodic lines to be distinguished.
1656 But occasionally it may be necessary to override this automatic
1657 behavior. This can be done for whole sections of music or even
1658 for an individual note. The property which controls this
1659 behavior is the @code{direction} property of each layout object.
1660 We first explain what this does, and then introduce a number of
1661 ready-made commands which avoid your having to code explicit
1662 overrides for the more common modifications.
1664 Some layout objects like slurs and ties curve, bend or point
1665 either up or down; others like stems and flags also move to
1666 right or left when they point up or down. This is controlled
1667 automatically when @code{direction} is set.
1674 The following example shows in bar 1 the default behavior of stems,
1675 with those on high notes pointing down and those on low notes pointing
1676 up, followed by four notes with all stems forced down, four notes with
1677 all stems forced up, and finally four notes reverted back to the
1680 @cindex Stem, example of overriding
1681 @cindex direction property, example
1683 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1685 \override Stem #'direction = #DOWN
1687 \override Stem #'direction = #UP
1689 \revert Stem #'direction
1693 Here we use the constants @code{DOWN} and @code{UP}.
1694 These have the values @code{-1} and @code{+1} respectively, and
1695 these numerical values may be used instead. The value @code{0}
1696 may also be used in some cases. It is simply treated as meaning
1697 @code{UP} for stems, but for some objects it means @q{center}.
1698 There is a constant, @code{CENTER} which has the value @code{0}.
1700 However, these explicit overrides are not usually used, as there are
1701 simpler equivalent predefined commands available. Here is a table of
1702 the commonest. The meaning of each is stated where it is not obvious.
1704 @multitable @columnfractions .2 .2 .25 .35
1709 @item @code{\arpeggioArrowDown}
1710 @tab @code{\arpeggioArrowUp}
1711 @tab @code{\arpeggioNormal}
1712 @tab Arrow is at bottom, at top, or no arrow
1713 @item @code{\dotsDown}
1715 @tab @code{\dotsNeutral}
1716 @tab Direction of movement to avoid staff lines
1717 @item @code{\dynamicDown}
1718 @tab @code{\dynamicUp}
1719 @tab @code{\dynamicNeutral}
1721 @item @code{\phrasingSlurDown}
1722 @tab @code{\phrasingSlurUp}
1723 @tab @code{\phrasingSlurNeutral}
1724 @tab Note: distinct from slur commands
1725 @item @code{\slurDown}
1727 @tab @code{\slurNeutral}
1729 @item @code{\stemDown}
1731 @tab @code{\stemNeutral}
1733 @item @code{\textSpannerDown}
1734 @tab @code{\textSpannerUp}
1735 @tab @code{\textSpannerNeutral}
1736 @tab Text entered as spanner is below/above staff
1737 @item @code{\tieDown}
1739 @tab @code{\tieNeutral}
1741 @item @code{\tupletDown}
1742 @tab @code{\tupletUp}
1743 @tab @code{\tupletNeutral}
1744 @tab Tuplets are below/above notes
1747 Note that these predefined commands may @strong{not} be
1748 preceded by @code{\once}. If you wish to limit the
1749 effect to a single note you must either use the equivalent
1750 @code{\once \override} command or use the predefined command
1751 followed after the affected note by the corresponding
1752 @code{\xxxNeutral} command.
1754 @subheading Fingering
1756 @cindex fingering, placement
1757 @cindex fingering, chords
1759 The placement of fingering on single notes can also be controlled
1760 by the @code{direction} property, but changing @code{direction}
1761 has no effect on chords. As we shall see, there are special
1762 commands which allow the fingering of individual notes
1763 of chords to be controlled, with the fingering being placed
1764 above, below, to the left or to the right of each note.
1766 First, here's the effect of @code{direction} on the fingering
1767 attached to single notes. The first bar shows the default
1768 behaviour, and the following two bars shows the effect of
1769 specifying @code{DOWN} and @code{UP}:
1771 @cindex Fingering, example of overriding
1772 @cindex direction property, example
1774 @lilypond[quote,verbatim,relative=2]
1776 \override Fingering #'direction = #DOWN
1778 \override Fingering #'direction = #UP
1782 However, overriding the @code{direction} property is not the
1783 easiest way of manually setting the fingering above or below
1784 the notes; using @code{_} or @code{^} instead of @code{-} before
1785 the fingering number is usually preferable. Here is the previous
1786 example using this method:
1788 @cindex fingering example
1790 @lilypond[quote,verbatim,relative=2]
1796 The @code{direction} property is ignored for chords, but the
1797 directional prefixes, @code{_} and @code{^} do work. By default,
1798 the fingering is automatically placed both above and below the
1799 notes of a chord, as shown:
1801 @cindex fingering example
1803 @lilypond[quote,verbatim,relative=2]
1810 but this may be overriden to manually force all or any of the
1811 individual fingering numbers above or below:
1813 @cindex fingering example
1815 @lilypond[quote,verbatim,relative=2]
1821 Even greater control over the placement of fingering of the
1822 individual notes in a chord is possible by using the
1823 @code{\set fingeringOrientations} command. The format of this
1827 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
1831 @code{\set} is used because @code{fingeringOrientations} is a
1832 property of the @code{Voice} context, created and used by the
1833 @code{New_fingering_engraver}.
1835 The property may be set to a list of one to three values.
1836 It controls whether fingerings may be placed above (if
1837 @code{up} appears in the list), below (if @code{down} appears),
1838 to the left (if @code{left} appears, or to the right
1839 (if @code{right} appears). Conversely, if a location is not
1840 listed, no fingering is placed there. LilyPond takes these
1841 constraints and works out the best placement for the fingering
1842 of the notes of the following chords. Note that @code{left} and
1843 @code{right} are mutually exclusive -- fingering may be placed
1844 only on one side or the other, not both.
1846 @warning{To control the placement of the fingering of a single
1847 note using this command it is necessary to write it as a single
1848 note chord by placing angle brackets round it.}
1850 Here are a few examples:
1852 @cindex fingering example
1853 @cindex @code{\set}, example of using
1854 @cindex fingeringOrientations property, example
1856 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1857 \set fingeringOrientations = #'(left)
1859 < c-1 e-2 g-3 b-5 > 4
1860 \set fingeringOrientations = #'(left)
1862 < c-1 e-2 g-3 b-5 > 4
1863 \set fingeringOrientations = #'(up left down)
1865 < c-1 e-2 g-3 b-5 > 4
1866 \set fingeringOrientations = #'(up left)
1868 < c-1 e-2 g-3 b-5 > 4
1869 \set fingeringOrientations = #'(right)
1871 < c-1 e-2 g-3 b-5 > 4
1875 If the fingering seems a little crowded the @code{font-size}
1876 could be reduced. The default value can be seen from the
1877 @code{Fingering} object in the IR to be @code{-5}, so let's
1880 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1881 \override Fingering #'font-size = #-7
1882 \set fingeringOrientations = #'(left)
1884 < c-1 e-2 g-3 b-5 > 4
1885 \set fingeringOrientations = #'(left)
1887 < c-1 e-2 g-3 b-5 > 4
1888 \set fingeringOrientations = #'(up left down)
1890 < c-1 e-2 g-3 b-5 > 4
1891 \set fingeringOrientations = #'(up left)
1893 < c-1 e-2 g-3 b-5 > 4
1894 \set fingeringOrientations = #'(right)
1896 < c-1 e-2 g-3 b-5 > 4
1899 @node Outside-staff objects
1900 @subsection Outside-staff objects
1902 Outside-staff objects are automatically placed to avoid collisions.
1903 Objects with the lower value of the @code{outside-staff-priority}
1904 property are placed nearer to the staff, and other outside-staff
1905 objects are then raised as far as necessary to avoid collisions.
1906 The @code{outside-staff-priority} is defined in the
1907 @code{grob-interface} and so is a property of all layout objects.
1908 By default it is set to @code{#f} for all within-staff objects,
1909 and to a numerical value appropriate to each outside-staff object
1910 when the object is created. The following table shows
1911 the default numerical values for some of the commonest
1912 outside-staff objects which are, by default, placed in the
1913 @code{Staff} or @code{Voice} contexts.
1915 @multitable @columnfractions .3 .3 .3
1916 @headitem Layout Object
1918 @tab Controls position of:
1919 @item @code{MultiMeasureRestText}
1921 @tab Text over full-bar rests
1922 @item @code{TextScript}
1925 @item @code{OttavaBracket}
1927 @tab Ottava brackets
1928 @item @code{TextSpanner}
1931 @item @code{DynamicLineSpanner}
1933 @tab All dynamic markings
1934 @item @code{VoltaBracketSpanner}
1937 @item @code{TrillSpanner}
1939 @tab Spanning trills
1942 Here is an example showing the default placement of some of
1945 @cindex text spanner
1946 @cindex ottava bracket
1948 @funindex \startTextSpan
1949 @funindex startTextSpan
1950 @funindex \stopTextSpan
1951 @funindex stopTextSpan
1953 @cindex TextSpanner, example of overriding
1954 @cindex bound-details property, example
1956 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1957 % Set details for later Text Spanner
1958 \override TextSpanner #'(bound-details left text)
1959 = \markup { \small \bold Slower }
1960 % Place dynamics above staff
1962 % Start Ottava Bracket
1967 % Add Dynamic Line Spanner
1973 c\ff c \stopTextSpan
1974 % Stop Ottava Bracket
1979 This example also shows how to create Text Spanners --
1980 text with extender lines above a section of music. The
1981 spanner extends from the @code{\startTextSpan} command to
1982 the @code{\stopTextSpan} command, and the format of the
1983 text is defined by the @code{\override TextSpanner} command.
1984 For more details see @ruser{Text spanners}.
1986 It also shows how ottava brackets are created.
1988 @cindex tweaking bar number placement
1989 @cindex bar numbers, tweaking placement
1990 @cindex tweaking metronome mark placement
1991 @cindex metronome mark, tweaking placement
1992 @cindex tweaking rehearsal mark placement
1993 @cindex rehearsal marks, tweaking placement
1995 Note that bar numbers, metronome marks and rehearsal marks are not
1996 shown. By default these are created in the @code{Score} context and
1997 their @code{outside-staff-priority} is ignored relative to the layout
1998 objects which are created in the @code{Staff} context. If you wish to
1999 place bar numbers, metronome marks or rehearsal marks in accordance
2000 with the value of their @code{outside-staff-priority} the
2001 @code{Bar_number_engraver}, @code{Metronome_mark_engraver} or
2002 @code{Mark_engraver} respectively should be removed from the
2003 @code{Score} context and placed in the top @code{Staff} context. If
2004 this is done, these marks will be given the following default
2005 @code{outside-staff-priority} values:
2007 @multitable @columnfractions .3 .3
2008 @headitem Layout Object @tab Priority
2009 @item @code{RehearsalMark} @tab @code{1500}
2010 @item @code{MetronomeMark} @tab @code{1000}
2011 @item @code{BarNumber} @tab @code{ 100}
2014 If the default values of @code{outside-staff-priority} do not give you
2015 the placing you want, the priority of any of the objects may be
2016 overridden. Suppose we would like the ottava bracket to be placed
2017 below the text spanner in the example above. All we need to do is to
2018 look up the priority of @code{OttavaBracket} in the IR or in the
2019 tables above, and reduce it to a value lower than that of a
2020 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
2021 in the @code{Staff} context:
2023 @cindex TextSpanner, example of overriding
2024 @cindex bound-details property, example
2026 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2027 % Set details for later Text Spanner
2028 \override TextSpanner #'(bound-details left text)
2029 = \markup { \small \bold Slower }
2030 % Place dynamics above staff
2032 %Place following Ottava Bracket below Text Spanners
2033 \once \override Staff.OttavaBracket #'outside-staff-priority = #340
2034 % Start Ottava Bracket
2039 % Add Dynamic Line Spanner
2045 c\ff c \stopTextSpan
2046 % Stop Ottava Bracket
2051 Changing the @code{outside-staff-priority} can also be used to
2052 control the vertical placement of individual objects, although
2053 the results may not always be desirable. Suppose we would
2054 like @qq{Text3} to be placed above @qq{Text4} in the example
2055 under Automatic behavior, above (see @ref{Automatic behavior}).
2056 All we need to do is to look up the priority of @code{TextScript}
2057 in the IR or in the tables above, and increase the priority of
2058 @qq{Text3} to a higher value:
2060 @cindex TextScript, example of overriding
2061 @cindex outside-staff-priority property, example
2063 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2066 \once \override TextScript #'outside-staff-priority = #500
2071 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2072 above @qq{Text2}, and @qq{Text4} now drops down. Perhaps this is not
2073 so good. What we would really like to do is to position all the
2074 annotation at the same distance above the staff. To do this, we
2075 clearly will need to space the notes out horizontally to make more
2076 room for the text. This is done using the @code{textLengthOn}
2079 @subheading \textLengthOn
2081 @cindex notes, spreading out with text
2083 @funindex \textLengthOn
2084 @funindex textLengthOn
2085 @funindex \textLengthOff
2086 @funindex textLengthOff
2088 By default, text produced by markup takes up no horizontal space
2089 as far as laying out the music is concerned. The @code{\textLengthOn}
2090 command reverses this behavior, causing the notes to be spaced
2091 out as far as is necessary to accommodate the text:
2093 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2094 \textLengthOn % Cause notes to space out to accommodate text
2101 The command to revert to the default behavior is
2102 @code{\textLengthOff}. Remember @code{\once} only works with
2103 @code{\override}, @code{\set}, @code{\revert} or @code{unset},
2104 so cannot be used with @code{\textLengthOn}.
2106 @cindex markup text, allowing collisions
2108 Markup text will also avoid notes which project above the staff.
2109 If this is not desired, the automatic displacement upwards may
2110 be turned off by setting the priority to @code{#f}. Here's an
2111 example to show how markup text interacts with such notes.
2113 @cindex TextScript, example of overriding
2114 @cindex outside-staff-priority property, example
2116 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2117 % This markup is short enough to fit without collision
2121 % This is too long to fit, so it is displaced upwards
2125 % Turn off collision avoidance
2126 \once \override TextScript #'outside-staff-priority = ##f
2130 % Turn off collision avoidance
2131 \once \override TextScript #'outside-staff-priority = ##f
2132 \textLengthOn % and turn on textLengthOn
2133 c,,2^"Long Text " % Spaces at end are honored
2138 @subheading Dynamics
2140 @cindex tweaking dynamics placement
2141 @cindex dynamics, tweaking placement
2143 Dynamic markings will normally be positioned beneath the
2144 staff, but may be positioned above with the @code{dynamicUp}
2145 command. They will be positioned vertically relative to the
2146 note to which they are attached, and will float below (or above)
2147 all within-staff objects such as phrasing slurs and bar numbers.
2148 This can give quite acceptable results, as this example
2151 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2156 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2157 ees,2.~\)\mf ees4 r8 |
2160 However, if the notes and attached dynamics are close
2161 together the automatic placement will avoid collisions
2162 by displacing later dynamic markings further away, but this may
2163 not be the optimum placement, as this rather artificial example
2166 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2172 Should a similar situation arise in @q{real} music, it may be
2173 preferable to space out the notes a little further, so the dynamic
2174 markings can all fit at the same vertical distance from the staff. We
2175 were able to do this for markup text by using the @code{\textLengthOn}
2176 command, but there is no equivalent command for dynamic marks. So we
2177 shall have to work out how to do this using @code{\override} commands.
2179 @subheading Grob sizing
2182 @cindex sizing grobs
2184 First we must learn how grobs are sized. All grobs have a
2185 reference point defined within them which is used to position
2186 them relative to their parent object. This point in the grob
2187 is then positioned at a horizontal distance, @code{X-offset},
2188 and at a vertical distance, @code{Y-offset}, from its parent.
2189 The horizontal extent of the object is given by a pair of
2190 numbers, @code{X-extent}, which say where the left and right
2191 edges are relative to the reference point. The vertical extent
2192 is similarly defined by a pair of numbers, @code{Y-extent}.
2193 These are properties of all grobs which support the
2194 @code{grob-interface}.
2196 @cindex @code{extra-spacing-width}
2198 By default, outside-staff objects are given a width of zero so
2199 that they may overlap in the horizontal direction. This is done
2200 by the trick of adding infinity to the leftmost extent and
2201 minus infinity to the rightmost extent by setting the
2202 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}. So
2203 to ensure they do not overlap in the horizontal direction we
2204 must override this value of @code{extra-spacing-width} to
2205 @code{'(0 . 0)} so the true width shines through. This is
2206 the command to do this for dynamic text:
2209 \override DynamicText #'extra-spacing-width = #'(0 . 0)
2213 Let's see if this works in our previous example:
2215 @cindex DynamicText, example of overriding
2216 @cindex extra-spacing-width property, example
2218 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2220 \override DynamicText #'extra-spacing-width = #'(0 . 0)
2225 Well, it has certainly stopped the dynamic marks being
2226 displaced, but two problems remain. The marks should be
2227 spaced a little further apart and it would be better
2228 if they were all the same distance from the staff.
2229 We can solve the first problem easily. Instead of making
2230 the @code{extra-spacing-width} zero we could add a little
2231 more to it. The units are the space between two staff
2232 lines, so moving the left edge half a unit to the left and the
2233 right edge half a unit to the right should do it:
2235 @cindex DynamicText, example of overriding
2236 @cindex extra-spacing-width property, example
2238 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2240 % Extend width by 1 staff space
2241 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
2246 This looks better, but maybe we would prefer the dynamic marks
2247 to be aligned along the same baseline rather than going up and
2248 down with the notes. The property to do this is
2249 @code{staff-padding} which is covered in the following section.
2252 @node Collisions of objects
2253 @section Collisions of objects
2257 * Fixing overlapping notation::
2258 * Real music example::
2261 @node Moving objects
2262 @subsection Moving objects
2264 @cindex moving overlapping objects
2265 @cindex moving colliding objects
2266 @cindex moving colliding grobs
2267 @cindex objects, moving colliding
2268 @cindex grobs, moving colliding
2270 This may come as a surprise, but LilyPond is not perfect. Some
2271 notation elements can overlap. This is unfortunate, but in fact
2272 rather rare. Usually the need to move objects is for clarity or
2273 aesthetic reasons -- they would look better with a little more
2274 or a little less space around them.
2276 There are three main approaches to resolving overlapping
2277 notation. They should be considered in the following order:
2281 The @strong{direction} of one of the overlapping objects may
2282 be changed using the predefined commands listed above for
2283 within-staff objects (see @ref{Within-staff objects}).
2284 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2285 repositioned easily in this way. The limitation is that you
2286 have a choice of only two positions, and neither may be
2290 The @strong{object properties}, which LilyPond uses when positioning
2291 layout objects, may be modified using @code{\override}. The
2292 advantages of making changes to this type of property are (a) that
2293 some other objects will be moved automatically if necessary to make
2294 room and (b) the single override can apply to all instances of the
2295 same type of object. Such properties include:
2302 This has already been covered in some detail -- see
2303 @ref{Within-staff objects}.
2306 @code{padding}, @code{left-padding},
2307 @code{right-padding}, @code{staff-padding}
2310 @cindex left-padding property
2311 @cindex padding property
2312 @cindex right-padding property
2313 @cindex staff-padding property
2315 As an object is being positioned the value of its @code{padding}
2316 property specifies the gap that must be left between itself and the
2317 nearest edge of the object against which it is being positioned. Note
2318 that it is the @code{padding} value of the object @strong{being
2319 placed} that is used; the @code{padding} value of the object which is
2320 already placed is ignored. Gaps specified by @code{padding} can be
2321 applied to all objects which support the
2322 @code{side-position-interface}.
2324 Instead of @code{padding}, the placement of groups of accidentals
2325 is controlled by @code{left-padding} and @code{right-padding}.
2326 These properties are to be found in the @code{AccidentalPlacement}
2327 object which, note, lives in the @strong{staff} context. In the
2328 type-setting process the note heads are type-set first and then
2329 the accidentals, if any, are added to the left of the note heads
2330 using the @code{right-padding} property to determine the separation
2331 from the note heads. So only the @code{right-padding} property of the
2332 @code{AccidentalPlacement} object has any effect on the placement
2335 The @code{staff-padding} property is closely related to the
2336 @code{padding} property: @code{padding} controls the minimum amount of
2337 space between any object which supports the
2338 @code{side-position-interface} and the nearest other object (generally
2339 the note or the staff lines); @code{staff-padding} applies only to
2340 those objects which are always set outside the staff -- it controls
2341 the minimum amount of space that should be inserted between that
2342 object and the staff. Note that @code{staff-padding} has no effect on
2343 objects which are positioned relative to the note rather than the
2344 staff, even though it may be overridden without error for such objects
2345 -- it is simply ignored.
2347 To discover which padding property is required for the object you wish
2348 to reposition, you need to return to the IR and look up the object's
2349 properties. Be aware that the padding properties might not be located
2350 in the obvious object, so look in objects that appear to be related.
2352 All padding values are measured in staff spaces. For most
2353 objects, this value is set by default to be around 1.0 or less
2354 (it varies with each object). It may be overridden if a larger
2355 (or smaller) gap is required.
2358 @code{self-alignment-X}
2360 @cindex self-alignment-X property
2362 This property can be used to align the object to the left, to
2363 the right, or to center it with respect to the parent object's
2364 reference point. It may be used with all objects which support
2365 the @code{self-alignment-interface}. In general these are objects
2366 that contain text. The values are @code{LEFT}, @code{RIGHT}
2367 or @code{CENTER}. Alternatively, a numerical value between
2368 @code{-1} and @code{+1} may be specified, where @code{-1} is
2369 left-aligned, @code{+1} is right-aligned, and numbers in between
2370 move the text progressively from left-aligned to right-aligned.
2371 Numerical values greater than @code{1} may be specified to move
2372 the text even further to the left, or less than @code{-1} to
2373 move the text even further to the right. A change of @code{1}
2374 in the value corresponds to a movement of half the text's length.
2377 @code{extra-spacing-width}
2379 @cindex extra-spacing-width property
2381 This property is available for all objects which support the
2382 @code{item-interface}. It takes two numbers, the first is added
2383 to the leftmost extent and the second is added to the rightmost
2384 extent. Negative numbers move the edge to the left, positive to
2385 the right, so to widen an object the first number must be negative,
2386 the second positive. Note that not all objects honor both
2387 numbers. For example, the @code{Accidental} object only takes
2388 notice of the first (left edge) number.
2391 @code{staff-position}
2393 @cindex staff-position property
2395 @code{staff-position} is a property of the
2396 @code{staff-symbol-referencer-interface}, which is supported by
2397 objects which are positioned relative to the staff. It specifies
2398 the vertical position of the object relative to the center line
2399 of the staff in half staff-spaces. It is useful in resolving
2400 collisions between layout objects like multi-measure rests, ties
2401 and notes in different voices.
2406 @cindex force-hshift property
2408 Closely spaced notes in a chord, or notes occurring at the same
2409 time in different voices, are arranged in two, occasionally more,
2410 columns to prevent the note heads overlapping. These are called
2411 note columns, and an object called @code{NoteColumn} is created
2412 to lay out the notes in that column.
2414 The @code{force-hshift} property is a property of a @code{NoteColumn}
2415 (actually of the @code{note-column-interface}). Changing it permits a
2416 note column to be moved in units appropriate to a note column,
2417 viz. the note head width of the first voice note. It should be used
2418 in complex situations where the normal @code{\shiftOn} commands (see
2419 @ref{Explicitly instantiating voices}) do not resolve the note
2420 conflict. It is preferable to the @code{extra-offset} property for
2421 this purpose as there is no need to work out the distance in
2422 staff-spaces, and moving the notes into or out of a @code{NoteColumn}
2423 affects other actions such as merging note heads.
2428 Finally, when all else fails, objects may be manually repositioned
2429 relative to the staff center line vertically, or by displacing them by
2430 any distance to a new position. The disadvantages are that the
2431 correct values for the repositioning have to be worked out, often by
2432 trial and error, for every object individually, and, because the
2433 movement is done after LilyPond has placed all other objects, the user
2434 is responsible for avoiding any collisions that might ensue. But the
2435 main difficulty with this approach is that the repositioning values
2436 may need to be reworked if the music is later modified. The
2437 properties that can be used for this type of manual repositioning are:
2442 @cindex extra-offset property
2444 This property applies to any layout object supporting the
2445 @code{grob-interface}. It takes a pair of numbers which specify the
2446 extra displacement in the horizontal and vertical directions.
2447 Negative numbers move the object to the left or down. The units are
2448 staff-spaces. The extra displacement is made after the typesetting of
2449 objects is finished, so an object may be repositioned anywhere without
2450 affecting anything else.
2454 @cindex positions property
2456 This is most useful for manually adjusting the slope and height
2457 of beams, slurs, and tuplets. It takes a pair of numbers
2458 giving the position of the left and right ends of the beam, slur,
2459 etc. relative to the center line of the staff. Units are
2460 staff-spaces. Note, though, that slurs and phrasing slurs cannot
2461 be repositioned by arbitrarily large amounts. LilyPond first
2462 generates a list of possible positions for the slur and by default
2463 finds the slur that @qq{looks best}. If the @code{positions}
2464 property has been overridden the slur that is closest to the
2465 requested positions is selected from the list.
2470 A particular object may not have all of these properties.
2471 It is necessary to go to the IR to look up which properties
2472 are available for the object in question.
2474 Here is a list of the objects which are most likely to be
2475 involved in collisions, together with the name of the object which
2476 should be looked up in the IR in order to discover which properties
2477 should be used to move them.
2479 @multitable @columnfractions .5 .5
2480 @headitem Object type @tab Object name
2481 @item Articulations @tab @code{Script}
2482 @item Beams @tab @code{Beam}
2483 @item Dynamics (vertically) @tab @code{DynamicLineSpanner}
2484 @item Dynamics (horizontally) @tab @code{DynamicText}
2485 @item Fingerings @tab @code{Fingering}
2486 @item Rehearsal / Text marks @tab @code{RehearsalMark}
2487 @item Slurs @tab @code{Slur}
2488 @item Text e.g. @code{^"text"} @tab @code{TextScript}
2489 @item Ties @tab @code{Tie}
2490 @item Tuplets @tab @code{TupletBracket}
2494 @node Fixing overlapping notation
2495 @subsection Fixing overlapping notation
2497 Let's now see how the properties in the previous section can
2498 help to resolve overlapping notation.
2500 @subheading padding property
2503 @cindex fixing overlapping notation
2504 @cindex overlapping notation
2506 The @code{padding} property can be set to increase
2507 (or decrease) the distance between symbols that are printed
2508 above or below notes.
2510 @cindex Script, example of overriding
2511 @cindex padding property, example
2513 @lilypond[quote,fragment,relative=1,verbatim]
2515 \override Script #'padding = #3
2519 @cindex MetronomeMark, example of overriding
2520 @cindex padding property, example
2522 @lilypond[quote,fragment,relative=1,verbatim]
2523 % This will not work, see below:
2524 \override MetronomeMark #'padding = #3
2528 \override Score.MetronomeMark #'padding = #3
2533 Note in the second example how important it is to figure out what
2534 context handles a certain object. Since the @code{MetronomeMark}
2535 object is handled in the @code{Score} context, property changes in the
2536 @code{Voice} context will not be noticed. For more details, see
2537 @ruser{Modifying properties}.
2539 If the @code{padding} property of an object is increased when that
2540 object is in a stack of objects being positioned according to
2541 their @code{outside-staff-priority}, then that object and all
2542 objects outside it are moved.
2545 @subheading left-padding and right-padding
2547 @cindex left-padding property
2548 @cindex right-padding property
2550 The @code{right-padding} property affects the spacing between the
2551 accidental and the note to which it applies. It is not often
2552 required, but the following example shows one situation where it
2553 is needed. Suppose we wish to show a chord containing both
2554 a B-natural and a B-flat. To avoid ambiguity we would like to
2555 precede the notes with both a natural and a flat sign. Here
2556 are a few attempts to do this:
2558 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2564 None work, with the second two showing bad collisions between
2567 One way of achieving this is to override the accidental stencil
2568 with a markup containing the natural and flat symbols in the
2569 order we would like, like this:
2571 @cindex Accidental, example of overriding
2572 @cindex text property, example
2573 @cindex stencil property, example
2574 @cindex AccidentalPlacement, example of overriding
2575 @cindex right-padding property, example
2577 @lilypond[quote,ragged-right,verbatim]
2578 naturalplusflat = \markup { \natural \flat }
2580 \once \override Accidental
2581 #'stencil = #ly:text-interface::print
2582 \once \override Accidental #'text = #naturalplusflat
2583 \once \override Score.AccidentalPlacement #'right-padding = #1.5
2589 This necessarily uses an override for the accidental stencil which
2590 will not be covered until later. The stencil type must be a
2591 procedure, here changed to print the contents of the @code{text}
2592 property of @code{Accidental}, which itself is set to be a natural
2593 sign followed by a flat sign. These are then moved further away
2594 from the note head by overriding @code{right-padding}.
2598 @subheading staff-padding property
2600 @cindex aligning objects on a baseline
2601 @cindex objects, aligning on a baseline
2603 @code{staff-padding} can be used to align objects such as dynamics
2604 along a baseline at a fixed height above the staff, rather than at a
2605 height dependent on the position of the note to which they are
2606 attached. It is not a property of @code{DynamicText} but of
2607 @code{DynamicLineSpanner}. This is because the baseline should apply
2608 equally to @strong{all} dynamics, including those created as extended
2609 spanners. So this is the way to align the dynamic marks in the
2610 example taken from the previous section:
2612 @cindex DynamicText, example of overriding
2613 @cindex extra-spacing-width property, example
2614 @cindex DynamicLineSpanner, example of overriding
2615 @cindex staff-padding property, example
2617 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2619 % Extend width by 1 unit
2620 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
2621 % Align dynamics to a base line 2 units above staff
2622 \override DynamicLineSpanner #'staff-padding = #2
2627 @subheading self-alignment-X property
2629 The following example shows how this can resolve the collision
2630 of a string fingering object with a note's stem by aligning the
2631 right edge with the reference point of the parent note:
2633 @cindex StringNumber, example of overriding
2634 @cindex self-alignment-X property, example
2636 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
2639 \once \override StringNumber #'self-alignment-X = #RIGHT
2643 @subheading staff-position property
2645 @cindex object collision within a staff
2647 Multimeasure rests in one voice can collide with notes in another.
2648 Since these rests are typeset centered between the bar lines, it
2649 would require significant effort for LilyPond to figure out which
2650 other notes might collide with it, since all the current collision
2651 handling between notes and between notes and rests is done only
2652 for notes and rests that occur at the same time. Here's an
2653 example of a collision of this type:
2655 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2656 << {c c c c} \\ {R1} >>
2659 The best solution here is to move the multimeasure rest down, since
2660 the rest is in voice two. The default in @code{\voiceTwo} (i.e. in
2661 the second voice of a @code{<<@{...@} \\ @{...@}>>} construct) is that
2662 @code{staff-position} is set to -4 for MultiMeasureRest, so we need to
2663 move it, say, four half-staff spaces down to @code{-8}.
2665 @cindex MultiMeasureRest, example of overriding
2666 @cindex staff-position property, example
2668 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2672 \override MultiMeasureRest #'staff-position = #-8
2677 This is better than using, for example, @code{extra-offset},
2678 because the ledger line above the rest is inserted automatically.
2680 @subheading extra-offset property
2682 @cindex positioning objects
2683 @cindex positioning grobs
2684 @cindex objects, positioning
2685 @cindex grobs, positioning
2687 The @code{extra-offset} property provides complete control over the
2688 positioning of an object both horizontally and vertically.
2690 In the following example, the second fingering is moved a little to
2691 the left, and 1.8 staff space downwards:
2693 @cindex Fingering, example of overriding
2694 @cindex extra-offset property, example
2696 @lilypond[quote,fragment,relative=1,verbatim]
2699 \once \override Fingering
2700 #'extra-offset = #'(-0.3 . -1.8)
2705 @subheading positions property
2707 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
2708 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
2709 @cindex tuplet beams, controlling manually
2710 @cindex slurs, controlling manually
2711 @cindex phrasing slurs, controlling manually
2712 @cindex beams, controlling manually
2714 The @code{positions} property allows the position and slope of
2715 tuplets, slurs, phrasing slurs and beams to be controlled manually.
2716 Here's an example which has an ugly phrasing slur due to its trying to
2717 avoid the slur on the acciaccatura.
2719 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2720 r4 \acciaccatura e8\( d8 c ~c d c d\)
2724 We could simply move the phrasing slur above the notes, and this
2725 would be the preferred solution:
2727 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2730 \acciaccatura e8\( d8 c ~c d c d\)
2734 But if there were some reason why this could not be done the
2735 other alternative would be to move the left end of the phrasing
2736 slur down a little using the @code{positions} property. This
2737 also resolves the rather nasty shape.
2739 @cindex PhrasingSlur, example of overriding
2740 @cindex positions property, example
2742 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2744 \once \override PhrasingSlur #'positions = #'(-4 . -3)
2746 e8\( d8 c ~c d c d\)
2749 Here's a further example taken from the opening of the left-hand
2750 staff of Chopin's Prelude Op 28 No. 2. We see that the beam
2751 collides with the upper notes:
2753 @lilypond[quote,verbatim,fragment,ragged-right]
2756 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2757 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2762 This can be resolved by manually moving both ends of the beam
2763 up from their position at 2 staff-spaces above the center line to,
2766 @cindex Beam, example of overriding
2767 @cindex positions property, example
2769 @lilypond[quote,verbatim,fragment,ragged-right]
2773 \override Beam #'positions = #'(3 . 3)
2778 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2783 Note that the override continues to apply in the first voice of
2784 the second block of quavers, but not to any of the beams in the
2787 @subheading force-hshift property
2789 @c FIXME: formatting stuff (ie not important right now IMO)
2790 @c @a nchor Chopin finally corrected TODOgp
2792 We can now see how to apply the final corrections to the Chopin
2793 example introduced at the end of @ref{I'm hearing Voices}, which
2794 was left looking like this:
2796 @lilypond[quote,verbatim,fragment,ragged-right]
2797 \new Staff \relative c'' {
2800 { c2 aes4. bes8 } \\
2812 The lower two notes of the first chord (i.e, those in the third voice)
2813 should not be shifted away from the note column of the higher two
2814 notes. To correct this we set @code{force-hshift}, which is a
2815 property of @code{NoteColumn}, of these notes to zero. The lower note
2816 of the second chord is best placed just to the right of the higher
2817 notes. We achieve this by setting @code{force-hshift} of this note to
2818 0.5, ie half a note head's width to the right of the note column of
2821 Here's the final result:
2823 @cindex NoteColumn, example of overriding
2824 @cindex force-hshift property, example
2826 @lilypond[quote,verbatim,fragment,ragged-right]
2827 \new Staff \relative c'' {
2830 { c2 aes4. bes8 } \\
2833 \once \override NoteColumn #'force-hshift = #0 <ees c>2
2834 \once \override NoteColumn #'force-hshift = #0.5 des2
2842 @node Real music example
2843 @subsection Real music example
2845 We end this section on Tweaks by showing the steps to be taken to
2846 deal with a tricky example which needs several tweaks to produce
2847 the desired output. The example has been deliberately chosen to
2848 illustrate the use of the Notation Reference to resolve unusual
2849 problems with notation. It is not representative of more usual
2850 engraving process, so please do not let these difficulties put
2851 you off! Fortunately, difficulties like these are not very common!
2853 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
2854 9, the transition from the opening Lento to Moderato.
2855 Here, first, is what we want the output to look like, but to avoid
2856 over-complicating the example too much we have left out the
2857 dynamics, fingering and pedalling.
2859 @c The following should appear as music without code
2860 @c This example should not be indexed
2861 @lilypond[quote,ragged-right]
2862 rhMusic = \relative c'' {
2865 \once \override Tie #'staff-position = #3.5
2869 \mergeDifferentlyHeadedOn
2870 \mergeDifferentlyDottedOn
2871 bes2.^\markup {\bold "Moderato"} r8
2873 {c,8[ d fis bes a] | }
2875 % Reposition the c2 to the right of the merged note
2876 {c,8~ \once \override NoteColumn #'force-hshift = #1.0
2877 % Move the c2 out of the main note column so the merge will work
2880 % Stem on the d2 must be down to permit merging
2881 {s8 \stemDown \once \override Stem #'transparent = ##t d2}
2885 \mergeDifferentlyHeadedOff
2886 \mergeDifferentlyDottedOff
2890 lhMusic = \relative c' {
2892 <d g, d>1)\arpeggio |
2899 \new Staff = "RH" <<
2903 \new Staff = "LH" <<
2912 We note first that the right hand part in the third bar
2913 requires four voices. These are the five beamed eighth notes,
2914 the tied C, the half-note D which is merged with the eighth note
2915 D, and the dotted quarter note F-sharp, which is also merged with
2916 the eighth note at the same pitch. Everything else is in a single
2917 voice, so the easiest way is to introduce these four voices
2918 temporarily at the time they are needed. If you have forgotten
2919 how to do this, look at @ref{I'm hearing Voices}. Let us begin
2920 by entering the notes as two variables and setting up the staff
2921 structure in a score block, and see what LilyPond produces by
2924 @lilypond[quote,verbatim,ragged-right]
2925 rhMusic = \relative c'' {
2930 % Start polyphonic section of four voices
2932 {c,8 d fis bes a | }
2943 lhMusic = \relative c' {
2952 \new Staff = "RH" <<
2956 \new Staff = "LH" <<
2965 All the notes are right, but the appearance is far from satisfactory.
2966 The tie clashes with the change in time signature, the beaming in the
2967 third bar is wrong, the notes are not merged together, and several
2968 notation elements are missing. Let's first deal with the easier
2969 things. We can correct the beaming by inserting a beam manually, and
2970 we can easily add the left hand slur and the right hand phrasing slur,
2971 since these were all covered in the Tutorial. Doing this gives:
2973 @lilypond[quote,verbatim,ragged-right]
2974 rhMusic = \relative c'' {
2979 % Start polyphonic section of four voices
2981 {c,8[ d fis bes a] | }
2992 lhMusic = \relative c' {
3001 \new Staff = "RH" <<
3005 \new Staff = "LH" <<
3014 The first bar is now correct. The second bar contains an arpeggio and
3015 is terminated by a double bar line. How do we do these, as they have
3016 not been mentioned in this Learning Manual? This is where we need to
3017 turn to the Notation Reference. Looking up @q{arpeggio} and @q{bar
3018 line} in the index quickly shows us that an arpeggio is produced by
3019 appending @code{\arpeggio} to a chord, and a double bar line is
3020 produced by the @code{\bar "||"} command. That's easily done. We
3021 next need to correct the collision of the tie with the time signature.
3022 This is best done by moving the tie upwards. Moving objects was
3023 covered earlier in @ref{Moving objects}, which says that objects
3024 positioned relative to the staff can be moved by overriding their
3025 @code{staff-position} property, which is specified in half staff
3026 spaces relative to the center line of the staff. So the following
3027 override placed just before the first tied note would move the tie up
3028 to 3.5 half staff spaces above the center line:
3030 @code{\once \override Tie #'staff-position = #3.5}
3032 This completes bar two, giving:
3034 @lilypond[quote,verbatim,ragged-right]
3035 rhMusic = \relative c'' {
3037 \once \override Tie #'staff-position = #3.5
3042 % Start polyphonic section of four voices
3044 {c,8[ d fis bes a] | }
3055 lhMusic = \relative c' {
3057 <d g, d>1)\arpeggio |
3064 \new Staff = "RH" <<
3068 \new Staff = "LH" <<
3077 On to bar three and the start of the Moderato section. The tutorial
3078 showed how to add embolded text with the @code{\markup} command, so
3079 adding @q{Moderato} in bold is easy. But how do we merge notes in
3080 different voices together? This is where we need to turn to the
3081 Notation Reference for help. A search for @qq{merge} in the Notation
3082 Reference index quickly leads us to the commands for merging
3083 differently headed and differently dotted notes in @ruser{Collision
3084 resolution}. In our example we need to merge both types of note for
3085 the duration of the polyphonic section in bar 3, so using the
3086 information we find in the Notation Reference we add
3089 \mergeDifferentlyHeadedOn
3090 \mergeDifferentlyDottedOn
3094 to the start of that section and
3097 \mergeDifferentlyHeadedOff
3098 \mergeDifferentlyDottedOff
3104 @lilypond[quote,verbatim,ragged-right]
3105 rhMusic = \relative c'' {
3107 \once \override Tie #'staff-position = #3.5
3111 bes2.^\markup {\bold "Moderato"} r8
3112 \mergeDifferentlyHeadedOn
3113 \mergeDifferentlyDottedOn
3114 % Start polyphonic section of four voices
3116 {c,8[ d fis bes a] | }
3124 \mergeDifferentlyHeadedOff
3125 \mergeDifferentlyDottedOff
3129 lhMusic = \relative c' {
3131 <d g, d>1)\arpeggio |
3138 \new Staff = "RH" <<
3142 \new Staff = "LH" <<
3151 These overrides have merged the two F-sharp notes, but not the two
3152 on D. Why not? The answer is there in the same section in the
3153 Notation Reference -- notes being merged must have stems in
3154 opposite directions and two notes cannot be merged successfully if
3155 there is a third note in the same note column. Here the two D's
3156 both have upward stems and there is a third note -- the C. We know
3157 how to change the stem direction using @code{\stemDown}, and
3158 the Notation Reference also says how to move the C -- apply a shift
3159 using one of the @code{\shift} commands. But which one?
3160 The C is in voice two which has shift off, and the two D's are in
3161 voices one and three, which have shift off and shift on,
3162 respectively. So we have to shift the C a further level still
3163 using @code{\shiftOnn} to avoid it interfering with the two D's.
3164 Applying these changes gives:
3166 @cindex Tie, example of overriding
3167 @cindex staff-position property, example
3169 @lilypond[quote,verbatim,ragged-right]
3170 rhMusic = \relative c'' {
3172 \once \override Tie #'staff-position = #3.5
3176 bes2.^\markup {\bold "Moderato"} r8
3177 \mergeDifferentlyHeadedOn
3178 \mergeDifferentlyDottedOn
3179 % Start polyphonic section of four voices
3181 {c,8[ d fis bes a] | }
3183 % Move the c2 out of the main note column so the merge will work
3184 {c,8~ \shiftOnn c2 | }
3186 % Stem on the d2 must be down to permit merging
3187 {s8 \stemDown d2 | }
3191 \mergeDifferentlyHeadedOff
3192 \mergeDifferentlyDottedOff
3196 lhMusic = \relative c' {
3198 <d g, d>1)\arpeggio |
3205 \new Staff = "RH" <<
3209 \new Staff = "LH" <<
3218 Nearly there. Only two problems remain: The downward stem on the
3219 merged D should not be there, and the C would be better positioned
3220 to the right of the D's. We know how to do both of these from the
3221 earlier tweaks: we make the stem transparent, and move the C with
3222 the @code{force-hshift} property. Here's the final result:
3224 @cindex NoteColumn, example of overriding
3225 @cindex force-hshift property, example
3226 @cindex Stem, example of overriding
3227 @cindex transparent property, example
3229 @lilypond[quote,verbatim,ragged-right]
3230 rhMusic = \relative c'' {
3233 \once \override Tie #'staff-position = #3.5
3237 bes2.^\markup {\bold "Moderato"} r8
3238 \mergeDifferentlyHeadedOn
3239 \mergeDifferentlyDottedOn
3241 {c,8[ d fis bes a] | }
3243 % Reposition the c2 to the right of the merged note
3244 {c,8~ \once \override NoteColumn #'force-hshift = #1.0
3245 % Move the c2 out of the main note column so the merge will work
3248 % Stem on the d2 must be down to permit merging
3249 {s8 \stemDown \once \override Stem #'transparent = ##t d2}
3253 \mergeDifferentlyHeadedOff
3254 \mergeDifferentlyDottedOff
3258 lhMusic = \relative c' {
3260 <d g, d>1)\arpeggio |
3267 \new Staff = "RH" <<
3271 \new Staff = "LH" <<
3281 @node Further tweaking
3282 @section Further tweaking
3285 * Other uses for tweaks::
3286 * Using variables for tweaks::
3287 * Other sources of information::
3288 * Avoiding tweaks with slower processing::
3289 * Advanced tweaks with Scheme::
3292 @node Other uses for tweaks
3293 @subsection Other uses for tweaks
3295 @cindex transparent property, use of
3296 @cindex objects, making invisible
3297 @cindex removing objects
3298 @cindex objects, removing
3299 @cindex hiding objects
3300 @cindex objects, hiding
3301 @cindex invisible objects
3302 @cindex objects, invisible
3303 @cindex tying notes across voices
3305 @subheading Tying notes across voices
3307 The following example demonstrates how to connect notes in
3308 different voices using ties. Normally, only two notes in the
3309 same voice can be connected with ties. By using two voices,
3310 with the tied notes in one of them
3312 @lilypond[quote,fragment,relative=2]
3313 << { b8~ b8\noBeam }
3319 and blanking the first up-stem in that voice, the tie appears to
3322 @cindex Stem, example of overriding
3323 @cindex transparent property, example
3325 @lilypond[quote,fragment,relative=2,verbatim]
3328 \once \override Stem #'transparent = ##t
3336 To make sure that the just-blanked stem doesn't squeeze the tie
3337 too much, we can lengthen the stem by setting the
3338 @code{length} to @code{8},
3340 @lilypond[quote,fragment,relative=2,verbatim]
3343 \once \override Stem #'transparent = ##t
3344 \once \override Stem #'length = #8
3352 @subheading Simulating a fermata in MIDI
3354 @cindex stencil property, use of
3355 @cindex fermata, implementing in MIDI
3357 For outside-staff objects it is usually better to override the
3358 object's @code{stencil} property rather than its @code{transparent}
3359 property when you wish to remove it from the printed output.
3360 Setting the @code{stencil} property of an object to @code{#f} will
3361 remove that object entirely from the printed output. This means it
3362 has no effect on the placement of other objects placed relative to
3365 For example, if we wished to change the metronome setting in order
3366 to simulate a fermata in the MIDI output we would not want the
3367 metronome markings to appear in the printed output, and we would
3368 not want it to influence the spacing between the two systems or
3369 the positions of adjacent annotations on the staff. So setting
3370 its @code{stencil} property to @code{#f} would be the best way.
3371 We show here the effect of the two methods:
3373 @cindex MetronomeMark, example of overriding
3374 @cindex transparent property, example
3376 @lilypond[quote,verbatim,ragged-right]
3379 % Visible tempo marking
3382 \once \override Score.MetronomeMark #'transparent = ##t
3383 % Invisible tempo marking to lengthen fermata in MIDI
3386 % New tempo for next section
3395 @cindex MetronomeMark, example of overriding
3396 @cindex stencil property, example
3398 @lilypond[quote,verbatim,ragged-right]
3401 % Visible tempo marking
3404 \once \override Score.MetronomeMark #'stencil = ##f
3405 % Invisible tempo marking to lengthen fermata in MIDI
3408 % New tempo for next section
3418 Both methods remove the metronome mark which lengthens the fermata
3419 from the printed output, and both affect the MIDI timing as
3420 required, but the transparent metronome mark in the first line
3421 forces the following tempo indication too high while the
3422 second (with the stencil removed) does not.
3424 @node Using variables for tweaks
3425 @subsection Using variables for tweaks
3427 @cindex variables, using for tweaks
3428 @cindex using variables for tweaks
3429 @cindex tweaks, using variables for
3431 Override commands are often long and tedious to type, and they
3432 have to be absolutely correct. If the same overrides are to be
3433 used many times it may be worth defining variables to hold them.
3434 Suppose we wish to emphasize certain words in lyrics by printing
3435 them in bold italics. The @code{\italic} and @code{\bold}
3436 commands only work within lyrics if they are also embedded in
3437 @code{\markup}, which makes them tedious to enter, so as an
3438 alternative can we instead use the @code{\override} and
3439 @code{\revert} commands?
3442 @code{\override Lyrics . LyricText #'font-shape = #'italic}
3443 @code{\override Lyrics . LyricText #'font-series = #'bold}
3445 @code{\revert Lyrics . LyricText #'font-shape}
3446 @code{\revert Lyrics . LyricText #'font-series}
3449 These would also be extremely tedious to enter if there were many
3450 words requiring emphasis. So instead we define these as two
3451 variables, and use them as follows, although normally we would
3452 perhaps choose shorter names for the variables to make them
3455 @cindex LyricText, example of overriding
3456 @cindex font-shape property, example
3457 @cindex font-series property, example
3459 @lilypond[quote,verbatim]
3461 \override Lyrics . LyricText #'font-shape = #'italic
3462 \override Lyrics . LyricText #'font-series = #'bold
3465 \revert Lyrics . LyricText #'font-shape
3466 \revert Lyrics . LyricText #'font-series
3469 global = { \time 4/4 \partial 4 \key c \major}
3470 SopranoMusic = \relative c' { c4 | e4. e8 g4 g | a a g }
3471 AltoMusic = \relative c' { c4 | c4. c8 e4 e | f f e }
3472 TenorMusic = \relative c { e4 | g4. g8 c4. b8 | a8 b c d e4 }
3473 BassMusic = \relative c { c4 | c4. c8 c4 c | f8 g a b c4 }
3474 VerseOne = \lyrics { E -- | ter -- nal \emphasize Fa -- ther, \normal | strong to save, }
3475 VerseTwo = \lyricmode { O | \emphasize Christ, \normal whose voice the | wa -- ters heard, }
3476 VerseThree = \lyricmode { O | \emphasize Ho -- ly Spi -- rit, \normal | who didst brood }
3477 VerseFour = \lyricmode { O | \emphasize Tri -- ni -- ty \normal of | love and pow'r }
3483 \new Voice = "Soprano" { \voiceOne \global \SopranoMusic }
3484 \new Voice = "Alto" { \voiceTwo \AltoMusic }
3485 \new Lyrics \lyricsto "Soprano" { \VerseOne }
3486 \new Lyrics \lyricsto "Soprano" { \VerseTwo }
3487 \new Lyrics \lyricsto "Soprano" { \VerseThree }
3488 \new Lyrics \lyricsto "Soprano" { \VerseFour }
3492 \new Voice = "Tenor" { \voiceOne \TenorMusic }
3493 \new Voice = "Bass" { \voiceTwo \BassMusic }
3501 @node Other sources of information
3502 @subsection Other sources of information
3504 The Internals Reference documentation contains a lot of information
3505 about LilyPond, but even more information can be gathered by
3506 looking at the internal LilyPond files. To explore these, you must
3507 first find the directory appropriate to your system. The location
3508 of this directory depends (a) on whether you obtained LilyPond
3509 by downloading a precompiled binary from lilypond.org
3510 or whether you installed it from a package manager (i.e.
3511 distributed with Linux, or installed under fink or cygwin) or
3512 compiled it from source, and (b) on which operating system it is
3515 @strong{Downloaded from lilypond.org}
3521 @file{@var{INSTALLDIR}/lilypond/usr/share/lilypond/current/}
3526 @file{@var{INSTALLDIR}/LilyPond.app/Contents/Resources/share/lilypond/current/}
3527 by either @code{cd}-ing into this directory from the
3528 Terminal, or control-clicking on the LilyPond application and
3529 selecting @q{Show Package Contents}.
3533 Using Windows Explorer, navigate to
3534 @file{@var{INSTALLDIR}/LilyPond/usr/share/lilypond/current/}
3538 @strong{Installed from a package manager or compiled from source}
3541 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
3542 @var{PREFIX} is set by your package manager or @code{configure}
3543 script, and @var{X.Y.Z} is the LilyPond version number.
3547 Within this directory the two interesting subdirectories are
3550 @item @file{ly/} - contains files in LilyPond format
3551 @item @file{scm/} - contains files in Scheme format
3554 Let's begin by looking at some files in @file{ly/}.
3555 Open @file{ly/property-init.ly} in a text editor. The one
3556 you normally use for @code{.ly} files will be fine. This file
3557 contains the definitions of all the standard LilyPond predefined
3558 commands, such as @code{\stemUp} and @code{\slurDotted}. You will
3559 see that these are nothing more than definitions of variables
3560 containing one or a group of @code{\override} commands. For
3561 example, @code{/tieDotted} is defined to be:
3565 \override Tie #'dash-period = #0.75
3566 \override Tie #'dash-fraction = #0.1
3570 If you do not like the default values these predefined commands can
3571 be redefined easily, just like any other variable, at the
3572 head of your input file.
3574 The following are the most useful files to be found in
3577 @multitable @columnfractions .4 .6
3580 @item @file{ly/engraver-init.ly}
3581 @tab Definitions of engraver Contexts
3582 @item @file{ly/paper-defaults-init.ly}
3583 @tab Specifications of paper-related defaults
3584 @item @file{ly/performer-init.ly}
3585 @tab Definitions of performer Contexts
3586 @item @file{ly/property-init.ly}
3587 @tab Definitions of all common predefined commands
3588 @item @file{ly/spanner-init.ly}
3589 @tab Definitions of spanner-related predefined commands
3592 Other settings (such as the definitions of markup commands) are
3593 stored as @code{.scm} (Scheme) files. The Scheme programming
3594 language is used to provide a programmable interface into
3595 LilyPond internal operation. Further explanation of these files
3596 is currently outside the scope of this manual, as a knowledge of
3597 the Scheme language is required. Users should be warned that
3598 a substantial amount of technical knowledge or time is required
3599 to understand Scheme and these files (see @ref{Scheme tutorial}).
3601 If you have this knowledge, the Scheme files which may be of
3604 @multitable @columnfractions .4 .6
3607 @item @file{scm/auto-beam.scm}
3608 @tab Sub-beaming defaults
3609 @item @file{scm/define-grobs.scm}
3610 @tab Default settings for grob properties
3611 @item @file{scm/define-markup-commands.scm}
3612 @tab Specify all markup commands
3613 @item @file{scm/midi.scm}
3614 @tab Default settings for MIDI output
3615 @item @file{scm/output-lib.scm}
3616 @tab Settings that affect appearance of frets, colors,
3617 accidentals, bar lines, etc
3618 @item @file{scm/parser-clef.scm}
3619 @tab Definitions of supported clefs
3620 @item @file{scm/script.scm}
3621 @tab Default settings for articulations
3626 @node Avoiding tweaks with slower processing
3627 @subsection Avoiding tweaks with slower processing
3629 LilyPond can perform extra checks while it processes input files. These
3630 checks will take extra time to perform, but fewer manual tweaks
3631 may be required to obtain an acceptable result. If a text script
3632 or part of the lyrics extends over the margins these checks will
3633 compress that line of the score just enough to fit within the
3636 To be effective under all circumstances these checks must be enabled
3637 by placing the overrides in a Score @code{\with} block, rather than
3638 in-line in music, as follows:
3642 % Makes sure text scripts and lyrics are within the paper margins
3643 \override PaperColumn #'keep-inside-line = ##t
3644 \override NonMusicalPaperColumn #'keep-inside-line = ##t
3650 @node Advanced tweaks with Scheme
3651 @subsection Advanced tweaks with Scheme
3653 Although many things are possible with the @code{\override} and
3654 @code{\tweak} commands, an even more powerful way of modifying
3655 the action of LilyPond is available through a programmable
3656 interface to the LilyPond internal operation. Code written in
3657 the Scheme programming language can be incorporated directly in
3658 the internal operation of LilyPond. Of course, at least a basic
3659 knowledge of programming in Scheme is required to do this, and an
3660 introduction is provided in the @ref{Scheme tutorial}.
3662 As an illustration of one of the many possibilities, instead of
3663 setting a property to a constant it can be set to a Scheme
3664 procedure which is then called whenever that property is accessed
3665 by LilyPond. The property can then be set dynamically to a value
3666 determined by the procedure at the time it is called. In this
3667 example we color the note head in accordance with its position on
3670 @cindex x11-color function, example of using
3671 @cindex NoteHead, example of overriding
3672 @cindex color property, setting to Scheme procedure
3674 @lilypond[quote,verbatim,ragged-right]
3675 #(define (color-notehead grob)
3676 "Color the notehead according to its position on the staff."
3677 (let ((mod-position (modulo (ly:grob-property grob 'staff-position) 7)))
3679 ;; Return rainbow colors
3680 ((1) (x11-color 'red )) ; for C
3681 ((2) (x11-color 'orange )) ; for D
3682 ((3) (x11-color 'yellow )) ; for E
3683 ((4) (x11-color 'green )) ; for F
3684 ((5) (x11-color 'blue )) ; for G
3685 ((6) (x11-color 'purple )) ; for A
3686 ((0) (x11-color 'violet )) ; for B
3692 % Arrange to obtain color from color-notehead procedure
3693 \override NoteHead #'color = #color-notehead
3700 Some -- where o -- ver the Rain -- bow, way up high,
3704 Further examples showing the use of these programmable interfaces
3705 can be found in @ref{Tweaking with Scheme}.