]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
Merge branch 'lilypond/translation' of /home/jcharles/GIT/Lily/ into lilypond/translation
[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 @c \version "2.11.55"
11
12 @node Changing defaults
13 @chapter Changing defaults
14
15 @strong{N.B. This Chapter is under heavy development at present.}
16
17 The purpose of LilyPond's design is to provide the finest output
18 quality as a default.  Nevertheless, it may happen that you need to
19 change this default layout.  The layout is controlled through a large
20 number of proverbial @q{knobs and switches.}  This chapter does not
21 list each and every knob.  Rather, it outlines what groups of controls
22 are available and explains how to lookup which knob to use for a
23 particular effect.
24
25
26 @cindex Internals Reference
27
28 The controls available for tuning are described in a separate
29 document: @rinternalsnamed{Top,the Internals Reference}.  That manual
30 lists all different variables, functions and options available in
31 LilyPond.  It is written as a HTML document, which is available
32 @c leave the @uref as one long line.
33 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
34 but is also included with the LilyPond documentation package.
35
36 @c TODO The following is at variance to what actually follows.  Fix -td
37
38 There are four areas where the default settings may be changed:
39
40 @itemize
41 @item
42 Automatic notation: changing the automatic creation of notation
43 elements.  For example, changing the beaming rules.
44
45 @item
46 Output: changing the appearance of individual
47 objects.  For example, changing stem directions or the location of
48 subscripts.
49
50 @item
51 Context: changing aspects of the translation from music events to
52 notation.  For example, giving each staff a separate time signature.
53
54 @item
55 Page layout: changing the appearance of the spacing, line
56 breaks, and page dimensions.  These modifications are discussed
57 @c in @ref{notation}, and @ref{Spacing issues}.
58 @end itemize
59
60 Internally, LilyPond uses Scheme (a LISP dialect) to provide
61 infrastructure.  Overriding layout decisions in effect accesses the
62 program internals, which requires Scheme input.  Scheme elements are
63 introduced in a @code{.ly} file with the hash mark
64 @code{#}.@footnote{@rlearning{Scheme tutorial}, contains a short tutorial
65 on entering numbers, lists, strings, and symbols in Scheme.}
66
67
68 @menu
69 * Interpretation contexts::     
70 * Explaining the Internals Reference::  
71 * Modifying properties::        
72 * Useful concepts and properties::  
73 * Common properties::           
74 * Advanced tweaks::             
75 * Discussion of specific tweaks::  
76 @end menu
77
78
79 @node Interpretation contexts
80 @section Interpretation contexts
81
82 This section describes what contexts are, and how to modify them.
83
84 @menu
85 * Contexts explained::          
86 * Creating contexts::           
87 * Modifying context plug-ins::  
88 * Changing context default settings::  
89 * Defining new contexts::       
90 * Aligning contexts::           
91 @end menu
92
93
94 @node Contexts explained
95 @subsection Contexts explained
96
97 @ignore
98 @c TODO Rethink and rewrite
99
100 >> > > - list of contexts: my *danger unmaintainable*
101 >> > > alarm just went off.  I'm
102
103 I knew it would... And leaving out some of them is perfectly fine
104 with me.
105 I do think that a list like this, with the main contexts and a
106 brief
107 description of  what they do (perhaps also with a note about what
108 default
109 behavior is associated with each of them, but this may be
110 unmanageable),
111 should be there, and then we could simply list the remaining ones
112 without
113 further explanation and with links to the IR.
114 @end ignore
115
116 @c TODO Improve layout, order and consistency of wording -td
117
118 @c TODO Add introduction which explains contexts in generality  -td
119
120 Contexts are arranged heirarchically:
121
122 @menu
123 * Score - the master of all contexts::  
124 * Top-level contexts - staff containers::  
125 * Intermediate-level contexts - staves::  
126 * Bottom-level contexts - voices::  
127 @end menu
128
129 @node Score - the master of all contexts
130 @unnumberedsubsubsec Score - the master of all contexts
131
132 This is the top level notation context. No other context can
133 contain a Score context. By default the Score context handles
134 the administration of time signatures and makes sure that items
135 such as clefs, time signatures, and key-signatures are aligned
136 across staves.
137
138 A Score context is instantiated implicitly when a
139 @code{\score @{@dots{}@}} or @code{\layout @{@dots{}@}} block is
140 processed, or explicitly when a @code{\new Score} command is
141 executed.
142
143 @node Top-level contexts - staff containers
144 @unnumberedsubsubsec Top-level contexts - staff containers
145
146 @strong{@emph{StaffGroup}}
147
148 Groups staves while adding a bracket on the left side, grouping
149 the staves together. The bar lines of the contained staves are
150 connected vertically. StaffGroup only consists of a collection
151 of staves, with a bracket in front and spanning bar lines.
152
153 @strong{@emph{ChoirStaff}}
154
155 Identical to StaffGroup except that the bar lines of the contained
156 staves are not connected vertically.
157
158 @strong{@emph{GrandStaff}}
159
160 A group of staves, with a brace on the left side, grouping
161 the staves together. The bar lines of the contained staves are
162 connected vertically.
163
164 @strong{@emph{PianoStaff}}
165
166 TODO No longer correct?  Check.  -td
167
168 Just like GrandStaff but with a forced distance between the
169 staves, so cross staff beaming and slurring can be used.
170
171 @strong{@emph{InnerStaffGroup}}
172
173 TODO  -td
174
175 @strong{@emph{InnerChoirStaff}}
176
177 TODO  -td
178
179 @node Intermediate-level contexts - staves
180 @unnumberedsubsubsec Intermediate-level contexts - staves
181
182 @strong{@emph{Staff}}
183
184 Handles clefs, bar lines, keys, accidentals. It can contain
185 Voice contexts.
186
187 @strong{@emph{RhythmicStaff}}
188
189 Like Staff but for printing rhythms. Pitches are ignored;
190 the notes are printed on one line.
191
192 @strong{@emph{TabStaff}}
193
194 Context for generating tablature. By default lays the music
195 expression out as a guitar tablature, printed on six lines.
196
197 @strong{@emph{DrumStaff}}
198
199 Handles typesetting for percussion. Can contain DrumVoice
200
201 @strong{@emph{VaticanaStaff}}
202
203 Same as Staff, except that it is designed for typesetting
204 a piece in gregorian style.
205
206 @strong{@emph{MensuralStaff}}
207
208 Same as Staff, except that it is designed for typesetting
209 a piece in mensural style.
210
211 @node Bottom-level contexts - voices
212 @unnumberedsubsubsec Bottom-level contexts - voices
213
214 Voice-level contexts initialise certain properties and start
215 appropriate engravers.  Being bottom-level contexts, they cannot
216 contain other contexts.
217
218 @strong{@emph{Voice}}
219
220 Corresponds to a voice on a staff. This context handles the
221 conversion of dynamic signs, stems, beams, super- and sub-scripts,
222 slurs, ties, and rests.  You have to instantiate this explicitly
223 if you require multiple voices on the same staff.
224
225 @strong{@emph{VaticanaVoice}}
226
227 Same as Voice, except that it is designed for typesetting a piece
228 in gregorian style.
229
230 @strong{@emph{MensuralVoice}}
231
232 Same as Voice, with modifications for typesetting a piece in
233 mensural style.
234
235 @strong{@emph{Lyrics}}
236
237 Corresponds to a voice with lyrics. Handles the printing of a
238 single line of lyrics.
239
240 @strong{@emph{DrumVoice}}
241
242 The voice context used in a percussion staff.
243
244 @strong{@emph{FiguredBass}}
245
246 The context in which BassFigure objects are created from
247 input entered in @code{\figuremode} mode.
248
249 @strong{@emph{TabVoice}}
250
251 The voice context used within a TabStaff context.  Usually left to
252 be created implicitly.
253
254 @strong{@emph{ChordNames}}
255
256 Typesets chord names.
257
258 ------------------------------
259
260 TODO
261
262 Then the following, which I don't know what to do with:
263
264     * GregorianTranscriptionVoice
265     * GregorianTranscriptionStaff
266
267     * FretBoards
268         Engraves fretboards from chords. Not easy... Not
269 documented.
270         There is now some documentation on FretBoards in the NR, under
271          instrument-specific notation -- cds.
272
273     * NoteNames
274
275     * CueVoice Not documented
276     * Global
277         Hard coded entry point for LilyPond. Cannot be tuned.
278     * Devnull
279         Silently discards all musical information given to this
280 context.
281
282
283 @node Creating contexts
284 @subsection Creating contexts
285
286 @c TODO \new Score and \score
287 @c TODO more complete descriptions rather than learning style
288
289 For scores with only one voice and one staff, contexts are
290 created automatically.  For more complex scores, it is necessary to
291 create them by hand.  There are three commands that do this.
292
293 @itemize
294
295 @item
296 The easiest command is @code{\new}, and it also the quickest to type.
297 It is prepended to a music expression, for example
298
299 @funindex \new
300 @cindex new contexts
301 @cindex Context, creating
302
303 @example
304 \new @var{type} @var{music expression}
305 @end example
306
307 @noindent
308 where @var{type} is a context name (like @code{Staff} or
309 @code{Voice}).  This command creates a new context, and starts
310 interpreting the @var{music expression} with that.
311
312 A practical application of @code{\new} is a score with many
313 staves.  Each part that should be on its own staff, is preceded with
314 @code{\new Staff}.
315
316 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
317 <<
318   \new Staff { c4 c }
319   \new Staff { d4 d }
320 >>
321 @end lilypond
322
323 The @code{\new} command may also give a name to the context,
324
325 @example
326 \new @var{type} = @var{id} @var{music}
327 @end example
328 However, this user specified name is only used if there is no other
329 context already earlier with the same name.
330
331
332 @funindex \context
333
334 @item
335 Like @code{\new}, the @code{\context} command also directs a music
336 expression to a context object, but gives the context an explicit name.  The
337 syntax is
338
339 @example
340 \context @var{type} = @var{id} @var{music}
341 @end example
342
343 This form will search for an existing context of type @var{type}
344 called @var{id}.  If that context does not exist yet, a new
345 context with the specified name is created.  This is useful if
346 the context is referred to later on.  For example, when
347 setting lyrics the melody is in a named context
348
349 @example
350 \context Voice = "@b{tenor}" @var{music}
351 @end example
352
353 @noindent
354 so the texts can be properly aligned to its notes,
355
356 @example
357 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
358 @end example
359
360 @noindent
361
362 Another possible use of named contexts is funneling two different
363 music expressions into one context.  In the following example,
364 articulations and notes are entered separately,
365
366 @example
367 music = @{ c4 c4 @}
368 arts = @{ s4-. s4-> @}
369 @end example
370
371 They are combined by sending both to the same @code{Voice} context,
372
373 @example
374 <<
375   \new Staff \context Voice = "A" \music
376   \context Voice = "A" \arts
377 >>
378 @end example
379 @lilypond[quote,ragged-right]
380 music = { c4 c4 }
381 arts = { s4-. s4-> }
382 \relative c'' <<
383   \new Staff \context Voice = "A" \music
384   \context Voice = "A" \arts
385 >>
386 @end lilypond
387
388 With this mechanism, it is possible to define an Urtext (original
389 edition), with the option to put several distinct articulations on the
390 same notes.
391
392 @cindex creating contexts
393
394 @item
395 The third command for creating contexts is
396 @example
397 \context @var{type} @var{music}
398 @end example
399
400
401 @noindent
402 This is similar to @code{\context} with @code{= @var{id}}, but matches
403 any context of type @var{type}, regardless of its given name.
404
405 This variant is used with music expressions that can be interpreted at
406 several levels.  For example, the @code{\applyOutput} command (see
407 @ref{Running a function on all layout objects}).  Without an explicit
408 @code{\context}, it is usually applied to @code{Voice}
409
410 @example
411 \applyOutput #'@var{context} #@var{function}   % apply to Voice
412 @end example
413
414 To have it interpreted at the @code{Score} or @code{Staff} level use
415 these forms
416
417 @example
418 \applyOutput #'Score #@var{function}
419 \applyOutput #'Staff #@var{function}
420 @end example
421
422 @end itemize
423
424
425 @node Modifying context plug-ins
426 @subsection Modifying context plug-ins
427
428 @c TODO Should this be Modifying engravers or Modifying contexts?
429
430 Notation contexts (like @code{Score} and @code{Staff}) not only
431 store properties,
432 they also contain plug-ins called @q{engravers} that create notation
433 elements.  For example, the @code{Voice} context contains a
434 @code{Note_head_engraver} and the @code{Staff} context contains a
435 @code{Key_signature_engraver}.
436
437 For a full a description of each plug-in, see
438 @ifhtml
439 @rinternals{Engravers and Performers}.
440 @end ifhtml
441 @ifnothtml
442 Internals Reference @expansion{} Translation @expansion{} Engravers.
443 @end ifnothtml
444 Every context described in
445 @ifhtml
446 @rinternals{Contexts}
447 @end ifhtml
448 @ifnothtml
449 Internals Reference @expansion{} Translation @expansion{} Context.
450 @end ifnothtml
451 lists the engravers used for that context.
452
453
454 It can be useful to shuffle around these plug-ins.  This is done by
455 starting a new context with @code{\new} or @code{\context}, and
456 modifying it,
457
458 @funindex \with
459
460 @example
461 \new @var{context} \with @{
462   \consists @dots{}
463   \consists @dots{}
464   \remove @dots{}
465   \remove @dots{}
466   @emph{etc.}
467 @}
468 @{
469   @emph{..music..}
470 @}
471 @end example
472
473 @noindent
474 where the @dots{} should be the name of an engraver.  Here is a simple
475 example which removes @code{Time_signature_engraver} and
476 @code{Clef_engraver} from a @code{Staff} context,
477
478 @lilypond[quote,relative=1,verbatim,fragment]
479 <<
480   \new Staff {
481     f2 g
482   }
483   \new Staff \with {
484      \remove "Time_signature_engraver"
485      \remove "Clef_engraver"
486   } {
487     f2 g2
488   }
489 >>
490 @end lilypond
491
492 In the second staff there are no time signature or clef symbols.  This
493 is a rather crude method of making objects disappear since it will affect
494 the entire staff.  This method also influences the spacing, which may or
495 may not be desirable.  More sophisticated methods of blanking objects
496 are shown in @rlearning{Visibility and color of objects}.
497
498 The next example shows a practical application.  Bar lines and time
499 signatures are normally synchronized across the score.  This is done
500 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
501 This plug-in keeps an administration of time signature, location
502 within the measure, etc.  By moving these engraver from @code{Score} to
503 @code{Staff} context, we can have a score where each staff has its own
504 time signature.
505
506 @cindex polymetric scores
507 @cindex Time signatures, multiple
508
509 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
510 \new Score \with {
511   \remove "Timing_translator"
512   \remove "Default_bar_line_engraver"
513 } <<
514   \new Staff \with {
515     \consists "Timing_translator"
516     \consists "Default_bar_line_engraver"
517   } {
518       \time 3/4
519       c4 c c c c c
520   }
521   \new Staff \with {
522     \consists "Timing_translator"
523     \consists "Default_bar_line_engraver"
524   } {
525        \time 2/4
526        c4 c c c c c
527   }
528 >>
529 @end lilypond
530
531
532 @node Changing context default settings
533 @subsection Changing context default settings
534
535 The adjustments of the previous subsections (
536 @ref{The set command}, @ref{Modifying context plug-ins}, and
537 @ref{Overview of modifying properties}) can also be entered
538 separately from the music in the @code{\layout} block,
539
540 @example
541 \layout @{
542   @dots{}
543   \context @{
544     \Staff
545
546     \set fontSize = #-2
547     \override Stem #'thickness = #4.0
548     \remove "Time_signature_engraver"
549   @}
550 @}
551 @end example
552
553 The @code{\Staff} command brings in the existing definition of the
554 staff context so that it can be modified.
555
556 The statements
557 @example
558 \set fontSize = #-2
559 \override Stem #'thickness = #4.0
560 \remove "Time_signature_engraver"
561 @end example
562
563 @noindent
564 affect all staves in the score.  Other contexts can be modified
565 analogously.
566
567 The @code{\set} keyword is optional within the @code{\layout} block, so
568
569 @example
570 \context @{
571   @dots{}
572   fontSize = #-2
573 @}
574 @end example
575
576 @noindent
577 will also work.
578
579
580
581 @knownissues
582
583 It is not possible to collect context changes in a variable and apply
584 them to a @code{\context} definition by referring to that variable.
585
586 The @code{\RemoveEmptyStaffContext} will overwrite your current
587 @code{\Staff} settings.  If you wish to change the defaults for a
588 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
589 after calling @code{\RemoveEmptyStaffContext}, ie
590
591 @example
592 \layout @{
593   \context @{
594     \RemoveEmptyStaffContext
595
596     \override Stem #'thickness = #4.0
597   @}
598 @}
599 @end example
600
601 TODO: add \with in here.
602
603
604
605 @node Defining new contexts
606 @subsection Defining new contexts
607
608 Specific contexts, like @code{Staff} and @code{Voice}, are made of
609 simple building blocks.  It is possible to create new types of
610 contexts with different combinations of engraver plug-ins.
611
612 The next example shows how to build a different type of
613 @code{Voice} context from scratch.  It will be similar to
614 @code{Voice}, but only prints centered slash note heads.  It can be used
615 to indicate improvisation in jazz pieces,
616
617 @lilypond[quote,ragged-right]
618 \layout { \context {
619   \name ImproVoice
620   \type "Engraver_group"
621   \consists "Note_heads_engraver"
622   \consists "Text_engraver"
623   \consists Pitch_squash_engraver
624   squashedPosition = #0
625   \override NoteHead #'style = #'slash
626   \override Stem #'transparent = ##t
627   \alias Voice
628 }
629 \context { \Staff
630   \accepts "ImproVoice"
631 }}
632
633 \relative c'' {
634   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
635    c4 c^"undress" c_"while playing :)" c }
636   a1
637 }
638 @end lilypond
639
640
641 These settings are defined within a @code{\context} block inside a
642 @code{\layout} block,
643
644 @example
645 \layout @{
646   \context @{
647     @dots{}
648   @}
649 @}
650 @end example
651
652 In the following discussion, the example input shown should go in place
653 of the @dots{} in the previous fragment.
654
655 First it is necessary to define a name for the new context:
656
657 @example
658 \name ImproVoice
659 @end example
660
661 Since it is similar to the @code{Voice}, we want commands that work
662 on (existing) @code{Voice}s to remain working.  This is achieved by
663 giving the new context an alias @code{Voice},
664
665 @example
666 \alias Voice
667 @end example
668
669 The context will print notes and instructive texts, so we need to add
670 the engravers which provide this functionality,
671
672 @example
673 \consists Note_heads_engraver
674 \consists Text_engraver
675 @end example
676
677 but we only need this on the center line,
678
679 @example
680 \consists Pitch_squash_engraver
681 squashedPosition = #0
682 @end example
683
684 The @rinternals{Pitch_squash_engraver} modifies note heads (created
685 by @rinternals{Note_heads_engraver}) and sets their vertical
686 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
687 the center line.
688
689 The notes look like a slash, and have no stem,
690
691 @example
692 \override NoteHead #'style = #'slash
693 \override Stem #'transparent = ##t
694 @end example
695
696 All these plug-ins have to cooperate, and this is achieved with a
697 special plug-in, which must be marked with the keyword @code{\type}.
698 This should always be @code{Engraver_group}.
699
700 @example
701 \type "Engraver_group"
702 @end example
703
704 Put together, we get
705
706 @example
707 \context @{
708   \name ImproVoice
709   \type "Engraver_group"
710   \consists "Note_heads_engraver"
711   \consists "Text_engraver"
712   \consists Pitch_squash_engraver
713   squashedPosition = #0
714   \override NoteHead #'style = #'slash
715   \override Stem #'transparent = ##t
716   \alias Voice
717 @}
718 @end example
719
720 @funindex \accepts
721 Contexts form hierarchies.  We want to hang the @code{ImproVoice}
722 under @code{Staff}, just like normal @code{Voice}s.  Therefore, we
723 modify the @code{Staff} definition with the @code{\accepts}
724 command,
725
726 @example
727 \context @{
728   \Staff
729   \accepts ImproVoice
730 @}
731 @end example
732
733 @funindex \denies
734 The opposite of @code{\accepts} is @code{\denies},
735 which is sometimes needed when reusing existing context definitions.
736
737 Putting both into a @code{\layout} block, like
738
739 @example
740 \layout @{
741   \context @{
742     \name ImproVoice
743     @dots{}
744   @}
745   \context @{
746     \Staff
747     \accepts "ImproVoice"
748   @}
749 @}
750 @end example
751
752 Then the output at the start of this subsection can be entered as
753
754 @example
755 \relative c'' @{
756   a4 d8 bes8
757   \new ImproVoice @{
758     c4^"ad lib" c
759     c4 c^"undress"
760     c c_"while playing :)"
761   @}
762   a1
763 @}
764 @end example
765
766
767 @node Aligning contexts
768 @subsection Aligning contexts
769
770 New contexts may be aligned above or below existing contexts.  This
771 could be useful in setting up a vocal staff (@rlearning{Vocal ensembles}) and
772 in ossia,
773
774 @c TODO Better example needed.  Ref LM, and expand on it.
775
776 @cindex ossia
777 @findex alignAboveContext
778 @findex alignBelowContext
779
780 @lilypond[quote,ragged-right]
781 ossia = { f4 f f f }
782 \score{
783   \relative c' \new Staff = "main" {
784     c4 c c c
785     <<
786       \new Staff \with {alignAboveContext=main} \ossia
787       { d8 f d f d f d f }
788     >>
789   }
790 }
791 @end lilypond
792
793
794 @node Explaining the Internals Reference
795 @section Explaining the Internals Reference
796
797
798 @menu
799 * Navigating the program reference::  
800 * Layout interfaces::           
801 * Determining the grob property::  
802 * Naming conventions::          
803 @end menu
804
805 @node Navigating the program reference
806 @subsection Navigating the program reference
807
808 @c TODO remove this (it's in the LM)
809 @c Replace with more factual directions
810
811 Suppose we want to move the fingering indication in the fragment
812 below:
813
814 @lilypond[quote,fragment,relative=2,verbatim]
815 c-2
816 \stemUp
817 f
818 @end lilypond
819
820 If you visit the documentation on fingering instructions (in
821 @ref{Fingering instructions}), you will notice:
822
823 @quotation
824 @strong{See also}
825
826 Internals Reference: @rinternals{Fingering}.
827
828 @end quotation
829
830
831 @c  outdated info; probably will delete.
832 @ignore
833 This fragment points to two parts of the program reference: a page
834 on @code{FingeringEvent} and one on @code{Fingering}.
835
836 The page on @code{FingeringEvent} describes the properties of the music
837 expression for the input @code{-2}.  The page contains many links
838 forward.  For example, it says
839
840 @quotation
841 Accepted by: @rinternals{Fingering_engraver},
842 @end quotation
843
844 @noindent
845 That link brings us to the documentation for the Engraver, the
846 plug-in, which says
847
848 @quotation
849 This engraver creates the following layout objects: @rinternals{Fingering}.
850 @end quotation
851
852 In other words, once the @code{FingeringEvent}s are interpreted, the
853 @code{Fingering_engraver} plug-in will process them.
854 @end ignore
855
856 @ignore
857 @c  I can't figure out what this is supposed to mean.  -gp
858
859 The @code{Fingering_engraver} is also listed to create
860 @rinternals{Fingering} objects,
861
862 @c  old info?  it doesn't make any sense to me with our current docs.
863 This is also the
864 second bit of information listed under @b{See also} in the Notation
865 manual.
866 @end ignore
867
868 @ifnothtml
869 The programmer's reference is available as an HTML document.  It is
870 highly recommended that you read it in HTML form, either online or
871 by downloading the HTML documentation.  This section will be much more
872 difficult to understand if you are using the
873 PDF manual.
874 @end ifnothtml
875
876 Follow the link to @rinternals{Fingering}.  At the top of the
877 page, you will see
878
879 @quotation
880 Fingering objects are created by: @rinternals{Fingering_engraver} and
881 @rinternals{New_fingering_engraver}.
882 @end quotation
883
884 By following related links inside the program reference, we can follow the
885 flow of information within the program:
886
887 @itemize
888
889 @item @rinternals{Fingering}:
890 @rinternals{Fingering} objects are created by:
891 @rinternals{Fingering_engraver}
892
893 @item @rinternals{Fingering_engraver}:
894 Music types accepted: @rinternals{fingering-event}
895
896 @item @rinternals{fingering-event}:
897 Music event type @code{fingering-event} is in Music expressions named
898 @rinternals{FingeringEvent}
899 @end itemize
900
901 This path goes against the flow of information in the program: it
902 starts from the output, and ends at the input event.  You could
903 also start at an input event, and read with the flow of
904 information, eventually ending up at the output object(s).
905
906 The program reference can also be browsed like a normal document.  It
907 contains chapters on
908 @ifhtml
909 @rinternals{Music definitions},
910 @end ifhtml
911 @ifnothtml
912 @code{Music definitions}
913 @end ifnothtml
914 on @rinternals{Translation}, and the @rinternals{Backend}.  Every
915 chapter lists all the definitions used and all properties that may be
916 tuned.
917
918
919 @node Layout interfaces
920 @subsection Layout interfaces
921
922 @cindex interface, layout
923 @cindex layout interface
924 @cindex grob
925
926 The HTML page that we found in the previous section describes the
927 layout object called @rinternals{Fingering}.  Such an object is a
928 symbol within the score.  It has properties that store numbers (like
929 thicknesses and directions), but also pointers to related objects.  A
930 layout object is also called a @emph{Grob}, which is short for Graphical
931 Object.  For more details about Grobs, see @rinternals{grob-interface}.
932
933 The page for @code{Fingering} lists the definitions for the
934 @code{Fingering} object.  For example, the page says
935
936 @quotation
937 @code{padding} (dimension, in staff space):
938
939 @code{0.5}
940 @end quotation
941
942 @noindent
943 which means that the number will be kept at a distance of at least 0.5
944 of the note head.
945
946
947 Each layout object may have several functions as a notational or
948 typographical element.  For example, the Fingering object
949 has the following aspects
950
951 @itemize
952 @item
953 Its size is independent of the horizontal spacing, unlike slurs or beams.
954
955 @item
956 It is a piece of text.  Granted, it is usually a very short text.
957
958 @item
959 That piece of text is typeset with a font, unlike slurs or beams.
960
961 @item
962 Horizontally, the center of the symbol should be aligned to the
963 center of the note head.
964
965 @item
966 Vertically, the symbol is placed next to the note and the staff.
967
968 @item
969 The vertical position is also coordinated with other superscript
970 and subscript symbols.
971 @end itemize
972
973 Each of these aspects is captured in so-called @emph{interface}s,
974 which are listed on the @rinternals{Fingering} page at the bottom
975
976 @quotation
977 This object supports the following interfaces:
978 @rinternals{item-interface},
979 @rinternals{self-alignment-interface},
980 @rinternals{side-position-interface}, @rinternals{text-interface},
981 @rinternals{text-script-interface}, @rinternals{font-interface},
982 @rinternals{finger-interface}, and @rinternals{grob-interface}.
983 @end quotation
984
985 Clicking any of the links will take you to the page of the respective
986 object interface.  Each interface has a number of properties.  Some of
987 them are not user-serviceable (@q{Internal properties}), but others
988 can be modified.
989
990 We have been talking of @emph{the} @code{Fingering} object, but actually it
991 does not amount to much.  The initialization file (see
992 @rlearning{Other sources of information})
993 @file{scm/@/define@/-grobs@/.scm} shows the soul of the @q{object},
994
995 @example
996 (Fingering
997   . ((padding . 0.5)
998      (avoid-slur . around)
999      (slur-padding . 0.2)
1000      (staff-padding . 0.5)
1001      (self-alignment-X . 0)
1002      (self-alignment-Y . 0)
1003      (script-priority . 100)
1004      (stencil . ,ly:text-interface::print)
1005      (direction . ,ly:script-interface::calc-direction)
1006      (font-encoding . fetaNumber)
1007      (font-size . -5)           ; don't overlap when next to heads.
1008      (meta . ((class . Item)
1009      (interfaces . (finger-interface
1010                     font-interface
1011                     text-script-interface
1012                     text-interface
1013                     side-position-interface
1014                     self-alignment-interface
1015                     item-interface))))))
1016 @end example
1017
1018 @noindent
1019 As you can see, the @code{Fingering} object is nothing more than a
1020 bunch of variable settings, and the webpage in the Internals Reference
1021 is directly generated from this definition.
1022
1023
1024 @node Determining the grob property
1025 @subsection Determining the grob property
1026
1027 @c TODO remove this (it's in the LM)
1028 @c Replace with more factual directions
1029
1030 Recall that we wanted to change the position of the @b{2} in
1031
1032 @lilypond[quote,fragment,relative=2,verbatim]
1033 c-2
1034 \stemUp
1035 f
1036 @end lilypond
1037
1038 Since the @b{2} is vertically positioned next to its note, we have to
1039 meddle with the interface associated with this positioning.  This is
1040 done using @code{side-position-interface}.  The page for this interface
1041 says
1042
1043 @quotation
1044 @code{side-position-interface}
1045
1046 Position a victim object (this one) next to other objects (the
1047 support).  The property @code{direction} signifies where to put the
1048 victim object relative to the support (left or right, up or down?)
1049 @end quotation
1050
1051 @cindex padding
1052 @noindent
1053 Below this description, the variable @code{padding} is described as
1054
1055 @quotation
1056 @table @code
1057 @item padding
1058 (dimension, in staff space)
1059
1060 Add this much extra space between objects that are next to each other.
1061 @end table
1062 @end quotation
1063
1064 By increasing the value of @code{padding}, we can move the
1065 fingering away from the note head.  The following command inserts
1066 3 staff spaces of white
1067 between the note and the fingering:
1068 @example
1069 \once \override Voice.Fingering #'padding = #3
1070 @end example
1071
1072 Inserting this command before the Fingering object is created,
1073 i.e., before @code{c2}, yields the following result:
1074
1075 @lilypond[quote,relative=2,fragment,verbatim]
1076 \once \override Voice.Fingering #'padding = #3
1077 c-2
1078 \stemUp
1079 f
1080 @end lilypond
1081
1082
1083 In this case, the context for this tweak is @code{Voice}.  This
1084 fact can also be deduced from the program reference, for the page for
1085 the @rinternals{Fingering_engraver} plug-in says
1086
1087 @quotation
1088 Fingering_engraver is part of contexts: @dots{} @rinternals{Voice}
1089 @end quotation
1090
1091
1092 @node Naming conventions
1093 @subsection Naming conventions
1094
1095 Another thing that is needed, is an overview of the various naming
1096 conventions:
1097
1098     scheme functions: lowercase-with-hyphens (incl. one-word
1099 names)
1100     scheme functions: ly:plus-scheme-style
1101     music events, music classes and music properties:
1102 as-scheme-functions
1103     Grob interfaces: scheme-style
1104     backend properties: scheme-style (but X and Y!)
1105     contexts (and MusicExpressions and grobs): Capitalized or
1106 CamelCase
1107     context properties: lowercaseFollowedByCamelCase
1108     engravers:
1109 Capitalized_followed_by_lowercase_and_with_underscores
1110
1111 Which of these are conventions and which are rules?
1112 Which are rules of the underlying language, and which are
1113 LP-specific?
1114
1115
1116 @node Modifying properties
1117 @section Modifying properties
1118
1119 @c TODO change the menu and subsection node names to use
1120 @c backslash once the new macro to handle the refs
1121 @c is available.  Need to find and change all refs at
1122 @c the same time. -td
1123
1124 @menu
1125 * Overview of modifying properties::
1126 * The set command::
1127 * The override command::
1128 * The tweak command::
1129 * set versus override::
1130 @end menu
1131
1132
1133 @node Overview of modifying properties
1134 @subsection Overview of modifying properties
1135
1136 Each context is responsible for creating certain types of graphical
1137 objects.  The settings used for printing these objects are also stored by
1138 context.  By changing these settings, the appearance of objects can be
1139 altered.
1140
1141 The syntax for this is
1142
1143 @example
1144 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1145 @end example
1146
1147 Here @var{name} is the name of a graphical object, like
1148 @code{Stem} or @code{NoteHead}, and @var{property} is an internal
1149 variable of the formatting system (@q{grob property} or @q{layout
1150 property}).  The latter is a symbol, so it must be quoted.  The
1151 subsection @ref{Modifying properties}, explains what to fill in
1152 for @var{name}, @var{property}, and @var{value}.  Here we only
1153 discuss the functionality of this command.
1154
1155 The command
1156
1157 @verbatim
1158 \override Staff.Stem #'thickness = #4.0
1159 @end verbatim
1160
1161 @noindent
1162 makes stems thicker (the default is 1.3, with staff line thickness as a
1163 unit).  Since the command specifies @code{Staff} as context, it only
1164 applies to the current staff.  Other staves will keep their normal
1165 appearance.  Here we see the command in action:
1166
1167 @lilypond[quote,verbatim,relative=2,fragment]
1168 c4
1169 \override Staff.Stem #'thickness = #4.0
1170 c4
1171 c4
1172 c4
1173 @end lilypond
1174
1175 The @code{\override} command changes the definition of the @code{Stem}
1176 within the current @code{Staff}.  After the command is interpreted
1177 all stems are thickened.
1178
1179 Analogous to @code{\set}, the @var{context} argument may be left out,
1180 causing the default context @code{Voice} to be used.  Adding
1181 @code{\once} applies the change during one timestep only.
1182
1183 @lilypond[quote,fragment,verbatim,relative=2]
1184 c4
1185 \once \override Stem #'thickness = #4.0
1186 c4
1187 c4
1188 @end lilypond
1189
1190 The @code{\override} must be done before the object is
1191 started.  Therefore, when altering @emph{Spanner} objects such as slurs
1192 or beams, the @code{\override} command must be executed at the moment
1193 when the object is created.  In this example,
1194
1195 @lilypond[quote,fragment,verbatim,relative=2]
1196 \override Slur #'thickness = #3.0
1197 c8[( c
1198 \override Beam #'thickness = #0.6
1199 c8 c])
1200 @end lilypond
1201
1202 @noindent
1203 the slur is fatter but the beam is not.  This is because the command for
1204 @code{Beam} comes after the Beam is started, so it has no effect.
1205
1206 Analogous to @code{\unset}, the @code{\revert} command for a context
1207 undoes an @code{\override} command; like with @code{\unset}, it only
1208 affects settings that were made in the same context.  In other words, the
1209 @code{\revert} in the next example does not do anything.
1210
1211 @example
1212 \override Voice.Stem #'thickness = #4.0
1213 \revert Staff.Stem #'thickness
1214 @end example
1215
1216 Some tweakable options are called @q{subproperties} and reside inside
1217 properties.  To tweak those, use commands of the form
1218
1219 @c leave this as a long long
1220 @example
1221 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
1222 @end example
1223
1224 @noindent
1225 such as
1226
1227 @example
1228 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1229 @end example
1230
1231
1232 @seealso
1233
1234 Internals: @rinternals{OverrideProperty}, @rinternals{RevertProperty},
1235 @rinternals{PropertySet}, @rinternals{Backend}, and
1236 @rinternals{All layout objects}.
1237
1238
1239 @knownissues
1240
1241 The back-end is not very strict in type-checking object properties.
1242 Cyclic references in Scheme values for properties can cause hangs
1243 or crashes, or both.
1244
1245
1246
1247 @node The set command
1248 @subsection The @code{\set} command
1249
1250 @cindex properties
1251 @funindex \set
1252 @cindex changing properties
1253
1254 Each context can have different @emph{properties}, variables contained
1255 in that context.  They can be changed during the interpretation step.
1256 This is achieved by inserting the @code{\set} command in the music,
1257
1258 @example
1259 \set @var{context}.@var{prop} = #@var{value}
1260 @end example
1261
1262 For example,
1263 @lilypond[quote,verbatim,relative=2,fragment]
1264 R1*2
1265 \set Score.skipBars = ##t
1266 R1*2
1267 @end lilypond
1268
1269 This command skips measures that have no notes.  The result is that
1270 multi-rests are condensed.  The value assigned is a Scheme object.  In
1271 this case, it is @code{#t}, the boolean True value.
1272
1273 If the @var{context} argument is left out, then the current bottom-most
1274 context (typically @code{ChordNames}, @code{Voice}, or
1275 @code{Lyrics}) is used.  In this example,
1276
1277 @lilypond[quote,verbatim,relative=2,fragment]
1278 c8 c c c
1279 \set autoBeaming = ##f
1280 c8 c c c
1281 @end lilypond
1282
1283 @noindent
1284 the @var{context} argument to @code{\set} is left out, so automatic
1285 beaming is switched off in the current @rinternals{Voice}.  Note that
1286 the bottom-most context does not always contain the property that you
1287 wish to change -- for example, attempting to set the @code{skipBars}
1288 property (of the bottom-most context, in this case @code{Voice}) will
1289 have no effect.
1290
1291 @lilypond[quote,verbatim,relative=2,fragment]
1292 R1*2
1293 \set skipBars = ##t
1294 R1*2
1295 @end lilypond
1296
1297 Contexts are hierarchical, so if a bigger context was specified, for
1298 example @code{Staff}, then the change would also apply to all
1299 @code{Voice}s in the current stave.  The change is applied
1300 @q{on-the-fly}, during the music, so that the setting only affects the
1301 second group of eighth notes.
1302
1303 @funindex \unset
1304
1305 There is also an @code{\unset} command,
1306 @example
1307 \unset @var{context}.@var{prop}
1308 @end example
1309
1310 @noindent
1311 which removes the definition of @var{prop}.  This command removes
1312 the definition only if it is set in @var{context}, so
1313
1314 @example
1315 \set Staff.autoBeaming = ##f
1316 @end example
1317
1318 @noindent
1319 introduces a property setting at @code{Staff} level.  The setting also
1320 applies to the current @code{Voice}.  However,
1321
1322 @example
1323 \unset Voice.autoBeaming
1324 @end example
1325
1326 @noindent
1327 does not have any effect.  To cancel this setting, the @code{\unset}
1328 must be specified on the same level as the original @code{\set}.  In
1329 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
1330 requires
1331 @example
1332 \unset Staff.autoBeaming
1333 @end example
1334
1335 Like @code{\set}, the @var{context} argument does not have to be
1336 specified for a bottom context, so the two statements
1337
1338 @example
1339 \set Voice.autoBeaming = ##t
1340 \set autoBeaming = ##t
1341 @end example
1342
1343 @noindent
1344 are equivalent.
1345
1346
1347 @cindex \once
1348 Settings that should only apply to a single time-step can be entered
1349 with @code{\once}, for example in
1350
1351 @lilypond[quote,verbatim,relative=2,fragment]
1352 c4
1353 \once \set fontSize = #4.7
1354 c4
1355 c4
1356 @end lilypond
1357
1358 the property @code{fontSize} is unset automatically after the second
1359 note.
1360
1361 A full description of all available context properties is in the
1362 program reference, see
1363 @ifhtml
1364 @rinternals{Tunable context properties}.
1365 @end ifhtml
1366 @ifnothtml
1367 Translation @expansion{} Tunable context properties.
1368 @end ifnothtml
1369
1370
1371
1372 @node The override command
1373 @subsection The @code{\override} command
1374
1375 Commands which change output generally look like
1376
1377 @example
1378 \override Voice.Stem #'thickness = #3.0
1379 @end example
1380
1381 @noindent
1382 To construct this tweak we must determine these bits of information:
1383
1384 @itemize
1385 @item the context: here @code{Voice}.
1386 @item the layout object: here @code{Stem}.
1387 @item the layout property: here @code{thickness}.
1388 @item a sensible value: here @code{3.0}.
1389 @end itemize
1390
1391 Some tweakable options are called @q{subproperties} and reside inside
1392 properties.  To tweak those, use commands in the form
1393
1394 @example
1395 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1396 @end example
1397
1398 @cindex internal documentation
1399 @cindex finding graphical objects
1400 @cindex graphical object descriptions
1401 @cindex tweaking
1402 @funindex \override
1403 @cindex internal documentation
1404
1405 For many properties, regardless of the data type of the property, setting the
1406 property to false ( @code{##f} ) will result in turning it off, causing
1407 LilyPond to ignore that property entirely.  This is particularly useful for
1408 turning off grob properties which may otherwise be causing problems.
1409
1410 We demonstrate how to glean this information from the notation manual
1411 and the program reference.
1412
1413
1414 @node The tweak command
1415 @subsection The @code{\tweak} command
1416
1417 @funindex \tweak
1418 @cindex tweaking
1419
1420 In some cases, it is possible to take a short-cut for tuning
1421 graphical objects.  For objects that are created directly from
1422 an item in the input file, you can use the @code{\tweak} command.
1423 For example:
1424
1425 @lilypond[relative=2,verbatim]
1426 < c
1427   \tweak #'color #red
1428   d
1429   g
1430   \tweak #'duration-log #1
1431   a
1432 > 4
1433 -\tweak #'padding #8
1434 -^
1435 @end lilypond
1436
1437 @cindex chord, modifying one note in
1438
1439 But the main use of the @code{\tweak} command is to modify just
1440 one of a number of notation elements which start at the same musical
1441 moment, like the notes of a chord, or tuplet brackets which start
1442 at the same time.
1443
1444 For an introduction to the syntax and uses of the tweak command
1445 see @rlearning{Tweaking methods}.
1446
1447 The @code{\tweak} command sets a property in the following object
1448 directly, without requiring the grob name or context to be
1449 specified.  For this to work, it is necessary for the @code{\tweak}
1450 command to remain immediately adjacent to the object to which it is
1451 to apply after the input file has been converted to a music stream.
1452 This is often not the case, as many additional elements are inserted
1453 into the music stream implicitly.  For example, when a note which is
1454 not part of a chord is processed, Lilypond implicitly inserts a
1455 @code{ChordEvent} event before the note, so separating the tweak
1456 from the note.  However, if chord symbols are placed round the
1457 tweak and the note, the @code{\tweak} command comes after the
1458 @code{ChordEvent} in the music stream, so remaining adjacent to the
1459 note, and able to modify it.
1460
1461 So, this works:
1462
1463 @lilypond[relative=2,verbatim,quote]
1464 <\tweak #'color #red c>4
1465 @end lilypond
1466
1467 @noindent
1468 but this does not:
1469
1470 @lilypond[relative=2,verbatim,quote]
1471 \tweak #'color #red c4
1472 @end lilypond
1473
1474 When several similar items are placed at the same musical moment,
1475 the @code{\override} command cannot be used to modify just one of
1476 them -- this is where the @code{\tweak} command must be used.
1477 Items which may appear more than once at the same musical moment
1478 include the following:
1479
1480 @c TODO expand to include any further uses of \tweak
1481 @itemize
1482 @item note heads of notes inside a chord
1483 @item articulation signs on a single note
1484 @item ties between notes in a chord
1485 @item tuplet brackets starting at the same time
1486 @end itemize
1487
1488 @c TODO add examples of these
1489
1490 @noindent
1491 and @code{\tweak} may be used to modify any single occurrence of
1492 these items.
1493
1494 Notably the @code{\tweak} command cannot be used to modify stems,
1495 beams or accidentals, since these are generated later by note heads,
1496 rather than by music elements in the input stream.  Nor can a
1497 @code{\tweak} command be used to modify clefs or time signatures,
1498 since these become separated from any preceding @code{\tweak}
1499 command in the input stream by the automatic insertion of extra
1500 elements required to specify the context.
1501
1502 But the @code{\tweak} command can be used as an alternative to
1503 the @code{\override} command to modify those notational elements
1504 that do not cause any additional implicit elements to be added
1505 before them in the music stream.  For example, slurs may be
1506 modified in this way:
1507
1508 @lilypond[verbatim,quote,relative=1]
1509 c-\tweak #'thickness #5 ( d e f)
1510 @end lilypond
1511
1512 Also several @code{\tweak} commands may be placed before a
1513 notational element -- all affect it:
1514
1515 @lilypond[verbatim,quote,relative=1]
1516 c
1517 -\tweak #'style #'dashed-line
1518 -\tweak #'dash-fraction #0.2
1519 -\tweak #'thickness #3
1520 -\tweak #'color #red
1521  \glissando
1522 f'
1523 @end lilypond
1524
1525 The music stream which is generated from a section of an input file,
1526 including any automatically inserted elements, may be examined,
1527 see @ref{Displaying music expressions}.  This may be helpful in
1528 determining what may be modified by a @code{\tweak} command.
1529
1530 @seealso
1531
1532 Learning Manual:
1533 @rlearning{Tweaking methods}.
1534
1535 Notation Reference:
1536 @ref{Displaying music expressions}.
1537
1538 @knownissues
1539
1540 @cindex tweaks in a variable
1541 The @code{\tweak} command cannot be used inside a variable.
1542
1543 @cindex tweaks in lyrics
1544 The @code{\tweak} commands cannot be used in @code{\lyricmode}.
1545
1546 @cindex tweaking control points
1547 @cindex control points, tweaking
1548
1549 The @code{\tweak} command cannot be used to modify the control
1550 points of just one of several ties in a chord, other than the first
1551 one encountered in the input file.
1552
1553 @node set versus override
1554 @subsection @code{\set} vs. @code{\override}
1555
1556 We have seen two methods of changing properties: @code{\set} and
1557 @code{\override}.  There are actually two different kinds of
1558 properties.
1559
1560 Contexts can have properties, which are usually named in
1561 @code{studlyCaps}.  They mostly control the translation from
1562 music to notation, eg. @code{localKeySignature} (for determining
1563 whether to print accidentals), @code{measurePosition} (for
1564 determining when to print a bar line).  Context properties can
1565 change value over time while interpreting a piece of music;
1566 @code{measurePosition} is an obvious example of
1567 this.  Context properties are modified with @code{\set}.
1568
1569 There is a special type of context property: the element
1570 description.  These properties are named in @code{StudlyCaps}
1571 (starting with capital letters).  They contain the
1572 @q{default settings} for said graphical object as an
1573 association list.  See @file{scm/@/define@/-grobs@/.scm}
1574 to see what kind of settings there are.  Element descriptions
1575 may be modified with @code{\override}.
1576
1577 @code{\override} is actually a shorthand;
1578
1579 @example
1580 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1581 @end example
1582
1583 @noindent
1584 is more or less equivalent to
1585
1586 @c  leave this long line -gp
1587 @example
1588 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1589 @end example
1590
1591 The value of @code{context} (the alist) is used to initialize
1592 the properties of individual grobs.  Grobs also have
1593 properties, named in Scheme style, with
1594 @code{dashed-words}.  The values of grob properties change
1595 during the formatting process: formatting basically amounts
1596 to computing properties using callback functions.
1597
1598 @code{fontSize} is a special property: it is equivalent to
1599 entering @code{\override ... #'font-size} for all pertinent
1600 objects.  Since this is a common change, the special
1601 property (modified with @code{\set}) was created.
1602
1603
1604 @node Useful concepts and properties
1605 @section Useful concepts and properties
1606
1607
1608 @menu
1609 * Input modes::
1610 * Direction and placement::
1611 * Distances and measurements::
1612 * Spanners::
1613 @end menu
1614
1615 @node Input modes
1616 @subsection Input modes
1617
1618 The way in which the notation contained within an input file is
1619 interpreted is determined by the current input mode.
1620
1621 @strong{Chord mode}
1622
1623 This is activated with the @code{\chordmode} command, and causes
1624 input to be interpreted with the syntax of chord notation, see
1625 @ref{Chord notation}.  Chords are rendered as notes on a staff.
1626
1627 Chord mode is also activated with the @code{\chords} command.
1628 This also creates a new @code{ChordNames} context and
1629 causes the following input to be interpreted with the syntax of
1630 chord notation and rendered as chord names in the @code{ChordNames}
1631 context, see @ref{Printing chord names}.
1632
1633 @strong{Drum mode}
1634
1635 This is activated with the @code{\drummode} command, and causes
1636 input to be interpreted with the syntax of drum notation, see
1637 @ref{Basic percussion notation}.
1638
1639 Drum mode is also activated with the @code{\drums} command.
1640 This also creates a new @code{DrumStaff} context and causes the
1641 following input to be interpreted with the syntax of drum notation
1642 and rendered as drum symbols on a drum staff, see @ref{Basic
1643 percussion notation}.
1644
1645 @strong{Figure mode}
1646
1647 This is activated with the @code{\figuremode} command, and causes
1648 input to be interpreted with the syntax of figured bass, see
1649 @ref{Entering figured bass}.
1650
1651 Figure mode is also activated with the @code{\figures} command.
1652 This also creates a new @code{FiguredBass} context and causes the
1653 following input to be interpreted with the figured bass syntax
1654 and rendered as figured bass symbols in the @code{FiguredBass}
1655 context, see @ref{Introduction to figured bass}.
1656
1657 @strong{Fret and tab modes}
1658
1659 There are no special input modes for entering fret and tab symbols.
1660
1661 To create tab diagrams, enter notes or chords in note mode and
1662 render them in a @code{TabStaff} context, see
1663 @ref{Default tablatures}.
1664
1665 To create fret diagrams above a staff, you have two choices.
1666 You can either use the @code{FretBoards} context (see
1667 @ref{Automatic fret diagrams} or you can enter them as a markup
1668 above the notes using the @code{\fret-diagram} command (see
1669 @ref{Fret diagram markups}).
1670
1671 @strong{Lyrics mode}
1672
1673 This is activated with the @code{\lyricmode} command, and causes
1674 input to be interpreted as lyric syllables with optional durations
1675 and associated lyric modifiers, see @ref{Vocal music}.
1676
1677 Lyric mode is also activated with the @code{\addlyrics} command.
1678 This also creates a new @code{Lyrics} context and an implicit
1679 @code{\lyricsto} command which associates the following lyrics
1680 with the preceding music.
1681
1682 @strong{Markup mode}
1683
1684 This is activated with the @code{\markup} command, and causes
1685 input to be interpreted with the syntax of markup, see
1686 @ref{Text markup commands}.
1687
1688 @c silly work-around for texinfo broken-ness
1689 @c (@strong{Note...} causes a spurious cross-reference in Info)
1690 @b{Note mode}
1691
1692 This is the default mode or it may be activated with the
1693 @code{\notemode} command.  Input is interpreted as pitches,
1694 durations, markup, etc and typeset as musical notation on a staff.
1695
1696 It is not normally necessary to specify note mode explicitly, but
1697 it may be useful to do so in certain situations, for example if you
1698 are in lyric mode, chord mode or any other mode and want to insert
1699 something that only can be done with note mode syntax.
1700
1701 For example, to indicate dynamic markings for the verses of a
1702 choral pieces it is necessary to enter note mode to interpret
1703 the markings:
1704
1705 @lilypond[verbatim,relative=2,quote]
1706 { c4 c4 c4 c4 }
1707 \addlyrics {
1708   \notemode{\set stanza = \markup{ \dynamic f 1. } }
1709   To be sung loudly
1710 }
1711 \addlyrics {
1712   \notemode{\set stanza = \markup{ \dynamic p 2. } }
1713   To be sung quietly
1714 }
1715 @end lilypond
1716
1717
1718
1719 @node Direction and placement
1720 @subsection Direction and placement
1721
1722 In typesetting music the direction and placement of many items is
1723 a matter of choice.  For example, the stems of notes can
1724 be directed up or down; lyrics, dynamics, and other expressive
1725 marks may be placed above or below the staff; text may be aligned
1726 left, right or center; etc.  Most of these choices may be left to
1727 be determined automatically by LilyPond, but in some cases it may
1728 be desirable to force a particular direction or placement.
1729
1730 @strong{Default actions}
1731
1732 By default some directions are always up or always down (e.g.
1733 dynamics or fermata), while other things can alternate between
1734 up or down based on the stem direction (like slurs or accents).
1735
1736 @c TODO Add table showing these
1737
1738 @strong{Context layout}
1739
1740 Contexts are positioned in a system from top to bottom in the
1741 order in which they are encountered.  Note, however, that a
1742 context will be created implicitly if a command is encountered
1743 when there is no suitable context available to contain it.
1744
1745 @c TODO Add example ?
1746
1747 The default order in which contexts are laid out can be changed,
1748 see @ref{Aligning contexts}
1749
1750 @strong{Articulation direction indicators}
1751
1752 When adding articulations to notes the direction indicator,
1753 @code{^} (meaning @qq{up}), @code{_} (meaning @qq{down}) or
1754 @code{-} (meaning @qq{use default direction}), can usually be
1755 omitted, in which case @code{-} is assumed.  But a direction
1756 indicator is @strong{always} required before
1757
1758 @itemize
1759 @item @code{\tweak} commands
1760 @item @code{\markup} commands
1761 @item @code{\tag} commands
1762 @item string markups, e.g. -"string"
1763 @item fingering instructions, e.g. @code{-1}
1764 @item articulation shortcuts, e.g. @code{-.}, @code{->}, @code{--}
1765 @end itemize
1766
1767 @strong{The direction property}
1768
1769 The position or direction of many layout objects is controlled
1770 by the @code{direction} property.
1771
1772 The value of the @code{direction} property may be
1773 set to @code{1}, meaning @qq{up} or @qq{above}, or to @code{-1},
1774 meaning @qq{down} or @qq{below}.  The symbols @code{UP} and
1775 @code{DOWN} may be used instead of @code{1} and @code{-1}
1776 respectively.  The default direction may be specified by setting
1777 @code{direction} to @code{0} or @code{CENTER}.  Alternatively,
1778 in many cases predefined commands
1779 exist to specify the direction.  These are all of the form
1780
1781 @noindent
1782 @code{\xxxUp}, @code{xxxDown}, @code{xxxNeutral}
1783
1784 @noindent
1785 where @code{xxxNeutral} means @qq{use the default direction}.
1786 See @rlearning{Within-staff objects}.
1787
1788 In a few cases, arpeggio being the only common example, the value
1789 of the @code{direction} property specifies whether the object
1790 is to be placed to the right or left of the parent object.  In
1791 this case @code{-1} or @code{LEFT} means @qq{to the left} and
1792 @code{1} or @code{RIGHT} means @qq{to the right}.  @code{0}
1793 or @code{CENTER} means @qq{use the default} direction, as before.
1794
1795 @ignore
1796 These all have side-axis set to #X
1797 AmbitusAccidental - direction has no effect
1798 Arpeggio - works
1799 StanzaNumber - not tried
1800 TrillPitchAccidental - not tried
1801 TrillPitchGroup - not tried
1802 @end ignore
1803
1804
1805
1806 @node Distances and measurements
1807 @subsection Distances and measurements
1808
1809 DISCUSS after working on other sections.
1810
1811 TODO: staff spaces.  Maybe move into tweaks?
1812
1813
1814 @node Spanners
1815 @subsection Spanners
1816
1817 Many objects of musical notation extend over several notes or even
1818 several bars.  Examples are crescendi, trills, tuplet brackets, and
1819 volta repeat brackets.  Such objects are called @qq{spanners}, and
1820 have special properties to control their appearance and behaviour.
1821 Some of these properties are common to all spanners; others are
1822 restricted to a sub-set of the spanners.
1823
1824 @node Common properties
1825 @section Common properties
1826
1827 @menu
1828 * Controlling visibility of objects::  
1829 * Line styles::                 
1830 * Rotating objects::            
1831 * Aligning objects::            
1832 @end menu
1833
1834 @node Controlling visibility of objects
1835 @subsection Controlling visibility of objects
1836
1837 @cindex objects, visibility of
1838 @cindex grobs, visibility of
1839 @cindex visibility of objects
1840
1841 There are four main ways in which the visibility of layout objects
1842 can be controlled: their stencil can be removed, they can be made
1843 transparent, they can be colored white, or their
1844 @code{break-visibility} property can be overridden.  The first
1845 three apply to all layout objects; the last to just a few -- the
1846 @emph{breakable} objects.  The Learning Manual introduces these
1847 four techniques, see @rlearning{Visibility and color of objects}.
1848
1849 There are also a few other techniques which are specific to
1850 certain layout objects.  These are covered under Special
1851 considerations.
1852
1853 @menu
1854 * Removing the stencil::        
1855 * Making objects transparent::  
1856 * Painting objects white::      
1857 * Using break-visibility::      
1858 * Special considerations::      
1859 @end menu
1860
1861
1862 @node Removing the stencil
1863 @unnumberedsubsubsec Removing the stencil
1864
1865 @cindex stencil, removing
1866
1867 Every layout object has a stencil property.  By default this is set
1868 to the specific function which draws that object.  If this property
1869 is overridden to @code{#f} no function will be called and the object
1870 will not be drawn.  The default action can be recovered with
1871 @code{\revert}.
1872
1873 @lilypond[quote,verbatim,relative=1]
1874 a1 a
1875 \override Score.BarLine #'stencil = ##f
1876 a a
1877 \revert Score.BarLine #'stencil
1878 a a a
1879 @end lilypond
1880
1881 @node Making objects transparent
1882 @unnumberedsubsubsec Making objects transparent
1883
1884 @cindex transparent, making objects
1885
1886 Every layout object has a transparent property which by default is
1887 set to @code{#f}.  If set to @code{#t} the object still occupies
1888 space but is made invisible.
1889
1890 @lilypond[quote,verbatim,relative=2]
1891 a4 a
1892 \once \override NoteHead #'transparent = ##t
1893 a a
1894 @end lilypond
1895
1896 @node Painting objects white
1897 @unnumberedsubsubsec Painting objects white
1898
1899 @cindex objects, coloring
1900 @cindex coloring objects
1901 @cindex layers
1902 @cindex printing order
1903 @cindex overwriting objects
1904 @cindex objects, overwriting
1905 @cindex grobs, overwriting
1906
1907 Every layout object has a color property which by default is set
1908 to @code{black}.  If this is overridden to @code{white} the object
1909 will be indistinguishable from the white background.  However,
1910 if the object crosses other objects the color of the crossing
1911 points will be determined by the order in which they are drawn,
1912 and this may leave a ghostly image of the white object, as shown
1913 here:
1914
1915 @lilypond[quote,verbatim,relative=2]
1916 \override Staff.Clef #'color = #white
1917 a1
1918 @end lilypond
1919
1920 This may be avoided by changing the order of printing the objects.
1921 All layout objects have a @code{layer} property which should be set
1922 to an integer.  Objects with the lowest value of @code{layer} are
1923 drawn first, then objects with progressively higher values are drawn,
1924 so objects with higher values overwrite objects with lower values.
1925 By default most objects are assigned a @code{layer} value of
1926 @code{1}, although a few objects, including @code{StaffSymbol} and
1927 @code{BarLine}, are assigned a value of @code{0}.  The order of
1928 printing objects with the same value of @code{layer} is indeterminate.
1929
1930 In the example above the white clef, with a default @code{layer}
1931 value of @code{1}, is drawn after the staff lines (default
1932 @code{layer} value @code{0}), so overwriting them.  To change this,
1933 the @code{Clef} object must be given in a lower value of
1934 @code{layer}, say @code{-1}, so that it is drawn earlier:
1935
1936 @lilypond[quote,verbatim,relative=2]
1937 \override Staff.Clef #'color = #white
1938 \override Staff.Clef #'layer = #-1
1939 a1
1940 @end lilypond
1941
1942 @node Using break-visibility
1943 @unnumberedsubsubsec Using break-visibility
1944
1945 @c TODO Add making other objects breakable
1946
1947 @cindex break-visibility
1948
1949 Most layout objects are printed only once, but some like
1950 bar lines, clefs, time signatures and key signatures, may need
1951 to be printed twice when a line break occurs -- once at the end
1952 of the line and again at the start of the next line.  Such
1953 objects are called @emph{breakable}, and have a property, the
1954 @code{break-visibility} property to control their visibility
1955 at the three positions in which they may appear -- at the
1956 start of a line, within a line if they are changed, and at the
1957 end of a line if a change takes place there.
1958
1959 For example, the time signature
1960 by default will be printed at the start of the first line, but
1961 nowhere else unless it changes, when it will be printed at the
1962 point at which the change occurs.  If this change occurs at the
1963 end of a line the new time signature will be printed at the start
1964 of the next line and a cautionary time signature will be printed
1965 at the end of the previous line as well.
1966
1967 This behaviour is controlled by the @code{break-visibility}
1968 property, which is explained in
1969 @c Leave this ref on a newline - formats incorrectly otherwise -td
1970 @rlearning{Visibility and color of objects}.  This property takes
1971 a vector of three booleans which, in order, determine whether the
1972 object is printed at the end of, within the body of, or at the
1973 beginning of a line.  Or to be more precise, before a line break,
1974 where there is no line break, or after a line break.
1975
1976 Alternatively, seven of the eight combinations may be specified
1977 by pre-defined functions, defined in @file{scm/output-lib.scm},
1978 where the last three columns indicate whether the layout objects
1979 will be visible in the positions shown at the head of the columns:
1980
1981 @multitable @columnfractions .40 .15 .1 .1 .1
1982 @c TODO check these more carefully
1983 @headitem Function                   @tab Vector                  @tab Before @tab At no    @tab After
1984 @headitem form                       @tab form                    @tab break  @tab break    @tab break
1985
1986 @item @code{all-invisible}           @tab @code{'#(#f #f #f)} @ @ @tab no     @tab no       @tab no
1987 @item @code{begin-of-line-visible}   @tab @code{'#(#f #f #t)}     @tab no     @tab no       @tab yes
1988 @item @code{end-of-line-visible}     @tab @code{'#(#t #f #f)}     @tab yes    @tab no       @tab no
1989 @item @code{all-visible}             @tab @code{'#(#t #t #t)}     @tab yes    @tab yes      @tab yes
1990 @c The center-visible function is not defined
1991 @c @item @code{center-visible}       @tab @code{'#(#f #t #f)}     @tab no     @tab yes      @tab no
1992 @item @code{begin-of-line-invisible} @tab @code{'#(#t #t #f)}     @tab yes    @tab yes      @tab no
1993 @item @code{end-of-line-invisible}   @tab @code{'#(#f #t #t)}     @tab no     @tab yes      @tab yes
1994 @item @code{center-invisible}        @tab @code{'#(#t #f #t)}     @tab yes    @tab no       @tab yes
1995 @end multitable
1996
1997 The @code{center-visible} function is not pre-defined.
1998
1999 The default settings of @code{break-visibility} depend on the
2000 layout object.  The following table shows all the layout objects
2001 of interest which are affected by @code{break-visibility} and the
2002 default setting of this property:
2003
2004 @multitable @columnfractions .3 .3 .4
2005
2006 @headitem Layout object   @tab Usual context  @tab Default setting
2007
2008 @c omit Ambitus as it appears not to be affected by break-visibility -td
2009 @c @item @code{Ambitus}          @tab as specified   @tab @code{begin-of-line-visible}
2010 @item @code{BarLine}             @tab @code{Score}          @tab calculated
2011 @item @code{BarNumber}           @tab @code{Score}          @tab @code{begin-of-line-visible}
2012 @c omit the following item until it can be explained -td
2013 @c @item @code{BreakAlignGroup}  @tab @code{Score}          @tab calculated
2014 @item @code{BreathingSign}       @tab @code{Voice}          @tab @code{begin-of-line-invisible}
2015 @item @code{Clef}                @tab @code{Staff}          @tab @code{begin-of-line-visible}
2016 @item @code{Custos}              @tab @code{Staff}          @tab @code{end-of-line-visible}
2017 @item @code{DoublePercentRepeat} @tab @code{Voice}          @tab @code{begin-of-line-invisible}
2018 @c omit KeyCancellation until it can be explained -td
2019 @c @item @code{KeyCancellation}  @tab ??             @tab @code{begin-of-line-invisible}
2020 @item @code{KeySignature}        @tab @code{Staff}          @tab @code{begin-of-line-visible}
2021 @c omit LeftEdge until it can be explained -td
2022 @c @item @code{LeftEdge}         @tab @code{Score}          @tab @code{center-invisible}
2023 @item @code{OctavateEight}       @tab @code{Staff}          @tab @code{begin-of-line-visible}
2024 @item @code{RehearsalMark}       @tab @code{Score}          @tab @code{end-of-line-invisible}
2025 @item @code{TimeSignature}       @tab @code{Staff}          @tab @code{all-visible}
2026
2027 @end multitable
2028
2029 The example below shows the use of the vector form to control the
2030 visibility of barlines:
2031
2032 @lilypond[quote,verbatim,relative=1,ragged-right]
2033 f4 g a b
2034 f4 g a b
2035 % Remove bar line at the end of the current line
2036 \once \override Score.BarLine #'break-visibility = #'#(#f #t #t)
2037 \break
2038 f4 g a b
2039 f4 g a b
2040 @end lilypond
2041
2042 Although all three components of the vector used to override
2043 @code{break-visibility} must be present, not all of them are
2044 effective with every layout object, and some combinations may
2045 even give errors.  The following limitations apply:
2046
2047 @itemize @bullet
2048 @item Bar lines cannot be printed at start of line.
2049 @item A bar number cannot be printed at the start of the first
2050 line unless it is set to be different from 1.
2051 @item Clef -- see below
2052 @item Double percent repeats are either all printed or all
2053 suppressed.  Use begin-of line-invisible to print and
2054 all-invisible to suppress.
2055 @item Key signature -- see below
2056 @item OctavateEight -- see below
2057 @end itemize
2058
2059 @node Special considerations
2060 @unnumberedsubsubsec Special considerations
2061
2062 @strong{@emph{Visibility following explicit changes}}
2063
2064 @cindex key signature, visibility following explicit change
2065 @cindex explicitKeySignatureVisibility
2066 @cindex clef, visibility following explicit change
2067 @cindex explicitClefVisibility
2068
2069 The @code{break-visibility} property controls the visibility of
2070 key signatures and changes of clef only at the start of lines,
2071 i.e. after a break.  It has no effect on the visibility of the
2072 key signature or clef following an explicit key change or an
2073 explicit clef change within or at the end of a line.  In the
2074 following example the key signature following the explicit change
2075 to B-flat major is still visible, even though @code{all-invisible}
2076 is set.
2077
2078 @lilypond[quote,verbatim,relative=1,ragged-right]
2079 \key g \major
2080 f4 g a b
2081 % Try to remove all key signatures
2082 \override Staff.KeySignature #'break-visibility = #all-invisible
2083 \key bes \major
2084 f4 g a b
2085 \break
2086 f4 g a b
2087 f4 g a b
2088 @end lilypond
2089
2090 The visibility of such explicit key signature and clef changes is
2091 controlled by the @code{explicitKeySignatureVisibility} and
2092 @code{explicitClefVisibility} properties.  These are the equivalent
2093 of the @code{break-visibility} property and both take a vector of
2094 three booleans or the predefined functions listed above, exactly like
2095 @code{break-visibility}.  Both are properties of the Staff context,
2096 not the layout objects themselves, and so they are set using the
2097 @code{\set} command.  Both are set by default to @code{all-visible}.
2098 These properties control only the visibility of key signatures and
2099 clefs resulting from explicit changes and do not affect key
2100 signatures and clefs at the beginning of lines;
2101 @code{break-visibility} must still be overridden in the appropriate
2102 object to remove these.
2103
2104 @lilypond[quote,verbatim,relative=1,ragged-right]
2105 \key g \major
2106 f4 g a b
2107 \set Staff.explicitKeySignatureVisibility = #all-invisible
2108 \override Staff.KeySignature #'break-visibility = #all-invisible
2109 \key bes \major
2110 f4 g a b \break
2111 f4 g a b
2112 f4 g a b
2113 @end lilypond
2114
2115 @strong{@emph{Visibility of cautionary accidentals}}
2116
2117 To remove the cautionary accidentals printed at an explicit key
2118 change, set the Staff context property @code{printKeyCancellation}
2119 to @code{#f}:
2120
2121 @lilypond[quote,verbatim,relative=1,ragged-right]
2122 \key g \major
2123 f4 g a b
2124 \set Staff.explicitKeySignatureVisibility = #all-invisible
2125 \set Staff.printKeyCancellation = ##f
2126 \override Staff.KeySignature #'break-visibility = #all-invisible
2127 \key bes \major
2128 f4 g a b \break
2129 f4 g a b
2130 f4 g a b
2131 @end lilypond
2132
2133 With these overrides only the accidentals before the notes remain
2134 to indicate the change of key.
2135
2136 @c TODO Add visibility of cautionary accidentals before notes
2137
2138 @strong{@emph{Automatic bars}}
2139
2140 @cindex automaticBars
2141 @cindex bar lines, suppressing
2142
2143 As a special case, the printing of bar lines can also be turned off
2144 by setting the @code{automaticBars} property in the Score context.
2145 If set to @code{#f}, bar lines will not be printed automatically;
2146 they must be explicitly created with a @code{\bar} command.  Unlike
2147 the @code{\cadenzaOn} predefined command, measures are still counted.
2148 Bar generation will resume according to that count if this property
2149 is later set to @code{#t}.  When set to @code{#f}, line breaks can
2150 occur only at explicit @code{\bar} commands.
2151
2152 @c TODO Add example
2153
2154 @strong{@emph{Octavated clefs}}
2155
2156 @cindex octavated clefs, visibility of
2157 @cindex visibility of octavated clefs
2158 @cindex clefs, visibility of octavation
2159
2160 The small octavation symbol on octavated clefs is produced by the
2161 @code{OctavateEight} layout object.  Its visibility is controlled
2162 independently from that of the @code{Clef} object, so it is
2163 necessary to apply any required @code{break-visibility} overrides
2164 to both the @code{Clef} and the @code{OctavateEight} layout objects
2165 to fully suppress such clef symbols at the start of each line.
2166
2167 For explicit clef changes, the @code{explicitClefVisibility}
2168 property controls both the clef symbol and any octavation symbol
2169 associated with it.
2170
2171
2172 @seealso
2173 Learning Manual:
2174 @rlearning{Visibility and color of objects}
2175
2176
2177 @node Line styles
2178 @subsection Line styles
2179
2180 @c TODO: split the following explanations between expressive marks and
2181 @c text-related stuff. Perhaps create a new subsection named
2182 @c "Spanner limits", "Spanner boundaries"? -vv
2183
2184 Some performance indications, e.g., @i{rallentando} and
2185 @i{accelerando} and @i{trills} are written as text and are
2186 extended over many measures with lines, sometimes dotted or wavy.
2187
2188 These all use the same routines as the glissando for drawing the
2189 texts and the lines, and tuning their behavior is therefore also
2190 done in the same way.  It is done with a spanner, and the routine
2191 responsible for drawing the spanners is
2192 @code{ly:line-interface::print}.  This routine determines the
2193 exact location of the two @i{span points} and draws a line in
2194 between, in the style requested.
2195
2196 Here is an example of the different line styles available, and how
2197 to tune them.
2198
2199 @lilypond[relative=2,ragged-right,verbatim,fragment]
2200 d2 \glissando d'2
2201 \once \override Glissando #'style = #'dashed-line
2202 d,2 \glissando d'2
2203 \override Glissando #'style = #'dotted-line
2204 d,2 \glissando d'2
2205 \override Glissando #'style = #'zigzag
2206 d,2 \glissando d'2
2207 \override Glissando #'style = #'trill
2208 d,2 \glissando d'2
2209 @end lilypond
2210
2211 The information that determines the end-points is computed
2212 on-the-fly for every graphic object, but it is possible to
2213 override these.
2214
2215 @lilypond[relative=2,ragged-right,verbatim,fragment]
2216 e2 \glissando f
2217 \once \override Glissando #'bound-details #'right #'Y = #-2
2218 e2 \glissando f
2219 @end lilypond
2220
2221 The @code{Glissando} object, like any other using the
2222 @code{ly:line-interface::print} routine, carries a nested
2223 association list.  In the above statement, the value for @code{Y}
2224 is set to @code{-2} for the association list corresponding to the
2225 right end point.  Of course, it is also possible to adjust the
2226 left side with @code{left} instead of @code{right}.
2227
2228 If @code{Y} is not set, the value is computed from the vertical
2229 position of right attachment point of the spanner.
2230
2231 In case of a line break, the values for the span-points are
2232 extended with contents of the @code{left-broken} and
2233 @code{right-broken} sublists, for example
2234
2235 @lilypond[relative=2,ragged-right,verbatim,fragment]
2236 \override Glissando #'breakable = ##T
2237 \override Glissando #'bound-details #'right-broken #'Y = #-3
2238 c1 \glissando \break
2239 f1
2240 @end lilypond
2241
2242 The following properties can be used for the
2243
2244 @table @code
2245 @item Y
2246 This sets the Y-coordinate of the end point, in staff space.  By
2247 default, it is the center of the bound object, so for a glissando
2248 it points to the vertical center of the note head.
2249
2250 For horizontal spanners, such as text spanner and trill spanners,
2251 it is hardcoded to 0.
2252
2253 @item attach-dir
2254 This determines where the line starts and ends in X-direction,
2255 relative to the bound object.  So, a value of @code{-1} (or
2256 @code{LEFT}) makes the line start/end at the left side of the note
2257 head it is attached to.
2258
2259 @item X
2260 This is the absolute coordinate of the end point.  It is usually
2261 computed on the fly, and there is little use in overriding it.
2262
2263 @item stencil
2264 Line spanners may have symbols at the beginning or end, which is
2265 contained in this sub-property.  This is for internal use, it is
2266 recommended to use @code{text}.
2267
2268 @item text
2269 This is a markup that is evaluated to yield stencil.  It is used
2270 to put @i{cresc.} and @i{tr} on horizontal spanners.
2271
2272 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
2273 \override TextSpanner #'bound-details #'left #'text
2274    = \markup { \small \bold Slower }
2275 c2\startTextSpan b c a\stopTextSpan
2276 @end lilypond
2277
2278 @item stencil-align-dir-y
2279 @item stencil-offset
2280 Without setting this, the stencil is simply put there at the
2281 end-point, as defined by the @code{X} and @code{Y} sub properties.
2282 Setting either @code{stencil-align-dir-y} or @code{stencil-offset}
2283 will move the symbol at the edge relative to the end point of the
2284 line
2285
2286 @lilypond[relative=1,fragment,verbatim]
2287 \override TextSpanner #'bound-details
2288   #'left #'stencil-align-dir-y = #DOWN
2289 \override TextSpanner #'bound-details
2290   #'right #'stencil-align-dir-y = #UP
2291
2292 \override TextSpanner #'bound-details
2293   #'left #'text = #"gggg"
2294 \override TextSpanner #'bound-details
2295   #'right #'text = #"hhhh"
2296 c4^\startTextSpan c c c \stopTextSpan
2297 @end lilypond
2298
2299 @item arrow
2300 Setting this sub property to @code{#t} produce an arrowhead at the
2301 end of the line.
2302
2303 @item padding
2304 This sub property controls the space between the specified
2305 end-point of the line and the actual end.  Without padding, a
2306 glissando would start and end in the center of each note head.
2307
2308 @end table
2309
2310 @c TODO: Move to 5.4.4
2311
2312 The music function \endSpanners terminates spanners and hairpins
2313 after exactly one note.
2314
2315 @lilypond[verbatim,quote,ragged-right,relative=2,fragment]
2316 \endSpanners
2317 c2 \startTextSpan c2
2318 c2 \< c2
2319 @end lilypond
2320
2321 When using \endSpanners it is not necessary to close
2322 \startTextSpan with \stopTextSpan, nor is it necessary to close
2323 hairpins with \!.
2324
2325
2326
2327 @seealso
2328
2329 Internals Reference: @rinternals{TextSpanner},
2330 @rinternals{Glissando}, @rinternals{VoiceFollower},
2331 @rinternals{TrillSpanner},
2332 @rinternals{line-spanner-interface}.
2333
2334
2335 @node Rotating objects
2336 @subsection Rotating objects
2337
2338 Both layout objects and elements of markup text can be rotated by
2339 any angle about any point, but the method of doing so differs.
2340
2341 @menu
2342 * Rotating layout objects::     
2343 * Rotating markup::             
2344 @end menu
2345
2346 @node Rotating layout objects
2347 @unnumberedsubsubsec Rotating layout objects
2348
2349 @cindex rotating objects
2350 @cindex objects, rotating
2351
2352 All layout objects which support the @code{grob-interface} can be
2353 rotated by setting their @code{rotation} property.  This takes a
2354 list of three items: the angle of rotation counter-clockwise,
2355 and the x and y coordinates of the point relative to the object's
2356 reference point about which the rotation is to be performed.  The
2357 angle of rotation is specified in degrees and the coordinates in
2358 staff-spaces.
2359
2360 The angle of rotation and the coordinates of the rotation point must
2361 be determined by trial and error.
2362
2363 @cindex hairpins, angled
2364 @cindex angled hairpins
2365
2366 There are only a few situations where the rotation of layout
2367 objects is useful; the following example shows one situation where
2368 they may be:
2369
2370 @lilypond[quote,verbatim,relative=1]
2371 g4\< e' d' f\!
2372 \override Hairpin #'rotation = #'(20 -1 0)
2373 g,,4\< e' d' f\!
2374 @end lilypond
2375
2376 @node Rotating markup
2377 @unnumberedsubsubsec Rotating markup
2378
2379 All markup text can be rotated to lie at any angle by prefixing it
2380 with the @code{\rotate} command.  The command takes two arguments:
2381 the angle of rotation in degrees counter-clockwise and the text to
2382 be rotated.  The extents of the text are not rotated: they take
2383 their values from the extremes of the x and y coordinates of the
2384 rotated text.  In the following example the
2385 @code{outside-staff-priority} property for text is set to @code{#f}
2386 to disable the automatic collision avoidance, which would push some
2387 of the text too high.
2388
2389 @lilypond[quote,verbatim,relative=1]
2390 \override TextScript #'outside-staff-priority = ##f
2391 g4^\markup { \rotate #30 "a G" }
2392 b^\markup { \rotate #30 "a B" }
2393 des^\markup { \rotate #30 "a D-Flat" }
2394 fis^\markup { \rotate #30 "an F-Sharp" }
2395 @end lilypond
2396
2397
2398 @node Aligning objects
2399 @subsection Aligning objects
2400
2401 @c FIXME Write this section
2402
2403
2404 @node Advanced tweaks
2405 @section Advanced tweaks
2406
2407 @menu
2408 * Vertical grouping of grobs::  
2409 * Modifying ends of spanners::  
2410 * Modifying stencils::          
2411 * Modifying shapes::            
2412 @end menu
2413
2414
2415
2416
2417 @node Vertical grouping of grobs
2418 @subsection Vertical grouping of grobs
2419
2420 @c FIXME Expand this section
2421
2422 The VerticalAlignment and VerticalAxisGroup grobs work together.
2423 VerticalAxisGroup groups together different grobs like Staff, Lyrics,
2424 etc.  VerticalAlignment then vertically aligns the different grobs
2425 grouped together by VerticalAxisGroup.  There is usually only one
2426 VerticalAlignment per score but every Staff, Lyrics, etc. has its own
2427 VerticalAxisGroup.
2428
2429
2430 @node Modifying ends of spanners
2431 @subsection Modifying ends of spanners
2432
2433 @c FIXME Write this section
2434 @c See earlier material in Line styles
2435
2436 @node Modifying stencils
2437 @subsection Modifying stencils
2438
2439 All layout objects have a @code{stencil} property which is part of
2440 the @code{grob-interface}.  By default, this property is usually
2441 set to a function specific to the object that is tailor-made to
2442 render the symbol which represents it in the output.  For example,
2443 the standard setting for the @code{stencil} property of the
2444 @code{MultiMeasureRest} object is @code{ly:multi-measure-rest::print}.
2445
2446 The standard symbol for any object can be replaced by modifying the
2447 @code{stencil} property to reference a different, specially-written,
2448 procedure.  This requires a high level of knowledge of the internal
2449 workings of LilyPond, but there is an easier way which can often
2450 produce adequate results.
2451
2452 This is to set the @code{stencil} property to the procedure which
2453 prints text -- @code{ly:text-interface::print} -- and to add a
2454 @code{text} property to the object which is set to contain the
2455 markup text which produces the required symbol.  Due to the
2456 flexibility of markup, much can be achieved -- see in particular
2457 @ref{Graphic notation inside markup}.
2458
2459 The following example demonstrates this by changing the note head
2460 symbol to a cross within a circle.
2461
2462 @lilypond[verbatim,quote]
2463 XinO = {
2464   \once \override NoteHead  #'stencil = #ly:text-interface::print
2465   \once \override NoteHead #'text = \markup {
2466     \combine
2467       \halign #-0.7 \draw-circle #0.85 #0.2 ##f
2468       \musicglyph #"noteheads.s2cross"
2469   }
2470 }
2471 \relative c'' {
2472   a a \XinO a a
2473 }
2474 @end lilypond
2475
2476 Any of the glyphs in the feta Font can be supplied to the
2477 @code{\musicglyph} markup command -- see @ref{The Feta font}.
2478
2479 @c TODO Add inserting eps files or ref to later
2480
2481 @c TODO Add inserting Postscript or ref to later
2482
2483 @seealso
2484
2485 Notation Reference:
2486 @ref{Graphic notation inside markup},
2487 @ref{Formatting text},
2488 @ref{Text markup commands},
2489 @ref{The Feta font}.
2490
2491
2492 @node Modifying shapes
2493 @subsection Modifying shapes
2494
2495 @menu
2496 * Modifying ties and slurs::
2497 @end menu
2498
2499 @node Modifying ties and slurs
2500 @unnumberedsubsubsec Modifying ties and slurs
2501
2502 Ties, slurs and phrasing slurs are drawn as third-order Bézier
2503 curves.  If the shape of the tie or slur which is calculated
2504 automatically is not optimum, the shape may be modified manually by
2505 explicitly specifying the four control points required to define
2506 a third-order Bézier curve.
2507
2508 Third-order or cubic Bézier curves are defined by four control
2509 points.  The first and fourth control points are precisely the
2510 starting and ending points of the curve.  The intermediate two
2511 control points define the shape.  Animations showing how the curve
2512 is drawn can be found on the web, but the following description
2513 may be helpful.  The curve starts from the first control point
2514 heading directly towards the second, gradually bending over to
2515 head towards the third and continuing to bend over to head towards
2516 the fourth, arriving there travelling directly from the third
2517 control point.  The curve is entirely contained in the
2518 quadrilateral defined by the four control points.
2519
2520 Here is an example of a case where the tie is not optimum, and
2521 where @code{\tieDown} would not help.
2522
2523 @lilypond[verbatim,quote,relative=1]
2524 <<
2525   { e1 ~ e }
2526 \\
2527   { r4 <g c,> <g c,> <g c,> }
2528 >>
2529 @end lilypond
2530
2531 One way of improving this tie is to manually modify its control
2532 points, as follows.
2533
2534 The coordinates of the Bézier control points are specified in units
2535 of staff-spaces.  The X@tie{}coordinate is relative to the reference
2536 point of the note to which the tie or slur is attached, and the
2537 Y@tie{}coordinate is relative to the staff center line.  The
2538 coordinates are entered as a list of four pairs of decimal numbers
2539 (reals).  One approach is to estimate the coordinates of the two
2540 end points, and then guess the two intermediate points.  The optimum
2541 values are then found by trial and error.
2542
2543 It is useful to remember that a symmetric curve requires symmetric
2544 control points, and that Bézier curves have the useful property that
2545 transformations of the curve such as translation, rotation and
2546 scaling can be achieved by applying the same transformation to the
2547 curve's control points.
2548
2549 For the example above the following override gives a satisfactory
2550 tie:
2551
2552 @lilypond[verbatim,quote,relative=1]
2553 <<
2554   \once \override Tie
2555     #'control-points = #'((1 . -1) (3 . 0.6) (12.5 . 0.6) (14.5 . -1))
2556   { e1 ~ e1 }
2557 \\
2558   { r4 <g c,> <g c,> <g c,>4  }
2559 >>
2560 @end lilypond
2561
2562 @knownissues
2563
2564 It is not possible to modify shapes of ties or slurs by changing
2565 the @code{control-points} property if there are more than one at
2566 the same musical moment, not even by using the @code{\tweak}
2567 command.
2568
2569
2570
2571 @node Discussion of specific tweaks
2572 @section Discussion of specific tweaks
2573
2574 @menu
2575 * old Contexts explained::      
2576 @end menu
2577
2578
2579 @node old Contexts explained
2580 @subsection old Contexts explained
2581
2582 @c FIXME Delete this section?  It is in LM
2583 @c Or leave heading and go on from LM?
2584
2585 When music is printed, a lot of notational elements must be added to the
2586 output.  For example, compare the input and output of the following example:
2587
2588 @lilypond[quote,verbatim,relative=2,fragment]
2589 cis4 cis2. g4
2590 @end lilypond
2591
2592 The input is rather sparse, but in the output, bar lines, accidentals,
2593 clef, and time signature are added.  LilyPond @emph{interprets} the
2594 input.  During this step, the musical information is inspected in time
2595 order, similar to reading a score from left to right.  While reading
2596 the input, the program remembers where measure boundaries are, and which
2597 pitches require explicit accidentals.  This information can be presented on
2598 several levels.  For example, the effect of an accidental is limited
2599 to a single staff, while a bar line must be synchronized across the
2600 entire score.
2601
2602 Within LilyPond, these rules and bits of information are grouped in
2603 @emph{Contexts}.  Some examples of contexts are @code{Voice},
2604 @code{Staff}, and @code{Score}.  They are hierarchical, for
2605 example: a @code{Staff} can contain many @code{Voice}s, and a
2606 @code{Score} can contain many @code{Staff} contexts.
2607
2608 @quotation
2609 @sourceimage{context-example,5cm,,}
2610 @end quotation
2611
2612 Each context has the responsibility for enforcing some notation rules,
2613 creating some notation objects and maintaining the associated
2614 properties.  For example, the @code{Voice} context may introduce an
2615 accidental and then the @code{Staff} context maintains the rule to
2616 show or suppress the accidental for the remainder of the measure.  The
2617 synchronization of bar lines is handled at @code{Score} context.
2618
2619 However, in some music we may not want the bar lines to be
2620 synchronized -- consider a polymetric score in 4/4 and 3/4 time.  In
2621 such cases, we must modify the default settings of the @code{Score}
2622 and @code{Staff} contexts.
2623
2624 For very simple scores, contexts are created implicitly, and you need
2625 not be aware of them.  For larger pieces, such as anything with more
2626 than one staff, they must be
2627 created explicitly to make sure that you get as many staves as you
2628 need, and that they are in the correct order.  For typesetting pieces
2629 with specialized notation, it can be useful to modify existing or
2630 to define new contexts.
2631
2632
2633 A complete description of all available contexts is in the program
2634 reference, see
2635 @ifhtml
2636 @rinternals{Contexts}.
2637 @end ifhtml
2638 @ifnothtml
2639 Translation @expansion{} Context.
2640 @end ifnothtml
2641
2642 @c [TODO: describe propagation]
2643
2644
2645