]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/tweaks.itely
Merge branch 'master' of git://git.sv.gnu.org/lilypond
[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.  The property to do this is
1697 @code{staff-padding} which is covered in the following section.
1698
1699
1700 @node Collisions of objects
1701 @section Collisions of objects
1702
1703 @menu
1704 * Moving objects::              
1705 * Fixing overlapping notation::  
1706 @end menu
1707
1708 @node Moving objects
1709 @subsection Moving objects
1710
1711 This may come as a surprise, but LilyPond is not perfect.  Some 
1712 notation elements can overlap.  This is unfortunate, but in fact 
1713 rather rare.  Usually the need to move objects is for clarity or
1714 aesthetic reasons -- they would look better with a little more
1715 space around them.
1716
1717 There are three main main approaches to resolving overlapping
1718 notation.  They should be considered in the following order:
1719
1720 @enumerate
1721 @item
1722 The @strong{direction} of one of the overlapping objects may
1723 be changed using the predefined commands listed above for
1724 within-staff objects (see @ref{Within-staff objects}).
1725 Stems, slurs, beams, ties, dynamics, text and tuplets may be
1726 repositioned easily in this way.  The limitation is that you
1727 have a choice of only two positions, and neither may be
1728 suitable.
1729
1730 @sp 1
1731 @item
1732 The @strong{object properties}, which LilyPond uses
1733 when positioning layout objects, may be modified.  The advantages
1734 of making changes to this type of property are (a) that some
1735 other objects will be moved automatically if necessary to make
1736 room and (b) the single override can apply to all instances of
1737 the same type of object.  Such properties include:
1738
1739 @itemize
1740 @sp 1
1741 @item @code{direction}
1742 This has already been covered in some detail -- see
1743 @ref{Within-staff objects}.
1744
1745 @sp 1
1746 @item @code{padding}, @code{left-padding},
1747       @code{right-padding}, @code{staff-padding}
1748
1749 @cindex left-padding property
1750 @cindex padding property
1751 @cindex right-padding property
1752 @cindex staff-padding property
1753 @sp 1
1754 The @code{padding} property specifies the gap that must be left
1755 between
1756 the top and bottom edges of objects which are positioned
1757 either above or below another previously placed object, or
1758 between the sides of objects which are positioned to the left or
1759 right of previously placed objects.  @code{padding} can be applied
1760 to all objects which support the @code{side-position-interface}.
1761 Instead of @code{padding} some objects have instead a
1762 @code{left-padding} or @code{right-padding} property.
1763 All padding values are measured in staff spaces.  For most
1764 objects, this value is set by default to be around 1.0 or less
1765 (it varies with each object).  It may be overridden if a larger
1766 (or smaller) gap is required.
1767
1768 The @code{staff-padding} property is closely related.  @code{padding}
1769 controls the minimum amount of space between any object which 
1770 supports the @code{side-position-interface} and the nearest
1771 other object (generally the note or the staff lines);
1772 @code{staff-padding} applies only to those objects which are always
1773 set outside the staff, and it controls the minimum amount of space 
1774 that should be inserted between an object and the staff.  Note that
1775 @code{staff-padding} has no effect on objects which are set relative
1776 to the note rather than the staff, even though it may be set for 
1777 such objects.
1778
1779 To discover which padding property is required for the object
1780 you wish to reposition, you
1781 need to return to the IR and look up the object's properties.
1782 Be aware that the padding properties might not be located in the
1783 obvious object.  For example, the placement of accidentals is
1784 controlled by @code{left-padding} and @code{right-padding},
1785 but these are to be found in the @code{AccidentalPlacement}
1786 object which lives in the staff context.
1787
1788 @sp 1
1789 @item @code{self-alignment-X}
1790
1791 @cindex self-alignment-X property
1792 This property aligns the object to the left, to the right, or
1793 centers it with respect to the parent object's reference point.
1794 It may be used with all objects which support the
1795 @code{self-alignment-interface}.  In general these are objects
1796 that contain text.  The values are @code{LEFT}, @code{RIGHT}
1797 or @code{CENTER}.  The movement is limited by the length of the
1798 object.  Any numerical value between @code{-1} and @code{+1} may
1799 also be specified, where @code{-1} is left-aligned and @code{+1}
1800 is right-aligned.
1801
1802 @item @code{staff-position}
1803
1804 @cindex staff-position property
1805 @code{staff-position} is a property of the
1806 @code{staff-symbol-referencer-interface}, which is supported by
1807 objects which are positioned relative to the staff.  It specifies
1808 the vertical position of the object relative to the center line
1809 of the staff in half staff-spaces.  It is useful in resolving
1810 collisions between layout objects like multi-measure rests and
1811 notes in different voices.  If the object is repositioned beyond
1812 the limits of the staff, ledger lines are automatically inserted.
1813
1814 @end itemize
1815
1816 Objects do not all have all of these properties in general.
1817 It is necessary to go to the IR to look up which properties
1818 are available for the object in question.
1819
1820 @sp 1
1821 @item
1822 Finally, when all else fails, objects may be repositioned manually
1823 by changing the distance which separates them from other objects,
1824 or by repositioning them relative to the staff center line.  The
1825 disadvantages are that the correct values for the repositioning
1826 have to be worked out, often by trial and error, for every object
1827 individually, and the user is responsible for any collisions that
1828 might follow.  But the main difficulty with this approach is that
1829 the repositioning values may need to be reworked if the music is
1830 later modified.  The properties that can be used for this type of
1831 repositioning are:
1832
1833 @itemize
1834 @sp 1
1835 @item @code{extra-offset}
1836
1837 @cindex extra-offset property
1838 This property applies to any layout object
1839 supporting the @code{grob-interface}.  It takes a pair of
1840 numbers which specify the extra displacement in the horizontal and
1841 vertical directions.  Negative numbers move the object to
1842 the left or down.  The units are staff-spaces.  The extra
1843 displacement is made after the typesetting of objects is
1844 finished, so an object may be repositioned anywhere without
1845 affecting anything else.
1846
1847 @sp 1
1848 @item @code{force-hshift}
1849
1850 @cindex force-hshift property
1851 Closely spaced notes in a chord, or notes occuring at the same
1852 time in different voices, are arranged in two, occasionally more,
1853 columns to prevent the noteheads overlapping.  These are called
1854 note columns, and an object called @code{NoteColumn} is created
1855 to lay out the notes in that column.  There are separate columns
1856 for each voice.  The @code{force-hshift}
1857 property is a property of a @code{NoteColumn} (actually of the
1858 @code{note-column-interface}).  Changing it permits a note column
1859 to be moved in units appropriate to a note column, viz. the note
1860 head width of the first voice note.  It is preferable to the
1861 @code{extra-offset} property for this purpose as there is no need
1862 to work out the distance in staff-spaces.
1863
1864 @item @code{positions}
1865
1866 @cindex positions property
1867 This is most useful for manually adjusting the slope and height
1868 of beams, ties, slurs, and tuplets.   It takes a pair of numbers
1869 giving the position of the left and right ends of the beam, slur,
1870 etc. relative to the center line of the staff.  Units are
1871 staff-spaces.
1872
1873 @end itemize
1874
1875 Objects do not all have all of these properties in general.
1876 It is necessary to go to the IR to look up which properties
1877 are available for the object in question.
1878
1879 @end enumerate
1880
1881 Here is a list of the objects which are most likely to be
1882 involved in collisions, together with the name of the object which
1883 should be looked up in the IR in order to discover which properties
1884 should be used to move them.
1885
1886 @multitable @columnfractions .4 .6
1887 @headitem Object type           @tab Object name
1888 @item Articulations             @tab @code{Script}
1889 @item Dynamics (vertically)     @tab @code{DynamicLineSpanner}
1890 @item Dynamics (horizontally)   @tab @code{DynamicText}
1891 @item Fingerings                @tab @code{Fingering}
1892 @item Rehearsal / Text marks    @tab @code{RehearsalMark}
1893 @item Slurs                     @tab @code{Slur}
1894 @item Text e.g. @code{^"text"}  @tab @code{TextScript}
1895 @item Ties                      @tab @code{Tie}
1896 @end multitable
1897
1898
1899 @node Fixing overlapping notation
1900 @subsection Fixing overlapping notation
1901
1902 Let's now see how the properties in the previous section can
1903 help to resolve overlapping notation.
1904
1905 @subheading padding property
1906 @cindex padding property
1907
1908 The @code{padding} property can be set to increase
1909 (or decrease) the distance between symbols that are printed
1910 above or below notes.
1911
1912 @lilypond[quote,fragment,relative=1,verbatim]
1913 c2\fermata
1914 \override Script #'padding = #3
1915 b2\fermata
1916 @end lilypond
1917
1918 @lilypond[quote,fragment,relative=1,verbatim]
1919 % This will not work, see below:
1920 \override MetronomeMark #'padding = #3
1921 \tempo 4=120
1922 c1
1923 % This works:
1924 \override Score.MetronomeMark #'padding = #3
1925 \tempo 4=80
1926 d1
1927 @end lilypond
1928
1929 Note in the second example how important it is to figure out what
1930 context handles a certain object.  Since the @code{MetronomeMark} object
1931 is handled in the @code{Score} context, property changes in the
1932 @code{Voice} context will not be noticed.  For more details, see
1933 @ruser{Constructing a tweak}.
1934
1935 @subheading left-padding and right-padding properties
1936 @cindex left-padding property
1937 @cindex right-padding property
1938
1939 TODO Example of this - at the moment I can't find one! -td
1940
1941 @subheading staff-padding property
1942 @cindex staff-padding property
1943
1944 @code{staff-padding} can be used to align objects such as dynamics
1945 along a baseline at a fixed height above the staff, rather than
1946 at a height dependent on the position of the note to which they
1947 are attached.  It is not a property of
1948 @code{DynamicText} but of @code{DynamicLineSpanner}.
1949 This is because the baseline should apply equally to @strong{all}
1950 dynamics, including those created as extended spanners.
1951 So this is the way to align the dynamic marks in the example
1952 taken from the previous section:
1953
1954 @lilypond[quote,fragment,ragged-right,verbatim,relative=2]
1955 \dynamicUp
1956 % Extend width by 1 unit
1957 \override DynamicText #'extra-spacing-width = #'(-0.5 . 0.5)
1958 % Align dynamics to a base line 2 units above staff
1959 \override DynamicLineSpanner #'staff-padding = #2
1960 a4\f b\mf c\mp b\p
1961 @end lilypond
1962
1963
1964 @subheading self-alignment-X property
1965 @cindex self-alignment-X property
1966
1967 The following example shows how this can resolve the collision
1968 of a string fingering object with a note's stem by aligning the
1969 right edge with the reference point of the parent note:
1970
1971 @lilypond[quote,fragment,ragged-right,verbatim,relative=3]
1972 \voiceOne
1973 < a \2 >
1974 \once \override StringNumber #'self-alignment-X = #RIGHT
1975 < a \2 >
1976 @end lilypond
1977
1978 @subheading staff-position property
1979 @cindex staff-position property
1980
1981 Multimeasure rests in one voice can collide with notes in another.
1982 Since these rests are typeset centered between the bar lines, it
1983 would require significant effort for LilyPond to figure out which
1984 other notes might collide with it, since all the current collision
1985 handling between notes and between notes and rests is done only
1986 for notes and rests that occur at the same time.  Here's an
1987 example of a collision of this type:
1988
1989 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
1990 << {c c c c} \\ {R1} >>
1991 @end lilypond
1992
1993 The best solution here is to move the multimeasure rest down.
1994 The default in @code{\voiceTwo} (i.e. in the second voice of a
1995 @code{<<@{...@} \\ @{...@}>>} construct)
1996 is that staff-position is set to -4 for MultiMeasureRest, so
1997 we need to move it, say, four half-staff spaces down to
1998 @code{-8}.
1999
2000 @lilypond[quote,verbatim,fragment,ragged-right, relative=1]
2001 <<
2002   {c c c c}
2003 \\
2004   \override MultiMeasureRest #'staff-position = #-8
2005   {R1}
2006 >>
2007 @end lilypond
2008
2009 This is better than using, for example, @code{extra-offset},
2010 because the extra ledger lines are inserted automatically.
2011
2012 @subheading extra-offset property
2013 @cindex extra-offset property
2014
2015 The @code{extra-offset} property provides complete control over the
2016 positioning of an object both horizontally and vertically.
2017 It is slightly more complicated than other overrides and can
2018 cause other problems.  When we move objects with @code{extra-offset},
2019 the movement is done after LilyPond has placed all other objects.
2020 This means that the result can overlap with other objects.
2021
2022 In the following example, the second fingering is moved a little to
2023 the left, and 1.8 staff space downwards:
2024
2025 @lilypond[quote,fragment,relative=1,verbatim]
2026 \stemUp
2027 f-5
2028 \once \override Fingering
2029     #'extra-offset = #'(-0.3 . -1.8)
2030 f-5
2031 @end lilypond
2032
2033
2034 @subheading force-hshift property
2035 @cindex force-hshift property
2036 @c FIXME: this doesn't work.
2037 @c @n ode Chopin finally corrected
2038
2039 We can now see how to apply the final corrections to the Chopin
2040 example introduced at the end of
2041 FIXME
2042 @c ref{I'm hearing voices}
2043 , which
2044 was left looking like this:
2045
2046 @lilypond[quote,verbatim,fragment,ragged-right]
2047 \new Staff \relative c'' {
2048   \key aes \major
2049   <<
2050     { c2 aes4. bes8 } \\
2051     { aes2 f4 fes   } \\
2052     { \voiceFour
2053       <ees c>2
2054       des2
2055     }
2056   >> |
2057   <c ees aes c>1 |
2058 }
2059 @end lilypond
2060
2061 @noindent
2062 The lower two notes of the first chord (i.e,
2063 those in the third voice) should not be shifted away from the
2064 note column of the higher two notes.  To correct this we set
2065 @code{force-hshift}, which is a property of
2066 @code{NoteColumn}, of these notes to zero.
2067 The lower note of the second chord is best placed just to the
2068 right of the higher notes.  We achieve this by setting
2069 @code{force-hshift} of this note to 0.5, ie half a notehead's
2070 width to the right of the note column of the higher notes.
2071
2072 Here's the final result:
2073
2074 @lilypond[quote,verbatim,fragment,ragged-right]
2075 \new Staff \relative c'' {
2076   \key aes \major
2077   <<
2078     { c2 aes4. bes8 } \\
2079     { aes2 f4 fes   } \\
2080     { \voiceFour
2081       \once \override NoteColumn #'force-hshift = #0 <ees c>2
2082       \once \override NoteColumn #'force-hshift = #0.5 des2
2083     }
2084   >> |
2085   <c ees aes c>1 |
2086 }
2087 @end lilypond
2088
2089
2090 @subheading positions property
2091 @cindex positions property
2092
2093 The @code{positions} property allows the position and slope of
2094 ties, tuplets, slurs, phrasing slurs and beams to be controlled
2095 manually.  Here's an example which has an ugly phrasing slur
2096 due to starting it on the acciaccatura.
2097
2098 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2099 r4  \acciaccatura e8\( d8 c ~c d c d\)
2100 @end lilypond
2101
2102 @noindent
2103 We simply could move the phrasing slur above the notes, and this
2104 would be the preferred solution:
2105
2106 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2107 r4
2108 \phrasingSlurUp
2109 \acciaccatura e8\( d8 c ~c d c d\)
2110 @end lilypond
2111
2112 @noindent
2113 but if there were some reason why this could not be done the
2114 other alternative would be to move the left end of the phrasing
2115 slur down a little using   This also resolves the rather nasty shape,
2116 which is due to the attempt to avoid the slur on the acciaccature.
2117
2118 @lilypond[quote,verbatim,fragment,ragged-right,relative=1]
2119 r4
2120 \once \override PhrasingSlur #'positions = #'(-4 . -3)
2121 \acciaccatura
2122 e8\( d8 c ~c d c d\)
2123 @end lilypond
2124
2125 Here's a further example taken from the opening of the left-hand
2126 staff of Chopin's Prelude Op 28 No. 2.  We see that the beam 
2127 collides with the upper notes:
2128
2129 @lilypond[quote,verbatim,fragment,ragged-right]
2130 {
2131 \clef "bass"
2132 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2133 << {b,8 ais, b, g,} \\ {e, g e, g} >>
2134 }
2135 @end lilypond
2136
2137 @noindent
2138 This can only be resolved by manually moving both ends of the beam 
2139 up from their position at 2 staff-spaces to, say, 3:
2140
2141 @lilypond[quote,verbatim,fragment,ragged-right]
2142 {
2143   \clef "bass"
2144   <<
2145     \override Beam #'positions = #'(3 . 3)
2146     {b,8 ais, b, g,}
2147   \\
2148     {e, g e, g}
2149   >>
2150   << {b,8 ais, b, g,} \\ {e, g e, g} >>
2151 }
2152 @end lilypond
2153
2154 @noindent
2155 Note that the override continues to apply in the first voice of
2156 the second block of quavers, but not to any of the beams in the
2157 second voice.
2158
2159 TODO Examples of real music showing collisions and their resolution
2160
2161 TODO Old stuff follows
2162
2163
2164
2165 @node Page layout
2166 @section Page layout
2167
2168 @menu
2169 * Fitting music onto fewer pages::  
2170 @end menu
2171
2172 @node Fitting music onto fewer pages
2173 @subsection Fitting music onto fewer pages
2174
2175 Sometimes you can end up with one or two staves on a second
2176 (or third, or fourth...) page.  This is annoying, especially
2177 if you look at previous pages and it looks like there is plenty
2178 of room left on those.
2179
2180 When investigating layout issues, @code{annotate-spacing} is
2181 an invaluable tool.  This command prints the values of various
2182 layout spacing commands; see @ruser{Displaying spacing}, for more
2183 details.  From the output of @code{annotate-spacing}, we can
2184 see which margins we may wish to alter.
2185
2186 Other than margins, there are a few other options to save space:
2187
2188 @itemize
2189 @item
2190 You may tell LilyPond to place systems as close together as
2191 possible (to fit as many systems as possible onto a page), but
2192 then to space those systems out so that there is no blank
2193 space at the bottom of the page.
2194
2195 @example
2196 \paper @{
2197   between-system-padding = #0.1
2198   between-system-space = #0.1
2199   ragged-last-bottom = ##f
2200   ragged-bottom = ##f
2201 @}
2202 @end example
2203
2204 @item
2205 You may force the number of systems (i.e., if LilyPond wants
2206 to typeset some music with 11 systems, you could force it to
2207 use 10).
2208
2209 @example
2210 \paper @{
2211   system-count = #10
2212 @}
2213 @end example
2214
2215 @item
2216 Avoid (or reduce) objects which increase the vertical size of
2217 a system.  For example, volta repeats (or alternate repeats)
2218 require extra space.  If these repeats are spread over two
2219 systems, they will take up more space than one system with
2220 the volta repeats and another system without.
2221
2222 Another example is moving dynamics which @q{stick out} of
2223 a system.
2224
2225 @lilypond[verbatim,quote,fragment]
2226 \relative c' {
2227   e4 c g\f c
2228   \override DynamicLineSpanner #'padding = #-1.8
2229   \override DynamicText #'extra-offset = #'( -2.1 . 0)
2230   e4 c g\f c
2231 }
2232 @end lilypond
2233
2234 @item
2235 Alter the horizontal spacing via @code{SpacingSpanner}.  See
2236 @ruser{Changing horizontal spacing}, for more details.
2237
2238 @lilypond[verbatim,quote]
2239 \score {
2240   \relative c'' {
2241     g4 e e2 | f4 d d2 | c4 d e f | g4 g g2 |
2242     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2243     d4 d d d | d4 e f2 | e4 e e e | e4 f g2 |
2244     g4 e e2 | f4 d d2 | c4 e g g | c,1 |
2245   }
2246   \layout {
2247     \context {
2248       \Score
2249       \override SpacingSpanner
2250                 #'base-shortest-duration = #(ly:make-moment 1 4)
2251     }
2252   }
2253 }
2254 @end lilypond
2255
2256 @end itemize
2257
2258
2259
2260 @node Common tweaks
2261 @section Common tweaks
2262
2263 blah blah
2264
2265 @menu
2266 * Other common tweaks::         
2267 @end menu
2268
2269
2270
2271 @node Other common tweaks
2272 @subsection Other common tweaks
2273
2274 Some overrides are so common that predefined commands are provided as
2275 short-cuts, such as @code{\slurUp} and @code{\stemDown}.  These
2276 commands are described in the Notation Reference under the appropriate
2277 sections.
2278
2279 The complete list of modifications available for each type of
2280 object (like slurs or beams) are documented in the Program
2281 Reference.  However, many layout objects share properties which can be
2282 used to apply generic tweaks.
2283
2284 @itemize
2285
2286
2287 @item
2288 Setting the @code{transparent} property will cause an object to be printed
2289 in @q{invisible ink}: the object is not printed, but all its other
2290 behavior is retained.  The object still takes up space, it takes part in
2291 collisions, and slurs, ties, and beams can be attached to it.
2292
2293 @cindex transparent objects
2294 @cindex removing objects
2295 @cindex hiding objects
2296 @cindex invisible objects
2297 The following example demonstrates how to connect different voices
2298 using ties.  Normally, ties only connect two notes in the same
2299 voice.  By introducing a tie in a different voice,
2300
2301 @lilypond[quote,fragment,relative=2]
2302 << {
2303   b8~ b8\noBeam
2304 } \\ {
2305   b[ g8]
2306 } >>
2307 @end lilypond
2308
2309 @noindent
2310 and blanking the first up-stem in that voice, the tie appears to cross
2311 voices:
2312
2313
2314 @lilypond[quote,fragment,relative=2,verbatim]
2315 << {
2316   \once \override Stem #'transparent = ##t
2317   b8~ b8\noBeam
2318 } \\ {
2319   b[ g8]
2320 } >>
2321 @end lilypond
2322
2323 To make sure that the just-blanked stem doesn't squeeze the tie too much,
2324 we also lengthen the stem, by setting the @code{length} to
2325 @code{8},
2326
2327 @lilypond[quote,fragment,relative=2,verbatim]
2328 << {
2329   \once \override Stem #'transparent = ##t
2330   \once \override Stem #'length = #8
2331   b8~ b8\noBeam
2332 } \\ {
2333   b[ g8]
2334 } >>
2335 @end lilypond
2336
2337 @end itemize
2338
2339 @cindex Tweaks, distances
2340 @cindex Distances
2341
2342 Distances in LilyPond are measured in staff-spaces, while most
2343 thickness properties are measured in line-thickness.  Some
2344 properties are different; for example, the thickness of beams
2345 are measured in staff-spaces.  For more information, see the
2346 relevant portion of the program reference.
2347
2348
2349
2350 @node TODO other name
2351 @section TODO other name
2352
2353 @menu
2354 * Predefined tweaks::           
2355 * Advanced tweaks with Scheme::  
2356 * Avoiding tweaks with slower processing::  
2357 * The three methods of tweaking::  
2358 @end menu
2359
2360 @node Predefined tweaks
2361 @subsection Predefined tweaks
2362
2363 TODO: Some tweaks are really common, blah blah.
2364
2365 for example \slurUp, \fatText.
2366
2367 Show example, then explain where to find ly/propert-ly.
2368
2369
2370 The Internals Reference documentation contains a lot of information
2371 about LilyPond, but even more information can be gathered from
2372 looking at the internal LilyPond files.
2373
2374 Some default settings (such as the definitions for
2375 @code{\header@{@}}s) are stored as @code{.ly} files.  Other
2376 settings (such as the definitions of markup commands) are
2377 stored as @code{.scm} (Scheme) files.  Further explanation is
2378 outside the scope of this manual; users should be warned that
2379 a substantial amount of technical knowledge or time is required
2380 to understand these files.
2381
2382 @itemize
2383
2384 @item Linux: @file{@var{installdir}/lilypond/usr/share/lilypond/current/}
2385
2386 @item OSX:
2387 @file{@var{installdir}/LilyPond.app/Contents/Resources/share/lilypond/current/}.
2388 To access this, either @code{cd} into this directory from the
2389 Terminal, or control-click on the LilyPond application and select
2390 @q{Show Package Contents}.
2391
2392 @item Windows: @file{@var{installdir}/LilyPond/usr/share/lilypond/current/}
2393
2394 @end itemize
2395
2396 The @file{ly/} and @file{scm/} directories will be of
2397 particular interest.  Files such as @file{ly/property-init.ly} and
2398 @file{ly/declarations-init.ly} define all the common tweaks.
2399
2400
2401 @node Advanced tweaks with Scheme
2402 @subsection Advanced tweaks with Scheme
2403
2404 We have seen how LilyPond output can be heavily modified using
2405 commands like
2406 @code{\override TextScript #'extra-offset = ( 1 . -1)}.  But
2407 we have even more power if we use Scheme.  For a full explantion
2408 of this, see the @ref{Scheme tutorial}, and
2409 @ruser{Interfaces for programmers}.
2410
2411 We can use Scheme to simply @code{\override} commands,
2412
2413 @lilypond[quote,verbatim,ragged-right]
2414 padText = #(define-music-function (parser location padding) (number?)
2415 #{
2416   \once \override TextScript #'padding = #$padding
2417 #})
2418
2419 \relative c''' {
2420   c4^"piu mosso" b a b
2421   \padText #1.8
2422   c4^"piu mosso" d e f
2423   \padText #2.6
2424   c4^"piu mosso" fis a g
2425 }
2426 @end lilypond
2427
2428 We can use it to create new commands,
2429
2430 @lilypond[quote,verbatim,ragged-right]
2431 tempoMark = #(define-music-function (parser location padding marktext)
2432                                     (number? string?)
2433 #{
2434   \once \override Score . RehearsalMark #'padding = $padding
2435   \once \override Score . RehearsalMark #'extra-spacing-width = #'(+inf.0 . -inf.0)
2436   \mark \markup { \bold $marktext }
2437 #})
2438
2439 \relative c'' {
2440   c2 e
2441   \tempoMark #3.0 #"Allegro"
2442   g c
2443 }
2444 @end lilypond
2445
2446 Even music expressions can be passed in.
2447
2448 @lilypond[quote,verbatim,ragged-right]
2449 pattern = #(define-music-function (parser location x y) (ly:music? ly:music?)
2450 #{
2451   $x e8 a b $y b a e
2452 #})
2453
2454 \relative c''{
2455   \pattern c8 c8\f
2456   \pattern {d16 dis} { ais16-> b\p }
2457 }
2458 @end lilypond
2459
2460
2461 @node Avoiding tweaks with slower processing
2462 @subsection Avoiding tweaks with slower processing
2463
2464 LilyPond can perform extra checks while it processes files.  These
2465 commands will take extra time, but the result may require fewer
2466 manual tweaks.
2467
2468 @example
2469 %%  makes sure text scripts and lyrics are within the paper margins
2470 \override Score.PaperColumn #'keep-inside-line = ##t 
2471 \override Score.NonMusicalPaperColumn #'keep-inside-line = ##t
2472 @end example
2473
2474 In some cases (see issue 246), this must be done before
2475 @code{\override} commands can be processed.
2476
2477 @verbatim
2478 \new Score \with {
2479     \override PaperColumn #'keep-inside-line = ##t 
2480     \override NonMusicalPaperColumn #'keep-inside-line = ##t
2481   } {
2482    ..
2483 }
2484 @end verbatim
2485
2486
2487 @node The three methods of tweaking
2488 @subsection The three methods of tweaking
2489
2490 FIXME write this.
2491
2492 @verbatim
2493 \override
2494 @end verbatim
2495
2496 @verbatim
2497 \with {
2498
2499 }
2500 @end verbatim
2501
2502 @verbatim
2503 \layout{ \context
2504
2505 }}
2506 @end verbatim
2507
2508
2509
2510 FIXME discuss \tweak
2511
2512
2513
2514
2515
2516 FIXME:
2517 - There is a section in the manual on \set vs \override (3.3.7),
2518 which is incomplete.  First it doesn't mention \overrideProperty,
2519 nor does it mention properties which are not capitalized at all.
2520 And it should explain that \override should be used to set
2521 properties with hyphenated names, like auto-knee-gap.  (I had to
2522 experiment to find out how to do this.)
2523
2524
2525
2526
2527
2528
2529