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