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