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