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