]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/tweaks.itely
Doc: LM 4.1.2 additonal para for positioning grobs
[lilypond.git] / Documentation / learning / tweaks.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.19.2"
12
13 @node Tweaking output
14 @chapter Tweaking output
15
16 This chapter discusses how to modify output.  LilyPond is extremely
17 configurable; virtually every fragment of output may be changed.
18
19
20 @menu
21 * Tweaking basics::
22 * The Internals Reference manual::
23 * Appearance of objects::
24 * Placement of objects::
25 * Vertical spacing::
26 * Collisions of objects::
27 * Further tweaking::
28 @end menu
29
30 @node Tweaking basics
31 @section Tweaking basics
32
33 @menu
34 * Introduction to tweaks::
35 * Objects and interfaces::
36 * Naming conventions of objects and properties::
37 * Tweaking methods::
38 @end menu
39
40 @node Introduction to tweaks
41 @subsection Introduction to tweaks
42
43 @q{Tweaking} is a LilyPond term for the various methods available
44 to the user for modifying the actions taken during interpretation
45 of the input file and modifying the appearance of the printed
46 output.  Some tweaks are very easy to use; others are more
47 complex.  But taken together the methods available for tweaking
48 permit almost any desired appearance of the printed music to be
49 achieved.
50
51 In this section we cover the basic concepts required to understand
52 tweaking.  Later we give a variety of ready-made commands which can
53 simply be copied to obtain the same effect in your own scores, and
54 at the same time we show how these commands may be constructed so
55 that you may learn how to develop your own tweaks.
56
57 Before starting on this Chapter you may wish to review the section
58 @ref{Contexts and engravers}, as Contexts, Engravers, and the
59 Properties contained within them are fundamental to understanding
60 and constructing Tweaks.
61
62 @node Objects and interfaces
63 @subsection Objects and interfaces
64
65 @cindex object
66 @cindex grob
67 @cindex spanner
68 @cindex interface
69 @cindex properties, object
70 @cindex object properties
71 @cindex layout object
72 @cindex object, layout
73 @cindex interface
74
75 Tweaking involves modifying the internal operation and structures
76 of the LilyPond program, so we must first introduce some terms
77 which are used to describe those internal operations and
78 structures.
79
80 The term @q{Object} is a generic term used to refer to the
81 multitude of internal structures built by LilyPond during the
82 processing of an input file.  So when a command like @code{\new
83 Staff} is encountered a new object of type @code{Staff} is
84 constructed.  That @code{Staff} object then holds all the
85 properties associated with that particular staff, for example, its
86 name and its key signature, together with details of the engravers
87 which have been assigned to operate within that staff's context.
88 Similarly, there are objects to hold the properties of all other
89 contexts, such as @code{Voice} objects, @code{Score} objects,
90 @code{Lyrics} objects, as well as objects to represent all
91 notational elements such as bar lines,
92 note heads, ties, dynamics, etc.  Every object has its own set of
93 property values.
94
95 Some types of object are given special names.  Objects which represent
96 items of notation on the printed output such as note heads, stems,
97 slurs, ties, fingering, clefs, etc are called @q{Layout objects},
98 often known as @q{Graphical Objects}, or @q{Grobs} for short.  These
99 are still objects in the generic sense above, and so they too all have
100 properties associated with them, such as their position, size, color,
101 etc.
102
103 Some layout objects are still more specialized.  Phrasing slurs,
104 crescendo hairpins, ottava marks, and many other grobs are not
105 localized in a single place -- they have a starting point, an
106 ending point, and maybe other properties concerned with their
107 shape.  Objects with an extended shape like these are called
108 @q{Spanners}.
109
110 What is more, there are @q{abstract} grobs which do not print
111 anything of their own, but rather collect, position and manage
112 other grobs.  Common examples for this are
113 @code{DynamicLineSpanner}, @code{BreakAlignment},
114 @code{NoteColumn}, @code{VerticalAxisGroup},
115 @code{NonMusicalPaperColumn} and similar.  We will see how some of
116 these are used later.
117
118 It remains to explain what @q{Interfaces} are.  Many objects, even
119 though they are quite different, share common features which need to
120 be processed in the same way.  For example, all grobs have a color, a
121 size, a position, etc, and all these properties are processed in the
122 same way during LilyPond's interpretation of the input file.  To
123 simplify these internal operations these common actions and properties
124 are grouped together in an object called a @code{grob-interface}.
125 There are many other groupings of common properties like this, each
126 one given a name ending in @code{interface}.  In total there are over
127 100 such interfaces.  We shall see later why this is of interest and
128 use to the user.
129
130 These, then, are the main terms relating to objects which we
131 shall use in this chapter.
132
133 @node Naming conventions of objects and properties
134 @subsection Naming conventions of objects and properties
135
136 @cindex naming conventions for objects
137 @cindex naming conventions for properties
138 @cindex objects, naming conventions
139 @cindex properties, naming conventions
140
141 We met some object naming conventions previously, in
142 @ref{Contexts and engravers}.  Here for reference is a list
143 of the most common object and property types together with
144 the conventions for naming them and a couple of examples of
145 some real names.  We have used @q{A} to stand for any capitalized
146 alphabetic character and @q{aaa} to stand for any number of
147 lower-case alphabetic characters.  Other characters are used
148 verbatim.
149
150 @multitable @columnfractions .33 .33 .33
151 @headitem Object/property type
152   @tab Naming convention
153   @tab Examples
154 @item Contexts
155   @tab Aaaa or AaaaAaaaAaaa
156   @tab Staff, GrandStaff
157 @item Layout Objects
158   @tab Aaaa or AaaaAaaaAaaa
159   @tab Slur, NoteHead
160 @item Engravers
161   @tab Aaaa_aaa_engraver
162   @tab Clef_engraver, Note_heads_engraver
163 @item Interfaces
164   @tab aaa-aaa-interface
165   @tab grob-interface, break-aligned-interface
166 @item Context Properties
167   @tab aaa or aaaAaaaAaaa
168   @tab alignAboveContext, skipBars
169 @item Layout Object Properties
170   @tab aaa or aaa-aaa-aaa
171   @tab direction, beam-thickness
172 @end multitable
173
174 As we shall see shortly, the properties of different types of object are
175 modified by different commands, so it is useful to be able to recognize
176 the types of objects and properties from their names.
177
178
179 @node Tweaking methods
180 @subsection Tweaking methods
181
182 @cindex tweaking methods
183
184 @menu
185 * The override command::
186 * The revert command::
187 * The once prefix::
188 * The overrideProperty command::
189 * The tweak command::
190 @end menu
191
192 @node The override command
193 @unnumberedsubsubsec The @code{@bs{}override} command
194
195 @cindex override command
196 @cindex override syntax
197
198 @funindex \override
199 @funindex override
200
201 We have already met the commands @code{\set} and @code{\with}, used to
202 change the properties of @strong{contexts} and to remove and add
203 @strong{engravers}, in @ref{Modifying context properties}, and
204 @ref{Adding and removing engravers}.  We must now introduce some more
205 important commands.
206
207 The command to change the properties of @strong{layout objects} is
208 @code{\override}.  Because this command has to modify
209 internal properties deep within LilyPond its syntax is not
210 as simple as the commands you have used so far.  It needs to
211 know precisely which property of which object in which context
212 has to be modified, and what its new value is to be.  Let's see
213 how this is done.
214
215 The general syntax of this command is:
216
217 @example
218 \override @var{Context}.@var{LayoutObject}.@var{layout-property} = #@var{value}
219 @end example
220
221 @noindent
222 This will set the property with the name @var{layout-property} of the
223 layout object with the name @var{LayoutObject}, which is a member of
224 the @var{Context} context, to the value @var{value}.
225
226 The @var{Context} may be omitted (and usually is) when the
227 required context is unambiguously implied and is one of lowest
228 level contexts, i.e., @code{Voice}, @code{ChordNames} or
229 @code{Lyrics}, and we shall omit it in many of the following
230 examples.  We shall see later when it must be specified.
231
232 Later sections deal comprehensively with properties and their
233 values, see @ref{Types of properties}.  But in this section we shall
234 use just a few simple properties and values which are easily
235 understood in order to illustrate the format and use of these
236 commands.
237
238 LilyPond's primary expressions are musical items like notes,
239 durations, and markups.  More basic expressions like numbers,
240 strings, and lists are processed in @q{Scheme mode}, which is
241 invoked by prefixing the value with @samp{#}.  Although the
242 values may sometimes have a valid representation in LilyPond's
243 musical mode, this manual will always use @samp{#} for their
244 entry for the sake of consistency.  For more information about
245 Scheme mode, see @rextend{LilyPond Scheme syntax}.
246
247 @code{\override} is the most common command used in tweaking, and
248 most of the rest of this chapter will be directed to presenting
249 examples of how it is used.  Here is a simple example to change the
250 color of the note head:
251
252 @cindex color property, example
253 @cindex NoteHead, example of overriding
254
255 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
256 c4 d
257 \override NoteHead.color = #red
258 e4 f |
259 \override NoteHead.color = #green
260 g4 a b c |
261 @end lilypond
262
263
264 @node The revert command
265 @unnumberedsubsubsec The @code{@bs{}revert} command
266
267 @cindex revert command
268
269 @funindex \revert
270 @funindex revert
271
272 Once overridden, the property retains its new value until it is
273 overridden again or a @code{\revert} command is encountered.
274 The @code{\revert} command has the following syntax and causes
275 the value of the property to revert to its original default
276 value; note, not its previous value if several @code{\override}
277 commands have been issued.
278
279 @example
280 \revert @var{Context}.@var{LayoutObject}.@var{layout-property}
281 @end example
282
283 Again, just like @var{Context} in the @code{\override} command,
284 @var{Context} is often not needed.  It will be omitted
285 in many of the following examples.  Here we revert the color
286 of the note head to the default value for the final two notes:
287
288 @cindex color property, example
289 @cindex NoteHead, example of overriding
290
291 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
292 c4 d
293 \override NoteHead.color = #red
294 e4 f |
295 \override NoteHead.color = #green
296 g4 a
297 \revert NoteHead.color
298 b4 c |
299 @end lilypond
300
301
302 @node The once prefix
303 @unnumberedsubsubsec The @code{@bs{}once} prefix
304
305 @funindex \once
306 @funindex once
307
308 Both the @code{\override} and the @code{\set} commands may be prefixed
309 by @code{\once}.  This causes the following @code{\override} or
310 @code{\set} command to be effective only during the current musical
311 moment before the property reverts back to its previous value (this can
312 be different from the default if another @code{\override} is still in
313 effect).  Using the same example, we can change the color of a single
314 note like this:
315
316 @cindex color property, example
317 @cindex NoteHead, example of overriding
318
319 @lilypond[quote,verbatim,relative=1]
320 c4 d
321 \override NoteHead.color = #red
322 e4 f |
323 \once \override NoteHead.color = #green
324 g4 a
325 \revert NoteHead.color
326 b c |
327 @end lilypond
328
329 The @code{\once} prefix may also be used in front of many
330 predefined commands to limit their effect to one musical moment:
331
332 @lilypond[quote,verbatim,relative=1]
333 c4 d
334 \once \stemDown
335 e4 f |
336 g4 a
337 \once \hideNotes
338 b c |
339 @end lilypond
340
341 However, predefined commands of the form @code{\@dots{}Neutral},
342 @code{\@dots{}Off} and @code{\un@dots{}} use @code{\revert} internally
343 rather than @code{\override} so prefixing these with @code{\once} has no
344 effect.
345
346
347 @node The overrideProperty command
348 @unnumberedsubsubsec The @code{@bs{}overrideProperty} command
349
350 @cindex overrideProperty command
351
352 @funindex \overrideProperty
353 @funindex overrideProperty
354
355 There is another form of the override command,
356 @code{\overrideProperty}, which is occasionally required.
357 We mention it here for completeness, but for details see
358 @rextend{Difficult tweaks}.
359 @c Maybe explain in a later iteration  -td
360
361
362 @node The tweak command
363 @unnumberedsubsubsec The @code{@bs{}tweak} command
364
365 @cindex tweak command
366
367 @funindex \tweak
368 @funindex tweak
369
370 The final tweaking command which is available is @code{\tweak}.  This
371 should be used when several objects occur at the same musical moment,
372 but you only want to change the properties of selected ones, such as a
373 single note within a chord.  Using @code{\override} would affect all the
374 notes within a chord, whereas @code{\tweak} affects just the following
375 item in the input stream.
376
377 Here's an example.  Suppose we wish to change the size of the
378 middle note head (the E) in a C major chord.  Let's first see what
379 @code{\once \override} would do:
380
381 @cindex font-size property, example
382 @cindex NoteHead, example of overriding
383
384 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
385 <c e g>4
386 \once \override NoteHead.font-size = #-3
387 <c e g>4
388 <c e g>4
389 @end lilypond
390
391 We see the override affects @emph{all} the note heads in the chord.
392 This is because all the notes of a chord occur at the same
393 @emph{musical moment}, and the action of @code{\once} is to
394 apply the override to all layout objects of the type specified
395 which occur at the same musical moment as the @code{\override}
396 command itself.
397
398 The @code{\tweak} command operates in a different way.  It acts on
399 the immediately following item in the input stream.  In its simplest
400 form, it is effective only on objects which are created directly
401 from the following item, essentially note heads and articulations.
402
403 So to return to our example, the size of the middle note of
404 a chord would be changed in this way:
405
406 @cindex font-size property, example
407 @cindex @code{\tweak}, example
408
409 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
410 <c e g>4
411 <c \tweak font-size #-3 e g>4
412 @end lilypond
413
414 Note that the syntax of @code{\tweak} is different from that of the
415 @code{\override} command.  The context should not be specified; in
416 fact, it would generate an error to do so.  Both context and layout
417 object are implied by the following item in the input stream.  Note
418 also that an equals sign should not be present.  So the simple form
419 of the @code{\tweak} command is
420
421 @example
422 \tweak @var{layout-property} #@var{value}
423 @end example
424
425 A @code{\tweak} command can also be used to modify just one in
426 a series of articulations, as shown here:
427
428 @cindex color property, example
429 @cindex @code{\tweak}, example
430
431 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
432 a4^"Black"
433   -\tweak color #red ^"Red"
434   -\tweak color #green _"Green"
435 @end lilypond
436
437 @noindent
438 Note that the @code{\tweak} command must be preceded by an articulation
439 mark since the tweaked expression needs to be applied as an articulation
440 itself.  In case of multiple direction overrides (@code{^} or @code{_}),
441 the leftmost override wins since it is applied last.
442
443 @cindex @code{\tweak}, Accidental
444 @cindex @code{\tweak}, specific layout object
445
446 Objects such as stems and accidentals are created later, and not
447 directly from the following event.  It is still possible to use
448 @code{\tweak} on such indirectly created objects by explicitly naming
449 the layout object, provided that LilyPond can trace its origin back to
450 the original event:
451
452 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
453 <\tweak Accidental.color #red   cis4
454  \tweak Accidental.color #green es
455  g>
456 @end lilypond
457
458 This long form of the @code{\tweak} command can be described as
459
460 @example
461 \tweak @var{LayoutObject}.@var{layout-property} #@var{value}
462 @end example
463
464 @cindex tuplets, nested
465 @cindex triplets, nested
466 @cindex bracket, tuplet
467 @cindex bracket, triplet
468 @cindex tuplet bracket
469 @cindex triplet bracket
470
471 @funindex TupletBracket
472
473 The @code{\tweak} command must also be used to change the
474 appearance of one of a set of nested tuplets which begin at the
475 same musical moment.  In the following example, the long tuplet
476 bracket and the first of the three short brackets begin at the
477 same musical moment, so any @code{\override} command would apply
478 to both of them.  In the example, @code{\tweak} is used to
479 distinguish between them.  The first @code{\tweak} command
480 specifies that the long tuplet bracket is to be placed above the
481 notes and the second one specifies that the tuplet number is to be
482 printed in red on the first short tuplet bracket.
483
484 @cindex @code{\tweak}, example
485 @cindex direction property, example
486 @cindex color property, example
487
488 @lilypond[quote,ragged-right,verbatim,fragment,relative=2]
489 \tweak direction #up
490 \tuplet 3/4 {
491   \tweak color #red
492   \tuplet 3/2 { c8[ c c] }
493   \tuplet 3/2 { c8[ c c] }
494   \tuplet 3/2 { c8[ c c] }
495 }
496 @end lilypond
497
498 If nested tuplets do not begin at the same moment, their
499 appearance may be modified in the usual way with
500 @code{\override} commands:
501
502 @cindex text property, example
503 @cindex tuplet-number function, example
504 @cindex transparent property, example
505 @cindex TupletNumber, example of overriding
506
507 @lilypond[quote,ragged-right,verbatim,fragment,relative=1]
508 \tuplet 3/2 { c8[ c c] }
509 \once \override TupletNumber.text = #tuplet-number::calc-fraction-text
510 \tuplet 3/2 {
511   c8[ c]
512   c8[ c]
513   \once \override TupletNumber.transparent = ##t
514   \tuplet 3/2 { c8[ c c] }
515   \tuplet 3/2 { c8[ c c] }
516 }
517 @end lilypond
518
519
520 @seealso
521 Notation Reference:
522 @ruser{The tweak command}.
523
524
525 @node The Internals Reference manual
526 @section The Internals Reference manual
527
528 @cindex Internals Reference
529
530 @menu
531 * Properties of layout objects::
532 * Properties found in interfaces::
533 * Types of properties::
534 @end menu
535
536 @node Properties of layout objects
537 @subsection Properties of layout objects
538
539 @cindex properties of layout objects
540 @cindex properties of grobs
541 @cindex grobs, properties of
542 @cindex layout objects, properties of
543 @cindex Internals Reference manual
544
545 Suppose you have a slur in a score which, to your mind,
546 appears too thin and you'd like to draw it a little heavier.
547 How do you go about doing this?  You know from the statements
548 earlier about the flexibility of LilyPond that such a thing
549 should be possible, and you would probably guess that an
550 @code{\override} command would be needed.  But is there a
551 heaviness property for a slur, and if there is, how might it
552 be modified?  This is where the Internals Reference manual
553 comes in.  It contains all the information you might need to
554 construct this and all other @code{\override} commands.
555
556 Before we look at the Internals Reference a word of warning.
557 This is a @strong{reference} document, which means there is
558 little or no explanation contained within it: its purpose is
559 to present information precisely and concisely.  This
560 means it might look daunting at first sight.  Don't worry!
561 The guidance and explanation presented here will enable you
562 to extract the information from the Internals Reference for
563 yourself with just a little practice.
564
565 @cindex override example
566 @cindex Internals Reference, example of using
567 @cindex @code{\addlyrics} example
568
569 Let's use a concrete example with a simple fragment of real
570 music:
571
572 @c Mozart, Die Zauberflöte Nr.7 Duett
573
574 @lilypond[quote,verbatim,relative=2]
575 {
576   \key es \major
577   \time 6/8
578   {
579     r4 bes8 bes[( g]) g |
580     g8[( es]) es d[( f]) as |
581     as8 g
582   }
583   \addlyrics {
584     The man who | feels love's sweet e -- | mo -- tion
585   }
586 }
587 @end lilypond
588
589 Suppose now that we decide we would like the slurs to be a
590 little heavier.  Is this possible?  The slur is certainly a
591 layout object, so the question is, @q{Is there a property
592 belonging to a slur which controls the heaviness?}  To answer
593 this we must look in the Internals Reference, or IR for short.
594
595 The IR for the version of LilyPond you are using may be found
596 on the LilyPond website at @uref{http://lilypond.org}.  Go to the
597 documentation page and click on the Internals Reference link.
598 For learning purposes you should use the standard HTML version,
599 not the @q{one big page} or the PDF.  For the next few
600 paragraphs to make sense you will need to actually do this
601 as you read.
602
603 Under the heading @strong{Top} you will see five links.  Select
604 the link to the @emph{Backend}, which is where information about
605 layout objects is to be found.  There, under the heading
606 @strong{Backend}, select the link to @emph{All layout objects}.
607 The page that appears lists all the layout objects used in your
608 version of LilyPond, in alphabetic order.  Select the link to
609 Slur, and the properties of Slurs are listed.
610
611 An alternative way of finding this page is from the Notation
612 Reference.  On one of the pages that deals with slurs you may find a
613 link to the Internals Reference.  This link will take you directly to
614 this page, but if you have an idea about the name of the layout object
615 to be tweaked, it is easier to go straight to the IR and search there.
616
617 This Slur page in the IR tells us first that Slur objects are created
618 by the Slur_engraver.  Then it lists the standard settings.  Browse
619 through them looking for a property that might control the heaviness of
620 slurs, and you should find
621
622 @example
623 @code{thickness} (number)
624      @code{1.2}
625      Line thickness, generally measured in @code{line-thickness}
626 @end example
627
628 This looks a good bet to change the heaviness.  It tells us that
629 the value of @code{thickness} is a simple @emph{number},
630 that the default value is 1.2, and that the units are
631 in another property called @code{line-thickness}.
632
633 As we said earlier, there are few to no explanations in the IR,
634 but we already have enough information to try changing the
635 slur thickness.  We see that the name of the layout object
636 is @code{Slur}, that the name of the property to change is
637 @code{thickness} and that the new value should be a number
638 somewhat larger than 1.2 if we are to make slurs thicker.
639
640 We can now construct the @code{\override} command by simply
641 substituting the values we have found for the names, omitting
642 the context.  Let's use a very large value for the thickness
643 at first, so we can be sure the command is working.  We get:
644
645 @example
646 \override Slur.thickness = #5.0
647 @end example
648
649 Don't forget the@tie{}@code{#} preceding the new value!
650
651 The final question is, @q{Where should this command be
652 placed?}  While you are unsure and learning, the best
653 answer is, @q{Within the music, before the first slur and
654 close to it.}  Let's do that:
655
656 @cindex Slur example of overriding
657 @cindex thickness property, example
658
659 @lilypond[quote,verbatim,relative=2]
660 {
661   \key es \major
662   \time 6/8
663   {
664     % Increase thickness of all following slurs from 1.2 to 5.0
665     \override Slur.thickness = #5.0
666     r4 bes8 bes[( g]) g |
667     g8[( es]) es d[( f]) as |
668     as8 g
669   }
670   \addlyrics {
671     The man who | feels love's sweet e -- | mo -- tion
672   }
673 }
674 @end lilypond
675
676 @noindent
677 and we see that the slur is indeed heavier.
678
679 So this is the basic way of constructing @code{\override}
680 commands.  There are a few more complications that we
681 shall meet in later sections, but you now know all the
682 essentials required to make up your own -- but you will
683 still need some practice.  This is provided in the examples
684 which follow.
685
686 @subsubsubheading Finding the context
687
688 @cindex context, finding
689 @cindex context, identifying correct
690
691 But first, what if we had needed to specify the Context?
692 What should it be?  We could guess that slurs are in
693 the Voice context, as they are clearly closely associated
694 with individual lines of music, but can we be sure?  To
695 find out, go back to the top of the IR page describing the
696 Slur, where it says @q{Slur objects are created by: Slur
697 engraver}.  So slurs will be created in whichever context
698 the @code{Slur_engraver} is in.  Follow the link to the
699 @code{Slur_engraver} page.  At the very bottom it tells
700 us that @code{Slur_engraver} is part of seven Voice contexts,
701 including the standard voice context, @code{Voice}, so our
702 guess was correct.  And because @code{Voice} is one of the
703 lowest level contexts which is implied unambiguously by
704 the fact that we are entering notes, we can omit it in this
705 location.
706
707 @subsubsubheading Overriding once only
708
709 @cindex overriding once only
710 @cindex once override
711
712 @funindex \once
713 @funindex once
714
715 As you can see, @emph{all} the slurs are thicker in the final example
716 above.  But what if we wanted just the first slur to be thicker?  This
717 is achieved with the @code{\once} command.  Placed immediately before
718 the @code{\override} command it causes it to change only the slur
719 which begins on the @strong{immediately following} note.  If the
720 immediately following note does not begin a slur the command has no
721 effect at all -- it is not remembered until a slur is encountered, it
722 is simply discarded.  So the command with @code{\once} must be
723 repositioned as follows:
724
725 @cindex Slur, example of overriding
726 @cindex thickness property, example
727
728 @lilypond[quote,verbatim,relative=2]
729 {
730   \key es \major
731   \time 6/8
732   {
733     r4 bes8
734     % Increase thickness of immediately following slur only
735     \once \override Slur.thickness = #5.0
736     bes8[( g]) g |
737     g8[( es]) es d[( f]) as |
738     as8 g
739   }
740   \addlyrics {
741     The man who | feels love's sweet e -- | mo -- tion
742   }
743 }
744 @end lilypond
745
746 @noindent
747 Now only the first slur is made heavier.
748
749 The @code{\once} command can also be used before the @code{\set}
750 command.
751
752 @subsubsubheading Reverting
753
754 @cindex revert
755 @cindex default properties, reverting to
756
757 @funindex \revert
758 @funindex revert
759
760 Finally, what if we wanted just the first two slurs to be
761 heavier?  Well, we could use two commands, each preceded by
762 @code{\once} placed immediately before each of the notes where
763 the slurs begin:
764
765 @cindex Slur, example of overriding
766 @cindex thickness property, example
767
768 @lilypond[quote,verbatim,relative=2]
769 {
770   \key es \major
771   \time 6/8
772   {
773     r4 bes8
774     % Increase thickness of immediately following slur only
775     \once \override Slur.thickness = #5.0
776     bes[( g]) g |
777     % Increase thickness of immediately following slur only
778     \once \override Slur.thickness = #5.0
779     g8[( es]) es d[( f]) as |
780     as8 g
781   }
782   \addlyrics {
783     The man who | feels love's sweet e -- | mo -- tion
784   }
785 }
786 @end lilypond
787
788 @noindent
789 or we could omit the @code{\once} command and use the @code{\revert}
790 command to return the @code{thickness} property to its default value
791 after the second slur:
792
793 @cindex Slur, example of overriding
794 @cindex thickness property, example
795
796 @lilypond[quote,verbatim,relative=2]
797 {
798   \key es \major
799   \time 6/8
800   {
801     r4 bes8
802     % Increase thickness of all following slurs from 1.2 to 5.0
803     \override Slur.thickness = #5.0
804     bes[( g]) g |
805     g8[( es]) es
806     % Revert thickness of all following slurs to default of 1.2
807     \revert Slur.thickness
808     d8[( f]) as |
809     as8 g
810   }
811   \addlyrics {
812     The man who | feels love's sweet e -- | mo -- tion
813   }
814 }
815 @end lilypond
816
817 @noindent
818 The @code{\revert} command can be used to return any property
819 changed with @code{\override} back to its default value.
820 You may use whichever method best suits what you want to do.
821
822 That concludes our introduction to the IR, and the basic
823 method of tweaking.  Several examples follow in the later
824 sections of this Chapter, partly to introduce you to some of the
825 additional features of the IR, and partly to give you more
826 practice in extracting information from it.  These examples will
827 contain progressively fewer words of guidance and explanation.
828
829
830 @node Properties found in interfaces
831 @subsection Properties found in interfaces
832
833 @cindex interface
834 @cindex interface properties
835 @cindex properties in interfaces
836
837 Suppose now that we wish to print the lyrics in italics.  What form of
838 @code{\override} command do we need to do this?  We first look in the
839 IR page listing @q{All layout objects}, as before, and look for an
840 object that might control lyrics.  We find @code{LyricText}, which
841 looks right.  Clicking on this shows the settable properties for lyric
842 text.  These include the @code{font-series} and @code{font-size}, but
843 nothing that might give an italic shape.  This is because the shape
844 property is one that is common to all font objects, so, rather than
845 including it in every layout object, it is grouped together with other
846 similar common properties and placed in an @strong{Interface}, the
847 @code{font-interface}.
848
849 So now we need to learn how to find the properties of interfaces,
850 and to discover what objects use these interface properties.
851
852 Look again at the IR page which describes LyricText.  At the bottom of
853 the page is a list of clickable interfaces which LyricText supports.
854 The list has several items, including @code{font-interface}.  Clicking
855 on this brings up the properties associated with this interface, which
856 are also properties of all the objects which support it, including
857 LyricText.
858
859 Now we see all the user-settable properties which control fonts,
860 including @code{font-shape(symbol)}, where @code{symbol} can be
861 set to @code{upright}, @code{italics} or @code{caps}.
862
863 You will notice that @code{font-series} and @code{font-size} are also
864 listed there.  This immediately raises the question: Why are the
865 common font properties @code{font-series} and @code{font-size} listed
866 under @code{LyricText} as well as under the interface
867 @code{font-interface} but @code{font-shape} is not?  The answer is
868 that @code{font-series} and @code{font-size} are changed from their
869 global default values when a @code{LyricText} object is created, but
870 @code{font-shape} is not.  The entries in @code{LyricText} then tell
871 you the values for those two properties which apply to
872 @code{LyricText}.  Other objects which support @code{font-interface}
873 will set these properties differently when they are created.
874
875 Let's see if we can now construct the @code{\override} command
876 to change the lyrics to italics.  The object is @code{LyricText},
877 the property is @code{font-shape} and the value is
878 @code{italic}.  As before, we'll omit the context.
879
880 As an aside, although it is an important one, note that some
881 properties take values that are symbols, like @code{italic}, and
882 must be preceded by an apostrophe, @code{'}.  Symbols are then
883 read internally by LilyPond.  Note the distinction from arbitrary
884 text strings, which would appear as @code{"a text string"}; for
885 more details about symbols and strings, see @rextend{Scheme tutorial}.
886
887 So we see that the @code{\override} command needed to print the lyrics
888 in italics is:
889
890 @example
891 \override LyricText.font-shape = #'italic
892 @end example
893
894 @noindent
895 This should be placed just in front of the lyrics we wish to affect,
896 like so:
897
898 @cindex font-shape property, example
899 @cindex italic, example
900 @cindex LyricText, example of overriding
901 @cindex @code{\addlyrics}, example
902
903 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
904 {
905   \key es \major
906   \time 6/8
907   {
908     r4 bes8 bes[( g]) g |
909     g8[( es]) es d[( f]) as |
910     as8 g
911   }
912   \addlyrics {
913     \override LyricText.font-shape = #'italic
914     The man who | feels love's sweet e -- | mo -- tion
915   }
916 }
917 @end lilypond
918
919 @noindent
920 and the lyrics are all printed in italics.
921
922 @warning{In lyrics always leave whitespace between the final
923 syllable and the terminating brace.}
924
925
926 @seealso
927 Extending: @rextend{Scheme tutorial}.
928
929
930 @node Types of properties
931 @subsection Types of properties
932
933 @cindex property types
934
935 So far we have seen two types of property: @code{number} and
936 @code{symbol}.  To be valid, the value given to a property
937 must be of the correct type and obey the rules for that type.
938 The type of property is always shown in brackets after the
939 property name in the IR.  Here is a list of the types you may
940 need, together with the rules for that type, and some examples.
941 You must always add a hash symbol, @code{#}, of course,
942 to the front of these values when they are entered in the
943 @code{\override} command, even if the value itself already
944 starts with@tie{}@code{#}.  We only give examples for constants
945 here: if you want to compute a value using Scheme, see
946 @rextend{Calculations in Scheme}.
947
948 @multitable @columnfractions .2 .45 .35
949 @headitem Property type
950   @tab Rules
951   @tab Examples
952 @item Boolean
953   @tab Either True or False, represented by #t or #f
954   @tab @code{#t}, @code{#f}
955 @item Dimension (in staff space)
956   @tab A decimal number (in units of staff space)
957   @tab @code{2.5}, @code{0.34}
958 @item Direction
959   @tab A valid direction constant or its numerical equivalent
960   (@code{0} or @code{CENTER} indicate a neutral direction)
961   @tab @code{LEFT}, @code{CENTER}, @code{UP},
962        @code{1}, @w{@code{-1}}
963 @item Integer
964   @tab A whole number
965   @tab @code{3}, @code{-1}
966 @item List
967   @tab A sequence of constants or symbols separated by spaces, enclosed
968   in parentheses
969 and preceded by an apostrophe (quote mark)
970   @tab @code{'(left-edge staff-bar)}, @code{'(1)}, @code{'()},
971        @code{'(1.0 0.25 0.5)}
972 @item Markup
973   @tab Any valid markup
974   @tab @code{\markup @{ \italic "cresc." @}}, @code{"bagpipe"}
975 @item Moment
976   @tab A fraction of a whole note constructed with the
977 make-moment function
978   @tab @code{(ly:make-moment 1/4)},
979        @code{(ly:make-moment 3/8)}
980 @item Number
981   @tab Any positive or negative, possibly decimal, value
982   @tab @code{3}, @w{@code{-2.45}}
983 @item Pair (of numbers)
984   @tab Two numbers separated by a @q{space . space} and enclosed
985 in brackets preceded by an apostrophe
986   @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
987 @item Symbol
988   @tab Any of the set of permitted symbols for that property,
989 preceded by an apostrophe
990   @tab @code{'italic}, @code{'inside}
991 @item Unknown
992   @tab A procedure, or @code{#f} to cause no action
993   @tab @code{bend::print}, @code{ly:text-interface::print},
994        @code{#f}
995 @item Vector
996   @tab Constants
997   enclosed in @code{#(}@dots{}@code{)}.
998   @tab @code{#(#t #t #f)}
999 @end multitable
1000
1001
1002 @seealso
1003 Extending: @rextend{Scheme tutorial}.
1004
1005
1006 @node Appearance of objects
1007 @section Appearance of objects
1008
1009 Let us now put what we have learned into practice with a few
1010 examples which show how tweaks may be used to change the
1011 appearance of the printed music.
1012
1013 @menu
1014 * Visibility and color of objects::
1015 * Size of objects::
1016 * Length and thickness of objects::
1017 @end menu
1018
1019 @node Visibility and color of objects
1020 @subsection Visibility and color of objects
1021
1022 In the educational use of music we might wish to print a score
1023 with certain elements omitted as an exercise for the student,
1024 who is required to supply them.  As a simple example,
1025 let us suppose the exercise is to supply the missing bar lines
1026 in a piece of music.  But the bar lines are normally inserted
1027 automatically.  How do we prevent them printing?
1028
1029 Before we tackle this, let us remember that object properties are
1030 grouped in what are called @emph{interfaces} -- see @ref{Properties
1031 found in interfaces}.  This is simply to group together those
1032 properties that may be used together to tweak a graphical object -- if
1033 one of them is allowed for an object, so are the others.  Some objects
1034 then use the properties in some interfaces, others use them from other
1035 interfaces.  The interfaces which contain the properties used by a
1036 particular grob are listed in the IR at the bottom of the page
1037 describing that grob, and those properties may be viewed by looking at
1038 those interfaces.
1039
1040 We explained how to find information about grobs in @ref{Properties of
1041 layout objects}.  Using the same approach, we go to the IR to find the
1042 layout object which prints bar lines.  Going via @emph{Backend} and
1043 @emph{All layout objects} we find there is a layout object called
1044 @code{BarLine}.  Its properties include two that control its
1045 visibility: @code{break-visibility} and @code{stencil}.  Barline also
1046 supports a number of interfaces, including the @code{grob-interface},
1047 where we find the @code{transparent} and the @code{color} properties.
1048 All of these can affect the visibility of bar lines (and, of course,
1049 by extension, many other layout objects too.)  Let's consider each of
1050 these in turn.
1051
1052 @menu
1053 * The stencil property::
1054 * The break-visibility property::
1055 * The transparent property::
1056 * The color property::
1057 @end menu
1058
1059 @node The stencil property
1060 @unnumberedsubsubsec The @code{stencil} property
1061
1062 @cindex stencil property
1063
1064 This property controls the appearance of the bar lines by specifying
1065 the symbol (glyph) which should be printed.  In common
1066 with many other properties, it can be set to print nothing by
1067 setting its value to @code{#f}.  Let's try it, as before, omitting
1068 the implied Context, @code{Voice}:
1069
1070 @cindex BarLine, example of overriding
1071 @cindex stencil property, example
1072
1073 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1074 {
1075   \time 12/16
1076   \override BarLine.stencil = ##f
1077   c4 b8 c d16 c d8 |
1078   g,8 a16 b8 c d4 e16 |
1079   e8
1080 }
1081 @end lilypond
1082
1083 The bar lines are still printed.  What is wrong?  Go back to the IR
1084 and look again at the page giving the properties of BarLine.  At the
1085 top of the page it says @qq{Barline objects are created by:
1086 Bar_engraver}.  Go to the @code{Bar_engraver} page.  At the bottom it
1087 gives a list of Contexts in which the bar engraver operates.  All of
1088 them are of the type @code{Staff}, so the reason the @code{\override}
1089 command failed to work as expected is because @code{Barline} is not in
1090 the default @code{Voice} context.  If the context is specified
1091 incorrectly, the command simply does not work.  No error message is
1092 produced, and nothing is logged in the log file.  Let's try correcting
1093 it by adding the correct context:
1094
1095 @cindex BarLine, example of overriding
1096 @cindex stencil property, example
1097
1098 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1099 {
1100   \time 12/16
1101   \override Staff.BarLine.stencil = ##f
1102   c4 b8 c d16 c d8 |
1103   g,8 a16 b8 c d4 e16 |
1104   e8
1105 }
1106 @end lilypond
1107
1108 Now the bar lines have vanished.  Setting the @code{stencil}
1109 property to @code{#f} is such a frequent operation that there is a
1110 shorthand for it called @code{\omit}:
1111 @funindex \omit
1112
1113 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1114 {
1115   \time 12/16
1116   \omit Staff.BarLine
1117   c4 b8 c d16 c d8 |
1118   g,8 a16 b8 c d4 e16 |
1119   e8
1120 }
1121 @end lilypond
1122
1123 Note, though, that setting the @code{stencil} property to @code{#f}
1124 will cause errors when the dimensions of the object are required for
1125 correct processing.  For example, errors will be generated if the
1126 @code{stencil} property of the @code{NoteHead} object is set to
1127 @code{#f}.  If this is the case, you can instead use the
1128 @code{point-stencil} function, which sets the stencil to an object
1129 with zero size:
1130
1131 @lilypond[quote,verbatim,relative=2]
1132 {
1133   c4 c
1134   \once \override NoteHead.stencil = #point-stencil
1135   c4 c
1136 }
1137 @end lilypond
1138
1139 @node The break-visibility property
1140 @unnumberedsubsubsec The @code{break-visibility} property
1141
1142 @cindex break-visibility property
1143
1144 We see from the @code{BarLine} properties in the IR that the
1145 @code{break-visibility} property requires a vector of three booleans.
1146 These control respectively whether bar lines are printed at the end of
1147 a line, in the middle of lines, and at the beginning of lines.  For
1148 our example we want all bar lines to be suppressed, so the value we
1149 need is @code{#(#f #f #f)} (also available
1150 under the name @code{all-invisible}).  Let's try that, remembering to include
1151 the @code{Staff} context.  Note also that in writing this value we
1152 have @code{##} before the opening parenthesis.  One @code{#} is required
1153 as part of vector constant syntax, and the first@tie{}@code{#} is
1154 required, as always, to precede the value itself in the
1155 @code{\override} command.
1156
1157 @cindex BarLine, example of overriding
1158 @cindex break-visibility property, example
1159
1160 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1161 {
1162   \time 12/16
1163   \override Staff.BarLine.break-visibility = ##(#f #f #f)
1164   c4 b8 c d16 c d8 |
1165   g,8 a16 b8 c d4 e16 |
1166   e8
1167 }
1168 @end lilypond
1169
1170 And we see this too removes all the bar lines.
1171
1172 @node The transparent property
1173 @unnumberedsubsubsec The @code{transparent} property
1174
1175 @cindex transparent property
1176 @cindex transparency
1177
1178 We see from the properties specified in the @code{grob-interface} page
1179 in the IR that the @code{transparent} property is a boolean.  This
1180 should be set to @code{#t} to make the grob transparent.  In this next
1181 example let us make the time signature invisible rather than the bar
1182 lines.  To do this we need to find the grob name for the time
1183 signature.  Back to the @q{All layout objects} page in the IR to find
1184 the properties of the @code{TimeSignature} layout object.  This is
1185 produced by the @code{Time_signature_engraver} which you can check
1186 also lives in the @code{Staff} context and also supports the
1187 @code{grob-interface}.  So the command to make the time signature
1188 transparent is:
1189
1190 @cindex TimeSignature, example of overriding
1191 @cindex transparent property, example
1192
1193 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1194 {
1195   \time 12/16
1196   \override Staff.TimeSignature.transparent = ##t
1197   c4 b8 c d16 c d8 |
1198   g,8 a16 b8 c d4 e16 |
1199   e8
1200 }
1201 @end lilypond
1202
1203 @noindent
1204 Again, setting the @code{transparent} property is a rather
1205 frequent operation, so we have a shorthand for it called
1206 @code{\hide}:
1207 @funindex \hide
1208
1209 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1210 {
1211   \time 12/16
1212   \hide Staff.TimeSignature
1213   c4 b8 c d16 c d8 |
1214   g,8 a16 b8 c d4 e16 |
1215   e8
1216 }
1217 @end lilypond
1218
1219 @noindent
1220 In either case, the time signature is gone, but this command
1221 leaves a gap where
1222 the time signature should be.  Maybe this is what is wanted for
1223 an exercise for the student to fill it in, but in other
1224 circumstances a gap might be undesirable.  To remove it, the
1225 stencil for the time signature should be set to @code{#f}
1226 instead:
1227
1228 @cindex TimeSignature, example of overriding
1229 @cindex stencil property, example
1230
1231 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1232 {
1233   \time 12/16
1234   \omit Staff.TimeSignature
1235   c4 b8 c d16 c d8 |
1236   g,8 a16 b8 c d4 e16 |
1237   e8
1238 }
1239 @end lilypond
1240
1241 @noindent
1242 and the difference is obvious: setting the stencil to @code{#f}
1243 (possibly via @code{\omit})
1244 removes the object entirely; making the object @code{transparent}
1245 (which can be done using @code{\hide})
1246 leaves it where it is, but makes it invisible.
1247
1248 @node The color property
1249 @unnumberedsubsubsec The @code{color} property
1250
1251 @cindex color property
1252
1253 Finally let us try making the bar lines invisible by coloring
1254 them white.  (There is a difficulty with this in that the
1255 white bar line may or may not blank out the staff lines where
1256 they cross.  You may see in some of the examples below that this
1257 happens unpredictably.  The details of why this is so and how to
1258 control it are covered in @ruser{Painting objects white}.  But at
1259 the moment we are learning about color, so please just accept this
1260 limitation for now.)
1261
1262 The @code{grob-interface} specifies that the
1263 color property value is a list, but there is no
1264 explanation of what that list should be.  The list it
1265 requires is actually a list of values in internal units,
1266 but, to avoid having to know what these are, several ways
1267 are provided to specify colors.  The first way is to use one
1268 of the @q{normal} colors listed in the first table in
1269 @ruser{List of colors}.  To set the bar lines to white
1270 we write:
1271
1272 @cindex BarLine, example of overriding
1273 @cindex color property, example
1274
1275 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1276 {
1277   \time 12/16
1278   \override Staff.BarLine.color = #white
1279   c4 b8 c d16 c d8 |
1280   g,8 a16 b8 c d4 e16 |
1281   e8
1282 }
1283 @end lilypond
1284
1285 @noindent
1286 and again, we see the bar lines are not visible.  Note that
1287 @emph{white} is not preceded by an apostrophe -- it is not
1288 a symbol, but a @emph{variable}.  When evaluated, it provides
1289 the list of internal values required to set the color to
1290 white.  The other colors in the normal list are variables
1291 too.  To convince yourself this is working you might like
1292 to change the color to one of the other variables in the
1293 list.
1294
1295 @cindex color, X11
1296 @cindex X11 colors
1297
1298 @funindex x11-color
1299
1300 The second way of changing the color is to use the list of
1301 X11 color names in the second list in @ruser{List of colors}.
1302 However, these are mapped to the actual values by the function
1303 @code{x11-color} which
1304 converts X11 color symbols into the list of internal values like this:
1305
1306 @cindex BarLine, example of overriding
1307 @cindex color property, example
1308
1309 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1310 {
1311   \time 12/16
1312   \override Staff.BarLine.color = #(x11-color 'white)
1313   c4 b8 c d16 c d8 |
1314   g,8 a16 b8 c d4 e16 |
1315   e8
1316 }
1317 @end lilypond
1318
1319 @noindent
1320 Note that in this case the function @code{x11-color} takes
1321 a symbol as an argument, so the symbol must be preceded by
1322 an apostrophe to keep it from being evaluated as a variable, and
1323 the whole function call has to be enclosed in parentheses.
1324
1325 @cindex rgb colors
1326 @cindex color, rgb
1327
1328 @funindex rgb-color
1329
1330 There is another function, one which converts RGB values into
1331 internal colors -- the @code{rgb-color} function.  This takes
1332 three arguments giving the intensities of the red, green and
1333 blue colors.  These take values in the range 0 to 1.  So to
1334 set the color to red the value should be @code{(rgb-color 1 0 0)}
1335 and to white it should be @code{(rgb-color 1 1 1)}:
1336
1337 @cindex BarLine, example of overriding
1338 @cindex color property, example
1339
1340 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1341 {
1342   \time 12/16
1343   \override Staff.BarLine.color = #(rgb-color 1 1 1)
1344   c4 b8 c d16 c d8 |
1345   g,8 a16 b8 c d4 e16 |
1346   e8
1347 }
1348 @end lilypond
1349
1350 Finally, there is also a grey scale available as part of the
1351 X11 set of colors.  These range from black, @code{'grey0},
1352 to white, @code{'grey100}, in steps of 1.  Let's illustrate
1353 this by setting all the layout objects in our example to
1354 various shades of grey:
1355
1356 @cindex StaffSymbol, example of overriding
1357 @cindex TimeSignature, example of overriding
1358 @cindex Clef, example of overriding
1359 @cindex NoteHead, example of overriding
1360 @cindex Stem, example of overriding
1361 @cindex BarLine, example of overriding
1362 @cindex color property, example
1363 @cindex x11-color, example of using
1364
1365 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1366 {
1367   \time 12/16
1368   \override Staff.StaffSymbol.color = #(x11-color 'grey30)
1369   \override Staff.TimeSignature.color = #(x11-color 'grey60)
1370   \override Staff.Clef.color = #(x11-color 'grey60)
1371   \override Voice.NoteHead.color = #(x11-color 'grey85)
1372   \override Voice.Stem.color = #(x11-color 'grey85)
1373   \override Staff.BarLine.color = #(x11-color 'grey10)
1374   c4 b8 c d16 c d8 |
1375   g,8 a16 b8 c d4 e16 |
1376   e8
1377 }
1378 @end lilypond
1379
1380 @noindent
1381 Note the contexts associated with each of the layout objects.
1382 It is important to get these right, or the commands will not
1383 work!  Remember, the context is the one in which the appropriate
1384 engraver is placed.  The default context for engravers can be
1385 found by starting from the layout object, going from there to
1386 the engraver which produces it, and on the engraver page in the
1387 IR it tells you in which context the engraver will normally be
1388 found.
1389
1390
1391 @node Size of objects
1392 @subsection Size of objects
1393
1394 @cindex changing size of objects
1395 @cindex size of objects
1396 @cindex objects, size of
1397 @cindex objects, changing size of
1398
1399 Let us begin by looking again at the earlier example
1400 (see @ref{Nesting music expressions}) which showed
1401 how to introduce a new temporary staff, as in an @rglos{ossia}.
1402
1403 @cindex alignAboveContext property, example
1404 @cindex @code{\with}, example
1405
1406 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1407 \new Staff ="main" {
1408   \relative g' {
1409     r4 g8 g c4 c8 d |
1410     e4 r8
1411     <<
1412       { f8 c c }
1413       \new Staff \with {
1414         alignAboveContext = #"main" }
1415       { f8 f c }
1416     >>
1417     r4 |
1418   }
1419 }
1420 @end lilypond
1421
1422 Ossia are normally written without clef and time signature, and
1423 are usually printed slightly smaller than the main staff.  We
1424 already know now how to remove the clef and time signature --
1425 we simply set the stencil of each to @code{#f}, as follows:
1426
1427 @cindex alignAboveContext property, example
1428 @cindex @code{\with}, example
1429 @funindex \omit
1430 @cindex Clef, example of overriding
1431 @cindex TimeSignature, example of overriding
1432
1433 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1434 \new Staff ="main" {
1435   \relative g' {
1436     r4 g8 g c4 c8 d |
1437     e4 r8
1438     <<
1439       { f8 c c }
1440       \new Staff \with {
1441         alignAboveContext = #"main"
1442       }
1443       {
1444         \omit Staff.Clef
1445         \omit Staff.TimeSignature
1446         { f8 f c }
1447       }
1448     >>
1449     r4 |
1450   }
1451 }
1452 @end lilypond
1453
1454 @noindent
1455 where the extra pair of braces after the @code{\with} clause are
1456 required to ensure the enclosed overrides and music are applied
1457 to the ossia staff.
1458
1459 But what is the difference between modifying the staff context by
1460 using @code{\with} and modifying the stencils of the clef and the
1461 time signature with @code{\override}, or in this case
1462 @code{\omit}?
1463 The main difference is that
1464 changes made in a @code{\with} clause are made at the time the
1465 context is created, and remain in force as the @strong{default}
1466 values for the duration of that context, whereas
1467 @code{\set} or @code{\override} commands embedded in the
1468 music are dynamic -- they make changes synchronized with
1469 a particular point in the music.  If changes are unset or
1470 reverted using @code{\unset} or @code{\revert} they return to
1471 their default values, which will be the ones set in the
1472 @code{\with} clause, or if none have been set there, the normal
1473 default values.
1474
1475 Some context properties can be modified only in @code{\with} clauses.
1476 These are those properties which cannot sensibly be changed after the
1477 context has been created.  @code{alignAboveContext} and its partner,
1478 @code{alignBelowContext}, are two such properties -- once the staff
1479 has been created its alignment is decided and it would make no sense
1480 to try to change it later.
1481
1482 The default values of layout object properties can also be set
1483 in @code{\with} clauses.  Simply use the normal @code{\override}
1484 command leaving out the context name, since this is unambiguously
1485 defined as the context which the @code{\with} clause is modifying.
1486 If fact, an error will be generated if a context is specified
1487 in this location.
1488
1489 So we could replace the example above with
1490
1491 @cindex alignAboveContext property, example
1492 @cindex @code{\with}, example
1493 @cindex Clef, example of overriding
1494 @cindex TimeSignature, example of overriding
1495
1496 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1497 \new Staff ="main" {
1498   \relative g' {
1499     r4 g8 g c4 c8 d |
1500     e4 r8
1501     <<
1502       { f8 c c }
1503       \new Staff \with {
1504         alignAboveContext = #"main"
1505         % Don't print clefs in this staff
1506         \override Clef.stencil = ##f
1507         % Don't print time signatures in this staff
1508         \override TimeSignature.stencil = ##f
1509       }
1510       { f8 f c }
1511     >>
1512     r4 |
1513   }
1514 }
1515 @end lilypond
1516
1517 It turns out that we can also employ the shorthands @code{\hide}
1518 and @code{\omit} for setting the @code{transparent} property and
1519 clearing the @code{stencil} here, leading to the result
1520
1521 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1522 \new Staff ="main" {
1523   \relative g' {
1524     r4 g8 g c4 c8 d |
1525     e4 r8
1526     <<
1527       { f8 c c }
1528       \new Staff \with {
1529         alignAboveContext = #"main"
1530         % Don't print clefs in this staff
1531         \omit Clef
1532         % Don't print time signatures in this staff
1533         \omit TimeSignature
1534       }
1535       { f8 f c }
1536     >>
1537     r4 |
1538   }
1539 }
1540 @end lilypond
1541
1542 Finally we come to changing the size of layout objects.
1543
1544 Some layout objects are created as glyphs selected from a typeface
1545 font.  These include note heads, accidentals, markup, clefs, time
1546 signatures, dynamics and lyrics.  Their size is changed by modifying
1547 the @code{font-size} property, as we shall shortly see.  Other layout
1548 objects such as slurs and ties -- in general, spanner objects -- are
1549 drawn individually, so there is no @code{font-size} associated with
1550 them.  These objects generally derive their size from the objects to
1551 which they are attached, so usually there is no need to change their
1552 size manually.  Still other properties such as the length of stems and
1553 bar lines, thickness of beams and other lines, and the separation of
1554 staff lines all need to be modified in special ways.
1555
1556 Returning to the ossia example, let us first change the font-size.
1557 We can do this in two ways.  We can either change the size of the
1558 fonts of each object type, like @code{NoteHead}s with commands
1559 like
1560
1561 @example
1562 \override NoteHead.font-size = #-2
1563 @end example
1564
1565 or we can change the size of all fonts by setting a special
1566 property, @code{fontSize}, using @code{\set}, or by including
1567 it in a @code{\with} clause (but without the @code{\set}).
1568
1569 @example
1570 \set fontSize = #-2
1571 @end example
1572
1573 Both of these statements would cause the font size to be reduced
1574 by 2 steps from its previous value, where each
1575 step reduces or increases the size by approximately 12%.
1576
1577 Let's try it in our ossia example:
1578
1579 @cindex alignAboveContext property, example
1580 @cindex @code{\with}, example
1581 @cindex Clef, example of overriding
1582 @cindex TimeSignature, example of overriding
1583 @cindex fontSize property, example
1584
1585 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1586 \new Staff ="main" {
1587   \relative g' {
1588     r4 g8 g c4 c8 d |
1589     e4 r8
1590     <<
1591       { f8 c c }
1592       \new Staff \with {
1593         alignAboveContext = #"main"
1594         \omit Clef
1595         \omit TimeSignature
1596         % Reduce all font sizes by ~24%
1597         fontSize = #-2
1598       }
1599       { f8 f c }
1600     >>
1601     r4 |
1602   }
1603 }
1604 @end lilypond
1605
1606 This is still not quite right.  The note heads and flags are
1607 smaller, but the stems are too long in proportion and the
1608 staff lines are spaced too widely apart.  These need to be
1609 scaled down in proportion to the font reduction.  The next
1610 sub-section discusses how this is done.
1611
1612 @node Length and thickness of objects
1613 @subsection Length and thickness of objects
1614
1615 @cindex distances
1616 @cindex thickness
1617 @cindex length
1618 @cindex magstep
1619 @cindex size, changing
1620 @cindex stem length, changing
1621 @cindex staff line spacing, changing
1622
1623 Distances and lengths in LilyPond are generally measured in
1624 staff-spaces, the distance between adjacent lines in the staff,
1625 (or occasionally half staff spaces) while most @code{thickness}
1626 properties are measured in units of an internal property called
1627 @code{line-thickness.}  For example, by default, the lines of
1628 hairpins are given a thickness of 1 unit of @code{line-thickness},
1629 while the @code{thickness} of a note stem is 1.3.  Note, though,
1630 that some thickness properties are different; for example, the
1631 thickness of beams is controlled by the value of the
1632 @code{beam-thickness} property, which is measured in staff-spaces.
1633
1634 So how are lengths to be scaled in proportion to the font size?
1635 This can be done with the help of a special function called
1636 @code{magstep} provided for exactly this purpose.  It takes
1637 one argument, the change in font size (#-2 in the example above)
1638 and returns a scaling factor suitable for reducing other
1639 objects in proportion.  It is used like this:
1640
1641 @cindex alignAboveContext property, example
1642 @cindex @code{\with}, example
1643 @cindex Clef, example of overriding
1644 @cindex TimeSignature, example of overriding
1645 @cindex fontSize property, example
1646 @cindex StaffSymbol, example of overriding
1647 @cindex magstep function, example of using
1648 @cindex staff-space property, example
1649 @cindex stencil property, example
1650
1651 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1652 \new Staff ="main" {
1653   \relative g' {
1654     r4 g8 g c4 c8 d |
1655     e4 r8
1656     <<
1657       { f8 c c }
1658       \new Staff \with {
1659         alignAboveContext = #"main"
1660         \omit Clef
1661         \omit TimeSignature
1662         fontSize = #-2
1663         % Reduce stem length and line spacing to match
1664         \override StaffSymbol.staff-space = #(magstep -2)
1665       }
1666       { f8 f c }
1667     >>
1668     r4 |
1669   }
1670 }
1671 @end lilypond
1672
1673 @noindent
1674 Since the length of stems and many other length-related properties are
1675 always calculated relative to the value of the @code{staff-space}
1676 property these are automatically scaled down in length too.  Note that
1677 this affects only the vertical scale of the ossia -- the horizontal
1678 scale is determined by the layout of the main music in order to remain
1679 synchronized with it, so it is not affected by any of these changes in
1680 size.  Of course, if the scale of all the main music were changed in
1681 this way then the horizontal spacing would be affected.  This is
1682 discussed later in the layout section.
1683
1684 This, then, completes the creation of an ossia.  The sizes and
1685 lengths of all other objects may be modified in analogous ways.
1686
1687 For small changes in scale, as in the example above, the
1688 thickness of the various drawn lines such as bar lines,
1689 beams, hairpins, slurs, etc does not usually require global
1690 adjustment.  If the thickness of any particular layout object
1691 needs to be adjusted this can be best achieved by overriding its
1692 @code{thickness} property.  An example of changing the thickness
1693 of slurs was shown above in @ref{Properties of layout objects}.
1694 The thickness of all drawn objects (i.e., those not produced
1695 from a font) may be changed in the same way.
1696
1697
1698 @node Placement of objects
1699 @section Placement of objects
1700
1701 @menu
1702 * Automatic behavior::
1703 * Within-staff objects::
1704 * Outside-staff objects::
1705 @end menu
1706
1707
1708 @node Automatic behavior
1709 @subsection Automatic behavior
1710
1711 @cindex within-staff objects
1712 @cindex outside-staff objects
1713 @cindex objects, within-staff
1714 @cindex objects, outside-staff
1715
1716 There are some objects in musical notation that belong to
1717 the staff and there are other objects that should be
1718 placed outside the staff.  These are called within-staff
1719 objects and outside-staff objects respectively.
1720
1721 Within-staff objects are those that are located on the staff
1722 -- note heads, stems, accidentals, etc.  The positions of
1723 these are usually fixed by the music itself -- they are
1724 vertically positioned on specific lines of the staff or are
1725 tied to other objects that are so positioned.  Collisions of
1726 note heads, stems and accidentals in closely set chords are
1727 normally avoided automatically.  There are commands and
1728 overrides which can modify this automatic behavior, as we
1729 shall shortly see.
1730
1731 Objects belonging outside the staff include things such as
1732 rehearsal marks, text and dynamic markings.  LilyPond's rule for
1733 the vertical placement of outside-staff objects is to place them
1734 as close to the staff as possible but not so close that they
1735 collide with any other object.  LilyPond uses the
1736 @code{outside-staff-priority} property to determine the order in
1737 which the objects should be placed, as follows.
1738
1739 First, LilyPond places all the within-staff objects.
1740 Then it sorts the outside-staff objects according to their
1741 @code{outside-staff-priority}.  The outside-staff objects are
1742 taken one by one, beginning with the object with the lowest
1743 @code{outside-staff-priority}, and placed so that they do not
1744 collide with any objects that have already been placed.  That is,
1745 if two outside-staff grobs are competing for the same space, the
1746 one with the lower @code{outside-staff-priority} will be placed
1747 closer to the staff.  If two objects have the same
1748 @code{outside-staff-priority} the one encountered first will be
1749 placed closer to the staff.
1750
1751 In the following example all the markup texts have the same
1752 priority (since it is not explicitly set).  Note that @q{Text3}
1753 is automatically positioned close to the staff again, nestling
1754 under @q{Text2}.
1755
1756 @cindex markup example
1757
1758 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1759 c2^"Text1"
1760 c2^"Text2" |
1761 c2^"Text3"
1762 c2^"Text4" |
1763 @end lilypond
1764
1765 Staves are also positioned, by default, as closely together as
1766 possible (subject to a minimum separation).  If notes project
1767 a long way towards an adjacent staff they will force the
1768 staves further apart only if an overlap of the notation
1769 would otherwise occur.  The following example demonstrates
1770 this @q{nestling} of the notes on adjacent staves:
1771
1772 @lilypond[quote,ragged-right,verbatim]
1773 <<
1774   \new Staff {
1775     \relative c' { c4 a, }
1776   }
1777   \new Staff {
1778     \relative c'''' { c4 a, }
1779   }
1780 >>
1781 @end lilypond
1782
1783
1784 @node Within-staff objects
1785 @subsection Within-staff objects
1786
1787 We have already seen how the commands @code{\voiceXXX} affect the
1788 direction of slurs, ties, fingering and everything else which depends on
1789 the direction of the stems -- see @ref{Explicitly instantiating voices}.
1790 These commands are essential when writing polyphonic music to permit
1791 interweaving melodic lines to be distinguished.  But occasionally it may
1792 be necessary to override this automatic behavior.  This can be done for
1793 whole sections of music or even for an individual note.  The property
1794 which controls this behavior is the @code{direction} property of each
1795 layout object.  We first explain what this does, and then introduce a
1796 number of ready-made commands which avoid your having to code explicit
1797 overrides for the more common modifications.
1798
1799 Some layout objects like slurs and ties curve, bend or point
1800 either up or down; others like stems and flags also move to
1801 right or left when they point up or down.  This is controlled
1802 automatically when @code{direction} is set.
1803
1804 @menu
1805 * The direction property::
1806 * Fingering::
1807 @end menu
1808
1809 @node The direction property
1810 @unnumberedsubsubsec The @code{direction} property
1811
1812 @cindex down
1813 @cindex up
1814 @cindex center
1815 @cindex neutral
1816
1817 The following example shows in bar 1 the default behavior of stems,
1818 with those on high notes pointing down and those on low notes pointing
1819 up, followed by four notes with all stems forced down, four notes with
1820 all stems forced up, and finally four notes reverted back to the
1821 default behavior.
1822
1823 @cindex Stem, example of overriding
1824 @cindex direction property, example
1825
1826 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1827 a4 g c a |
1828 \override Stem.direction = #DOWN
1829 a4 g c a |
1830 \override Stem.direction = #UP
1831 a4 g c a |
1832 \revert Stem.direction
1833 a4 g c a |
1834 @end lilypond
1835
1836 Here we use the constants @code{DOWN} and @code{UP}.
1837 These have the values @w{@code{-1}} and @code{+1} respectively, and
1838 these numerical values may be used instead.  The value @code{0}
1839 may also be used in some cases.  It is simply treated as meaning
1840 @code{UP} for stems, but for some objects it means @q{center}.
1841 There is a constant, @code{CENTER} which has the value @code{0}.
1842
1843 However, these explicit overrides are not usually used, as there are
1844 simpler equivalent predefined commands available.  Here is a table of
1845 the commonest.  The meaning of each is stated where it is not obvious.
1846
1847 @multitable @columnfractions .2 .2 .25 .35
1848 @headitem Down/Left
1849   @tab Up/Right
1850   @tab Revert
1851   @tab Effect
1852 @item @code{\arpeggioArrowDown}
1853   @tab @code{\arpeggioArrowUp}
1854   @tab @code{\arpeggioNormal}
1855   @tab Arrow is at bottom, at top, or no arrow
1856 @item @code{\dotsDown}
1857   @tab @code{\dotsUp}
1858   @tab @code{\dotsNeutral}
1859   @tab Direction of movement to avoid staff lines
1860 @item @code{\dynamicDown}
1861   @tab @code{\dynamicUp}
1862   @tab @code{\dynamicNeutral}
1863   @tab
1864 @item @code{\phrasingSlurDown}
1865   @tab @code{\phrasingSlurUp}
1866   @tab @code{\phrasingSlurNeutral}
1867   @tab Note: distinct from slur commands
1868 @item @code{\slurDown}
1869   @tab @code{\slurUp}
1870   @tab @code{\slurNeutral}
1871   @tab
1872 @item @code{\stemDown}
1873   @tab @code{\stemUp}
1874   @tab @code{\stemNeutral}
1875   @tab
1876 @item @code{\textSpannerDown}
1877   @tab @code{\textSpannerUp}
1878   @tab @code{\textSpannerNeutral}
1879   @tab Text entered as spanner is below/above staff
1880 @item @code{\tieDown}
1881   @tab @code{\tieUp}
1882   @tab @code{\tieNeutral}
1883   @tab
1884 @item @code{\tupletDown}
1885   @tab @code{\tupletUp}
1886   @tab @code{\tupletNeutral}
1887   @tab Tuplets are below/above notes
1888 @end multitable
1889
1890 The neutral/normal variants of these commands are implemented
1891 using @code{\revert} and may @strong{not} be
1892 preceded by @code{\once}.  If you wish to limit the
1893 effect of the other commands (which are implemented using
1894 @code{\override}) to a single timestep, you can precede them with
1895 @code{\once} like you would do with explicit overrides.
1896
1897 @node Fingering
1898 @unnumberedsubsubsec Fingering
1899
1900 @cindex fingering, placement
1901 @cindex fingering, chords
1902
1903 The placement of fingering on single notes can also be controlled
1904 by the @code{direction} property, but changing @code{direction}
1905 has no effect on chords.  As we shall see, there are special
1906 commands which allow the fingering of individual notes
1907 of chords to be controlled, with the fingering being placed
1908 above, below, to the left or to the right of each note.
1909
1910 First, here's the effect of @code{direction} on the fingering
1911 attached to single notes.  The first bar shows the default
1912 behaviour, and the following two bars shows the effect of
1913 specifying @code{DOWN} and @code{UP}:
1914
1915 @cindex Fingering, example of overriding
1916 @cindex direction property, example
1917
1918 @lilypond[quote,verbatim,relative=2]
1919 c4-5 a-3 f-1 c'-5 |
1920 \override Fingering.direction = #DOWN
1921 c4-5 a-3 f-1 c'-5 |
1922 \override Fingering.direction = #UP
1923 c4-5 a-3 f-1 c'-5 |
1924 @end lilypond
1925
1926 However, overriding the @code{direction} property is not the
1927 easiest way of manually setting the fingering above or below
1928 the notes; using @code{_} or @code{^} instead of @code{-} before
1929 the fingering number is usually preferable.  Here is the previous
1930 example using this method:
1931
1932 @cindex fingering example
1933
1934 @lilypond[quote,verbatim,relative=2]
1935 c4-5 a-3 f-1 c'-5 |
1936 c4_5 a_3 f_1 c'_5 |
1937 c4^5 a^3 f^1 c'^5 |
1938 @end lilypond
1939
1940 The @code{direction} property is ignored for chords, but the
1941 directional prefixes, @code{_} and @code{^} do work.  By default,
1942 the fingering is automatically placed both above and below the
1943 notes of a chord, as shown:
1944
1945 @cindex fingering example
1946
1947 @lilypond[quote,verbatim,relative=2]
1948 <c-5 g-3>4
1949 <c-5 g-3 e-2>4
1950 <c-5 g-3 e-2 c-1>4
1951 @end lilypond
1952
1953 @noindent
1954 but this may be overridden to manually force all or any of the
1955 individual fingering numbers above or below:
1956
1957 @cindex fingering example
1958
1959 @lilypond[quote,verbatim,relative=2]
1960 <c-5 g-3 e-2 c-1>4
1961 <c^5 g_3 e_2 c_1>4
1962 <c^5 g^3 e^2 c_1>4
1963 @end lilypond
1964
1965 Even greater control over the placement of fingering of the
1966 individual notes in a chord is possible by using the
1967 @code{\set fingeringOrientations} command.  The format of this
1968 command is:
1969
1970 @example
1971 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
1972 @end example
1973
1974 @noindent
1975 @code{\set} is used because @code{fingeringOrientations} is a
1976 property of the @code{Voice} context, created and used by the
1977 @code{New_fingering_engraver}.
1978
1979 The property may be set to a list of one to three values.
1980 It controls whether fingerings may be placed above (if
1981 @code{up} appears in the list), below (if @code{down} appears),
1982 to the left (if @code{left} appears, or to the right
1983 (if @code{right} appears).  Conversely, if a location is not
1984 listed, no fingering is placed there.  LilyPond takes these
1985 constraints and works out the best placement for the fingering
1986 of the notes of the following chords.  Note that @code{left} and
1987 @code{right} are mutually exclusive -- fingering may be placed
1988 only on one side or the other, not both.
1989
1990 @warning{To control the placement of the fingering of a single
1991 note using this command it is necessary to write it as a single
1992 note chord by placing angle brackets round it.}
1993
1994 Here are a few examples:
1995
1996 @cindex fingering example
1997 @cindex @code{\set}, example of using
1998 @cindex fingeringOrientations property, example
1999
2000 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2001 \set fingeringOrientations = #'(left)
2002 <f-2>4
2003 <c-1 e-2 g-3 b-5>4
2004 \set fingeringOrientations = #'(left)
2005 <f-2>4
2006 <c-1 e-2 g-3 b-5>4 |
2007 \set fingeringOrientations = #'(up left down)
2008 <f-2>4
2009 <c-1 e-2 g-3 b-5>4
2010 \set fingeringOrientations = #'(up left)
2011 <f-2>4
2012 <c-1 e-2 g-3 b-5>4 |
2013 \set fingeringOrientations = #'(right)
2014 <f-2>4
2015 <c-1 e-2 g-3 b-5>4
2016 @end lilypond
2017
2018 @noindent
2019 If the fingering seems a little crowded the @code{font-size}
2020 could be reduced.  The default value can be seen from the
2021 @code{Fingering} object in the IR to be @w{@code{-5}}, so let's
2022 try @w{@code{-7}}:
2023
2024 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2025 \override Fingering.font-size = #-7
2026 \set fingeringOrientations = #'(left)
2027 <f-2>4
2028 <c-1 e-2 g-3 b-5>4
2029 \set fingeringOrientations = #'(left)
2030 <f-2>4
2031 <c-1 e-2 g-3 b-5>4 |
2032 \set fingeringOrientations = #'(up left down)
2033 <f-2>4
2034 <c-1 e-2 g-3 b-5>4
2035 \set fingeringOrientations = #'(up left)
2036 <f-2>4
2037 <c-1 e-2 g-3 b-5>4 |
2038 \set fingeringOrientations = #'(right)
2039 <f-2>4
2040 <c-1 e-2 g-3 b-5>4
2041 @end lilypond
2042
2043 @node Outside-staff objects
2044 @subsection Outside-staff objects
2045
2046 Outside-staff objects are automatically placed to avoid collisions.
2047 There are several ways to override the automatic placement if the
2048 positioning is not optimum.
2049
2050 @menu
2051 * The outside-staff-priority property::
2052 * The textLengthOn command::
2053 * Dynamics placement::
2054 * Grob sizing::
2055 @end menu
2056
2057
2058 @node The outside-staff-priority property
2059 @unnumberedsubsubsec The @code{outside-staff-priority} property
2060
2061 Objects with the lower value of the @code{outside-staff-priority}
2062 property are placed nearer to the staff, and other outside-staff
2063 objects are then raised as far as necessary to avoid collisions.
2064 The @code{outside-staff-priority} is defined in the
2065 @code{grob-interface} and so is a property of all layout objects.
2066 By default it is set to @code{#f} for all within-staff objects,
2067 and to a numerical value appropriate to each outside-staff object
2068 when the object is created.  The following table shows the default
2069 numerical values for some of the commonest outside-staff objects.
2070
2071 @cindex spanners
2072
2073 Note the unusual names for some of the objects: spanner objects
2074 are automatically created to control the vertical positioning of
2075 grobs which (might) start and end at different musical moments, so
2076 changing the @code{outside-staff-priority} of the underlying grob
2077 will have no effect.  For example, changing
2078 @code{outside-staff-priority} of the @code{Hairpin} object will
2079 have no effect on the vertical positioning of hairpins -- you must
2080 change @code{outside-staff-priority} of the associated
2081 @code{DynamicLineSpanner} object instead.  This override must be
2082 placed at the start of the spanner, which might include several
2083 linked hairpins and dynamics.
2084
2085 @multitable @columnfractions .3 .3 .3
2086 @headitem Layout Object
2087   @tab Priority
2088   @tab Controls position of:
2089 @item @code{RehearsalMark}
2090   @tab @code{1500}
2091   @tab Rehearsal marks
2092 @item @code{MetronomeMark}
2093   @tab @code{1000}
2094   @tab Metronome marks
2095 @item @code{VoltaBracketSpanner}
2096   @tab @code{600}
2097   @tab Volta brackets
2098 @item @code{TextScript}
2099   @tab @code{450}
2100   @tab Markup text
2101 @item @code{MultiMeasureRestText}
2102   @tab @code{450}
2103   @tab Markup text over full-bar rests
2104 @item @code{OttavaBracket}
2105   @tab @code{400}
2106   @tab Ottava brackets
2107 @item @code{TextSpanner}
2108   @tab @code{350}
2109   @tab Text spanners
2110 @item @code{DynamicLineSpanner}
2111   @tab @code{250}
2112   @tab All dynamic markings
2113 @item @code{BarNumber}
2114   @tab @code{ 100}
2115   @tab Bar numbers
2116 @item @code{TrillSpanner}
2117   @tab @code{50}
2118   @tab Spanning trills
2119 @end multitable
2120
2121 Here is an example showing the default placement of some of
2122 these.
2123
2124 @cindex text spanner
2125 @cindex ottava bracket
2126
2127 @funindex \startTextSpan
2128 @funindex startTextSpan
2129 @funindex \stopTextSpan
2130 @funindex stopTextSpan
2131
2132 @cindex TextSpanner, example of overriding
2133 @cindex bound-details property, example
2134
2135 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2136 % Set details for later Text Spanner
2137 \override TextSpanner.bound-details.left.text
2138     = \markup { \small \bold Slower }
2139 % Place dynamics above staff
2140 \dynamicUp
2141 % Start Ottava Bracket
2142 \ottava #1
2143 c'4 \startTextSpan
2144 % Add Dynamic Text and hairpin
2145 c4\pp\<
2146 c4
2147 % Add Text Script
2148 c4^Text |
2149 c4 c
2150 % Add Dynamic Text and terminate hairpin
2151 c4\ff c \stopTextSpan |
2152 % Stop Ottava Bracket
2153 \ottava #0
2154 c,4 c c c |
2155 @end lilypond
2156
2157 This example also shows how to create Text Spanners --
2158 text with extender lines above a section of music.  The
2159 spanner extends from the @code{\startTextSpan} command to
2160 the @code{\stopTextSpan} command, and the format of the
2161 text is defined by the @code{\override TextSpanner} command.
2162 For more details see @ruser{Text spanners}.
2163
2164 It also shows how ottava brackets are created.
2165
2166 @cindex tweaking bar number placement
2167 @cindex bar numbers, tweaking placement
2168 @cindex tweaking metronome mark placement
2169 @cindex metronome mark, tweaking placement
2170 @cindex tweaking rehearsal mark placement
2171 @cindex rehearsal marks, tweaking placement
2172
2173 If the default values of @code{outside-staff-priority} do not give you
2174 the placing you want, the priority of any of the objects may be
2175 overridden.  Suppose we would like the ottava bracket to be placed
2176 below the text spanner in the example above.  All we need to do is to
2177 look up the priority of @code{OttavaBracket} in the IR or in the
2178 tables above, and reduce it to a value lower than that of a
2179 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
2180 in the @code{Staff} context:
2181
2182 @cindex TextSpanner, example of overriding
2183 @cindex bound-details property, example
2184
2185 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2186 % Set details for later Text Spanner
2187 \override TextSpanner.bound-details.left.text
2188     = \markup { \small \bold Slower }
2189 % Place dynamics above staff
2190 \dynamicUp
2191 % Place following Ottava Bracket below Text Spanners
2192 \once \override Staff.OttavaBracket.outside-staff-priority = #340
2193 % Start Ottava Bracket
2194 \ottava #1
2195 c'4 \startTextSpan
2196 % Add Dynamic Text
2197 c4\pp
2198 % Add Dynamic Line Spanner
2199 c4\<
2200 % Add Text Script
2201 c4^Text |
2202 c4 c
2203 % Add Dynamic Text
2204 c4\ff c \stopTextSpan |
2205 % Stop Ottava Bracket
2206 \ottava #0
2207 c,4 c c c |
2208 @end lilypond
2209
2210 Note that some of these objects, in particular bar numbers,
2211 metronome marks and rehearsal marks, live by default in the
2212 @code{Score} context, so be sure to use the correct context
2213 when these are being overriden.
2214
2215 @cindex slurs and outside-staff-priority
2216 @cindex slurs and articulations
2217 @cindex articulations and slurs
2218
2219 Slurs by default are classed as within-staff objects, but
2220 they often appear above the staff if the notes to
2221 which they are attached are high on the staff.  This can push
2222 outside-staff objects such as articulations too high, as the slur
2223 will be placed first.  The @code{avoid-slur} property of the
2224 articulation can be set to @code{'inside} to bring the articulation
2225 inside the slur, but the @code{avoid-slur} property is effective
2226 only if the @code{outside-staff-priority} is also set to @code{#f}.
2227 Alternatively, the @code{outside-staff-priority} of the slur
2228 can be set to a numerical value to cause it to be placed along with
2229 other outside-staff objects according to that value.  Here's an
2230 example showing the effect of the two methods:
2231
2232 @lilypond[quote,verbatim,relative=2]
2233 c4( c^\markup { \tiny \sharp } d4.) c8 |
2234 c4(
2235 \once \override TextScript.avoid-slur = #'inside
2236 \once \override TextScript.outside-staff-priority = ##f
2237 c4^\markup { \tiny \sharp } d4.) c8 |
2238 \once \override Slur.outside-staff-priority = #500
2239 c4( c^\markup { \tiny \sharp } d4.) c8 |
2240 @end lilypond
2241
2242 Changing the @code{outside-staff-priority} can also be used to
2243 control the vertical placement of individual objects, although
2244 the results may not always be desirable.  Suppose we would
2245 like @qq{Text3} to be placed above @qq{Text4} in the example
2246 under Automatic behavior, above (see @ref{Automatic behavior}).
2247 All we need to do is to look up the priority of @code{TextScript}
2248 in the IR or in the tables above, and increase the priority of
2249 @qq{Text3} to a higher value:
2250
2251 @cindex TextScript, example of overriding
2252 @cindex outside-staff-priority property, example
2253
2254 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2255 c2^"Text1"
2256 c2^"Text2" |
2257 \once \override TextScript.outside-staff-priority = #500
2258 c2^"Text3"
2259 c2^"Text4" |
2260 @end lilypond
2261
2262 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2263 above @qq{Text2}, and @qq{Text4} now drops down.  Perhaps this is not
2264 so good.  What we would really like to do is to position all the
2265 annotation at the same distance above the staff.  To do this, we
2266 clearly will need to space the notes out horizontally to make more
2267 room for the text.  This is done using the @code{textLengthOn}
2268 command.
2269
2270 @node The textLengthOn command
2271 @unnumberedsubsubsec The @code{@bs{}textLengthOn} command
2272
2273 @cindex notes, spreading out with text
2274
2275 @funindex \textLengthOn
2276 @funindex textLengthOn
2277 @funindex \textLengthOff
2278 @funindex textLengthOff
2279
2280 By default, text produced by markup takes up no horizontal space
2281 as far as laying out the music is concerned.  The @code{\textLengthOn}
2282 command reverses this behavior, causing the notes to be spaced
2283 out as far as is necessary to accommodate the text:
2284
2285 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2286 \textLengthOn  % Cause notes to space out to accommodate text
2287 c2^"Text1"
2288 c2^"Text2" |
2289 c2^"Text3"
2290 c2^"Text4" |
2291 @end lilypond
2292
2293 The command to revert to the default behavior is
2294 @code{\textLengthOff}.  Alternatively, @code{\once} may be used
2295 with @code{\textLengthOn} if the effect is to be limited to just a
2296 single musical moment.
2297 The corresponding spacing behavior for rehearsal marks and tempo
2298 indications is independently controlled with the commands
2299 @code{\markLengthOn} and @code{\markLengthOff}.
2300
2301 @cindex markup text, allowing collisions
2302
2303 Markup text will also avoid notes which project above the staff.
2304 If this is not desired, the automatic displacement upwards may
2305 be turned off by setting the priority to @code{#f}.  Here's an
2306 example to show how markup text interacts with such notes.
2307
2308 @cindex TextScript, example of overriding
2309 @cindex outside-staff-priority property, example
2310
2311 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2312 % This markup is short enough to fit without collision
2313 c2^"Tex" c'' |
2314 R1 |
2315
2316 % This is too long to fit, so it is displaced upwards
2317 c,,2^"Text" c'' |
2318 R1 |
2319
2320 % Turn off collision avoidance
2321 \once \override TextScript.outside-staff-priority = ##f
2322 c,,2^"Long Text   " c'' |
2323 R1 |
2324
2325 % Turn off collision avoidance
2326 \once \override TextScript.outside-staff-priority = ##f
2327 \textLengthOn        % and turn on textLengthOn
2328 c,,2^"Long Text   "  % Spaces at end are honored
2329 c''2 |
2330 @end lilypond
2331
2332 @node Dynamics placement
2333 @unnumberedsubsubsec Dynamics placement
2334
2335 @cindex tweaking dynamics placement
2336 @cindex dynamics, tweaking placement
2337
2338 Dynamic markings will normally be positioned beneath the
2339 staff, but may be positioned above with the @code{\dynamicUp}
2340 command.  They will be positioned vertically relative to the
2341 note to which they are attached, and will float below (or above)
2342 all within-staff objects such as phrasing slurs and bar numbers.
2343 This can give quite acceptable results, as this example
2344 shows:
2345
2346 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
2347 \clef "bass"
2348 \key aes \major
2349 \time 9/8
2350 \dynamicUp
2351 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2352 ees,2.~\)\mf ees4 r8 |
2353 @end lilypond
2354
2355 However, if the notes and attached dynamics are close
2356 together the automatic placement will avoid collisions
2357 by displacing later dynamic markings further away, but this may
2358 not be the optimum placement, as this rather artificial example
2359 shows:
2360
2361 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2362 \dynamicUp
2363 a4\f b\mf a\mp b\p
2364 @end lilypond
2365
2366 @noindent
2367 Should a similar situation arise in @q{real} music, it may be
2368 preferable to space out the notes a little further, so the dynamic
2369 markings can all fit at the same vertical distance from the staff.  We
2370 were able to do this for markup text by using the @code{\textLengthOn}
2371 command, but there is no equivalent command for dynamic marks.  So we
2372 shall have to work out how to do this using @code{\override} commands.
2373
2374 @node Grob sizing
2375 @unnumberedsubsubsec Grob sizing
2376
2377 @cindex grob sizing
2378 @cindex sizing grobs
2379
2380 First we must learn how grobs are sized.  All grobs have a
2381 reference point defined within them which is used to position
2382 them relative to their parent object.  This point in the grob
2383 is then positioned at a horizontal distance, @code{X-offset},
2384 and at a vertical distance, @code{Y-offset}, from its parent.
2385 The horizontal extent of the object is given by a pair of
2386 numbers, @code{X-extent}, which say where the left and right
2387 edges are relative to the reference point.  The vertical extent
2388 is similarly defined by a pair of numbers, @code{Y-extent}.
2389 These are properties of all grobs which support the
2390 @code{grob-interface}.
2391
2392 @cindex @code{extra-spacing-width}
2393
2394 By default, outside-staff objects are given a width of zero so
2395 that they may overlap in the horizontal direction.  This is done
2396 by the trick of making the leftmost extent infinity and
2397 the rightmost extent minus infinity by setting the
2398 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}.  To
2399 ensure they do not overlap in the horizontal direction we
2400 must override this value of @code{extra-spacing-width} to give them
2401 a little extra spacing.  The units are the space between two staff
2402 lines, so moving the left edge half a unit to the left and the
2403 right edge half a unit to the right should do it:
2404
2405 @example
2406 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2407 @end example
2408
2409 @noindent
2410 Let's see if this works in our previous example:
2411
2412 @cindex DynamicText, example of overriding
2413 @cindex extra-spacing-width property, example
2414
2415
2416 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
2417 \dynamicUp
2418 % Extend width by 1 staff space
2419 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2420 a4\f b\mf a\mp b\p
2421 @end lilypond
2422
2423 @noindent
2424 This looks better, but maybe we would prefer the dynamic marks
2425 to be aligned along the same baseline rather than going up and
2426 down with the notes.  The property to do this is
2427 @code{staff-padding} which is covered in the section on collisions
2428 (see @ref{Collisions of objects}).
2429
2430
2431 @node Vertical spacing
2432 @section Vertical spacing
2433
2434 As a rule, LilyPond's vertical spacing of musical objects is pretty
2435 good.  Let's see how it does with a simple song, with 2 voices and
2436 piano accompaniment:
2437
2438 @lilypond[quote,fragment,ragged-right]
2439 <<
2440   \new ChoirStaff
2441   <<
2442     \new Staff {
2443       \new Voice = "music" {
2444         b'2 c' c' c'
2445       }
2446     }
2447     \new Lyrics
2448     \lyricsto "music" {
2449       Here are some lyrics
2450     }
2451     \new Staff {
2452       \clef bass e'2 f e c
2453     }
2454   >>
2455   \new PianoStaff
2456   <<
2457     \new Staff {
2458       g''2 c'' c'' a''
2459     }
2460     \new Staff {
2461       \clef bass e2 f c e
2462     }
2463   >>
2464 >>
2465 @end lilypond
2466
2467 There's nothing wrong with the default vertical spacing.  However, let's
2468 assume that you're working with a publisher with some specific
2469 requirements for vertical spacing of staves and lyrics: they want
2470 the lyrics spaced away from any notes, they want the piano
2471 accompaniment spaced away from the vocal line and they want the two
2472 piano staves pushed together tightly.  Let's start with the lyrics.
2473
2474 Lyrics sit within a system, and therefore the commands to space them
2475 are found in @ruser{Flexible vertical spacing within systems}.  It
2476 tells us that lyrics are @code{non-staff lines} and therefore the
2477 command to change their spacing will refer to the @code{nonstaff}
2478 property.  Spacing them away from the staff to which they relate
2479 (the top line) will use the @code{relatedstaff} property.  Spacing
2480 them from the lower line will use the @code{unrelatedstaff} property.
2481 The vocal parts are part of a @code{VerticalAxisGroup}, so we need to
2482 adjust its properties.  Let's try it and see if it works.
2483
2484 @lilypond[quote,fragment,ragged-right,verbatim]
2485 <<
2486   \new ChoirStaff
2487   <<
2488     \new Staff {
2489       \new Voice = "music" {
2490         b'2 c' c' c'
2491       }
2492     }
2493     \new Lyrics \with {
2494       \override VerticalAxisGroup.
2495         nonstaff-relatedstaff-spacing.padding = #5
2496       \override VerticalAxisGroup.
2497         nonstaff-unrelatedstaff-spacing.padding = #5
2498     }
2499     \lyricsto "music" {
2500       Here are some lyrics
2501     }
2502     \new Staff {
2503       \clef bass e'2 f e c
2504     }
2505   >>
2506   \new PianoStaff
2507   <<
2508     \new Staff {
2509       g''2 c'' c'' a''
2510     }
2511     \new Staff {
2512       \clef bass e2 f c e
2513     }
2514   >>
2515 >>
2516 @end lilypond
2517
2518 Well - yes it does, but perhaps too well.  When we set the
2519 @code{padding} to 5, LilyPond adds 5 staff spaces to the distance
2520 between objects, which is too much for us here.  We'll use 2.
2521
2522 Next, let's move the piano music away from the vocal parts.  The
2523 vocal music is a @code{ChoirStaff}, so we need to increase the
2524 spacing between that group of staves and the piano staff below.
2525 We'll do this by changing the @code{basic-distance} of the
2526 @code{StaffGrouper}'s @code{staffgroup-staff-spacing}.
2527
2528 @lilypond[quote,fragment,ragged-right,verbatim]
2529 <<
2530   \new ChoirStaff \with {
2531     \override StaffGrouper.
2532       staffgroup-staff-spacing.basic-distance = #15
2533   }
2534   <<
2535     \new Staff {
2536       \new Voice = "music" {
2537         b'2 c' c' c'
2538       }
2539     }
2540     \new Lyrics \with {
2541       \override VerticalAxisGroup.
2542         nonstaff-relatedstaff-spacing.padding = #2
2543       \override VerticalAxisGroup.
2544         nonstaff-unrelatedstaff-spacing.padding = #2
2545     }
2546     \lyricsto "music" {
2547       Here are some lyrics
2548     }
2549     \new Staff {
2550       \clef bass e'2 f e c
2551     }
2552   >>
2553   \new PianoStaff
2554   <<
2555     \new Staff {
2556       g''2 c'' c'' a''
2557     }
2558     \new Staff {
2559       \clef bass e2 f c e
2560     }
2561   >>
2562 >>
2563 @end lilypond
2564
2565 Excellent.  Now just for the last requirement to make the piano staves
2566 closer together.  To do this, we again alter the properties of the
2567 @code{StaffGrouper}, but this time we're going to reduce both
2568 the @code{basic-distance} and the @code{padding}.  We can do this
2569 as shown below.
2570
2571 @lilypond[quote,fragment,ragged-right,verbatim]
2572 <<
2573   \new ChoirStaff \with {
2574     \override StaffGrouper.
2575       staffgroup-staff-spacing.basic-distance = #15
2576   }
2577   <<
2578     \new Staff {
2579       \new Voice = "music" {
2580         b'2 c' c' c'
2581       }
2582     }
2583     \new Lyrics \with {
2584       \override VerticalAxisGroup.
2585         nonstaff-relatedstaff-spacing.padding = #2
2586       \override VerticalAxisGroup.
2587         nonstaff-unrelatedstaff-spacing.padding = #2
2588     }
2589     \lyricsto "music" {
2590       Here are some lyrics
2591     }
2592     \new Staff {
2593       \clef bass e'2 f e c
2594     }
2595   >>
2596   \new PianoStaff \with {
2597     \override StaffGrouper.staff-staff-spacing = #'(
2598                             (basic-distance . 0)
2599                             (padding . 0))
2600   }
2601   <<
2602     \new Staff {
2603       g''2 c'' c'' a''
2604     }
2605     \new Staff {
2606       \clef bass e2 f c e
2607     }
2608   >>
2609 >>
2610 @end lilypond
2611
2612 That's put them really close together -- but it's what
2613 the publisher wanted.  They could be moved further
2614 apart by altering the @code{padding} or @code{basic-distance}
2615 if wanted.
2616
2617 There are many ways of altering vertical spacing.  A key point
2618 to remember is that the spacing between objects in a
2619 @code{StaffGroup} (like @code{GrandStaff} or
2620 @code{PianoStaff} groups) is controlled by the spacing variables
2621 of the @code{StaffGrouper}. Spacing from ungrouped staves
2622 (like @code{Lyrics} and @code{Staff}) is controlled by the
2623 variables of the @code{VerticalAxisGroup}.  See the
2624 @ruser{Flexible vertical spacing paper variables} and
2625 @ruser{Flexible vertical spacing within systems} for more
2626 details.
2627
2628 @node Collisions of objects
2629 @section Collisions of objects
2630
2631 @menu
2632 * Moving objects::
2633 * Fixing overlapping notation::
2634 * Real music example::
2635 @end menu
2636
2637 @node Moving objects
2638 @subsection Moving objects
2639
2640 @cindex moving overlapping objects
2641 @cindex moving colliding objects
2642 @cindex moving colliding grobs
2643 @cindex objects, moving colliding
2644 @cindex grobs, moving colliding
2645
2646 This may come as a surprise, but LilyPond is not perfect.  Some
2647 notation elements can overlap.  This is unfortunate, but in fact
2648 rather rare.  Usually the need to move objects is for clarity or
2649 aesthetic reasons -- they would look better with a little more
2650 or a little less space around them.
2651
2652 There are three main approaches to resolving overlapping
2653 notation.  They should be considered in the following order:
2654
2655 @enumerate
2656 @item
2657 The @strong{direction} of one of the overlapping objects may
2658 be changed using the predefined commands listed above for
2659 within-staff objects (see @ref{Within-staff objects}).
2660 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2661 repositioned easily in this way.  The limitation is that you
2662 have a choice of only two positions, and neither may be
2663 suitable.
2664
2665 @item
2666 The @strong{object properties}, which LilyPond uses when positioning
2667 layout objects, may be modified using @code{\override}.  The
2668 advantages of making changes to this type of property are (a) that
2669 some other objects will be moved automatically if necessary to make
2670 room and (b) the single override can apply to all instances of the
2671 same type of object.  Such properties include:
2672
2673 @itemize
2674
2675 @item
2676 @code{direction}
2677
2678 This has already been covered in some detail -- see
2679 @ref{Within-staff objects}.
2680
2681 @item
2682 @code{padding}, @code{right-padding}, @code{staff-padding}
2683
2684 @cindex padding
2685 @cindex padding property
2686 @cindex right-padding property
2687 @cindex staff-padding property
2688
2689 As an object is being positioned the value of its @code{padding}
2690 property specifies the gap that must be left between itself and the
2691 nearest edge of the object against which it is being positioned.  Note
2692 that it is the @code{padding} value of the object @strong{being
2693 placed} that is used; the @code{padding} value of the object which is
2694 already placed is ignored.  Gaps specified by @code{padding} can be
2695 applied to all objects which support the
2696 @code{side-position-interface}.
2697
2698 Instead of @code{padding}, the placement of groups of accidentals
2699 is controlled by @code{right-padding}.  This property is to be found
2700 in the @code{AccidentalPlacement} object which, note, lives in the
2701 @strong{Staff} context.  In the typesetting process the note heads
2702 are typeset first and then the accidentals, if any, are added to the
2703 left of the note heads using the @code{right-padding} property to determine
2704 the separation from the note heads and between individual accidentals.
2705 So only the @code{right-padding} property of the @code{AccidentalPlacement}
2706 object has any effect on the placement of the accidentals.
2707
2708 The @code{staff-padding} property is closely related to the
2709 @code{padding} property: @code{padding} controls the minimum amount of
2710 space between any object which supports the
2711 @code{side-position-interface} and the nearest other object (generally
2712 the note or the staff lines); @code{staff-padding} applies only to
2713 those objects which are always set outside the staff -- it controls
2714 the minimum distance from the staff to the outside-staff object.
2715 Note that @code{staff-padding} has no effect on
2716 objects that are positioned relative to the note rather than the
2717 staff, even though it may be overridden without error for such objects
2718 -- it is simply ignored.
2719
2720 To discover which padding property is required for the object you wish
2721 to reposition, you need to return to the IR and look up the object's
2722 properties.  Be aware that the padding properties might not be located
2723 in the obvious object, so look in objects that appear to be related.
2724
2725 All padding values are measured in staff spaces.  For most
2726 objects, this value is set by default to be around 1.0 or less
2727 (it varies with each object).  It may be overridden if a larger
2728 (or smaller) gap is required.
2729
2730 @item
2731 @code{self-alignment-X}
2732
2733 @cindex self-alignment-X property
2734
2735 This property can be used to align the object to the left, to
2736 the right, or to center it with respect to the parent object's
2737 reference point.  It may be used with all objects which support
2738 the @code{self-alignment-interface}.  In general these are objects
2739 that contain text.  The values are @code{LEFT}, @code{RIGHT}
2740 or @code{CENTER}.  Alternatively, a numerical value between
2741 @w{@code{-1}} and @code{+1} may be specified, where @w{@code{-1}} is
2742 left-aligned, @code{+1} is right-aligned, and numbers in between
2743 move the text progressively from left-aligned to right-aligned.
2744 Numerical values greater than @code{1} may be specified to move
2745 the text even further to the left, or less than @w{@code{-1}} to
2746 move the text even further to the right.  A change of @code{1}
2747 in the value corresponds to a movement of half the text's length.
2748
2749 @item
2750 @code{extra-spacing-width}
2751
2752 @cindex extra-spacing-width property
2753
2754 This property is available for all objects which support the
2755 @code{item-interface}.  It takes two numbers, the first is added
2756 to the leftmost extent and the second is added to the rightmost
2757 extent.  Negative numbers move the edge to the left, positive to
2758 the right, so to widen an object the first number must be negative,
2759 the second positive.  Note that not all objects honor both
2760 numbers.  For example, the @code{Accidental} object only takes
2761 notice of the first (left edge) number.
2762
2763 @item
2764 @code{staff-position}
2765
2766 @cindex staff-position property
2767
2768 @code{staff-position} is a property of the
2769 @code{staff-symbol-referencer-interface}, which is supported by
2770 objects which are positioned relative to the staff.  It specifies
2771 the vertical position of the object relative to the center line
2772 of the staff in half staff-spaces.  It is useful in resolving
2773 collisions between layout objects like multi-measure rests, ties
2774 and notes in different voices.
2775
2776 @item
2777 @code{horizontal-shift}
2778
2779 @cindex horizontal-shift property
2780 @cindex note column
2781 @cindex note collisions
2782 @cindex collisions, notes
2783 @cindex shift commands
2784 @funindex \shiftOff
2785 @funindex shiftOff
2786 @funindex \shiftOn
2787 @funindex shiftOn
2788 @funindex \shiftOnn
2789 @funindex shiftOnn
2790 @funindex \shiftOnnn
2791 @funindex shiftOnnn
2792
2793 Within a voice, all the notes occuring at the same musical moment are
2794 grouped into a note column, and a @code{NoteColumn} object is created
2795 to control the horizontal positioning of that group of notes (see
2796 @qq{Note columns} in @ref{Explicitly instantiating voices}).  If
2797 @emph{and only if} two or more note columns within a single Staff
2798 context, both with stems in the same direction, occur at the same
2799 musical moment, the values of their @code{horizontal-shift} properties
2800 are used to rank them and the columns in the higher ranks are
2801 progessively offset to avoid collisions of the noteheads.  This
2802 property is set by the @code{\voiceXXX} commands and may be overridden
2803 directly with an @code{\override} command or, more usually, by the
2804 @code{\shiftOn} commands.  Note that this property is used to
2805 @emph{rank} the note columns for off-setting - it does not specify the
2806 magnitude of the offset, which is progressively increased in steps
2807 based on the note head's width for each rank.  The steps are usually
2808 of half a note head's width, but may be a full note head's width when
2809 a closely spaced group of notes is involved.
2810
2811 @item
2812 @code{force-hshift}
2813
2814 @cindex force-hshift property
2815
2816 The @code{force-hshift} property is a property of a @code{NoteColumn}
2817 (actually of the @code{note-column-interface}).  Changing it permits a
2818 note column to be moved in situations where the note columns overlap.
2819 Note that it has no effect on note columns that do not overlap.
2820 It is specified in units appropriate to a note column, viz. the note
2821 head width of the first voice note.  It should be used in complex
2822 situations where the normal @code{\shiftOn} commands (see
2823 @ref{Explicitly instantiating voices}) do not resolve the note
2824 conflict satisfactorily.  It is preferable to the @code{extra-offset}
2825 property for this purpose as there is no need to work out the distance
2826 in staff-spaces, and moving the notes into or out of a
2827 @code{NoteColumn} affects other actions such as merging note heads.
2828
2829 @end itemize
2830
2831 @item
2832 Finally, when all else fails, objects may be manually repositioned
2833 relative to the staff center line vertically, or by displacing them by
2834 any distance to a new position.  The disadvantages are that the
2835 correct values for the repositioning have to be worked out, often by
2836 trial and error, for every object individually, and, because the
2837 movement is done after LilyPond has placed all other objects, the user
2838 is responsible for avoiding any collisions that might ensue.  But the
2839 main difficulty with this approach is that the repositioning values
2840 may need to be reworked if the music is later modified.  The
2841 properties that can be used for this type of manual repositioning are:
2842
2843 @table @code
2844 @item extra-offset
2845
2846 @cindex extra-offset property
2847
2848 This property applies to any layout object supporting the
2849 @code{grob-interface}.  It takes a pair of numbers which specify the
2850 extra displacement in the horizontal and vertical directions.
2851 Negative numbers move the object to the left or down.  The units are
2852 staff-spaces.  The extra displacement is made after the typesetting of
2853 objects is finished, so an object may be repositioned anywhere without
2854 affecting anything else.
2855
2856 @item positions
2857
2858 @cindex positions property
2859
2860 This is most useful for manually adjusting the slope and height
2861 of beams, slurs, and tuplets.  It takes a pair of numbers
2862 giving the position of the left and right ends of the beam, slur,
2863 etc. relative to the center line of the staff.  Units are
2864 staff-spaces.  Note, though, that slurs and phrasing slurs cannot
2865 be repositioned by arbitrarily large amounts.  LilyPond first
2866 generates a list of possible positions for the slur and by default
2867 finds the slur that @qq{looks best}.  If the @code{positions}
2868 property has been overridden the slur that is closest to the
2869 requested positions is selected from the list.
2870 @end table
2871
2872 @end enumerate
2873
2874 A particular object may not have all of these properties.
2875 It is necessary to go to the IR to look up which properties
2876 are available for the object in question.
2877
2878 Here is a list of the objects which are most likely to be
2879 involved in collisions, together with the name of the object which
2880 should be looked up in the IR in order to discover which properties
2881 should be used to move them.
2882
2883 @multitable @columnfractions .5 .5
2884 @headitem Object type           @tab Object name
2885 @item Articulations             @tab @code{Script}
2886 @item Beams                     @tab @code{Beam}
2887 @item Dynamics (vertically)     @tab @code{DynamicLineSpanner}
2888 @item Dynamics (horizontally)   @tab @code{DynamicText}
2889 @item Fingerings                @tab @code{Fingering}
2890 @item Rehearsal / Text marks    @tab @code{RehearsalMark}
2891 @item Slurs                     @tab @code{Slur}
2892 @item Text e.g. @code{^"text"}  @tab @code{TextScript}
2893 @item Ties                      @tab @code{Tie}
2894 @item Tuplets                   @tab @code{TupletBracket}
2895 @end multitable
2896
2897
2898 @node Fixing overlapping notation
2899 @subsection Fixing overlapping notation
2900
2901 Let's now see how the properties in the previous section can
2902 help to resolve overlapping notation.
2903
2904 @menu
2905 * The padding property::
2906 * The right-padding property::
2907 * The staff-padding property::
2908 * The self-alignment-X property::
2909 * The staff-position property::
2910 * The extra-offset property::
2911 * The positions property::
2912 * The force-hshift property::
2913 @end menu
2914
2915 @node The padding property
2916 @unnumberedsubsubsec The @code{padding} property
2917
2918 @cindex padding
2919 @cindex fixing overlapping notation
2920 @cindex overlapping notation
2921
2922 The @code{padding} property can be set to increase
2923 (or decrease) the distance between symbols that are printed
2924 above or below notes.
2925
2926 @cindex Script, example of overriding
2927 @cindex padding property, example
2928
2929 @lilypond[quote,fragment,relative=1,verbatim]
2930 c2\fermata
2931 \override Script.padding = #3
2932 b2\fermata
2933 @end lilypond
2934
2935 @cindex MetronomeMark, example of overriding
2936 @cindex padding property, example
2937
2938 @lilypond[quote,fragment,relative=1,verbatim]
2939 % This will not work, see below
2940 \override MetronomeMark.padding = #3
2941 \tempo 4 = 120
2942 c1 |
2943 % This works
2944 \override Score.MetronomeMark.padding = #3
2945 \tempo 4 = 80
2946 d1 |
2947 @end lilypond
2948
2949 Note in the second example how important it is to figure out what
2950 context handles a certain object.  Since the @code{MetronomeMark}
2951 object is handled in the @code{Score} context, property changes in the
2952 @code{Voice} context will not be noticed.  For more details, see
2953 @ruser{Modifying properties}.
2954
2955 If the @code{padding} property of an object is increased when that
2956 object is in a stack of objects being positioned according to
2957 their @code{outside-staff-priority}, then that object and all
2958 objects outside it are moved.
2959
2960
2961 @node The right-padding property
2962 @unnumberedsubsubsec The @code{right-padding} property
2963
2964 @cindex right-padding property
2965
2966 The @code{right-padding} property affects the spacing between the
2967 accidental and the note to which it applies.  It is not often
2968 required, but the default spacing may be wrong for certain special
2969 accidental glyphs or combination of glyphs used in some microtonal
2970 music.  These have to be entered by overriding the accidental
2971 stencil with a markup containing the desired symbol(s), like this:
2972
2973 @cindex Accidental, example of overriding
2974 @cindex text property, example
2975 @cindex stencil property, example
2976 @cindex AccidentalPlacement, example of overriding
2977 @cindex right-padding property, example
2978
2979 @lilypond[quote,ragged-right,verbatim]
2980 sesquisharp = \markup { \sesquisharp }
2981 \relative c'' {
2982   c4
2983   % This prints a sesquisharp but the spacing is too small
2984   \once \override Accidental.stencil = #ly:text-interface::print
2985   \once \override Accidental.text = #sesquisharp
2986   cis4 c
2987   % This improves the spacing
2988   \once \override Score.AccidentalPlacement.right-padding = #0.6
2989   \once \override Accidental.stencil = #ly:text-interface::print
2990   \once \override Accidental.text = #sesquisharp
2991   cis4 |
2992 }
2993 @end lilypond
2994
2995 @noindent
2996 This necessarily uses an override for the accidental stencil which
2997 will not be covered until later.  The stencil type must be a
2998 procedure, here changed to print the contents of the @code{text}
2999 property of @code{Accidental}, which itself is set to be a
3000 sesquisharp sign.  This sign is then moved further away from the
3001 note head by overriding @code{right-padding}.
3002
3003 @noindent
3004
3005 @node The staff-padding property
3006 @unnumberedsubsubsec The @code{staff-padding} property
3007
3008 @cindex aligning objects on a baseline
3009 @cindex objects, aligning on a baseline
3010
3011 @code{staff-padding} can be used to align objects such as dynamics
3012 along a baseline at a fixed distance from the staff, when no other
3013 notation forces them further from the staff.
3014 It is not a property of @code{DynamicText} but of
3015 @code{DynamicLineSpanner}.  This is because the baseline should apply
3016 equally to @strong{all} dynamics, including those created as extended
3017 spanners.  So this is the way to align the dynamic marks in the
3018 example taken from the previous section:
3019
3020 @cindex DynamicText, example of overriding
3021 @cindex extra-spacing-width property, example
3022 @cindex DynamicLineSpanner, example of overriding
3023 @cindex staff-padding property, example
3024
3025 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
3026 \override DynamicLineSpanner.staff-padding = #3
3027 a4\f b\mf a\p b\mp
3028 @end lilypond
3029
3030
3031 @node The self-alignment-X property
3032 @unnumberedsubsubsec The @code{self-alignment-X} property
3033
3034 The following example shows how to adjust the position
3035 of a string fingering object relative to a note's stem by aligning the
3036 right edge with the reference point of the parent note:
3037
3038 @cindex StringNumber, example of overriding
3039 @cindex self-alignment-X property, example
3040
3041 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
3042 \voiceOne
3043 <a\2>
3044 \once \override StringNumber.self-alignment-X = #RIGHT
3045 <a\2>
3046 @end lilypond
3047
3048 @node The staff-position property
3049 @unnumberedsubsubsec The @code{staff-position} property
3050
3051 @cindex object collision within a staff
3052
3053 Multimeasure rests in one voice can collide with notes in another.
3054 Since these rests are typeset centered between the bar lines, it
3055 would require significant effort for LilyPond to figure out which
3056 other notes might collide with it, since all the current collision
3057 handling between notes and between notes and rests is done only
3058 for notes and rests that occur at the same time.  Here's an
3059 example of a collision of this type:
3060
3061 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
3062 << { c4 c c c } \\ { R1 } >>
3063 @end lilypond
3064
3065 The best solution here is to move the multimeasure rest down, since the
3066 rest is in voice two. The default in @code{\voiceTwo} (i.e. in the
3067 second voice of a @code{<<@{@dots{}@} \\ @{@dots{}@}>>} construct) is
3068 that @code{staff-position} is set to -4 for MultiMeasureRest, so we need
3069 to move it, say, four half-staff spaces down to @w{@code{-8}}.
3070
3071 @cindex MultiMeasureRest, example of overriding
3072 @cindex staff-position property, example
3073
3074 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
3075 <<
3076   { c4 c c c }
3077   \\
3078   \override MultiMeasureRest.staff-position = #-8
3079   { R1 }
3080 >>
3081 @end lilypond
3082
3083 This is better than using, for example, @code{extra-offset},
3084 because the ledger line above the rest is inserted automatically.
3085
3086 @node The extra-offset property
3087 @unnumberedsubsubsec The @code{extra-offset} property
3088
3089 @cindex positioning objects
3090 @cindex positioning grobs
3091 @cindex objects, positioning
3092 @cindex grobs, positioning
3093
3094 The @code{extra-offset} property provides complete control over the
3095 positioning of an object both horizontally and vertically.
3096
3097 In the following example, the second fingering is moved a little to
3098 the left, and 1.8 staff space downwards:
3099
3100 @cindex Fingering, example of overriding
3101 @cindex extra-offset property, example
3102
3103 @lilypond[quote,fragment,relative=1,verbatim]
3104 \stemUp
3105 f4-5
3106 \once \override Fingering.extra-offset = #'(-0.3 . -1.8)
3107 f4-5
3108 @end lilypond
3109
3110
3111 @node The positions property
3112 @unnumberedsubsubsec The @code{positions} property
3113
3114 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
3115 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
3116 @cindex tuplet beams, controlling manually
3117 @cindex slurs, controlling manually
3118 @cindex phrasing slurs, controlling manually
3119 @cindex beams, controlling manually
3120
3121 The @code{positions} property allows the vertical position and hence
3122 the slope of tuplets, slurs, phrasing slurs and beams to be controlled
3123 manually.
3124
3125 Here's an example in which the phrasing slur and slur collide:
3126
3127 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
3128 a8 \( ( a'16 ) a \)
3129 @end lilypond
3130
3131 @cindex PhrasingSlur, example of overriding
3132 @cindex positions property, example
3133
3134 @noindent
3135 One possibility would be to move the two ends of the phrasing slur
3136 higher.  We can try setting the left end to 2.5 staff-spaces above the
3137 centre line and the right end to 4.5 above, and LilyPond will
3138 select the phrasing slur from the candidates it has found with its
3139 end points closest to these:
3140
3141 @lilypond[quote,verbatim,fragment,ragged-right,relative=2]
3142 \once \override PhrasingSlur.positions = #'(2.5 . 4.5)
3143 a8 \( ( a'16 ) a \)
3144 @end lilypond
3145
3146 This is an improvement, but why not lower the right end of the slur
3147 a little?  If you try it you'll find it can't be done in this way.
3148 That's because there are no candidate slurs lower than the one
3149 already selected, and in this case the @code{positions} property has
3150 no effect.  However, ties, slurs and phrasing slurs @emph{can} be
3151 positioned and shaped very precisely when necessary.  To learn how to
3152 do this, see @ruser{Modifying ties and slurs}.
3153
3154 Here's a further example.  We see that the beams
3155 collide with the ties:
3156
3157 @lilypond[quote,verbatim,fragment,ragged-right]
3158 {
3159   \time 4/2
3160   <<
3161     { c'1 ~ 2. e'8 f' }
3162     \\
3163     { e''8 e'' e'' e''  e'' e'' e'' e''  f''2 g'' }
3164   >>
3165   <<
3166     { c'1 ~ 2. e'8 f' }
3167     \\
3168     { e''8 e'' e'' e''  e'' e'' e'' e''  f''2 g'' }
3169   >>
3170 }
3171 @end lilypond
3172
3173 @noindent
3174 This can be resolved by manually moving both ends of the beam
3175 up from their position at 1.81 staff-spaces below the center line to,
3176 say, 1:
3177
3178 @cindex Beam, example of overriding
3179 @cindex positions property, example
3180
3181 @lilypond[quote,verbatim,fragment,ragged-right]
3182 {
3183   \time 4/2
3184   <<
3185     { c'1 ~ 2. e'8 f' }
3186     \\
3187     {
3188       \override Beam.positions = #'(-1 . -1)
3189       e''8 e'' e'' e''  e'' e'' e'' e''  f''2 g''
3190     }
3191   >>
3192   <<
3193     { c'1 ~ 2. e'8 f' }
3194     \\
3195     { e''8 e'' e'' e''  e'' e'' e'' e''  f''2 g'' }
3196   >>
3197 }
3198 @end lilypond
3199
3200 @noindent
3201 Note that the override continues to apply in the first voice of
3202 the second measure of eighth notes, but not to any of the beams in the
3203 second voice.
3204
3205 @node The force-hshift property
3206 @unnumberedsubsubsec The @code{force-hshift} property
3207
3208 We can now see how to apply the final corrections to the Chopin
3209 example introduced at the end of @ref{I'm hearing Voices}, which
3210 was left looking like this:
3211
3212 @lilypond[quote,verbatim,fragment,ragged-right]
3213 \new Staff \relative c'' {
3214   \key aes \major
3215   <<
3216     { c2 aes4. bes8 }
3217     \\
3218     { <ees, c>2 des }
3219     \\
3220     \\
3221     { aes'2 f4 fes }
3222   >> |
3223   <c ees aes c>1 |
3224 }
3225 @end lilypond
3226
3227 @noindent
3228 The inner note of the first chord (i.e. the A-flat in the fourth
3229 Voice) need not be shifted away from the note column of the higher
3230 note.  We might expect to correct this by using @code{\shiftOff}, but
3231 this will cause warnings about clashing note columns.  Instead, we
3232 set @code{force-hshift}, which is a property of @code{NoteColumn},
3233 of this note to zero.
3234
3235 In the second chord we prefer the F to line up with the A-flat and
3236 the lowest note to be positioned slightly right to avoid a collision
3237 of stems.  We achieve this by setting @code{force-hshift} in the
3238 @code{NoteColumn} of the low D-flat to move it to the right by half
3239 a staff-space, and setting @code{force-hshift} for the F to zero.
3240 Note that we use @code{\once} to avoid the settings propagating
3241 beyond the immediate musical moment, although in this small example
3242 the @code{\once} and the second @code{\override} in Voice four could
3243 be omitted.  This would not be good practice.
3244
3245 Here's the final result:
3246
3247 @cindex NoteColumn, example of overriding
3248 @cindex force-hshift property, example
3249
3250 @lilypond[quote,verbatim,fragment,ragged-right]
3251 \new Staff \relative c'' {
3252   \key aes \major
3253   <<
3254     { c2 aes4. bes8 }
3255     \\
3256     { <ees, c>2 \once \override NoteColumn.force-hshift = 0.5 des }
3257     \\
3258     \\
3259     { \once \override NoteColumn.force-hshift = 0 aes'2
3260       \once \override NoteColumn.force-hshift = 0 f4 fes }
3261   >> |
3262   <c ees aes c>1 |
3263 }
3264 @end lilypond
3265
3266
3267 @node Real music example
3268 @subsection Real music example
3269
3270 We end this section on Tweaks by showing the steps to be taken to
3271 deal with a tricky example which needs several tweaks to produce
3272 the desired output.  The example has been deliberately chosen to
3273 illustrate the use of the Notation Reference to resolve unusual
3274 problems with notation.  It is not representative of the more usual
3275 engraving process, so please do not let these difficulties put
3276 you off!  Fortunately, difficulties like these are not very common!
3277
3278 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
3279 9, the transition from the opening Lento to Moderato.
3280 Here, first, is what we want the output to look like, but to avoid
3281 over-complicating the example too much we have left out the
3282 dynamics, fingering and pedalling.
3283
3284 @c The following should appear as music without code
3285 @c This example should not be indexed
3286 @c line-width ensures no break
3287 @lilypond[quote,ragged-right,line-width=6\in]
3288 rhMusic = \relative c'' {
3289   \new Voice {
3290     r2 c4.\( g8 |
3291     \once \override Tie.staff-position = #3.5
3292     bes1~ |
3293     \bar "||"
3294     \time 6/4
3295     \mergeDifferentlyHeadedOn
3296     \mergeDifferentlyDottedOn
3297     bes2.\tempo "Moderato" r8
3298     <<
3299       { c,8 d fis bes a }
3300       \new Voice {
3301         \voiceTwo
3302         c,8~
3303         % Reposition the c2 to the right of the merged note
3304         \once \override NoteColumn.force-hshift = #1.0
3305         % Move the c2 out of the main note column
3306         % so the merge will work
3307         \shiftOnn
3308         c2
3309       }
3310       \new Voice {
3311         \voiceThree
3312         s8
3313         % Stem on the d2 must be down to permit merging
3314         \stemDown
3315         % Stem on the d2 should be invisible
3316         \tweak Stem.transparent ##t
3317         d2
3318       }
3319       \new Voice {
3320         \voiceFour
3321         s4 fis4.
3322       }
3323     >> |
3324     \mergeDifferentlyHeadedOff
3325     \mergeDifferentlyDottedOff
3326     g2.\)
3327   }
3328 }
3329
3330 lhMusic = \relative c' {
3331   r2 <c g ees>2( |
3332   <d g, d>1)\arpeggio |
3333   r2. d,,4 r4 r |
3334   r4
3335 }
3336
3337 \score {
3338   \new PianoStaff <<
3339     \new Staff = "RH"  <<
3340       \key g \minor
3341       \rhMusic
3342     >>
3343     \new Staff = "LH" <<
3344       \key g \minor
3345       \clef "bass"
3346       \lhMusic
3347     >>
3348   >>
3349 }
3350 @end lilypond
3351
3352 We note first that the right hand part in the third bar
3353 requires four voices.  These are the five beamed eighth notes,
3354 the tied C, the half-note D which is merged with the eighth note
3355 D, and the dotted quarter note F-sharp, which is also merged with
3356 the eighth note at the same pitch.  Everything else is in a single
3357 voice, so the easiest way is to introduce these extra three voices
3358 temporarily at the time they are needed.  If you have forgotten
3359 how to do this, look at @ref{I'm hearing Voices} and @ref{Explicitly
3360 instantiating voices}.  Here we choose to use explicitly instantiated
3361 voices for the polyphonic passage, as LilyPond is better able to
3362 avoid collisions if all voices are instantiated explicitly in this
3363 way.
3364
3365 So let us begin by entering the notes as two variables, setting up
3366 the staff structure in a score block, and seeing what LilyPond
3367 produces by default:
3368
3369 @c line-width ensures no break
3370 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3371 rhMusic = \relative c'' {
3372   \new Voice {
3373     r2 c4. g8 |
3374     bes1~ |
3375     \time 6/4
3376     bes2. r8
3377     % Start polyphonic section of four voices
3378     <<
3379       { c,8 d fis bes a }  % continuation of main voice
3380       \new Voice {
3381         \voiceTwo
3382         c,8~ 2
3383       }
3384       \new Voice {
3385         \voiceThree
3386         s8 d2
3387       }
3388       \new Voice {
3389         \voiceFour
3390         s4 fis4.
3391       }
3392     >> |
3393     g2.  % continuation of main voice
3394   }
3395 }
3396
3397 lhMusic = \relative c' {
3398   r2 <c g ees>2 |
3399   <d g, d>1 |
3400   r2. d,,4 r4 r |
3401   r4
3402 }
3403
3404 \score {
3405   \new PianoStaff <<
3406     \new Staff = "RH"  <<
3407       \key g \minor
3408       \rhMusic
3409     >>
3410     \new Staff = "LH" <<
3411       \key g \minor
3412       \clef "bass"
3413       \lhMusic
3414     >>
3415   >>
3416 }
3417 @end lilypond
3418
3419 All the notes are right, but the appearance is far from
3420 satisfactory.  The tie collides with the change in time signature,
3421 some notes are not merged together, and several notation elements
3422 are missing.  Let's first deal with the easier things.  We can
3423 easily add the left hand slur and the right hand phrasing slur,
3424 since these were all covered in the Tutorial.  Doing this gives:
3425
3426 @c line-width ensures no break
3427 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3428 rhMusic = \relative c'' {
3429   \new Voice {
3430     r2 c4.\( g8 |
3431     bes1~ |
3432     \time 6/4
3433     bes2. r8
3434     % Start polyphonic section of four voices
3435     <<
3436       { c,8 d fis bes a }  % continuation of main voice
3437       \new Voice {
3438         \voiceTwo
3439         c,8~ 2
3440       }
3441       \new Voice {
3442         \voiceThree
3443         s8 d2
3444       }
3445       \new Voice {
3446         \voiceFour
3447         s4 fis4.
3448       }
3449     >> |
3450     g2.\)  % continuation of main voice
3451   }
3452 }
3453
3454 lhMusic = \relative c' {
3455   r2 <c g ees>2( |
3456   <d g, d>1) |
3457   r2. d,,4 r4 r |
3458   r4
3459 }
3460
3461 \score {
3462   \new PianoStaff <<
3463     \new Staff = "RH"  <<
3464       \key g \minor
3465       \rhMusic
3466     >>
3467     \new Staff = "LH" <<
3468       \key g \minor
3469       \clef "bass"
3470       \lhMusic
3471     >>
3472   >>
3473 }
3474 @end lilypond
3475
3476 The first bar is now correct.  The second bar contains an arpeggio and
3477 is terminated by a double bar line.  How do we do these, as they have
3478 not been mentioned in this Learning Manual?  This is where we need to
3479 turn to the Notation Reference.  Looking up @q{arpeggio} and @q{bar
3480 line} in the index quickly shows us that an arpeggio is produced by
3481 appending @code{\arpeggio} to a chord, and a double bar line is
3482 produced by the @code{\bar "||"} command.  That's easily done.  We
3483 next need to correct the collision of the tie with the time signature.
3484 This is best done by moving the tie upwards.  Moving objects was
3485 covered earlier in @ref{Moving objects}, which says that objects
3486 positioned relative to the staff can be moved vertically by overriding
3487 their @code{staff-position} property, which is specified in half staff
3488 spaces relative to the center line of the staff.  So the following
3489 override placed just before the first tied note would move the tie up
3490 to 3.5 half staff spaces above the center line:
3491
3492 @code{\once \override Tie.staff-position = #3.5}
3493
3494 This completes bar two, giving:
3495
3496 @c line-width ensures no break
3497 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3498 rhMusic = \relative c'' {
3499   \new Voice {
3500     r2 c4.\( g8 |
3501     \once \override Tie.staff-position = #3.5
3502     bes1~ |
3503     \bar "||"
3504     \time 6/4
3505     bes2. r8
3506     % Start polyphonic section of four voices
3507     <<
3508       { c,8 d fis bes a }  % continuation of main voice
3509       \new Voice {
3510         \voiceTwo
3511         c,8~ 2
3512       }
3513       \new Voice {
3514         \voiceThree
3515         s8 d2
3516       }
3517       \new Voice {
3518         \voiceFour
3519         s4 fis4.
3520       }
3521     >> |
3522     g2.\)  % continuation of main voice
3523   }
3524 }
3525
3526 lhMusic = \relative c' {
3527   r2 <c g ees>2( |
3528   <d g, d>1)\arpeggio |
3529   r2. d,,4 r4 r |
3530   r4
3531 }
3532
3533 \score {
3534   \new PianoStaff <<
3535     \new Staff = "RH"  <<
3536       \key g \minor
3537       \rhMusic
3538     >>
3539     \new Staff = "LH" <<
3540       \key g \minor
3541       \clef "bass"
3542       \lhMusic
3543     >>
3544   >>
3545 }
3546 @end lilypond
3547
3548 On to bar three and the start of the Moderato section.  The tutorial
3549 showed how to add a tempo indication with the @code{\tempo} command, so
3550 adding @qq{Moderato} is easy.  But how do we merge notes in
3551 different voices together?  This is where we need to turn again to
3552 the Notation Reference for help.  A search for @qq{merge} in the
3553 Notation Reference index quickly leads us to the commands for merging
3554 differently headed and differently dotted notes in
3555 @ruser{Collision resolution}.  In our example we need to merge both
3556 types of note for the duration of the polyphonic section in bar 3,
3557 so using the information we find in the Notation Reference we add
3558
3559 @example
3560 \mergeDifferentlyHeadedOn
3561 \mergeDifferentlyDottedOn
3562 @end example
3563
3564 @noindent
3565 to the start of that section and
3566
3567 @example
3568 \mergeDifferentlyHeadedOff
3569 \mergeDifferentlyDottedOff
3570 @end example
3571
3572 @noindent
3573 to the end, giving:
3574
3575 @c line-width ensures no break
3576 @lilypond[quote,ragged-right,line-width=6\in]
3577 rhMusic = \relative c'' {
3578   \new Voice {
3579     r2 c4.\( g8 |
3580     \once \override Tie.staff-position = #3.5
3581     bes1~ |
3582     \bar "||"
3583     \time 6/4
3584     bes2.\tempo "Moderato" r8
3585     \mergeDifferentlyHeadedOn
3586     \mergeDifferentlyDottedOn
3587     % Start polyphonic section of four voices
3588     <<
3589       { c,8 d fis bes a }  % continuation of main voice
3590       \new Voice {
3591         \voiceTwo
3592         c,8~ 2
3593       }
3594       \new Voice {
3595         \voiceThree
3596         s8 d2
3597       }
3598       \new Voice {
3599         \voiceFour
3600         s4 fis4.
3601       }
3602     >> |
3603     \mergeDifferentlyHeadedOff
3604     \mergeDifferentlyDottedOff
3605     g2.\)  % continuation of main voice
3606   }
3607 }
3608
3609 lhMusic = \relative c' {
3610   r2 <c g ees>2( |
3611   <d g, d>1)\arpeggio |
3612   r2. d,,4 r4 r |
3613   r4
3614 }
3615
3616 \score {
3617   \new PianoStaff <<
3618     \new Staff = "RH"  <<
3619       \key g \minor
3620       \rhMusic
3621     >>
3622     \new Staff = "LH" <<
3623       \key g \minor
3624       \clef "bass"
3625       \lhMusic
3626     >>
3627   >>
3628 }
3629 @end lilypond
3630
3631 These overrides have merged the two F-sharp notes, but not the two
3632 on D.  Why not?  The answer is there in the same section in the
3633 Notation Reference -- notes being merged must have stems in
3634 opposite directions and two notes cannot be merged successfully if
3635 there is a third note in the same note column.  Here the two D's
3636 both have upward stems and there is a third note -- the C.  We know
3637 how to change the stem direction using @code{\stemDown}, and
3638 the Notation Reference also says how to move the C -- apply a shift
3639 using one of the @code{\shift} commands.  But which one?
3640 The C is in voice two which has shift off, and the two D's are in
3641 voices one and three, which have shift off and shift on,
3642 respectively.  So we have to shift the C a further level still
3643 using @code{\shiftOnn} to avoid it interfering with the two D's.
3644 Applying these changes gives:
3645
3646 @cindex Tie, example of overriding
3647 @cindex staff-position property, example
3648
3649 @c line-width ensures no break
3650 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3651 rhMusic = \relative c'' {
3652   \new Voice {
3653     r2 c4.\( g8 |
3654     \once \override Tie.staff-position = #3.5
3655     bes1~ |
3656     \bar "||"
3657     \time 6/4
3658     bes2.\tempo "Moderato" r8
3659     \mergeDifferentlyHeadedOn
3660     \mergeDifferentlyDottedOn
3661     % Start polyphonic section of four voices
3662     <<
3663       { c,8 d fis bes a }  % continuation of main voice
3664       \new Voice {
3665         \voiceTwo
3666         % Move the c2 out of the main note column
3667         % so the merge will work
3668         c,8~ \shiftOnn c2
3669       }
3670       \new Voice {
3671         \voiceThree
3672         % Stem on the d2 must be down to permit merging
3673         s8 \stemDown d2
3674       }
3675       \new Voice {
3676         \voiceFour
3677         s4 fis4.
3678       }
3679     >> |
3680     \mergeDifferentlyHeadedOff
3681     \mergeDifferentlyDottedOff
3682     g2.\)  % continuation of main voice
3683   }
3684 }
3685
3686 lhMusic = \relative c' {
3687   r2 <c g ees>2( |
3688   <d g, d>1)\arpeggio |
3689   r2. d,,4 r4 r |
3690   r4
3691 }
3692
3693 \score {
3694   \new PianoStaff <<
3695     \new Staff = "RH"  <<
3696       \key g \minor
3697       \rhMusic
3698     >>
3699     \new Staff = "LH" <<
3700       \key g \minor
3701       \clef "bass"
3702       \lhMusic
3703     >>
3704   >>
3705 }
3706 @end lilypond
3707
3708 Nearly there.  Only two problems remain: The downward stem on the
3709 merged D should not be there, and the C would be better positioned
3710 to the right of the D's.  We know how to do both of these from the
3711 earlier tweaks: we make the stem transparent, and move the C with
3712 the @code{force-hshift} property.  Here's the final result:
3713
3714 @cindex NoteColumn, example of overriding
3715 @cindex force-hshift property, example
3716 @cindex Stem, example of overriding
3717 @cindex transparent property, example
3718
3719 @c line-width ensures no break
3720 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3721 rhMusic = \relative c'' {
3722   \new Voice {
3723     r2 c4.\( g8 |
3724     \once \override Tie.staff-position = #3.5
3725     bes1~ |
3726     \bar "||"
3727     \time 6/4
3728     bes2.\tempo "Moderato" r8
3729     \mergeDifferentlyHeadedOn
3730     \mergeDifferentlyDottedOn
3731     % Start polyphonic section of four voices
3732     <<
3733       { c,8 d fis bes a }  % continuation of main voice
3734       \new Voice {
3735         \voiceTwo
3736         c,8~
3737         % Reposition the c2 to the right of the merged note
3738         \once \override NoteColumn.force-hshift = #1.0
3739         % Move the c2 out of the main note column
3740         % so the merge will work
3741         \shiftOnn
3742         c2
3743       }
3744       \new Voice {
3745         \voiceThree
3746         s8
3747         % Stem on the d2 must be down to permit merging
3748         \stemDown
3749         % Stem on the d2 should be invisible
3750         \tweak Stem.transparent ##t
3751         d2
3752       }
3753       \new Voice {
3754         \voiceFour
3755         s4 fis4.
3756       }
3757     >> |
3758     \mergeDifferentlyHeadedOff
3759     \mergeDifferentlyDottedOff
3760     g2.\)  % continuation of main voice
3761   }
3762 }
3763
3764 lhMusic = \relative c' {
3765   r2 <c g ees>2( |
3766   <d g, d>1)\arpeggio |
3767   r2. d,,4 r4 r |
3768   r4
3769 }
3770
3771 \score {
3772   \new PianoStaff <<
3773     \new Staff = "RH"  <<
3774       \key g \minor
3775       \rhMusic
3776     >>
3777     \new Staff = "LH" <<
3778       \key g \minor
3779       \clef "bass"
3780       \lhMusic
3781     >>
3782   >>
3783 }
3784 @end lilypond
3785
3786
3787 @node Further tweaking
3788 @section Further tweaking
3789
3790 @menu
3791 * Other uses for tweaks::
3792 * Using variables for layout adjustments::
3793 * Style sheets::
3794 * Other sources of information::
3795 * Advanced tweaks with Scheme::
3796 @end menu
3797
3798 @node Other uses for tweaks
3799 @subsection Other uses for tweaks
3800
3801 @menu
3802 * Tying notes across voices::
3803 * Simulating a fermata in MIDI::
3804 @end menu
3805
3806 @cindex transparent property, use of
3807 @cindex objects, making invisible
3808 @cindex removing objects
3809 @cindex objects, removing
3810 @cindex hiding objects
3811 @cindex objects, hiding
3812 @cindex invisible objects
3813 @cindex objects, invisible
3814
3815 @node Tying notes across voices
3816 @unnumberedsubsubsec Tying notes across voices
3817
3818 @cindex tying notes across voices
3819
3820 The following example demonstrates how to connect notes in
3821 different voices using ties.  Normally, only two notes in the
3822 same voice can be connected with ties.  By using two voices,
3823 with the tied notes in one of them
3824
3825 @lilypond[quote,fragment,relative=2]
3826 << { b8~ 8\noBeam } \\ { b8[ g] } >>
3827 @end lilypond
3828
3829 @noindent
3830 and blanking the first up-stem in that voice, the tie appears to
3831 cross voices:
3832
3833 @cindex Stem, example of overriding
3834 @cindex transparent property, example
3835
3836 @lilypond[quote,fragment,relative=2,verbatim]
3837 <<
3838   {
3839     \tweak Stem.transparent ##t
3840     b8~ 8\noBeam
3841   }
3842 \\
3843   { b8[ g] }
3844 >>
3845 @end lilypond
3846
3847 To make sure that the just-blanked stem doesn't squeeze the tie
3848 too much, we can lengthen the stem by setting the
3849 @code{length} to @code{8},
3850
3851 @lilypond[quote,fragment,relative=2,verbatim]
3852 <<
3853   {
3854     \tweak Stem.transparent ##t
3855     \tweak Stem.length #8
3856     b8~ 8\noBeam
3857   }
3858 \\
3859   { b8[ g] }
3860 >>
3861 @end lilypond
3862
3863 @funindex \single
3864 @cindex tweak, generated from override
3865 Now for @emph{overriding} the transparency of a graphical object,
3866 we could have used the shorthand @code{\hide} as explained above.
3867 Tweaking is a different operation, affecting only properties
3868 generated from a single music expression.  It turns out that we
3869 can convert overrides into tweaks using @code{\single}, making it
3870 possible to rewrite the above example as
3871
3872 @lilypond[quote,fragment,relative=2,verbatim]
3873 <<
3874   {
3875     \single \hide Stem
3876     \single \hide Flag
3877     \tweak Stem.length #8
3878     b8~ 8\noBeam
3879   }
3880 \\
3881   { b8[ g] }
3882 >>
3883 @end lilypond
3884
3885 In this particular case, the difference to @code{\once \hide} is
3886 not apparent.  It is important when there are several objects at
3887 the same point in musical time (like noteheads in a chord).  In
3888 that case, @code{\once} will affect all of those objects while
3889 @code{\single} will only affect a single one, the one generated by
3890 the immediately following music expression.
3891
3892 @node Simulating a fermata in MIDI
3893 @unnumberedsubsubsec Simulating a fermata in MIDI
3894
3895 @cindex stencil property, use of
3896 @cindex fermata, implementing in MIDI
3897
3898 For outside-staff objects it is usually better to override the
3899 object's @code{stencil} property rather than its @code{transparent}
3900 property when you wish to remove it from the printed output.
3901 Setting the @code{stencil} property of an object to @code{#f} will
3902 remove that object entirely from the printed output.  This means it
3903 has no effect on the placement of other objects placed relative to
3904 it.
3905
3906 For example, if we wished to change the metronome setting in order
3907 to simulate a fermata in the MIDI output we would not want the
3908 metronome markings to appear in the printed output, and we would
3909 not want it to influence the spacing between the two systems or
3910 the positions of adjacent annotations on the staff.  So setting
3911 its @code{stencil} property to @code{#f} would be the best way.
3912 We show here the effect of the two methods:
3913
3914 @cindex MetronomeMark, example of overriding
3915 @cindex transparent property, example
3916
3917 @lilypond[quote,verbatim,ragged-right]
3918 \score {
3919   \relative c'' {
3920     % Visible tempo marking
3921     \tempo 4=120
3922     a4 a a
3923     \once \hide Score.MetronomeMark
3924     % Invisible tempo marking to lengthen fermata in MIDI
3925     \tempo 4=80
3926     a4\fermata |
3927     % New tempo for next section
3928     \tempo 4=100
3929     a4 a a a |
3930   }
3931   \layout { }
3932   \midi { }
3933 }
3934 @end lilypond
3935
3936 @cindex MetronomeMark, example of overriding
3937 @cindex stencil property, example
3938
3939 @lilypond[quote,verbatim,ragged-right]
3940 \score {
3941   \relative c'' {
3942     % Visible tempo marking
3943     \tempo 4=120
3944     a4 a a
3945     \once \omit Score.MetronomeMark
3946     % Invisible tempo marking to lengthen fermata in MIDI
3947     \tempo 4=80
3948     a4\fermata |
3949     % New tempo for next section
3950     \tempo 4=100
3951     a4 a a a |
3952   }
3953   \layout { }
3954   \midi { }
3955 }
3956 @end lilypond
3957
3958 @noindent
3959 Both methods remove the metronome mark which lengthens the fermata
3960 from the printed output, and both affect the MIDI timing as
3961 required, but the transparent metronome mark in the first line
3962 forces the following tempo indication too high while the
3963 second (with the stencil removed) does not.
3964
3965 @seealso
3966 Music Glossary:
3967 @rglos{system}.
3968
3969 @node Using variables for layout adjustments
3970 @subsection Using variables for layout adjustments
3971
3972 @cindex variables, using for overrides
3973 @cindex overrides, using variables for
3974 @cindex adjustments, using variables for
3975 @cindex layout adjustments, using variables for
3976
3977 Override commands are often long and tedious to type, and they
3978 have to be absolutely correct.  If the same overrides are to be
3979 used many times it may be worth defining variables to hold them.
3980
3981 Suppose we wish to emphasize certain words in lyrics by printing
3982 them in bold italics.  The @code{\italic} and @code{\bold}
3983 commands only work within lyrics if they are embedded, together with
3984 the word or words to be modified, within a @code{\markup} block,
3985 which makes them tedious to enter.  The need to embed the words
3986 themselves prevents their use in simple variables.  As an
3987 alternative can we use @code{\override} and @code{\revert} commands?
3988
3989 @example
3990 @code{\override Lyrics.LyricText.font-shape = #'italic}
3991 @code{\override Lyrics.LyricText.font-series = #'bold}
3992
3993 @code{\revert Lyrics.LyricText.font-shape}
3994 @code{\revert Lyrics.LyricText.font-series}
3995 @end example
3996
3997 These would also be extremely tedious to enter if there were many
3998 words requiring emphasis.  But we @emph{can} define these as two
3999 variables and use those to bracket the words to be emphasized.
4000 Another advantage of using variables for these overrides is that
4001 the spaces around the dot are not necessary, since they are not
4002 being interpreted in @code{\lyricmode} directly.  Here's an example
4003 of this, although in practice  we would choose shorter names
4004 for the variables to make them quicker to type:
4005
4006 @cindex LyricText, example of overriding
4007 @cindex font-shape property, example
4008 @cindex font-series property, example
4009
4010 @lilypond[quote,verbatim]
4011 emphasize = {
4012   \override Lyrics.LyricText.font-shape = #'italic
4013   \override Lyrics.LyricText.font-series = #'bold
4014 }
4015
4016 normal = {
4017   \revert Lyrics.LyricText.font-shape
4018   \revert Lyrics.LyricText.font-series
4019 }
4020
4021 global = { \key c \major \time 4/4 \partial 4 }
4022
4023 SopranoMusic = \relative c' { c4 | e4. e8 g4 g    | a4   a   g  }
4024 AltoMusic    = \relative c' { c4 | c4. c8 e4 e    | f4   f   e  }
4025 TenorMusic   = \relative c  { e4 | g4. g8 c4.  b8 | a8 b c d e4 }
4026 BassMusic    = \relative c  { c4 | c4. c8 c4 c    | f8 g a b c4 }
4027
4028 VerseOne = \lyrics {
4029   E -- | ter -- nal \emphasize Fa -- ther, | \normal strong to save,
4030 }
4031
4032 VerseTwo = \lyricmode {
4033   O | \once \emphasize Christ, whose voice the | wa -- ters heard,
4034 }
4035
4036 VerseThree = \lyricmode {
4037   O | \emphasize Ho -- ly Spi -- rit, | \normal who didst brood
4038 }
4039
4040 VerseFour = \lyricmode {
4041   O | \emphasize Tri -- ni -- ty \normal of | love and pow'r
4042 }
4043
4044 \score {
4045   \new ChoirStaff <<
4046     \new Staff <<
4047       \clef "treble"
4048       \new Voice = "Soprano"  { \voiceOne \global \SopranoMusic }
4049       \new Voice = "Alto" { \voiceTwo \AltoMusic }
4050       \new Lyrics \lyricsto "Soprano" { \VerseOne }
4051       \new Lyrics \lyricsto "Soprano" { \VerseTwo }
4052       \new Lyrics \lyricsto "Soprano" { \VerseThree }
4053       \new Lyrics \lyricsto "Soprano" { \VerseFour }
4054     >>
4055     \new Staff <<
4056       \clef "bass"
4057       \new Voice = "Tenor" { \voiceOne \TenorMusic }
4058       \new Voice = "Bass"  { \voiceTwo \BassMusic }
4059     >>
4060   >>
4061 }
4062 @end lilypond
4063
4064
4065 @node Style sheets
4066 @subsection Style sheets
4067
4068 The output that LilyPond produces can be heavily modified; see
4069 @ref{Tweaking output}, for details.  But what if you have many
4070 input files that you want to apply your tweaks to?  Or what if you
4071 simply want to separate your tweaks from the actual music?  This
4072 is quite easy to do.
4073
4074 Let's look at an example.  Don't worry if you don't understand
4075 the parts with all the @code{#()}.  This is explained in
4076 @ref{Advanced tweaks with Scheme}.
4077
4078 @lilypond[quote,verbatim,ragged-right]
4079 mpdolce =
4080   \tweak self-alignment-X #-0.6
4081   #(make-dynamic-script
4082     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4083
4084 inst =
4085 #(define-music-function
4086      (parser location string)
4087      (string?)
4088    #{ <>^\markup \bold \box #string #})
4089
4090 \relative c'' {
4091   \tempo 4=50
4092   a4.\mpdolce d8 cis4--\glissando a |
4093   b4 bes a2 |
4094   \inst "Clarinet"
4095   cis4.\< d8 e4 fis |
4096   g8(\! fis)-. e( d)-. cis2 |
4097 }
4098 @end lilypond
4099
4100 Let's do something about the @code{mpdolce} and @code{inst} definitions.
4101 They produce the output we desire, but we might want to use them in
4102 another piece.  We could simply copy-and-paste them at the top of every
4103 file, but that's an annoyance.  It also leaves those definitions in our
4104 input files, and I personally find all the @code{#()} somewhat ugly.
4105 Let's hide them in another file:
4106
4107 @example
4108 %%% save this to a file called "definitions.ily"
4109 mpdolce =
4110   \tweak self-alignment-X #-0.6
4111   #(make-dynamic-script
4112     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4113
4114 inst =
4115 #(define-music-function
4116      (parser location string)
4117      (string?)
4118    #@{ <>^\markup \bold \box #string #@})
4119 @end example
4120
4121 We will refer to this file using the @code{\include} command near
4122 the top of the music file.  (The extension @file{.ily} is used to
4123 distinguish this included file, which is not meant to be compiled
4124 on its own, from the main file.)
4125 Now let's modify our music (let's save this file as @file{music.ly}).
4126
4127 @c  We have to do this awkward example/lilypond-non-verbatim
4128 @c  because we can't do the \include stuff in the manual.
4129
4130 @example
4131 \include "definitions.ily"
4132
4133 \relative c'' @{
4134   \tempo 4=50
4135   a4.\mpdolce d8 cis4--\glissando a |
4136   b4 bes a2 |
4137   \inst "Clarinet"
4138   cis4.\< d8 e4 fis |
4139   g8(\! fis)-. e( d)-. cis2 |
4140 @}
4141 @end example
4142
4143 @lilypond[quote,ragged-right]
4144 mpdolce =
4145   \tweak self-alignment-X #-0.6
4146   #(make-dynamic-script
4147     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4148
4149 inst =
4150 #(define-music-function
4151      (parser location string)
4152      (string?)
4153    #{ <>^\markup \bold \box #string #})
4154
4155 \relative c'' {
4156   \tempo 4=50
4157   a4.\mpdolce d8 cis4--\glissando a |
4158   b4 bes a2 |
4159   \inst "Clarinet"
4160   cis4.\< d8 e4 fis |
4161   g8(\! fis)-. e( d)-. cis2 |
4162 }
4163 @end lilypond
4164
4165 That looks better, but let's make a few changes.  The glissando is hard
4166 to see, so let's make it thicker and closer to the note heads.  Let's
4167 put the metronome marking above the clef, instead of over the first
4168 note.  And finally, my composition professor hates @q{C} time signatures,
4169 so we'd better make that @q{4/4} instead.
4170
4171 Don't change @file{music.ly}, though.  Replace our @file{definitions.ily}
4172 with this:
4173
4174 @example
4175 %%%  definitions.ily
4176 mpdolce =
4177   \tweak self-alignment-X #-0.6
4178   #(make-dynamic-script
4179     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4180
4181 inst =
4182 #(define-music-function
4183      (parser location string)
4184      (string?)
4185    #@{ <>^\markup \bold \box #string #@})
4186
4187 \layout@{
4188   \context @{
4189     \Score
4190     \override MetronomeMark.extra-offset = #'(-5 . 0)
4191     \override MetronomeMark.padding = #'3
4192   @}
4193   \context @{
4194     \Staff
4195     \override TimeSignature.style = #'numbered
4196   @}
4197   \context @{
4198     \Voice
4199     \override Glissando.thickness = #3
4200     \override Glissando.gap = #0.1
4201   @}
4202 @}
4203 @end example
4204
4205 @lilypond[quote,ragged-right]
4206 mpdolce =
4207   \tweak self-alignment-X #-0.6
4208   #(make-dynamic-script
4209     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4210
4211 inst =
4212 #(define-music-function
4213      (parser location string)
4214      (string?)
4215    #{ <>^\markup \bold \box #string #})
4216
4217 \layout{
4218   \context {
4219     \Score
4220     \override MetronomeMark.extra-offset = #'(-5 . 0)
4221     \override MetronomeMark.padding = #'3
4222   }
4223   \context {
4224     \Staff
4225     \override TimeSignature.style = #'numbered
4226   }
4227   \context {
4228     \Voice
4229     \override Glissando.thickness = #3
4230     \override Glissando.gap = #0.1
4231   }
4232 }
4233
4234 \relative c'' {
4235   \tempo 4=50
4236   a4.\mpdolce d8 cis4--\glissando a |
4237   b4 bes a2 |
4238   \inst "Clarinet"
4239   cis4.\< d8 e4 fis |
4240   g8(\! fis)-. e( d)-. cis2 |
4241 }
4242 @end lilypond
4243
4244 That looks nicer!  But now suppose that I want to publish this
4245 piece.  My composition professor doesn't like @q{C} time
4246 signatures, but I'm somewhat fond of them.  Let's copy the
4247 current @file{definitions.ily} to @file{web-publish.ily} and
4248 modify that.  Since this music is aimed at producing a pdf which
4249 will be displayed on the screen, we'll also increase the
4250 overall size of the output.
4251
4252 @example
4253 %%%  web-publish.ily
4254 mpdolce =
4255   \tweak self-alignment-X #-0.6
4256   #(make-dynamic-script
4257     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4258
4259 inst =
4260 #(define-music-function
4261      (parser location string)
4262      (string?)
4263    #@{ <>^\markup \bold \box #string #@})
4264
4265 #(set-global-staff-size 23)
4266
4267 \layout@{
4268   \context @{
4269     \Score
4270     \override MetronomeMark.extra-offset = #'(-5 . 0)
4271     \override MetronomeMark.padding = #'3
4272   @}
4273   \context @{
4274     \Staff
4275   @}
4276   \context @{
4277     \Voice
4278     \override Glissando.thickness = #3
4279     \override Glissando.gap = #0.1
4280   @}
4281 @}
4282 @end example
4283
4284 @lilypond[quote,ragged-right]
4285 mpdolce =
4286   \tweak self-alignment-X #-0.6
4287   #(make-dynamic-script
4288     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4289
4290 inst =
4291 #(define-music-function
4292      (parser location string)
4293      (string?)
4294    #{ <>^\markup \bold \box #string #})
4295
4296 #(set-global-staff-size 23)
4297
4298 \layout{
4299   \context { \Score
4300     \override MetronomeMark.extra-offset = #'(-5 . 0)
4301     \override MetronomeMark.padding = #'3
4302   }
4303   \context { \Voice
4304     \override Glissando.thickness = #3
4305     \override Glissando.gap = #0.1
4306   }
4307 }
4308
4309 \relative c'' {
4310   \tempo 4=50
4311   a4.\mpdolce d8 cis4--\glissando a |
4312   b4 bes a2 |
4313   \inst "Clarinet"
4314   cis4.\< d8 e4 fis |
4315   g8(\! fis)-. e( d)-. cis2 |
4316 }
4317 @end lilypond
4318
4319 Now in our music, I simply replace
4320 @code{\include "definitions.ily"} with
4321 @code{\include "web-publish.ily"}.  Of course, we could make this
4322 even more convenient.  We could make a @file{definitions.ily} file which
4323 contains only the definitions of @code{mpdolce} and @code{inst}, a
4324 @file{web-publish.ily} file which contains only the @code{\layout}
4325 section listed above, and a @file{university.ily} file which
4326 contains only the tweaks to produce the output that my professor
4327 prefers.  The top of @file{music.ly} would then look like this:
4328
4329 @example
4330 \include "definitions.ily"
4331
4332 %%%  Only uncomment one of these two lines!
4333 \include "web-publish.ily"
4334 %\include "university.ily"
4335 @end example
4336
4337 This approach can be useful even if you are only producing
4338 one set of parts.  I use half a dozen different
4339 @q{style sheet} files for my projects.  I begin every music
4340 file with @code{\include "../global.ily"}, which contains
4341
4342 @example
4343 %%%   global.ily
4344 \version @w{"@version{}"}
4345
4346 #(ly:set-option 'point-and-click #f)
4347
4348 \include "../init/init-defs.ly"
4349 \include "../init/init-layout.ly"
4350 \include "../init/init-headers.ly"
4351 \include "../init/init-paper.ly"
4352 @end example
4353
4354
4355 @node Other sources of information
4356 @subsection Other sources of information
4357
4358 The Internals Reference documentation contains a lot of information
4359 about LilyPond, but even more information can be gathered by
4360 looking at the internal LilyPond files.  To explore these, you must
4361 first find the directory appropriate to your system.  The location
4362 of this directory depends (a) on whether you obtained LilyPond
4363 by downloading a precompiled binary from lilypond.org
4364 or whether you installed it from a package manager (i.e.
4365 distributed with GNU/Linux, or installed under fink or cygwin) or
4366 compiled it from source, and (b) on which operating system it is
4367 being used:
4368
4369 @subsubsubheading Downloaded from lilypond.org
4370
4371 @itemize @bullet
4372 @item GNU/Linux
4373
4374 Navigate to
4375 @example
4376 @file{@var{INSTALLDIR}/lilypond/usr/@/share/lilypond/current/}
4377 @end example
4378
4379 @item MacOS X
4380
4381 Navigate to
4382 @example
4383 @file{@var{INSTALLDIR}/LilyPond.app/Contents/@/Resources/share/lilypond/current/}
4384 @end example
4385
4386 by either @code{cd}-ing into this directory from the
4387 Terminal, or control-clicking on the LilyPond application and
4388 selecting @q{Show Package Contents}.
4389
4390 @item Windows
4391
4392 Using Windows Explorer, navigate to
4393 @example
4394 @file{@var{INSTALLDIR}/LilyPond/usr/@/share/lilypond/current/}
4395 @end example
4396
4397 @end itemize
4398
4399 @subsubsubheading Installed from a package manager or compiled from source
4400
4401 Navigate to
4402 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
4403 @var{PREFIX} is set by your package manager or @code{configure}
4404 script, and @var{X.Y.Z} is the LilyPond version number.
4405
4406 @smallspace
4407
4408 Within this directory the two interesting subdirectories are
4409
4410 @itemize
4411 @item @file{ly/} - contains files in LilyPond format
4412 @item @file{scm/} - contains files in Scheme format
4413 @end itemize
4414
4415 Let's begin by looking at some files in @file{ly/}.
4416 Open @file{ly/property-init.ly} in a text editor.  The one
4417 you normally use for @code{.ly} files will be fine.  This file
4418 contains the definitions of all the standard LilyPond predefined
4419 commands, such as @code{\stemUp} and @code{\slurDotted}.  You will
4420 see that these are nothing more than definitions of variables
4421 containing one or a group of @code{\override} commands.  For
4422 example, @code{/tieDotted} is defined to be:
4423
4424 @example
4425 tieDotted = @{
4426   \override Tie.dash-period = #0.75
4427   \override Tie.dash-fraction = #0.1
4428 @}
4429 @end example
4430
4431 If you do not like the default values these predefined commands can
4432 be redefined easily, just like any other variable, at the
4433 head of your input file.
4434
4435 The following are the most useful files to be found in
4436 @file{ly/}:
4437
4438 @multitable @columnfractions .4 .6
4439 @headitem Filename
4440   @tab Contents
4441 @item @file{ly/engraver-init.ly}
4442   @tab Definitions of engraver Contexts
4443 @item @file{ly/paper-defaults-init.ly}
4444   @tab Specifications of paper-related defaults
4445 @item @file{ly/performer-init.ly}
4446   @tab Definitions of performer Contexts
4447 @item @file{ly/property-init.ly}
4448   @tab Definitions of all common predefined commands
4449 @item @file{ly/spanner-init.ly}
4450   @tab Definitions of spanner-related predefined commands
4451 @end multitable
4452
4453 Other settings (such as the definitions of markup commands) are
4454 stored as @file{.scm} (Scheme) files.  The Scheme programming
4455 language is used to provide a programmable interface into
4456 LilyPond internal operation.  Further explanation of these files
4457 is currently outside the scope of this manual, as a knowledge of
4458 the Scheme language is required.  Users should be warned that
4459 a substantial amount of technical knowledge or time is required
4460 to understand Scheme and these files (see @rextend{Scheme tutorial}).
4461
4462 If you have this knowledge, the Scheme files which may be of
4463 interest are:
4464
4465 @multitable @columnfractions .4 .6
4466 @headitem Filename
4467   @tab Contents
4468 @item @file{scm/auto-beam.scm}
4469   @tab Sub-beaming defaults
4470 @item @file{scm/define-grobs.scm}
4471   @tab Default settings for grob properties
4472 @item @file{scm/define-markup-commands.scm}
4473   @tab Specify all markup commands
4474 @item @file{scm/midi.scm}
4475   @tab Default settings for MIDI output
4476 @item @file{scm/output-lib.scm}
4477   @tab Settings that affect appearance of frets, colors,
4478        accidentals, bar lines, etc
4479 @item @file{scm/parser-clef.scm}
4480   @tab Definitions of supported clefs
4481 @item @file{scm/script.scm}
4482   @tab Default settings for articulations
4483 @end multitable
4484
4485
4486 @node Advanced tweaks with Scheme
4487 @subsection Advanced tweaks with Scheme
4488
4489 Although many things are possible with the @code{\override} and
4490 @code{\tweak} commands, an even more powerful way of modifying
4491 the action of LilyPond is available through a programmable
4492 interface to the LilyPond internal operation.  Code written in
4493 the Scheme programming language can be incorporated directly in
4494 the internal operation of LilyPond.  Of course, at least a basic
4495 knowledge of programming in Scheme is required to do this, and an
4496 introduction is provided in the @rextend{Scheme tutorial}.
4497
4498 As an illustration of one of the many possibilities, instead of
4499 setting a property to a constant it can be set to a Scheme
4500 procedure which is then called whenever that property is accessed
4501 by LilyPond.  The property can then be set dynamically to a value
4502 determined by the procedure at the time it is called.  In this
4503 example we color the note head in accordance with its position on
4504 the staff.
4505
4506 @cindex x11-color function, example of using
4507 @cindex NoteHead, example of overriding
4508 @cindex color property, setting to Scheme procedure
4509
4510 @lilypond[quote,verbatim,ragged-right]
4511 #(define (color-notehead grob)
4512    "Color the notehead according to its position on the staff."
4513    (let ((mod-position (modulo (ly:grob-property grob 'staff-position)
4514                                7)))
4515      (case mod-position
4516        ;;   Return rainbow colors
4517        ((1) (x11-color 'red    ))  ; for C
4518        ((2) (x11-color 'orange ))  ; for D
4519        ((3) (x11-color 'yellow ))  ; for E
4520        ((4) (x11-color 'green  ))  ; for F
4521        ((5) (x11-color 'blue   ))  ; for G
4522        ((6) (x11-color 'purple ))  ; for A
4523        ((0) (x11-color 'violet ))  ; for B
4524        )))
4525
4526 \relative c' {
4527   % Arrange to obtain color from color-notehead procedure
4528   \override NoteHead.color = #color-notehead
4529   a2 b | c2 d | e2 f | g2 a |
4530 }
4531 @end lilypond
4532
4533 Further examples showing the use of these programmable interfaces
4534 can be found in @rextend{Callback functions}.
4535
4536
4537