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