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