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
230 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
232 \override NoteHead #'color = #red
234 \override NoteHead #'color = #green
238 @strong{\revert command}
240 @cindex revert command
245 Once overridden, the property retains its new value until it is
246 overridden again or a @code{\revert} command is encountered.
247 The @code{\revert} command has the following syntax and causes
248 the value of the property to revert to its original default
249 value; note, not its previous value if several @code{\override}
250 commands have been issued.
253 \revert @var{Context}.@var{LayoutObject} #'@var{layout-property}
256 Again, just like @var{Context} in the @code{\override} command,
257 @var{Context} is often not needed. It will be omitted
258 in many of the following examples. Here we revert the color
259 of the note head to the default value for the final two notes:
261 @cindex color property, example
263 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
265 \override NoteHead #'color = #red
267 \override NoteHead #'color = #green
269 \revert NoteHead #'color
273 @strong{\once prefix}
278 Both the @code{\override} and the @code{\set} commands may be
279 prefixed by @code{\once}. This causes the following
280 @code{\override} or @code{\set} command to be effective only
281 during the current musical moment before the property reverts
282 back to its default value. Using the same example, we can
283 change the color of a single note like this:
285 @cindex color property, example
287 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
289 \once \override NoteHead #'color = #red
291 \once \override NoteHead #'color = #green
295 @strong{\overrideProperty command}
297 @cindex overrideProperty command
299 @funindex \overrideProperty
300 @funindex overrideProperty
302 There is another form of the override command,
303 @code{\overrideProperty}, which is occasionally required.
304 We mention it here for completeness, but for details see
305 @ruser{Difficult tweaks}.
306 @c Maybe explain in a later iteration -td
308 @strong{\tweak command}
310 @cindex tweak command
315 The final tweaking command which is available is @code{\tweak}.
316 This should be used to change the properties of objects which
317 occur at the same musical moment, such as the notes within a
318 chord. Using @code{\override} would affect all the notes
319 within a chord, whereas @code{\tweak} affects just the following
320 item in the input stream.
322 Here's an example. Suppose we wish to change the size of the
323 middle note head (the E) in a C major chord. Let's first see what
324 @code{\once \override} would do:
326 @cindex font-size property, example
328 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
330 \once \override NoteHead #'font-size = #-3
335 We see the override affects @emph{all} the note heads in the chord.
336 This is because all the notes of a chord occur at the same
337 @emph{musical moment}, and the action of @code{\once} is to
338 apply the override to all layout objects of the type specified
339 which occur at the same musical moment as the @code{\override}
342 The @code{\tweak} command operates in a different way. It acts
343 on the immediately following item in the input stream. However,
344 it is effective only on objects which are created directly from
345 the input stream, essentially note heads and articulations;
346 objects such as stems and accidentals are created later and
347 cannot be tweaked in this way. Furthermore, when it is applied
348 to note heads these @emph{must} be within a chord, i.e., within
349 single angle brackets, so to tweak a single note the @code{\tweak}
350 command must be placed inside single angle brackets with the
353 So to return to our example, the size of the middle note of
354 a chord would be changed in this way:
356 @cindex font-size property, example
358 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
360 <c \tweak #'font-size #-3 e g>4
363 Note that the syntax of @code{\tweak} is different from that
364 of the @code{\override} command. Neither the context nor the
365 layout object should be specified; in fact, it would generate
366 an error to do so. These are both implied by the following
367 item in the input stream. So the general syntax of the
368 @code{\tweak} command is simply
371 \tweak #'@var{layout-property} = #@var{value}
374 A @code{\tweak} command can also be used to modify just one in
375 a series of articulations, as shown here:
377 @cindex color property, example
378 @cindex tweak example
380 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
382 -\tweak #'color #red ^Red
383 -\tweak #'color #green _Green
387 Note that the @code{\tweak} command must be preceded by an
388 articulation mark as if it were an articulation itself.
390 @cindex tuplets, nested
391 @cindex triplets, nested
392 @cindex bracket, tuplet
393 @cindex tuplet bracket
394 @cindex triplet bracket
396 @funindex TupletBracket
398 The @code{\tweak} command must also be used to change the
399 appearance of one of a set of nested tuplets which begin at the
400 same musical moment. In the following example, the long tuplet
401 bracket and the first of the three short brackets begin at the
402 same musical moment, so any @code{\override} command would apply
403 to both of them. In the example, @code{\tweak} is used to
404 distinguish between them. The first @code{\tweak} command
405 specifies that the long tuplet bracket is to be placed above the
406 notes and the second one specifies that the tuplet number is to be
407 printed in red on the first short tuplet bracket.
409 @cindex tweak example
410 @cindex direction property, example
411 @cindex color property, example
413 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
414 \tweak #'direction #up
417 \times 2/3 { c8[ c8 c8] }
418 \times 2/3 { c8[ c8 c8] }
419 \times 2/3 { c8[ c8 c8] }
423 If nested tuplets do not begin at the same moment, their
424 appearance may be modified in the usual way with
425 @code{\override} commands:
427 @cindex text property, example
428 @cindex tuplet-number example
429 @cindex transparent property, example
431 @c NOTE Tuplet brackets collide if notes are high on staff
433 @lilypond[quote,ragged-right,verbatim,fragment,relative=1]
434 \times 2/3 { c8[ c c]}
435 \once \override TupletNumber
436 #'text = #tuplet-number::calc-fraction-text
440 \once \override TupletNumber #'transparent = ##t
441 \times 2/3 { c8[ c c] }
442 \times 2/3 { c8[ c c]}
449 @ruser{The tweak command}.
452 @node The Internals Reference manual
453 @section The Internals Reference manual
455 @cindex Internals Reference
458 * Properties of layout objects::
459 * Properties found in interfaces::
460 * Types of properties::
463 @node Properties of layout objects
464 @subsection Properties of layout objects
466 @cindex properties of layout objects
467 @cindex properties of grobs
468 @cindex grobs, properties of
469 @cindex layout objects, properties of
470 @cindex Internals Reference manual
472 Suppose you have a slur in a score which, to your mind,
473 appears too thin and you'd like to draw it a little heavier.
474 How do you go about doing this? You know from the statements
475 earlier about the flexibility of LilyPond that such a thing
476 should be possible, and you would probably guess that an
477 @code{\override} command would be needed. But is there a
478 heaviness property for a slur, and if there is, how might it
479 be modified? This is where the Internals Reference manual
480 comes in. It contains all the information you might need to
481 construct this and all other @code{\override} commands.
483 Before we look at the Internals Reference a word of warning.
484 This is a @strong{reference} document, which means there is
485 little or no explanation contained within it: its purpose is
486 to present information precisely and concisely. This
487 means it might look daunting at first sight. Don't worry!
488 The guidance and explanation presented here will enable you
489 to extract the information from the Internals Reference for
490 yourself with just a little practice.
492 @cindex override example
493 @cindex Internals Reference, example of using
494 @cindex addlyrics example
496 Let's use a concrete example with a simple fragment of real
499 @lilypond[quote,verbatim,relative=2]
504 g[( e]) e d[( f]) a |
508 The man who feels love's sweet e -- mo -- tion
513 Suppose now that we decide we would like the slurs to be a
514 little heavier. Is this possible? The slur is certainly a
515 layout object, so the question is, @q{Is there a property
516 belonging to a slur which controls the heaviness?} To answer
517 this we must look in the Internals Reference, or IR for short.
519 The IR for the version of LilyPond you are using may be found
520 on the LilyPond website at @uref{http://lilypond.org}. Go to the
521 documentation page and click on the Internals Reference link.
522 For learning purposes you should use the standard HTML version,
523 not the @q{one big page} or the PDF. For the next few
524 paragraphs to make sense you will need to actually do this
527 Under the heading @strong{Top} you will see five links. Select
528 the link to the @emph{Backend}, which is where information about
529 layout objects is to be found. There, under the heading
530 @strong{Backend}, select the link to @emph{All layout objects}.
531 The page that appears lists all the layout objects used in your
532 version of LilyPond, in alphabetic order. Select the link to
533 Slur, and the properties of Slurs are listed.
535 An alternative way of finding this page is from the Notation
536 Reference. On one of the pages that deals with slurs you may find a
537 link to the Internals Reference. This link will take you directly to
538 this page, but if you have an idea about the name of the layout object
539 to be tweaked, it is easier to go straight to the IR and search there.
541 This Slur page in the IR tells us first that Slur objects are created
542 by the Slur_engraver. Then it lists the standard settings. Note
543 these are @strong{not} in alphabetic order. Browse down them looking
544 for a property that might control the heaviness of slurs, and you
548 @code{thickness} (number)
550 Line thickness, generally measured in @code{line-thickness}
553 This looks a good bet to change the heaviness. It tells us that
554 the value of @code{thickness} is a simple @emph{number},
555 that the default value is 1.2, and that the units are
556 in another property called @code{line-thickness}.
558 As we said earlier, there are few to no explanations in the IR,
559 but we already have enough information to try changing the
560 slur thickness. We see that the name of the layout object
561 is @code{Slur}, that the name of the property to change is
562 @code{thickness} and that the new value should be a number
563 somewhat larger than 1.2 if we are to make slurs thicker.
565 We can now construct the @code{\override} command by simply
566 substituting the values we have found for the names, omitting
567 the context. Let's use a very large value for the thickness
568 at first, so we can be sure the command is working. We get:
571 \override Slur #'thickness = #5.0
574 Don't forget the @code{#'} preceding the
575 property name and and @code{#} preceding the new value!
577 The final question is, @q{Where should this command be
578 placed?} While you are unsure and learning, the best
579 answer is, @q{Within the music, before the first slur and
580 close to it.} Let's do that:
583 @cindex thickness property, example
585 @lilypond[quote,verbatim,relative=2]
589 % Increase thickness of all following slurs from 1.2 to 5.0
590 \override Slur #'thickness = #5.0
592 g[( e]) e d[( f]) a |
596 The man who feels love's sweet e -- mo -- tion
602 and we see that the slur is indeed heavier.
604 So this is the basic way of constructing @code{\override}
605 commands. There are a few more complications that we
606 shall meet in later sections, but you now know all the
607 essentials required to make up your own -- but you will
608 still need some practice. This is provided in the examples
611 @subheading Finding the context
613 @cindex context, finding
614 @cindex context, identifying correct
616 But first, what if we had needed to specify the Context?
617 What should it be? We could guess that slurs are in
618 the Voice context, as they are clearly closely associated
619 with individual lines of music, but can we be sure? To
620 find out, go back to the top of the IR page describing the
621 Slur, where it says @q{Slur objects are created by: Slur
622 engraver}. So slurs will be created in whichever context
623 the @code{Slur_engraver} is in. Follow the link to the
624 @code{Slur_engraver} page. At the very bottom it tells
625 us that @code{Slur_engraver} is part of five Voice contexts,
626 including the standard voice context, @code{Voice}, so our
627 guess was correct. And because @code{Voice} is one of the
628 lowest level contexts which is implied unambiguously by
629 the fact that we are entering notes, we can omit it in this
632 @subheading Overriding once only
634 @cindex overriding once only
635 @cindex once override
640 As you can see, @emph{all} the slurs are thicker in the final example
641 above. But what if we wanted just the first slur to be thicker? This
642 is achieved with the @code{\once} command. Placed immediately before
643 the @code{\override} command it causes it to change only the slur
644 which begins on the @strong{immediately following} note. If the
645 immediately following note does not begin a slur the command has no
646 effect at all -- it is not remembered until a slur is encountered, it
647 is simply discarded. So the command with @code{\once} must be
648 repositioned as follows:
651 @cindex thickness property, example
653 @lilypond[quote,verbatim,relative=2]
658 % Increase thickness of immediately following slur only
659 \once \override Slur #'thickness = #5.0
661 g[( e]) e d[( f]) a |
665 The man who feels love's sweet e -- mo -- tion
671 Now only the first slur is made heavier.
673 The @code{\once} command can also be used before the @code{\set}
676 @subheading Reverting
679 @cindex default properties, reverting to
684 Finally, what if we wanted just the first two slurs to be
685 heavier? Well, we could use two commands, each preceded by
686 @code{\once} placed immediately before each of the notes where
690 @cindex thickness property, example
692 @lilypond[quote,verbatim,relative=2]
697 % Increase thickness of immediately following slur only
698 \once \override Slur #'thickness = #5.0
700 % Increase thickness of immediately following slur only
701 \once \override Slur #'thickness = #5.0
702 g[( e]) e d[( f]) a |
706 The man who feels love's sweet e -- mo -- tion
712 or we could omit the @code{\once} command and use the @code{\revert}
713 command to return the @code{thickness} property to its default value
714 after the second slur:
717 @cindex thickness property, example
719 @lilypond[quote,verbatim,relative=2]
724 % Increase thickness of all following slurs from 1.2 to 5.0
725 \override Slur #'thickness = #5.0
728 % Revert thickness of all following slurs to default of 1.2
729 \revert Slur #'thickness
734 The man who feels love's sweet e -- mo -- tion
740 The @code{\revert} command can be used to return any property
741 changed with @code{\override} back to its default value.
742 You may use whichever method best suits what you want to do.
744 That concludes our introduction to the IR, and the basic
745 method of tweaking. Several examples follow in the later
746 sections of this Chapter, partly to introduce you to some of the
747 additional features of the IR, and partly to give you more
748 practice in extracting information from it. These examples will
749 contain progressively fewer words of guidance and explanation.
752 @node Properties found in interfaces
753 @subsection Properties found in interfaces
756 @cindex interface properties
757 @cindex properties in interfaces
759 Suppose now that we wish to print the lyrics in italics. What form of
760 @code{\override} command do we need to do this? We first look in the
761 IR page listing @q{All layout objects}, as before, and look for an
762 object that might control lyrics. We find @code{LyricText}, which
763 looks right. Clicking on this shows the settable properties for lyric
764 text. These include the @code{font-series} and @code{font-size}, but
765 nothing that might give an italic shape. This is because the shape
766 property is one that is common to all font objects, so, rather than
767 including it in every layout object, it is grouped together with other
768 similar common properties and placed in an @strong{Interface}, the
769 @code{font-interface}.
771 So now we need to learn how to find the properties of interfaces,
772 and to discover what objects use these interface properties.
774 Look again at the IR page which describes LyricText. At the bottom of
775 the page is a list of clickable interfaces which LyricText supports.
776 The list has several items, including @code{font-interface}. Clicking
777 on this brings up the properties associated with this interface, which
778 are also properties of all the objects which support it, including
781 Now we see all the user-settable properties which control fonts,
782 including @code{font-shape(symbol)}, where @code{symbol} can be
783 set to @code{upright}, @code{italics} or @code{caps}.
785 You will notice that @code{font-series} and @code{font-size} are also
786 listed there. This immediately raises the question: Why are the
787 common font properties @code{font-series} and @code{font-size} listed
788 under @code{LyricText} as well as under the interface
789 @code{font-interface} but @code{font-shape} is not? The answer is
790 that @code{font-series} and @code{font-size} are changed from their
791 global default values when a @code{LyricText} object is created, but
792 @code{font-shape} is not. The entries in @code{LyricText} then tell
793 you the values for those two properties which apply to
794 @code{LyricText}. Other objects which support @code{font-interface}
795 will set these properties differently when they are created.
797 Let's see if we can now construct the @code{\override} command
798 to change the lyrics to italics. The object is @code{LyricText},
799 the property is @code{font-shape} and the value is
800 @code{italic}. As before, we'll omit the context.
802 As an aside, although it is an important one, note that because the
803 values of @code{font-shape} are symbols they must be introduced with a
804 single apostrophe, @code{'}. That is why apostrophes are needed
805 before @code{thickness} in the earlier example and @code{font-shape}.
806 These are both symbols too. Symbols are then read internally by
807 LilyPond. Some of them are the names of properties, like
808 @code{thickness} or @code{font-shape}, others are used as values that
809 can be given to properties, like @code{italic}. Note the distinction
810 from arbitrary text strings, which would appear as @code{"a text
811 string"}; for more details about symbols and strings, see @ref{Scheme
814 Ok, so the @code{\override} command we need to print the lyrics
818 \override LyricText #'font-shape = #'italic
822 and this should be placed just in front of and close to the
823 lyrics which it should affect, like this:
825 @cindex font-shape property, example
826 @cindex italic example
827 @cindex LyricText example
829 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
834 g[( e]) e d[( f]) a |
838 \override LyricText #'font-shape = #'italic
839 The man who feels love's sweet e -- mo -- tion
845 and the lyrics are all printed in italics.
847 @subheading Specifying the context in lyric mode
849 @cindex context, specifying in lyric mode
850 @cindex lyric mode, specifying context
852 In the case of lyrics, if you try specifying the context in the
853 format given earlier the command will fail. A syllable
854 entered in lyricmode is terminated by either a space,
855 a newline or a digit. All other characters are included
856 as part of the syllable. For this reason a space or newline
857 must appear before the terminating @code{@}} to prevent it being
858 included as part of the final syllable. Similarly,
859 spaces must be inserted before and after the
860 period or dot, @q{.}, separating the context name from the
861 object name, as otherwise the two names are run together and
862 the interpreter cannot recognize them. So the command should be:
865 \override Lyrics . LyricText #'font-shape = #'italic
868 @warning{In lyrics always leave whitespace between the final
869 syllable and the terminating brace.}
871 @warning{In overrides in lyrics always place spaces around
872 the dot between the context name and the object name.}
876 Learning Manual: @ref{Scheme tutorial}.
879 @node Types of properties
880 @subsection Types of properties
882 @cindex property types
884 So far we have seen two types of property: @code{number} and
885 @code{symbol}. To be valid, the value given to a property
886 must be of the correct type and obey the rules for that type.
887 The type of property is always shown in brackets after the
888 property name in the IR. Here is a list of the types you may
889 need, together with the rules for that type, and some examples.
890 You must always add a hash symbol, @code{#}, of course,
891 to the front of these values when they are entered in the
892 @code{\override} command.
894 @multitable @columnfractions .2 .45 .35
895 @headitem Property type
899 @tab Either True or False, represented by #t or #f
900 @tab @code{#t}, @code{#f}
901 @item Dimension (in staff space)
902 @tab A positive decimal number (in units of staff space)
903 @tab @code{2.5}, @code{0.34}
905 @tab A valid direction constant or its numerical equivalent (decimal
906 values between -1 and 1 are allowed)
907 @tab @code{LEFT}, @code{CENTER}, @code{UP},
910 @tab A positive whole number
911 @tab @code{3}, @code{1}
913 @tab A set of values separated by spaces, enclosed in parentheses
914 and preceded by an apostrophe
915 @tab @code{'(left-edge staff-bar)}, @code{'(1)},
916 @code{'(1.0 0.25 0.5)}
918 @tab Any valid markup
919 @tab @code{\markup @{ \italic "cresc." @}}
921 @tab A fraction of a whole note constructed with the
923 @tab @code{(ly:make-moment 1 4)},
924 @code{(ly:make-moment 3 8)}
926 @tab Any positive or negative decimal value
927 @tab @code{3.5}, @code{-2.45}
928 @item Pair (of numbers)
929 @tab Two numbers separated by a @q{space . space} and enclosed
930 in brackets preceded by an apostrophe
931 @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
933 @tab Any of the set of permitted symbols for that property,
934 preceded by an apostrophe
935 @tab @code{'italic}, @code{'inside}
937 @tab A procedure, or @code{#f} to cause no action
938 @tab @code{bend::print}, @code{ly:text-interface::print},
941 @tab A list of three items enclosed in parentheses and preceded
942 by apostrophe-hash, @code{'#}.
943 @tab @code{'#(#t #t #f)}
948 Learning Manual: @ref{Scheme tutorial}.
951 @node Appearance of objects
952 @section Appearance of objects
954 Let us now put what we have learned into practice with a few
955 examples which show how tweaks may be used to change the
956 appearance of the printed music.
959 * Visibility and color of objects::
961 * Length and thickness of objects::
964 @node Visibility and color of objects
965 @subsection Visibility and color of objects
967 In the educational use of music we might wish to print a score
968 with certain elements omitted as an exercise for the student,
969 who is required to supply them. As a simple example,
970 let us suppose the exercise is to supply the missing bar lines
971 in a piece of music. But the bar lines are normally inserted
972 automatically. How do we prevent them printing?
974 Before we tackle this, let us remember that object properties are
975 grouped in what are called @emph{interfaces} -- see @ref{Properties
976 found in interfaces}. This is simply to group together those
977 properties that may be used together to tweak a graphical object -- if
978 one of them is allowed for an object, so are the others. Some objects
979 then use the properties in some interfaces, others use them from other
980 interfaces. The interfaces which contain the properties used by a
981 particular grob are listed in the IR at the bottom of the page
982 describing that grob, and those properties may be viewed by looking at
985 We explained how to find information about grobs in @ref{Properties of
986 layout objects}. Using the same approach, we go to the IR to find the
987 layout object which prints bar lines. Going via @emph{Backend} and
988 @emph{All layout objects} we find there is a layout object called
989 @code{BarLine}. Its properties include two that control its
990 visibility: @code{break-visibility} and @code{stencil}. Barline also
991 supports a number of interfaces, including the @code{grob-interface},
992 where we find the @code{transparent} and the @code{color} properties.
993 All of these can affect the visibility of bar lines (and, of course,
994 by extension, many other layout objects too.) Let's consider each of
999 @cindex stencil property
1001 This property controls the appearance of the bar lines by specifying
1002 the symbol (glyph) which should be printed. In common
1003 with many other properties, it can be set to print nothing by
1004 setting its value to @code{#f}. Let's try it, as before, omitting
1005 the implied Context, @code{Voice}:
1007 @cindex BarLine example
1008 @cindex stencil property, example
1010 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1013 \override BarLine #'stencil = ##f
1015 g, a16 b8 c d4 e16 |
1020 The bar lines are still printed. What is wrong? Go back to the IR
1021 and look again at the page giving the properties of BarLine. At the
1022 top of the page it says @qq{Barline objects are created by:
1023 Bar_engraver}. Go to the @code{Bar_engraver} page. At the bottom it
1024 gives a list of Contexts in which the bar engraver operates. All of
1025 them are of the type @code{Staff}, so the reason the @code{\override}
1026 command failed to work as expected is because @code{Barline} is not in
1027 the default @code{Voice} context. If the context is specified
1028 wrongly, the command simply does not work. No error message is
1029 produced, and nothing is logged in the log file. Let's try correcting
1030 it by adding the correct context:
1032 @cindex BarLine example
1033 @cindex stencil property, example
1035 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1038 \override Staff.BarLine #'stencil = ##f
1040 g, a16 b8 c d4 e16 |
1045 Now the bar lines have vanished.
1047 @subheading break-visibility
1049 @cindex break-visibility property
1051 We see from the @code{BarLine} properties in the IR that the
1052 @code{break-visibility} property requires a vector of three booleans.
1053 These control respectively whether bar lines are printed at the end of
1054 a line, in the middle of lines, and at the beginning of lines. For
1055 our example we want all bar lines to be suppressed, so the value we
1056 need is @code{'#(#f #f #f)}. Let's try that, remembering to include
1057 the @code{Staff} context. Note also that in writing this value we
1058 have @code{#'#} before the opening bracket. The @code{'#} is required
1059 as part of the value to introduce a vector, and the first @code{#} is
1060 required, as always, to precede the value itself in the
1061 @code{\override} command.
1063 @cindex BarLine example
1064 @cindex break-visibility property, example
1066 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1069 \override Staff.BarLine #'break-visibility = #'#(#f #f #f)
1071 g, a16 b8 c d4 e16 |
1076 And we see this too removes all the bar lines.
1078 @subheading transparent
1080 @cindex transparent property
1081 @cindex transparency
1083 We see from the properties specified in the @code{grob-interface} page
1084 in the IR that the @code{transparent} property is a boolean. This
1085 should be set to @code{#t} to make the grob transparent. In this next
1086 example let us make the time signature invisible rather than the bar
1087 lines. To do this we need to find the grob name for the time
1088 signature. Back to the @q{All layout objects} page in the IR to find
1089 the properties of the @code{TimeSignature} layout object. This is
1090 produced by the @code{Time_signature_engraver} which you can check
1091 also lives in the @code{Staff} context and also supports the
1092 @code{grob-interface}. So the command to make the time signature
1095 @cindex TimeSignature example of overriding
1096 @cindex transparent property, example
1098 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1101 \override Staff.TimeSignature #'transparent = ##t
1103 g, a16 b8 c d4 e16 |
1109 The time signature is gone, but this command leaves a gap where
1110 the time signature should be. Maybe this is what is wanted for
1111 an exercise for the student to fill it in, but in other
1112 circumstances a gap might be undesirable. To remove it, the
1113 stencil for the time signature should be set to @code{#f}
1116 @cindex TimeSignature, example of overriding
1117 @cindex stencil property, example
1119 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1122 \override Staff.TimeSignature #'stencil = ##f
1124 g, a16 b8 c d4 e16 |
1130 and the difference is obvious: setting the stencil to @code{#f}
1131 removes the object entirely; making the object @code{transparent}
1132 leaves it where it is, but makes it invisible.
1136 @cindex color property
1138 Finally let us try making the bar lines invisible by coloring
1139 them white. (There is a difficulty with this in that the
1140 white bar line may or may not blank out the staff lines where
1141 they cross. You may see in some of the examples below that this
1142 happens unpredictably. The details of why this is so and how to
1143 control it are covered in @ruser{Painting objects white}. But at
1144 the moment we are learning about color, so please just accept this
1145 limitation for now.)
1147 The @code{grob-interface} specifies that the
1148 color property value is a list, but there is no
1149 explanation of what that list should be. The list it
1150 requires is actually a list of values in internal units,
1151 but, to avoid having to know what these are, several ways
1152 are provided to specify colors. The first way is to use one
1153 of the @q{normal} colors listed in the first table in
1154 @ruser{List of colors}. To set the bar lines to white
1157 @cindex BarLine, example of overriding
1158 @cindex color property, example
1160 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1163 \override Staff.BarLine #'color = #white
1165 g, a16 b8 c d4 e16 |
1171 and again, we see the bar lines are not visible. Note that
1172 @emph{white} is not preceded by an apostrophe -- it is not
1173 a symbol, but a @emph{function}. When called, it provides
1174 the list of internal values required to set the color to
1175 white. The other colors in the normal list are functions
1176 too. To convince yourself this is working you might like
1177 to change the color to one of the other functions in the
1185 The second way of changing the color is to use the list of
1186 X11 color names in the second list in @ruser{List of colors}.
1187 However, these must be preceded by another function, which
1188 converts X11 color names into the list of internal values,
1189 @code{x11-color}, like this:
1191 @cindex BarLine, example of overriding
1192 @cindex color property, example
1194 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1197 \override Staff.BarLine #'color = #(x11-color 'white)
1199 g, a16 b8 c d4 e16 |
1205 Note that in this case the function @code{x11-color} takes
1206 a symbol as an argument, so the symbol must be preceded by
1207 an apostrophe and the two enclosed in brackets.
1214 There is yet a third function, one which converts RGB values into
1215 internal colors -- the @code{rgb-color} function. This takes
1216 three arguments giving the intensities of the red, green and
1217 blue colors. These take values in the range 0 to 1. So to
1218 set the color to red the value should be @code{(rgb-color 1 0 0)}
1219 and to white it should be @code{(rgb-color 1 1 1)}:
1221 @cindex BarLine, example of overriding
1222 @cindex color property, example
1224 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1227 \override Staff.BarLine #'color = #(rgb-color 1 1 1)
1229 g, a16 b8 c d4 e16 |
1234 Finally, there is also a grey scale available as part of the
1235 X11 set of colors. These range from black, @code{'grey0'},
1236 to white, @code{'grey100}, in steps of 1. Let's illustrate
1237 this by setting all the layout objects in our example to
1238 various shades of grey:
1240 @cindex StaffSymbol, example of overriding
1241 @cindex TimeSignature, example of overriding
1242 @cindex Clef, example of overriding
1243 @cindex NoteHead, example of overriding
1244 @cindex Stem, example of overriding
1245 @cindex BarLine, example of overriding
1246 @cindex color property, example
1247 @cindex x11-color, example of using
1249 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1252 \override Staff.StaffSymbol #'color = #(x11-color 'grey30)
1253 \override Staff.TimeSignature #'color = #(x11-color 'grey60)
1254 \override Staff.Clef #'color = #(x11-color 'grey60)
1255 \override Voice.NoteHead #'color = #(x11-color 'grey85)
1256 \override Voice.Stem #'color = #(x11-color 'grey85)
1257 \override Staff.BarLine #'color = #(x11-color 'grey10)
1259 g, a16 b8 c d4 e16 |
1265 Note the contexts associated with each of the layout objects.
1266 It is important to get these right, or the commands will not
1267 work! Remember, the context is the one in which the appropriate
1268 engraver is placed. The default context for engravers can be
1269 found by starting from the layout object, going from there to
1270 the engraver which produces it, and on the engraver page in the
1271 IR it tells you in which context the engraver will normally be
1275 @node Size of objects
1276 @subsection Size of objects
1278 @cindex changing size of objects
1279 @cindex size of objects
1280 @cindex objects, size of
1281 @cindex objects, changing size of
1283 Let us begin by looking again at the earlier example
1284 see @ref{Nesting music expressions}) which showed
1285 how to introduce a new temporary staff, as in an @rglos{ossia}.
1287 @cindex alignAboveContext property, example
1288 @cindex @code{\with} example
1290 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1291 \new Staff ="main" {
1298 alignAboveContext = "main" }
1306 Ossia are normally written without clef and time signature, and
1307 are usually printed slightly smaller than the main staff. We
1308 already know now how to remove the clef and time signature --
1309 we simply set the stencil of each to @code{#f}, as follows:
1311 @cindex alignAboveContext property, example
1312 @cindex @code{\with} example
1313 @cindex stencil property, example
1314 @cindex Clef, example of overriding
1315 @cindex TimeSignature, example of overriding
1317 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1318 \new Staff ="main" {
1325 alignAboveContext = "main"
1328 \override Staff.Clef #'stencil = ##f
1329 \override Staff.TimeSignature #'stencil = ##f
1339 where the extra pair of braces after the @code{\with} clause are
1340 required to ensure the enclosed overrides and music are applied
1343 But what is the difference between modifying the staff context by
1344 using @code{\with} and modifying the stencils of the clef and the
1345 time signature with \override? The main difference is that
1346 changes made in a @code{\with} clause are made at the time the
1347 context is created, and remain in force as the @strong{default}
1348 values for the duration of that context, whereas
1349 @code{\set} or @code{\override} commands embedded in the
1350 music are dynamic -- they make changes synchronized with
1351 a particular point in the music. If changes are unset or
1352 reverted using @code{\unset} or @code{\revert} they return to
1353 their default values, which will be the ones set in the
1354 @code{\with} clause, or if none have been set there, the normal
1357 Some context properties can be modified only in @code{\with} clauses.
1358 These are those properties which cannot sensibly be changed after the
1359 context has been created. @code{alignAboveContext} and its partner,
1360 @code{alignBelowContext}, are two such properties -- once the staff
1361 has been created its alignment is decided and it would make no sense
1362 to try to change it later.
1364 The default values of layout object properties can also be set
1365 in @code{\with} clauses. Simply use the normal @code{\override}
1366 command leaving out the context name, since this is unambiguously
1367 defined as the context which the @code{\with} clause is modifying.
1368 If fact, an error will be generated if a context is specified
1371 So we could replace the example above with
1373 @cindex alignAboveContext property, example
1374 @cindex @code{\with} example
1375 @cindex Clef, example of overriding
1376 @cindex TimeSignature, example of overriding
1378 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1379 \new Staff ="main" {
1386 alignAboveContext = "main"
1387 % Don't print clefs in this staff
1388 \override Clef #'stencil = ##f
1389 % Don't print time signatures in this staff
1390 \override TimeSignature #'stencil = ##f
1399 Finally we come to changing the size of layout objects.
1401 Some layout objects are created as glyphs selected from a typeface
1402 font. These include note heads, accidentals, markup, clefs, time
1403 signatures, dynamics and lyrics. Their size is changed by modifying
1404 the @code{font-size} property, as we shall shortly see. Other layout
1405 objects such as slurs and ties -- in general, spanner objects -- are
1406 drawn individually, so there is no @code{font-size} associated with
1407 them. These objects generally derive their size from the objects to
1408 which they are attached, so usually there is no need to change their
1409 size manually. Still other properties such as the length of stems and
1410 bar lines, thickness of beams and other lines, and the separation of
1411 staff lines all need to be modified in special ways.
1413 Returning to the ossia example, let us first change the font-size.
1414 We can do this in two ways. We can either change the size of the
1415 fonts of each object type, like @code{NoteHead}s with commands
1419 \override NoteHead #'font-size = #-2
1422 or we can change the size of all fonts by setting a special
1423 property, @code{fontSize}, using @code{\set}, or by including
1424 it in a @code{\with} clause (but without the @code{\set}).
1430 Both of these statements would cause the font size to be reduced
1431 by 2 steps from its previous value, where each
1432 step reduces or increases the size by approximately 12%.
1434 Let's try it in our ossia example:
1436 @cindex alignAboveContext property, example
1437 @cindex @code{\with} example
1438 @cindex Clef, example of overriding
1439 @cindex TimeSignature, example of overriding
1441 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1442 \new Staff ="main" {
1449 alignAboveContext = "main"
1450 \override Clef #'stencil = ##f
1451 \override TimeSignature #'stencil = ##f
1452 % Reduce all font sizes by ~24%
1462 This is still not quite right. The note heads and flags are
1463 smaller, but the stems are too long in proportion and the
1464 staff lines are spaced too widely apart. These need to be
1465 scaled down in proportion to the font reduction. The next
1466 sub-section discusses how this is done.
1468 @node Length and thickness of objects
1469 @subsection Length and thickness of objects
1475 @cindex size, changing
1476 @cindex stem length, changing
1477 @cindex staff line spacing, changing
1479 Distances and lengths in LilyPond are generally measured in
1480 staff-spaces, the distance between adjacent lines in the staff,
1481 (or occasionally half staff spaces) while most @code{thickness}
1482 properties are measured in units of an internal property called
1483 @code{line-thickness.} For example, by default, the lines of
1484 hairpins are given a thickness of 1 unit of @code{line-thickness},
1485 while the @code{thickness} of a note stem is 1.3. Note, though,
1486 that some thickness properties are different; for example, the
1487 thickness of beams is measured in staff-spaces.
1489 So how are lengths to be scaled in proportion to the font size?
1490 This can be done with the help of a special function called
1491 @code{magstep} provided for exactly this purpose. It takes
1492 one argument, the change in font size (#-2 in the example above)
1493 and returns a scaling factor suitable for reducing other
1494 objects in proportion. It is used like this:
1496 @cindex alignAboveContext property, example
1497 @cindex @code{\with} example
1498 @cindex Clef, example of overriding
1499 @cindex TimeSignature, example of overriding
1500 @cindex fontsize property, example
1501 @cindex StaffSymbol, example
1502 @cindex magstep, example of using
1504 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1505 \new Staff ="main" {
1512 alignAboveContext = "main"
1513 \override Clef #'stencil = ##f
1514 \override TimeSignature #'stencil = ##f
1516 % Reduce stem length and line spacing to match
1517 \override StaffSymbol #'staff-space = #(magstep -2)
1527 Since the length of stems and many other length-related properties are
1528 always calculated relative to the value of the @code{staff-space}
1529 property these are automatically scaled down in length too. Note that
1530 this affects only the vertical scale of the ossia -- the horizontal
1531 scale is determined by the layout of the main music in order to remain
1532 synchronized with it, so it is not affected by any of these changes in
1533 size. Of course, if the scale of all the main music were changed in
1534 this way then the horizontal spacing would be affected. This is
1535 discussed later in the layout section.
1537 This, then, completes the creation of an ossia. The sizes and
1538 lengths of all other objects may be modified in analogous ways.
1540 For small changes in scale, as in the example above, the
1541 thickness of the various drawn lines such as bar lines,
1542 beams, hairpins, slurs, etc does not usually require global
1543 adjustment. If the thickness of any particular layout object
1544 needs to be adjusted this can be best achieved by overriding its
1545 @code{thickness} property. An example of changing the thickness
1546 of slurs was shown above in @ref{Properties of layout objects}.
1547 The thickness of all drawn objects (i.e., those not produced
1548 from a font) may be changed in the same way.
1551 @node Placement of objects
1552 @section Placement of objects
1555 * Automatic behavior::
1556 * Within-staff objects::
1557 * Outside-staff objects::
1561 @node Automatic behavior
1562 @subsection Automatic behavior
1564 @cindex within-staff objects
1565 @cindex outside-staff objects
1566 @cindex objects, within-staff
1567 @cindex objects, outside-staff
1569 There are some objects in musical notation that belong to
1570 the staff and there are other objects that should be
1571 placed outside the staff. These are called within-staff
1572 objects and outside-staff objects respectively.
1574 Within-staff objects are those that are located on the staff
1575 -- note heads, stems, accidentals, etc. The positions of
1576 these are usually fixed by the music itself -- they are
1577 vertically positioned on specific lines of the staff or are
1578 tied to other objects that are so positioned. Collisions of
1579 note heads, stems and accidentals in closely set chords are
1580 normally avoided automatically. There are commands and
1581 overrides which can modify this automatic behavior, as we
1584 Objects belonging outside the staff include things such as
1585 rehearsal marks, text and dynamic markings. LilyPond's rule for
1586 the vertical placement of outside-staff objects is to place them
1587 as close to the staff as possible but not so close that they
1588 collide with any other object. LilyPond uses the
1589 @code{outside-staff-priority} property to determine the order in
1590 which the objects should be placed, as follows.
1592 First, LilyPond places all the within-staff objects.
1593 Then it sorts the outside-staff objects according to their
1594 @code{outside-staff-priority}. The outside-staff objects are
1595 taken one by one, beginning with the object with the lowest
1596 @code{outside-staff-priority}, and placed so that they do not
1597 collide with any objects that have already been placed. That is,
1598 if two outside-staff grobs are competing for the same space, the
1599 one with the lower @code{outside-staff-priority} will be placed
1600 closer to the staff. If two objects have the same
1601 @code{outside-staff-priority} the one encountered first will be
1602 placed closer to the staff.
1604 In the following example all the markup texts have the same
1605 priority (since it is not explicitly set). Note that @q{Text3}
1606 is automatically positioned close to the staff again, nestling
1609 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1616 Staves are also positioned, by default, as closely together as
1617 possible (subject to a minimum separation). If notes project
1618 a long way towards an adjacent staff they will force the
1619 staves further apart only if an overlap of the notation
1620 would otherwise occur. The following example demonstrates
1621 this @q{nestling} of the notes on adjacent staves:
1623 @lilypond[quote,ragged-right,verbatim]
1626 \relative c' { c a, }
1629 \relative c'''' { c a, }
1635 @node Within-staff objects
1636 @subsection Within-staff objects
1638 We have already seen how the commands @code{\voiceXXX} affect
1639 the direction of slurs, ties, fingering and
1640 everything else which depends on the direction of the stems.
1641 These commands are essential when writing polyphonic music to
1642 permit interweaving melodic lines to be distinguished.
1643 But occasionally it may be necessary to override this automatic
1644 behavior. This can be done for whole sections of music or even
1645 for an individual note. The property which controls this
1646 behavior is the @code{direction} property of each layout object.
1647 We first explain what this does, and then introduce a number of
1648 ready-made commands which avoid your having to code explicit
1649 overrides for the more common modifications.
1651 Some layout objects like slurs and ties curve, bend or point
1652 either up or down; others like stems and flags also move to
1653 right or left when they point up or down. This is controlled
1654 automatically when @code{direction} is set.
1661 The following example shows in bar 1 the default behavior of stems,
1662 with those on high notes pointing down and those on low notes pointing
1663 up, followed by four notes with all stems forced down, four notes with
1664 all stems forced up, and finally four notes reverted back to the
1667 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1669 \override Stem #'direction = #DOWN
1671 \override Stem #'direction = #UP
1673 \revert Stem #'direction
1677 Here we use the constants @code{DOWN} and @code{UP}.
1678 These have the values @code{-1} and @code{+1} respectively, and
1679 these numerical values may be used instead. The value @code{0}
1680 may also be used in some cases. It is simply treated as meaning
1681 @code{UP} for stems, but for some objects it means @q{center}.
1682 There is a constant, @code{CENTER} which has the value @code{0}.
1684 However, these explicit overrides are not usually used, as there are
1685 simpler equivalent predefined commands available. Here is a table of
1686 the commonest. The meaning of each is stated where it is not obvious.
1688 @multitable @columnfractions .2 .2 .25 .35
1693 @item @code{\arpeggioArrowDown}
1694 @tab @code{\arpeggioArrowUp}
1695 @tab @code{\arpeggioNormal}
1696 @tab Arrow is at bottom, at top, or no arrow
1697 @item @code{\dotsDown}
1699 @tab @code{\dotsNeutral}
1700 @tab Direction of movement to avoid staff lines
1701 @item @code{\dynamicDown}
1702 @tab @code{\dynamicUp}
1703 @tab @code{\dynamicNeutral}
1705 @item @code{\phrasingSlurDown}
1706 @tab @code{\phrasingSlurUp}
1707 @tab @code{\phrasingSlurNeutral}
1708 @tab Note: distinct from slur commands
1709 @item @code{\slurDown}
1711 @tab @code{\slurNeutral}
1713 @item @code{\stemDown}
1715 @tab @code{\stemNeutral}
1717 @item @code{\textSpannerDown}
1718 @tab @code{\textSpannerUp}
1719 @tab @code{\textSpannerNeutral}
1720 @tab Text entered as spanner is below/above staff
1721 @item @code{\tieDown}
1723 @tab @code{\tieNeutral}
1725 @item @code{\tupletDown}
1726 @tab @code{\tupletUp}
1727 @tab @code{\tupletNeutral}
1728 @tab Tuplets are below/above notes
1731 Note that these predefined commands may @strong{not} be
1732 preceded by @code{\once}. If you wish to limit the
1733 effect to a single note you must either use the equivalent
1734 @code{\once \override} command or use the predefined command
1735 followed after the affected note by the corresponding
1736 @code{\xxxNeutral} command.
1738 @subheading Fingering
1740 @cindex fingering, placement
1741 @cindex fingering, chords
1743 The placement of fingering on single notes can also be controlled
1744 by the @code{direction} property, but changing @code{direction}
1745 has no effect on chords. As we shall see, there are special
1746 commands which allow the fingering of individual notes
1747 of chords to be controlled, with the fingering being placed
1748 above, below, to the left or to the right of each note.
1750 First, here's the effect of @code{direction} on the fingering
1751 attached to single notes. The first bar shows the default
1752 behaviour, and the following two bars shows the effect of
1753 specifying @code{DOWN} and @code{UP}:
1755 @lilypond[quote,verbatim,relative=2]
1757 \override Fingering #'direction = #DOWN
1759 \override Fingering #'direction = #UP
1763 However, overriding the @code{direction} property is not the
1764 easiest way of manually setting the fingering above or below
1765 the notes; using @code{_} or @code{^} instead of @code{-} before
1766 the fingering number is usually preferable. Here is the previous
1767 example using this method:
1769 @lilypond[quote,verbatim,relative=2]
1775 The @code{direction} property is ignored for chords, but the
1776 directional prefixes, @code{_} and @code{^} do work. By default,
1777 the fingering is automatically placed both above and below the
1778 notes of a chord, as shown:
1780 @lilypond[quote,verbatim,relative=2]
1787 but this may be overriden to manually force all or any of the
1788 individual fingering numbers above or below:
1790 @lilypond[quote,verbatim,relative=2]
1796 Even greater control over the placement of fingering of the
1797 individual notes in a chord is possible by using the
1798 @code{\set fingeringOrientations} command. The format of this
1802 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
1806 @code{\set} is used because @code{fingeringOrientations} is a
1807 property of the @code{Voice} context, created and used by the
1808 @code{New_fingering_engraver}.
1810 The property may be set to a list of one to three values.
1811 It controls whether fingerings may be placed above (if
1812 @code{up} appears in the list), below (if @code{down} appears),
1813 to the left (if @code{left} appears, or to the right
1814 (if @code{right} appears). Conversely, if a location is not
1815 listed, no fingering is placed there. LilyPond takes these
1816 constraints and works out the best placement for the fingering
1817 of the notes of the following chords. Note that @code{left} and
1818 @code{right} are mutually exclusive -- fingering may be placed
1819 only on one side or the other, not both.
1821 @warning{To control the placement of the fingering of a single
1822 note using this command it is necessary to write it as a single
1823 note chord by placing angle brackets round it.}
1825 Here are a few examples:
1827 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1828 \set fingeringOrientations = #'(left)
1830 < c-1 e-2 g-3 b-5 > 4
1831 \set fingeringOrientations = #'(left)
1833 < c-1 e-2 g-3 b-5 > 4
1834 \set fingeringOrientations = #'(up left down)
1836 < c-1 e-2 g-3 b-5 > 4
1837 \set fingeringOrientations = #'(up left)
1839 < c-1 e-2 g-3 b-5 > 4
1840 \set fingeringOrientations = #'(right)
1842 < c-1 e-2 g-3 b-5 > 4
1846 If the fingering seems a little crowded the @code{font-size}
1847 could be reduced. The default value can be seen from the
1848 @code{Fingering} object in the IR to be @code{-5}, so let's
1851 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1852 \override Fingering #'font-size = #-7
1853 \set fingeringOrientations = #'(left)
1855 < c-1 e-2 g-3 b-5 > 4
1856 \set fingeringOrientations = #'(left)
1858 < c-1 e-2 g-3 b-5 > 4
1859 \set fingeringOrientations = #'(up left down)
1861 < c-1 e-2 g-3 b-5 > 4
1862 \set fingeringOrientations = #'(up left)
1864 < c-1 e-2 g-3 b-5 > 4
1865 \set fingeringOrientations = #'(right)
1867 < c-1 e-2 g-3 b-5 > 4
1870 @node Outside-staff objects
1871 @subsection Outside-staff objects
1873 Outside-staff objects are automatically placed to avoid collisions.
1874 Objects with the lower value of the @code{outside-staff-priority}
1875 property are placed nearer to the staff, and other outside-staff
1876 objects are then raised as far as necessary to avoid collisions.
1877 The @code{outside-staff-priority} is defined in the
1878 @code{grob-interface} and so is a property of all layout objects.
1879 By default it is set to @code{#f} for all within-staff objects,
1880 and to a numerical value appropriate to each outside-staff object
1881 when the object is created. The following table shows
1882 the default numerical values for some of the commonest
1883 outside-staff objects which are, by default, placed in the
1884 @code{Staff} or @code{Voice} contexts.
1886 @multitable @columnfractions .3 .3 .3
1887 @headitem Layout Object
1889 @tab Controls position of:
1890 @item @code{MultiMeasureRestText}
1892 @tab Text over full-bar rests
1893 @item @code{TextScript}
1896 @item @code{OttavaBracket}
1898 @tab Ottava brackets
1899 @item @code{TextSpanner}
1902 @item @code{DynamicLineSpanner}
1904 @tab All dynamic markings
1905 @item @code{VoltaBracketSpanner}
1908 @item @code{TrillSpanner}
1910 @tab Spanning trills
1913 Here is an example showing the default placement of some of
1916 @cindex text spanner
1917 @cindex ottava bracket
1919 @funindex \startTextSpan
1920 @funindex startTextSpan
1921 @funindex \stopTextSpan
1922 @funindex stopTextSpan
1925 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1926 % Set details for later Text Spanner
1927 \override TextSpanner #'bound-details #'left #'text
1928 = \markup { \small \bold Slower }
1929 % Place dynamics above staff
1931 % Start Ottava Bracket
1936 % Add Dynamic Line Spanner
1942 c\ff c \stopTextSpan
1943 % Stop Ottava Bracket
1948 This example also shows how to create Text Spanners --
1949 text with extender lines above a section of music. The
1950 spanner extends from the @code{\startTextSpan} command to
1951 the @code{\stopTextSpan} command, and the format of the
1952 text is defined by the @code{\override TextSpanner} command.
1953 For more details see @ruser{Text spanners}.
1955 It also shows how ottava brackets are created.
1957 @cindex tweaking bar number placement
1958 @cindex bar numbers, tweaking placement
1959 @cindex tweaking metronome mark placement
1960 @cindex metronome mark, tweaking placement
1961 @cindex tweaking rehearsal mark placement
1962 @cindex rehearsal marks, tweaking placement
1964 Note that bar numbers, metronome marks and rehearsal marks are not
1965 shown. By default these are created in the @code{Score} context and
1966 their @code{outside-staff-priority} is ignored relative to the layout
1967 objects which are created in the @code{Staff} context. If you wish to
1968 place bar numbers, metronome marks or rehearsal marks in accordance
1969 with the value of their @code{outside-staff-priority} the
1970 @code{Bar_number_engraver}, @code{Metronome_mark_engraver} or
1971 @code{Mark_engraver} respectively should be removed from the
1972 @code{Score} context and placed in the top @code{Staff} context. If
1973 this is done, these marks will be given the following default
1974 @code{outside-staff-priority} values:
1976 @multitable @columnfractions .3 .3
1977 @headitem Layout Object @tab Priority
1978 @item @code{RehearsalMark} @tab @code{1500}
1979 @item @code{MetronomeMark} @tab @code{1000}
1980 @item @code{BarNumber} @tab @code{ 100}
1983 If the default values of @code{outside-staff-priority} do not give you
1984 the placing you want, the priority of any of the objects may be
1985 overridden. Suppose we would like the ottava bracket to be placed
1986 below the text spanner in the example above. All we need to do is to
1987 look up the priority of @code{OttavaBracket} in the IR or in the
1988 tables above, and reduce it to a value lower than that of a
1989 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
1990 in the @code{Staff} context:
1992 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1993 % Set details for later Text Spanner
1994 \override TextSpanner #'bound-details #'left #'text
1995 = \markup { \small \bold Slower }
1996 % Place dynamics above staff
1998 %Place following Ottava Bracket below Text Spanners
1999 \once \override Staff.OttavaBracket #'outside-staff-priority = #340
2000 % Start Ottava Bracket
2005 % Add Dynamic Line Spanner
2011 c\ff c \stopTextSpan
2012 % Stop Ottava Bracket
2017 Changing the @code{outside-staff-priority} can also be used to
2018 control the vertical placement of individual objects, although
2019 the results may not always be desirable. Suppose we would
2020 like @qq{Text3} to be placed above @qq{Text4} in the example
2021 under Automatic behavior, above (see @ref{Automatic behavior}).
2022 All we need to do is to look up the priority of @code{TextScript}
2023 in the IR or in the tables above, and increase the priority of
2024 @qq{Text3} to a higher value:
2026 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2029 \once \override TextScript #'outside-staff-priority = #500
2034 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2035 above @qq{Text2}, and @qq{Text4} now drops down. Perhaps this is not
2036 so good. What we would really like to do is to position all the
2037 annotation at the same distance above the staff. To do this, we
2038 clearly will need to space the notes out horizontally to make more
2039 room for the text. This is done using the @code{textLengthOn}
2042 @subheading \textLengthOn
2044 @cindex notes, spreading out with text
2046 @funindex \textLengthOn
2047 @funindex textLengthOn
2048 @funindex \textLengthOff
2049 @funindex textLengthOff
2051 By default, text produced by markup takes up no horizontal space
2052 as far as laying out the music is concerned. The @code{\textLengthOn}
2053 command reverses this behavior, causing the notes to be spaced
2054 out as far as is necessary to accommodate the text:
2056 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2057 \textLengthOn % Cause notes to space out to accommodate text
2064 The command to revert to the default behavior is
2065 @code{\textLengthOff}. Remember @code{\once} only works with
2066 @code{\override}, @code{\set}, @code{\revert} or @code{unset},
2067 so cannot be used with @code{\textLengthOn}.
2069 @cindex markup text, allowing collisions
2071 Markup text will also avoid notes which project above the staff.
2072 If this is not desired, the automatic displacement upwards may
2073 be turned off by setting the priority to @code{#f}. Here's an
2074 example to show how markup text interacts with such notes.
2076 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2077 % This markup is short enough to fit without collision
2081 % This is too long to fit, so it is displaced upwards
2085 % Turn off collision avoidance
2086 \once \override TextScript #'outside-staff-priority = ##f
2090 % Turn off collision avoidance
2091 \once \override TextScript #'outside-staff-priority = ##f
2092 \textLengthOn % and turn on textLengthOn
2093 c,,2^"Long Text " % Spaces at end are honored
2098 @subheading Dynamics
2100 @cindex tweaking dynamics placement
2101 @cindex dynamics, tweaking placement
2103 Dynamic markings will normally be positioned beneath the
2104 staff, but may be positioned above with the @code{dynamicUp}
2105 command. They will be positioned vertically relative to the
2106 note to which they are attached, and will float below (or above)
2107 all within-staff objects such as phrasing slurs and bar numbers.
2108 This can give quite acceptable results, as this example
2111 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2116 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2117 ees,2.~\)\mf ees4 r8 |
2120 However, if the notes and attached dynamics are close
2121 together the automatic placement will avoid collisions
2122 by displacing later dynamic markings further away, but this may
2123 not be the optimum placement, as this rather artificial example
2126 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2132 Should a similar situation arise in @q{real} music, it may be
2133 preferable to space out the notes a little further, so the dynamic
2134 markings can all fit at the same vertical distance from the staff. We
2135 were able to do this for markup text by using the @code{\textLengthOn}
2136 command, but there is no equivalent command for dynamic marks. So we
2137 shall have to work out how to do this using @code{\override} commands.
2139 @subheading Grob sizing
2142 @cindex sizing grobs
2144 First we must learn how grobs are sized. All grobs have a
2145 reference point defined within them which is used to position
2146 them relative to their parent object. This point in the grob
2147 is then positioned at a horizontal distance, @code{X-offset},
2148 and at a vertical distance, @code{Y-offset}, from its parent.
2149 The horizontal extent of the object is given by a pair of
2150 numbers, @code{X-extent}, which say where the left and right
2151 edges are relative to the reference point. The vertical extent
2152 is similarly defined by a pair of numbers, @code{Y-extent}.
2153 These are properties of all grobs which support the
2154 @code{grob-interface}.
2156 @cindex @code{extra-spacing-width}
2158 By default, outside-staff objects are given a width of zero so
2159 that they may overlap in the horizontal direction. This is done
2160 by the trick of adding infinity to the leftmost extent and
2161 minus infinity to the rightmost extent by setting the
2162 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}. So
2163 to ensure they do not overlap in the horizontal direction we
2164 must override this value of @code{extra-spacing-width} to
2165 @code{'(0 . 0)} so the true width shines through. This is
2166 the command to do this for dynamic text:
2169 \override DynamicText #'extra-spacing-width = #'(0 . 0)
2173 Let's see if this works in our previous example:
2175 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2177 \override DynamicText #'extra-spacing-width = #'(0 . 0)
2182 Well, it has certainly stopped the dynamic marks being
2183 displaced, but two problems remain. The marks should be
2184 spaced a little further apart and it would be better
2185 if they were all the same distance from the staff.
2186 We can solve the first problem easily. Instead of making
2187 the @code{extra-spacing-width} zero we could add a little
2188 more to it. The units are the space between two staff
2189 lines, so moving the left edge half a unit to the left and the
2190 right edge half a unit to the right should do it:
2192 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2194 % Extend width by 1 staff space
2195 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
2200 This looks better, but maybe we would prefer the dynamic marks
2201 to be aligned along the same baseline rather than going up and
2202 down with the notes. The property to do this is
2203 @code{staff-padding} which is covered in the following section.
2206 @node Collisions of objects
2207 @section Collisions of objects
2211 * Fixing overlapping notation::
2212 * Real music example::
2215 @node Moving objects
2216 @subsection Moving objects
2218 @cindex moving overlapping objects
2219 @cindex moving colliding objects
2220 @cindex moving colliding grobs
2221 @cindex objects, moving colliding
2222 @cindex grobs, moving colliding
2224 This may come as a surprise, but LilyPond is not perfect. Some
2225 notation elements can overlap. This is unfortunate, but in fact
2226 rather rare. Usually the need to move objects is for clarity or
2227 aesthetic reasons -- they would look better with a little more
2228 or a little less space around them.
2230 There are three main approaches to resolving overlapping
2231 notation. They should be considered in the following order:
2235 The @strong{direction} of one of the overlapping objects may
2236 be changed using the predefined commands listed above for
2237 within-staff objects (see @ref{Within-staff objects}).
2238 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2239 repositioned easily in this way. The limitation is that you
2240 have a choice of only two positions, and neither may be
2244 The @strong{object properties}, which LilyPond uses when positioning
2245 layout objects, may be modified using @code{\override}. The
2246 advantages of making changes to this type of property are (a) that
2247 some other objects will be moved automatically if necessary to make
2248 room and (b) the single override can apply to all instances of the
2249 same type of object. Such properties include:
2256 This has already been covered in some detail -- see
2257 @ref{Within-staff objects}.
2260 @code{padding}, @code{left-padding},
2261 @code{right-padding}, @code{staff-padding}
2264 @cindex left-padding property
2265 @cindex padding property
2266 @cindex right-padding property
2267 @cindex staff-padding property
2269 As an object is being positioned the value of its @code{padding}
2270 property specifies the gap that must be left between itself and the
2271 nearest edge of the object against which it is being positioned. Note
2272 that it is the @code{padding} value of the object @strong{being
2273 placed} that is used; the @code{padding} value of the object which is
2274 already placed is ignored. Gaps specified by @code{padding} can be
2275 applied to all objects which support the
2276 @code{side-position-interface}.
2278 Instead of @code{padding}, the placement of groups of accidentals
2279 is controlled by @code{left-padding} and @code{right-padding}.
2280 These properties are to be found in the @code{AccidentalPlacement}
2281 object which, note, lives in the @strong{staff} context. In the
2282 type-setting process the note heads are type-set first and then
2283 the accidentals, if any, are added to the left of the note heads
2284 using the @code{right-padding} property to determine the separation
2285 from the note heads. So only the @code{right-padding} property of the
2286 @code{AccidentalPlacement} object has any effect on the placement
2289 The @code{staff-padding} property is closely related to the
2290 @code{padding} property: @code{padding} controls the minimum amount of
2291 space between any object which supports the
2292 @code{side-position-interface} and the nearest other object (generally
2293 the note or the staff lines); @code{staff-padding} applies only to
2294 those objects which are always set outside the staff -- it controls
2295 the minimum amount of space that should be inserted between that
2296 object and the staff. Note that @code{staff-padding} has no effect on
2297 objects which are positioned relative to the note rather than the
2298 staff, even though it may be overridden without error for such objects
2299 -- it is simply ignored.
2301 To discover which padding property is required for the object you wish
2302 to reposition, you need to return to the IR and look up the object's
2303 properties. Be aware that the padding properties might not be located
2304 in the obvious object, so look in objects that appear to be related.
2306 All padding values are measured in staff spaces. For most
2307 objects, this value is set by default to be around 1.0 or less
2308 (it varies with each object). It may be overridden if a larger
2309 (or smaller) gap is required.
2312 @code{self-alignment-X}
2314 @cindex self-alignment-X property
2316 This property can be used to align the object to the left, to
2317 the right, or to center it with respect to the parent object's
2318 reference point. It may be used with all objects which support
2319 the @code{self-alignment-interface}. In general these are objects
2320 that contain text. The values are @code{LEFT}, @code{RIGHT}
2321 or @code{CENTER}. Alternatively, a numerical value between
2322 @code{-1} and @code{+1} may be specified, where @code{-1} is
2323 left-aligned, @code{+1} is right-aligned, and numbers in between
2324 move the text progressively from left-aligned to right-aligned.
2325 Numerical values greater than @code{1} may be specified to move
2326 the text even further to the left, or less than @code{-1} to
2327 move the text even further to the right. A change of @code{1}
2328 in the value corresponds to a movement of half the text's length.
2331 @code{extra-spacing-width}
2333 @cindex extra-spacing-width property
2335 This property is available for all objects which support the
2336 @code{item-interface}. It takes two numbers, the first is added
2337 to the leftmost extent and the second is added to the rightmost
2338 extent. Negative numbers move the edge to the left, positive to
2339 the right, so to widen an object the first number must be negative,
2340 the second positive. Note that not all objects honor both
2341 numbers. For example, the @code{Accidental} object only takes
2342 notice of the first (left edge) number.
2345 @code{staff-position}
2347 @cindex staff-position property
2349 @code{staff-position} is a property of the
2350 @code{staff-symbol-referencer-interface}, which is supported by
2351 objects which are positioned relative to the staff. It specifies
2352 the vertical position of the object relative to the center line
2353 of the staff in half staff-spaces. It is useful in resolving
2354 collisions between layout objects like multi-measure rests, ties
2355 and notes in different voices.
2360 @cindex force-hshift property
2362 Closely spaced notes in a chord, or notes occurring at the same
2363 time in different voices, are arranged in two, occasionally more,
2364 columns to prevent the note heads overlapping. These are called
2365 note columns, and an object called @code{NoteColumn} is created
2366 to lay out the notes in that column.
2368 The @code{force-hshift} property is a property of a @code{NoteColumn}
2369 (actually of the @code{note-column-interface}). Changing it permits a
2370 note column to be moved in units appropriate to a note column,
2371 viz. the note head width of the first voice note. It should be used
2372 in complex situations where the normal @code{\shiftOn} commands (see
2373 @ref{Explicitly instantiating voices}) do not resolve the note
2374 conflict. It is preferable to the @code{extra-offset} property for
2375 this purpose as there is no need to work out the distance in
2376 staff-spaces, and moving the notes into or out of a @code{NoteColumn}
2377 affects other actions such as merging note heads.
2382 Finally, when all else fails, objects may be manually repositioned
2383 relative to the staff center line vertically, or by displacing them by
2384 any distance to a new position. The disadvantages are that the
2385 correct values for the repositioning have to be worked out, often by
2386 trial and error, for every object individually, and, because the
2387 movement is done after LilyPond has placed all other objects, the user
2388 is responsible for avoiding any collisions that might ensue. But the
2389 main difficulty with this approach is that the repositioning values
2390 may need to be reworked if the music is later modified. The
2391 properties that can be used for this type of manual repositioning are:
2396 @cindex extra-offset property
2398 This property applies to any layout object supporting the
2399 @code{grob-interface}. It takes a pair of numbers which specify the
2400 extra displacement in the horizontal and vertical directions.
2401 Negative numbers move the object to the left or down. The units are
2402 staff-spaces. The extra displacement is made after the typesetting of
2403 objects is finished, so an object may be repositioned anywhere without
2404 affecting anything else.
2408 @cindex positions property
2410 This is most useful for manually adjusting the slope and height
2411 of beams, slurs, and tuplets. It takes a pair of numbers
2412 giving the position of the left and right ends of the beam, slur,
2413 etc. relative to the center line of the staff. Units are
2414 staff-spaces. Note, though, that slurs and phrasing slurs cannot
2415 be repositioned by arbitrarily large amounts. LilyPond first
2416 generates a list of possible positions for the slur and by default
2417 finds the slur that @qq{looks best}. If the @code{positions}
2418 property has been overridden the slur that is closest to the
2419 requested positions is selected from the list.
2424 A particular object may not have all of these properties.
2425 It is necessary to go to the IR to look up which properties
2426 are available for the object in question.
2428 Here is a list of the objects which are most likely to be
2429 involved in collisions, together with the name of the object which
2430 should be looked up in the IR in order to discover which properties
2431 should be used to move them.
2433 @multitable @columnfractions .5 .5
2434 @headitem Object type @tab Object name
2435 @item Articulations @tab @code{Script}
2436 @item Beams @tab @code{Beam}
2437 @item Dynamics (vertically) @tab @code{DynamicLineSpanner}
2438 @item Dynamics (horizontally) @tab @code{DynamicText}
2439 @item Fingerings @tab @code{Fingering}
2440 @item Rehearsal / Text marks @tab @code{RehearsalMark}
2441 @item Slurs @tab @code{Slur}
2442 @item Text e.g. @code{^"text"} @tab @code{TextScript}
2443 @item Ties @tab @code{Tie}
2444 @item Tuplets @tab @code{TupletBracket}
2448 @node Fixing overlapping notation
2449 @subsection Fixing overlapping notation
2451 Let's now see how the properties in the previous section can
2452 help to resolve overlapping notation.
2454 @subheading padding property
2457 @cindex fixing overlapping notation
2458 @cindex overlapping notation
2460 The @code{padding} property can be set to increase
2461 (or decrease) the distance between symbols that are printed
2462 above or below notes.
2464 @lilypond[quote,fragment,relative=1,verbatim]
2466 \override Script #'padding = #3
2470 @lilypond[quote,fragment,relative=1,verbatim]
2471 % This will not work, see below:
2472 \override MetronomeMark #'padding = #3
2476 \override Score.MetronomeMark #'padding = #3
2481 Note in the second example how important it is to figure out what
2482 context handles a certain object. Since the @code{MetronomeMark}
2483 object is handled in the @code{Score} context, property changes in the
2484 @code{Voice} context will not be noticed. For more details, see
2485 @ruser{Modifying properties}.
2487 If the @code{padding} property of an object is increased when that
2488 object is in a stack of objects being positioned according to
2489 their @code{outside-staff-priority}, then that object and all
2490 objects outside it are moved.
2493 @subheading left-padding and right-padding
2495 @cindex left-padding property
2496 @cindex right-padding property
2498 The @code{right-padding} property affects the spacing between the
2499 accidental and the note to which it applies. It is not often
2500 required, but the following example shows one situation where it
2501 is needed. Suppose we wish to show a chord containing both
2502 a B-natural and a B-flat. To avoid ambiguity we would like to
2503 precede the notes with both a natural and a flat sign. Here
2504 are a few attempts to do this:
2506 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2512 None work, with the second two showing bad collisions between
2515 One way of achieving this is to override the accidental stencil
2516 with a markup containing the natural and flat symbols in the
2517 order we would like, like this:
2519 @lilypond[quote,ragged-right,verbatim]
2520 naturalplusflat = \markup { \natural \flat }
2522 \once \override Accidental
2523 #'stencil = #ly:text-interface::print
2524 \once \override Accidental #'text = #naturalplusflat
2525 \once \override Score.AccidentalPlacement #'right-padding = #1.5
2531 This necessarily uses an override for the accidental stencil which
2532 will not be covered until later. The stencil type must be a
2533 procedure, here changed to print the contents of the @code{text}
2534 property of @code{Accidental}, which itself is set to be a natural
2535 sign followed by a flat sign. These are then moved further away
2536 from the note head by overriding @code{right-padding}.
2540 @subheading staff-padding property
2542 @cindex aligning objects on a baseline
2543 @cindex objects, aligning on a baseline
2545 @code{staff-padding} can be used to align objects such as dynamics
2546 along a baseline at a fixed height above the staff, rather than at a
2547 height dependent on the position of the note to which they are
2548 attached. It is not a property of @code{DynamicText} but of
2549 @code{DynamicLineSpanner}. This is because the baseline should apply
2550 equally to @strong{all} dynamics, including those created as extended
2551 spanners. So this is the way to align the dynamic marks in the
2552 example taken from the previous section:
2554 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2556 % Extend width by 1 unit
2557 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
2558 % Align dynamics to a base line 2 units above staff
2559 \override DynamicLineSpanner #'staff-padding = #2
2564 @subheading self-alignment-X property
2566 The following example shows how this can resolve the collision
2567 of a string fingering object with a note's stem by aligning the
2568 right edge with the reference point of the parent note:
2570 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
2573 \once \override StringNumber #'self-alignment-X = #RIGHT
2577 @subheading staff-position property
2579 @cindex object collision within a staff
2581 Multimeasure rests in one voice can collide with notes in another.
2582 Since these rests are typeset centered between the bar lines, it
2583 would require significant effort for LilyPond to figure out which
2584 other notes might collide with it, since all the current collision
2585 handling between notes and between notes and rests is done only
2586 for notes and rests that occur at the same time. Here's an
2587 example of a collision of this type:
2589 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2590 << {c c c c} \\ {R1} >>
2593 The best solution here is to move the multimeasure rest down, since
2594 the rest is in voice two. The default in @code{\voiceTwo} (i.e. in
2595 the second voice of a @code{<<@{...@} \\ @{...@}>>} construct) is that
2596 @code{staff-position} is set to -4 for MultiMeasureRest, so we need to
2597 move it, say, four half-staff spaces down to @code{-8}.
2599 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2603 \override MultiMeasureRest #'staff-position = #-8
2608 This is better than using, for example, @code{extra-offset},
2609 because the ledger line above the rest is inserted automatically.
2611 @subheading extra-offset property
2613 @cindex positioning objects
2614 @cindex positioning grobs
2615 @cindex objects, positioning
2616 @cindex grobs, positioning
2618 The @code{extra-offset} property provides complete control over the
2619 positioning of an object both horizontally and vertically.
2621 In the following example, the second fingering is moved a little to
2622 the left, and 1.8 staff space downwards:
2624 @lilypond[quote,fragment,relative=1,verbatim]
2627 \once \override Fingering
2628 #'extra-offset = #'(-0.3 . -1.8)
2633 @subheading positions property
2635 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
2636 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
2637 @cindex tuplet beams, controlling manually
2638 @cindex slurs, controlling manually
2639 @cindex phrasing slurs, controlling manually
2640 @cindex beams, controlling manually
2642 The @code{positions} property allows the position and slope of
2643 tuplets, slurs, phrasing slurs and beams to be controlled manually.
2644 Here's an example which has an ugly phrasing slur due to its trying to
2645 avoid the slur on the acciaccatura.
2647 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2648 r4 \acciaccatura e8\( d8 c ~c d c d\)
2652 We could simply move the phrasing slur above the notes, and this
2653 would be the preferred solution:
2655 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2658 \acciaccatura e8\( d8 c ~c d c d\)
2662 But if there were some reason why this could not be done the
2663 other alternative would be to move the left end of the phrasing
2664 slur down a little using the @code{positions} property. This
2665 also resolves the rather nasty shape.
2667 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2669 \once \override PhrasingSlur #'positions = #'(-4 . -3)
2671 e8\( d8 c ~c d c d\)
2674 Here's a further example taken from the opening of the left-hand
2675 staff of Chopin's Prelude Op 28 No. 2. We see that the beam
2676 collides with the upper notes:
2678 @lilypond[quote,verbatim,fragment,ragged-right]
2681 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2682 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2687 This can be resolved by manually moving both ends of the beam
2688 up from their position at 2 staff-spaces above the center line to,
2691 @lilypond[quote,verbatim,fragment,ragged-right]
2695 \override Beam #'positions = #'(3 . 3)
2700 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2705 Note that the override continues to apply in the first voice of
2706 the second block of quavers, but not to any of the beams in the
2709 @subheading force-hshift property
2711 @c FIXME: formatting stuff (ie not important right now IMO)
2712 @c @a nchor Chopin finally corrected TODOgp
2714 We can now see how to apply the final corrections to the Chopin
2715 example introduced at the end of @ref{I'm hearing Voices}, which
2716 was left looking like this:
2718 @lilypond[quote,verbatim,fragment,ragged-right]
2719 \new Staff \relative c'' {
2722 { c2 aes4. bes8 } \\
2734 The lower two notes of the first chord (i.e, those in the third voice)
2735 should not be shifted away from the note column of the higher two
2736 notes. To correct this we set @code{force-hshift}, which is a
2737 property of @code{NoteColumn}, of these notes to zero. The lower note
2738 of the second chord is best placed just to the right of the higher
2739 notes. We achieve this by setting @code{force-hshift} of this note to
2740 0.5, ie half a note head's width to the right of the note column of
2743 Here's the final result:
2745 @lilypond[quote,verbatim,fragment,ragged-right]
2746 \new Staff \relative c'' {
2749 { c2 aes4. bes8 } \\
2752 \once \override NoteColumn #'force-hshift = #0 <ees c>2
2753 \once \override NoteColumn #'force-hshift = #0.5 des2
2761 @node Real music example
2762 @subsection Real music example
2764 We end this section on Tweaks by showing the steps to be taken to
2765 deal with a tricky example which needs several tweaks to produce
2766 the desired output. The example has been deliberately chosen to
2767 illustrate the use of the Notation Reference to resolve unusual
2768 problems with notation. It is not representative of more usual
2769 engraving process, so please do not let these difficulties put
2770 you off! Fortunately, difficulties like these are not very common!
2772 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
2773 9, the transition from the opening Lento to Moderato.
2774 Here, first, is what we want the output to look like, but to avoid
2775 over-complicating the example too much we have left out the
2776 dynamics, fingering and pedalling.
2778 @c The following should appear as music without code
2779 @lilypond[quote,ragged-right]
2780 rhMusic = \relative c'' {
2783 \once \override Tie #'staff-position = #3.5
2787 \mergeDifferentlyHeadedOn
2788 \mergeDifferentlyDottedOn
2789 bes2.^\markup {\bold "Moderato"} r8
2791 {c,8[ d fis bes a] | }
2793 % Reposition the c2 to the right of the merged note
2794 {c,8~ \once \override NoteColumn #'force-hshift = #1.0
2795 % Move the c2 out of the main note column so the merge will work
2798 % Stem on the d2 must be down to permit merging
2799 {s8 \stemDown \once \override Stem #'transparent = ##t d2}
2803 \mergeDifferentlyHeadedOff
2804 \mergeDifferentlyDottedOff
2808 lhMusic = \relative c' {
2810 <d g, d>1)\arpeggio |
2817 \new Staff = "RH" <<
2821 \new Staff = "LH" <<
2830 We note first that the right hand part in the third bar
2831 requires four voices. These are the five beamed eighth notes,
2832 the tied C, the half-note D which is merged with the eighth note
2833 D, and the dotted quarter note F-sharp, which is also merged with
2834 the eighth note at the same pitch. Everything else is in a single
2835 voice, so the easiest way is to introduce these four voices
2836 temporarily at the time they are needed. If you have forgotten
2837 how to do this, look at @ref{I'm hearing Voices}. Let us begin
2838 by entering the notes as two variables and setting up the staff
2839 structure in a score block, and see what LilyPond produces by
2842 @lilypond[quote,verbatim,ragged-right]
2843 rhMusic = \relative c'' {
2848 % Start polyphonic section of four voices
2850 {c,8 d fis bes a | }
2861 lhMusic = \relative c' {
2870 \new Staff = "RH" <<
2874 \new Staff = "LH" <<
2883 All the notes are right, but the appearance is far from satisfactory.
2884 The tie clashes with the change in time signature, the beaming in the
2885 third bar is wrong, the notes are not merged together, and several
2886 notation elements are missing. Let's first deal with the easier
2887 things. We can correct the beaming by inserting a beam manually, and
2888 we can easily add the left hand slur and the right hand phrasing slur,
2889 since these were all covered in the Tutorial. Doing this gives:
2891 @lilypond[quote,verbatim,ragged-right]
2892 rhMusic = \relative c'' {
2897 % Start polyphonic section of four voices
2899 {c,8[ d fis bes a] | }
2910 lhMusic = \relative c' {
2919 \new Staff = "RH" <<
2923 \new Staff = "LH" <<
2932 The first bar is now correct. The second bar contains an arpeggio and
2933 is terminated by a double bar line. How do we do these, as they have
2934 not been mentioned in this Learning Manual? This is where we need to
2935 turn to the Notation Reference. Looking up @q{arpeggio} and @q{bar
2936 line} in the index quickly shows us that an arpeggio is produced by
2937 appending @code{\arpeggio} to a chord, and a double bar line is
2938 produced by the @code{\bar "||"} command. That's easily done. We
2939 next need to correct the collision of the tie with the time signature.
2940 This is best done by moving the tie upwards. Moving objects was
2941 covered earlier in @ref{Moving objects}, which says that objects
2942 positioned relative to the staff can be moved by overriding their
2943 @code{staff-position} property, which is specified in half staff
2944 spaces relative to the center line of the staff. So the following
2945 override placed just before the first tied note would move the tie up
2946 to 3.5 half staff spaces above the center line:
2948 @code{\once \override Tie #'staff-position = #3.5}
2950 This completes bar two, giving:
2952 @lilypond[quote,verbatim,ragged-right]
2953 rhMusic = \relative c'' {
2955 \once \override Tie #'staff-position = #3.5
2960 % Start polyphonic section of four voices
2962 {c,8[ d fis bes a] | }
2973 lhMusic = \relative c' {
2975 <d g, d>1)\arpeggio |
2982 \new Staff = "RH" <<
2986 \new Staff = "LH" <<
2995 On to bar three and the start of the Moderato section. The tutorial
2996 showed how to add embolded text with the @code{\markup} command, so
2997 adding @q{Moderato} in bold is easy. But how do we merge notes in
2998 different voices together? This is where we need to turn to the
2999 Notation Reference for help. A search for @qq{merge} in the Notation
3000 Reference index quickly leads us to the commands for merging
3001 differently headed and differently dotted notes in @ruser{Collision
3002 resolution}. In our example we need to merge both types of note for
3003 the duration of the polyphonic section in bar 3, so using the
3004 information we find in the Notation Reference we add
3007 \mergeDifferentlyHeadedOn
3008 \mergeDifferentlyDottedOn
3012 to the start of that section and
3015 \mergeDifferentlyHeadedOff
3016 \mergeDifferentlyDottedOff
3022 @lilypond[quote,verbatim,ragged-right]
3023 rhMusic = \relative c'' {
3025 \once \override Tie #'staff-position = #3.5
3029 bes2.^\markup {\bold "Moderato"} r8
3030 \mergeDifferentlyHeadedOn
3031 \mergeDifferentlyDottedOn
3032 % Start polyphonic section of four voices
3034 {c,8[ d fis bes a] | }
3042 \mergeDifferentlyHeadedOff
3043 \mergeDifferentlyDottedOff
3047 lhMusic = \relative c' {
3049 <d g, d>1)\arpeggio |
3056 \new Staff = "RH" <<
3060 \new Staff = "LH" <<
3069 These overrides have merged the two F-sharp notes, but not the two
3070 on D. Why not? The answer is there in the same section in the
3071 Notation Reference -- notes being merged must have stems in
3072 opposite directions and two notes cannot be merged successfully if
3073 there is a third note in the same note column. Here the two D's
3074 both have upward stems and there is a third note -- the C. We know
3075 how to change the stem direction using @code{\stemDown}, and
3076 the Notation Reference also says how to move the C -- apply a shift
3077 using one of the @code{\shift} commands. But which one?
3078 The C is in voice two which has shift off, and the two D's are in
3079 voices one and three, which have shift off and shift on,
3080 respectively. So we have to shift the C a further level still
3081 using @code{\shiftOnn} to avoid it interfering with the two D's.
3082 Applying these changes gives:
3084 @lilypond[quote,verbatim,ragged-right]
3085 rhMusic = \relative c'' {
3087 \once \override Tie #'staff-position = #3.5
3091 bes2.^\markup {\bold "Moderato"} r8
3092 \mergeDifferentlyHeadedOn
3093 \mergeDifferentlyDottedOn
3094 % Start polyphonic section of four voices
3096 {c,8[ d fis bes a] | }
3098 % Move the c2 out of the main note column so the merge will work
3099 {c,8~ \shiftOnn c2 | }
3101 % Stem on the d2 must be down to permit merging
3102 {s8 \stemDown d2 | }
3106 \mergeDifferentlyHeadedOff
3107 \mergeDifferentlyDottedOff
3111 lhMusic = \relative c' {
3113 <d g, d>1)\arpeggio |
3120 \new Staff = "RH" <<
3124 \new Staff = "LH" <<
3133 Nearly there. Only two problems remain: The downward stem on the
3134 merged D should not be there, and the C would be better positioned
3135 to the right of the D's. We know how to do both of these from the
3136 earlier tweaks: we make the stem transparent, and move the C with
3137 the @code{force-hshift} property. Here's the final result:
3139 @lilypond[quote,verbatim,ragged-right]
3140 rhMusic = \relative c'' {
3143 \once \override Tie #'staff-position = #3.5
3147 bes2.^\markup {\bold "Moderato"} r8
3148 \mergeDifferentlyHeadedOn
3149 \mergeDifferentlyDottedOn
3151 {c,8[ d fis bes a] | }
3153 % Reposition the c2 to the right of the merged note
3154 {c,8~ \once \override NoteColumn #'force-hshift = #1.0
3155 % Move the c2 out of the main note column so the merge will work
3158 % Stem on the d2 must be down to permit merging
3159 {s8 \stemDown \once \override Stem #'transparent = ##t d2}
3163 \mergeDifferentlyHeadedOff
3164 \mergeDifferentlyDottedOff
3168 lhMusic = \relative c' {
3170 <d g, d>1)\arpeggio |
3177 \new Staff = "RH" <<
3181 \new Staff = "LH" <<
3191 @node Further tweaking
3192 @section Further tweaking
3195 * Other uses for tweaks::
3196 * Using variables for tweaks::
3197 * Other sources of information::
3198 * Avoiding tweaks with slower processing::
3199 * Advanced tweaks with Scheme::
3202 @node Other uses for tweaks
3203 @subsection Other uses for tweaks
3205 @cindex transparent property, use of
3206 @cindex objects, making invisible
3207 @cindex removing objects
3208 @cindex objects, removing
3209 @cindex hiding objects
3210 @cindex objects, hiding
3211 @cindex invisible objects
3212 @cindex objects, invisible
3213 @cindex tying notes across voices
3215 @subheading Tying notes across voices
3217 The following example demonstrates how to connect notes in
3218 different voices using ties. Normally, only two notes in the
3219 same voice can be connected with ties. By using two voices,
3220 with the tied notes in one of them
3222 @lilypond[quote,fragment,relative=2]
3223 << { b8~ b8\noBeam }
3229 and blanking the first up-stem in that voice, the tie appears to
3232 @lilypond[quote,fragment,relative=2,verbatim]
3235 \once \override Stem #'transparent = ##t
3243 To make sure that the just-blanked stem doesn't squeeze the tie
3244 too much, we can lengthen the stem by setting the
3245 @code{length} to @code{8},
3247 @lilypond[quote,fragment,relative=2,verbatim]
3250 \once \override Stem #'transparent = ##t
3251 \once \override Stem #'length = #8
3259 @subheading Simulating a fermata in MIDI
3261 @cindex stencil property, use of
3262 @cindex fermata, implementing in MIDI
3264 For outside-staff objects it is usually better to override the
3265 object's @code{stencil} property rather than its @code{transparent}
3266 property when you wish to remove it from the printed output.
3267 Setting the @code{stencil} property of an object to @code{#f} will
3268 remove that object entirely from the printed output. This means it
3269 has no effect on the placement of other objects placed relative to
3272 For example, if we wished to change the metronome setting in order
3273 to simulate a fermata in the MIDI output we would not want the
3274 metronome markings to appear in the printed output, and we would
3275 not want it to influence the spacing between the two systems or
3276 the positions of adjacent annotations on the staff. So setting
3277 its @code{stencil} property to @code{#f} would be the best way.
3278 We show here the effect of the two methods:
3280 @lilypond[quote,verbatim,ragged-right]
3283 % Visible tempo marking
3286 \once \override Score.MetronomeMark #'transparent = ##t
3287 % Invisible tempo marking to lengthen fermata in MIDI
3290 % New tempo for next section
3299 @lilypond[quote,verbatim,ragged-right]
3302 % Visible tempo marking
3305 \once \override Score.MetronomeMark #'stencil = ##f
3306 % Invisible tempo marking to lengthen fermata in MIDI
3309 % New tempo for next section
3319 Both methods remove the metronome mark which lengthens the fermata
3320 from the printed output, and both affect the MIDI timing as
3321 required, but the transparent metronome mark in the first line
3322 forces the following tempo indication too high while the
3323 second (with the stencil removed) does not.
3325 @node Using variables for tweaks
3326 @subsection Using variables for tweaks
3328 @cindex variables, using for tweaks
3329 @cindex using variables for tweaks
3330 @cindex tweaks, using variables for
3332 Override commands are often long and tedious to type, and they
3333 have to be absolutely correct. If the same overrides are to be
3334 used many times it may be worth defining variables to hold them.
3335 Suppose we wish to emphasize certain words in lyrics by printing
3336 them in bold italics. The @code{\italic} and @code{\bold}
3337 commands only work within lyrics if they are also embedded in
3338 @code{\markup}, which makes them tedious to enter, so as an
3339 alternative can we instead use the @code{\override} and
3340 @code{\revert} commands?
3343 @code{\override Lyrics . LyricText #'font-shape = #'italic}
3344 @code{\override Lyrics . LyricText #'font-series = #'bold}
3346 @code{\revert Lyrics . LyricText #'font-shape}
3347 @code{\revert Lyrics . LyricText #'font-series}
3350 These would also be extremely tedious to enter if there were many
3351 words requiring emphasis. So instead we define these as two
3352 variables, and use them as follows, although normally we would
3353 perhaps choose shorter names for the variables to make them
3356 @lilypond[quote,verbatim]
3358 \override Lyrics . LyricText #'font-shape = #'italic
3359 \override Lyrics . LyricText #'font-series = #'bold
3362 \revert Lyrics . LyricText #'font-shape
3363 \revert Lyrics . LyricText #'font-series
3366 global = { \time 4/4 \partial 4 \key c \major}
3367 SopranoMusic = \relative c' { c4 | e4. e8 g4 g | a a g }
3368 AltoMusic = \relative c' { c4 | c4. c8 e4 e | f f e }
3369 TenorMusic = \relative c { e4 | g4. g8 c4. b8 | a8 b c d e4 }
3370 BassMusic = \relative c { c4 | c4. c8 c4 c | f8 g a b c4 }
3371 VerseOne = \lyrics { E -- | ter -- nal \emphasize Fa -- ther, \normal | strong to save, }
3372 VerseTwo = \lyricmode { O | \emphasize Christ, \normal whose voice the | wa -- ters heard, }
3373 VerseThree = \lyricmode { O | \emphasize Ho -- ly Spi -- rit, \normal | who didst brood }
3374 VerseFour = \lyricmode { O | \emphasize Tri -- ni -- ty \normal of | love and pow'r }
3380 \new Voice = "Soprano" { \voiceOne \global \SopranoMusic }
3381 \new Voice = "Alto" { \voiceTwo \AltoMusic }
3382 \new Lyrics \lyricsto "Soprano" { \VerseOne }
3383 \new Lyrics \lyricsto "Soprano" { \VerseTwo }
3384 \new Lyrics \lyricsto "Soprano" { \VerseThree }
3385 \new Lyrics \lyricsto "Soprano" { \VerseFour }
3389 \new Voice = "Tenor" { \voiceOne \TenorMusic }
3390 \new Voice = "Bass" { \voiceTwo \BassMusic }
3398 @node Other sources of information
3399 @subsection Other sources of information
3401 The Internals Reference documentation contains a lot of information
3402 about LilyPond, but even more information can be gathered by
3403 looking at the internal LilyPond files. To explore these, you must
3404 first find the directory appropriate to your system. The location
3405 of this directory depends (a) on whether you obtained LilyPond
3406 by downloading a precompiled binary from lilypond.org
3407 or whether you installed it from a package manager (i.e.
3408 distributed with Linux, or installed under fink or cygwin) or
3409 compiled it from source, and (b) on which operating system it is
3412 @strong{Downloaded from lilypond.org}
3418 @file{@var{INSTALLDIR}/lilypond/usr/share/lilypond/current/}
3423 @file{@var{INSTALLDIR}/LilyPond.app/Contents/Resources/share/lilypond/current/}
3424 by either @code{cd}-ing into this directory from the
3425 Terminal, or control-clicking on the LilyPond application and
3426 selecting @q{Show Package Contents}.
3430 Using Windows Explorer, navigate to
3431 @file{@var{INSTALLDIR}/LilyPond/usr/share/lilypond/current/}
3435 @strong{Installed from a package manager or compiled from source}
3438 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
3439 @var{PREFIX} is set by your package manager or @code{configure}
3440 script, and @var{X.Y.Z} is the LilyPond version number.
3444 Within this directory the two interesting subdirectories are
3447 @item @file{ly/} - contains files in LilyPond format
3448 @item @file{scm/} - contains files in Scheme format
3451 Let's begin by looking at some files in @file{ly/}.
3452 Open @file{ly/property-init.ly} in a text editor. The one
3453 you normally use for @code{.ly} files will be fine. This file
3454 contains the definitions of all the standard LilyPond predefined
3455 commands, such as @code{\stemUp} and @code{\slurDotted}. You will
3456 see that these are nothing more than definitions of variables
3457 containing one or a group of @code{\override} commands. For
3458 example, @code{/tieDotted} is defined to be:
3462 \override Tie #'dash-period = #0.75
3463 \override Tie #'dash-fraction = #0.1
3467 If you do not like the default values these predefined commands can
3468 be redefined easily, just like any other variable, at the
3469 head of your input file.
3471 The following are the most useful files to be found in
3474 @multitable @columnfractions .4 .6
3477 @item @file{ly/engraver-init.ly}
3478 @tab Definitions of engraver Contexts
3479 @item @file{ly/paper-defaults-init.ly}
3480 @tab Specifications of paper-related defaults
3481 @item @file{ly/performer-init.ly}
3482 @tab Definitions of performer Contexts
3483 @item @file{ly/property-init.ly}
3484 @tab Definitions of all common predefined commands
3485 @item @file{ly/spanner-init.ly}
3486 @tab Definitions of spanner-related predefined commands
3489 Other settings (such as the definitions of markup commands) are
3490 stored as @code{.scm} (Scheme) files. The Scheme programming
3491 language is used to provide a programmable interface into
3492 LilyPond internal operation. Further explanation of these files
3493 is currently outside the scope of this manual, as a knowledge of
3494 the Scheme language is required. Users should be warned that
3495 a substantial amount of technical knowledge or time is required
3496 to understand Scheme and these files (see @ref{Scheme tutorial}).
3498 If you have this knowledge, the Scheme files which may be of
3501 @multitable @columnfractions .4 .6
3504 @item @file{scm/auto-beam.scm}
3505 @tab Sub-beaming defaults
3506 @item @file{scm/define-grobs.scm}
3507 @tab Default settings for grob properties
3508 @item @file{scm/define-markup-commands.scm}
3509 @tab Specify all markup commands
3510 @item @file{scm/midi.scm}
3511 @tab Default settings for MIDI output
3512 @item @file{scm/output-lib.scm}
3513 @tab Settings that affect appearance of frets, colors,
3514 accidentals, bar lines, etc
3515 @item @file{scm/parser-clef.scm}
3516 @tab Definitions of supported clefs
3517 @item @file{scm/script.scm}
3518 @tab Default settings for articulations
3523 @node Avoiding tweaks with slower processing
3524 @subsection Avoiding tweaks with slower processing
3526 LilyPond can perform extra checks while it processes input files. These
3527 checks will take extra time to perform, but fewer manual tweaks
3528 may be required to obtain an acceptable result. If a text script
3529 or part of the lyrics extends over the margins these checks will
3530 compress that line of the score just enough to fit within the
3533 To be effective under all circumstances these checks must be enabled
3534 by placing the overrides in a Score @code{\with} block, rather than
3535 in-line in music, as follows:
3539 % Makes sure text scripts and lyrics are within the paper margins
3540 \override PaperColumn #'keep-inside-line = ##t
3541 \override NonMusicalPaperColumn #'keep-inside-line = ##t
3547 @node Advanced tweaks with Scheme
3548 @subsection Advanced tweaks with Scheme
3550 Although many things are possible with the @code{\override} and
3551 @code{\tweak} commands, an even more powerful way of modifying
3552 the action of LilyPond is available through a programmable
3553 interface to the LilyPond internal operation. Code written in
3554 the Scheme programming language can be incorporated directly in
3555 the internal operation of LilyPond. Of course, at least a basic
3556 knowledge of programming in Scheme is required to do this, and an
3557 introduction is provided in the @ref{Scheme tutorial}.
3559 As an illustration of one of the many possibilities, instead of
3560 setting a property to a constant it can be set to a Scheme
3561 procedure which is then called whenever that property is accessed
3562 by LilyPond. The property can then be set dynamically to a value
3563 determined by the procedure at the time it is called. In this
3564 example we color the note head in accordance with its position on
3567 @lilypond[quote,verbatim,ragged-right]
3568 #(define (color-notehead grob)
3569 "Color the notehead according to its position on the staff."
3570 (let ((mod-position (modulo (ly:grob-property grob 'staff-position) 7)))
3572 ;; Return rainbow colors
3573 ((1) (x11-color 'red )) ; for C
3574 ((2) (x11-color 'orange )) ; for D
3575 ((3) (x11-color 'yellow )) ; for E
3576 ((4) (x11-color 'green )) ; for F
3577 ((5) (x11-color 'blue )) ; for G
3578 ((6) (x11-color 'purple )) ; for A
3579 ((0) (x11-color 'violet )) ; for B
3585 % Arrange to obtain color from color-notehead procedure
3586 \override NoteHead #'color = #color-notehead
3593 Some -- where o -- ver the Rain -- bow, way up high,
3597 Further examples showing the use of these programmable interfaces
3598 can be found in @ref{Tweaking with Scheme}.