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