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