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