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