]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
Remove duplicate cindex entries.
[lilypond.git] / Documentation / user / changing-defaults.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @node Changing defaults
3 @chapter Changing defaults
4
5
6 The purpose of LilyPond's design is to provide the finest output
7 quality as a default.  Nevertheless, it may happen that you need to
8 change this default layout.  The layout is controlled through a large
9 number of proverbial ``knobs and switches.''  This chapter does not
10 list each and every knob.  Rather, it outlines what groups of controls
11 are available and explains how to lookup which knob to use for a
12 particular effect.
13
14
15 @cindex Program reference
16
17 The controls available for tuning are described in a separate
18 document, the
19 @iftex
20 Program reference
21 @end iftex
22 @ifnottex
23 @ref{Top,Program reference,,lilypond-internals}.
24 @end ifnottex
25 manual.  That manual
26 lists all different variables, functions and options available in
27 LilyPond.  It is written as a HTML document, which is available
28 @uref{http://@/lilypond@/.org/@/doc/@/v2.5/@/Documentation/@/user/@/out@/-www/@/lilypond@/-internals/,on@/-line},
29 but is also included with the LilyPond documentation package.
30
31 There are three areas where the default settings may be changed:
32
33 @itemize @bullet
34 @item
35 Output: changing the appearance of individual
36 objects.  For example, changing stem directions or the location of
37 subscripts.
38   
39 @item
40 Context: changing aspects of the translation from music events to
41 notation.  For example, giving each staff a separate time signature. 
42   
43 @item
44 Global layout: changing the appearance of the spacing, line
45 breaks, and page dimensions.
46 @end itemize
47
48 Then there are separate systems for typesetting text (like
49 @emph{ritardando}) and selecting different fonts.  This chapter also
50 discusses these.
51
52 Internally, LilyPond uses Scheme (a LISP dialect) to provide
53 infrastructure.  Overriding layout decisions in effect accesses the
54 program internals, which requires Scheme input.  Scheme elements are
55 introduced in a @code{.ly} file with the hash mark
56 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
57 on entering numbers, lists, strings, and symbols in Scheme.}
58
59
60 @menu
61 * Interpretation contexts::     
62 * The \override command::       
63 * Fonts::                       
64 @end menu
65
66  
67 @node Interpretation contexts
68 @section Interpretation contexts
69
70 When music is printed, a lot of notational elements must be added to the
71 input, which is often bare bones.  For example, compare the input and
72 output of the following example:
73
74 @lilypond[quote,verbatim,relative=2,fragment]
75 cis4 cis2. g4
76 @end lilypond
77
78 The input is rather sparse, but in the output, bar lines, accidentals,
79 clef, and time signature are added.  LilyPond @emph{interprets} the
80 input.  During this step, the musical information is inspected in time
81 order, similar to reading a score from left to right.  While reading,
82 the input, the program remembers where measure boundaries are, and what
83 pitches need explicit accidentals.  This information can be presented on
84 several levels.  For example, the effect of an accidental is limited
85 to a single staff, while a bar line must be synchronized across the
86 entire score.
87
88 Within LilyPond, these rules and bits of information are grouped in
89 so-called Contexts.  Examples of context are @context{Voice},
90 @context{Staff}, and @context{Score}.  They are hierarchical, for
91 example, a @context{Staff} can contain many @context{Voice}s, and a
92 @context{Score} can contain many @context{Staff} contexts.
93
94 Each context has the responsibility for enforcing some notation rules,
95 creating some notation objects and maintaining the associated
96 properties.  So, the synchronization of bar lines is handled at
97 @context{Score} context.  The @context{Voice} may introduce an
98 accidental and then the @context{Staff} context maintains the rule to
99 show or suppress the accidental for the remainder of the measure.
100
101 For simple scores, contexts are created implicitly, and you need not
102 be aware of them.  For larger pieces, such as piano music, they must be
103 created explicitly to make sure that you get as many staves as you
104 need, and that they are in the correct order.  For typesetting pieces
105 with specialized notation, it can be useful to modify existing or
106 to define new contexts.
107
108
109 A complete description of all available contexts is in the program
110 reference, see
111 @ifhtml
112 @internalsref{Contexts}.
113 @end ifhtml
114 @ifnothtml 
115 Translation @arrow{} Context.
116 @end ifnothtml
117
118 @c [TODO: describe propagation]
119
120
121 @menu
122 * Creating contexts::           
123 * Changing context properties on the fly::  
124 * Modifying context plug-ins::  
125 * Layout tunings within contexts::  
126 * Changing context default settings::  
127 * Defining new contexts::       
128 @end menu
129
130 @node Creating contexts
131 @subsection Creating contexts
132
133 For scores with only one voice and one staff, correct contexts are
134 created automatically.  For more complex scores, it is necessary to
135 create them by hand.  There are three commands that do this.
136
137 The easiest command is @code{\new}, and it also the quickest to type.
138 It is prepended to a music expression, for example
139
140 @cindex @code{\new}
141 @cindex new contexts
142 @cindex Context, creating
143
144 @example
145 \new @var{type} @var{music expression}
146 @end example
147
148 @noindent
149 where @var{type} is a context name (like @code{Staff} or
150 @code{Voice}).  This command creates a new context, and starts
151 interpreting the @var{music expression} with that.
152
153 A practical application of @code{\new} is a score with many
154 staves.  Each part that should be on its own staff, is preceded with 
155 @code{\new Staff}.
156
157 @lilypond[quote,verbatim,relative=2,raggedright,fragment]
158 << \new Staff { c4 c }
159    \new Staff { d4 d }
160 >>
161 @end lilypond
162
163 @cindex @code{\context}
164
165 Like @code{\new}, the @code{\context} command also directs a music
166 expression to a context object, but gives the context an extra name.  The
167 syntax is
168
169 @example
170 \context @var{type} = @var{id} @var{music}
171 @end example
172
173 This form will search for an existing context of type @var{type}
174 called @var{id}.  If that context does not exist yet, it is created.
175 This is useful if the context is referred to later on.  For example, when
176 setting lyrics the melody is in a named context
177
178 @example
179 \context Voice = "@b{tenor}" @var{music}
180 @end example
181
182 @noindent
183 so the texts can be properly aligned to its notes,
184
185 @example
186 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics} 
187 @end example
188
189 @noindent
190
191 Another possibility is funneling two different music expressions into
192 one context.  In the following example, articulations and notes are
193 entered separately,
194
195 @example
196 music = @{ c4 c4 @}
197 arts = @{ s4-. s4-> @}
198 @end example
199
200 They are combined by sending both to the same @context{Voice} context,
201
202 @example
203 << \new Staff \context Voice = "A" \music
204    \context Voice = "A" \arts
205 >>
206 @end example
207 @lilypond[quote,raggedright]
208 music = { c4 c4 }
209 arts = { s4-. s4-> }
210 \relative c'' <<
211   \new Staff \context Voice = "A" \music
212   \context Voice = "A" \arts
213 >>
214 @end lilypond
215
216 With this mechanism, it is possible to define an Urtext (original
217 edition), with the option to put several distinct articulations on the
218 same notes.
219
220 @cindex creating contexts
221
222 The third command for creating contexts is
223 @example
224 \context @var{type} @var{music}
225 @end example
226
227
228 @noindent
229 This is similar to @code{\context} with @code{= @var{id}}, but matches
230 any context of type @var{type}, regardless of its given name.
231
232 This variant is used with music expressions that can be interpreted at
233 several levels.  For example, the @code{\applyoutput} command (see
234 @ref{Running a function on all layout objects}).  Without an explicit
235 @code{\context}, it is usually applied to @context{Voice}
236
237 @example
238 \applyoutput #@var{function}   % apply to Voice
239 @end example
240
241 To have it interpreted at the @context{Score} or @context{Staff} level use
242 these forms
243
244 @example
245 \context Score \applyoutput #@var{function}
246 \context Staff \applyoutput #@var{function}
247 @end example
248
249
250 @node Changing context properties on the fly
251 @subsection Changing context properties on the fly
252
253 @cindex properties
254 @cindex @code{\set}
255 @cindex changing properties
256
257 Each context can have different @emph{properties}, variables contained
258 in that context.  They can be changed during the interpretation step.
259 This is achieved by inserting the @code{\set} command in the music,
260
261 @example
262 \set @var{context}.@var{prop} = #@var{value}
263 @end example
264
265 For example,
266 @lilypond[quote,verbatim,relative=2,fragment]
267 R1*2 
268 \set Score.skipBars = ##t
269 R1*2
270 @end lilypond
271
272 This command skips measures that have no notes.  The result is that
273 multi-rests are condensed.  The value assigned is a Scheme object.  In
274 this case, it is @code{#t}, the boolean True value.
275
276 If the @var{context} argument is left out, then the current bottom-most
277 context (typically @context{ChordNames}, @context{Voice}, or
278 @context{Lyrics}) is used.  In this example,
279
280 @lilypond[quote,verbatim,relative=2,fragment]
281 c8 c c c
282 \set autoBeaming = ##f
283 c8 c c c
284 @end lilypond
285
286 @noindent
287 the @var{context} argument to @code{\set} is left out, so automatic
288 beaming is switched off in the current @internalsref{Voice}.  Note that
289 the bottom-most context does not always contain the property that you
290 wish to change -- for example, attempting to set the @code{skipBars}
291 property (of the bottom-most context, in this case @code{Voice}) will
292 have no effect.
293
294 @lilypond[quote,verbatim,relative=2,fragment]
295 R1*2 
296 \set skipBars = ##t
297 R1*2
298 @end lilypond
299
300 Contexts are hierarchical, so if a bigger context was specified, for
301 example @context{Staff}, then the change would also apply to all
302 @context{Voice}s in the current stave.  The change is applied
303 `on-the-fly', during the music, so that the setting only affects the
304 second group of eighth notes.
305
306 @cindex @code{\unset} 
307
308 There is also an @code{\unset} command,
309 @example
310 \unset @var{context}.@var{prop}
311 @end example
312
313 @noindent
314 which removes the definition of @var{prop}.  This command removes
315 the definition only if it is set in @var{context}, so
316
317 @example
318 \set Staff.autoBeaming = ##f
319 @end example
320
321 @noindent
322 introduces a property setting at @code{Staff} level.  The setting also
323 applies to the current @code{Voice}.  However,
324
325 @example
326 \unset Voice.autoBeaming
327 @end example
328
329 @noindent
330 does not have any effect.  To cancel this setting, the @code{\unset}
331 must be specified on the same level as the original @code{\set}.  In
332 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
333 requires
334 @example
335 \unset Staff.autoBeaming
336 @end example
337
338 Like @code{\set}, the @var{context} argument does not have to be
339 specified for a bottom context, so the two statements
340
341 @example
342 \set Voice.autoBeaming = ##t 
343 \set autoBeaming = ##t 
344 @end example 
345
346 @noindent
347 are equivalent.
348
349
350 @cindex \once
351 Settings that should only apply to a single time-step can be entered
352 with @code{\once}, for example in
353
354 @lilypond[quote,verbatim,relative=2,fragment]
355 c4
356 \once \set fontSize = #4.7
357 c4
358 c4
359 @end lilypond
360
361 the property @code{fontSize} is unset automatically after the second
362 note.
363
364 A full description of all available context properties is in the
365 program reference, see
366 @ifhtml
367 @internalsref{Tunable context properties}.
368 @end ifhtml
369 @ifnothtml
370 Translation @arrow{} Tunable context properties.
371 @end ifnothtml
372
373
374 @node Modifying context plug-ins
375 @subsection Modifying context plug-ins
376
377 Notation contexts (like Score and Staff) not only store properties,
378 they also contain plug-ins, called ``engravers'' that create notation
379 elements.  For example, the Voice context contains a
380 @code{Note_head_engraver} and the Staff context contains a
381 @code{Key_signature_engraver}.
382
383 For a full a description of each plug-in, see 
384 @ifhtml
385 @internalsref{Engravers}.
386 @end ifhtml
387 @ifnothtml
388 Program reference @arrow Translation @arrow{} Engravers.
389 @end ifnothtml
390 Every context described in
391 @ifhtml
392 @internalsref{Contexts}
393 @end ifhtml
394 @ifnothtml 
395 Program reference @arrow Translation @arrow{} Context.
396 @end ifnothtml
397 lists the engravers used for that context.
398
399
400 It can be useful to shuffle around these plug-ins.  This is done by
401 starting a new context, with @code{\new} or @code{\context}, and
402 modifying it like this, 
403
404 @example
405 \new @var{context} \with @{
406   \consists @dots{}
407   \consists @dots{}
408   \remove @dots{}
409   \remove @dots{}
410   @emph{etc.}
411 @}
412 @emph{..music..}
413 @end example
414
415 @noindent
416 where the @dots{} should be the name of an engraver.  Here is a simple
417 example which removes @code{Time_signature_engraver} and
418 @code{Clef_engraver} from a @code{Staff} context,
419
420 @lilypond[quote,relative=1,verbatim,fragment]
421 << \new Staff {
422     f2 g
423   }
424   \new Staff \with {
425      \remove "Time_signature_engraver"
426      \remove "Clef_engraver"
427   } {
428     f2 g2
429   }
430 >>
431 @end lilypond
432
433 In the second staff there are no time signature or clef symbols.  This
434 is a rather crude method of making objects disappear since it will affect
435 the entire staff.  The spacing is adversely influenced too.  A more
436 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
437
438 The next example shows a practical application.  Bar lines and time
439 signatures are normally synchronized across the score.  This is done
440 by the @code{Timing_engraver}.  This plug-in keeps an administration of
441 time signature, location within the measure, etc.  By moving the
442 @code{Timing_engraver} engraver from @code{Score} to @code{Staff}
443 context, we can have a score where each staff has its own time
444 signature.
445
446 @cindex polymetric scores
447 @cindex Time signatures, multiple
448
449 @lilypond[quote,relative=1,raggedright,verbatim,fragment]
450 \new Score \with {
451   \remove "Timing_engraver"
452 } <<
453   \new Staff \with {
454     \consists "Timing_engraver"
455   } {
456       \time 3/4
457       c4 c c c c c
458   }
459   \new Staff \with {
460     \consists "Timing_engraver"
461   } {
462        \time 2/4
463        c4 c c c c c
464   }
465 >>
466 @end lilypond
467
468
469 @node Layout tunings within contexts
470 @subsection Layout tunings within contexts
471
472 Each context is responsible for creating certain types of graphical
473 objects.  The settings used for printing these objects are also stored by
474 context.  By changing these settings, the appearance of objects can be
475 altered.
476  
477 The syntax for this is
478
479 @example
480 \override @var{context}.@var{name} #'@var{property} = #@var{value}
481 @end example
482
483 Here @var{name} is the name of a graphical object, like @code{Stem} or
484 @code{NoteHead}, and @var{property} is an internal variable of the
485 formatting system (`grob property' or `layout property').  The latter is a
486 symbol, so it must be quoted.  The subsection @ref{Constructing a
487 tweak} explains what to fill in for @var{name}, @var{property}, and
488 @var{value}.  Here we only discuss the functionality of this command.
489
490 The command
491
492 @verbatim
493 \override Staff.Stem #'thickness = #4.0 
494 @end verbatim
495
496 @noindent
497 makes stems thicker (the default is 1.3, with staff line thickness as a
498 unit).  Since the command specifies @context{Staff} as context, it only
499 applies to the current staff.  Other staves will keep their normal
500 appearance.  Here we see the command in action:
501
502 @lilypond[quote,verbatim,relative=2,fragment]
503 c4
504 \override Staff.Stem #'thickness = #4.0 
505 c4
506 c4
507 c4
508 @end lilypond
509
510 The @code{\override} command changes the definition of the @code{Stem}
511 within the current @context{Staff}.  After the command is interpreted
512 all stems are thickened.
513
514 Analogous to @code{\set}, the @var{context} argument may be left out,
515 causing it to default to @context{Voice}, and adding @code{\once} applies
516 the change during one timestep only 
517
518 @lilypond[quote,fragment,verbatim,relative=2]
519 c4
520 \once \override Stem #'thickness = #4.0 
521 c4
522 c4 
523 @end lilypond
524
525 The @code{\override} must be done before the object is
526 started.  Therefore, when altering @emph{Spanner} objects, like slurs or
527 beams, the @code{\override} command must be executed at the moment when
528 the object is created.  In this example,
529
530
531 @lilypond[quote,fragment,verbatim,relative=2]
532 \override Slur #'thickness = #3.0
533 c8[( c
534 \override Beam #'thickness = #0.6
535 c8 c]) 
536 @end lilypond
537
538 @noindent
539 the slur is fatter but the beam is not.  This is because the command for
540 @code{Beam} comes after the Beam is started.  Therefore it has no effect.
541
542 Analogous to @code{\unset}, the @code{\revert} command for a context
543 undoes an @code{\override} command; like with @code{\unset}, it only
544 affects settings that were made in the same context.  In other words, the
545 @code{\revert} in the next example does not do anything.
546
547 @example
548 \override Voice.Stem #'thickness = #4.0
549 \revert Staff.Stem #'thickness
550 @end example
551
552
553
554
555 @seealso
556
557 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
558 @internalsref{PropertySet}, @internalsref{Backend}, and
559 @internalsref{All layout objects}.
560
561
562 @refbugs
563
564 The back-end is not very strict in type-checking object properties.
565 Cyclic references in Scheme values for properties can cause hangs
566 or crashes, or both.
567
568
569 @node Changing context default settings
570 @subsection Changing context default settings
571
572 The adjustments of the previous subsections (@ref{Changing context
573 properties on the fly}, @ref{Modifying context plug-ins}, and
574 @ref{Layout tunings within contexts}) can also be entered separately
575 from the music, in the @code{\layout} block,
576
577 @example
578 \layout @{
579   @dots{}
580   \context @{
581     \Staff
582
583     \set fontSize = #-2
584     \override Stem #'thickness = #4.0
585     \remove "Time_signature_engraver"
586   @}
587 @}
588 @end example
589
590 Here
591 @example
592 \Staff
593 @end example
594
595 @noindent
596 takes the existing definition for context @context{Staff} from the
597 identifier @code{\Staff}. 
598
599 The statements
600 @example
601 \set fontSize = #-2
602 \override Stem #'thickness = #4.0
603 \remove "Time_signature_engraver"
604 @end example
605
606 @noindent
607 affect all staves in the score.
608
609 Other contexts can be modified analogously.
610
611 The @code{\set} keyword is optional within the @code{\layout} block, so
612
613 @example
614 \context @{
615   @dots{}
616   fontSize = #-2
617 @}
618 @end example
619
620 @noindent
621 will also work.
622
623
624
625 @refbugs
626
627 It is not possible to collect context changes in a variable, and apply
628 them to one @code{\context} definition by referring to that variable.
629
630 The @code{\RemoveEmptyStaffContext} will override your current
631 @code{\Staff} variable.  If you wish to change the defaults for a
632 staff that uses @code{\RemoveEmptyStaffContext}, you must do so
633 after calling @code{\RemoveemptyStaffContext}, ie
634
635 @example
636 \layout @{
637   \context @{
638     \RemoveEmptyStaffContext
639
640     \override Stem #'thickness = #4.0
641   @}
642 @}
643 @end example
644
645
646 @node Defining new contexts
647 @subsection Defining new contexts
648
649 Specific contexts, like @context{Staff} and @code{Voice}, are made of
650 simple building blocks, and it is possible to compose engraver
651 plug-ins in different combinations, thereby creating new types of
652 contexts.
653
654 The next example shows how to build a different type of
655 @context{Voice} context from scratch.  It will be similar to
656 @code{Voice}, but prints centered slash noteheads only.  It can be used
657 to indicate improvisation in Jazz pieces,
658
659 @lilypond[quote,raggedright]
660 \layout { \context {
661   \name ImproVoice
662   \type "Engraver_group_engraver"
663   \consists "Note_heads_engraver"
664   \consists "Text_engraver"
665   \consists Pitch_squash_engraver
666   squashedPosition = #0
667   \override NoteHead #'style = #'slash
668   \override Stem #'transparent = ##t
669   \alias Voice
670 }
671 \context { \Staff
672   \accepts "ImproVoice"
673 }}
674
675 \relative c'' {
676   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c 
677    c4 c^"undress" c_"while playing :)" c } 
678   a1 
679 }
680 @end lilypond
681
682
683 These settings are again done within a @code{\context} block inside a
684 @code{\layout} block,
685
686 @example
687 \layout @{
688   \context @{
689     @dots{}
690   @}
691 @}
692 @end example
693
694 In the following discussion, the example input shown should go on the
695 @dots{} in the previous fragment.
696
697 First, the context gets a name.  Instead of @context{Voice} it
698 will be called @context{ImproVoice},
699
700 @example
701 \name ImproVoice
702 @end example
703
704 Since it is similar to the @context{Voice}, we want commands that work
705 on (existing) @context{Voice}s to remain working.  This is achieved by
706 giving the new context an alias @context{Voice},
707
708 @example
709 \alias Voice
710 @end example
711
712 The context will print notes, and instructive texts
713
714 @example
715 \consists Note_heads_engraver
716 \consists Text_engraver
717 @end example
718
719 but only on the center line,
720
721 @example
722 \consists Pitch_squash_engraver
723 squashedPosition = #0
724 @end example
725
726 The @internalsref{Pitch_squash_engraver} modifies note heads (created
727 by @internalsref{Note_heads_engraver}) and sets their vertical
728 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
729 the center line.
730
731 The notes look like a slash, without a stem,
732
733 @example
734 \override NoteHead #'style = #'slash
735 \override Stem #'transparent = ##t
736 @end example
737
738
739 All these plug-ins have to cooperate, and this is achieved with a
740 special plug-in, which must be marked with the keyword @code{\type}.
741 This should always be @internalsref{Engraver_group_engraver},
742
743 @example
744 \type "Engraver_group_engraver"
745 @end example
746
747 Put together, we get
748
749 @example
750 \context @{
751   \name ImproVoice
752   \type "Engraver_group_engraver"
753   \consists "Note_heads_engraver"
754   \consists "Text_engraver"
755   \consists Pitch_squash_engraver
756   squashedPosition = #0
757   \override NoteHead #'style = #'slash
758   \override Stem #'transparent = ##t
759   \alias Voice
760 @}
761 @end example
762
763 Contexts form hierarchies.  We want to hang the @context{ImproVoice}
764 under @context{Staff}, just like normal @code{Voice}s.  Therefore, we
765 modify the @code{Staff} definition with the @code{\accepts}
766 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
767 which is sometimes needed when reusing existing context definitions.}
768
769
770
771 @example
772 \context @{
773   \Staff
774   \accepts ImproVoice    
775 @}
776 @end example
777
778 Putting both into a @code{\layout} block, like
779
780 @example
781 \layout @{
782   \context @{
783     \name ImproVoice
784     @dots{}
785   @}
786   \context @{
787     \Staff
788     \accepts "ImproVoice"
789   @}
790 @}
791 @end example
792
793 Then the output at the start of this subsection can be entered as
794
795 @example
796 \relative c'' @{
797   a4 d8 bes8
798   \new ImproVoice @{
799     c4^"ad lib" c 
800     c4 c^"undress"
801     c c_"while playing :)"
802   @}
803   a1
804 @}
805 @end example
806   
807
808     
809
810 @node The \override command
811 @section The \override command
812
813 In the previous section, we have already touched on a command that
814 changes layout details: the @code{\override} command.  In this section,
815 we will look in more detail at how to use the command in practice.
816 First, we will give a few versatile commands that are sufficient
817 for many situations.  The next section will discuss the general use of
818 @code{\override}.
819
820
821 @menu
822 * Common tweaks::               
823 * Constructing a tweak::        
824 * Navigating the program reference::  
825 * Layout interfaces::           
826 * Determining the grob property::  
827 * Difficult tweaks::            
828 @end menu
829
830
831
832 @node Common tweaks
833 @subsection Common tweaks
834
835 @c  Should we point at ly/property-init.ly ?  -gp
836 Some overrides are so common that predefined commands are provided as
837 short-cuts, for example, @code{\slurUp} and @code{\stemDown}.  These
838 commands are described in
839 @ifhtml
840 the
841 @end ifhtml
842 @c @ref{Notation manual},
843 Notation manual
844 @c FIXME 
845 under the sections for slurs and stems
846 respectively.
847
848 The exact tuning possibilities for each type of layout object are
849 documented in the program reference of the respective
850 object.  However, many layout objects share properties, which can be
851 used to apply generic tweaks.  We mention a few of these:
852
853 @itemize @bullet
854 @item The @code{extra-offset} property, which
855 @cindex @code{extra-offset}
856 has a pair of numbers as value, moves objects around in the printout.
857 The first number controls left-right movement; a positive number will
858 move the object to the right.  The second number controls up-down
859 movement; a positive number will move it higher.  The units of these
860 offsets are staff-spaces.  The @code{extra-offset} property is a
861 low-level feature: the formatting engine is completely oblivious to
862 these offsets.
863
864 In the following example, the second fingering is moved a little to
865 the left, and 1.8 staff space downwards:
866
867 @cindex setting object properties
868
869 @lilypond[quote,fragment,relative=1,verbatim]
870 \stemUp
871 f-5
872 \once \override Fingering
873     #'extra-offset = #'(-0.3 . -1.8) 
874 f-5
875 @end lilypond
876
877 @item
878 Setting the @code{transparent} property will cause an object to be printed
879 in `invisible ink': the object is not printed, but all its other
880 behavior is retained.  The object still takes up space, it takes part in
881 collisions, and slurs, ties, and beams can be attached to it.
882
883 @cindex transparent objects
884 @cindex removing objects
885 @cindex hiding objects
886 @cindex invisible objects
887 The following example demonstrates how to connect different voices
888 using ties.  Normally, ties only connect two notes in the same
889 voice.  By introducing a tie in a different voice,
890
891 @lilypond[quote,fragment,relative=2]
892 << {
893   b8~ b8\noBeam
894 } \\ {
895   b[ g8]
896 } >>
897 @end lilypond
898
899 @noindent
900 and blanking the first up-stem in that voice, the tie appears to cross
901 voices:
902
903 @lilypond[quote,fragment,relative=2,verbatim]
904 << {
905   \once \override Stem #'transparent = ##t
906   b8~ b8\noBeam
907 } \\ {
908   b[ g8]
909 } >>
910 @end lilypond
911
912 @item
913 The @code{padding} property for objects with
914 @cindex @code{padding}
915 @code{side-position-interface} can be set to increase the distance between
916 symbols that are printed above or below notes.  We provide two
917 examples; a more elaborate explanation is in @ref{Constructing a
918 tweak}:
919
920 @lilypond[quote,fragment,relative=1,verbatim]
921 c2\fermata
922 \override Script #'padding = #3
923 b2\fermata
924 @end lilypond
925
926 @lilypond[quote,fragment,relative=1,verbatim]
927 % This will not work, see below:
928 \override MetronomeMark #'padding = #3
929 \tempo 4=120
930 c1
931 % This works:
932 \override Score.MetronomeMark #'padding = #3
933 \tempo 4=80
934 d1
935 @end lilypond
936
937 Note in the second example how important it is to figure out what
938 context handles a certain object. Since the @code{MetronomeMark} object
939 is handled in the Score context, property changes in the @code{Voice}
940 context will not be noticed. 
941
942 @end itemize
943
944 More specific overrides are also possible.  The next section
945 discusses in depth how to figure out these statements for yourself.
946
947
948 @node Constructing a tweak
949 @subsection Constructing a tweak
950
951 The general procedure of changing output, that is, entering
952 a command like
953
954 @example
955 \override Voice.Stem #'thickness = #3.0
956 @end example
957
958 @noindent
959 means that we have to determine these bits of information:
960
961 @itemize
962 @item the context: here @context{Voice}.
963 @item the layout object: here @code{Stem}.
964 @item the layout property: here @code{thickness}
965 @item a sensible value: here @code{3.0}
966 @end itemize  
967
968
969 @cindex internal documentation
970 @cindex finding graphical objects
971 @cindex graphical object descriptions 
972 @cindex tweaking
973 @cindex @code{\override}
974 @cindex internal documentation
975
976 We demonstrate how to glean this information from the notation manual
977 and the program reference.
978
979 @node Navigating the program reference
980 @subsection Navigating the program reference
981
982 Suppose we want to move the fingering indication in the fragment
983 below:
984
985 @lilypond[quote,fragment,relative=2,verbatim]
986 c-2
987 \stemUp
988 f
989 @end lilypond
990
991 If you visit the documentation on fingering instructions (in
992 @ref{Fingering instructions}), you will notice that there is written:
993
994 @quotation
995 @seealso
996
997 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
998
999 @end quotation
1000
1001
1002
1003 This fragment points to two parts of the program reference: a page
1004 on @code{FingerEvent} and one on @code{Fingering}.
1005
1006 The page on @code{FingerEvent} describes the properties of the music
1007 expression for the input @code{-2}.  The page contains many links
1008 forward.  For example, it says
1009
1010 @quotation
1011 Accepted by: @internalsref{Fingering_engraver},
1012 @end quotation 
1013
1014 @noindent
1015 That link brings us to the documentation for the Engraver, the
1016 plug-in, which says
1017
1018 @quotation
1019 This engraver creates the following layout objects: @internalsref{Fingering}.
1020 @end quotation
1021
1022 In other words, once the @code{FingerEvent}s are interpreted, the
1023 @code{Fingering_engraver} plug-in will process them.
1024 The @code{Fingering_engraver} is also listed to create
1025 @internalsref{Fingering} objects,
1026
1027
1028 Lo and behold, that is also the
1029 second bit of information listed under @b{See also} in the Notation
1030 manual.  By clicking around in the program reference, we can follow the
1031 flow of information within the program, either forward (like we did
1032 here), or backwards, following links like this:
1033
1034 @itemize @bullet
1035
1036 @item @internalsref{Fingering}:
1037 @internalsref{Fingering} objects are created by:
1038 @b{@internalsref{Fingering_engraver}}
1039
1040 @item @internalsref{Fingering_engraver}:
1041 Music types accepted: @b{@internalsref{fingering-event}}
1042
1043 @item @internalsref{fingering-event}:
1044 Music event type @code{fingering-event} is in Music expressions named
1045 @b{@internalsref{FingerEvent}}
1046 @end itemize
1047
1048 This path goes against the flow of information in the program: it
1049 starts from the output, and ends at the input event.
1050
1051 The program reference can also be browsed like a normal document.  It
1052 contains a chapter on
1053 @ifhtml
1054 @internalsref{Music definitions},
1055 @end ifhtml
1056 @ifnothtml
1057 @code{Music definitions}
1058 @end ifnothtml
1059 on @internalsref{Translation}, and the @internalsref{Backend}.  Every
1060 chapter lists all the definitions used, and all properties that may be
1061 tuned.
1062
1063  
1064 @node Layout interfaces
1065 @subsection Layout interfaces
1066
1067 @cindex interface, layout
1068 @cindex layout interface
1069
1070 The HTML page that we found in the previous section, describes the
1071 layout object called @internalsref{Fingering}.  Such an object is a
1072 symbol within the score.  It has properties that store numbers (like
1073 thicknesses and directions), but also pointers to related objects.  A
1074 layout object is also called @emph{grob},
1075 @cindex grob
1076 which is short for Graphical Object.
1077
1078
1079 The page for @code{Fingering} lists the definitions for the
1080 @code{Fingering} object.  For example, the page says
1081
1082 @quotation
1083 @code{padding} (dimension, in staff space):
1084   
1085 @code{0.6}
1086 @end quotation
1087
1088 @noindent
1089 which means that the number will be kept at a distance of at least 0.6
1090 of the note head.
1091
1092
1093 Each layout object may have several functions as a notational or
1094 typographical element.  For example, the Fingering object
1095 has the following aspects
1096
1097 @itemize @bullet
1098 @item
1099 Its size is independent of the horizontal spacing, unlike slurs or beams.
1100
1101 @item
1102 It is a piece of text.  Granted, it is usually a very short text.
1103
1104 @item
1105 That piece of text is typeset with a font, unlike slurs or beams.
1106
1107 @item
1108 Horizontally, the center of the symbol should be aligned to the
1109 center of the notehead.
1110
1111 @item
1112 Vertically, the symbol is placed next to the note and the staff.
1113
1114 @item
1115 The vertical position is also coordinated with other super- and subscript
1116 symbols.
1117 @end itemize
1118
1119 Each of these aspects is captured in so-called @emph{interface}s,
1120 which are listed on the @internalsref{Fingering} page at the bottom
1121
1122 @quotation
1123 This object supports the following interfaces:
1124 @internalsref{item-interface},
1125 @internalsref{self-alignment-interface},
1126 @internalsref{side-position-interface}, @internalsref{text-interface},
1127 @internalsref{text-script-interface}, @internalsref{font-interface},
1128 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1129 @end quotation
1130
1131 Clicking any of the links will take you to the page of the respective
1132 object interface.  Each interface has a number of properties.  Some of
1133 them are not user-serviceable (``Internal properties''), but others
1134 are.
1135
1136 We have been talking of @emph{the} @code{Fingering} object, but actually it
1137 does not amount to much.  The initialization file
1138 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1139
1140 @example
1141 (Fingering
1142   . ((print-function . ,Text_interface::print)
1143      (padding . 0.6)
1144      (staff-padding . 0.6)
1145      (self-alignment-X . 0)
1146      (self-alignment-Y . 0)
1147      (script-priority . 100)
1148      (font-size . -5)
1149      (meta . ((interfaces . (finger-interface font-interface
1150                              text-script-interface text-interface
1151                              side-position-interface
1152                              self-alignment-interface
1153                              item-interface))))))
1154 @end example
1155
1156 @noindent
1157 As you can see, the @code{Fingering} object is nothing more than a
1158 bunch of variable settings, and the webpage in the Program Reference
1159 is directly generated from this definition.
1160
1161 @node Determining the grob property
1162 @subsection Determining the grob property
1163
1164
1165 Recall that we wanted to change the position of the @b{2} in 
1166
1167 @lilypond[quote,fragment,relative=2,verbatim]
1168 c-2
1169 \stemUp
1170 f
1171 @end lilypond
1172
1173 Since the @b{2} is vertically positioned next to its note, we have to
1174 meddle with the interface associated with this positioning.  This is
1175 done using @code{side-position-interface}.  The page for this interface 
1176 says
1177
1178 @quotation
1179 @code{side-position-interface}
1180
1181 Position a victim object (this one) next to other objects (the
1182 support).  The property @code{direction} signifies where to put the
1183 victim object relative to the support (left or right, up or down?)
1184 @end quotation
1185
1186 @cindex padding
1187 @noindent
1188 below this description, the variable @code{padding} is described as
1189
1190 @quotation
1191 @table @code
1192 @item padding
1193 (dimension, in staff space)
1194
1195 Add this much extra space between objects that are next to each other. 
1196 @end table
1197 @end quotation
1198
1199 By increasing the value of @code{padding}, we can move away the
1200 fingering.  The following command inserts 3 staff spaces of white
1201 between the note and the fingering:
1202 @example
1203 \once \override Voice.Fingering #'padding = #3
1204 @end example
1205
1206 Inserting this command before the Fingering object is created,
1207 i.e., before @code{c2}, yields the following result:
1208
1209 @lilypond[quote,relative=2,fragment,verbatim]
1210 \once \override Voice.Fingering #'padding = #3
1211 c-2
1212 \stemUp
1213 f
1214 @end lilypond
1215
1216
1217 In this case, the context for this tweak is @context{Voice}.  This
1218 fact can also be deduced from the program reference, for the page for
1219 the @internalsref{Fingering_engraver} plug-in says
1220
1221 @quotation
1222 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1223 @end quotation
1224
1225 @node Difficult tweaks
1226 @subsection Difficult tweaks
1227
1228 There are two classes of difficult adjustments.  First, when there are
1229 several of the same objects at one point, and you want to adjust only
1230 one.  For example, if you want to change only one note head in a chord.
1231
1232 In this case, the @code{\applyoutput} function must be used.  The
1233 next example defines a Scheme function @code{set-position-font-size}
1234 that sets the @code{font-size} property, but only  
1235 on objects that have @internalsref{note-head-interface} and are at the
1236 right Y-position.
1237
1238 @lilypond[quote,verbatim]
1239 #(define ((set-position-font-size pos size) grob origin current)
1240   (let*
1241       ((interfaces (ly:grob-property grob 'interfaces))
1242        (position (ly:grob-property grob 'staff-position)))
1243    (if (and
1244         ; is this a note head?
1245         (memq 'note-head-interface interfaces)
1246
1247         ; is the Y coordinate right?
1248         (= pos position))
1249
1250       ; then do it.
1251       (set! (ly:grob-property grob 'font-size) size))))
1252
1253 \relative {
1254   c
1255   \applyoutput #(set-position-font-size -2 4)
1256   <c e g>
1257 }
1258 @end lilypond
1259
1260 @noindent
1261 A similar technique can be used for accidentals.  In that case, the
1262 function should check for @code{accidental-interface}.
1263
1264 Another difficult adjustment is the appearance of spanner objects,
1265 such as slur and tie.  Initially, only one of these objects is created,
1266 and they can be adjusted with the normal mechanism.  However, in some
1267 cases the spanners cross line breaks.  If this happens, these objects
1268 are cloned.  A separate object is created for every system that it is
1269 in.  These are clones of the original object and inherit all
1270 properties, including @code{\override}s.
1271
1272 In other words, an @code{\override} always affects all pieces of a
1273 broken spanner.  To change only one part of a spanner at a line break,
1274 it is necessary to hook into the formatting process.  The
1275 @code{after-line-breaking-callback} property contains the Scheme procedure
1276 that is called after the line breaks have been determined, and layout
1277 objects have been split over different systems.
1278
1279 In the following example, we define a procedure
1280 @code{my-callback}.  This procedure
1281  
1282 @itemize @bullet
1283 @item
1284 determines if we have been split across line breaks
1285 @item
1286 if yes, retrieves all the split objects
1287 @item
1288 checks if we are the last of the split objects
1289 @item
1290 if yes, it sets @code{extra-offset}.
1291 @end itemize
1292
1293 This procedure is installed into @internalsref{Tie}, so the last part
1294 of the broken tie is translated up.
1295
1296
1297 @lilypond[quote,verbatim,raggedright]
1298 #(define (my-callback grob)
1299   (let* (
1300          ; have we been split? 
1301          (orig (ly:grob-original grob))
1302
1303          ; if yes, get the split pieces (our siblings)
1304          (siblings (if (ly:grob? orig)
1305                      (ly:spanner-broken-into orig) '() )))
1306
1307    (if (and (>= (length siblings) 2)
1308              (eq? (car (last-pair siblings)) grob))
1309      (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1310
1311 \relative c'' { 
1312   \override Tie #'after-line-breaking-callback =
1313   #my-callback
1314   c1 ~ \break c2 ~ c
1315 }
1316 @end lilypond
1317
1318 @noindent
1319 When applying this trick, the new @code{after-line-breaking-callback}
1320 should also call the old @code{after-line-breaking-callback}, if there
1321 is one.  For example, if using this with @code{Slur},
1322 @code{Slur::after_line_breaking} should also be called.
1323
1324 @node Fonts
1325 @section Fonts
1326
1327 This section details the ways that the font can be changed.
1328
1329 @menu
1330 * Selecting font sizes::        
1331 * Font selection::              
1332 @end menu
1333
1334
1335
1336 @node Selecting font sizes
1337 @subsection Selecting font sizes
1338
1339
1340 The easiest method of setting the font size of any context, is by
1341 setting the @code{fontSize} property.
1342
1343 @lilypond[quote,fragment,relative=1,verbatim]
1344 c8
1345 \set fontSize = #-4
1346 c f
1347 \set fontSize = #3
1348 g
1349 @end lilypond
1350
1351 @noindent
1352 It does not change the size of variable symbols, such as beams or
1353 slurs.
1354
1355 Internally, the @code{fontSize} context property will cause the
1356 @code{font-size} property to be set in all layout objects.  The value
1357 of @code{font-size} is a number indicating the size relative to the
1358 standard size for the current staff height.  Each step up is an
1359 increase of approximately 12% of the font size.  Six steps is exactly a
1360 factor two.  The Scheme function @code{magstep} converts a
1361 @code{font-size} number to a scaling factor.
1362
1363 @lilypond[quote,fragment,relative=1,verbatim]
1364 c8
1365 \override NoteHead #'font-size = #-4
1366 c f
1367 \override NoteHead #'font-size = #3
1368 g
1369 @end lilypond
1370
1371 LilyPond has fonts in different design sizes.  The music fonts for
1372 smaller sizes are chubbier, while the text fonts are relatively wider.
1373 Font size changes are achieved by scaling the design size that is
1374 closest to the desired size.  The standard font size (for
1375 @code{font-size} equals 0), depends on the standard staff height.  For
1376 a 20pt staff, a 10pt font is selected.
1377
1378 The @code{font-size} property can only be set on layout objects that
1379 use fonts. These are the ones supporting the
1380 @internalsref{font-interface} layout interface.
1381
1382 @refcommands
1383
1384 The following commands set @code{fontSize} for the current voice:
1385
1386 @cindex @code{\tiny}
1387 @code{\tiny}, 
1388 @cindex @code{\small}
1389 @code{\small}, 
1390 @cindex @code{\normalsize}
1391 @code{\normalsize}.
1392
1393
1394
1395 @cindex magnification
1396 @cindex cue notes
1397
1398
1399 @node Font selection
1400 @subsection Font selection
1401
1402
1403
1404 @cindex font selection
1405 @cindex font magnification
1406 @cindex @code{font-interface}
1407
1408 By setting the object properties described below, you can select a
1409 font from the preconfigured font families.  LilyPond has default
1410 support for the feta music fonts and @TeX{}'s Computer Modern text
1411 fonts.
1412
1413
1414 @itemize @bullet
1415 @item @code{font-encoding}
1416 is a symbol that sets layout of the glyphs.  This should only be set to
1417 select different types of non-text fonts, eg.
1418
1419 @code{fetaBraces} for piano staff braces, @code{fetaMusic} the
1420 standard music font, including ancient glyphs, @code{fetaDynamic} for
1421 dynamic signs and @code{fetaNumber} for the number font.
1422
1423 @item @code{font-family}
1424 is a symbol indicating the general class of the typeface.  Supported are
1425 @code{roman} (Computer Modern), @code{sans}, and @code{typewriter}.
1426   
1427 @item @code{font-shape}
1428 is a symbol indicating the shape of the font.  There are typically
1429 several font shapes available for each font family.  Choices are
1430 @code{italic}, @code{caps}, and @code{upright}.
1431
1432 @item @code{font-series}
1433 is a symbol indicating the series of the font.  There are typically
1434 several font series for each font family and shape.  Choices are
1435 @code{medium} and @code{bold}. 
1436
1437 @end itemize
1438
1439 Fonts selected in the way sketched above come from a predefined style
1440 sheet. If you want to use a font from outside the style sheet, 
1441 then set the 
1442 @code{font-name} property, 
1443
1444 @lilypond[fragment,verbatim]
1445 {
1446   \override Staff.TimeSignature #'font-name = #"Times"
1447   \override Staff.TimeSignature #'font-size = #2
1448   \time 3/4
1449   c'1_\markup {
1450     \override #'(font-name . "Vera Bold")
1451       { This text is in Vera Bold }
1452   }
1453 }
1454 @end lilypond
1455
1456 @noindent
1457 Any font can be used, as long as it is available to Pango/FontConfig.
1458
1459 The size of the font may be set with the @code{font-size}
1460 property. The resulting size is taken relative to the
1461 @code{text-font-size} as defined in the @code{\paper} block.
1462
1463
1464 @cindex font size
1465 @cindex font magnification
1466
1467
1468
1469 @seealso
1470
1471 Init files: @file{ly/@/declarations@/-init@/.ly} contains hints how new
1472 fonts may be added to LilyPond.
1473
1474
1475
1476