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