]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tweaks.itely
More goodness from Trevor D.
[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 @node Tweaking output
11 @chapter Tweaking output
12
13 This chapter discusses how to modify output.  LilyPond is extremely
14 configurable; virtually every fragment of output may be changed.
15
16 NB: This chapter is still under development and this version is
17 somewhat experimental; nothing is fixed.  Don't translate yet!
18
19
20
21 @menu
22 * Tweaking basics::             
23 * The Internals Reference manual::  
24 * Appearance of objects::       
25 * Placement of objects::        
26 * Collisions of objects::       
27 * Page layout::                 
28 * Common tweaks::               
29 * TODO other name::             
30 @end menu
31
32 @node Tweaking basics
33 @section Tweaking basics
34
35 @menu
36 * Introduction to tweaks::      
37 * Objects and interfaces::      
38 * Naming conventions of objects and properties::  
39 * Tweaking methods::            
40 @end menu
41
42 @node Introduction to tweaks
43 @subsection Introduction to tweaks
44
45 @q{Tweaking} is a LilyPond term for the various methods available
46 to the user for modifying the actions taken during interpretation
47 of the input file and modifying the appearance of the printed 
48 output.  Some tweaks are very easy to use; others are more 
49 complex.  But taken together the methods available for tweaking 
50 permit almost any desired appearance of the printed music to be 
51 achieved.
52
53 In this section we cover the basic concepts required to understand
54 tweaking.  Later we give a variety of potted commands which can
55 simply be copied to obtain the same effect in your own scores, and
56 at the same time we show how these commands may be constructed so 
57 that you may learn how to develop your own tweaks.
58
59 Before starting on this Chapter you may wish to review the section
60 @ref{Contexts and engravers}, as Contexts, Engravers, and the 
61 Properties contained within them are fundamental to understanding
62 and constructing Tweaks.
63
64 @node Objects and interfaces
65 @subsection Objects and interfaces
66
67 @cindex Objects
68 @cindex Grobs
69 @cindex Spanners
70 @cindex Interfaces
71
72 Tweaking involves modifying the internal operation and structures
73 of the LilyPond program, so we must first introduce some terms
74 which are used to describe those internal operations and 
75 structures.
76
77 The term @q{Object} is a generic term used to refer to the
78 multitude of internal structures built by LilyPond during the
79 processing of an input file.  So when a command like @code{\new
80 Staff} is encountered a new object of type @code{Staff} is
81 constructed.  That @code{Staff} object then holds all the
82 properties associated with that particular staff, for example, its
83 name and its key signature, together with details of the engravers
84 which have been assigned to operate within that staff's context.
85 Similarly, there are @code{Voice} objects, @code{Score} objects,
86 @code{Lyric} objects, and objects to represent barlines,
87 noteheads, ties, dynamics, etc, each with their own set of
88 properties.
89
90 Some types of object are given special names.  Objects which
91 represent items of notation on the printed output such as
92 noteheads, stems, slurs, ties, fingering, clefs, etc are called
93 @q{Layout objects}, often known as @q{Graphical Objects}, or
94 @q{Grobs} for short.  These are still objects in the generic sense
95 above, and so they too all have properties associated with them,
96 such as their position, size, color, etc.
97
98 Some layout objects are still more specialised.  Phrasing slurs,
99 crescendo hairpins, ottavo marks, and many other grobs are not
100 localised in a single place -- they have a starting point, an
101 ending point, and maybe other properties concerned with their
102 shape.  Objects with an extended shape like these are called
103 @q{Spanners}.
104
105 It remains to explain what @q{Interfaces} are.  Many objects,
106 even though they are quite different, share common features 
107 which need to be processed in the same way.
108 For example, all grobs have a color, a size, a position, etc,
109 and all these properties are processed in the same way during
110 LilyPond's
111 interpretation of the input file.  To simplify these internal
112 operations these common actions and properties are grouped 
113 together in an object called a @code{grob-interface}.  There
114 are many other groupings of common properties like this, each 
115 one given a name ending in @code{-interface}.  In total there
116 are over 100 such interfaces.  We shall see later why this is
117 of interest and use to the user.
118
119 These, then, are the main terms relating to objects which we 
120 shall use in this chapter.
121
122 @node Naming conventions of objects and properties
123 @subsection Naming conventions of objects and properties
124
125 We met some object naming conventions previously, in 
126 @ref{Contexts and engravers}.  Here for reference is a list
127 of the most common object and property types together with 
128 the conventions for naming them and a couple of examples of 
129 some real names.  We have used A to stand for any capitalised
130 alphabetic character and aaa to stand for any number of
131 lower-case alphabetic characters.  Other characters are used
132 verbatim. 
133
134 @multitable @columnfractions .33 .33 .33
135 @headitem Object/property type           
136   @tab Naming convention
137   @tab Example
138 @item Contexts, Layout Objects     
139   @tab Aaaa or AaaaAaaaAaaa
140   @tab Staff, GrandStaff, 
141 @item Engravers
142   @tab Aaaa_aaa_engraver
143   @tab Clef_engraver, Note_heads_engraver
144 @item Interfaces
145   @tab aaa-aaa-interface
146   @tab grob-interface, break-aligned-interface 
147 @item Context Properties
148   @tab aaa or aaaAaaaAaaa
149   @tab alignAboveContext, skipBars
150 @item Layout Object Properties
151   @tab aaa or aaa-aaa-aaa
152   @tab direction, beam-thickness
153 @end multitable
154
155 As we shall see shortly, the properties of different types of 
156 object are modified by different commands, so it is useful to
157 be able to recognise the type of object from the names of its
158 properties.
159
160
161 @node Tweaking methods
162 @subsection Tweaking methods
163
164 We have already met the commands @code{\set} and @code{\with},
165 used to change the properties of @strong{contexts} and to remove
166 and add @strong{engravers}, in 
167 @ref{Modifying context properties} and @ref{Adding
168 and removing engravers}.  We now must meet one more command.
169
170 The command to change the properties of @strong{layout objects} is
171 @code{\override}.  Because this command has to modify
172 internal properties deep within LilyPond its syntax is not
173 as simple as the commands you have met so far.  It needs to
174 know precisely which property of which object in which context
175 has to be modified, and what its new value is to be.  Let's see
176 how this is done.
177
178 The general syntax of this command is:
179
180 @example
181 \override @emph{context}.@emph{layout_object} #'@emph{layout_property} = #@emph{value}
182 @end example
183
184 @noindent
185 This will set the property with the name @emph{layout_property}
186 of the layout object with the name 
187 @emph{layout_object}, which is a member of the @emph{context}
188 context, to the value @emph{value}.
189
190 The @emph{context} can be omitted (and usually is) when the 
191 required context is unambiguously implied and is one of lowest
192 level contexts, i.e., @code{Voice}, @code{ChordNames} or 
193 @code{Lyrics}, and we shall omit it in many of the following 
194 examples.  We shall see later when it must be specified.
195
196 For now, don't worry about the @code{#'}, which must precede the
197 layout property, and the @code{#}, which must precede the value.
198 These must always be present in exactly this form.  This is the
199 most common command used in tweaking, and most of the rest of
200 this chapter will be directed to presenting examples of how it is
201 used.
202
203 Once overridden, the property retains its new value until it is
204 overridden again or a @code{\revert} command is encountered.
205 The @code{\revert} command has the following syntax and causes
206 the value of the property to revert to its original default
207 value; note, not its previous value if several @code{\override}
208 commands have been issued.
209
210 @example
211 \revert @emph{context}.@emph{layout_object} #'@emph{layout_property}
212 @end example
213
214 Again, just like @emph{context} in the @code{\override} command,
215 @emph{context} is often not needed.  It will be omitted 
216 in many of the following examples.
217
218 There is another form of the override command, 
219 @code{\overrideProperty}, which is occasionally required.  
220 We mention it here for completeness, but for details see 
221 @ruser{Difficult tweaks}.
222 @c Maybe explain in a later iteration  -td
223
224 The final tweaking command which is available is @code{\tweak}.
225 It is not really a new command but a shorthand for an 
226 @code{\override} command which must be used in a few special 
227 circumstances.  Again, we shall not discuss or use it here.  
228 You may find the details in 
229 @ruser{Objects connected to the input}.
230 @c Maybe explain in a later iteration  -td
231
232 @node The Internals Reference manual
233 @section The Internals Reference manual
234
235 @cindex Internals Reference
236
237 @menu
238 * Properties of layout objects::  
239 * Properties found in interfaces::  
240 * Types of properties::         
241 @end menu
242
243 @node Properties of layout objects
244 @subsection Properties of layout objects
245
246 @cindex properties of layout objects
247 @cindex properties of grobs
248 @cindex grobs, properties of
249 @cindex layout objects, properties of
250
251 Suppose you have a slur in a score which, to your mind,
252 appears too thin and you'd like to draw it a little heavier.
253 How do you go about doing this?  You know from the statements
254 earlier about the flexibility of LilyPond that such a thing
255 should be possible, and you would probably guess that an
256 @code{\override} command would be needed.  But is there a
257 heaviness property for a slur, and if there is, how might it 
258 be modified?  This is where the Internals Reference manual
259 comes in.  It contains all the information you might need to
260 construct this and all other @code{\override} commands.
261
262 Before we look at the Internals Reference a word of warning.
263 This is a @strong{reference} document, which means there is
264 little or no explanation contained within it: its purpose is
265 to present information precisely and concisely.  This
266 means it might look daunting at first sight.  Don't worry!
267 The guidance and explanation presented here will enable you
268 to extract the information from the Internals Reference for
269 yourself with just a little practice.
270
271 @cindex override example
272 @cindex Internals Reference, example of using
273
274 Let's use a concrete example with a simple fragment of real
275 music:
276
277 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
278 {
279   \time 6/8
280   { 
281     r4 b8 b[( g]) g | 
282     g[( e]) e d[( f]) a | 
283     a g
284   }
285   \addlyrics { 
286     The man who feels love's sweet e -- mo -- tion 
287   }
288 }
289 @end lilypond 
290
291 Suppose now that we decide we would like the slurs to be a
292 little heavier.  Is this possible?  The slur is certainly a
293 layout object, so the question is, @q{Is there a property
294 belonging to a slur which controls the heaviness?}  To answer
295 this we must look in the Internals Reference, or IR for short.
296
297 The IR for the version of LilyPond you are using may be found
298 on the LilyPond website at @uref{http://lilypond.org}.  Go to the
299 documentation page and click on the Internals Reference link.
300 For learning purposes you should use the standard html version,
301 not the @q{one big page} or the PDF.  For the next few
302 paragraphs to make sense you will need to actually do this
303 as you read.
304
305 Under the heading @strong{Top} you will see five links.  Select
306 the link to the @emph{Backend}, which is where information about
307 layout objects is to be found.  There, under the heading 
308 @strong{Backend}, select the link to @emph{All layout objects}.
309 The page that appears lists all the layout objects used in your
310 version of LilyPond, in alphabetic order.  Select the link to
311 Slur, and the properties of Slurs are listed.
312
313 (An alternative way of finding this page is from the Notation
314 Reference.  On one of the pages that deals with slurs you may
315 find a link to the Internals Reference.  This link will
316 take you directly to this page, but often it is easier to go
317 straight to the IR and search there.)
318
319 This Slur page in the IR tells us first that Slur objects are 
320 created by the 
321 Slur_engraver.  Then it lists the standard settings.  Note
322 these are @strong{not} in alphabetic order.  Browse down
323 them looking for a property that might control the heaviness
324 of slurs, and you should find
325
326 @example
327 @code{thickness} (number)
328      @code{1.2}
329      Line thickness, generally measured in @code{line-thickness}
330 @end example
331
332 This looks a good bet to change the heaviness. It tells us that
333 the value of @code{thickness} is a simple @emph{number},
334 that the default value is 1.2, and that the units are
335 in another property called @code{line-thickness}.
336
337 As we said earlier, there are few to no explanations in the IR,
338 but we already have enough information to try changing the
339 slur thickness.  We see that the name of the layout object 
340 is @code{Slur}, that the name of the property to change is
341 @code{thickness} and that the new value should be a number
342 somewhat larger than 1.2 if we are to make slurs thicker.
343
344 We can now construct the @code{\override} command by simply
345 substituting the values we have found for the names, omitting
346 the context.  Let's use a very large value for the thickness 
347 at first, so we can be sure the command is working.  We get:
348
349 @example
350   \override Slur #'thickness = #5.0
351 @end example 
352
353 Don't forget the @code{#'} preceding the
354 property name and and @code{#} preceding the new value!
355
356 The final question is, @q{Where should this command be
357 placed?}  While you are unsure and learning, the best 
358 answer is, @q{Within the music, before the first slur and 
359 close to it.}  Let's do that:
360
361 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
362 {
363   \time 6/8
364   { 
365     % Increase thickness of all following slurs from 1.2 to 5.0
366     \override Slur #'thickness = #5.0
367     r4 b8 b[( g]) g |
368     g[( e]) e d[( f]) a |
369     a g
370   }
371   \addlyrics {
372     The man who feels love's sweet e -- mo -- tion 
373   }
374 }
375 @end lilypond 
376
377 @noindent
378 and we see that the slur is indeed heavier.
379
380 So this is the basic way of constructing @code{\override}
381 commands.  There are a few more complications that we
382 shall meet in later sections, but you now know all the
383 essentials required to make up your own -- but you will
384 still need some practice.  This is provided in the examples
385 which follow.
386
387 @subheading Finding the context
388 @cindex context, finding
389
390 But first, what if we had needed to specify the Context?  
391 What should it be?  We could guess that slurs are in
392 the Voice context, as they are clearly closely associated
393 with individual lines of music, but can we be sure?  To
394 find out, go back to the top of the IR page describing the
395 Slur, where it says @q{Slur objects are created by: Slur
396 engraver}.  So slurs will be created in whichever context
397 the @code{Slur_engraver} is in.  Follow the link to the
398 @code{Slur_engraver} page.  At the very bottom it tells
399 us that @code{Slur_engraver} is part of five Voice contexts,
400 including the standard voice context, @code{Voice}, so our 
401 guess was correct.  And because @code{Voice} is one of the
402 lowest level contexts which is implied unambiguously by 
403 the fact that we are entering notes, we can omit it in this 
404 location.
405
406 @subheading Overriding once only
407
408 @cindex overriding once only
409 @cindex once override
410 @funindex \once
411
412 As you can see, @emph{all} the slurs are thicker in the 
413 final example above.  But what if we
414 wanted just the first slur to be thicker?  This is achieved
415 with the @code{\once} command.  Placed immediately before
416 the @code{\override} command it causes it to change only the
417 slur which begins on the @strong{immediately following} note.
418 If the
419 immediately following note does not begin a slur the command
420 has no effect at all -- it is not remembered until a slur
421 is encountered, it is simply discarded.  So the command with
422 @code{\once} must be 
423 repositioned as follows:
424
425 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
426 {
427   \time 6/8
428   { 
429     r4 b8
430     % Increase thickness of immediately following slur only
431     \once \override Slur #'thickness = #5.0
432     b[( g]) g | 
433     g[( e]) e d[( f]) a | 
434     a g 
435   }
436   \addlyrics { 
437     The man who feels love's sweet e -- mo -- tion 
438   }
439 }
440 @end lilypond 
441
442 @noindent
443 Now only the first slur is made heavier.
444
445 The @code{\once} command can also be used before @code{\set}
446 and @code{\unset}, and before the command to be introduced
447 in the following section -- @code{revert}.
448  
449 @subheading Reverting
450
451 @cindex revert
452 @cindex default properties, reverting
453 @funindex \revert
454
455 Finally, what if we wanted just the first two slurs to be
456 heavier?  Well, we could use two commands, each preceded by
457 @code{\once} placed immediately before each of the notes where
458 the slurs begin:
459
460 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
461 {
462   \time 6/8
463   {
464     r4 b8
465     % Increase thickness of immediately following slur only
466     \once \override Slur #'thickness = #5.0
467     b[( g]) g |
468     % Increase thickness of immediately following slur only
469     \once \override Slur #'thickness = #5.0
470     g[( e]) e d[( f]) a | 
471     a g
472   }
473   \addlyrics { 
474     The man who feels love's sweet e -- mo -- tion 
475   }
476 }
477 @end lilypond 
478
479 @noindent
480 or we could omit the @code{\once} command and use the 
481 @code{\revert} command
482 to return the @code{thickness} property to its default value
483 after the second slur:
484
485 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
486 {
487   \time 6/8
488   {
489     r4 b8
490     % Increase thickness of all following slurs from 1.2 to 5.0
491     \override Slur #'thickness = #5.0
492     b[( g]) g |
493     g[( e]) 
494     % Revert thickness of all following slurs to default of 1.2
495     \revert Slur #'thickness
496     e d[( f]) a | 
497     a g
498   }
499   \addlyrics { 
500     The man who feels love's sweet e -- mo -- tion 
501   }
502 }
503 @end lilypond
504
505 @noindent
506 The @code{\revert} command can be used to return any property
507 changed with @code{\override} back to its default value.
508 You may use whichever method best suits what you want to do.
509
510 That concludes our introduction to the IR, and the basic
511 method of tweaking.  Several examples follow in the later
512 sections of this Chapter, partly to introduce you to some of the
513 additional features of the IR, and partly to give you more 
514 practice in extracting information from it.  These examples will
515 contain progressively fewer words of guidance and explanation. 
516
517 @node Properties found in interfaces
518 @subsection Properties found in interfaces
519
520 @cindex interface properties
521 @cindex properties in interfaces
522
523 Suppose now that we wish to print the lyrics in italics.  What
524 form of @code{\override} command do we need to do this?
525 We first look in the IR page listing @q{All layout objects}, as
526 before, and look for an object that might control lyrics.  We
527 find @code{LyricText}, which looks right.  Clicking on this shows
528 the settable properties for lyric text.  These include the 
529 @code{font-series} and @code{font-size}, but nothing that might
530 give an italic shape.   
531 This is because the shape property is one that is common to all
532 font objects, so, rather than including it in every layout
533 object, it is grouped together with other similar common
534 properties and placed in an @strong{Interface}, the 
535 @code{font-interface}.
536
537 So now we need to learn how to find the properties of interfaces,
538 and to discover what objects use these interface properties.
539
540 Look again at the IR page which describes LyricText.  At the
541 bottom of the page is a list of clickable (in the html versions
542 of the IR) interfaces which LyricText supports.  The list has 
543 seven items, including @code{font-interface}.  
544 Clicking on this brings up the properties associated
545 with this interface, which are also properties of all the objects
546 which support it, including LyricText.
547
548 Now we see all the user-settable properties which control fonts,
549 including @code{font-shape(symbol)}, where @code{symbol} can be
550 set to @code{upright}, @code{italics} or @code{caps}.
551
552 You will notice that that @code{font-series} and @code{font-size}
553 are also listed there.
554 This immediately raises the question: Why are the common font
555 properties @code{font-series} and @code{font-size} listed under
556 @code{LyricText} as well as under the interface 
557 @code{font-interface} but @code{font-shape} is not?  The answer
558 is that @code{font-series} and @code{font-size} are changed
559 from their global default values when a @code{LyricText} object
560 is created, but @code{font-shape} is not.  The entries in 
561 @code{LyricText} then tell you the values for those two
562 properties which apply to @code{LyricText}.  Other objects
563 which support @code{font-interface} will set these
564 properties diferently when they are created.
565
566 Let's see if we can now construct the @code{\override} command
567 to change the lyrics to italics.  The object is @code{LyricText},
568 the property is @code{font-shape} and the value is 
569 @code{italic}.  As before, we'll omit the context.
570
571 As an aside, although it is an important one, note that because 
572 the values of
573 @code{font-shape} are symbols they must be introduced with a
574 single apostrophe, @code{'}.  That is why apostrophes
575 are needed before @code{thickness} in the earlier example
576 and @code{font-shape}.  These are both symbols too.  
577 Symbols are special names which are known internally to 
578 LilyPond.  Some of them are the names of properties,
579 like @code{thickness} or @code{font-shape}, others are in
580 effect special values that can be given to properties, like
581 @code{italic}.  Note the distinction from arbitary
582 text strings, which would appear as @code{"a text string"}.
583
584 Ok, so the @code{\override} command we need to print the lyrics
585 in italics should be
586
587 @example
588   \override LyricText #'font-shape = #'italic
589 @end example
590
591 @noindent
592 and this should be placed just in front of and close to the
593 lyrics which it should affect, like this:
594
595 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
596 {
597   \time 6/8
598   {
599     r4 b8 b[( g]) g |
600     g[( e]) e d[( f]) a |
601     a g
602   }
603   \addlyrics {
604     \override LyricText #'font-shape = #'italic
605     The man who feels love's sweet e -- mo -- tion 
606   }
607 }
608 @end lilypond
609
610 @noindent
611 and the lyrics are all printed in italics.
612
613 @subheading Specifying context in lyric mode
614 @cindex context, specifying in lyric mode
615
616 In the case of lyrics, if you try specifying the context in the 
617 format given earlier the command will fail.  A syllable
618 entered in lyricmode is terminated by either a space,
619 a newline or a digit.  All other characters are included 
620 as part of the syllable.  For this reason a space or newline
621 must appear before the terminating @code{@}} to prevent it being
622 included as part of the final syllable.  Similarly,
623 spaces must be inserted before and after the
624 period or dot, @q{.}, separating the context name from the
625 object name, as otherwise the two names are run together and
626 the interpreter cannot recognise them.  So the command should be:
627
628 @example
629   \override Lyrics . LyricText #'font-shape = #'italic
630 @end example
631
632 @warning{In lyrics always leave whitespace between the final
633 syllable and the terminating brace.}
634
635 @warning{In overrides in lyrics always place spaces around
636 the dot between the context name and the object name.}
637
638 @node Types of properties
639 @subsection Types of properties
640
641 @cindex Property types
642
643 So far we have seen two types of property: @code{number} and
644 @code{symbol}.  To be valid, the value given to a property
645 must be of the correct type and obey the rules for that type.
646 The type of property is always shown in brackets after the
647 property name in the IR.  Here is a list of the types you may 
648 need, together with the rules for that type, and some examples.
649 You must always add a hash symbol, @code{#}, of course, 
650 to the front of these values when they are entered in the 
651 @code{\override} command.
652
653 @multitable @columnfractions .2 .45 .35
654 @headitem Property type           
655   @tab Rules
656   @tab Examples
657 @item Boolean
658   @tab Either True or False, represented by #t or #f
659   @tab @code{#t}, @code{#f}
660 @item Dimension (in staff space)
661   @tab A positive decimal number (in units of staff space)
662   @tab @code{2.5}, @code{0.34}
663 @item Direction
664   @tab A valid direction constant or its numerical equivalent
665   @tab @code{#LEFT}, @code{#CENTER}, @code{#UP}, 
666        @code{1}, @code{-1}
667 @item Integer
668   @tab A positive whole number
669   @tab @code{3}, @code{1}
670 @item List
671   @tab A bracketed set of items separated by spaces,
672 preceded by an apostrophe
673   @tab @code{'(left-edge staff-bar)}, @code{'(1)}, 
674        @code{'(1.0 0.25 0.5)}
675 @item Markup
676   @tab Any valid markup
677   @tab @code{\markup @{ \italic "cresc." @}}
678 @item Moment
679   @tab A fraction of a whole note constructed with the 
680 make-moment function
681   @tab @code{(ly:make-moment 1 4)}, 
682        @code{(ly:make-moment 3 8)}
683 @item Number
684   @tab Any positive or negative decimal value
685   @tab @code{3.5}, @code{-2.45}
686 @item Pair (of numbers)
687   @tab Two numbers separated by a @q{space . space} and enclosed
688 in brackets preceded by an apostrophe
689   @tab @code{'(2 . 3.5)}, @code{'(0.1 . -3.2)}
690 @item Symbol
691   @tab Any of the set of permitted symbols for that property,
692 preceded by an apostrophe
693   @tab @code{'italic}, @code{'inside}
694 @item Unknown
695   @tab A procedure or @code{#f} (to cause no action)
696   @tab @code{bend::print}, @code{ly:text-interface::print}, 
697        @code{#f}
698 @item Vector
699   @tab A list of three items enclosed in brackets and preceded
700 by a hash sign, @code{#}.
701   @tab @code{#(#t #t #f)} 
702 @end multitable
703
704 @node Appearance of objects
705 @section Appearance of objects
706
707 Let us now put what we have learnt into practice with a few
708 examples which show how tweaks may be used to change the 
709 appearance of the printed music.
710
711 @menu
712 * Visibility and color of objects::  
713 * Size of objects::             
714 @end menu
715
716 @node Visibility and color of objects
717 @subsection Visibility and color of objects
718
719 In the educational use of music we might wish to print a score
720 with certain elements omitted as an exercise for the student,
721 who is required to supply them.  As a simple example,
722 let us suppose the exercise is to supply the missing barlines 
723 in a piece of music.  But the barlines are normally inserted
724 automatically.  How do we prevent them printing?
725
726 As before, we go to the IR to find the layout object which prints
727 barlines.  Going via @emph{Backend} and @emph{All layout objects}
728 we find there
729 is a layout object called @code{BarLine}.  Its properties include
730 two that control its visibility: @code{break-visibility} and
731 @code{stencil}.  Barline also supports a number of interfaces, 
732 including the @code{grob-interface}, where we find the 
733 @code{transparent} and the @code{color} properties.  All
734 of these can affect the visibility of barlines (and, of course,
735 by extension, many other layout objects too.)  Let's consider
736 each of these in turn.
737
738 @subheading stencil
739 @cindex stencil property
740
741 This property controls the appearance of the barlines by specifying
742 the symbol (glyph) which should be printed.  In common
743 with many other properties, it can be set to print nothing by 
744 setting its value to @code{#f}.  Let's try it, as before, omitting
745 the implied Context, @code{Voice}:
746
747 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
748 {
749   \time 12/16
750   \override BarLine #'stencil = ##f
751   c4 b8 c d16 c d8 |
752   g, a16 b8 c d4 e16 |
753   e8
754 }
755 @end lilypond
756
757 The barlines are still printed.  What is wrong?  Go back to the
758 IR and look again at the page giving the properties of BarLine.
759 At the top of the page it says @qq{Barline objects are created
760 by: Bar_engraver}.  Go to the @code{Bar_engraver} page.
761 At the bottom
762 it gives a list of Contexts in which the bar engraver operates.
763 All of them are of the type @code{Staff}, so the reason the
764 @code{\override} command failed to work as expected is because
765 @code{Barline} is not in the default @code{Voice} context.
766 If the context
767 is specified wrongly, the command simply does not work.  No
768 error message is produced, and nothing is logged in the log
769 file.  Let's try correcting it by adding the correct context:
770
771 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
772 {
773   \time 12/16
774   \override Staff.BarLine #'stencil = ##f
775   c4 b8 c d16 c d8 |
776   g, a16 b8 c d4 e16 |
777   e8
778 }
779 @end lilypond
780
781 Now the barlines have vanished.
782
783 @subheading break-visibility
784
785 @cindex break-visibility property
786
787 We see from the @code{BarLine} properties in the IR that the 
788 @code{break-visibility} property requires a vector of three 
789 booleans.
790 These control respectively whether barlines are printed at
791 the end of a line, in the middle of lines, and at the beginning
792 of lines.  For our example we want all barlines to be suppressed,
793 so the value we need is @code{#(#f #f #f)}.  
794 Let's try that, remembering
795 to include the @code{Staff} context.  Note also that in writing
796 this value we have two hash signs before the opening bracket.
797 One is required as part of the value to introduce a vector, 
798 and one is required, as always, to precede the value itself in 
799 the @code{\override} command.
800
801 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
802 {
803   \time 12/16
804   \override Staff.BarLine #'break-visibility = ##(#f #f #f)
805   c4 b8 c d16 c d8 |
806   g, a16 b8 c d4 e16 |
807   e8
808 }
809 @end lilypond
810
811 And we see this too removes all the barlines.
812
813 @subheading transparent
814 @cindex transparent property
815
816 We see from the properties specified in the @code{grob-interface}
817 page in the IR that the @code{transparent} property is a boolean.
818 This
819 should be set to @code{#t} to make the grob transparent.
820 In this next example let us make the time signature invisible 
821 rather than the barlines.  
822 To do this we need to find the grob name for the time signature.
823 Back to
824 the @q{All layout objects} page in the IR to find the properties
825 of the @code{TimeSignature} layout object.  This is produced by
826 the @code{Time_signature_engraver} which you can check also lives
827 in the @code{Staff} context and also supports the 
828 @code{grob-interface}.  So the command to make the time signature
829 transparent is:
830
831 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
832 {
833   \time 12/16
834   \override Staff.TimeSignature #'transparent = ##t
835   c4 b8 c d16 c d8 |
836   g, a16 b8 c d4 e16 |
837   e8
838 }
839 @end lilypond
840
841 @noindent
842 The time signature is gone, but this command leaves a gap where 
843 the time signature should be.  Maybe this is what is wanted for
844 an exercise for the student to fill it in, but in other 
845 circumstances a gap might be undesirable.  To remove it, the 
846 stencil for the time signature should be set to @code{#f} 
847 instead:
848
849 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
850 {
851   \time 12/16
852   \override Staff.TimeSignature #'stencil = ##f
853   c4 b8 c d16 c d8 |
854   g, a16 b8 c d4 e16 |
855   e8
856 }
857 @end lilypond
858
859 @noindent
860 and the difference is obvious: setting the stencil to @code{#f}
861 removes the object entirely; making the object @code{transparent}
862 leaves it where it is, but makes it invisible.
863
864 @subheading color
865 @cindex color property
866
867 Finally we could make the barlines invisible by coloring
868 them white.  The @code{grob-interface} specifies that the
869 color property value is a list, but there is no
870 explanation of what that list should be.  The list it
871 requires is actually a list of values in internal units,
872 but, to avoid having to know what these are, several ways
873 are provided to specify colors.  The first way is to use one
874 of the @q{normal} colours listed in the first table in
875 @ruser{List of colors}.  To set the barlines to white
876 we write:
877
878 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
879 {
880   \time 12/16
881   \override Staff.BarLine #'color = #white
882   c4 b8 c d16 c d8 |
883   g, a16 b8 c d4 e16 |
884   e8
885 }
886 @end lilypond
887
888 @noindent
889 and again, we see the barlines are not visible.  Note that
890 @emph{white} is not preceded by an apostrophe -- it is not
891 a symbol, but a @emph{function}.  When called, it provides
892 the list of internal values required to set the color to
893 white.  The other colors in the normal list are functions
894 too.  To convince yourself this is working you might like 
895 to change the color to one of the other functions in the
896 list.
897
898 @cindex color, X11
899 @cindex X11 colors
900
901 The second way of changing the color is to use the list of
902 X11 color names in the second list in @ruser{List of colors}.
903 However, these must be preceded by another function, which
904 converts X11 color names into the list of internal values,
905 @code{x11-color}, like this:
906
907 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
908 {
909   \time 12/16
910   \override Staff.BarLine #'color = #(x11-color 'white)
911   c4 b8 c d16 c d8 |
912   g, a16 b8 c d4 e16 |
913   e8
914 }
915 @end lilypond
916
917 @noindent
918 Note that in this case the function @code{x11-color} takes
919 a symbol as an argument, so the symbol must be preceded by
920 an apostrophe and the two enclosed in brackets.
921
922 @cindex rgb colors
923 @cindex color, rgb
924
925 There is yet a third function, one which converts RGB values into
926 internal colors -- the @code{rgb-color} function.  This takes
927 three arguments giving the intensities of the red, green and 
928 blue colors.  These take values in the range 0 to 1.  So to
929 set the color to red the value should be @code{(rgb-color 1 0 0)}
930 and to white it should be @code{(rgb-color 1 1 1)}:
931
932 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
933 {
934   \time 12/16
935   \override Staff.BarLine #'color = #(rgb-color 1 1 1)
936   c4 b8 c d16 c d8 |
937   g, a16 b8 c d4 e16 |
938   e8
939 }
940 @end lilypond
941
942 Finally, there is also a grey scale available as part of the
943 X11 set of colors.  These range from black, @code{'grey0'},
944 to white, @code{'grey100}, in steps of 1.  Let's illustrate
945 this by setting all the layout objects in our example to
946 various shades of grey:
947
948 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
949 {
950   \time 12/16
951   \override Staff.StaffSymbol   #'color = #(x11-color 'grey30)
952   \override Staff.TimeSignature #'color = #(x11-color 'grey60)
953   \override Staff.Clef          #'color = #(x11-color 'grey60)
954   \override Voice.NoteHead      #'color = #(x11-color 'grey85)
955   \override Voice.Stem          #'color = #(x11-color 'grey85)
956   \override Staff.BarLine       #'color = #(x11-color 'grey10)
957   c4 b8 c d16 c d8 |
958   g, a16 b8 c d4 e16 |
959   e8
960 }
961 @end lilypond
962
963 @noindent
964 Note the contexts associated with each of the layout objects.
965 It is important to get these right, or the commands will not
966 work!  Remember, the context is the one in which the appropriate
967 engraver is placed.  The default context for engravers can be
968 found by starting from the layout object, going from there to
969 the engraver which produces it, and on the engraver page in the
970 IR it tells you in which context the engraver will normally be 
971 found.  
972
973
974 @node Size of objects
975 @subsection Size of objects
976
977 Let us begin by looking again at the earlier example 
978 see @ref{Nesting music expressions}) which showed
979 how to introduce a new temporary staff, as in an @rglos{ossia}.  
980
981 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
982 \new Staff ="main" {
983        \relative g' {
984          r4 g8 g c4 c8 d |
985          e4 r8
986          <<
987            { f c c }
988            \new Staff \with {
989              alignAboveContext = "main" }
990            { f8 f c }
991          >>
992          r4 |
993        }
994      }
995 @end lilypond
996
997 Ossia are normally written without clef and time signature, and
998 are usually printed slightly smaller than the main staff.  We
999 already know now how to remove the clef and time signature --
1000 we simply set the stencil of each to @code{#f}, as follows:
1001
1002 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1003 \new Staff ="main" {
1004   \relative g' {
1005     r4 g8 g c4 c8 d |
1006     e4 r8
1007     <<
1008       { f c c }
1009       \new Staff \with {
1010         alignAboveContext = "main" 
1011       }
1012       {
1013         \override Staff.Clef #'stencil = ##f
1014         \override Staff.TimeSignature #'stencil = ##f
1015         { f8 f c }
1016       }
1017     >>
1018     r4 |
1019   }
1020 }
1021 @end lilypond
1022
1023 @noindent
1024 where the extra pair of braces after the @code{\with} clause are
1025 required to ensure the enclosed overrrides and music are applied
1026 to the ossia staff.
1027
1028 But what is the difference between modifying the staff context by 
1029 using @code{\with} and modifying the stencils of the clef and the
1030 time signature with \override?  The main difference is that 
1031 changes made in a @code{\with} clause are made at the time the
1032 context is created, and remain in force as the @strong{default}
1033 values for the duration of that context, whereas
1034 @code{\set} or @code{\override} commands embedded in the
1035 music are dynamic -- they make changes synchronised with
1036 a particular point in the music.  If changes are unset or
1037 reverted using @code{\unset} or @code{\revert} they return to
1038 their default values, which will be the ones set in the 
1039 @code{\with} clause, or if none have been set there, the normal
1040 default values.
1041
1042 Some context properties
1043 can be modified only in @code{\with} clauses.  These are those
1044 properties which cannot sensibly be changed after the context 
1045 has been created.  @code{alignAboveContext} and its partner,
1046 @code{alignBelowContext}, are two such properties -- once the
1047 staff has been created its alignment is decided and it would
1048 make no sense to try to change it later.
1049
1050 The default values of layout object properties can also be set
1051 in @code{\with} clauses.  Simply use the normal @code{\override}
1052 command leaving out the context name, since this is unambiguously
1053 defined as the context which the @code{\with} clause is modifying.
1054 If fact, an error will be generated if a context is specified
1055 in this location.
1056
1057 So we could replace the example above with
1058
1059 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1060 \new Staff ="main" {
1061   \relative g' {
1062     r4 g8 g c4 c8 d |
1063     e4 r8
1064     <<
1065       { f c c }
1066       \new Staff \with {
1067         alignAboveContext = "main" 
1068         % Don't print clefs in this staff
1069         \override Clef #'stencil = ##f
1070         % Don't print time signatures in this staff
1071         \override TimeSignature #'stencil = ##f
1072       }
1073         { f8 f c }
1074     >>
1075     r4 |
1076   }
1077 }
1078 @end lilypond
1079
1080 Finally we come to changing the size of layout objects.
1081
1082 Some layout objects are created as glyphs selected from
1083 a typeface font.  These include noteheads, accidentals, markup, 
1084 clefs, time signatures, dynamics and lyrics.  
1085 Their size is changed by modifying the
1086 @code{font-size} property, as we shall shortly see.  Other 
1087 layout objects such as slurs and ties -- in general, spanner
1088 objects -- are drawn individually, so there is no 
1089 @code{font-size}
1090 associated with them.  These objects generally derive their
1091 size from the objects to which they are attached, so usually
1092 there is no need to change their size manually.  Still other 
1093 properties such as the length of stems and barlines, thickness 
1094 of beams and other lines, and the separation of staff lines all 
1095 need to be modified in special ways. 
1096
1097 Returning to the ossia example, let us first change the font-size.
1098 We can do this in two ways.  We can either change the size of the
1099 fonts of each object type, like @code{NoteHead}s with commands
1100 like
1101
1102 @example
1103 \override NoteHead #'font-size = #-2
1104 @end example
1105
1106 or we can change the size of all fonts by setting a special
1107 property, @code{fontSize}, using @code{\set}, or by including
1108 it in a @code{\with} clause (but without the @code{\set}).
1109
1110 @example
1111 \set fontSize = #-2
1112 @end example
1113
1114 Both of these statements would cause the font size to be reduced
1115 by 2 steps from its previous value, where each
1116 step reduces or increases the size by approximately 12%.
1117
1118 Let's try it in our ossia example:
1119
1120 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1121 \new Staff ="main" {
1122   \relative g' {
1123     r4 g8 g c4 c8 d |
1124     e4 r8
1125     <<
1126       { f c c }
1127       \new Staff \with {
1128         alignAboveContext = "main" 
1129         \override Clef #'stencil = ##f
1130         \override TimeSignature #'stencil = ##f
1131         % Reduce all font sizes by ~24%
1132         fontSize = #-2
1133       }
1134         { f8 f c }
1135     >>
1136     r4 |
1137   }
1138 }
1139 @end lilypond
1140
1141 This is still not quite right.  The noteheads and flags are 
1142 smaller, but the stems are too long in proportion and the
1143 staff lines are spaced too widely apart.  These need to be
1144 scaled down in proportion to the font reduction.
1145
1146 @cindex magstep
1147 @cindex size, changing
1148 @cindex stem length, changing
1149 @cindex staff line spacing, changing
1150
1151 This can be done with the help of a special function called
1152 @code{magstep} provided for exactly this purpose.  It takes
1153 one argument, the change in font size (#-2 in the example above)
1154 and returns a scaling factor suitable for reducing other
1155 objects in proportion.  It is used like this:
1156
1157 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1158 \new Staff ="main" {
1159   \relative g' {
1160     r4 g8 g c4 c8 d |
1161     e4 r8
1162     <<
1163       { f c c }
1164       \new Staff \with {
1165         alignAboveContext = "main" 
1166         \override Clef #'stencil = ##f
1167         \override TimeSignature #'stencil = ##f
1168         fontSize = #-2
1169         % Reduce stems and line spacing to match
1170         \override StaffSymbol #'staff-space = #(magstep -2)
1171       }
1172         { f8 f c }
1173     >>
1174     r4 |
1175   }
1176 }
1177 @end lilypond
1178
1179 @noindent
1180 Since the length of stems and many other length-related properties
1181 are always calculated relative to the
1182 value of the @code{staff-space} property these are automatically
1183 scaled down in length too.  Note that this affects only the
1184 vertical scale of the ossia -- the horizontal scale is determined 
1185 by the layout of the main music in order to remain synchronised 
1186 with it, so it is not affected by any of these changes in size.
1187 Of course, if the scale of all the main music were changed in this
1188 way then the horizontal spacing would be affected.  This is 
1189 discussed later in the layout section.
1190
1191 This, then, completes the creation of an ossia.  The sizes of all
1192 other objects may be modified in analogous ways.
1193
1194 @node Placement of objects
1195 @section Placement of objects
1196
1197 @menu
1198 * Automatic behaviour::         
1199 * Within-staff objects::        
1200 * Outside staff objects::       
1201 @end menu
1202
1203
1204 @node Automatic behaviour
1205 @subsection Automatic behaviour
1206
1207 There are some objects in musical notation that belong to
1208 the staff and there are other objects that should be 
1209 placed outside the staff.  These are called within-staff
1210 objects and outside-staff objects respectively.
1211
1212 Within-staff objects are those that are located on the staff
1213 -- note heads, stems, accidentals, etc.  The positions of
1214 these are usually fixed by the music itself -- they are
1215 vertically positioned on specific lines of the staff or are 
1216 tied to other objects that are so positioned.  Collisions of
1217 noteheads, stems and accidentals in closely set chords are
1218 normally avoided automatically.  There are commands and
1219 overrides which can modify this automatic behaviour, as we
1220 shall shortly see.
1221
1222 Objects belonging outside the staff include things 
1223 such as rehearsal marks, text and dynamic markings. 
1224 LilyPond’s rule for the 
1225 vertical placement of outside-staff objects is to place them as 
1226 close to the staff as possible but not so close that they 
1227 collide with any other object.  LilyPond uses the 
1228 @code{outside-staff-priority} property to determine the order 
1229 in which the objects should be placed, as follows.
1230
1231 First, LilyPond places all the within-staff objects.
1232 Then it sorts the outside-staff objects according to their 
1233 @code{outside-staff-priority}.  The outside-staff objects are
1234 taken one by one, beginning with the object with the lowest
1235 @code{outside-staff-priority}, and placed so that they do not 
1236 collide with any objects that have already been placed. That is, 
1237 if two outside-staff grobs are competing for the same space, the 
1238 one with the lower @code{outside-staff-priority} will be placed 
1239 closer to the staff.  If two objects have the same
1240 @code{outside-staff-priority} the one encountered first will be
1241 placed closer to the staff.
1242
1243 In the following example all the markup texts have the same 
1244 priority (since it is not explicity set).  Note that @q{Text3}
1245 is automatically positioned close to the staff again, nestling
1246 under @q{Text2}.
1247
1248 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1249 c2^"Text1"
1250 c^"Text2"
1251 c^"Text3"
1252 c^"Text4"
1253 @end lilypond
1254
1255 Staves are also positioned, by default, as closely together as
1256 possible (subject to a minimum separation).  If notes project
1257 a long way towards an adjacent staff they will force the
1258 staves further apart only if an overlap of the notation
1259 would otherwise occur.  The following example demonstrates
1260 this @q{nestling} of the notes on adjacent staves:
1261
1262 @lilypond[quote,ragged-right,verbatim]
1263 <<
1264   \new Staff {
1265     \relative c' { c a, }
1266   }
1267   \new Staff {
1268     \relative c'''' { c a, }
1269   }
1270 >>
1271 @end lilypond 
1272
1273 @c TODO Mention somewhere, probably not here, how to avoid staves
1274 @c interleaving too much by specifying skyline-horizontal-padding
1275 @c Presumably this moves the skyline boundary further out, making
1276 @c objects appear wider?  Not yet tested.  -td
1277
1278 @node Within-staff objects
1279 @subsection Within-staff objects
1280
1281 We have already seen how the commands @code{\voiceXXX} affect
1282 the direction of slurs, ties, fingering and 
1283 everything else which depends on the direction of the stems.
1284 These commands are essential when writing polyphonic music to
1285 permit interweaving melodic lines to be distinguished.
1286 But occasionally it may be necessary to override this automatic
1287 behaviour.  This can be done for whole sections of music or even
1288 for an individual note.  The property which controls this
1289 behaviour is the @code{direction} property of each layout object.
1290 We first explain what this does, and then introduce a number of
1291 ready-made commands which avoid your having to code explicit
1292 overrides for the more common modifications.
1293
1294 Some layout objects like slurs and ties curve, bend or point 
1295 either up or down; others like stems and flags also move to
1296 right or left when they point up or down.  This is controlled
1297 automatically when @code{direction} is set.
1298
1299 The following example shows in bar 1 the default behaviour of 
1300 stems, 
1301 with those on high notes pointing down and those on low notes
1302 pointing up, followed by four notes with all stems forced down, 
1303 four notes with all stems forced up, and finally four notes
1304 reverted back to the default behaviour.
1305
1306 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1307 a4 g c a
1308 \override Stem #'direction = #DOWN
1309 a g c a
1310 \override Stem #'direction = #UP
1311 a g c a
1312 \revert Stem #'direction
1313 a g c a
1314 @end lilypond
1315
1316 Here we use the constants @code{DOWN} and @code{UP}.
1317 These have the values @code{-1} and @code{+1} respectively, and
1318 these numerical values may be used instead.  The value @code{0}
1319 may also be used in some cases.  It is simply treated as meaning
1320 @code{UP} for stems, but for some objects it means @q{center}.
1321 There is a constant, @code{CENTER} which has the value @code{0}.
1322
1323 However, these explicit overrides are not usually used, as there
1324 are simpler equivalent predefined commands available.  
1325 Here is a table of the commonest.  The meaning of each is stated
1326 where it is not obvious.
1327
1328 @c TODO put @code{} round all these
1329
1330 @multitable @columnfractions .2 .2 .2 .4
1331 @headitem Down/Left           
1332   @tab Up/Right
1333   @tab Revert
1334   @tab Effect 
1335 @item \arpeggioDown
1336   @tab \arpeggioUp
1337   @tab \arpeggioNeutral
1338   @tab Arrow is at bottom, at top, or no arrow
1339 @item \dotsDown
1340   @tab \dotsUp
1341   @tab \dotsNeutral
1342   @tab Direction of movement to avoid staff lines
1343 @item \dynamicDown
1344   @tab \dynamicUp
1345   @tab \dynamicNeutral
1346   @tab
1347 @item \phrasingSlurDown
1348   @tab \phrasingSlurUp
1349   @tab \phrasingSlurNeutral
1350   @tab Note: distinct from slur commands
1351 @item \slurDown     
1352   @tab \slurUp
1353   @tab \slurNeutral
1354   @tab
1355 @item \stemDown
1356   @tab \stemUp
1357   @tab \stemNeutral
1358   @tab
1359 @item \textSpannerDown
1360   @tab \textSpannerUp
1361   @tab \textSpannerNeutral
1362   @tab Text entered as spanner is below/above staff
1363 @item \tieDown
1364   @tab \tieUp
1365   @tab \tieNeutral
1366   @tab
1367 @item \tupletDown
1368   @tab \tupletUp
1369   @tab \tupletNeutral
1370   @tab Tuplets are below/above notes
1371 @end multitable
1372
1373 Note that these predefined commands may @strong{not} be 
1374 preceded by @code{\once}.  If you wish to limit the
1375 effect to a single note you must either use the equivalent
1376 @code{\once \override} command or use the predefined command
1377 followed after the affected note by the corresponding 
1378 @code{\xxxNeutral} command.
1379
1380 @subheading Fingering
1381 @cindex fingering, placement
1382
1383 The placement of fingering is also affected by the value
1384 of its @code{direction} property, but there are special
1385 commands which allow the fingering of individual notes
1386 of chords to be controlled, with the fingering being placed
1387 above, below, to the left or to the right of each note.
1388
1389 First, here's the effect of @code{direction} on fingering,
1390 the first bar shows the default, then the effect of specifying
1391 @code{DOWN} and @code{UP}:
1392
1393 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1394 c-5 a-3 f-1 c'-5
1395 \override Fingering #'direction = #DOWN
1396 c-5 a-3 f-1 c'-5
1397 \override Fingering #'direction = #UP
1398 c-5 a-3 f-1 c'-5
1399 @end lilypond
1400
1401 This is how to control fingering on single notes, but the 
1402 @code{direction}
1403 property is ignored for chords.  Instead, by default, the
1404 fingering is automatically placed both above and below the 
1405 notes of a chord, as shown:
1406
1407 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1408 <c-5 g-3>
1409 <c-5 g-3 e-2>
1410 <c-5 g-3 e-2 c-1>
1411 @end lilypond
1412
1413 Greater control over the placement of fingering of the 
1414 individual notes in a chord is possible by using
1415 the @code{\set fingeringOrientations} command.  The format of
1416 this command is
1417
1418 @example
1419 @code{\set fingeringOrientations = #'([up] [left/right] [down])}
1420 @end example
1421
1422 @noindent
1423 @code{\set} is used because @code{fingeringOrientations} is a
1424 property of the @code{Voice} context, created and used by the
1425 @code{New_fingering_engraver}.
1426
1427 The property may be set to a list of one to three values.
1428 It controls whether fingerings may be placed above (if 
1429 @code{up} appears in the list), below (if @code{down} appears), 
1430 to the left (if @code{left} appears, or to the right 
1431 (if @code{right} appears).  Conversely, if a location is not
1432 listed, no fingering is placed there.  LilyPond takes these 
1433 contraints and works out the best placement for the fingering
1434 of the notes of the following chords.  Note that @code{left} and
1435 @code{right} are mutually exclusive -- fingering may be placed
1436 only on one side or the other, not both.
1437
1438 To control the placement of the fingering of a single note 
1439 using this command it is necessary to write it as a single 
1440 note chord by placing angle brackets round it.
1441   
1442 Here are a few examples:
1443
1444 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1445 \set fingeringOrientations = #'(left)
1446 <f-2>
1447 < c-1  e-2 g-3 b-5 > 4
1448 \set fingeringOrientations = #'(left)
1449 <f-2>
1450 < c-1  e-2 g-3 b-5 > 4
1451 \set fingeringOrientations = #'(up left down)
1452 <f-2>
1453 < c-1  e-2 g-3 b-5 > 4
1454 \set fingeringOrientations = #'(up left)
1455 <f-2>
1456 < c-1  e-2 g-3 b-5 > 4
1457 \set fingeringOrientations = #'(right)
1458 <f-2>
1459 < c-1  e-2 g-3 b-5 > 4
1460 @end lilypond 
1461
1462 @noindent
1463 If the fingering seems a little crowded the @code{font-size}
1464 could be reduced.  The default value can be seen from the
1465 @code{Fingering} object in the IR to be @code{-5}, so let's
1466 try @code{-7}:
1467
1468 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1469 \override Fingering #'font-size = #-7
1470 \set fingeringOrientations = #'(left)
1471 <f-2>
1472 < c-1  e-2 g-3 b-5 > 4
1473 \set fingeringOrientations = #'(left)
1474 <f-2>
1475 < c-1  e-2 g-3 b-5 > 4
1476 \set fingeringOrientations = #'(up left down)
1477 <f-2>
1478 < c-1  e-2 g-3 b-5 > 4
1479 \set fingeringOrientations = #'(up left)
1480 <f-2>
1481 < c-1  e-2 g-3 b-5 > 4
1482 \set fingeringOrientations = #'(right)
1483 <f-2>
1484 < c-1  e-2 g-3 b-5 > 4
1485 @end lilypond
1486
1487 @node Outside staff objects
1488 @subsection Outside staff objects
1489
1490 Outside-staff objects are automatically placed to avoid collisions.
1491 Objects with the lower value of @code{outside-staff-priority} 
1492 property are placed nearer to the staff, and other outside-staff
1493 objects are then raised as far as necessary to avoid collisions.  
1494 The @code{outside-staff-priority} is defined in the 
1495 @code{grob-interface} and so is a property of all layout objects.
1496 It is set to @code{#f} (the default) for all within-staff objects,
1497 and is set explicitly to the default numerical value appropriate 
1498 to the each object as it is created.  The following table shows
1499 the default numerical values for some of the commonest 
1500 outside-staff objects.  Others may be found in the object 
1501 properties listed in the IR.
1502
1503 @multitable @columnfractions .3 .3 
1504 @headitem Layout Object           @tab Priority
1505 @item @code{BarNumber}            @tab @code{ 100}
1506 @item @code{DynamicLineSpanner}   @tab @code{ 250}
1507 @item @code{DynamicText}          @tab @code{ 250}
1508 @item @code{MetronomeMark}        @tab @code{1000}
1509 @item @code{OttavaBracket}        @tab @code{ 400}
1510 @item @code{RehearsalMark}        @tab @code{1500}
1511 @item @code{TextScript}           @tab @code{ 450}
1512 @end multitable
1513
1514 TODO Add example showing iteraction of all these
1515
1516 If this ordering does not give you the placing you want, the
1517 priority of the objects may be overridden.  Suppose we would
1518 like @qq{Text3} to be placed above @qq{Text4} in the example
1519 under Automatic behaviour, above (see @ref{Automatic behaviour}).
1520 All we need to do is to look up the priority of @code{TextScript}
1521 in the IR or in the table above, and increase the priority of
1522 @qq{Text3} to a higher value:
1523
1524 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1525 c2^"Text1"
1526 c^"Text2"
1527 \once \override TextScript #'outside-staff-priority = #500
1528 c^"Text3"
1529 c^"Text4"
1530 @end lilypond
1531
1532 This certainly lifts @qq{Text3} above @qq{Text4} but it also
1533 lifts it above @qq{Text2}, and @qq{Text4} now drops down.
1534 Perhaps this is not so good.  Can we instead position them all
1535 at the same distance from the staff?  To do this, we clearly
1536 will need to space the notes out horizontally to make more
1537 room for the text.  This is done using the @code{fatText}
1538 command.
1539
1540 @subheading \fatText
1541
1542 @funindex \fatText
1543 @cindex notes, spreading out with text
1544
1545 By default, text produced by markup takes up no horizontal space
1546 as far as laying out the music is concerned.  The @code{\fatText} 
1547 command reverses this behaviour, causing the notes to be spaced 
1548 out as far as is necessary to accommodate the text:
1549
1550 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1551 \fatText  % Cause notes to space out to accommodate text
1552 c2^"Text1"
1553 c^"Text2"
1554 c^"Text3"
1555 c^"Text4"
1556 @end lilypond  
1557
1558 The command to revert to the default behaviour is 
1559 @code{\emptyText}.  Remember @code{\once} only works with
1560 @code{\override}, @code{\set}, @code{\revert} or @code{unset},
1561 so cannot be used with @code{\fatText}.
1562
1563 Markup text will also avoid notes which project above the staff.
1564 If this is not desired, the automatic displacement upwards may
1565 be turned off by setting the priority to @code{#f}.  Here's an
1566 example to show how markup text interacts with such notes.
1567
1568 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1569 % This markup is short enough to fit without collision
1570 c2^"Tex"
1571 c''2
1572 R1
1573 % This is too long to fit, so it is displaced upwards
1574 c,,2^"Text"
1575 c''2
1576 R1
1577 % Turn off collision avoidance
1578 \once \override TextScript #'outside-staff-priority = ##f
1579 c,,2^"Long Text   "
1580 c''2
1581 R1
1582 % Turn off collision avoidance
1583 \once \override TextScript #'outside-staff-priority = ##f
1584 \fatText  % and turn on fatText
1585 c,,2^"Long Text   "  % Spaces at end are honoured
1586 c''2
1587 @end lilypond
1588
1589
1590 @subheading Dynamics
1591
1592 Dynamic markings will normally be positioned beneath the
1593 staff, but may be positioned above with the @code{dynamicUp}
1594 command.  They will be positioned vertically relative to the
1595 note to which they are attached, and will float below (or above)
1596 all within-staff objects such as phrasing slurs and bar numbers.
1597 This can give quite acceptable results, as this example
1598 shows:
1599
1600 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
1601 \clef "bass"
1602 \key aes \major
1603 \time 9/8
1604 \dynamicUp
1605 bes4.~\f\< \( bes4 bes8 des4\ff\> c16 bes\! |
1606 ees,2.~\)\mf ees4 r8 |
1607 @end lilypond
1608
1609 However, if the notes and attached dynamics are close
1610 together the automatic placement will avoid collisions
1611 by displacing later dynamic markings further away, but this may 
1612 not be the optimum placement, as this rather artificial example
1613 shows:
1614
1615 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1616 \dynamicUp
1617 a4\f b\mf c\mp b\p
1618 @end lilypond
1619
1620 @noindent
1621 Should a similar situation arise in @q{real} music, it may 
1622 be preferable to space out the notes
1623 a little further, so the dynamic markings can all fit at the
1624 same vertical distance from the staff.  We were able to do this
1625 for markup text by using the @code{\fatText} command, but there
1626 is no equivalent command for dynamic marks.  So we shall have to
1627 work out how to do this using @code{\override} commands.
1628
1629 @subheading Grob sizing
1630
1631 @cindex grob sizing
1632 @cindex sizing grobs
1633 @cindex @code{X-offset}
1634 @cindex @code{Y-offset}
1635 @cindex @code{X-extent}
1636 @cindex @code{Y-extent}
1637
1638 First we must learn how grobs are sized.  All grobs have a
1639 reference point defined within them which is used to position 
1640 them relative to their parent object.  This point in the grob
1641 is then positioned at a horizontal distance, @code{X-offset},
1642 and at a vertical distance, @code{Y-offset}, from its parent.
1643 The horizontal extent of the object is given by a pair of
1644 numbers, @code{X-extent}, which say where the left and right
1645 edges are relative to the reference point.  The vertical extent
1646 is similarly defined by a pair of numbers, @code{Y-extent}.
1647 These are properties of all grobs which support the 
1648 @code{grob-interface}.
1649
1650 @cindex @code{extra-spacing-width}
1651
1652 By default, outside-staff objects are given a width of zero so
1653 that they may overlap in the horizontal direction.  This is done
1654 by by the trick of adding infinity to the leftmost extent and 
1655 minus infinity to the rightmost extent by setting the 
1656 @code{extra-spacing-width} to @code{'(+inf.0 . -inf.0)}.  So
1657 to ensure they do not overlap in the horizontal direction we
1658 must override this value of @code{extra-spacing-width} to
1659 @code{'(0 . 0)} so the true width shines through.  This is
1660 the command to do this for dynamic text:
1661
1662 @example
1663 \override DynamicText #'extra-spacing-width = #'(0 . 0)
1664 @end example
1665
1666 @noindent
1667 Let's see if this works in our previous example:
1668
1669 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1670 \dynamicUp
1671 \override DynamicText #'extra-spacing-width = #'(0 . 0)
1672 a4\f b\mf c\mp b\p
1673 @end lilypond
1674
1675 @noindent
1676 Well, it has certainly stopped the dynamic marks being
1677 displaced, but two problems remain.  The marks should be
1678 spaced a little further apart and it would be better
1679 if they were all the same distance from the staff.
1680 We can solve the first problem easily.  Instead of making
1681 the @code{extra-spacing-width} zero we could add a little
1682 more to it.  The units are the space between two staff
1683 lines, so moving the left edge half a unit to the left and the
1684 right edge half a unit to the right should do it:
1685
1686 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1687 \dynamicUp
1688 % Extend width by 1 staff space
1689 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
1690 a4\f b\mf c\mp b\p
1691 @end lilypond
1692
1693 @noindent
1694 This looks better, but maybe we would prefer the dynamic marks
1695 to be aligned along the same baseline rather than going up and
1696 down with the notes.  There is a property to control this, but
1697 it is not so easy to find in the IR.  It is not a property of
1698 @code{DynamicText} but of @code{DynamicLineSpanner}.  
1699 This is because the baseline should apply equally to @strong{all}
1700 dynamics, including those created as extended spanners.
1701 So this is the way to align the dynamic marks in our example: 
1702
1703 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1704 \dynamicUp
1705 % Extend width by 1 unit
1706 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
1707 % Align dynamics to a base line 2 units above staff
1708 \override DynamicLineSpanner #'staff-padding = #2
1709 a4\f b\mf c\mp b\p
1710 @end lilypond
1711
1712
1713
1714 @node Collisions of objects
1715 @section Collisions of objects
1716
1717 @menu
1718 * Moving objects::              
1719 * Fixing overlapping notation::  
1720 @end menu
1721
1722 @node Moving objects
1723 @subsection Moving objects
1724
1725 This may come as a surprise, but LilyPond is not perfect.  Some 
1726 notation elements can overlap.  This is unfortunate, but in fact 
1727 rather rare.  Usually the need to move objects is for clarity or
1728 aesthetic reasons -- they would look better with a little more
1729 space around them.
1730
1731 There are three main main approaches to resolving overlapping
1732 notation.  They should be considered in the following order:
1733
1734 @enumerate
1735 @item
1736 The @strong{direction} of one of the overlapping objects may
1737 be changed using the predefined commands listed above for
1738 within-staff objects (see @ref{Within-staff objects}).
1739 Stems, slurs, beams, ties, dynamics, text and tuplets may be
1740 repositioned easily in this way.  The limitation is that you
1741 have a choice of only two positions, and neither may be
1742 suitable.
1743
1744 @item
1745 The @strong{object properties} taken into account by LilyPond
1746 when positioning the objects may be modified.  The advantages
1747 of making changes to this type of property are (a) that some
1748 other objects will be moved automatically if necessary to make
1749 room and (b) the single change can apply to all instances of
1750 the same type of object.  Such properties include:
1751
1752 @itemize @bullet
1753 @item @code{direction}
1754
1755 This has already been covered in some detail -- see
1756 @ref{Within-staff objects}.
1757
1758 @item @code{left-padding}, @code{padding}, 
1759       @code{right-padding}, @code{staff-padding}
1760 @cindex left-padding property
1761 @cindex padding property
1762 @cindex right-padding property
1763
1764 The @code{padding} property specifies the gap that must be left 
1765 between
1766 the top and bottom edges of objects which are positioned
1767 either above or below another previously placed object, or
1768 between the sides of objects which are positioned to the left or
1769 right of previously placed objects.
1770 Instead of @code{padding} some objects have instead a
1771 @code{left-padding} or @code{right-padding} property.
1772 All padding values are measured in staff spaces.  For most
1773 objects, this value is set by default to be around 1.0 or less
1774 (it varies with each object).  It may be overridden if a larger
1775 (or smaller) gap is required.
1776
1777 The @code{staff-padding} property is closely related.  @code{padding}
1778 controls the minimum amount of space between an object and the nearest
1779 other object (generally the note or the staff lines);
1780 @code{staff-padding} controls the minimum amount of space between an
1781 object and the staff.
1782
1783 To discover which padding property is required for the object
1784 you wish to reposition, you
1785 need to return to the IR and look up the object's properties.
1786 Be aware that the padding property might not be located in the
1787 obvious object.  For example, the placement of accidentals is
1788 controlled by @code{left-padding} and @code{right-padding},
1789 but these are to be found in the @code{AccidentalPlacement}
1790 object.
1791
1792 @item @code{self-alignment-X}
1793
1794 This property aligns the object to the left, to the right, or
1795 centers it with respect to the parent object's reference point.
1796 It may be used with all objects which support the
1797 @code{self-alignment-interface} -- in general these are objects
1798 that contain text.  The values are @code{LEFT}, @code{RIGHT}
1799 or @code{CENTER}.  The movement is limited by the length of the
1800 object.
1801
1802 @end itemize
1803
1804 Objects do not all have all of these properties in general.
1805 It is necessary to go to the IR to look up which properties
1806 are available for the object in question.
1807
1808 @item
1809 Finally, when all else fails, objects may be repositioned manually
1810 by changing their separation distance from other objects, or by
1811 repositioning them relative to the staff center line.  The
1812 disadvantages are that the correct values for the repositioning
1813 have to be worked out, often by trial and error, for every object
1814 individually, and the user is responsible for any collisions that
1815 might follow.  But the main difficulty with this approach is that
1816 the repositioning values may need to be reworked if the music is
1817 later modified.  The properties that can be used for this type of
1818 repositioning are:
1819
1820 @itemize @bullet
1821 @item @code{extra-offset}
1822 @cindex extra-offset property
1823
1824 This property applies to any layout object
1825 supporting the @code{grob-interface}.  It takes a pair of
1826 numbers giving the extra displacement in the horizontal and
1827 vertical directions.  Negative numbers move the object to
1828 the left or down.  The units are staff-spaces.  The extra
1829 displacement is made after the typesetting of objects is
1830 finished, so an object may be repositioned anywhere without
1831 affecting anything else.
1832
1833 @item @code{force-hshift}
1834 @cindex force-hshift property
1835
1836 Closely spaced notes in a chord, or notes occuring at the same
1837 time in different voices, are arranged in two, occasionally more,
1838 columns to prevent the noteheads overlapping.  These are called
1839 note columns, and an object called @code{NoteColumn} is created
1840 to lay out the notes in that column.  There are separate columns
1841 for each voice.  The @code{force-hshift}
1842 property is a property of a @code{NoteColumn} (actually of the
1843 @code{note-column-interface}).  Changing it permits a note column
1844 to be moved in units appropriate to a note column, viz. the note
1845 head width of the first voice note.  It is preferable to the
1846 @code{extra-offset} property for this purpose as there is no need
1847 to work out the distance in staff-spaces.
1848
1849 @item @code{positions}
1850 @cindex positions property
1851
1852 This is most useful for manually adjusting the slope and height
1853 of beams, ties, slurs, and tuplets.   It takes a pair of numbers
1854 giving the position of the left and right ends of the beam, slur,
1855 etc. relative to the center line of the staff.  Units are
1856 staff-spaces.
1857
1858 @item @code{staff-position}
1859 @cindex staff-position property
1860
1861 @code{staff-position} is a property of the
1862 @code{staff-symbol-referencer-interface}, which is supported by
1863 objects which are positioned relative to the staff.  It specifies
1864 the vertical position of the object relative to the center line
1865 of the staff in half staff-spaces.
1866
1867 @end itemize
1868
1869 Objects do not all have all of these properties in general.
1870 It is necessary to go to the IR to look up which properties
1871 are available for the object in question.
1872
1873 @end enumerate
1874
1875 Here is a list of the objects which are most likely to be
1876 involved in collisions, together with the name of the object which
1877 should be looked up in the IR in order to discover which properties
1878 should be used to move them.
1879
1880 @multitable @columnfractions .33 .66
1881 @headitem Object type           @tab Object name
1882 @item Articulations             @tab @code{Script}
1883 @item Dynamics (vertically)     @tab @code{DynamicLineSpanner}
1884 @item Dynamics (horizontally)   @tab @code{DynamicText}
1885 @item Fingerings                @tab @code{Fingering}
1886 @item Rehearsal / Text marks    @tab @code{RehearsalMark}
1887 @item Slurs                     @tab @code{Slur}
1888 @item Text e.g. @code{^"text"}  @tab @code{TextScript}
1889 @item Ties                      @tab @code{Tie}
1890 @end multitable
1891
1892
1893 @node Fixing overlapping notation
1894 @subsection Fixing overlapping notation
1895
1896 Let's now see how the properties in the previous section can
1897 help to resolve overlapping notation.
1898
1899 @subheading padding
1900 @cindex padding
1901
1902 TODO Find a better example
1903
1904 Let's try the effect of @code{padding} on the rather artificial
1905 example above.  This is a property of
1906 @code{DynamicLineSpanner}, not @code{DynamicText}.
1907
1908 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1909 \dynamicUp
1910 % Increase vertical padding by 5 units
1911 \override DynamicLineSpanner #'padding = #'5
1912 a4\f b\mf c\mp b\p
1913 @end lilypond
1914
1915 Dynamics are positioned vertically with respect to the note to
1916 which they are attached.  We see that this has moved all the
1917 dynamics up by five staff spaces, but has had no effect on the
1918 horizontal separation, nor on the placement of the dynamics
1919 relative to each other.
1920
1921 The @code{padding} property can be set to increase
1922 (or decrease) the distance between symbols that are printed
1923 above or below notes.  This applies to all objects with
1924 @code{side-position-interface}.
1925
1926 @lilypond[quote,fragment,relative=1,verbatim]
1927 c2\fermata
1928 \override Script #'padding = #3
1929 b2\fermata
1930 @end lilypond
1931
1932 @lilypond[quote,fragment,relative=1,verbatim]
1933 % This will not work, see below:
1934 \override MetronomeMark #'padding = #3
1935 \tempo 4=120
1936 c1
1937 % This works:
1938 \override Score.MetronomeMark #'padding = #3
1939 \tempo 4=80
1940 d1
1941 @end lilypond
1942
1943 Note in the second example how important it is to figure out what
1944 context handles a certain object.  Since the @code{MetronomeMark} object
1945 is handled in the @code{Score} context, property changes in the
1946 @code{Voice} context will not be noticed.  For more details, see
1947 @ruser{Constructing a tweak}.
1948
1949
1950 @subheading self-alignment-X
1951 @cindex self-alignment-X
1952
1953 The following example shows how this can resolve the collision
1954 of a string fingering object with a note's stem by aligning the
1955 right edge with the reference point of the parent note:
1956
1957 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
1958 \voiceOne
1959 < a \2 >
1960 \once \override StringNumber #'self-alignment-X = #RIGHT
1961 < a \2 >
1962 @end lilypond
1963
1964 @subheading extra-offset
1965 @cindex extra-offset property
1966
1967 Another solution gives us complete control over placing the object -- we
1968 can move it horizontally or vertically.  This is done with the
1969 @code{extra-offset} property.  It is slightly more complicated and can
1970 cause other problems.  When we move objects with @code{extra-offset},
1971 the movement is done after LilyPond has placed all other objects.  This
1972 means that the result can overlap with other objects.
1973
1974 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1975   % temporary code to break this example:
1976   \override TextScript #'outside-staff-priority = ##f
1977 \once \override TextScript #'extra-offset = #'( 1.0 . -1.0 )
1978 e4^\markup{ \italic ritenuto } g b e
1979 @end lilypond
1980
1981 With @code{extra-offset}, the first number controls the horizontal
1982 movement (left is negative); the second number controls the vertical
1983 movement (up is positive).  After a bit of experimenting, we decided
1984 that these values look good
1985
1986 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1987   % temporary code to break this example:
1988   \override TextScript #'outside-staff-priority = ##f
1989 \once \override TextScript #'extra-offset = #'( -1.6 . 1.0 )
1990 e4^\markup{ \italic ritenuto } g b e
1991 @end lilypond
1992
1993 @noindent
1994 Again, these numbers are simply the result of a few experiments and
1995 looking at the output.  You might prefer the text to be slightly higher,
1996 or to the left, or whatever.  Try it and look at the result!
1997
1998 In the following example, the second fingering is moved a little to
1999 the left, and 1.8 staff space downwards:
2000
2001 @lilypond[quote,fragment,relative=1,verbatim]
2002 \stemUp
2003 f-5
2004 \once \override Fingering
2005     #'extra-offset = #'(-0.3 . -1.8)
2006 f-5
2007 @end lilypond
2008
2009
2010 @subheading force-hshift
2011 @cindex force-hshift property
2012
2013 We introduce just one here, the @code{force-hshift} property of
2014 @code{NoteColumn}.  The lower two notes of the first chord (i.e,
2015 those in the third voice) should not be shifted away from the
2016 note column of the higher two notes.  To correct this we set
2017 @code{force-hshift} of these notes to zero.
2018 The lower note of the second chord is best placed just to the
2019 right of the higher notes.  We achieve this by setting
2020 @code{force-hshift} of this note to 0.5, ie half a notehead's
2021 width to the right of the note column of the higher notes.
2022
2023 Here's the final result:
2024
2025 @lilypond[quote,verbatim,fragment,ragged-right]
2026 \new Staff \relative c'' {
2027   \key aes \major
2028   <<
2029     { c2 aes4. bes8 } \\
2030     { aes2 f4 fes   } \\
2031     { \voiceFour
2032       \once \override NoteColumn #'force-hshift = #0 <ees c>2
2033       \once \override NoteColumn #'force-hshift = #0.5 des2
2034     }
2035   >> |
2036   <c ees aes c>1 |
2037 }
2038 @end lilypond
2039
2040
2041 TODO To be continued ....
2042
2043 TODO Old stuff follows
2044
2045
2046
2047 @node Page layout
2048 @section Page layout
2049
2050 @menu
2051 * Fitting music onto fewer pages::  
2052 @end menu
2053
2054 @node Fitting music onto fewer pages
2055 @subsection Fitting music onto fewer pages
2056
2057 Sometimes you can end up with one or two staves on a second
2058 (or third, or fourth...) page.  This is annoying, especially
2059 if you look at previous pages and it looks like there is plenty
2060 of room left on those.
2061
2062 When investigating layout issues, @code{annotate-spacing} is
2063 an invaluable tool.  This command prints the values of various
2064 layout spacing commands; see @ruser{Displaying spacing}, for more
2065 details.  From the output of @code{annotate-spacing}, we can
2066 see which margins we may wish to alter.
2067
2068 Other than margins, there are a few other options to save space:
2069
2070 @itemize
2071 @item
2072 You may tell LilyPond to place systems as close together as
2073 possible (to fit as many systems as possible onto a page), but
2074 then to space those systems out so that there is no blank
2075 space at the bottom of the page.
2076
2077 @example
2078 \paper @{
2079   between-system-padding = #0.1
2080   between-system-space = #0.1
2081   ragged-last-bottom = ##f
2082   ragged-bottom = ##f
2083 @}
2084 @end example
2085
2086 @item
2087 You may force the number of systems (i.e., if LilyPond wants
2088 to typeset some music with 11 systems, you could force it to
2089 use 10).
2090
2091 @example
2092 \paper @{
2093   system-count = #10
2094 @}
2095 @end example
2096
2097 @item
2098 Avoid (or reduce) objects which increase the vertical size of
2099 a system.  For example, volta repeats (or alternate repeats)
2100 require extra space.  If these repeats are spread over two
2101 systems, they will take up more space than one system with
2102 the volta repeats and another system without.
2103
2104 Another example is moving dynamics which @q{stick out} of
2105 a system.
2106
2107 @lilypond[verbatim,quote,fragment]
2108 \relative c' {
2109   e4 c g\f c
2110   \override DynamicLineSpanner #'padding = #-1.8
2111   \override DynamicText #'extra-offset = #'( -2.1 . 0)
2112   e4 c g\f c
2113 }
2114 @end lilypond
2115
2116 @item
2117 Alter the horizontal spacing via @code{SpacingSpanner}.  See
2118 @ruser{Changing horizontal spacing}, for more details.
2119
2120 @lilypond[verbatim,quote]
2121 \score {
2122   \relative c'' {
2123     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
2124     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2125     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
2126     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2127   }
2128   \layout {
2129     \context {
2130       \Score
2131       \override SpacingSpanner
2132                 #'base-shortest-duration = #(ly:make-moment 1 4)
2133     }
2134   }
2135 }
2136 @end lilypond
2137
2138 @end itemize
2139
2140
2141
2142
2143
2144 @c Old stuff follows  -td
2145
2146 @node Common tweaks
2147 @section Common tweaks
2148
2149 blah blah
2150
2151 @menu
2152 * Other common tweaks::         
2153 @end menu
2154
2155
2156
2157 @node Other common tweaks
2158 @subsection Other common tweaks
2159
2160 Some overrides are so common that predefined commands are provided as
2161 short-cuts, such as @code{\slurUp} and @code{\stemDown}.  These
2162 commands are described in the Notation Reference under the appropriate
2163 sections.
2164
2165 The complete list of modifications available for each type of
2166 object (like slurs or beams) are documented in the Program
2167 Reference.  However, many layout objects share properties which can be
2168 used to apply generic tweaks.
2169
2170 @itemize
2171
2172
2173 @item
2174 Setting the @code{transparent} property will cause an object to be printed
2175 in @q{invisible ink}: the object is not printed, but all its other
2176 behavior is retained.  The object still takes up space, it takes part in
2177 collisions, and slurs, ties, and beams can be attached to it.
2178
2179 @cindex transparent objects
2180 @cindex removing objects
2181 @cindex hiding objects
2182 @cindex invisible objects
2183 The following example demonstrates how to connect different voices
2184 using ties.  Normally, ties only connect two notes in the same
2185 voice.  By introducing a tie in a different voice,
2186
2187 @lilypond[quote,fragment,relative=2]
2188 << {
2189   b8~ b8\noBeam
2190 } \\ {
2191   b[ g8]
2192 } >>
2193 @end lilypond
2194
2195 @noindent
2196 and blanking the first up-stem in that voice, the tie appears to cross
2197 voices:
2198
2199
2200 @lilypond[quote,fragment,relative=2,verbatim]
2201 << {
2202   \once \override Stem #'transparent = ##t
2203   b8~ b8\noBeam
2204 } \\ {
2205   b[ g8]
2206 } >>
2207 @end lilypond
2208
2209 To make sure that the just-blanked stem doesn't squeeze the tie too much,
2210 we also lengthen the stem, by setting the @code{length} to
2211 @code{8},
2212
2213 @lilypond[quote,fragment,relative=2,verbatim]
2214 << {
2215   \once \override Stem #'transparent = ##t
2216   \once \override Stem #'length = #8
2217   b8~ b8\noBeam
2218 } \\ {
2219   b[ g8]
2220 } >>
2221 @end lilypond
2222
2223 @end itemize
2224
2225 @cindex Tweaks, distances
2226 @cindex Distances
2227
2228 Distances in LilyPond are measured in staff-spaces, while most
2229 thickness properties are measured in line-thickness.  Some
2230 properties are different; for example, the thickness of beams
2231 are measured in staff-spaces.  For more information, see the
2232 relevant portion of the program reference.
2233
2234
2235
2236 @node TODO other name
2237 @section TODO other name
2238
2239 @menu
2240 * Predefined tweaks::           
2241 * Advanced tweaks with Scheme::  
2242 * Avoiding tweaks with slower processing::  
2243 * The three methods of tweaking::  
2244 @end menu
2245
2246 @node Predefined tweaks
2247 @subsection Predefined tweaks
2248
2249 TODO: Some tweaks are really common, blah blah.
2250
2251 for example \slurUp, \fatText.
2252
2253 Show example, then explain where to find ly/propert-ly.
2254
2255
2256 The Internals Reference documentation contains a lot of information
2257 about LilyPond, but even more information can be gathered from
2258 looking at the internal LilyPond files.
2259
2260 Some default settings (such as the definitions for
2261 @code{\header@{@}}s) are stored as @code{.ly} files.  Other
2262 settings (such as the definitions of markup commands) are
2263 stored as @code{.scm} (Scheme) files.  Further explanation is
2264 outside the scope of this manual; users should be warned that
2265 a substantial amount of technical knowledge or time is required
2266 to understand these files.
2267
2268 @itemize
2269
2270 @item Linux: @file{@var{installdir}/lilypond/usr/share/lilypond/current/}
2271
2272 @item OSX:
2273 @file{@var{installdir}/LilyPond.app/Contents/Resources/share/lilypond/current/}.
2274 To access this, either @code{cd} into this directory from the
2275 Terminal, or control-click on the LilyPond application and select
2276 @q{Show Package Contents}.
2277
2278 @item Windows: @file{@var{installdir}/LilyPond/usr/share/lilypond/current/}
2279
2280 @end itemize
2281
2282 The @file{ly/} and @file{scm/} directories will be of
2283 particular interest.  Files such as @file{ly/property-init.ly} and
2284 @file{ly/declarations-init.ly} define all the common tweaks.
2285
2286
2287 @node Advanced tweaks with Scheme
2288 @subsection Advanced tweaks with Scheme
2289
2290 We have seen how LilyPond output can be heavily modified using
2291 commands like
2292 @code{\override TextScript #'extra-offset = ( 1 . -1)}.  But
2293 we have even more power if we use Scheme.  For a full explantion
2294 of this, see the @ref{Scheme tutorial}, and
2295 @ruser{Interfaces for programmers}.
2296
2297 We can use Scheme to simply @code{\override} commands,
2298
2299 @lilypond[quote,verbatim,ragged-right]
2300 padText = #(define-music-function (parser location padding) (number?)
2301 #{
2302   \once \override TextScript #'padding = #$padding
2303 #})
2304
2305 \relative c''' {
2306   c4^"piu mosso" b a b
2307   \padText #1.8
2308   c4^"piu mosso" d e f
2309   \padText #2.6
2310   c4^"piu mosso" fis a g
2311 }
2312 @end lilypond
2313
2314 We can use it to create new commands,
2315
2316 @lilypond[quote,verbatim,ragged-right]
2317 tempoMark = #(define-music-function (parser location padding marktext)
2318                                     (number? string?)
2319 #{
2320   \once \override Score . RehearsalMark #'padding = $padding
2321   \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
2322   \mark \markup { \bold $marktext }
2323 #})
2324
2325 \relative c'' {
2326   c2 e
2327   \tempoMark #3.0 #"Allegro"
2328   g c
2329 }
2330 @end lilypond
2331
2332 Even music expressions can be passed in.
2333
2334 @lilypond[quote,verbatim,ragged-right]
2335 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
2336 #{
2337   $x e8 a b $y b a e
2338 #})
2339
2340 \relative c''{
2341   \pattern c8 c8\f
2342   \pattern {d16 dis} { ais16-> b\p }
2343 }
2344 @end lilypond
2345
2346
2347 @node Avoiding tweaks with slower processing
2348 @subsection Avoiding tweaks with slower processing
2349
2350 LilyPond can perform extra checks while it processes files.  These
2351 commands will take extra time, but the result may require fewer
2352 manual tweaks.
2353
2354 @example
2355 %%  makes sure text scripts and lyrics are within the paper margins
2356 \override Score.PaperColumn #'keep-inside-line = ##t 
2357 \override Score.NonMusicalPaperColumn #'keep-inside-line = ##t
2358 @end example
2359
2360 In some cases (see issue 246), this must be done before
2361 @code{\override} commands can be processed.
2362
2363 @verbatim
2364 \new Score \with {
2365     \override PaperColumn #'keep-inside-line = ##t 
2366     \override NonMusicalPaperColumn #'keep-inside-line = ##t
2367   } {
2368    ..
2369 }
2370 @end verbatim
2371
2372
2373 @node The three methods of tweaking
2374 @subsection The three methods of tweaking
2375
2376 FIXME write this.
2377
2378 @verbatim
2379 \override
2380 @end verbatim
2381
2382 @verbatim
2383 \with {
2384
2385 }
2386 @end verbatim
2387
2388 @verbatim
2389 \layout{ \context
2390
2391 }}
2392 @end verbatim
2393
2394
2395
2396 FIXME discuss \tweak
2397
2398
2399
2400
2401
2402 FIXME:
2403 - There is a section in the manual on \set vs \override (3.3.7),
2404 which is incomplete.  First it doesn't mention \overrideProperty,
2405 nor does it mention properties which are not capitalized at all.
2406 And it should explain that \override should be used to set
2407 properties with hyphenated names, like auto-knee-gap.  (I had to
2408 experiment to find out how to do this.)
2409
2410
2411
2412
2413
2414