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.
11 @chapter Tweaking output
13 This chapter discusses how to modify output. LilyPond is extremely
14 configurable; virtually every fragment of output may be changed.
16 NB: This chapter is still under development and this version is
17 somewhat experimental; nothing is fixed. Don't translate yet!
23 * The Internals Reference manual::
24 * Appearance of objects::
25 * Placement of objects::
26 * Collisions of objects::
33 @section Tweaking basics
36 * Introduction to tweaks::
37 * Objects and interfaces::
38 * Naming conventions of objects and properties::
42 @node Introduction to tweaks
43 @subsection Introduction to tweaks
45 @q{Tweaking} is a LilyPond term for the various methods available
46 to the user for modifying the actions taken during interpretation
47 of the input file and modifying the appearance of the printed
48 output. Some tweaks are very easy to use; others are more
49 complex. But taken together the methods available for tweaking
50 permit almost any desired appearance of the printed music to be
53 In this section we cover the basic concepts required to understand
54 tweaking. Later we give a variety of potted commands which can
55 simply be copied to obtain the same effect in your own scores, and
56 at the same time we show how these commands may be constructed so
57 that you may learn how to develop your own tweaks.
59 Before starting on this Chapter you may wish to review the section
60 @ref{Contexts and engravers}, as Contexts, Engravers, and the
61 Properties contained within them are fundamental to understanding
62 and constructing Tweaks.
64 @node Objects and interfaces
65 @subsection Objects and interfaces
72 Tweaking involves modifying the internal operation and structures
73 of the LilyPond program, so we must first introduce some terms
74 which are used to describe those internal operations and
77 The term @q{Object} is a generic term used to refer to the
78 multitude of internal structures built by LilyPond during the
79 processing of an input file. So when a command like @code{\new
80 Staff} is encountered a new object of type @code{Staff} is
81 constructed. That @code{Staff} object then holds all the
82 properties associated with that particular staff, for example, its
83 name and its key signature, together with details of the engravers
84 which have been assigned to operate within that staff's context.
85 Similarly, there are @code{Voice} objects, @code{Score} objects,
86 @code{Lyric} objects, and objects to represent barlines,
87 noteheads, ties, dynamics, etc, each with their own set of
90 Some types of object are given special names. Objects which
91 represent items of notation on the printed output such as
92 noteheads, stems, slurs, ties, fingering, clefs, etc are called
93 @q{Layout objects}, often known as @q{Graphical Objects}, or
94 @q{Grobs} for short. These are still objects in the generic sense
95 above, and so they too all have properties associated with them,
96 such as their position, size, color, etc.
98 Some layout objects are still more specialised. Phrasing slurs,
99 crescendo hairpins, ottavo marks, and many other grobs are not
100 localised in a single place -- they have a starting point, an
101 ending point, and maybe other properties concerned with their
102 shape. Objects with an extended shape like these are called
105 It remains to explain what @q{Interfaces} are. Many objects,
106 even though they are quite different, share common features
107 which need to be processed in the same way.
108 For example, all grobs have a color, a size, a position, etc,
109 and all these properties are processed in the same way during
111 interpretation of the input file. To simplify these internal
112 operations these common actions and properties are grouped
113 together in an object called a @code{grob-interface}. There
114 are many other groupings of common properties like this, each
115 one given a name ending in @code{-interface}. In total there
116 are over 100 such interfaces. We shall see later why this is
117 of interest and use to the user.
119 These, then, are the main terms relating to objects which we
120 shall use in this chapter.
122 @node Naming conventions of objects and properties
123 @subsection Naming conventions of objects and properties
125 We met some object naming conventions previously, in
126 @ref{Contexts and engravers}. Here for reference is a list
127 of the most common object and property types together with
128 the conventions for naming them and a couple of examples of
129 some real names. We have used A to stand for any capitalised
130 alphabetic character and aaa to stand for any number of
131 lower-case alphabetic characters. Other characters are used
134 @multitable @columnfractions .33 .33 .33
135 @headitem Object/property type
136 @tab Naming convention
138 @item Contexts, Layout Objects
139 @tab Aaaa or AaaaAaaaAaaa
140 @tab Staff, GrandStaff,
142 @tab Aaaa_aaa_engraver
143 @tab Clef_engraver, Note_heads_engraver
145 @tab aaa-aaa-interface
146 @tab grob-interface, break-aligned-interface
147 @item Context Properties
148 @tab aaa or aaaAaaaAaaa
149 @tab alignAboveContext, skipBars
150 @item Layout Object Properties
151 @tab aaa or aaa-aaa-aaa
152 @tab direction, beam-thickness
155 As we shall see shortly, the properties of different types of
156 object are modified by different commands, so it is useful to
157 be able to recognise the type of object from the names of its
161 @node Tweaking methods
162 @subsection Tweaking methods
164 We have already met the commands @code{\set} and @code{\with},
165 used to change the properties of @strong{contexts} and to remove
166 and add @strong{engravers}, in
167 @ref{Modifying context properties} and @ref{Adding
168 and removing engravers}. We now must meet one more command.
170 The command to change the properties of @strong{layout objects} is
171 @code{\override}. Because this command has to modify
172 internal properties deep within LilyPond its syntax is not
173 as simple as the commands you have met so far. It needs to
174 know precisely which property of which object in which context
175 has to be modified, and what its new value is to be. Let's see
178 The general syntax of this command is:
181 \override @emph{context}.@emph{layout_object} #'@emph{layout_property} = #@emph{value}
185 This will set the property with the name @emph{layout_property}
186 of the layout object with the name
187 @emph{layout_object}, which is a member of the @emph{context}
188 context, to the value @emph{value}.
190 The @emph{context} can be omitted (and usually is) when the
191 required context is unambiguously implied and is one of lowest
192 level contexts, i.e., @code{Voice}, @code{ChordNames} or
193 @code{Lyrics}, and we shall omit it in many of the following
194 examples. We shall see later when it must be specified.
196 For now, don't worry about the @code{#'}, which must precede the
197 layout property, and the @code{#}, which must precede the value.
198 These must always be present in exactly this form. This is the
199 most common command used in tweaking, and most of the rest of
200 this chapter will be directed to presenting examples of how it is
203 Once overridden, the property retains its new value until it is
204 overridden again or a @code{\revert} command is encountered.
205 The @code{\revert} command has the following syntax and causes
206 the value of the property to revert to its original default
207 value; note, not its previous value if several @code{\override}
208 commands have been issued.
211 \revert @emph{context}.@emph{layout_object} #'@emph{layout_property}
214 Again, just like @emph{context} in the @code{\override} command,
215 @emph{context} is often not needed. It will be omitted
216 in many of the following examples.
218 There is another form of the override command,
219 @code{\overrideProperty}, which is occasionally required.
220 We mention it here for completeness, but for details see
221 @ruser{Difficult tweaks}.
222 @c Maybe explain in a later iteration -td
224 The final tweaking command which is available is @code{\tweak}.
225 It is not really a new command but a shorthand for an
226 @code{\override} command which must be used in a few special
227 circumstances. Again, we shall not discuss or use it here.
228 You may find the details in
229 @ruser{Objects connected to the input}.
230 @c Maybe explain in a later iteration -td
232 @node The Internals Reference manual
233 @section The Internals Reference manual
235 @cindex Internals Reference
238 * Properties of layout objects::
239 * Properties found in interfaces::
240 * Types of properties::
243 @node Properties of layout objects
244 @subsection Properties of layout objects
246 @cindex properties of layout objects
247 @cindex properties of grobs
248 @cindex grobs, properties of
249 @cindex layout objects, properties of
251 Suppose you have a slur in a score which, to your mind,
252 appears too thin and you'd like to draw it a little heavier.
253 How do you go about doing this? You know from the statements
254 earlier about the flexibility of LilyPond that such a thing
255 should be possible, and you would probably guess that an
256 @code{\override} command would be needed. But is there a
257 heaviness property for a slur, and if there is, how might it
258 be modified? This is where the Internals Reference manual
259 comes in. It contains all the information you might need to
260 construct this and all other @code{\override} commands.
262 Before we look at the Internals Reference a word of warning.
263 This is a @strong{reference} document, which means there is
264 little or no explanation contained within it: its purpose is
265 to present information precisely and concisely. This
266 means it might look daunting at first sight. Don't worry!
267 The guidance and explanation presented here will enable you
268 to extract the information from the Internals Reference for
269 yourself with just a little practice.
271 @cindex override example
272 @cindex Internals Reference, example of using
274 Let's use a concrete example with a simple fragment of real
277 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
282 g[( e]) e d[( f]) a |
286 The man who feels love's sweet e -- mo -- tion
291 Suppose now that we decide we would like the slurs to be a
292 little heavier. Is this possible? The slur is certainly a
293 layout object, so the question is, @q{Is there a property
294 belonging to a slur which controls the heaviness?} To answer
295 this we must look in the Internals Reference, or IR for short.
297 The IR for the version of LilyPond you are using may be found
298 on the LilyPond website at @uref{http://lilypond.org}. Go to the
299 documentation page and click on the Internals Reference link.
300 For learning purposes you should use the standard html version,
301 not the @q{one big page} or the PDF. For the next few
302 paragraphs to make sense you will need to actually do this
305 Under the heading @strong{Top} you will see five links. Select
306 the link to the @emph{Backend}, which is where information about
307 layout objects is to be found. There, under the heading
308 @strong{Backend}, select the link to @emph{All layout objects}.
309 The page that appears lists all the layout objects used in your
310 version of LilyPond, in alphabetic order. Select the link to
311 Slur, and the properties of Slurs are listed.
313 (An alternative way of finding this page is from the Notation
314 Reference. On one of the pages that deals with slurs you may
315 find a link to the Internals Reference. This link will
316 take you directly to this page, but often it is easier to go
317 straight to the IR and search there.)
319 This Slur page in the IR tells us first that Slur objects are
321 Slur_engraver. Then it lists the standard settings. Note
322 these are @strong{not} in alphabetic order. Browse down
323 them looking for a property that might control the heaviness
324 of slurs, and you should find
327 @code{thickness} (number)
329 Line thickness, generally measured in @code{line-thickness}
332 This looks a good bet to change the heaviness. It tells us that
333 the value of @code{thickness} is a simple @emph{number},
334 that the default value is 1.2, and that the units are
335 in another property called @code{line-thickness}.
337 As we said earlier, there are few to no explanations in the IR,
338 but we already have enough information to try changing the
339 slur thickness. We see that the name of the layout object
340 is @code{Slur}, that the name of the property to change is
341 @code{thickness} and that the new value should be a number
342 somewhat larger than 1.2 if we are to make slurs thicker.
344 We can now construct the @code{\override} command by simply
345 substituting the values we have found for the names, omitting
346 the context. Let's use a very large value for the thickness
347 at first, so we can be sure the command is working. We get:
350 \override Slur #'thickness = #5.0
353 Don't forget the @code{#'} preceding the
354 property name and and @code{#} preceding the new value!
356 The final question is, @q{Where should this command be
357 placed?} While you are unsure and learning, the best
358 answer is, @q{Within the music, before the first slur and
359 close to it.} Let's do that:
361 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
365 % Increase thickness of all following slurs from 1.2 to 5.0
366 \override Slur #'thickness = #5.0
368 g[( e]) e d[( f]) a |
372 The man who feels love's sweet e -- mo -- tion
378 and we see that the slur is indeed heavier.
380 So this is the basic way of constructing @code{\override}
381 commands. There are a few more complications that we
382 shall meet in later sections, but you now know all the
383 essentials required to make up your own -- but you will
384 still need some practice. This is provided in the examples
387 @subheading Finding the context
388 @cindex context, finding
390 But first, what if we had needed to specify the Context?
391 What should it be? We could guess that slurs are in
392 the Voice context, as they are clearly closely associated
393 with individual lines of music, but can we be sure? To
394 find out, go back to the top of the IR page describing the
395 Slur, where it says @q{Slur objects are created by: Slur
396 engraver}. So slurs will be created in whichever context
397 the @code{Slur_engraver} is in. Follow the link to the
398 @code{Slur_engraver} page. At the very bottom it tells
399 us that @code{Slur_engraver} is part of five Voice contexts,
400 including the standard voice context, @code{Voice}, so our
401 guess was correct. And because @code{Voice} is one of the
402 lowest level contexts which is implied unambiguously by
403 the fact that we are entering notes, we can omit it in this
406 @subheading Overriding once only
408 @cindex overriding once only
409 @cindex once override
412 As you can see, @emph{all} the slurs are thicker in the
413 final example above. But what if we
414 wanted just the first slur to be thicker? This is achieved
415 with the @code{\once} command. Placed immediately before
416 the @code{\override} command it causes it to change only the
417 slur which begins on the @strong{immediately following} note.
419 immediately following note does not begin a slur the command
420 has no effect at all -- it is not remembered until a slur
421 is encountered, it is simply discarded. So the command with
423 repositioned as follows:
425 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
430 % Increase thickness of immediately following slur only
431 \once \override Slur #'thickness = #5.0
433 g[( e]) e d[( f]) a |
437 The man who feels love's sweet e -- mo -- tion
443 Now only the first slur is made heavier.
445 The @code{\once} command can also be used before @code{\set}
446 and @code{\unset}, and before the command to be introduced
447 in the following section -- @code{revert}.
449 @subheading Reverting
452 @cindex default properties, reverting
455 Finally, what if we wanted just the first two slurs to be
456 heavier? Well, we could use two commands, each preceded by
457 @code{\once} placed immediately before each of the notes where
460 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
465 % Increase thickness of immediately following slur only
466 \once \override Slur #'thickness = #5.0
468 % Increase thickness of immediately following slur only
469 \once \override Slur #'thickness = #5.0
470 g[( e]) e d[( f]) a |
474 The man who feels love's sweet e -- mo -- tion
480 or we could omit the @code{\once} command and use the
481 @code{\revert} command
482 to return the @code{thickness} property to its default value
483 after the second slur:
485 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
490 % Increase thickness of all following slurs from 1.2 to 5.0
491 \override Slur #'thickness = #5.0
494 % Revert thickness of all following slurs to default of 1.2
495 \revert Slur #'thickness
500 The man who feels love's sweet e -- mo -- tion
506 The @code{\revert} command can be used to return any property
507 changed with @code{\override} back to its default value.
508 You may use whichever method best suits what you want to do.
510 That concludes our introduction to the IR, and the basic
511 method of tweaking. Several examples follow in the later
512 sections of this Chapter, partly to introduce you to some of the
513 additional features of the IR, and partly to give you more
514 practice in extracting information from it. These examples will
515 contain progressively fewer words of guidance and explanation.
517 @node Properties found in interfaces
518 @subsection Properties found in interfaces
520 @cindex interface properties
521 @cindex properties in interfaces
523 Suppose now that we wish to print the lyrics in italics. What
524 form of @code{\override} command do we need to do this?
525 We first look in the IR page listing @q{All layout objects}, as
526 before, and look for an object that might control lyrics. We
527 find @code{LyricText}, which looks right. Clicking on this shows
528 the settable properties for lyric text. These include the
529 @code{font-series} and @code{font-size}, but nothing that might
530 give an italic shape.
531 This is because the shape property is one that is common to all
532 font objects, so, rather than including it in every layout
533 object, it is grouped together with other similar common
534 properties and placed in an @strong{Interface}, the
535 @code{font-interface}.
537 So now we need to learn how to find the properties of interfaces,
538 and to discover what objects use these interface properties.
540 Look again at the IR page which describes LyricText. At the
541 bottom of the page is a list of clickable (in the html versions
542 of the IR) interfaces which LyricText supports. The list has
543 seven items, including @code{font-interface}.
544 Clicking on this brings up the properties associated
545 with this interface, which are also properties of all the objects
546 which support it, including LyricText.
548 Now we see all the user-settable properties which control fonts,
549 including @code{font-shape(symbol)}, where @code{symbol} can be
550 set to @code{upright}, @code{italics} or @code{caps}.
552 You will notice that that @code{font-series} and @code{font-size}
553 are also listed there.
554 This immediately raises the question: Why are the common font
555 properties @code{font-series} and @code{font-size} listed under
556 @code{LyricText} as well as under the interface
557 @code{font-interface} but @code{font-shape} is not? The answer
558 is that @code{font-series} and @code{font-size} are changed
559 from their global default values when a @code{LyricText} object
560 is created, but @code{font-shape} is not. The entries in
561 @code{LyricText} then tell you the values for those two
562 properties which apply to @code{LyricText}. Other objects
563 which support @code{font-interface} will set these
564 properties diferently when they are created.
566 Let's see if we can now construct the @code{\override} command
567 to change the lyrics to italics. The object is @code{LyricText},
568 the property is @code{font-shape} and the value is
569 @code{italic}. As before, we'll omit the context.
571 As an aside, although it is an important one, note that because
573 @code{font-shape} are symbols they must be introduced with a
574 single apostrophe, @code{'}. That is why apostrophes
575 are needed before @code{thickness} in the earlier example
576 and @code{font-shape}. These are both symbols too.
577 Symbols are special names which are known internally to
578 LilyPond. Some of them are the names of properties,
579 like @code{thickness} or @code{font-shape}, others are in
580 effect special values that can be given to properties, like
581 @code{italic}. Note the distinction from arbitary
582 text strings, which would appear as @code{"a text string"}.
584 Ok, so the @code{\override} command we need to print the lyrics
588 \override LyricText #'font-shape = #'italic
592 and this should be placed just in front of and close to the
593 lyrics which it should affect, like this:
595 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
600 g[( e]) e d[( f]) a |
604 \override LyricText #'font-shape = #'italic
605 The man who feels love's sweet e -- mo -- tion
611 and the lyrics are all printed in italics.
613 @subheading Specifying context in lyric mode
614 @cindex context, specifying in lyric mode
616 In the case of lyrics, if you try specifying the context in the
617 format given earlier the command will fail. A syllable
618 entered in lyricmode is terminated by either a space,
619 a newline or a digit. All other characters are included
620 as part of the syllable. For this reason a space or newline
621 must appear before the terminating @code{@}} to prevent it being
622 included as part of the final syllable. Similarly,
623 spaces must be inserted before and after the
624 period or dot, @q{.}, separating the context name from the
625 object name, as otherwise the two names are run together and
626 the interpreter cannot recognise them. So the command should be:
629 \override Lyrics . LyricText #'font-shape = #'italic
632 @warning{In lyrics always leave whitespace between the final
633 syllable and the terminating brace.}
635 @warning{In overrides in lyrics always place spaces around
636 the dot between the context name and the object name.}
638 @node Types of properties
639 @subsection Types of properties
641 @cindex Property types
643 So far we have seen two types of property: @code{number} and
644 @code{symbol}. To be valid, the value given to a property
645 must be of the correct type and obey the rules for that type.
646 The type of property is always shown in brackets after the
647 property name in the IR. Here is a list of the types you may
648 need, together with the rules for that type, and some examples.
649 You must always add a hash symbol, @code{#}, of course,
650 to the front of these values when they are entered in the
651 @code{\override} command.
653 @multitable @columnfractions .2 .45 .35
654 @headitem Property type
658 @tab Either True or False, represented by #t or #f
659 @tab @code{#t}, @code{#f}
660 @item Dimension (in staff space)
661 @tab A positive decimal number (in units of staff space)
662 @tab @code{2.5}, @code{0.34}
664 @tab A valid direction constant or its numerical equivalent
665 @tab @code{#LEFT}, @code{#CENTER}, @code{#UP},
668 @tab A positive whole number
669 @tab @code{3}, @code{1}
671 @tab A bracketed set of items separated by spaces,
672 preceded by an apostrophe
673 @tab @code{'(left-edge staff-bar)}, @code{'(1)},
674 @code{'(1.0 0.25 0.5)}
676 @tab Any valid markup
677 @tab @code{\markup @{ \italic "cresc." @}}
679 @tab A fraction of a whole note constructed with the
681 @tab @code{(ly:make-moment 1 4)},
682 @code{(ly:make-moment 3 8)}
684 @tab Any positive or negative decimal value
685 @tab @code{3.5}, @code{-2.45}
686 @item Pair (of numbers)
687 @tab Two numbers separated by a @q{space . space} and enclosed
688 in brackets preceded by an apostrophe
689 @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
691 @tab Any of the set of permitted symbols for that property,
692 preceded by an apostrophe
693 @tab @code{'italic}, @code{'inside}
695 @tab A procedure or @code{#f} (to cause no action)
696 @tab @code{bend::print}, @code{ly:text-interface::print},
699 @tab A list of three items enclosed in brackets and preceded
700 by a hash sign, @code{#}.
701 @tab @code{#(#t #t #f)}
704 @node Appearance of objects
705 @section Appearance of objects
707 Let us now put what we have learnt into practice with a few
708 examples which show how tweaks may be used to change the
709 appearance of the printed music.
712 * Visibility and color of objects::
716 @node Visibility and color of objects
717 @subsection Visibility and color of objects
719 In the educational use of music we might wish to print a score
720 with certain elements omitted as an exercise for the student,
721 who is required to supply them. As a simple example,
722 let us suppose the exercise is to supply the missing barlines
723 in a piece of music. But the barlines are normally inserted
724 automatically. How do we prevent them printing?
726 As before, we go to the IR to find the layout object which prints
727 barlines. Going via @emph{Backend} and @emph{All layout objects}
729 is a layout object called @code{BarLine}. Its properties include
730 two that control its visibility: @code{break-visibility} and
731 @code{stencil}. Barline also supports a number of interfaces,
732 including the @code{grob-interface}, where we find the
733 @code{transparent} and the @code{color} properties. All
734 of these can affect the visibility of barlines (and, of course,
735 by extension, many other layout objects too.) Let's consider
736 each of these in turn.
739 @cindex stencil property
741 This property controls the appearance of the barlines by specifying
742 the symbol (glyph) which should be printed. In common
743 with many other properties, it can be set to print nothing by
744 setting its value to @code{#f}. Let's try it, as before, omitting
745 the implied Context, @code{Voice}:
747 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
750 \override BarLine #'stencil = ##f
757 The barlines are still printed. What is wrong? Go back to the
758 IR and look again at the page giving the properties of BarLine.
759 At the top of the page it says @qq{Barline objects are created
760 by: Bar_engraver}. Go to the @code{Bar_engraver} page.
762 it gives a list of Contexts in which the bar engraver operates.
763 All of them are of the type @code{Staff}, so the reason the
764 @code{\override} command failed to work as expected is because
765 @code{Barline} is not in the default @code{Voice} context.
767 is specified wrongly, the command simply does not work. No
768 error message is produced, and nothing is logged in the log
769 file. Let's try correcting it by adding the correct context:
771 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
774 \override Staff.BarLine #'stencil = ##f
781 Now the barlines have vanished.
783 @subheading break-visibility
785 @cindex break-visibility property
787 We see from the @code{BarLine} properties in the IR that the
788 @code{break-visibility} property requires a vector of three
790 These control respectively whether barlines are printed at
791 the end of a line, in the middle of lines, and at the beginning
792 of lines. For our example we want all barlines to be suppressed,
793 so the value we need is @code{#(#f #f #f)}.
794 Let's try that, remembering
795 to include the @code{Staff} context. Note also that in writing
796 this value we have two hash signs before the opening bracket.
797 One is required as part of the value to introduce a vector,
798 and one is required, as always, to precede the value itself in
799 the @code{\override} command.
801 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
804 \override Staff.BarLine #'break-visibility = ##(#f #f #f)
811 And we see this too removes all the barlines.
813 @subheading transparent
814 @cindex transparent property
816 We see from the properties specified in the @code{grob-interface}
817 page in the IR that the @code{transparent} property is a boolean.
819 should be set to @code{#t} to make the grob transparent.
820 In this next example let us make the time signature invisible
821 rather than the barlines.
822 To do this we need to find the grob name for the time signature.
824 the @q{All layout objects} page in the IR to find the properties
825 of the @code{TimeSignature} layout object. This is produced by
826 the @code{Time_signature_engraver} which you can check also lives
827 in the @code{Staff} context and also supports the
828 @code{grob-interface}. So the command to make the time signature
831 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
834 \override Staff.TimeSignature #'transparent = ##t
842 The time signature is gone, but this command leaves a gap where
843 the time signature should be. Maybe this is what is wanted for
844 an exercise for the student to fill it in, but in other
845 circumstances a gap might be undesirable. To remove it, the
846 stencil for the time signature should be set to @code{#f}
849 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
852 \override Staff.TimeSignature #'stencil = ##f
860 and the difference is obvious: setting the stencil to @code{#f}
861 removes the object entirely; making the object @code{transparent}
862 leaves it where it is, but makes it invisible.
865 @cindex color property
867 Finally we could make the barlines invisible by coloring
868 them white. The @code{grob-interface} specifies that the
869 color property value is a list, but there is no
870 explanation of what that list should be. The list it
871 requires is actually a list of values in internal units,
872 but, to avoid having to know what these are, several ways
873 are provided to specify colors. The first way is to use one
874 of the @q{normal} colours listed in the first table in
875 @ruser{List of colors}. To set the barlines to white
878 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
881 \override Staff.BarLine #'color = #white
889 and again, we see the barlines are not visible. Note that
890 @emph{white} is not preceded by an apostrophe -- it is not
891 a symbol, but a @emph{function}. When called, it provides
892 the list of internal values required to set the color to
893 white. The other colors in the normal list are functions
894 too. To convince yourself this is working you might like
895 to change the color to one of the other functions in the
901 The second way of changing the color is to use the list of
902 X11 color names in the second list in @ruser{List of colors}.
903 However, these must be preceded by another function, which
904 converts X11 color names into the list of internal values,
905 @code{x11-color}, like this:
907 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
910 \override Staff.BarLine #'color = #(x11-color 'white)
918 Note that in this case the function @code{x11-color} takes
919 a symbol as an argument, so the symbol must be preceded by
920 an apostrophe and the two enclosed in brackets.
925 There is yet a third function, one which converts RGB values into
926 internal colors -- the @code{rgb-color} function. This takes
927 three arguments giving the intensities of the red, green and
928 blue colors. These take values in the range 0 to 1. So to
929 set the color to red the value should be @code{(rgb-color 1 0 0)}
930 and to white it should be @code{(rgb-color 1 1 1)}:
932 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
935 \override Staff.BarLine #'color = #(rgb-color 1 1 1)
942 Finally, there is also a grey scale available as part of the
943 X11 set of colors. These range from black, @code{'grey0'},
944 to white, @code{'grey100}, in steps of 1. Let's illustrate
945 this by setting all the layout objects in our example to
946 various shades of grey:
948 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
951 \override Staff.StaffSymbol #'color = #(x11-color 'grey30)
952 \override Staff.TimeSignature #'color = #(x11-color 'grey60)
953 \override Staff.Clef #'color = #(x11-color 'grey60)
954 \override Voice.NoteHead #'color = #(x11-color 'grey85)
955 \override Voice.Stem #'color = #(x11-color 'grey85)
956 \override Staff.BarLine #'color = #(x11-color 'grey10)
964 Note the contexts associated with each of the layout objects.
965 It is important to get these right, or the commands will not
966 work! Remember, the context is the one in which the appropriate
967 engraver is placed. The default context for engravers can be
968 found by starting from the layout object, going from there to
969 the engraver which produces it, and on the engraver page in the
970 IR it tells you in which context the engraver will normally be
974 @node Size of objects
975 @subsection Size of objects
977 Let us begin by looking again at the earlier example
978 see @ref{Nesting music expressions}) which showed
979 how to introduce a new temporary staff, as in an @rglos{ossia}.
981 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
989 alignAboveContext = "main" }
997 Ossia are normally written without clef and time signature, and
998 are usually printed slightly smaller than the main staff. We
999 already know now how to remove the clef and time signature --
1000 we simply set the stencil of each to @code{#f}, as follows:
1002 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1003 \new Staff ="main" {
1010 alignAboveContext = "main"
1013 \override Staff.Clef #'stencil = ##f
1014 \override Staff.TimeSignature #'stencil = ##f
1024 where the extra pair of braces after the @code{\with} clause are
1025 required to ensure the enclosed overrrides and music are applied
1028 But what is the difference between modifying the staff context by
1029 using @code{\with} and modifying the stencils of the clef and the
1030 time signature with \override? The main difference is that
1031 changes made in a @code{\with} clause are made at the time the
1032 context is created, and remain in force as the @strong{default}
1033 values for the duration of that context, whereas
1034 @code{\set} or @code{\override} commands embedded in the
1035 music are dynamic -- they make changes synchronised with
1036 a particular point in the music. If changes are unset or
1037 reverted using @code{\unset} or @code{\revert} they return to
1038 their default values, which will be the ones set in the
1039 @code{\with} clause, or if none have been set there, the normal
1042 Some context properties
1043 can be modified only in @code{\with} clauses. These are those
1044 properties which cannot sensibly be changed after the context
1045 has been created. @code{alignAboveContext} and its partner,
1046 @code{alignBelowContext}, are two such properties -- once the
1047 staff has been created its alignment is decided and it would
1048 make no sense to try to change it later.
1050 The default values of layout object properties can also be set
1051 in @code{\with} clauses. Simply use the normal @code{\override}
1052 command leaving out the context name, since this is unambiguously
1053 defined as the context which the @code{\with} clause is modifying.
1054 If fact, an error will be generated if a context is specified
1057 So we could replace the example above with
1059 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1060 \new Staff ="main" {
1067 alignAboveContext = "main"
1068 % Don't print clefs in this staff
1069 \override Clef #'stencil = ##f
1070 % Don't print time signatures in this staff
1071 \override TimeSignature #'stencil = ##f
1080 Finally we come to changing the size of layout objects.
1082 Some layout objects are created as glyphs selected from
1083 a typeface font. These include noteheads, accidentals, markup,
1084 clefs, time signatures, dynamics and lyrics.
1085 Their size is changed by modifying the
1086 @code{font-size} property, as we shall shortly see. Other
1087 layout objects such as slurs and ties -- in general, spanner
1088 objects -- are drawn individually, so there is no
1090 associated with them. These objects generally derive their
1091 size from the objects to which they are attached, so usually
1092 there is no need to change their size manually. Still other
1093 properties such as the length of stems and barlines, thickness
1094 of beams and other lines, and the separation of staff lines all
1095 need to be modified in special ways.
1097 Returning to the ossia example, let us first change the font-size.
1098 We can do this in two ways. We can either change the size of the
1099 fonts of each object type, like @code{NoteHead}s with commands
1103 \override NoteHead #'font-size = #-2
1106 or we can change the size of all fonts by setting a special
1107 property, @code{fontSize}, using @code{\set}, or by including
1108 it in a @code{\with} clause (but without the @code{\set}).
1114 Both of these statements would cause the font size to be reduced
1115 by 2 steps from its previous value, where each
1116 step reduces or increases the size by approximately 12%.
1118 Let's try it in our ossia example:
1120 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1121 \new Staff ="main" {
1128 alignAboveContext = "main"
1129 \override Clef #'stencil = ##f
1130 \override TimeSignature #'stencil = ##f
1131 % Reduce all font sizes by ~24%
1141 This is still not quite right. The noteheads and flags are
1142 smaller, but the stems are too long in proportion and the
1143 staff lines are spaced too widely apart. These need to be
1144 scaled down in proportion to the font reduction.
1147 @cindex size, changing
1148 @cindex stem length, changing
1149 @cindex staff line spacing, changing
1151 This can be done with the help of a special function called
1152 @code{magstep} provided for exactly this purpose. It takes
1153 one argument, the change in font size (#-2 in the example above)
1154 and returns a scaling factor suitable for reducing other
1155 objects in proportion. It is used like this:
1157 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1158 \new Staff ="main" {
1165 alignAboveContext = "main"
1166 \override Clef #'stencil = ##f
1167 \override TimeSignature #'stencil = ##f
1169 % Reduce stems and line spacing to match
1170 \override StaffSymbol #'staff-space = #(magstep -2)
1180 Since the length of stems and many other length-related properties
1181 are always calculated relative to the
1182 value of the @code{staff-space} property these are automatically
1183 scaled down in length too. Note that this affects only the
1184 vertical scale of the ossia -- the horizontal scale is determined
1185 by the layout of the main music in order to remain synchronised
1186 with it, so it is not affected by any of these changes in size.
1187 Of course, if the scale of all the main music were changed in this
1188 way then the horizontal spacing would be affected. This is
1189 discussed later in the layout section.
1191 This, then, completes the creation of an ossia. The sizes of all
1192 other objects may be modified in analogous ways.
1194 @node Placement of objects
1195 @section Placement of objects
1198 * Automatic behaviour::
1199 * Within-staff objects::
1200 * Outside staff objects::
1204 @node Automatic behaviour
1205 @subsection Automatic behaviour
1207 There are some objects in musical notation that belong to
1208 the staff and there are other objects that should be
1209 placed outside the staff. These are called within-staff
1210 objects and outside-staff objects respectively.
1212 Within-staff objects are those that are located on the staff
1213 -- note heads, stems, accidentals, etc. The positions of
1214 these are usually fixed by the music itself -- they are
1215 vertically positioned on specific lines of the staff or are
1216 tied to other objects that are so positioned. Collisions of
1217 noteheads, stems and accidentals in closely set chords are
1218 normally avoided automatically. There are commands and
1219 overrides which can modify this automatic behaviour, as we
1222 Objects belonging outside the staff include things
1223 such as rehearsal marks, text and dynamic markings.
1224 LilyPond’s rule for the
1225 vertical placement of outside-staff objects is to place them as
1226 close to the staff as possible but not so close that they
1227 collide with any other object. LilyPond uses the
1228 @code{outside-staff-priority} property to determine the order
1229 in which the objects should be placed, as follows.
1231 First, LilyPond places all the within-staff objects.
1232 Then it sorts the outside-staff objects according to their
1233 @code{outside-staff-priority}. The outside-staff objects are
1234 taken one by one, beginning with the object with the lowest
1235 @code{outside-staff-priority}, and placed so that they do not
1236 collide with any objects that have already been placed. That is,
1237 if two outside-staff grobs are competing for the same space, the
1238 one with the lower @code{outside-staff-priority} will be placed
1239 closer to the staff. If two objects have the same
1240 @code{outside-staff-priority} the one encountered first will be
1241 placed closer to the staff.
1243 In the following example all the markup texts have the same
1244 priority (since it is not explicity set). Note that @q{Text3}
1245 is automatically positioned close to the staff again, nestling
1248 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1255 Staves are also positioned, by default, as closely together as
1256 possible (subject to a minimum separation). If notes project
1257 a long way towards an adjacent staff they will force the
1258 staves further apart only if an overlap of the notation
1259 would otherwise occur. The following example demonstrates
1260 this @q{nestling} of the notes on adjacent staves:
1262 @lilypond[quote,ragged-right,verbatim]
1265 \relative c' { c a, }
1268 \relative c'''' { c a, }
1273 @c TODO Mention somewhere, probably not here, how to avoid staves
1274 @c interleaving too much by specifying skyline-horizontal-padding
1275 @c Presumably this moves the skyline boundary further out, making
1276 @c objects appear wider? Not yet tested. -td
1278 @node Within-staff objects
1279 @subsection Within-staff objects
1281 We have already seen how the commands @code{\voiceXXX} affect
1282 the direction of slurs, ties, fingering and
1283 everything else which depends on the direction of the stems.
1284 These commands are essential when writing polyphonic music to
1285 permit interweaving melodic lines to be distinguished.
1286 But occasionally it may be necessary to override this automatic
1287 behaviour. This can be done for whole sections of music or even
1288 for an individual note. The property which controls this
1289 behaviour is the @code{direction} property of each layout object.
1290 We first explain what this does, and then introduce a number of
1291 ready-made commands which avoid your having to code explicit
1292 overrides for the more common modifications.
1294 Some layout objects like slurs and ties curve, bend or point
1295 either up or down; others like stems and flags also move to
1296 right or left when they point up or down. This is controlled
1297 automatically when @code{direction} is set.
1299 The following example shows in bar 1 the default behaviour of
1301 with those on high notes pointing down and those on low notes
1302 pointing up, followed by four notes with all stems forced down,
1303 four notes with all stems forced up, and finally four notes
1304 reverted back to the default behaviour.
1306 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1308 \override Stem #'direction = #DOWN
1310 \override Stem #'direction = #UP
1312 \revert Stem #'direction
1316 Here we use the constants @code{DOWN} and @code{UP}.
1317 These have the values @code{-1} and @code{+1} respectively, and
1318 these numerical values may be used instead. The value @code{0}
1319 may also be used in some cases. It is simply treated as meaning
1320 @code{UP} for stems, but for some objects it means @q{center}.
1321 There is a constant, @code{CENTER} which has the value @code{0}.
1323 However, these explicit overrides are not usually used, as there
1324 are simpler equivalent predefined commands available.
1325 Here is a table of the commonest. The meaning of each is stated
1326 where it is not obvious.
1328 @c TODO put @code{} round all these
1330 @multitable @columnfractions .2 .2 .2 .4
1337 @tab \arpeggioNeutral
1338 @tab Arrow is at bottom, at top, or no arrow
1342 @tab Direction of movement to avoid staff lines
1345 @tab \dynamicNeutral
1347 @item \phrasingSlurDown
1348 @tab \phrasingSlurUp
1349 @tab \phrasingSlurNeutral
1350 @tab Note: distinct from slur commands
1359 @item \textSpannerDown
1361 @tab \textSpannerNeutral
1362 @tab Text entered as spanner is below/above staff
1370 @tab Tuplets are below/above notes
1373 Note that these predefined commands may @strong{not} be
1374 preceded by @code{\once}. If you wish to limit the
1375 effect to a single note you must either use the equivalent
1376 @code{\once \override} command or use the predefined command
1377 followed after the affected note by the corresponding
1378 @code{\xxxNeutral} command.
1380 @subheading Fingering
1381 @cindex fingering, placement
1383 The placement of fingering is also affected by the value
1384 of its @code{direction} property, but there are special
1385 commands which allow the fingering of individual notes
1386 of chords to be controlled, with the fingering being placed
1387 above, below, to the left or to the right of each note.
1389 First, here's the effect of @code{direction} on fingering,
1390 the first bar shows the default, then the effect of specifying
1391 @code{DOWN} and @code{UP}:
1393 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1395 \override Fingering #'direction = #DOWN
1397 \override Fingering #'direction = #UP
1401 This is how to control fingering on single notes, but the
1403 property is ignored for chords. Instead, by default, the
1404 fingering is automatically placed both above and below the
1405 notes of a chord, as shown:
1407 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1413 Greater control over the placement of fingering of the
1414 individual notes in a chord is possible by using
1415 the @code{\set fingeringOrientations} command. The format of
1419 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
1423 @code{\set} is used because @code{fingeringOrientations} is a
1424 property of the @code{Voice} context, created and used by the
1425 @code{New_fingering_engraver}.
1427 The property may be set to a list of one to three values.
1428 It controls whether fingerings may be placed above (if
1429 @code{up} appears in the list), below (if @code{down} appears),
1430 to the left (if @code{left} appears, or to the right
1431 (if @code{right} appears). Conversely, if a location is not
1432 listed, no fingering is placed there. LilyPond takes these
1433 contraints and works out the best placement for the fingering
1434 of the notes of the following chords. Note that @code{left} and
1435 @code{right} are mutually exclusive -- fingering may be placed
1436 only on one side or the other, not both.
1438 To control the placement of the fingering of a single note
1439 using this command it is necessary to write it as a single
1440 note chord by placing angle brackets round it.
1442 Here are a few examples:
1444 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1445 \set fingeringOrientations = #'(left)
1447 < c-1 e-2 g-3 b-5 > 4
1448 \set fingeringOrientations = #'(left)
1450 < c-1 e-2 g-3 b-5 > 4
1451 \set fingeringOrientations = #'(up left down)
1453 < c-1 e-2 g-3 b-5 > 4
1454 \set fingeringOrientations = #'(up left)
1456 < c-1 e-2 g-3 b-5 > 4
1457 \set fingeringOrientations = #'(right)
1459 < c-1 e-2 g-3 b-5 > 4
1463 If the fingering seems a little crowded the @code{font-size}
1464 could be reduced. The default value can be seen from the
1465 @code{Fingering} object in the IR to be @code{-5}, so let's
1468 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1469 \override Fingering #'font-size = #-7
1470 \set fingeringOrientations = #'(left)
1472 < c-1 e-2 g-3 b-5 > 4
1473 \set fingeringOrientations = #'(left)
1475 < c-1 e-2 g-3 b-5 > 4
1476 \set fingeringOrientations = #'(up left down)
1478 < c-1 e-2 g-3 b-5 > 4
1479 \set fingeringOrientations = #'(up left)
1481 < c-1 e-2 g-3 b-5 > 4
1482 \set fingeringOrientations = #'(right)
1484 < c-1 e-2 g-3 b-5 > 4
1487 @node Outside staff objects
1488 @subsection Outside staff objects
1490 Outside-staff objects are automatically placed to avoid collisions.
1491 Objects with the lower value of @code{outside-staff-priority}
1492 property are placed nearer to the staff, and other outside-staff
1493 objects are then raised as far as necessary to avoid collisions.
1494 The @code{outside-staff-priority} is defined in the
1495 @code{grob-interface} and so is a property of all layout objects.
1496 It is set to @code{#f} (the default) for all within-staff objects,
1497 and is set explicitly to the default numerical value appropriate
1498 to the each object as it is created. The following table shows
1499 the default numerical values for some of the commonest
1500 outside-staff objects. Others may be found in the object
1501 properties listed in the IR.
1503 @multitable @columnfractions .3 .3
1504 @headitem Layout Object @tab Priority
1505 @item @code{BarNumber} @tab @code{ 100}
1506 @item @code{DynamicLineSpanner} @tab @code{ 250}
1507 @item @code{DynamicText} @tab @code{ 250}
1508 @item @code{MetronomeMark} @tab @code{1000}
1509 @item @code{OttavaBracket} @tab @code{ 400}
1510 @item @code{RehearsalMark} @tab @code{1500}
1511 @item @code{TextScript} @tab @code{ 450}
1514 TODO Add example showing iteraction of all these
1516 If this ordering does not give you the placing you want, the
1517 priority of the objects may be overridden. Suppose we would
1518 like @qq{Text3} to be placed above @qq{Text4} in the example
1519 under Automatic behaviour, above (see @ref{Automatic behaviour}).
1520 All we need to do is to look up the priority of @code{TextScript}
1521 in the IR or in the table above, and increase the priority of
1522 @qq{Text3} to a higher value:
1524 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1527 \once \override TextScript #'outside-staff-priority = #500
1532 This certainly lifts @qq{Text3} above @qq{Text4} but it also
1533 lifts it above @qq{Text2}, and @qq{Text4} now drops down.
1534 Perhaps this is not so good. Can we instead position them all
1535 at the same distance from the staff? To do this, we clearly
1536 will need to space the notes out horizontally to make more
1537 room for the text. This is done using the @code{fatText}
1540 @subheading \fatText
1543 @cindex notes, spreading out with text
1545 By default, text produced by markup takes up no horizontal space
1546 as far as laying out the music is concerned. The @code{\fatText}
1547 command reverses this behaviour, causing the notes to be spaced
1548 out as far as is necessary to accommodate the text:
1550 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1551 \fatText % Cause notes to space out to accommodate text
1558 The command to revert to the default behaviour is
1559 @code{\emptyText}. Remember @code{\once} only works with
1560 @code{\override}, @code{\set}, @code{\revert} or @code{unset},
1561 so cannot be used with @code{\fatText}.
1563 Markup text will also avoid notes which project above the staff.
1564 If this is not desired, the automatic displacement upwards may
1565 be turned off by setting the priority to @code{#f}. Here's an
1566 example to show how markup text interacts with such notes.
1568 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1569 % This markup is short enough to fit without collision
1573 % This is too long to fit, so it is displaced upwards
1577 % Turn off collision avoidance
1578 \once \override TextScript #'outside-staff-priority = ##f
1582 % Turn off collision avoidance
1583 \once \override TextScript #'outside-staff-priority = ##f
1584 \fatText % and turn on fatText
1585 c,,2^"Long Text " % Spaces at end are honoured
1590 @subheading Dynamics
1592 Dynamic markings will normally be positioned beneath the
1593 staff, but may be positioned above with the @code{dynamicUp}
1594 command. They will be positioned vertically relative to the
1595 note to which they are attached, and will float below (or above)
1596 all within-staff objects such as phrasing slurs and bar numbers.
1597 This can give quite acceptable results, as this example
1600 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1605 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
1606 ees,2.~\)\mf ees4 r8 |
1609 However, if the notes and attached dynamics are close
1610 together the automatic placement will avoid collisions
1611 by displacing later dynamic markings further away, but this may
1612 not be the optimum placement, as this rather artificial example
1615 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1621 Should a similar situation arise in @q{real} music, it may
1622 be preferable to space out the notes
1623 a little further, so the dynamic markings can all fit at the
1624 same vertical distance from the staff. We were able to do this
1625 for markup text by using the @code{\fatText} command, but there
1626 is no equivalent command for dynamic marks. So we shall have to
1627 work out how to do this using @code{\override} commands.
1629 @subheading Grob sizing
1632 @cindex sizing grobs
1633 @cindex @code{X-offset}
1634 @cindex @code{Y-offset}
1635 @cindex @code{X-extent}
1636 @cindex @code{Y-extent}
1638 First we must learn how grobs are sized. All grobs have a
1639 reference point defined within them which is used to position
1640 them relative to their parent object. This point in the grob
1641 is then positioned at a horizontal distance, @code{X-offset},
1642 and at a vertical distance, @code{Y-offset}, from its parent.
1643 The horizontal extent of the object is given by a pair of
1644 numbers, @code{X-extent}, which say where the left and right
1645 edges are relative to the reference point. The vertical extent
1646 is similarly defined by a pair of numbers, @code{Y-extent}.
1647 These are properties of all grobs which support the
1648 @code{grob-interface}.
1650 @cindex @code{extra-spacing-width}
1652 By default, outside-staff objects are given a width of zero so
1653 that they may overlap in the horizontal direction. This is done
1654 by by the trick of adding infinity to the leftmost extent and
1655 minus infinity to the rightmost extent by setting the
1656 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}. So
1657 to ensure they do not overlap in the horizontal direction we
1658 must override this value of @code{extra-spacing-width} to
1659 @code{'(0 . 0)} so the true width shines through. This is
1660 the command to do this for dynamic text:
1663 \override DynamicText #'extra-spacing-width = #'(0 . 0)
1667 Let's see if this works in our previous example:
1669 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1671 \override DynamicText #'extra-spacing-width = #'(0 . 0)
1676 Well, it has certainly stopped the dynamic marks being
1677 displaced, but two problems remain. The marks should be
1678 spaced a little further apart and it would be better
1679 if they were all the same distance from the staff.
1680 We can solve the first problem easily. Instead of making
1681 the @code{extra-spacing-width} zero we could add a little
1682 more to it. The units are the space between two staff
1683 lines, so moving the left edge half a unit to the left and the
1684 right edge half a unit to the right should do it:
1686 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1688 % Extend width by 1 staff space
1689 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
1694 This looks better, but maybe we would prefer the dynamic marks
1695 to be aligned along the same baseline rather than going up and
1696 down with the notes. There is a property to control this, but
1697 it is not so easy to find in the IR. It is not a property of
1698 @code{DynamicText} but of @code{DynamicLineSpanner}.
1699 This is because the baseline should apply equally to @strong{all}
1700 dynamics, including those created as extended spanners.
1701 So this is the way to align the dynamic marks in our example:
1703 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1705 % Extend width by 1 unit
1706 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
1707 % Align dynamics to a base line 2 units above staff
1708 \override DynamicLineSpanner #'staff-padding = #2
1714 @node Collisions of objects
1715 @section Collisions of objects
1719 * Fixing overlapping notation::
1722 @node Moving objects
1723 @subsection Moving objects
1725 This may come as a surprise, but LilyPond is not perfect. Some
1726 notation elements can overlap. This is unfortunate, but in fact
1727 rather rare. Usually the need to move objects is for clarity or
1728 aesthetic reasons -- they would look better with a little more
1731 There are three main main approaches to resolving overlapping
1732 notation. They should be considered in the following order:
1736 The @strong{direction} of one of the overlapping objects may
1737 be changed using the predefined commands listed above for
1738 within-staff objects (see @ref{Within-staff objects}).
1739 Stems, slurs, beams, ties, dynamics, text and tuplets may be
1740 repositioned easily in this way. The limitation is that you
1741 have a choice of only two positions, and neither may be
1745 The @strong{object properties} taken into account by LilyPond
1746 when positioning the objects may be modified. The advantages
1747 of making changes to this type of property are (a) that some
1748 other objects will be moved automatically if necessary to make
1749 room and (b) the single change can apply to all instances of
1750 the same type of object. Such properties include:
1753 @item @code{direction}
1755 This has already been covered in some detail -- see
1756 @ref{Within-staff objects}.
1758 @item @code{left-padding}, @code{padding},
1759 @code{right-padding}, @code{staff-padding}
1760 @cindex left-padding property
1761 @cindex padding property
1762 @cindex right-padding property
1764 The @code{padding} property specifies the gap that must be left
1766 the top and bottom edges of objects which are positioned
1767 either above or below another previously placed object, or
1768 between the sides of objects which are positioned to the left or
1769 right of previously placed objects.
1770 Instead of @code{padding} some objects have instead a
1771 @code{left-padding} or @code{right-padding} property.
1772 All padding values are measured in staff spaces. For most
1773 objects, this value is set by default to be around 1.0 or less
1774 (it varies with each object). It may be overridden if a larger
1775 (or smaller) gap is required.
1777 The @code{staff-padding} property is closely related. @code{padding}
1778 controls the minimum amount of space between an object and the nearest
1779 other object (generally the note or the staff lines);
1780 @code{staff-padding} controls the minimum amount of space between an
1781 object and the staff.
1783 To discover which padding property is required for the object
1784 you wish to reposition, you
1785 need to return to the IR and look up the object's properties.
1786 Be aware that the padding property might not be located in the
1787 obvious object. For example, the placement of accidentals is
1788 controlled by @code{left-padding} and @code{right-padding},
1789 but these are to be found in the @code{AccidentalPlacement}
1792 @item @code{self-alignment-X}
1794 This property aligns the object to the left, to the right, or
1795 centers it with respect to the parent object's reference point.
1796 It may be used with all objects which support the
1797 @code{self-alignment-interface} -- in general these are objects
1798 that contain text. The values are @code{LEFT}, @code{RIGHT}
1799 or @code{CENTER}. The movement is limited by the length of the
1804 Objects do not all have all of these properties in general.
1805 It is necessary to go to the IR to look up which properties
1806 are available for the object in question.
1809 Finally, when all else fails, objects may be repositioned manually
1810 by changing their separation distance from other objects, or by
1811 repositioning them relative to the staff center line. The
1812 disadvantages are that the correct values for the repositioning
1813 have to be worked out, often by trial and error, for every object
1814 individually, and the user is responsible for any collisions that
1815 might follow. But the main difficulty with this approach is that
1816 the repositioning values may need to be reworked if the music is
1817 later modified. The properties that can be used for this type of
1821 @item @code{extra-offset}
1822 @cindex extra-offset property
1824 This property applies to any layout object
1825 supporting the @code{grob-interface}. It takes a pair of
1826 numbers giving the extra displacement in the horizontal and
1827 vertical directions. Negative numbers move the object to
1828 the left or down. The units are staff-spaces. The extra
1829 displacement is made after the typesetting of objects is
1830 finished, so an object may be repositioned anywhere without
1831 affecting anything else.
1833 @item @code{force-hshift}
1834 @cindex force-hshift property
1836 Closely spaced notes in a chord, or notes occuring at the same
1837 time in different voices, are arranged in two, occasionally more,
1838 columns to prevent the noteheads overlapping. These are called
1839 note columns, and an object called @code{NoteColumn} is created
1840 to lay out the notes in that column. There are separate columns
1841 for each voice. The @code{force-hshift}
1842 property is a property of a @code{NoteColumn} (actually of the
1843 @code{note-column-interface}). Changing it permits a note column
1844 to be moved in units appropriate to a note column, viz. the note
1845 head width of the first voice note. It is preferable to the
1846 @code{extra-offset} property for this purpose as there is no need
1847 to work out the distance in staff-spaces.
1849 @item @code{positions}
1850 @cindex positions property
1852 This is most useful for manually adjusting the slope and height
1853 of beams, ties, slurs, and tuplets. It takes a pair of numbers
1854 giving the position of the left and right ends of the beam, slur,
1855 etc. relative to the center line of the staff. Units are
1858 @item @code{staff-position}
1859 @cindex staff-position property
1861 @code{staff-position} is a property of the
1862 @code{staff-symbol-referencer-interface}, which is supported by
1863 objects which are positioned relative to the staff. It specifies
1864 the vertical position of the object relative to the center line
1865 of the staff in half staff-spaces.
1869 Objects do not all have all of these properties in general.
1870 It is necessary to go to the IR to look up which properties
1871 are available for the object in question.
1875 Here is a list of the objects which are most likely to be
1876 involved in collisions, together with the name of the object which
1877 should be looked up in the IR in order to discover which properties
1878 should be used to move them.
1880 @multitable @columnfractions .33 .66
1881 @headitem Object type @tab Object name
1882 @item Articulations @tab @code{Script}
1883 @item Dynamics (vertically) @tab @code{DynamicLineSpanner}
1884 @item Dynamics (horizontally) @tab @code{DynamicText}
1885 @item Fingerings @tab @code{Fingering}
1886 @item Rehearsal / Text marks @tab @code{RehearsalMark}
1887 @item Slurs @tab @code{Slur}
1888 @item Text e.g. @code{^"text"} @tab @code{TextScript}
1889 @item Ties @tab @code{Tie}
1893 @node Fixing overlapping notation
1894 @subsection Fixing overlapping notation
1896 Let's now see how the properties in the previous section can
1897 help to resolve overlapping notation.
1902 TODO Find a better example
1904 Let's try the effect of @code{padding} on the rather artificial
1905 example above. This is a property of
1906 @code{DynamicLineSpanner}, not @code{DynamicText}.
1908 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1910 % Increase vertical padding by 5 units
1911 \override DynamicLineSpanner #'padding = #'5
1915 Dynamics are positioned vertically with respect to the note to
1916 which they are attached. We see that this has moved all the
1917 dynamics up by five staff spaces, but has had no effect on the
1918 horizontal separation, nor on the placement of the dynamics
1919 relative to each other.
1921 The @code{padding} property can be set to increase
1922 (or decrease) the distance between symbols that are printed
1923 above or below notes. This applies to all objects with
1924 @code{side-position-interface}.
1926 @lilypond[quote,fragment,relative=1,verbatim]
1928 \override Script #'padding = #3
1932 @lilypond[quote,fragment,relative=1,verbatim]
1933 % This will not work, see below:
1934 \override MetronomeMark #'padding = #3
1938 \override Score.MetronomeMark #'padding = #3
1943 Note in the second example how important it is to figure out what
1944 context handles a certain object. Since the @code{MetronomeMark} object
1945 is handled in the @code{Score} context, property changes in the
1946 @code{Voice} context will not be noticed. For more details, see
1947 @ruser{Constructing a tweak}.
1950 @subheading self-alignment-X
1951 @cindex self-alignment-X
1953 The following example shows how this can resolve the collision
1954 of a string fingering object with a note's stem by aligning the
1955 right edge with the reference point of the parent note:
1957 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
1960 \once \override StringNumber #'self-alignment-X = #RIGHT
1964 @subheading extra-offset
1965 @cindex extra-offset property
1967 Another solution gives us complete control over placing the object -- we
1968 can move it horizontally or vertically. This is done with the
1969 @code{extra-offset} property. It is slightly more complicated and can
1970 cause other problems. When we move objects with @code{extra-offset},
1971 the movement is done after LilyPond has placed all other objects. This
1972 means that the result can overlap with other objects.
1974 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1975 % temporary code to break this example:
1976 \override TextScript #'outside-staff-priority = ##f
1977 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
1978 e4^\markup{ \italic ritenuto } g b e
1981 With @code{extra-offset}, the first number controls the horizontal
1982 movement (left is negative); the second number controls the vertical
1983 movement (up is positive). After a bit of experimenting, we decided
1984 that these values look good
1986 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1987 % temporary code to break this example:
1988 \override TextScript #'outside-staff-priority = ##f
1989 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
1990 e4^\markup{ \italic ritenuto } g b e
1994 Again, these numbers are simply the result of a few experiments and
1995 looking at the output. You might prefer the text to be slightly higher,
1996 or to the left, or whatever. Try it and look at the result!
1998 In the following example, the second fingering is moved a little to
1999 the left, and 1.8 staff space downwards:
2001 @lilypond[quote,fragment,relative=1,verbatim]
2004 \once \override Fingering
2005 #'extra-offset = #'(-0.3 . -1.8)
2010 @subheading force-hshift
2011 @cindex force-hshift property
2013 We introduce just one here, the @code{force-hshift} property of
2014 @code{NoteColumn}. The lower two notes of the first chord (i.e,
2015 those in the third voice) should not be shifted away from the
2016 note column of the higher two notes. To correct this we set
2017 @code{force-hshift} of these notes to zero.
2018 The lower note of the second chord is best placed just to the
2019 right of the higher notes. We achieve this by setting
2020 @code{force-hshift} of this note to 0.5, ie half a notehead's
2021 width to the right of the note column of the higher notes.
2023 Here's the final result:
2025 @lilypond[quote,verbatim,fragment,ragged-right]
2026 \new Staff \relative c'' {
2029 { c2 aes4. bes8 } \\
2032 \once \override NoteColumn #'force-hshift = #0 <ees c>2
2033 \once \override NoteColumn #'force-hshift = #0.5 des2
2041 TODO To be continued ....
2043 TODO Old stuff follows
2048 @section Page layout
2051 * Fitting music onto fewer pages::
2054 @node Fitting music onto fewer pages
2055 @subsection Fitting music onto fewer pages
2057 Sometimes you can end up with one or two staves on a second
2058 (or third, or fourth...) page. This is annoying, especially
2059 if you look at previous pages and it looks like there is plenty
2060 of room left on those.
2062 When investigating layout issues, @code{annotate-spacing} is
2063 an invaluable tool. This command prints the values of various
2064 layout spacing commands; see @ruser{Displaying spacing}, for more
2065 details. From the output of @code{annotate-spacing}, we can
2066 see which margins we may wish to alter.
2068 Other than margins, there are a few other options to save space:
2072 You may tell LilyPond to place systems as close together as
2073 possible (to fit as many systems as possible onto a page), but
2074 then to space those systems out so that there is no blank
2075 space at the bottom of the page.
2079 between-system-padding = #0.1
2080 between-system-space = #0.1
2081 ragged-last-bottom = ##f
2087 You may force the number of systems (i.e., if LilyPond wants
2088 to typeset some music with 11 systems, you could force it to
2098 Avoid (or reduce) objects which increase the vertical size of
2099 a system. For example, volta repeats (or alternate repeats)
2100 require extra space. If these repeats are spread over two
2101 systems, they will take up more space than one system with
2102 the volta repeats and another system without.
2104 Another example is moving dynamics which @q{stick out} of
2107 @lilypond[verbatim,quote,fragment]
2110 \override DynamicLineSpanner #'padding = #-1.8
2111 \override DynamicText #'extra-offset = #'( -2.1 . 0)
2117 Alter the horizontal spacing via @code{SpacingSpanner}. See
2118 @ruser{Changing horizontal spacing}, for more details.
2120 @lilypond[verbatim,quote]
2123 g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
2124 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2125 d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
2126 g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2131 \override SpacingSpanner
2132 #'base-shortest-duration = #(ly:make-moment 1 4)
2144 @c Old stuff follows -td
2147 @section Common tweaks
2152 * Other common tweaks::
2157 @node Other common tweaks
2158 @subsection Other common tweaks
2160 Some overrides are so common that predefined commands are provided as
2161 short-cuts, such as @code{\slurUp} and @code{\stemDown}. These
2162 commands are described in the Notation Reference under the appropriate
2165 The complete list of modifications available for each type of
2166 object (like slurs or beams) are documented in the Program
2167 Reference. However, many layout objects share properties which can be
2168 used to apply generic tweaks.
2174 Setting the @code{transparent} property will cause an object to be printed
2175 in @q{invisible ink}: the object is not printed, but all its other
2176 behavior is retained. The object still takes up space, it takes part in
2177 collisions, and slurs, ties, and beams can be attached to it.
2179 @cindex transparent objects
2180 @cindex removing objects
2181 @cindex hiding objects
2182 @cindex invisible objects
2183 The following example demonstrates how to connect different voices
2184 using ties. Normally, ties only connect two notes in the same
2185 voice. By introducing a tie in a different voice,
2187 @lilypond[quote,fragment,relative=2]
2196 and blanking the first up-stem in that voice, the tie appears to cross
2200 @lilypond[quote,fragment,relative=2,verbatim]
2202 \once \override Stem #'transparent = ##t
2209 To make sure that the just-blanked stem doesn't squeeze the tie too much,
2210 we also lengthen the stem, by setting the @code{length} to
2213 @lilypond[quote,fragment,relative=2,verbatim]
2215 \once \override Stem #'transparent = ##t
2216 \once \override Stem #'length = #8
2225 @cindex Tweaks, distances
2228 Distances in LilyPond are measured in staff-spaces, while most
2229 thickness properties are measured in line-thickness. Some
2230 properties are different; for example, the thickness of beams
2231 are measured in staff-spaces. For more information, see the
2232 relevant portion of the program reference.
2236 @node TODO other name
2237 @section TODO other name
2240 * Predefined tweaks::
2241 * Advanced tweaks with Scheme::
2242 * Avoiding tweaks with slower processing::
2243 * The three methods of tweaking::
2246 @node Predefined tweaks
2247 @subsection Predefined tweaks
2249 TODO: Some tweaks are really common, blah blah.
2251 for example \slurUp, \fatText.
2253 Show example, then explain where to find ly/propert-ly.
2256 The Internals Reference documentation contains a lot of information
2257 about LilyPond, but even more information can be gathered from
2258 looking at the internal LilyPond files.
2260 Some default settings (such as the definitions for
2261 @code{\header@{@}}s) are stored as @code{.ly} files. Other
2262 settings (such as the definitions of markup commands) are
2263 stored as @code{.scm} (Scheme) files. Further explanation is
2264 outside the scope of this manual; users should be warned that
2265 a substantial amount of technical knowledge or time is required
2266 to understand these files.
2270 @item Linux: @file{@var{installdir}/lilypond/usr/share/lilypond/current/}
2273 @file{@var{installdir}/LilyPond.app/Contents/Resources/share/lilypond/current/}.
2274 To access this, either @code{cd} into this directory from the
2275 Terminal, or control-click on the LilyPond application and select
2276 @q{Show Package Contents}.
2278 @item Windows: @file{@var{installdir}/LilyPond/usr/share/lilypond/current/}
2282 The @file{ly/} and @file{scm/} directories will be of
2283 particular interest. Files such as @file{ly/property-init.ly} and
2284 @file{ly/declarations-init.ly} define all the common tweaks.
2287 @node Advanced tweaks with Scheme
2288 @subsection Advanced tweaks with Scheme
2290 We have seen how LilyPond output can be heavily modified using
2292 @code{\override TextScript #'extra-offset = ( 1 . -1)}. But
2293 we have even more power if we use Scheme. For a full explantion
2294 of this, see the @ref{Scheme tutorial}, and
2295 @ruser{Interfaces for programmers}.
2297 We can use Scheme to simply @code{\override} commands,
2299 @lilypond[quote,verbatim,ragged-right]
2300 padText = #(define-music-function (parser location padding) (number?)
2302 \once \override TextScript #'padding = #$padding
2306 c4^"piu mosso" b a b
2308 c4^"piu mosso" d e f
2310 c4^"piu mosso" fis a g
2314 We can use it to create new commands,
2316 @lilypond[quote,verbatim,ragged-right]
2317 tempoMark = #(define-music-function (parser location padding marktext)
2320 \once \override Score . RehearsalMark #'padding = $padding
2321 \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
2322 \mark \markup { \bold $marktext }
2327 \tempoMark #3.0 #"Allegro"
2332 Even music expressions can be passed in.
2334 @lilypond[quote,verbatim,ragged-right]
2335 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
2342 \pattern {d16 dis} { ais16-> b\p }
2347 @node Avoiding tweaks with slower processing
2348 @subsection Avoiding tweaks with slower processing
2350 LilyPond can perform extra checks while it processes files. These
2351 commands will take extra time, but the result may require fewer
2355 %% makes sure text scripts and lyrics are within the paper margins
2356 \override Score.PaperColumn #'keep-inside-line = ##t
2357 \override Score.NonMusicalPaperColumn #'keep-inside-line = ##t
2360 In some cases (see issue 246), this must be done before
2361 @code{\override} commands can be processed.
2365 \override PaperColumn #'keep-inside-line = ##t
2366 \override NonMusicalPaperColumn #'keep-inside-line = ##t
2373 @node The three methods of tweaking
2374 @subsection The three methods of tweaking
2396 FIXME discuss \tweak
2403 - There is a section in the manual on \set vs \override (3.3.7),
2404 which is incomplete. First it doesn't mention \overrideProperty,
2405 nor does it mention properties which are not capitalized at all.
2406 And it should explain that \override should be used to set
2407 properties with hyphenated names, like auto-knee-gap. (I had to
2408 experiment to find out how to do this.)