]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/learning/tweaks.itely
Doc: LM - Document tweaking of StaffSymbol and LedgerLineSpanner
[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 .3 .3
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{VoltaBracketSpanner}
2193   @tab @code{600}
2194   @tab Volta brackets
2195 @item @code{TextScript}
2196   @tab @code{450}
2197   @tab Markup text
2198 @item @code{MultiMeasureRestText}
2199   @tab @code{450}
2200   @tab Markup text over full-bar rests
2201 @item @code{OttavaBracket}
2202   @tab @code{400}
2203   @tab Ottava brackets
2204 @item @code{TextSpanner}
2205   @tab @code{350}
2206   @tab Text spanners
2207 @item @code{DynamicLineSpanner}
2208   @tab @code{250}
2209   @tab All dynamic markings
2210 @item @code{BarNumber}
2211   @tab @code{ 100}
2212   @tab Bar numbers
2213 @item @code{TrillSpanner}
2214   @tab @code{50}
2215   @tab Spanning trills
2216 @end multitable
2217
2218 Here is an example showing the default placement of some of
2219 these.
2220
2221 @cindex text spanner
2222 @cindex ottava bracket
2223
2224 @funindex \startTextSpan
2225 @funindex startTextSpan
2226 @funindex \stopTextSpan
2227 @funindex stopTextSpan
2228
2229 @cindex TextSpanner, example of overriding
2230 @cindex bound-details property, example
2231
2232 @lilypond[quote,fragment,ragged-right,verbatim]
2233 % Set details for later Text Spanner
2234 \override TextSpanner.bound-details.left.text
2235     = \markup { \small \bold Slower }
2236 % Place dynamics above staff
2237 \dynamicUp
2238 % Start Ottava Bracket
2239 \ottava #1
2240 c''4 \startTextSpan
2241 % Add Dynamic Text and hairpin
2242 c''4\pp\<
2243 c''4
2244 % Add Text Script
2245 c''4^Text |
2246 c''4 c''
2247 % Add Dynamic Text and terminate hairpin
2248 c''4\ff c'' \stopTextSpan |
2249 % Stop Ottava Bracket
2250 \ottava #0
2251 c'4 c' c' c' |
2252 @end lilypond
2253
2254 This example also shows how to create Text Spanners --
2255 text with extender lines above a section of music.  The
2256 spanner extends from the @code{\startTextSpan} command to
2257 the @code{\stopTextSpan} command, and the format of the
2258 text is defined by the @code{\override TextSpanner} command.
2259 For more details see @ruser{Text spanners}.
2260
2261 It also shows how ottava brackets are created.
2262
2263 @cindex tweaking bar number placement
2264 @cindex bar numbers, tweaking placement
2265 @cindex tweaking metronome mark placement
2266 @cindex metronome mark, tweaking placement
2267 @cindex tweaking rehearsal mark placement
2268 @cindex rehearsal marks, tweaking placement
2269
2270 If the default values of @code{outside-staff-priority} do not give you
2271 the placing you want, the priority of any of the objects may be
2272 overridden.  Suppose we would like the ottava bracket to be placed
2273 below the text spanner in the example above.  All we need to do is to
2274 look up the priority of @code{OttavaBracket} in the IR or in the
2275 tables above, and reduce it to a value lower than that of a
2276 @code{TextSpanner}, remembering that @code{OttavaBracket} is created
2277 in the @code{Staff} context:
2278
2279 @cindex TextSpanner, example of overriding
2280 @cindex bound-details property, example
2281
2282 @lilypond[quote,fragment,ragged-right,verbatim]
2283 % Set details for later Text Spanner
2284 \override TextSpanner.bound-details.left.text
2285     = \markup { \small \bold Slower }
2286 % Place dynamics above staff
2287 \dynamicUp
2288 % Place following Ottava Bracket below Text Spanners
2289 \once \override Staff.OttavaBracket.outside-staff-priority = #340
2290 % Start Ottava Bracket
2291 \ottava #1
2292 c''4 \startTextSpan
2293 % Add Dynamic Text
2294 c''4\pp
2295 % Add Dynamic Line Spanner
2296 c''4\<
2297 % Add Text Script
2298 c''4^Text |
2299 c''4 c''
2300 % Add Dynamic Text
2301 c''4\ff c'' \stopTextSpan |
2302 % Stop Ottava Bracket
2303 \ottava #0
2304 c'4 c' c' c' |
2305 @end lilypond
2306
2307 Note that some of these objects, in particular bar numbers,
2308 metronome marks and rehearsal marks, live by default in the
2309 @code{Score} context, so be sure to use the correct context
2310 when these are being overriden.
2311
2312 @cindex slurs and outside-staff-priority
2313 @cindex slurs and articulations
2314 @cindex articulations and slurs
2315
2316 Slurs by default are classed as within-staff objects, but
2317 they often appear above the staff if the notes to
2318 which they are attached are high on the staff.  This can push
2319 outside-staff objects such as articulations too high, as the slur
2320 will be placed first.  The @code{avoid-slur} property of the
2321 articulation can be set to @code{'inside} to bring the articulation
2322 inside the slur, but the @code{avoid-slur} property is effective
2323 only if the @code{outside-staff-priority} is also set to @code{#f}.
2324 Alternatively, the @code{outside-staff-priority} of the slur
2325 can be set to a numerical value to cause it to be placed along with
2326 other outside-staff objects according to that value.  Here's an
2327 example showing the effect of the two methods:
2328
2329 @lilypond[quote,verbatim]
2330 \relative c'' {
2331   c4( c^\markup { \tiny \sharp } d4.) c8 |
2332   c4(
2333     \once \override TextScript.avoid-slur = #'inside
2334     \once \override TextScript.outside-staff-priority = ##f
2335     c4^\markup { \tiny \sharp } d4.) c8 |
2336   \once \override Slur.outside-staff-priority = #500
2337     c4( c^\markup { \tiny \sharp } d4.) c8 |
2338 }
2339 @end lilypond
2340
2341 Changing the @code{outside-staff-priority} can also be used to
2342 control the vertical placement of individual objects, although
2343 the results may not always be desirable.  Suppose we would
2344 like @qq{Text3} to be placed above @qq{Text4} in the example
2345 under Automatic behavior, above (see @ref{Automatic behavior}).
2346 All we need to do is to look up the priority of @code{TextScript}
2347 in the IR or in the tables above, and increase the priority of
2348 @qq{Text3} to a higher value:
2349
2350 @cindex TextScript, example of overriding
2351 @cindex outside-staff-priority property, example
2352
2353 @lilypond[quote,fragment,ragged-right,verbatim]
2354 c''2^"Text1"
2355 c''2^"Text2" |
2356 \once \override TextScript.outside-staff-priority = #500
2357 c''2^"Text3"
2358 c''2^"Text4" |
2359 @end lilypond
2360
2361 This certainly lifts @qq{Text3} above @qq{Text4} but it also lifts it
2362 above @qq{Text2}, and @qq{Text4} now drops down.  Perhaps this is not
2363 so good.  What we would really like to do is to position all the
2364 annotation at the same distance above the staff.  To do this, we
2365 clearly will need to space the notes out horizontally to make more
2366 room for the text.  This is done using the @code{textLengthOn}
2367 command.
2368
2369 @node The textLengthOn command
2370 @unnumberedsubsubsec The @code{@bs{}textLengthOn} command
2371
2372 @cindex notes, spreading out with text
2373
2374 @funindex \textLengthOn
2375 @funindex textLengthOn
2376 @funindex \textLengthOff
2377 @funindex textLengthOff
2378
2379 By default, text produced by markup takes up no horizontal space
2380 as far as laying out the music is concerned.  The @code{\textLengthOn}
2381 command reverses this behavior, causing the notes to be spaced
2382 out as far as is necessary to accommodate the text:
2383
2384 @lilypond[quote,fragment,ragged-right,verbatim]
2385 \textLengthOn  % Cause notes to space out to accommodate text
2386 c''2^"Text1"
2387 c''2^"Text2" |
2388 c''2^"Text3"
2389 c''2^"Text4" |
2390 @end lilypond
2391
2392 The command to revert to the default behavior is
2393 @code{\textLengthOff}.  Alternatively, @code{\once} may be used
2394 with @code{\textLengthOn} if the effect is to be limited to just a
2395 single musical moment.
2396 The corresponding spacing behavior for rehearsal marks and tempo
2397 indications is independently controlled with the commands
2398 @code{\markLengthOn} and @code{\markLengthOff}.
2399
2400 @cindex markup text, allowing collisions
2401
2402 Markup text will also avoid notes which project above the staff.
2403 If this is not desired, the automatic displacement upwards may
2404 be turned off by setting the priority to @code{#f}.  Here's an
2405 example to show how markup text interacts with such notes.
2406
2407 @cindex TextScript, example of overriding
2408 @cindex outside-staff-priority property, example
2409
2410 @lilypond[quote,ragged-right,verbatim]
2411 \relative {
2412   % This markup is short enough to fit without collision
2413   c''2^"Tex" c'' |
2414   R1 |
2415
2416   % This is too long to fit, so it is displaced upwards
2417   c,,2^"Text" c'' |
2418   R1 |
2419
2420   % Turn off collision avoidance
2421   \once \override TextScript.outside-staff-priority = ##f
2422   c,,2^"Long Text   " c'' |
2423   R1 |
2424
2425   % Turn off collision avoidance
2426   \once \override TextScript.outside-staff-priority = ##f
2427   \textLengthOn        % and turn on textLengthOn
2428   c,,2^"Long Text   "  % Spaces at end are honored
2429   c''2 |
2430 }
2431 @end lilypond
2432
2433 @node Dynamics placement
2434 @unnumberedsubsubsec Dynamics placement
2435
2436 @cindex tweaking dynamics placement
2437 @cindex dynamics, tweaking placement
2438
2439 Dynamic markings will normally be positioned beneath the
2440 staff, but may be positioned above with the @code{\dynamicUp}
2441 command.  They will be positioned vertically relative to the
2442 note to which they are attached, and will float below (or above)
2443 all within-staff objects such as phrasing slurs and bar numbers.
2444 This can give quite acceptable results, as this example
2445 shows:
2446
2447 @lilypond[quote,ragged-right,verbatim]
2448 \relative {
2449   \clef "bass"
2450   \key aes \major
2451   \time 9/8
2452   \dynamicUp
2453   bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
2454   ees,2.~\)\mf ees4 r8 |
2455 }
2456 @end lilypond
2457
2458 However, if the notes and attached dynamics are close
2459 together the automatic placement will avoid collisions
2460 by displacing later dynamic markings further away, but this may
2461 not be the optimum placement, as this rather artificial example
2462 shows:
2463
2464 @lilypond[quote,ragged-right,verbatim,fragment]
2465 \dynamicUp
2466 \relative { a'4\f b\mf a\mp b\p }
2467 @end lilypond
2468
2469 @noindent
2470 Should a similar situation arise in @q{real} music, it may be
2471 preferable to space out the notes a little further, so the dynamic
2472 markings can all fit at the same vertical distance from the staff.  We
2473 were able to do this for markup text by using the @code{\textLengthOn}
2474 command, but there is no equivalent command for dynamic marks.  So we
2475 shall have to work out how to do this using @code{\override} commands.
2476
2477 @node Grob sizing
2478 @unnumberedsubsubsec Grob sizing
2479
2480 @cindex grob sizing
2481 @cindex sizing grobs
2482
2483 First we must learn how grobs are sized.  All grobs have a
2484 reference point defined within them which is used to position
2485 them relative to their parent object.  This point in the grob
2486 is then positioned at a horizontal distance, @code{X-offset},
2487 and at a vertical distance, @code{Y-offset}, from its parent.
2488 The horizontal extent of the object is given by a pair of
2489 numbers, @code{X-extent}, which say where the left and right
2490 edges are relative to the reference point.  The vertical extent
2491 is similarly defined by a pair of numbers, @code{Y-extent}.
2492 These are properties of all grobs which support the
2493 @code{grob-interface}.
2494
2495 @cindex @code{extra-spacing-width}
2496
2497 By default, outside-staff objects are given a width of zero so
2498 that they may overlap in the horizontal direction.  This is done
2499 by the trick of making the leftmost extent infinity and
2500 the rightmost extent minus infinity by setting the
2501 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}.  To
2502 ensure they do not overlap in the horizontal direction we
2503 must override this value of @code{extra-spacing-width} to give them
2504 a little extra spacing.  The units are the space between two staff
2505 lines, so moving the left edge half a unit to the left and the
2506 right edge half a unit to the right should do it:
2507
2508 @example
2509 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2510 @end example
2511
2512 @noindent
2513 Let's see if this works in our previous example:
2514
2515 @cindex DynamicText, example of overriding
2516 @cindex extra-spacing-width property, example
2517
2518
2519 @lilypond[quote,ragged-right,verbatim,fragment]
2520 \dynamicUp
2521 % Extend width by 1 staff space
2522 \override DynamicText.extra-spacing-width = #'(-0.5 . 0.5)
2523 \relative { a'4\f b\mf a\mp b\p }
2524 @end lilypond
2525
2526 @noindent
2527 This looks better, but maybe we would prefer the dynamic marks
2528 to be aligned along the same baseline rather than going up and
2529 down with the notes.  The property to do this is
2530 @code{staff-padding} which is covered in the section on collisions
2531 (see @ref{Collisions of objects}).
2532
2533
2534 @node Vertical spacing
2535 @section Vertical spacing
2536
2537 As a rule, LilyPond's vertical spacing of musical objects is pretty
2538 good.  Let's see how it does with a simple song, with 2 voices and
2539 piano accompaniment:
2540
2541 @lilypond[quote,fragment,ragged-right]
2542 <<
2543   \new ChoirStaff
2544   <<
2545     \new Staff {
2546       \new Voice = "music" {
2547         b'2 c' c' c'
2548       }
2549     }
2550     \new Lyrics
2551     \lyricsto "music" {
2552       Here are some lyrics
2553     }
2554     \new Staff {
2555       \clef bass e'2 f e c
2556     }
2557   >>
2558   \new PianoStaff
2559   <<
2560     \new Staff {
2561       g''2 c'' c'' a''
2562     }
2563     \new Staff {
2564       \clef bass e2 f c e
2565     }
2566   >>
2567 >>
2568 @end lilypond
2569
2570 There's nothing wrong with the default vertical spacing.  However, let's
2571 assume that you're working with a publisher with some specific
2572 requirements for vertical spacing of staves and lyrics: they want
2573 the lyrics spaced away from any notes, they want the piano
2574 accompaniment spaced away from the vocal line and they want the two
2575 piano staves pushed together tightly.  Let's start with the lyrics.
2576
2577 Lyrics sit within a system, and therefore the commands to space them
2578 are found in @ruser{Flexible vertical spacing within systems}.  It
2579 tells us that lyrics are @code{non-staff lines} and therefore the
2580 command to change their spacing will refer to the @code{nonstaff}
2581 property.  Spacing them away from the staff to which they relate
2582 (the top line) will use the @code{relatedstaff} property.  Spacing
2583 them from the lower line will use the @code{unrelatedstaff} property.
2584 The vocal parts are part of a @code{VerticalAxisGroup}, so we need to
2585 adjust its properties.  Let's try it and see if it works.
2586
2587 @lilypond[quote,fragment,ragged-right,verbatim]
2588 <<
2589   \new ChoirStaff
2590   <<
2591     \new Staff {
2592       \new Voice = "music" {
2593         b'2 c' c' c'
2594       }
2595     }
2596     \new Lyrics \with {
2597       \override VerticalAxisGroup.
2598         nonstaff-relatedstaff-spacing.padding = #5
2599       \override VerticalAxisGroup.
2600         nonstaff-unrelatedstaff-spacing.padding = #5
2601     }
2602     \lyricsto "music" {
2603       Here are some lyrics
2604     }
2605     \new Staff {
2606       \clef bass e'2 f e c
2607     }
2608   >>
2609   \new PianoStaff
2610   <<
2611     \new Staff {
2612       g''2 c'' c'' a''
2613     }
2614     \new Staff {
2615       \clef bass e2 f c e
2616     }
2617   >>
2618 >>
2619 @end lilypond
2620
2621 Well - yes it does, but perhaps too well.  When we set the
2622 @code{padding} to 5, LilyPond adds 5 staff spaces to the distance
2623 between objects, which is too much for us here.  We'll use 2.
2624
2625 Next, let's move the piano music away from the vocal parts.  The
2626 vocal music is a @code{ChoirStaff}, so we need to increase the
2627 spacing between that group of staves and the piano staff below.
2628 We'll do this by changing the @code{basic-distance} of the
2629 @code{StaffGrouper}'s @code{staffgroup-staff-spacing}.
2630
2631 @lilypond[quote,fragment,ragged-right,verbatim]
2632 <<
2633   \new ChoirStaff \with {
2634     \override StaffGrouper.
2635       staffgroup-staff-spacing.basic-distance = #15
2636   }
2637   <<
2638     \new Staff {
2639       \new Voice = "music" {
2640         b'2 c' c' c'
2641       }
2642     }
2643     \new Lyrics \with {
2644       \override VerticalAxisGroup.
2645         nonstaff-relatedstaff-spacing.padding = #2
2646       \override VerticalAxisGroup.
2647         nonstaff-unrelatedstaff-spacing.padding = #2
2648     }
2649     \lyricsto "music" {
2650       Here are some lyrics
2651     }
2652     \new Staff {
2653       \clef bass e'2 f e c
2654     }
2655   >>
2656   \new PianoStaff
2657   <<
2658     \new Staff {
2659       g''2 c'' c'' a''
2660     }
2661     \new Staff {
2662       \clef bass e2 f c e
2663     }
2664   >>
2665 >>
2666 @end lilypond
2667
2668 Excellent.  Now just for the last requirement to make the piano staves
2669 closer together.  To do this, we again alter the properties of the
2670 @code{StaffGrouper}, but this time we're going to reduce both
2671 the @code{basic-distance} and the @code{padding}.  We can do this
2672 as shown below.
2673
2674 @lilypond[quote,fragment,ragged-right,verbatim]
2675 <<
2676   \new ChoirStaff \with {
2677     \override StaffGrouper.
2678       staffgroup-staff-spacing.basic-distance = #15
2679   }
2680   <<
2681     \new Staff {
2682       \new Voice = "music" {
2683         b'2 c' c' c'
2684       }
2685     }
2686     \new Lyrics \with {
2687       \override VerticalAxisGroup.
2688         nonstaff-relatedstaff-spacing.padding = #2
2689       \override VerticalAxisGroup.
2690         nonstaff-unrelatedstaff-spacing.padding = #2
2691     }
2692     \lyricsto "music" {
2693       Here are some lyrics
2694     }
2695     \new Staff {
2696       \clef bass e'2 f e c
2697     }
2698   >>
2699   \new PianoStaff \with {
2700     \override StaffGrouper.staff-staff-spacing = #'(
2701                             (basic-distance . 0)
2702                             (padding . 0))
2703   }
2704   <<
2705     \new Staff {
2706       g''2 c'' c'' a''
2707     }
2708     \new Staff {
2709       \clef bass e2 f c e
2710     }
2711   >>
2712 >>
2713 @end lilypond
2714
2715 That's put them really close together -- but it's what
2716 the publisher wanted.  They could be moved further
2717 apart by altering the @code{padding} or @code{basic-distance}
2718 if wanted.
2719
2720 There are many ways of altering vertical spacing.  A key point
2721 to remember is that the spacing between objects in a
2722 @code{StaffGroup} (like @code{GrandStaff} or
2723 @code{PianoStaff} groups) is controlled by the spacing variables
2724 of the @code{StaffGrouper}. Spacing from ungrouped staves
2725 (like @code{Lyrics} and @code{Staff}) is controlled by the
2726 variables of the @code{VerticalAxisGroup}.  See the
2727 @ruser{Flexible vertical spacing paper variables} and
2728 @ruser{Flexible vertical spacing within systems} for more
2729 details.
2730
2731 @node Collisions of objects
2732 @section Collisions of objects
2733
2734 @menu
2735 * Moving objects::
2736 * Fixing overlapping notation::
2737 * Real music example::
2738 @end menu
2739
2740 @node Moving objects
2741 @subsection Moving objects
2742
2743 @cindex moving overlapping objects
2744 @cindex moving colliding objects
2745 @cindex moving colliding grobs
2746 @cindex objects, moving colliding
2747 @cindex grobs, moving colliding
2748
2749 This may come as a surprise, but LilyPond is not perfect.  Some
2750 notation elements can overlap.  This is unfortunate, but in fact
2751 rather rare.  Usually the need to move objects is for clarity or
2752 aesthetic reasons -- they would look better with a little more
2753 or a little less space around them.
2754
2755 There are three main approaches to resolving overlapping
2756 notation.  They should be considered in the following order:
2757
2758 @enumerate
2759 @item
2760 The @strong{direction} of one of the overlapping objects may
2761 be changed using the predefined commands listed above for
2762 within-staff objects (see @ref{Within-staff objects}).
2763 Stems, slurs, beams, ties, dynamics, text and tuplets may be
2764 repositioned easily in this way.  The limitation is that you
2765 have a choice of only two positions, and neither may be
2766 suitable.
2767
2768 @item
2769 The @strong{object properties}, which LilyPond uses when positioning
2770 layout objects, may be modified using @code{\override}.  The
2771 advantages of making changes to this type of property are (a) that
2772 some other objects will be moved automatically if necessary to make
2773 room and (b) the single override can apply to all instances of the
2774 same type of object.  Such properties include:
2775
2776 @itemize
2777
2778 @item
2779 @code{direction}
2780
2781 This has already been covered in some detail -- see
2782 @ref{Within-staff objects}.
2783
2784 @item
2785 @code{padding}, @code{right-padding}, @code{staff-padding}
2786
2787 @cindex padding
2788 @cindex padding property
2789 @cindex right-padding property
2790 @cindex staff-padding property
2791
2792 As an object is being positioned the value of its @code{padding}
2793 property specifies the gap that must be left between itself and the
2794 nearest edge of the object against which it is being positioned.  Note
2795 that it is the @code{padding} value of the object @strong{being
2796 placed} that is used; the @code{padding} value of the object which is
2797 already placed is ignored.  Gaps specified by @code{padding} can be
2798 applied to all objects which support the
2799 @code{side-position-interface}.
2800
2801 Instead of @code{padding}, the placement of groups of accidentals
2802 is controlled by @code{right-padding}.  This property is to be found
2803 in the @code{AccidentalPlacement} object which, note, lives in the
2804 @strong{Staff} context.  In the typesetting process the note heads
2805 are typeset first and then the accidentals, if any, are added to the
2806 left of the note heads using the @code{right-padding} property to determine
2807 the separation from the note heads and between individual accidentals.
2808 So only the @code{right-padding} property of the @code{AccidentalPlacement}
2809 object has any effect on the placement of the accidentals.
2810
2811 The @code{staff-padding} property is closely related to the
2812 @code{padding} property: @code{padding} controls the minimum amount of
2813 space between any object which supports the
2814 @code{side-position-interface} and the nearest other object (generally
2815 the note or the staff lines); @code{staff-padding} applies only to
2816 those objects which are always set outside the staff -- it controls
2817 the minimum distance from the staff to the outside-staff object.
2818 Note that @code{staff-padding} has no effect on
2819 objects that are positioned relative to the note rather than the
2820 staff, even though it may be overridden without error for such objects
2821 -- it is simply ignored.
2822
2823 To discover which padding property is required for the object you wish
2824 to reposition, you need to return to the IR and look up the object's
2825 properties.  Be aware that the padding properties might not be located
2826 in the obvious object, so look in objects that appear to be related.
2827
2828 All padding values are measured in staff spaces.  For most
2829 objects, this value is set by default to be around 1.0 or less
2830 (it varies with each object).  It may be overridden if a larger
2831 (or smaller) gap is required.
2832
2833 @item
2834 @code{self-alignment-X}
2835
2836 @cindex self-alignment-X property
2837
2838 This property can be used to align the object to the left, to
2839 the right, or to center it with respect to the parent object's
2840 reference point.  It may be used with all objects which support
2841 the @code{self-alignment-interface}.  In general these are objects
2842 that contain text.  The values are @code{LEFT}, @code{RIGHT}
2843 or @code{CENTER}.  Alternatively, a numerical value between
2844 @w{@code{-1}} and @code{+1} may be specified, where @w{@code{-1}} is
2845 left-aligned, @code{+1} is right-aligned, and numbers in between
2846 move the text progressively from left-aligned to right-aligned.
2847 Numerical values greater than @code{1} may be specified to move
2848 the text even further to the left, or less than @w{@code{-1}} to
2849 move the text even further to the right.  A change of @code{1}
2850 in the value corresponds to a movement of half the text's length.
2851
2852 @item
2853 @code{extra-spacing-width}
2854
2855 @cindex extra-spacing-width property
2856
2857 This property is available for all objects which support the
2858 @code{item-interface}.  It takes two numbers, the first is added
2859 to the leftmost extent and the second is added to the rightmost
2860 extent.  Negative numbers move the edge to the left, positive to
2861 the right, so to widen an object the first number must be negative,
2862 the second positive.  Note that not all objects honor both
2863 numbers.  For example, the @code{Accidental} object only takes
2864 notice of the first (left edge) number.
2865
2866 @item
2867 @code{staff-position}
2868
2869 @cindex staff-position property
2870
2871 @code{staff-position} is a property of the
2872 @code{staff-symbol-referencer-interface}, which is supported by
2873 objects which are positioned relative to the staff.  It specifies
2874 the vertical position of the object relative to the center line
2875 of the staff in half staff-spaces.  It is useful in resolving
2876 collisions between layout objects like multi-measure rests, ties
2877 and notes in different voices.
2878
2879 @item
2880 @code{horizontal-shift}
2881
2882 @cindex horizontal-shift property
2883 @cindex note column
2884 @cindex note collisions
2885 @cindex collisions, notes
2886 @cindex shift commands
2887 @funindex \shiftOff
2888 @funindex shiftOff
2889 @funindex \shiftOn
2890 @funindex shiftOn
2891 @funindex \shiftOnn
2892 @funindex shiftOnn
2893 @funindex \shiftOnnn
2894 @funindex shiftOnnn
2895
2896 Within a voice, all the notes occuring at the same musical moment are
2897 grouped into a note column, and a @code{NoteColumn} object is created
2898 to control the horizontal positioning of that group of notes (see
2899 @qq{Note columns} in @ref{Explicitly instantiating voices}).  If
2900 @emph{and only if} two or more note columns within a single Staff
2901 context, both with stems in the same direction, occur at the same
2902 musical moment, the values of their @code{horizontal-shift} properties
2903 are used to rank them and the columns in the higher ranks are
2904 progessively offset to avoid collisions of the noteheads.  This
2905 property is set by the @code{\voiceXXX} commands and may be overridden
2906 directly with an @code{\override} command or, more usually, by the
2907 @code{\shiftOn} commands.  Note that this property is used to
2908 @emph{rank} the note columns for off-setting - it does not specify the
2909 magnitude of the offset, which is progressively increased in steps
2910 based on the note head's width for each rank.  The steps are usually
2911 of half a note head's width, but may be a full note head's width when
2912 a closely spaced group of notes is involved.
2913
2914 @item
2915 @code{force-hshift}
2916
2917 @cindex force-hshift property
2918
2919 The @code{force-hshift} property is a property of a @code{NoteColumn}
2920 (actually of the @code{note-column-interface}).  Changing it permits a
2921 note column to be moved in situations where the note columns overlap.
2922 Note that it has no effect on note columns that do not overlap.
2923 It is specified in units appropriate to a note column, viz. the note
2924 head width of the first voice note.  It should be used in complex
2925 situations where the normal @code{\shiftOn} commands (see
2926 @ref{Explicitly instantiating voices}) do not resolve the note
2927 conflict satisfactorily.  It is preferable to the @code{extra-offset}
2928 property for this purpose as there is no need to work out the distance
2929 in staff-spaces, and moving the notes into or out of a
2930 @code{NoteColumn} affects other actions such as merging note heads.
2931
2932 @end itemize
2933
2934 @item
2935 Finally, when all else fails, objects may be manually repositioned
2936 relative to the staff center line vertically, or by displacing them by
2937 any distance to a new position.  The disadvantages are that the
2938 correct values for the repositioning have to be worked out, often by
2939 trial and error, for every object individually, and, because the
2940 movement is done after LilyPond has placed all other objects, the user
2941 is responsible for avoiding any collisions that might ensue.  But the
2942 main difficulty with this approach is that the repositioning values
2943 may need to be reworked if the music is later modified.  The
2944 properties that can be used for this type of manual repositioning are:
2945
2946 @table @code
2947 @item extra-offset
2948
2949 @cindex extra-offset property
2950
2951 This property applies to any layout object supporting the
2952 @code{grob-interface}.  It takes a pair of numbers which specify the
2953 extra displacement in the horizontal and vertical directions.
2954 Negative numbers move the object to the left or down.  The units are
2955 staff-spaces.  The extra displacement is made after the typesetting of
2956 objects is finished, so an object may be repositioned anywhere without
2957 affecting anything else.
2958
2959 @item positions
2960
2961 @cindex positions property
2962
2963 This is most useful for manually adjusting the slope and height
2964 of beams, slurs, and tuplets.  It takes a pair of numbers
2965 giving the position of the left and right ends of the beam, slur,
2966 etc. relative to the center line of the staff.  Units are
2967 staff-spaces.  Note, though, that slurs and phrasing slurs cannot
2968 be repositioned by arbitrarily large amounts.  LilyPond first
2969 generates a list of possible positions for the slur and by default
2970 finds the slur that @qq{looks best}.  If the @code{positions}
2971 property has been overridden the slur that is closest to the
2972 requested positions is selected from the list.
2973 @end table
2974
2975 @end enumerate
2976
2977 A particular object may not have all of these properties.
2978 It is necessary to go to the IR to look up which properties
2979 are available for the object in question.
2980
2981 Here is a list of the objects which are most likely to be
2982 involved in collisions, together with the name of the object which
2983 should be looked up in the IR in order to discover which properties
2984 should be used to move them.
2985
2986 @multitable @columnfractions .5 .5
2987 @headitem Object type           @tab Object name
2988 @item Articulations             @tab @code{Script}
2989 @item Beams                     @tab @code{Beam}
2990 @item Dynamics (vertically)     @tab @code{DynamicLineSpanner}
2991 @item Dynamics (horizontally)   @tab @code{DynamicText}
2992 @item Fingerings                @tab @code{Fingering}
2993 @item Rehearsal / Text marks    @tab @code{RehearsalMark}
2994 @item Slurs                     @tab @code{Slur}
2995 @item Text e.g. @code{^"text"}  @tab @code{TextScript}
2996 @item Ties                      @tab @code{Tie}
2997 @item Tuplets                   @tab @code{TupletBracket}
2998 @end multitable
2999
3000
3001 @node Fixing overlapping notation
3002 @subsection Fixing overlapping notation
3003
3004 Let's now see how the properties in the previous section can
3005 help to resolve overlapping notation.
3006
3007 @menu
3008 * The padding property::
3009 * The right-padding property::
3010 * The staff-padding property::
3011 * The self-alignment-X property::
3012 * The staff-position property::
3013 * The extra-offset property::
3014 * The positions property::
3015 * The force-hshift property::
3016 @end menu
3017
3018 @node The padding property
3019 @unnumberedsubsubsec The @code{padding} property
3020
3021 @cindex padding
3022 @cindex fixing overlapping notation
3023 @cindex overlapping notation
3024
3025 The @code{padding} property can be set to increase
3026 (or decrease) the distance between symbols that are printed
3027 above or below notes.
3028
3029 @cindex Script, example of overriding
3030 @cindex padding property, example
3031
3032 @lilypond[quote,fragment,verbatim]
3033 c'2\fermata
3034 \override Script.padding = #3
3035 b2\fermata
3036 @end lilypond
3037
3038 @cindex MetronomeMark, example of overriding
3039 @cindex padding property, example
3040
3041 @lilypond[quote,fragment,verbatim]
3042 % This will not work, see below
3043 \override MetronomeMark.padding = #3
3044 \tempo 4 = 120
3045 c'1 |
3046 % This works
3047 \override Score.MetronomeMark.padding = #3
3048 \tempo 4 = 80
3049 d'1 |
3050 @end lilypond
3051
3052 Note in the second example how important it is to figure out what
3053 context handles a certain object.  Since the @code{MetronomeMark}
3054 object is handled in the @code{Score} context, property changes in the
3055 @code{Voice} context will not be noticed.  For more details, see
3056 @ruser{Modifying properties}.
3057
3058 If the @code{padding} property of an object is increased when that
3059 object is in a stack of objects being positioned according to
3060 their @code{outside-staff-priority}, then that object and all
3061 objects outside it are moved.
3062
3063
3064 @node The right-padding property
3065 @unnumberedsubsubsec The @code{right-padding} property
3066
3067 @cindex right-padding property
3068
3069 The @code{right-padding} property affects the spacing between the
3070 accidental and the note to which it applies.  It is not often
3071 required, but the default spacing may be wrong for certain special
3072 accidental glyphs or combination of glyphs used in some microtonal
3073 music.  These have to be entered by overriding the accidental
3074 stencil with a markup containing the desired symbol(s), like this:
3075
3076 @cindex Accidental, example of overriding
3077 @cindex text property, example
3078 @cindex stencil property, example
3079 @cindex AccidentalPlacement, example of overriding
3080 @cindex right-padding property, example
3081
3082 @lilypond[quote,ragged-right,verbatim]
3083 sesquisharp = \markup { \sesquisharp }
3084 \relative {
3085   c''4
3086   % This prints a sesquisharp but the spacing is too small
3087   \once \override Accidental.stencil = #ly:text-interface::print
3088   \once \override Accidental.text = #sesquisharp
3089   cis4 c
3090   % This improves the spacing
3091   \once \override Score.AccidentalPlacement.right-padding = #0.6
3092   \once \override Accidental.stencil = #ly:text-interface::print
3093   \once \override Accidental.text = #sesquisharp
3094   cis4 |
3095 }
3096 @end lilypond
3097
3098 @noindent
3099 This necessarily uses an override for the accidental stencil which
3100 will not be covered until later.  The stencil type must be a
3101 procedure, here changed to print the contents of the @code{text}
3102 property of @code{Accidental}, which itself is set to be a
3103 sesquisharp sign.  This sign is then moved further away from the
3104 note head by overriding @code{right-padding}.
3105
3106 @noindent
3107
3108 @node The staff-padding property
3109 @unnumberedsubsubsec The @code{staff-padding} property
3110
3111 @cindex aligning objects on a baseline
3112 @cindex objects, aligning on a baseline
3113
3114 @code{staff-padding} can be used to align objects such as dynamics
3115 along a baseline at a fixed distance from the staff, when no other
3116 notation forces them further from the staff.
3117 It is not a property of @code{DynamicText} but of
3118 @code{DynamicLineSpanner}.  This is because the baseline should apply
3119 equally to @strong{all} dynamics, including those created as extended
3120 spanners.  So this is the way to align the dynamic marks in the
3121 example taken from the previous section:
3122
3123 @cindex DynamicText, example of overriding
3124 @cindex extra-spacing-width property, example
3125 @cindex DynamicLineSpanner, example of overriding
3126 @cindex staff-padding property, example
3127
3128 @lilypond[quote,fragment,ragged-right,verbatim]
3129 \override DynamicLineSpanner.staff-padding = #3
3130 \relative { a'4\f b\mf a\p b\mp }
3131 @end lilypond
3132
3133
3134 @node The self-alignment-X property
3135 @unnumberedsubsubsec The @code{self-alignment-X} property
3136
3137 The following example shows how to adjust the position
3138 of a string fingering object relative to a note's stem by aligning the
3139 right edge with the reference point of the parent note:
3140
3141 @cindex StringNumber, example of overriding
3142 @cindex self-alignment-X property, example
3143
3144 @lilypond[quote,fragment,ragged-right,verbatim]
3145 \voiceOne
3146 <a''\2>
3147 \once \override StringNumber.self-alignment-X = #RIGHT
3148 <a''\2>
3149 @end lilypond
3150
3151 @node The staff-position property
3152 @unnumberedsubsubsec The @code{staff-position} property
3153
3154 @cindex object collision within a staff
3155
3156 Multimeasure rests in one voice can collide with notes in another.
3157 Since these rests are typeset centered between the bar lines, it
3158 would require significant effort for LilyPond to figure out which
3159 other notes might collide with it, since all the current collision
3160 handling between notes and between notes and rests is done only
3161 for notes and rests that occur at the same time.  Here's an
3162 example of a collision of this type:
3163
3164 @lilypond[quote,verbatim,ragged-right]
3165 << \relative { c'4 c c c } \\ { R1 } >>
3166 @end lilypond
3167
3168 The best solution here is to move the multimeasure rest down, since the
3169 rest is in voice two. The default in @code{\voiceTwo} (i.e. in the
3170 second voice of a @code{<<@{@dots{}@} \\ @{@dots{}@}>>} construct) is
3171 that @code{staff-position} is set to -4 for MultiMeasureRest, so we need
3172 to move it, say, four half-staff spaces down to @w{@code{-8}}.
3173
3174 @cindex MultiMeasureRest, example of overriding
3175 @cindex staff-position property, example
3176
3177 @lilypond[quote,verbatim,ragged-right]
3178 <<
3179   \relative { c'4 c c c }
3180   \\
3181   \override MultiMeasureRest.staff-position = #-8
3182   { R1 }
3183 >>
3184 @end lilypond
3185
3186 This is better than using, for example, @code{extra-offset},
3187 because the ledger line above the rest is inserted automatically.
3188
3189 @node The extra-offset property
3190 @unnumberedsubsubsec The @code{extra-offset} property
3191
3192 @cindex positioning objects
3193 @cindex positioning grobs
3194 @cindex objects, positioning
3195 @cindex grobs, positioning
3196
3197 The @code{extra-offset} property provides complete control over the
3198 positioning of an object both horizontally and vertically.
3199
3200 In the following example, the second fingering is moved a little to
3201 the left, and 1.8 staff space downwards:
3202
3203 @cindex Fingering, example of overriding
3204 @cindex extra-offset property, example
3205
3206 @lilypond[quote,fragment,verbatim]
3207 f'4-5
3208 \once \override Fingering.extra-offset = #'(-0.3 . -1.8)
3209 f'4-5
3210 @end lilypond
3211
3212
3213 @node The positions property
3214 @unnumberedsubsubsec The @code{positions} property
3215
3216 @cindex controlling tuplets, slurs, phrasing slurs, and beams manually
3217 @cindex manually controlling tuplets, slurs, phrasing slurs, and beams
3218 @cindex tuplet beams, controlling manually
3219 @cindex slurs, controlling manually
3220 @cindex phrasing slurs, controlling manually
3221 @cindex beams, controlling manually
3222
3223 The @code{positions} property allows the vertical position and hence
3224 the slope of tuplets, slurs, phrasing slurs and beams to be controlled
3225 manually.
3226
3227 Here's an example in which the phrasing slur and slur collide:
3228
3229 @lilypond[quote,verbatim,ragged-right]
3230 \relative { a'8 \( ( a'16 ) a \) }
3231 @end lilypond
3232
3233 @cindex PhrasingSlur, example of overriding
3234 @cindex positions property, example
3235
3236 @noindent
3237 One possibility would be to move the two ends of the phrasing slur
3238 higher.  We can try setting the left end to 2.5 staff-spaces above the
3239 centre line and the right end to 4.5 above, and LilyPond will
3240 select the phrasing slur from the candidates it has found with its
3241 end points closest to these:
3242
3243 @lilypond[quote,verbatim,fragment,ragged-right]
3244 \once \override PhrasingSlur.positions = #'(2.5 . 4.5)
3245 a'8 \( ( a''16 ) a'' \)
3246 @end lilypond
3247
3248 This is an improvement, but why not lower the right end of the slur
3249 a little?  If you try it you'll find it can't be done in this way.
3250 That's because there are no candidate slurs lower than the one
3251 already selected, and in this case the @code{positions} property has
3252 no effect.  However, ties, slurs and phrasing slurs @emph{can} be
3253 positioned and shaped very precisely when necessary.  To learn how to
3254 do this, see @ruser{Modifying ties and slurs}.
3255
3256 Here's a further example.  We see that the beams
3257 collide with the ties:
3258
3259 @lilypond[quote,verbatim,ragged-right]
3260 {
3261   \time 4/2
3262   <<
3263     \relative { c'1~ 2. e8 f }
3264     \\
3265     \relative {
3266       e''8 e e e
3267       e e e e
3268       f2 g
3269     }
3270   >>
3271   <<
3272     \relative { c'1~ 2. e8 f }
3273     \\
3274     \relative {
3275       e''8 e e e
3276       e e e e
3277       f2 g
3278     }
3279   >>
3280 }
3281 @end lilypond
3282
3283 @noindent
3284 This can be resolved by manually moving both ends of the beam
3285 up from their position at 1.81 staff-spaces below the center line to,
3286 say, 1:
3287
3288 @cindex Beam, example of overriding
3289 @cindex positions property, example
3290
3291 @lilypond[quote,verbatim,ragged-right]
3292 {
3293   \time 4/2
3294   <<
3295     \relative { c'1~ 2. e8 f }
3296     \\
3297     \relative {
3298       \override Beam.positions = #'(-1 . -1)
3299       e''8 e e e
3300       e e e e
3301       f2 g
3302     }
3303   >>
3304   <<
3305     \relative { c'1~ 2. e8 f }
3306     \\
3307     \relative {
3308       e''8 e e e
3309       e e e e
3310       f2 g
3311       \revert Beam.positions
3312     }
3313   >>
3314 }
3315 @end lilypond
3316
3317 @noindent
3318 Note that the override continues to apply in the second voice of
3319 the second measure of eighth notes, but not to any of the beams in the
3320 first voice, even those in the later second measure.  As soon as the
3321 override should no longer apply it should be reverted, as shown.
3322
3323 @node The force-hshift property
3324 @unnumberedsubsubsec The @code{force-hshift} property
3325
3326 We can now see how to apply the final corrections to the Chopin
3327 example introduced at the end of @ref{I'm hearing Voices}, which
3328 was left looking like this:
3329
3330 @lilypond[quote,verbatim,fragment,ragged-right]
3331 \new Staff \relative {
3332   \key aes \major
3333   <<
3334     { c''2 aes4. bes8 }
3335     \\
3336     { <ees, c>2 des }
3337     \\
3338     \\
3339     { aes'2 f4 fes }
3340   >> |
3341   <c ees aes c>1 |
3342 }
3343 @end lilypond
3344
3345 @noindent
3346 The inner note of the first chord (i.e. the A-flat in the fourth
3347 Voice) need not be shifted away from the note column of the higher
3348 note, so we use @code{\shiftOff}.
3349
3350 In the second chord we prefer the F to line up with the A-flat and
3351 the lowest note to be positioned slightly right to avoid a collision
3352 of stems.  We achieve this by setting @code{force-hshift} in the
3353 @code{NoteColumn} of the low D-flat to move it to the right by half
3354 a staff-space, and setting @code{force-hshift} for the F to zero.
3355 Note that we use @code{\once} to avoid the settings propagating
3356 beyond the immediate musical moment, although in this small example
3357 the @code{\once} and the second @code{\override} in Voice four could
3358 be omitted.  This would not be good practice.
3359
3360 Here's the final result:
3361
3362 @cindex NoteColumn, example of overriding
3363 @cindex force-hshift property, example
3364
3365 @lilypond[quote,verbatim,fragment,ragged-right]
3366 \new Staff \relative {
3367   \key aes \major
3368   <<
3369     { c''2 aes4. bes8 }
3370     \\
3371     { <ees, c>2 \once \override NoteColumn.force-hshift = 0.5 des }
3372     \\
3373     \\
3374     { \once \shiftOff aes'2 \once \shiftOff f4 fes }
3375   >> |
3376   <c ees aes c>1 |
3377 }
3378 @end lilypond
3379
3380
3381 @node Real music example
3382 @subsection Real music example
3383
3384 We end this section on Tweaks by showing the steps to be taken to
3385 deal with a tricky example which needs several tweaks to produce
3386 the desired output.  The example has been deliberately chosen to
3387 illustrate the use of the Notation Reference to resolve unusual
3388 problems with notation.  It is not representative of the more usual
3389 engraving process, so please do not let these difficulties put
3390 you off!  Fortunately, difficulties like these are not very common!
3391
3392 The example is from Chopin's Première Ballade, Op. 23, bars 6 to
3393 9, the transition from the opening Lento to Moderato.
3394 Here, first, is what we want the output to look like, but to avoid
3395 over-complicating the example too much we have left out the
3396 dynamics, fingering and pedalling.
3397
3398 @c The following should appear as music without code
3399 @c This example should not be indexed
3400 @c line-width ensures no break
3401 @lilypond[quote,ragged-right,line-width=6\in]
3402 rhMusic = \relative {
3403   \new Voice {
3404     r2 c''4.\( g8 |
3405     \once \override Tie.staff-position = #3.5
3406     bes1~ |
3407     \bar "||"
3408     \time 6/4
3409     \mergeDifferentlyHeadedOn
3410     \mergeDifferentlyDottedOn
3411     bes2.\tempo "Moderato" r8
3412     <<
3413       { c,8 d fis bes a }
3414       \new Voice {
3415         \voiceTwo
3416         c,8~
3417         % Reposition the c2 to the right of the merged note
3418         \once \override NoteColumn.force-hshift = #1.0
3419         % Move the c2 out of the main note column
3420         % so the merge will work
3421         \shiftOnn
3422         c2
3423       }
3424       \new Voice {
3425         \voiceThree
3426         s8
3427         % Stem on the d2 must be down to permit merging
3428         \stemDown
3429         % Stem on the d2 should be invisible
3430         \tweak Stem.transparent ##t
3431         d2
3432       }
3433       \new Voice {
3434         \voiceFour
3435         s4 fis4.
3436       }
3437     >> |
3438     \mergeDifferentlyHeadedOff
3439     \mergeDifferentlyDottedOff
3440     g2.\)
3441   }
3442 }
3443
3444 lhMusic = \relative {
3445   r2 <c' g ees>2( |
3446   <d g, d>1)\arpeggio |
3447   r2. d,,4 r4 r |
3448   r4
3449 }
3450
3451 \score {
3452   \new PianoStaff <<
3453     \new Staff = "RH"  <<
3454       \key g \minor
3455       \rhMusic
3456     >>
3457     \new Staff = "LH" <<
3458       \key g \minor
3459       \clef "bass"
3460       \lhMusic
3461     >>
3462   >>
3463 }
3464 @end lilypond
3465
3466 We note first that the right hand part in the third bar
3467 requires four voices.  These are the five beamed eighth notes,
3468 the tied C, the half-note D which is merged with the eighth note
3469 D, and the dotted quarter note F-sharp, which is also merged with
3470 the eighth note at the same pitch.  Everything else is in a single
3471 voice, so the easiest way is to introduce these extra three voices
3472 temporarily at the time they are needed.  If you have forgotten
3473 how to do this, look at @ref{I'm hearing Voices} and @ref{Explicitly
3474 instantiating voices}.  Here we choose to use explicitly instantiated
3475 voices for the polyphonic passage, as LilyPond is better able to
3476 avoid collisions if all voices are instantiated explicitly in this
3477 way.
3478
3479 So let us begin by entering the notes as two variables, setting up
3480 the staff structure in a score block, and seeing what LilyPond
3481 produces by default:
3482
3483 @c line-width ensures no break
3484 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3485 rhMusic = \relative {
3486   \new Voice {
3487     r2 c''4. g8 |
3488     bes1~ |
3489     \time 6/4
3490     bes2. r8
3491     % Start polyphonic section of four voices
3492     <<
3493       { c,8 d fis bes a }  % continuation of main voice
3494       \new Voice {
3495         \voiceTwo
3496         c,8~ 2
3497       }
3498       \new Voice {
3499         \voiceThree
3500         s8 d2
3501       }
3502       \new Voice {
3503         \voiceFour
3504         s4 fis4.
3505       }
3506     >> |
3507     g2.  % continuation of main voice
3508   }
3509 }
3510
3511 lhMusic = \relative {
3512   r2 <c' g ees>2 |
3513   <d g, d>1 |
3514   r2. d,,4 r4 r |
3515   r4
3516 }
3517
3518 \score {
3519   \new PianoStaff <<
3520     \new Staff = "RH"  <<
3521       \key g \minor
3522       \rhMusic
3523     >>
3524     \new Staff = "LH" <<
3525       \key g \minor
3526       \clef "bass"
3527       \lhMusic
3528     >>
3529   >>
3530 }
3531 @end lilypond
3532
3533 All the notes are right, but the appearance is far from
3534 satisfactory.  The tie collides with the change in time signature,
3535 some notes are not merged together, and several notation elements
3536 are missing.  Let's first deal with the easier things.  We can
3537 easily add the left hand slur and the right hand phrasing slur,
3538 since these were all covered in the Tutorial.  Doing this gives:
3539
3540 @c line-width ensures no break
3541 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3542 rhMusic = \relative {
3543   \new Voice {
3544     r2 c''4.\( g8 |
3545     bes1~ |
3546     \time 6/4
3547     bes2. r8
3548     % Start polyphonic section of four voices
3549     <<
3550       { c,8 d fis bes a }  % continuation of main voice
3551       \new Voice {
3552         \voiceTwo
3553         c,8~ 2
3554       }
3555       \new Voice {
3556         \voiceThree
3557         s8 d2
3558       }
3559       \new Voice {
3560         \voiceFour
3561         s4 fis4.
3562       }
3563     >> |
3564     g2.\)  % continuation of main voice
3565   }
3566 }
3567
3568 lhMusic = \relative {
3569   r2 <c' g ees>2( |
3570   <d g, d>1) |
3571   r2. d,,4 r4 r |
3572   r4
3573 }
3574
3575 \score {
3576   \new PianoStaff <<
3577     \new Staff = "RH"  <<
3578       \key g \minor
3579       \rhMusic
3580     >>
3581     \new Staff = "LH" <<
3582       \key g \minor
3583       \clef "bass"
3584       \lhMusic
3585     >>
3586   >>
3587 }
3588 @end lilypond
3589
3590 The first bar is now correct.  The second bar contains an arpeggio and
3591 is terminated by a double bar line.  How do we do these, as they have
3592 not been mentioned in this Learning Manual?  This is where we need to
3593 turn to the Notation Reference.  Looking up @q{arpeggio} and @q{bar
3594 line} in the index quickly shows us that an arpeggio is produced by
3595 appending @code{\arpeggio} to a chord, and a double bar line is
3596 produced by the @code{\bar "||"} command.  That's easily done.  We
3597 next need to correct the collision of the tie with the time signature.
3598 This is best done by moving the tie upwards.  Moving objects was
3599 covered earlier in @ref{Moving objects}, which says that objects
3600 positioned relative to the staff can be moved vertically by overriding
3601 their @code{staff-position} property, which is specified in half staff
3602 spaces relative to the center line of the staff.  So the following
3603 override placed just before the first tied note would move the tie up
3604 to 3.5 half staff spaces above the center line:
3605
3606 @code{\once \override Tie.staff-position = #3.5}
3607
3608 This completes bar two, giving:
3609
3610 @c line-width ensures no break
3611 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3612 rhMusic = \relative {
3613   \new Voice {
3614     r2 c''4.\( g8 |
3615     \once \override Tie.staff-position = #3.5
3616     bes1~ |
3617     \bar "||"
3618     \time 6/4
3619     bes2. r8
3620     % Start polyphonic section of four voices
3621     <<
3622       { c,8 d fis bes a }  % continuation of main voice
3623       \new Voice {
3624         \voiceTwo
3625         c,8~ 2
3626       }
3627       \new Voice {
3628         \voiceThree
3629         s8 d2
3630       }
3631       \new Voice {
3632         \voiceFour
3633         s4 fis4.
3634       }
3635     >> |
3636     g2.\)  % continuation of main voice
3637   }
3638 }
3639
3640 lhMusic = \relative {
3641   r2 <c' g ees>2( |
3642   <d g, d>1)\arpeggio |
3643   r2. d,,4 r4 r |
3644   r4
3645 }
3646
3647 \score {
3648   \new PianoStaff <<
3649     \new Staff = "RH"  <<
3650       \key g \minor
3651       \rhMusic
3652     >>
3653     \new Staff = "LH" <<
3654       \key g \minor
3655       \clef "bass"
3656       \lhMusic
3657     >>
3658   >>
3659 }
3660 @end lilypond
3661
3662 On to bar three and the start of the Moderato section.  The tutorial
3663 showed how to add a tempo indication with the @code{\tempo} command, so
3664 adding @qq{Moderato} is easy.  But how do we merge notes in
3665 different voices together?  This is where we need to turn again to
3666 the Notation Reference for help.  A search for @qq{merge} in the
3667 Notation Reference index quickly leads us to the commands for merging
3668 differently headed and differently dotted notes in
3669 @ruser{Collision resolution}.  In our example we need to merge both
3670 types of note for the duration of the polyphonic section in bar 3,
3671 so using the information we find in the Notation Reference we add
3672
3673 @example
3674 \mergeDifferentlyHeadedOn
3675 \mergeDifferentlyDottedOn
3676 @end example
3677
3678 @noindent
3679 to the start of that section and
3680
3681 @example
3682 \mergeDifferentlyHeadedOff
3683 \mergeDifferentlyDottedOff
3684 @end example
3685
3686 @noindent
3687 to the end, giving:
3688
3689 @c line-width ensures no break
3690 @lilypond[quote,ragged-right,line-width=6\in]
3691 rhMusic = \relative {
3692   \new Voice {
3693     r2 c''4.\( g8 |
3694     \once \override Tie.staff-position = #3.5
3695     bes1~ |
3696     \bar "||"
3697     \time 6/4
3698     bes2.\tempo "Moderato" r8
3699     \mergeDifferentlyHeadedOn
3700     \mergeDifferentlyDottedOn
3701     % Start polyphonic section of four voices
3702     <<
3703       { c,8 d fis bes a }  % continuation of main voice
3704       \new Voice {
3705         \voiceTwo
3706         c,8~ 2
3707       }
3708       \new Voice {
3709         \voiceThree
3710         s8 d2
3711       }
3712       \new Voice {
3713         \voiceFour
3714         s4 fis4.
3715       }
3716     >> |
3717     \mergeDifferentlyHeadedOff
3718     \mergeDifferentlyDottedOff
3719     g2.\)  % continuation of main voice
3720   }
3721 }
3722
3723 lhMusic = \relative {
3724   r2 <c' g ees>2( |
3725   <d g, d>1)\arpeggio |
3726   r2. d,,4 r4 r |
3727   r4
3728 }
3729
3730 \score {
3731   \new PianoStaff <<
3732     \new Staff = "RH"  <<
3733       \key g \minor
3734       \rhMusic
3735     >>
3736     \new Staff = "LH" <<
3737       \key g \minor
3738       \clef "bass"
3739       \lhMusic
3740     >>
3741   >>
3742 }
3743 @end lilypond
3744
3745 These overrides have merged the two F-sharp notes, but not the two
3746 on D.  Why not?  The answer is there in the same section in the
3747 Notation Reference -- notes being merged must have stems in
3748 opposite directions and two notes cannot be merged successfully if
3749 there is a third note in the same note column.  Here the two D's
3750 both have upward stems and there is a third note -- the C.  We know
3751 how to change the stem direction using @code{\stemDown}, and
3752 the Notation Reference also says how to move the C -- apply a shift
3753 using one of the @code{\shift} commands.  But which one?
3754 The C is in voice two which has shift off, and the two D's are in
3755 voices one and three, which have shift off and shift on,
3756 respectively.  So we have to shift the C a further level still
3757 using @code{\shiftOnn} to avoid it interfering with the two D's.
3758 Applying these changes gives:
3759
3760 @cindex Tie, example of overriding
3761 @cindex staff-position property, example
3762
3763 @c line-width ensures no break
3764 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3765 rhMusic = \relative {
3766   \new Voice {
3767     r2 c''4.\( g8 |
3768     \once \override Tie.staff-position = #3.5
3769     bes1~ |
3770     \bar "||"
3771     \time 6/4
3772     bes2.\tempo "Moderato" r8
3773     \mergeDifferentlyHeadedOn
3774     \mergeDifferentlyDottedOn
3775     % Start polyphonic section of four voices
3776     <<
3777       { c,8 d fis bes a }  % continuation of main voice
3778       \new Voice {
3779         \voiceTwo
3780         % Move the c2 out of the main note column
3781         % so the merge will work
3782         c,8~ \shiftOnn c2
3783       }
3784       \new Voice {
3785         \voiceThree
3786         % Stem on the d2 must be down to permit merging
3787         s8 \stemDown d2
3788       }
3789       \new Voice {
3790         \voiceFour
3791         s4 fis4.
3792       }
3793     >> |
3794     \mergeDifferentlyHeadedOff
3795     \mergeDifferentlyDottedOff
3796     g2.\)  % continuation of main voice
3797   }
3798 }
3799
3800 lhMusic = \relative {
3801   r2 <c' g ees>2( |
3802   <d g, d>1)\arpeggio |
3803   r2. d,,4 r4 r |
3804   r4
3805 }
3806
3807 \score {
3808   \new PianoStaff <<
3809     \new Staff = "RH"  <<
3810       \key g \minor
3811       \rhMusic
3812     >>
3813     \new Staff = "LH" <<
3814       \key g \minor
3815       \clef "bass"
3816       \lhMusic
3817     >>
3818   >>
3819 }
3820 @end lilypond
3821
3822 Nearly there.  Only two problems remain: The downward stem on the
3823 merged D should not be there, and the C would be better positioned
3824 to the right of the D's.  We know how to do both of these from the
3825 earlier tweaks: we make the stem transparent, and move the C with
3826 the @code{force-hshift} property.  Here's the final result:
3827
3828 @cindex NoteColumn, example of overriding
3829 @cindex force-hshift property, example
3830 @cindex Stem, example of overriding
3831 @cindex transparent property, example
3832
3833 @c line-width ensures no break
3834 @lilypond[quote,verbatim,ragged-right,line-width=6\in]
3835 rhMusic = \relative {
3836   \new Voice {
3837     r2 c''4.\( g8 |
3838     \once \override Tie.staff-position = #3.5
3839     bes1~ |
3840     \bar "||"
3841     \time 6/4
3842     bes2.\tempo "Moderato" r8
3843     \mergeDifferentlyHeadedOn
3844     \mergeDifferentlyDottedOn
3845     % Start polyphonic section of four voices
3846     <<
3847       { c,8 d fis bes a }  % continuation of main voice
3848       \new Voice {
3849         \voiceTwo
3850         c,8~
3851         % Reposition the c2 to the right of the merged note
3852         \once \override NoteColumn.force-hshift = #1.0
3853         % Move the c2 out of the main note column
3854         % so the merge will work
3855         \shiftOnn
3856         c2
3857       }
3858       \new Voice {
3859         \voiceThree
3860         s8
3861         % Stem on the d2 must be down to permit merging
3862         \stemDown
3863         % Stem on the d2 should be invisible
3864         \tweak Stem.transparent ##t
3865         d2
3866       }
3867       \new Voice {
3868         \voiceFour
3869         s4 fis4.
3870       }
3871     >> |
3872     \mergeDifferentlyHeadedOff
3873     \mergeDifferentlyDottedOff
3874     g2.\)  % continuation of main voice
3875   }
3876 }
3877
3878 lhMusic = \relative {
3879   r2 <c' g ees>2( |
3880   <d g, d>1)\arpeggio |
3881   r2. d,,4 r4 r |
3882   r4
3883 }
3884
3885 \score {
3886   \new PianoStaff <<
3887     \new Staff = "RH"  <<
3888       \key g \minor
3889       \rhMusic
3890     >>
3891     \new Staff = "LH" <<
3892       \key g \minor
3893       \clef "bass"
3894       \lhMusic
3895     >>
3896   >>
3897 }
3898 @end lilypond
3899
3900
3901 @node Further tweaking
3902 @section Further tweaking
3903
3904 @menu
3905 * Other uses for tweaks::
3906 * Using variables for layout adjustments::
3907 * Style sheets::
3908 * Other sources of information::
3909 * Advanced tweaks with Scheme::
3910 @end menu
3911
3912 @node Other uses for tweaks
3913 @subsection Other uses for tweaks
3914
3915 @menu
3916 * Tying notes across voices::
3917 * Simulating a fermata in MIDI::
3918 @end menu
3919
3920 @cindex removing objects
3921 @cindex objects, removing
3922
3923 @node Tying notes across voices
3924 @unnumberedsubsubsec Tying notes across voices
3925
3926 @cindex tying notes across voices
3927
3928 The following example demonstrates how to connect notes in different
3929 voices using ties.  Normally, only notes in the same voice can be
3930 connected with ties.  By using two voices, with the tied notes in one
3931 of them
3932
3933 @lilypond[quote]
3934 << { b'8~ 8\noBeam } \\ { b'8[ g'] } >>
3935 @end lilypond
3936
3937 @noindent
3938 and removing the first up-stem and its flag in that voice, the tie
3939 appears to cross voices:
3940
3941 @funindex \omit
3942 @cindex Stem, example of removing
3943 @cindex Flag, example of removing
3944 @cindex @code{\omit}, example
3945 @cindex example of @code{\omit}
3946
3947 @lilypond[quote,verbatim]
3948 <<
3949   {
3950     \once \omit Stem
3951     \once \omit Flag
3952     b'8~ 8\noBeam
3953   }
3954 \\
3955   { b'8[ g'] }
3956 >>
3957 @end lilypond
3958
3959 @seealso
3960 Learning Manual:
3961 @ref{The once prefix,,The @code{@bs{}once} prefix},
3962 @ref{The stencil property}.
3963
3964
3965 @node Simulating a fermata in MIDI
3966 @unnumberedsubsubsec Simulating a fermata in MIDI
3967
3968 @cindex stencil property, use of
3969 @cindex fermata, implementing in MIDI
3970
3971 For outside-staff objects it is usually better to override the
3972 object's @code{stencil} property rather than its @code{transparent}
3973 property when you wish to remove it from the printed output.
3974 Setting the @code{stencil} property of an object to @code{#f} will
3975 remove that object entirely from the printed output.  This means it
3976 has no effect on the placement of other objects placed relative to
3977 it.
3978
3979 For example, if we wished to change the metronome setting in order
3980 to simulate a fermata in the MIDI output we would not want the
3981 metronome markings to appear in the printed output, and we would
3982 not want it to influence the spacing between the two systems or
3983 the positions of adjacent annotations on the staff.  So setting
3984 its @code{stencil} property to @code{#f} would be the best way.
3985 We show here the effect of the two methods:
3986
3987 @cindex MetronomeMark, example of overriding
3988 @cindex transparent property, example
3989
3990 @lilypond[quote,verbatim,ragged-right]
3991 \score {
3992   \relative {
3993     % Visible tempo marking
3994     \tempo 4=120
3995     a'4 a a
3996     \once \hide Score.MetronomeMark
3997     % Invisible tempo marking to lengthen fermata in MIDI
3998     \tempo 4=80
3999     a4\fermata |
4000     % New tempo for next section
4001     \tempo 4=100
4002     a4 a a a |
4003   }
4004   \layout { }
4005   \midi { }
4006 }
4007 @end lilypond
4008
4009 @cindex MetronomeMark, example of overriding
4010 @cindex stencil property, example
4011
4012 @lilypond[quote,verbatim,ragged-right]
4013 \score {
4014   \relative {
4015     % Visible tempo marking
4016     \tempo 4=120
4017     a'4 a a
4018     \once \omit Score.MetronomeMark
4019     % Invisible tempo marking to lengthen fermata in MIDI
4020     \tempo 4=80
4021     a4\fermata |
4022     % New tempo for next section
4023     \tempo 4=100
4024     a4 a a a |
4025   }
4026   \layout { }
4027   \midi { }
4028 }
4029 @end lilypond
4030
4031 @noindent
4032 Both methods remove the metronome mark which lengthens the fermata
4033 from the printed output, and both affect the MIDI timing as
4034 required, but the transparent metronome mark in the first line
4035 forces the following tempo indication too high while the
4036 second (with the stencil removed) does not.
4037
4038 @seealso
4039 Music Glossary:
4040 @rglos{system}.
4041
4042 @node Using variables for layout adjustments
4043 @subsection Using variables for layout adjustments
4044
4045 @cindex variables, using for overrides
4046 @cindex overrides, using variables for
4047 @cindex adjustments, using variables for
4048 @cindex layout adjustments, using variables for
4049
4050 Override commands are often long and tedious to type, and they
4051 have to be absolutely correct.  If the same overrides are to be
4052 used many times it may be worth defining variables to hold them.
4053
4054 Suppose we wish to emphasize certain words in lyrics by printing
4055 them in bold italics.  The @code{\italic} and @code{\bold}
4056 commands only work within lyrics if they are embedded, together with
4057 the word or words to be modified, within a @code{\markup} block,
4058 which makes them tedious to enter.  The need to embed the words
4059 themselves prevents their use in simple variables.  As an
4060 alternative can we use @code{\override} and @code{\revert} commands?
4061
4062 @example
4063 @code{\override Lyrics.LyricText.font-shape = #'italic}
4064 @code{\override Lyrics.LyricText.font-series = #'bold}
4065
4066 @code{\revert Lyrics.LyricText.font-shape}
4067 @code{\revert Lyrics.LyricText.font-series}
4068 @end example
4069
4070 These would also be extremely tedious to enter if there were many
4071 words requiring emphasis.  But we @emph{can} define these as two
4072 variables and use those to bracket the words to be emphasized.
4073 Another advantage of using variables for these overrides is that
4074 the spaces around the dot are not necessary, since they are not
4075 being interpreted in @code{\lyricmode} directly.  Here's an example
4076 of this, although in practice  we would choose shorter names
4077 for the variables to make them quicker to type:
4078
4079 @cindex LyricText, example of overriding
4080 @cindex font-shape property, example
4081 @cindex font-series property, example
4082
4083 @lilypond[quote,verbatim]
4084 emphasize = {
4085   \override Lyrics.LyricText.font-shape = #'italic
4086   \override Lyrics.LyricText.font-series = #'bold
4087 }
4088
4089 normal = {
4090   \revert Lyrics.LyricText.font-shape
4091   \revert Lyrics.LyricText.font-series
4092 }
4093
4094 global = { \key c \major \time 4/4 \partial 4 }
4095
4096 SopranoMusic = \relative { c'4 | e4. e8 g4 g    | a4   a   g  }
4097 AltoMusic    = \relative { c'4 | c4. c8 e4 e    | f4   f   e  }
4098 TenorMusic   = \relative  { e4 | g4. g8 c4.  b8 | a8 b c d e4 }
4099 BassMusic    = \relative  { c4 | c4. c8 c4 c    | f8 g a b c4 }
4100
4101 VerseOne = \lyrics {
4102   E -- | ter -- nal \emphasize Fa -- ther, | \normal strong to save,
4103 }
4104
4105 VerseTwo = \lyricmode {
4106   O | \once \emphasize Christ, whose voice the | wa -- ters heard,
4107 }
4108
4109 VerseThree = \lyricmode {
4110   O | \emphasize Ho -- ly Spi -- rit, | \normal who didst brood
4111 }
4112
4113 VerseFour = \lyricmode {
4114   O | \emphasize Tri -- ni -- ty \normal of | love and pow'r
4115 }
4116
4117 \score {
4118   \new ChoirStaff <<
4119     \new Staff <<
4120       \clef "treble"
4121       \new Voice = "Soprano"  { \voiceOne \global \SopranoMusic }
4122       \new Voice = "Alto" { \voiceTwo \AltoMusic }
4123       \new Lyrics \lyricsto "Soprano" { \VerseOne }
4124       \new Lyrics \lyricsto "Soprano" { \VerseTwo }
4125       \new Lyrics \lyricsto "Soprano" { \VerseThree }
4126       \new Lyrics \lyricsto "Soprano" { \VerseFour }
4127     >>
4128     \new Staff <<
4129       \clef "bass"
4130       \new Voice = "Tenor" { \voiceOne \TenorMusic }
4131       \new Voice = "Bass"  { \voiceTwo \BassMusic }
4132     >>
4133   >>
4134 }
4135 @end lilypond
4136
4137
4138 @node Style sheets
4139 @subsection Style sheets
4140
4141 The output that LilyPond produces can be heavily modified; see
4142 @ref{Tweaking output}, for details.  But what if you have many
4143 input files that you want to apply your tweaks to?  Or what if you
4144 simply want to separate your tweaks from the actual music?  This
4145 is quite easy to do.
4146
4147 Let's look at an example.  Don't worry if you don't understand
4148 the parts with all the @code{#()}.  This is explained in
4149 @ref{Advanced tweaks with Scheme}.
4150
4151 @lilypond[quote,verbatim,ragged-right]
4152 mpdolce =
4153   \tweak self-alignment-X #-0.6
4154   #(make-dynamic-script
4155     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4156
4157 inst =
4158 #(define-music-function
4159      (string)
4160      (string?)
4161    #{ <>^\markup \bold \box #string #})
4162
4163 \relative {
4164   \tempo 4=50
4165   a'4.\mpdolce d8 cis4--\glissando a |
4166   b4 bes a2 |
4167   \inst "Clarinet"
4168   cis4.\< d8 e4 fis |
4169   g8(\! fis)-. e( d)-. cis2 |
4170 }
4171 @end lilypond
4172
4173 Let's do something about the @code{mpdolce} and @code{inst} definitions.
4174 They produce the output we desire, but we might want to use them in
4175 another piece.  We could simply copy-and-paste them at the top of every
4176 file, but that's an annoyance.  It also leaves those definitions in our
4177 input files, and I personally find all the @code{#()} somewhat ugly.
4178 Let's hide them in another file:
4179
4180 @example
4181 %%% save this to a file called "definitions.ily"
4182 mpdolce =
4183   \tweak self-alignment-X #-0.6
4184   #(make-dynamic-script
4185     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4186
4187 inst =
4188 #(define-music-function
4189      (string)
4190      (string?)
4191    #@{ <>^\markup \bold \box #string #@})
4192 @end example
4193
4194 We will refer to this file using the @code{\include} command near
4195 the top of the music file.  (The extension @file{.ily} is used to
4196 distinguish this included file, which is not meant to be compiled
4197 on its own, from the main file.)
4198 Now let's modify our music (let's save this file as @file{music.ly}).
4199
4200 @c  We have to do this awkward example/lilypond-non-verbatim
4201 @c  because we can't do the \include stuff in the manual.
4202
4203 @example
4204 \include "definitions.ily"
4205
4206 \relative @{
4207   \tempo 4=50
4208   a'4.\mpdolce d8 cis4--\glissando a |
4209   b4 bes a2 |
4210   \inst "Clarinet"
4211   cis4.\< d8 e4 fis |
4212   g8(\! fis)-. e( d)-. cis2 |
4213 @}
4214 @end example
4215
4216 @lilypond[quote,ragged-right]
4217 mpdolce =
4218   \tweak self-alignment-X #-0.6
4219   #(make-dynamic-script
4220     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4221
4222 inst =
4223 #(define-music-function
4224      (string)
4225      (string?)
4226    #{ <>^\markup \bold \box #string #})
4227
4228 \relative {
4229   \tempo 4=50
4230   a'4.\mpdolce d8 cis4--\glissando a |
4231   b4 bes a2 |
4232   \inst "Clarinet"
4233   cis4.\< d8 e4 fis |
4234   g8(\! fis)-. e( d)-. cis2 |
4235 }
4236 @end lilypond
4237
4238 That looks better, but let's make a few changes.  The glissando is hard
4239 to see, so let's make it thicker and closer to the note heads.  Let's
4240 put the metronome marking above the clef, instead of over the first
4241 note.  And finally, my composition professor hates @q{C} time signatures,
4242 so we'd better make that @q{4/4} instead.
4243
4244 Don't change @file{music.ly}, though.  Replace our @file{definitions.ily}
4245 with this:
4246
4247 @example
4248 %%%  definitions.ily
4249 mpdolce =
4250   \tweak self-alignment-X #-0.6
4251   #(make-dynamic-script
4252     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4253
4254 inst =
4255 #(define-music-function
4256      (string)
4257      (string?)
4258    #@{ <>^\markup \bold \box #string #@})
4259
4260 \layout@{
4261   \context @{
4262     \Score
4263     \override MetronomeMark.extra-offset = #'(-5 . 0)
4264     \override MetronomeMark.padding = #'3
4265   @}
4266   \context @{
4267     \Staff
4268     \override TimeSignature.style = #'numbered
4269   @}
4270   \context @{
4271     \Voice
4272     \override Glissando.thickness = #3
4273     \override Glissando.gap = #0.1
4274   @}
4275 @}
4276 @end example
4277
4278 @lilypond[quote,ragged-right]
4279 mpdolce =
4280   \tweak self-alignment-X #-0.6
4281   #(make-dynamic-script
4282     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4283
4284 inst =
4285 #(define-music-function
4286      (string)
4287      (string?)
4288    #{ <>^\markup \bold \box #string #})
4289
4290 \layout{
4291   \context {
4292     \Score
4293     \override MetronomeMark.extra-offset = #'(-5 . 0)
4294     \override MetronomeMark.padding = #'3
4295   }
4296   \context {
4297     \Staff
4298     \override TimeSignature.style = #'numbered
4299   }
4300   \context {
4301     \Voice
4302     \override Glissando.thickness = #3
4303     \override Glissando.gap = #0.1
4304   }
4305 }
4306
4307 \relative {
4308   \tempo 4=50
4309   a'4.\mpdolce d8 cis4--\glissando a |
4310   b4 bes a2 |
4311   \inst "Clarinet"
4312   cis4.\< d8 e4 fis |
4313   g8(\! fis)-. e( d)-. cis2 |
4314 }
4315 @end lilypond
4316
4317 That looks nicer!  But now suppose that I want to publish this
4318 piece.  My composition professor doesn't like @q{C} time
4319 signatures, but I'm somewhat fond of them.  Let's copy the
4320 current @file{definitions.ily} to @file{web-publish.ily} and
4321 modify that.  Since this music is aimed at producing a pdf which
4322 will be displayed on the screen, we'll also increase the
4323 overall size of the output.
4324
4325 @example
4326 %%%  web-publish.ily
4327 mpdolce =
4328   \tweak self-alignment-X #-0.6
4329   #(make-dynamic-script
4330     #@{ \markup @{ \dynamic mp \normal-text \italic \bold dolce @} #@})
4331
4332 inst =
4333 #(define-music-function
4334      (string)
4335      (string?)
4336    #@{ <>^\markup \bold \box #string #@})
4337
4338 #(set-global-staff-size 23)
4339
4340 \layout@{
4341   \context @{
4342     \Score
4343     \override MetronomeMark.extra-offset = #'(-5 . 0)
4344     \override MetronomeMark.padding = #'3
4345   @}
4346   \context @{
4347     \Staff
4348   @}
4349   \context @{
4350     \Voice
4351     \override Glissando.thickness = #3
4352     \override Glissando.gap = #0.1
4353   @}
4354 @}
4355 @end example
4356
4357 @lilypond[quote,ragged-right]
4358 mpdolce =
4359   \tweak self-alignment-X #-0.6
4360   #(make-dynamic-script
4361     #{ \markup { \dynamic mp \normal-text \italic \bold dolce } #})
4362
4363 inst =
4364 #(define-music-function
4365      (string)
4366      (string?)
4367    #{ <>^\markup \bold \box #string #})
4368
4369 #(set-global-staff-size 23)
4370
4371 \layout{
4372   \context { \Score
4373     \override MetronomeMark.extra-offset = #'(-5 . 0)
4374     \override MetronomeMark.padding = #'3
4375   }
4376   \context { \Voice
4377     \override Glissando.thickness = #3
4378     \override Glissando.gap = #0.1
4379   }
4380 }
4381
4382 \relative {
4383   \tempo 4=50
4384   a'4.\mpdolce d8 cis4--\glissando a |
4385   b4 bes a2 |
4386   \inst "Clarinet"
4387   cis4.\< d8 e4 fis |
4388   g8(\! fis)-. e( d)-. cis2 |
4389 }
4390 @end lilypond
4391
4392 Now in our music, I simply replace
4393 @code{\include "definitions.ily"} with
4394 @code{\include "web-publish.ily"}.  Of course, we could make this
4395 even more convenient.  We could make a @file{definitions.ily} file which
4396 contains only the definitions of @code{mpdolce} and @code{inst}, a
4397 @file{web-publish.ily} file which contains only the @code{\layout}
4398 section listed above, and a @file{university.ily} file which
4399 contains only the tweaks to produce the output that my professor
4400 prefers.  The top of @file{music.ly} would then look like this:
4401
4402 @example
4403 \include "definitions.ily"
4404
4405 %%%  Only uncomment one of these two lines!
4406 \include "web-publish.ily"
4407 %\include "university.ily"
4408 @end example
4409
4410 This approach can be useful even if you are only producing
4411 one set of parts.  I use half a dozen different
4412 @q{style sheet} files for my projects.  I begin every music
4413 file with @code{\include "../global.ily"}, which contains
4414
4415 @example
4416 %%%   global.ily
4417 \version @w{"@version{}"}
4418
4419 #(ly:set-option 'point-and-click #f)
4420
4421 \include "../init/init-defs.ly"
4422 \include "../init/init-layout.ly"
4423 \include "../init/init-headers.ly"
4424 \include "../init/init-paper.ly"
4425 @end example
4426
4427
4428 @node Other sources of information
4429 @subsection Other sources of information
4430
4431 The Internals Reference documentation contains a lot of information
4432 about LilyPond, but even more information can be gathered by
4433 looking at the internal LilyPond files.  To explore these, you must
4434 first find the directory appropriate to your system.  The location
4435 of this directory depends (a) on whether you obtained LilyPond
4436 by downloading a precompiled binary from lilypond.org
4437 or whether you installed it from a package manager (i.e.
4438 distributed with GNU/Linux, or installed under fink or cygwin) or
4439 compiled it from source, and (b) on which operating system it is
4440 being used:
4441
4442 @subsubsubheading Downloaded from lilypond.org
4443
4444 @itemize @bullet
4445 @item GNU/Linux
4446
4447 Navigate to
4448 @example
4449 @file{@var{INSTALLDIR}/lilypond/usr/@/share/lilypond/current/}
4450 @end example
4451
4452 @item MacOS X
4453
4454 Navigate to
4455 @example
4456 @file{@var{INSTALLDIR}/LilyPond.app/Contents/@/Resources/share/lilypond/current/}
4457 @end example
4458
4459 by either @code{cd}-ing into this directory from the
4460 Terminal, or control-clicking on the LilyPond application and
4461 selecting @q{Show Package Contents}.
4462
4463 @item Windows
4464
4465 Using Windows Explorer, navigate to
4466 @example
4467 @file{@var{INSTALLDIR}/LilyPond/usr/@/share/lilypond/current/}
4468 @end example
4469
4470 @end itemize
4471
4472 @subsubsubheading Installed from a package manager or compiled from source
4473
4474 Navigate to
4475 @file{@var{PREFIX}/share/lilypond/@var{X.Y.Z}/}, where
4476 @var{PREFIX} is set by your package manager or @code{configure}
4477 script, and @var{X.Y.Z} is the LilyPond version number.
4478
4479 @smallspace
4480
4481 Within this directory the two interesting subdirectories are
4482
4483 @itemize
4484 @item @file{ly/} - contains files in LilyPond format
4485 @item @file{scm/} - contains files in Scheme format
4486 @end itemize
4487
4488 Let's begin by looking at some files in @file{ly/}.
4489 Open @file{ly/property-init.ly} in a text editor.  The one
4490 you normally use for @code{.ly} files will be fine.  This file
4491 contains the definitions of all the standard LilyPond predefined
4492 commands, such as @code{\tieUp} and @code{\slurDotted}.  You will
4493 see that these are nothing more than definitions of variables
4494 containing one or a group of @code{\override} commands.  For
4495 example, @code{\tieDotted} is defined to be:
4496
4497 @example
4498 tieDotted = @{
4499   \override Tie.dash-period = #0.75
4500   \override Tie.dash-fraction = #0.1
4501 @}
4502 @end example
4503
4504 If you do not like the default values these predefined commands can
4505 be redefined easily, just like any other variable, at the
4506 head of your input file.
4507
4508 The following are the most useful files to be found in
4509 @file{ly/}:
4510
4511 @multitable @columnfractions .4 .6
4512 @headitem Filename
4513   @tab Contents
4514 @item @file{ly/engraver-init.ly}
4515   @tab Definitions of engraver Contexts
4516 @item @file{ly/paper-defaults-init.ly}
4517   @tab Specifications of paper-related defaults
4518 @item @file{ly/performer-init.ly}
4519   @tab Definitions of performer Contexts
4520 @item @file{ly/property-init.ly}
4521   @tab Definitions of all common predefined commands
4522 @item @file{ly/spanner-init.ly}
4523   @tab Definitions of spanner-related predefined commands
4524 @end multitable
4525
4526 Other settings (such as the definitions of markup commands) are
4527 stored as @file{.scm} (Scheme) files.  The Scheme programming
4528 language is used to provide a programmable interface into
4529 LilyPond internal operation.  Further explanation of these files
4530 is currently outside the scope of this manual, as a knowledge of
4531 the Scheme language is required.  Users should be warned that
4532 a substantial amount of technical knowledge or time is required
4533 to understand Scheme and these files (see @rextend{Scheme tutorial}).
4534
4535 If you have this knowledge, the Scheme files which may be of
4536 interest are:
4537
4538 @multitable @columnfractions .4 .6
4539 @headitem Filename
4540   @tab Contents
4541 @item @file{scm/auto-beam.scm}
4542   @tab Sub-beaming defaults
4543 @item @file{scm/define-grobs.scm}
4544   @tab Default settings for grob properties
4545 @item @file{scm/define-markup-commands.scm}
4546   @tab Specify all markup commands
4547 @item @file{scm/midi.scm}
4548   @tab Default settings for MIDI output
4549 @item @file{scm/output-lib.scm}
4550   @tab Settings that affect appearance of frets, colors,
4551        accidentals, bar lines, etc
4552 @item @file{scm/parser-clef.scm}
4553   @tab Definitions of supported clefs
4554 @item @file{scm/script.scm}
4555   @tab Default settings for articulations
4556 @end multitable
4557
4558
4559 @node Advanced tweaks with Scheme
4560 @subsection Advanced tweaks with Scheme
4561
4562 Although many things are possible with the @code{\override} and
4563 @code{\tweak} commands, an even more powerful way of modifying
4564 the action of LilyPond is available through a programmable
4565 interface to the LilyPond internal operation.  Code written in
4566 the Scheme programming language can be incorporated directly in
4567 the internal operation of LilyPond.  Of course, at least a basic
4568 knowledge of programming in Scheme is required to do this, and an
4569 introduction is provided in the @rextend{Scheme tutorial}.
4570
4571 As an illustration of one of the many possibilities, instead of
4572 setting a property to a constant it can be set to a Scheme
4573 procedure which is then called whenever that property is accessed
4574 by LilyPond.  The property can then be set dynamically to a value
4575 determined by the procedure at the time it is called.  In this
4576 example we color the note head in accordance with its position on
4577 the staff.
4578
4579 @cindex x11-color function, example of using
4580 @cindex NoteHead, example of overriding
4581 @cindex color property, setting to Scheme procedure
4582
4583 @lilypond[quote,verbatim,ragged-right]
4584 #(define (color-notehead grob)
4585    "Color the notehead according to its position on the staff."
4586    (let ((mod-position (modulo (ly:grob-property grob 'staff-position)
4587                                7)))
4588      (case mod-position
4589        ;;   Return rainbow colors
4590        ((1) (x11-color 'red    ))  ; for C
4591        ((2) (x11-color 'orange ))  ; for D
4592        ((3) (x11-color 'yellow ))  ; for E
4593        ((4) (x11-color 'green  ))  ; for F
4594        ((5) (x11-color 'blue   ))  ; for G
4595        ((6) (x11-color 'purple ))  ; for A
4596        ((0) (x11-color 'violet ))  ; for B
4597        )))
4598
4599 \relative {
4600   % Arrange to obtain color from color-notehead procedure
4601   \override NoteHead.color = #color-notehead
4602   a2 b | c2 d | e2 f | g2 a |
4603 }
4604 @end lilypond
4605
4606 Further examples showing the use of these programmable interfaces
4607 can be found in @rextend{Callback functions}.
4608
4609
4610