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