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