]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
9e379f688a1f99ffa63426ef77033c8579ef62e2
[lilypond.git] / Documentation / user / changing-defaults.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @node Changing defaults
11 @chapter Changing defaults
12
13
14 The purpose of LilyPond's design is to provide the finest output
15 quality as a default.  Nevertheless, it may happen that you need to
16 change this default layout.  The layout is controlled through a large
17 number of proverbial @q{knobs and switches.}  This chapter does not
18 list each and every knob.  Rather, it outlines what groups of controls
19 are available and explains how to lookup which knob to use for a
20 particular effect.
21
22
23 @cindex Internals Reference
24
25 The controls available for tuning are described in a separate
26 document, the
27 @iftex
28 Internals Reference manual.
29 @end iftex
30 @ifnottex
31 @ref{Top,Internals Reference,,lilypond-internals}.
32 @end ifnottex
33 That manual
34 lists all different variables, functions and options available in
35 LilyPond.  It is written as a HTML document, which is available
36 @c leave the @uref as one long line.
37 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
38 but is also included with the LilyPond documentation package.
39
40 There are four areas where the default settings may be changed:
41
42 @itemize
43 @item
44 Automatic notation: changing the automatic creation of notation
45 elements.  For example, changing the beaming rules.
46
47 @item
48 Output: changing the appearance of individual
49 objects.  For example, changing stem directions or the location of
50 subscripts.
51
52 @item
53 Context: changing aspects of the translation from music events to
54 notation.  For example, giving each staff a separate time signature.
55
56 @item
57 Page layout: changing the appearance of the spacing, line
58 breaks, and page dimensions.  These modifications are discussed
59 in @ref{Non-musical notation}, and @ref{Spacing issues}.
60 @end itemize
61
62 Internally, LilyPond uses Scheme (a LISP dialect) to provide
63 infrastructure.  Overriding layout decisions in effect accesses the
64 program internals, which requires Scheme input.  Scheme elements are
65 introduced in a @code{.ly} file with the hash mark
66 @code{#}.@footnote{@rlearning{Scheme tutorial}, contains a short tutorial
67 on entering numbers, lists, strings, and symbols in Scheme.}
68
69
70 @menu
71 * Interpretation contexts::     
72 * The \override command::       
73 @end menu
74
75
76 @node Interpretation contexts
77 @section Interpretation contexts
78
79 This section describes what contexts are, and how to modify them.
80
81 @menu
82 * Contexts explained::          
83 * Creating contexts::           
84 * Changing context properties on the fly::  
85 * Modifying context plug-ins::  
86 * Layout tunings within contexts::  
87 * Changing context default settings::  
88 * Defining new contexts::       
89 * Aligning contexts::           
90 * Vertical grouping of grobs::  
91 @end menu
92
93
94 @node Contexts explained
95 @subsection Contexts explained
96
97 When music is printed, a lot of notational elements must be added to the
98 output.  For example, compare the input and output of the following example:
99
100 @lilypond[quote,verbatim,relative=2,fragment]
101 cis4 cis2. g4
102 @end lilypond
103
104 The input is rather sparse, but in the output, bar lines, accidentals,
105 clef, and time signature are added.  LilyPond @emph{interprets} the
106 input.  During this step, the musical information is inspected in time
107 order, similar to reading a score from left to right.  While reading
108 the input, the program remembers where measure boundaries are, and which
109 pitches require explicit accidentals.  This information can be presented on
110 several levels.  For example, the effect of an accidental is limited
111 to a single staff, while a bar line must be synchronized across the
112 entire score.
113
114 Within LilyPond, these rules and bits of information are grouped in
115 @emph{Contexts}.  Some examples of contexts are @code{Voice},
116 @code{Staff}, and @code{Score}.  They are hierarchical, for
117 example: a @code{Staff} can contain many @code{Voice}s, and a
118 @code{Score} can contain many @code{Staff} contexts.
119
120 @quotation
121 @image{context-example,5cm,,}
122 @end quotation
123
124 Each context has the responsibility for enforcing some notation rules,
125 creating some notation objects and maintaining the associated
126 properties.  For example, the @code{Voice} context may introduce an
127 accidental and then the @code{Staff} context maintains the rule to
128 show or suppress the accidental for the remainder of the measure.  The
129 synchronization of bar lines is handled at @code{Score} context.
130
131 However, in some music we may not want the bar lines to be
132 synchronized -- consider a polymetric score in 4/4 and 3/4 time.  In
133 such cases, we must modify the default settings of the @code{Score}
134 and @code{Staff} contexts.
135
136 For very simple scores, contexts are created implicitly, and you need
137 not be aware of them.  For larger pieces, such as anything with more
138 than one staff, they must be
139 created explicitly to make sure that you get as many staves as you
140 need, and that they are in the correct order.  For typesetting pieces
141 with specialized notation, it can be useful to modify existing or
142 to define new contexts.
143
144
145 A complete description of all available contexts is in the program
146 reference, see
147 @ifhtml
148 @internalsref{Contexts}.
149 @end ifhtml
150 @ifnothtml
151 Translation @expansion{} Context.
152 @end ifnothtml
153
154 @c [TODO: describe propagation]
155
156
157 @node Creating contexts
158 @subsection Creating contexts
159
160 For scores with only one voice and one staff, contexts are
161 created automatically.  For more complex scores, it is necessary to
162 create them by hand.  There are three commands that do this.
163
164 @itemize
165
166 @item
167 The easiest command is @code{\new}, and it also the quickest to type.
168 It is prepended to a music expression, for example
169
170 @funindex \new
171 @cindex new contexts
172 @cindex Context, creating
173
174 @example
175 \new @var{type} @var{music expression}
176 @end example
177
178 @noindent
179 where @var{type} is a context name (like @code{Staff} or
180 @code{Voice}).  This command creates a new context, and starts
181 interpreting the @var{music expression} with that.
182
183 A practical application of @code{\new} is a score with many
184 staves.  Each part that should be on its own staff, is preceded with
185 @code{\new Staff}.
186
187 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
188 <<
189   \new Staff { c4 c }
190   \new Staff { d4 d }
191 >>
192 @end lilypond
193
194 The @code{\new} command may also give a name to the context,
195
196 @example
197 \new @var{type} = @var{id} @var{music}
198 @end example
199 However, this user specified name is only used if there is no other
200 context already earlier with the same name.
201
202
203 @funindex \context
204
205 @item
206 Like @code{\new}, the @code{\context} command also directs a music
207 expression to a context object, but gives the context an explicit name.  The
208 syntax is
209
210 @example
211 \context @var{type} = @var{id} @var{music}
212 @end example
213
214 This form will search for an existing context of type @var{type}
215 called @var{id}.  If that context does not exist yet, a new
216 context with the specified name is created.  This is useful if
217 the context is referred to later on.  For example, when
218 setting lyrics the melody is in a named context
219
220 @example
221 \context Voice = "@b{tenor}" @var{music}
222 @end example
223
224 @noindent
225 so the texts can be properly aligned to its notes,
226
227 @example
228 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
229 @end example
230
231 @noindent
232
233 Another possible use of named contexts is funneling two different
234 music expressions into one context.  In the following example,
235 articulations and notes are entered separately,
236
237 @example
238 music = @{ c4 c4 @}
239 arts = @{ s4-. s4-> @}
240 @end example
241
242 They are combined by sending both to the same @code{Voice} context,
243
244 @example
245 <<
246   \new Staff \context Voice = "A" \music
247   \context Voice = "A" \arts
248 >>
249 @end example
250 @lilypond[quote,ragged-right]
251 music = { c4 c4 }
252 arts = { s4-. s4-> }
253 \relative c'' <<
254   \new Staff \context Voice = "A" \music
255   \context Voice = "A" \arts
256 >>
257 @end lilypond
258
259 With this mechanism, it is possible to define an Urtext (original
260 edition), with the option to put several distinct articulations on the
261 same notes.
262
263 @cindex creating contexts
264
265 @item
266 The third command for creating contexts is
267 @example
268 \context @var{type} @var{music}
269 @end example
270
271
272 @noindent
273 This is similar to @code{\context} with @code{= @var{id}}, but matches
274 any context of type @var{type}, regardless of its given name.
275
276 This variant is used with music expressions that can be interpreted at
277 several levels.  For example, the @code{\applyOutput} command (see
278 @ref{Running a function on all layout objects}).  Without an explicit
279 @code{\context}, it is usually applied to @code{Voice}
280
281 @example
282 \applyOutput #'@var{context} #@var{function}   % apply to Voice
283 @end example
284
285 To have it interpreted at the @code{Score} or @code{Staff} level use
286 these forms
287
288 @example
289 \applyOutput #'Score #@var{function}
290 \applyOutput #'Staff #@var{function}
291 @end example
292
293 @end itemize
294
295
296 @node Changing context properties on the fly
297 @subsection Changing context properties on the fly
298
299 @cindex properties
300 @funindex \set
301 @cindex changing properties
302
303 Each context can have different @emph{properties}, variables contained
304 in that context.  They can be changed during the interpretation step.
305 This is achieved by inserting the @code{\set} command in the music,
306
307 @example
308 \set @var{context}.@var{prop} = #@var{value}
309 @end example
310
311 For example,
312 @lilypond[quote,verbatim,relative=2,fragment]
313 R1*2
314 \set Score.skipBars = ##t
315 R1*2
316 @end lilypond
317
318 This command skips measures that have no notes.  The result is that
319 multi-rests are condensed.  The value assigned is a Scheme object.  In
320 this case, it is @code{#t}, the boolean True value.
321
322 If the @var{context} argument is left out, then the current bottom-most
323 context (typically @code{ChordNames}, @code{Voice}, or
324 @code{Lyrics}) is used.  In this example,
325
326 @lilypond[quote,verbatim,relative=2,fragment]
327 c8 c c c
328 \set autoBeaming = ##f
329 c8 c c c
330 @end lilypond
331
332 @noindent
333 the @var{context} argument to @code{\set} is left out, so automatic
334 beaming is switched off in the current @internalsref{Voice}.  Note that
335 the bottom-most context does not always contain the property that you
336 wish to change -- for example, attempting to set the @code{skipBars}
337 property (of the bottom-most context, in this case @code{Voice}) will
338 have no effect.
339
340 @lilypond[quote,verbatim,relative=2,fragment]
341 R1*2
342 \set skipBars = ##t
343 R1*2
344 @end lilypond
345
346 Contexts are hierarchical, so if a bigger context was specified, for
347 example @code{Staff}, then the change would also apply to all
348 @code{Voice}s in the current stave.  The change is applied
349 @q{on-the-fly}, during the music, so that the setting only affects the
350 second group of eighth notes.
351
352 @funindex \unset
353
354 There is also an @code{\unset} command,
355 @example
356 \unset @var{context}.@var{prop}
357 @end example
358
359 @noindent
360 which removes the definition of @var{prop}.  This command removes
361 the definition only if it is set in @var{context}, so
362
363 @example
364 \set Staff.autoBeaming = ##f
365 @end example
366
367 @noindent
368 introduces a property setting at @code{Staff} level.  The setting also
369 applies to the current @code{Voice}.  However,
370
371 @example
372 \unset Voice.autoBeaming
373 @end example
374
375 @noindent
376 does not have any effect.  To cancel this setting, the @code{\unset}
377 must be specified on the same level as the original @code{\set}.  In
378 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
379 requires
380 @example
381 \unset Staff.autoBeaming
382 @end example
383
384 Like @code{\set}, the @var{context} argument does not have to be
385 specified for a bottom context, so the two statements
386
387 @example
388 \set Voice.autoBeaming = ##t
389 \set autoBeaming = ##t
390 @end example
391
392 @noindent
393 are equivalent.
394
395
396 @cindex \once
397 Settings that should only apply to a single time-step can be entered
398 with @code{\once}, for example in
399
400 @lilypond[quote,verbatim,relative=2,fragment]
401 c4
402 \once \set fontSize = #4.7
403 c4
404 c4
405 @end lilypond
406
407 the property @code{fontSize} is unset automatically after the second
408 note.
409
410 A full description of all available context properties is in the
411 program reference, see
412 @ifhtml
413 @internalsref{Tunable context properties}.
414 @end ifhtml
415 @ifnothtml
416 Translation @expansion{} Tunable context properties.
417 @end ifnothtml
418
419
420 @node Modifying context plug-ins
421 @subsection Modifying context plug-ins
422
423 Notation contexts (like @code{Score} and @code{Staff}) not only
424 store properties,
425 they also contain plug-ins called @q{engravers} that create notation
426 elements.  For example, the @code{Voice} context contains a
427 @code{Note_head_engraver} and the @code{Staff} context contains a
428 @code{Key_signature_engraver}.
429
430 For a full a description of each plug-in, see
431 @ifhtml
432 @internalsref{Engravers}.
433 @end ifhtml
434 @ifnothtml
435 Internals Reference @expansion{} Translation @expansion{} Engravers.
436 @end ifnothtml
437 Every context described in
438 @ifhtml
439 @internalsref{Contexts}
440 @end ifhtml
441 @ifnothtml
442 Internals Reference @expansion{} Translation @expansion{} Context.
443 @end ifnothtml
444 lists the engravers used for that context.
445
446
447 It can be useful to shuffle around these plug-ins.  This is done by
448 starting a new context with @code{\new} or @code{\context}, and
449 modifying it,
450
451 @funindex \with
452
453 @example
454 \new @var{context} \with @{
455   \consists @dots{}
456   \consists @dots{}
457   \remove @dots{}
458   \remove @dots{}
459   @emph{etc.}
460 @}
461 @{
462   @emph{..music..}
463 @}
464 @end example
465
466 @noindent
467 where the @dots{} should be the name of an engraver.  Here is a simple
468 example which removes @code{Time_signature_engraver} and
469 @code{Clef_engraver} from a @code{Staff} context,
470
471 @lilypond[quote,relative=1,verbatim,fragment]
472 <<
473   \new Staff {
474     f2 g
475   }
476   \new Staff \with {
477      \remove "Time_signature_engraver"
478      \remove "Clef_engraver"
479   } {
480     f2 g2
481   }
482 >>
483 @end lilypond
484
485 In the second staff there are no time signature or clef symbols.  This
486 is a rather crude method of making objects disappear since it will affect
487 the entire staff.  This method also influences the spacing, which may or
488 may not be desirable.  A more
489 sophisticated method of blanking objects is shown in @rlearning{Common tweaks}.
490
491 The next example shows a practical application.  Bar lines and time
492 signatures are normally synchronized across the score.  This is done
493 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
494 This plug-in keeps an administration of time signature, location
495 within the measure, etc.  By moving thes engraver from @code{Score} to
496 @code{Staff} context, we can have a score where each staff has its own
497 time signature.
498
499 @cindex polymetric scores
500 @cindex Time signatures, multiple
501
502 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
503 \new Score \with {
504   \remove "Timing_translator"
505   \remove "Default_bar_line_engraver"
506 } <<
507   \new Staff \with {
508     \consists "Timing_translator"
509     \consists "Default_bar_line_engraver"
510   } {
511       \time 3/4
512       c4 c c c c c
513   }
514   \new Staff \with {
515     \consists "Timing_translator"
516     \consists "Default_bar_line_engraver"
517   } {
518        \time 2/4
519        c4 c c c c c
520   }
521 >>
522 @end lilypond
523
524
525 @node Layout tunings within contexts
526 @subsection Layout tunings within contexts
527
528 Each context is responsible for creating certain types of graphical
529 objects.  The settings used for printing these objects are also stored by
530 context.  By changing these settings, the appearance of objects can be
531 altered.
532
533 The syntax for this is
534
535 @example
536 \override @var{context}.@var{name} #'@var{property} = #@var{value}
537 @end example
538
539 Here @var{name} is the name of a graphical object, like @code{Stem} or
540 @code{NoteHead}, and @var{property} is an internal variable of the
541 formatting system (@q{grob property} or @q{layout property}).  The latter is a
542 symbol, so it must be quoted.  The subsection @ref{Constructing a
543 tweak}, explains what to fill in for @var{name}, @var{property}, and
544 @var{value}.  Here we only discuss the functionality of this command.
545
546 The command
547
548 @verbatim
549 \override Staff.Stem #'thickness = #4.0
550 @end verbatim
551
552 @noindent
553 makes stems thicker (the default is 1.3, with staff line thickness as a
554 unit).  Since the command specifies @code{Staff} as context, it only
555 applies to the current staff.  Other staves will keep their normal
556 appearance.  Here we see the command in action:
557
558 @lilypond[quote,verbatim,relative=2,fragment]
559 c4
560 \override Staff.Stem #'thickness = #4.0
561 c4
562 c4
563 c4
564 @end lilypond
565
566 The @code{\override} command changes the definition of the @code{Stem}
567 within the current @code{Staff}.  After the command is interpreted
568 all stems are thickened.
569
570 Analogous to @code{\set}, the @var{context} argument may be left out,
571 causing the default context @code{Voice} to be used.  Adding
572 @code{\once} applies the change during one timestep only.
573
574 @lilypond[quote,fragment,verbatim,relative=2]
575 c4
576 \once \override Stem #'thickness = #4.0
577 c4
578 c4
579 @end lilypond
580
581 The @code{\override} must be done before the object is
582 started.  Therefore, when altering @emph{Spanner} objects such as slurs
583 or beams, the @code{\override} command must be executed at the moment
584 when the object is created.  In this example,
585
586 @lilypond[quote,fragment,verbatim,relative=2]
587 \override Slur #'thickness = #3.0
588 c8[( c
589 \override Beam #'thickness = #0.6
590 c8 c])
591 @end lilypond
592
593 @noindent
594 the slur is fatter but the beam is not.  This is because the command for
595 @code{Beam} comes after the Beam is started, so it has no effect.
596
597 Analogous to @code{\unset}, the @code{\revert} command for a context
598 undoes an @code{\override} command; like with @code{\unset}, it only
599 affects settings that were made in the same context.  In other words, the
600 @code{\revert} in the next example does not do anything.
601
602 @example
603 \override Voice.Stem #'thickness = #4.0
604 \revert Staff.Stem #'thickness
605 @end example
606
607 Some tweakable options are called @q{subproperties} and reside inside
608 properties.  To tweak those, use commands of the form
609
610 @c leave this as a long long
611 @example
612 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
613 @end example
614
615 @noindent
616 such as
617
618 @example
619 \override Stem #'details #'beamed-lengths = #'(4 4 3)
620 @end example
621
622
623 @seealso
624
625 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
626 @internalsref{PropertySet}, @internalsref{Backend}, and
627 @internalsref{All layout objects}.
628
629
630 @refbugs
631
632 The back-end is not very strict in type-checking object properties.
633 Cyclic references in Scheme values for properties can cause hangs
634 or crashes, or both.
635
636
637 @node Changing context default settings
638 @subsection Changing context default settings
639
640 The adjustments of the previous subsections (@ref{Changing context
641 properties on the fly}, @ref{Modifying context plug-ins}, and
642 @ref{Layout tunings within contexts}) can also be entered separately
643 from the music in the @code{\layout} block,
644
645 @example
646 \layout @{
647   @dots{}
648   \context @{
649     \Staff
650
651     \set fontSize = #-2
652     \override Stem #'thickness = #4.0
653     \remove "Time_signature_engraver"
654   @}
655 @}
656 @end example
657
658 The @code{\Staff} command brings in the existing definition of the
659 staff context so that it can be modified.
660
661 The statements
662 @example
663 \set fontSize = #-2
664 \override Stem #'thickness = #4.0
665 \remove "Time_signature_engraver"
666 @end example
667
668 @noindent
669 affect all staves in the score.  Other contexts can be modified
670 analogously.
671
672 The @code{\set} keyword is optional within the @code{\layout} block, so
673
674 @example
675 \context @{
676   @dots{}
677   fontSize = #-2
678 @}
679 @end example
680
681 @noindent
682 will also work.
683
684
685
686 @refbugs
687
688 It is not possible to collect context changes in a variable and apply
689 them to a @code{\context} definition by referring to that variable.
690
691 The @code{\RemoveEmptyStaffContext} will overwrite your current
692 @code{\Staff} settings.  If you wish to change the defaults for a
693 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
694 after calling @code{\RemoveEmptyStaffContext}, ie
695
696 @example
697 \layout @{
698   \context @{
699     \RemoveEmptyStaffContext
700
701     \override Stem #'thickness = #4.0
702   @}
703 @}
704 @end example
705
706
707 @node Defining new contexts
708 @subsection Defining new contexts
709
710 Specific contexts, like @code{Staff} and @code{Voice}, are made of
711 simple building blocks.  It is possible to create new types of
712 contexts with different combinations of engraver plug-ins.
713
714 The next example shows how to build a different type of
715 @code{Voice} context from scratch.  It will be similar to
716 @code{Voice}, but only prints centered slash note heads.  It can be used
717 to indicate improvisation in jazz pieces,
718
719 @lilypond[quote,ragged-right]
720 \layout { \context {
721   \name ImproVoice
722   \type "Engraver_group"
723   \consists "Note_heads_engraver"
724   \consists "Text_engraver"
725   \consists Pitch_squash_engraver
726   squashedPosition = #0
727   \override NoteHead #'style = #'slash
728   \override Stem #'transparent = ##t
729   \alias Voice
730 }
731 \context { \Staff
732   \accepts "ImproVoice"
733 }}
734
735 \relative c'' {
736   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
737    c4 c^"undress" c_"while playing :)" c }
738   a1
739 }
740 @end lilypond
741
742
743 These settings are defined within a @code{\context} block inside a
744 @code{\layout} block,
745
746 @example
747 \layout @{
748   \context @{
749     @dots{}
750   @}
751 @}
752 @end example
753
754 In the following discussion, the example input shown should go in place
755 of the @dots{} in the previous fragment.
756
757 First it is necessary to define a name for the new context:
758
759 @example
760 \name ImproVoice
761 @end example
762
763 Since it is similar to the @code{Voice}, we want commands that work
764 on (existing) @code{Voice}s to remain working.  This is achieved by
765 giving the new context an alias @code{Voice},
766
767 @example
768 \alias Voice
769 @end example
770
771 The context will print notes and instructive texts, so we need to add
772 the engravers which provide this functionality,
773
774 @example
775 \consists Note_heads_engraver
776 \consists Text_engraver
777 @end example
778
779 but we only need this on the center line,
780
781 @example
782 \consists Pitch_squash_engraver
783 squashedPosition = #0
784 @end example
785
786 The @internalsref{Pitch_squash_engraver} modifies note heads (created
787 by @internalsref{Note_heads_engraver}) and sets their vertical
788 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
789 the center line.
790
791 The notes look like a slash, and have no stem,
792
793 @example
794 \override NoteHead #'style = #'slash
795 \override Stem #'transparent = ##t
796 @end example
797
798 All these plug-ins have to cooperate, and this is achieved with a
799 special plug-in, which must be marked with the keyword @code{\type}.
800 This should always be @internalsref{Engraver_group},
801
802 @example
803 \type "Engraver_group"
804 @end example
805
806 Put together, we get
807
808 @example
809 \context @{
810   \name ImproVoice
811   \type "Engraver_group"
812   \consists "Note_heads_engraver"
813   \consists "Text_engraver"
814   \consists Pitch_squash_engraver
815   squashedPosition = #0
816   \override NoteHead #'style = #'slash
817   \override Stem #'transparent = ##t
818   \alias Voice
819 @}
820 @end example
821
822 @funindex \accepts
823 Contexts form hierarchies.  We want to hang the @code{ImproVoice}
824 under @code{Staff}, just like normal @code{Voice}s.  Therefore, we
825 modify the @code{Staff} definition with the @code{\accepts}
826 command,
827
828 @example
829 \context @{
830   \Staff
831   \accepts ImproVoice
832 @}
833 @end example
834
835 @funindex \denies
836 The opposite of @code{\accepts} is @code{\denies},
837 which is sometimes needed when reusing existing context definitions.
838
839 Putting both into a @code{\layout} block, like
840
841 @example
842 \layout @{
843   \context @{
844     \name ImproVoice
845     @dots{}
846   @}
847   \context @{
848     \Staff
849     \accepts "ImproVoice"
850   @}
851 @}
852 @end example
853
854 Then the output at the start of this subsection can be entered as
855
856 @example
857 \relative c'' @{
858   a4 d8 bes8
859   \new ImproVoice @{
860     c4^"ad lib" c
861     c4 c^"undress"
862     c c_"while playing :)"
863   @}
864   a1
865 @}
866 @end example
867
868
869 @node Aligning contexts
870 @subsection Aligning contexts
871
872 New contexts may be aligned above or below exisiting contexts.  This
873 could be useful in setting up a vocal staff (@rlearning{Vocal ensembles}) and
874 in ossia,
875
876 FIXME: this section doens't work in pdf.  (?)
877
878 @cindex ossia
879 @findex alignAboveContext
880 @findex alignBelowContext
881
882 @lilypond[quote,ragged-right]
883 ossia = { f4 f f f }
884 \score{
885   \relative c' \new Staff = "main" {
886     c4 c c c
887     <<
888       \new Staff \with {alignAboveContext=main} \ossia
889       { d8 f d f d f d f }
890     >>
891   }
892 }
893 @end lilypond
894
895
896 @node Vertical grouping of grobs
897 @subsection Vertical grouping of grobs
898
899 The VerticalAlignment and VerticalAxisGroup grobs work together.
900 VerticalAxisGroup groups together different grobs like Staff, Lyrics,
901 etc.  VerticalAlignment then vertically aligns the different grobs
902 grouped together by VerticalAxisGroup.  There is usually only one
903 VerticalAlignment per score but every Staff, Lyrics, etc. has its own
904 VerticalAxisGroup. 
905
906
907 @node The \override command
908 @section The @code{\override} command
909
910 In the previous section, we have already touched on a command that
911 changes layout details: the @code{\override} command.  In this section,
912 we will look in more detail at how to use the command in practice.  The
913 general syntax of this command is:
914
915 @example
916 \override @var{context}.@var{layout_object} #'@var{layout_property} = #@var{value}
917 @end example
918
919 This will set the @var{layout_property} of the specified @var{layout_object},
920 which is a member of the @var{context}, to the @var{value}.
921
922 @menu
923 * Constructing a tweak::        
924 * Navigating the program reference::  
925 * Layout interfaces::           
926 * Determining the grob property::  
927 * Objects connected to the input::  
928 * Using Scheme code instead of \tweak::  
929 * \set versus \override::       
930 * Difficult tweaks::            
931 @end menu
932
933
934
935 @node Constructing a tweak
936 @subsection Constructing a tweak
937
938 Commands which change output generally look like
939
940 @example
941 \override Voice.Stem #'thickness = #3.0
942 @end example
943
944 @noindent
945 To construct this tweak we must determine these bits of information:
946
947 @itemize
948 @item the context: here @code{Voice}.
949 @item the layout object: here @code{Stem}.
950 @item the layout property: here @code{thickness}.
951 @item a sensible value: here @code{3.0}.
952 @end itemize
953
954 Some tweakable options are called @q{subproperties} and reside inside
955 properties.  To tweak those, use commands in the form
956
957 @example
958 \override Stem #'details #'beamed-lengths = #'(4 4 3)
959 @end example
960
961 @cindex internal documentation
962 @cindex finding graphical objects
963 @cindex graphical object descriptions
964 @cindex tweaking
965 @funindex \override
966 @cindex internal documentation
967
968 For many properties, regardless of the data type of the property, setting the
969 property to false ( @code{##f} ) will result in turning it off, causing
970 Lilypond to ignore that property entirely.  This is particularly useful for
971 turning off grob properties which may otherwise be causing problems.
972
973 We demonstrate how to glean this information from the notation manual
974 and the program reference.
975
976
977
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:
993
994 @quotation
995 @seealso
996
997 Internals Reference: @internalsref{Fingering}.
998
999 @end quotation
1000
1001
1002 @c  outdated info; probably will delete.
1003 @ignore
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 @end ignore
1026
1027 @ignore
1028 @c  I can't figure out what this is supposed to mean.  -gp
1029
1030 The @code{Fingering_engraver} is also listed to create
1031 @internalsref{Fingering} objects,
1032
1033 @c  old info?  it doesn't make any sense to me with our current docs.
1034 This is also the
1035 second bit of information listed under @b{See also} in the Notation
1036 manual.
1037 @end ignore
1038
1039 @ifnothtml
1040 The programmer's reference is available as an HTML document.  It is
1041 highly recommended that you read it in HTML form, either online or
1042 by downloading the HTML documentation.  This section will be much more
1043 difficult to understand if you are using the 
1044 PDF manual.
1045 @end ifnothtml
1046
1047 Follow the link to @internalsref{Fingering}.  At the top of the
1048 page, you will see
1049
1050 @quotation
1051 Fingering objects are created by: @internalsref{Fingering_engraver} and
1052 @internalsref{New_fingering_engraver}.
1053 @end quotation
1054
1055 By following related links inside the program reference, we can follow the
1056 flow of information within the program:
1057
1058 @itemize
1059
1060 @item @internalsref{Fingering}:
1061 @internalsref{Fingering} objects are created by:
1062 @internalsref{Fingering_engraver}
1063
1064 @item @internalsref{Fingering_engraver}:
1065 Music types accepted: @internalsref{fingering-event}
1066
1067 @item @internalsref{fingering-event}:
1068 Music event type @code{fingering-event} is in Music expressions named
1069 @internalsref{FingerEvent}
1070 @end itemize
1071
1072 This path goes against the flow of information in the program: it
1073 starts from the output, and ends at the input event.  You could
1074 also start at an input event, and read with the flow of
1075 information, eventually ending up at the output object(s).
1076
1077 The program reference can also be browsed like a normal document.  It
1078 contains chapters 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.5}
1111 @end quotation
1112
1113 @noindent
1114 which means that the number will be kept at a distance of at least 0.5
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
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 note head.
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 superscript
1141 and subscript 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 (@q{Internal properties}), but others
1159 can be modified.
1160
1161 We have been talking of @emph{the} @code{Fingering} object, but actually it
1162 does not amount to much.  The initialization file (see
1163 @rlearning{Default files})
1164 @file{scm/@/define@/-grobs@/.scm} shows the soul of the @q{object},
1165
1166 @example
1167 (Fingering
1168   . ((padding . 0.5)
1169      (avoid-slur . around)
1170      (slur-padding . 0.2)
1171      (staff-padding . 0.5)
1172      (self-alignment-X . 0)
1173      (self-alignment-Y . 0)
1174      (script-priority . 100)
1175      (stencil . ,ly:text-interface::print)
1176      (direction . ,ly:script-interface::calc-direction)
1177      (font-encoding . fetaNumber)
1178      (font-size . -5)           ; don't overlap when next to heads.
1179      (meta . ((class . Item)
1180      (interfaces . (finger-interface
1181                     font-interface
1182                     text-script-interface
1183                     text-interface
1184                     side-position-interface
1185                     self-alignment-interface
1186                     item-interface))))))
1187 @end example
1188
1189 @noindent
1190 As you can see, the @code{Fingering} object is nothing more than a
1191 bunch of variable settings, and the webpage in the Internals Reference
1192 is directly generated from this definition.
1193
1194
1195 @node Determining the grob property
1196 @subsection Determining the grob property
1197
1198 Recall that we wanted to change the position of the @b{2} in
1199
1200 @lilypond[quote,fragment,relative=2,verbatim]
1201 c-2
1202 \stemUp
1203 f
1204 @end lilypond
1205
1206 Since the @b{2} is vertically positioned next to its note, we have to
1207 meddle with the interface associated with this positioning.  This is
1208 done using @code{side-position-interface}.  The page for this interface
1209 says
1210
1211 @quotation
1212 @code{side-position-interface}
1213
1214 Position a victim object (this one) next to other objects (the
1215 support).  The property @code{direction} signifies where to put the
1216 victim object relative to the support (left or right, up or down?)
1217 @end quotation
1218
1219 @cindex padding
1220 @noindent
1221 Below this description, the variable @code{padding} is described as
1222
1223 @quotation
1224 @table @code
1225 @item padding
1226 (dimension, in staff space)
1227
1228 Add this much extra space between objects that are next to each other.
1229 @end table
1230 @end quotation
1231
1232 By increasing the value of @code{padding}, we can move the
1233 fingering away from the note head.  The following command inserts
1234 3 staff spaces of white
1235 between the note and the fingering:
1236 @example
1237 \once \override Voice.Fingering #'padding = #3
1238 @end example
1239
1240 Inserting this command before the Fingering object is created,
1241 i.e., before @code{c2}, yields the following result:
1242
1243 @lilypond[quote,relative=2,fragment,verbatim]
1244 \once \override Voice.Fingering #'padding = #3
1245 c-2
1246 \stemUp
1247 f
1248 @end lilypond
1249
1250
1251 In this case, the context for this tweak is @code{Voice}.  This
1252 fact can also be deduced from the program reference, for the page for
1253 the @internalsref{Fingering_engraver} plug-in says
1254
1255 @quotation
1256 Fingering_engraver is part of contexts: @dots{} @internalsref{Voice}
1257 @end quotation
1258
1259
1260 @node Objects connected to the input
1261 @subsection Objects connected to the input
1262
1263 @funindex \tweak
1264
1265 In some cases, it is possible to take a short-cut for tuning graphical
1266 objects.  For objects that result directly from a piece of the input,
1267 you can use the @code{\tweak} function, for example
1268
1269 @lilypond[relative=2,fragment,verbatim,ragged-right]
1270 <
1271   c
1272   \tweak #'color #red d
1273   g
1274   \tweak #'duration-log #1  a
1275 >4-\tweak #'padding #10 -.
1276 @end lilypond
1277
1278 As you can see, properties are set in the objects directly,
1279 without mentioning the grob name or context where this should be
1280 applied.
1281
1282 This technique only works for objects that are directly connected to
1283 an @internalsref{Event} from the input, for example
1284
1285 @itemize
1286 @item note heads, caused by chord-pitch (i.e., notes inside a chord)
1287 @item articulation signs, caused by articulation instructions
1288 @end itemize
1289
1290 It notably does not work for stems and accidentals (these are caused
1291 by note heads, not by music events) or clefs (these are not caused by
1292 music inputs, but rather by the change of a property value).
1293
1294 There are very few objects which are @emph{directly} connected to
1295 output.  A normal note (like @code{c4}) is not directly connected
1296 to output, so
1297
1298 @example
1299 \tweak #'color #red c4
1300 @end example
1301
1302 @noindent
1303 does not change color.  See @ref{Displaying music expressions}, for
1304 details.
1305
1306
1307 @node Using Scheme code instead of \tweak
1308 @subsection Using Scheme code instead of @code{\tweak}
1309
1310 The main disadvantage of @code{\tweak} is its syntactical
1311 inflexibility.  For example, the following produces a syntax error.
1312
1313 @example
1314 F = \tweak #'font-size #-3 -\flageolet
1315
1316 \relative c'' @{
1317   c4^\F c4_\F
1318 @}
1319 @end example
1320
1321 @noindent
1322 With other words, @code{\tweak} doesn't behave like an articulation
1323 regarding the syntax; in particular, it can't be attached with
1324 @code{^} and @code{_}.
1325
1326 Using Scheme, this problem can be circumvented.  The route to the
1327 result is given in @ref{Adding articulation to notes (example)},
1328 especially how to use @code{\displayMusic} as a helping guide.
1329
1330 @example
1331 F = #(let ((m (make-music 'ArticulationEvent
1332                           'articulation-type "flageolet")))
1333        (set! (ly:music-property m 'tweaks)
1334              (acons 'font-size -3
1335                     (ly:music-property m 'tweaks)))
1336        m)
1337  
1338 \relative c'' @{
1339   c4^\F c4_\F
1340 @}
1341 @end example
1342
1343 @noindent
1344 Here, the @code{tweaks} properties of the flageolet object
1345 @code{m} (created with @code{make-music}) are extracted with
1346 @code{ly:music-property}, a new key-value pair to change the
1347 font size is prepended to the property list with the
1348 @code{acons} Scheme function, and the result is finally
1349 written back with @code{set!}.  The last element of the
1350 @code{let} block is the return value, @code{m} itself.
1351
1352
1353 @node \set versus \override
1354 @subsection @code{\set} vs. @code{\override}
1355
1356 We have seen two methods of changing properties: @code{\set} and
1357 @code{\override}.  There are actually two different kinds of
1358 properties.
1359
1360 Contexts can have properties, which are usually named in
1361 @code{studlyCaps}.  They mostly control the translation from
1362 music to notatino, eg. @code{localKeySignature} (for determining
1363 whether to print accidentals), @code{measurePosition} (for
1364 determining when to print a bar line).  Context properties can
1365 change value over time while interpreting a piece of music;
1366 @code{measurePosition} is an obvious example of
1367 this.  Context properties are modified with @code{\set}.
1368
1369 There is a special type of context property: the element
1370 description.  These properties are named in @code{StudlyCaps}
1371 (starting with capital letters).  They contain the
1372 @q{default settings} for said graphical object as an
1373 association list.  See @file{scm/@/define@/-grobs@/.scm}
1374 to see what kind of settings there are.  Element descriptions
1375 may be modified with @code{\override}.
1376
1377 @code{\override} is actually a shorthand;
1378
1379 @example
1380 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1381 @end example
1382
1383 @noindent
1384 is more or less equivalent to
1385
1386 @c  leave this long line -gp
1387 @example
1388 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1389 @end example
1390
1391 The value of @code{context} (the alist) is used to initalize
1392 the properties of individual grobs.  Grobs also have
1393 properties, named in Scheme style, with
1394 @code{dashed-words}.  The values of grob properties change
1395 during the formatting process: formatting basically amounts
1396 to computing properties using callback functions.
1397
1398 @code{fontSize} is a special property: it is equivalent to
1399 entering @code{\override ... #'font-size} for all pertinent
1400 objects.  Since this is a common change, the special
1401 property (modified with @code{\set}) was created.
1402
1403
1404 @node Difficult tweaks
1405 @subsection Difficult tweaks
1406
1407 There are a few classes of difficult adjustments.
1408
1409 @itemize
1410
1411
1412 @item
1413 One type of difficult adjustment is the appearance of spanner objects,
1414 such as slur and tie.  Initially, only one of these objects is created,
1415 and they can be adjusted with the normal mechanism.  However, in some
1416 cases the spanners cross line breaks.  If this happens, these objects
1417 are cloned.  A separate object is created for every system that it is
1418 in.  These are clones of the original object and inherit all
1419 properties, including @code{\override}s.
1420
1421
1422 In other words, an @code{\override} always affects all pieces of a
1423 broken spanner.  To change only one part of a spanner at a line break,
1424 it is necessary to hook into the formatting process.  The
1425 @code{after-line-breaking} callback contains the Scheme procedure that
1426 is called after the line breaks have been determined, and layout
1427 objects have been split over different systems.
1428
1429 In the following example, we define a procedure
1430 @code{my-callback}.  This procedure
1431
1432 @itemize
1433 @item
1434 determines if we have been split across line breaks
1435 @item
1436 if yes, retrieves all the split objects
1437 @item
1438 checks if we are the last of the split objects
1439 @item
1440 if yes, it sets @code{extra-offset}.
1441 @end itemize
1442
1443 This procedure is installed into @internalsref{Tie}, so the last part
1444 of the broken tie is translated up.
1445
1446 @lilypond[quote,verbatim,ragged-right]
1447 #(define (my-callback grob)
1448   (let* (
1449          ; have we been split?
1450          (orig (ly:grob-original grob))
1451
1452          ; if yes, get the split pieces (our siblings)
1453          (siblings (if (ly:grob? orig)
1454                      (ly:spanner-broken-into orig) '() )))
1455
1456    (if (and (>= (length siblings) 2)
1457              (eq? (car (last-pair siblings)) grob))
1458      (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1459
1460 \relative c'' {
1461   \override Tie #'after-line-breaking =
1462   #my-callback
1463   c1 ~ \break c2 ~ c
1464 }
1465 @end lilypond
1466
1467 @noindent
1468 When applying this trick, the new @code{after-line-breaking} callback
1469 should also call the old one @code{after-line-breaking}, if there is
1470 one.  For example, if using this with @code{Hairpin},
1471 @code{ly:hairpin::after-line-breaking} should also be called.
1472
1473
1474 @item Some objects cannot be changed with @code{\override} for
1475 technical reasons.  Examples of those are @code{NonMusicalPaperColumn}
1476 and @code{PaperColumn}.  They can be changed with the
1477 @code{\overrideProperty} function, which works similar to @code{\once
1478 \override}, but uses a different syntax.
1479
1480 @example
1481 \overrideProperty
1482 #"Score.NonMusicalPaperColumn"  % Grob name
1483 #'line-break-system-details     % Property name
1484 #'((next-padding . 20))         % Value
1485 @end example
1486
1487 Note, however, that @code{\override}, applied to
1488 @code{NoteMusicalPaperColumn} and @code{PaperColumn}, still works as
1489 expected within @code{\context} blocks.
1490
1491 @end itemize