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