]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[lilypond.git] / Documentation / user / changing-defaults.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.11.51"
11
12 @node Changing defaults
13 @chapter Changing defaults
14
15
16 The purpose of LilyPond's design is to provide the finest output
17 quality as a default.  Nevertheless, it may happen that you need to
18 change this default layout.  The layout is controlled through a large
19 number of proverbial @q{knobs and switches.}  This chapter does not
20 list each and every knob.  Rather, it outlines what groups of controls
21 are available and explains how to lookup which knob to use for a
22 particular effect.
23
24
25 @cindex Internals Reference
26
27 The controls available for tuning are described in a separate
28 document, the
29 @iftex
30 Internals Reference manual.
31 @end iftex
32 @ifnottex
33 @ref{Top,Internals Reference,,lilypond-internals}.
34 @end ifnottex
35 That manual
36 lists all different variables, functions and options available in
37 LilyPond.  It is written as a HTML document, which is available
38 @c leave the @uref as one long line.
39 @uref{http://@/lilypond@/.org/@/doc/@/stable/@/Documentation/@/user/@/lilypond@/-internals/,on@/-line},
40 but is also included with the LilyPond documentation package.
41
42 There are four areas where the default settings may be changed:
43
44 @itemize
45 @item
46 Automatic notation: changing the automatic creation of notation
47 elements.  For example, changing the beaming rules.
48
49 @item
50 Output: changing the appearance of individual
51 objects.  For example, changing stem directions or the location of
52 subscripts.
53
54 @item
55 Context: changing aspects of the translation from music events to
56 notation.  For example, giving each staff a separate time signature.
57
58 @item
59 Page layout: changing the appearance of the spacing, line
60 breaks, and page dimensions.  These modifications are discussed
61 @c in @ref{notation}, and @ref{Spacing issues}.
62 @end itemize
63
64 Internally, LilyPond uses Scheme (a LISP dialect) to provide
65 infrastructure.  Overriding layout decisions in effect accesses the
66 program internals, which requires Scheme input.  Scheme elements are
67 introduced in a @code{.ly} file with the hash mark
68 @code{#}.@footnote{@rlearning{Scheme tutorial}, contains a short tutorial
69 on entering numbers, lists, strings, and symbols in Scheme.}
70
71
72 @menu
73 * Interpretation contexts::
74 * Explaining the Internals Reference::
75 * Modifying properties::
76 * Useful concepts and properties::
77 * Common properties::
78 * Advanced tweaks::
79 * Discussion of specific tweaks::
80 @end menu
81
82
83 @node Interpretation contexts
84 @section Interpretation contexts
85
86 This section describes what contexts are, and how to modify them.
87
88 @menu
89 * Contexts explained::
90 * Creating contexts::
91 * Modifying context plug-ins::
92 * Changing context default settings::
93 * Defining new contexts::
94 * Aligning contexts::
95 @end menu
96
97
98 @node Contexts explained
99 @subsection Contexts explained
100
101 @c FIXME Rethink and rewrite
102
103 >> > > - list of contexts: my *danger unmaintainable*
104 >> > > alarm just went off.  I'm 
105
106 I knew it would... And leaving out some of them is perfectly fine
107 with me.
108 I do think that a list like this, with the main contexts and a
109 brief
110 description of  what they do (perhaps also with a note about what
111 default
112 behavior is associated with each of them, but this may be
113 unmanageable),
114 should be there, and then we could simply list the remaining ones
115 without
116 further explanation and with links to the IR.
117
118
119 The Master Of All Contexts
120 ==========================
121
122     * Score
123         This is the top level notation context. No other context
124 can
125         contain a Score context. This context handles the
126         administration of time signatures. It also makes sure that
127         items such as clefs, time signatures, and key-signatures
128 are
129         aligned across staves.
130         You cannot explicitly instantiate a Score context (since
131 it is
132         not contained in any other context). It is instantiated
133         automatically when an output definition (a \score or
134 \layout
135         block) is processed. 
136         (it should also be made clear somewhere what the
137 difference is between
138         \score and \Score).
139
140 Top-level contexts: Staff containers
141 ====================================
142     * StaffGroup
143         Groups staves while adding a bracket on the left side,
144         grouping the staves together. The bar lines of the
145 contained
146         staves are connected vertically. StaffGroup only consists
147 of a
148         collection of staves, with a bracket in front and spanning
149 bar
150         lines.
151     * ChoirStaff
152         Identical to StaffGroup except that the contained staves
153 are
154         not connected vertically.
155     * GrandStaff
156         A group of staves, with a brace on the left side, grouping
157 the
158         staves together. The bar lines of the contained staves are
159         connected vertically.
160     * PianoStaff
161         Just like GrandStaff but with a forced distance between
162 the
163         staves, so cross staff beaming and slurring can be used.
164     * DrumStaff
165         Handles typesetting for percussion. Can contain DrumVoice
166     * InnerStaffGroup
167     * InnerChoirStaff
168
169 Staff-level contexts
170 ====================
171     * Staff
172         Handles clefs, bar lines, keys, accidentals. It can
173 contain
174         Voice contexts.
175     * RhythmicStaff
176         Like Staff but for printing rhythms. Pitches are
177         ignored; the notes are printed on one line.
178     * TabStaff
179         Context for generating tablature. By default lays the
180 music
181         expression out as a guitar tablature, printed on six
182 lines.
183     * VaticanaStaff
184         Same as Staff, except that it is accommodated for
185         typesetting a piece in gregorian style. 
186     * MensuralStaff
187         Same as Staff, except that it is accommodated for
188         typesetting a piece in mensural style. 
189
190 Voice-level (bottom) contexts
191 =============================
192 What is generated by default here?  The voice-level contexts
193 initiate
194 certain properties and start engravers. 
195
196     * Voice 
197         Corresponds to a voice on a staff. This context handles
198 the
199         conversion of dynamic signs, stems, beams, super- and
200         subscripts, slurs, ties, and rests.
201         You have to instantiate this explicitly if you want to
202 have
203         multiple voices on the same staff. 
204         Bottom context.
205     * VaticanaVoice
206         Same as Voice, except that it is accommodated for
207         typesetting a piece in gregorian style.  
208     * MensuralVoice
209         Same as Voice, except that it is accommodated for
210         typesetting a piece in mensural style. 
211     * Lyrics
212         Corresponds to a voice with lyrics. Handles the printing
213 of a
214         single line of lyrics.
215         Bottom context.
216     * DrumVoice
217         A voice on a percussion staff.
218     * FiguredBass
219          
220     * ChordNames
221         Typesets chord names.  This context is a `bottom' context;
222 it
223         cannot contain other contexts.
224
225 ------------------------------
226 Then the following, which I don't know what to do with:
227
228     * TabVoice
229     * GregorianTranscriptionVoice
230     * GregorianTranscriptionStaff
231
232     * FretBoards
233         Engraves fretboards from chords. Not easy... Not
234 documented.
235         There is now some documentation on FretBoards in the NR, under
236          instrument-specific notation -- cds.
237
238     * NoteNames
239
240     * CueVoice Not documented
241     * Global
242         Hard coded entry point for LilyPond. Cannot be tuned.
243     * Devnull
244         Silently discards all musical information given to this
245 context.
246
247
248
249 @node Creating contexts
250 @subsection Creating contexts
251
252 @c TODO \new Score and \score
253 @c TODO more complete descriptions rather than learning style
254
255 For scores with only one voice and one staff, contexts are
256 created automatically.  For more complex scores, it is necessary to
257 create them by hand.  There are three commands that do this.
258
259 @itemize
260
261 @item
262 The easiest command is @code{\new}, and it also the quickest to type.
263 It is prepended to a music expression, for example
264
265 @funindex \new
266 @cindex new contexts
267 @cindex Context, creating
268
269 @example
270 \new @var{type} @var{music expression}
271 @end example
272
273 @noindent
274 where @var{type} is a context name (like @code{Staff} or
275 @code{Voice}).  This command creates a new context, and starts
276 interpreting the @var{music expression} with that.
277
278 A practical application of @code{\new} is a score with many
279 staves.  Each part that should be on its own staff, is preceded with
280 @code{\new Staff}.
281
282 @lilypond[quote,verbatim,relative=2,ragged-right,fragment]
283 <<
284   \new Staff { c4 c }
285   \new Staff { d4 d }
286 >>
287 @end lilypond
288
289 The @code{\new} command may also give a name to the context,
290
291 @example
292 \new @var{type} = @var{id} @var{music}
293 @end example
294 However, this user specified name is only used if there is no other
295 context already earlier with the same name.
296
297
298 @funindex \context
299
300 @item
301 Like @code{\new}, the @code{\context} command also directs a music
302 expression to a context object, but gives the context an explicit name.  The
303 syntax is
304
305 @example
306 \context @var{type} = @var{id} @var{music}
307 @end example
308
309 This form will search for an existing context of type @var{type}
310 called @var{id}.  If that context does not exist yet, a new
311 context with the specified name is created.  This is useful if
312 the context is referred to later on.  For example, when
313 setting lyrics the melody is in a named context
314
315 @example
316 \context Voice = "@b{tenor}" @var{music}
317 @end example
318
319 @noindent
320 so the texts can be properly aligned to its notes,
321
322 @example
323 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics}
324 @end example
325
326 @noindent
327
328 Another possible use of named contexts is funneling two different
329 music expressions into one context.  In the following example,
330 articulations and notes are entered separately,
331
332 @example
333 music = @{ c4 c4 @}
334 arts = @{ s4-. s4-> @}
335 @end example
336
337 They are combined by sending both to the same @code{Voice} context,
338
339 @example
340 <<
341   \new Staff \context Voice = "A" \music
342   \context Voice = "A" \arts
343 >>
344 @end example
345 @lilypond[quote,ragged-right]
346 music = { c4 c4 }
347 arts = { s4-. s4-> }
348 \relative c'' <<
349   \new Staff \context Voice = "A" \music
350   \context Voice = "A" \arts
351 >>
352 @end lilypond
353
354 With this mechanism, it is possible to define an Urtext (original
355 edition), with the option to put several distinct articulations on the
356 same notes.
357
358 @cindex creating contexts
359
360 @item
361 The third command for creating contexts is
362 @example
363 \context @var{type} @var{music}
364 @end example
365
366
367 @noindent
368 This is similar to @code{\context} with @code{= @var{id}}, but matches
369 any context of type @var{type}, regardless of its given name.
370
371 This variant is used with music expressions that can be interpreted at
372 several levels.  For example, the @code{\applyOutput} command (see
373 @ref{Running a function on all layout objects}).  Without an explicit
374 @code{\context}, it is usually applied to @code{Voice}
375
376 @example
377 \applyOutput #'@var{context} #@var{function}   % apply to Voice
378 @end example
379
380 To have it interpreted at the @code{Score} or @code{Staff} level use
381 these forms
382
383 @example
384 \applyOutput #'Score #@var{function}
385 \applyOutput #'Staff #@var{function}
386 @end example
387
388 @end itemize
389
390
391 @node Modifying context plug-ins
392 @subsection Modifying context plug-ins
393
394 @c TODO Should this be Modifying engravers or Modifying contexts?
395
396 Notation contexts (like @code{Score} and @code{Staff}) not only
397 store properties,
398 they also contain plug-ins called @q{engravers} that create notation
399 elements.  For example, the @code{Voice} context contains a
400 @code{Note_head_engraver} and the @code{Staff} context contains a
401 @code{Key_signature_engraver}.
402
403 For a full a description of each plug-in, see
404 @ifhtml
405 @rinternals{Engravers and Performers}.
406 @end ifhtml
407 @ifnothtml
408 Internals Reference @expansion{} Translation @expansion{} Engravers.
409 @end ifnothtml
410 Every context described in
411 @ifhtml
412 @rinternals{Contexts}
413 @end ifhtml
414 @ifnothtml
415 Internals Reference @expansion{} Translation @expansion{} Context.
416 @end ifnothtml
417 lists the engravers used for that context.
418
419
420 It can be useful to shuffle around these plug-ins.  This is done by
421 starting a new context with @code{\new} or @code{\context}, and
422 modifying it,
423
424 @funindex \with
425
426 @example
427 \new @var{context} \with @{
428   \consists @dots{}
429   \consists @dots{}
430   \remove @dots{}
431   \remove @dots{}
432   @emph{etc.}
433 @}
434 @{
435   @emph{..music..}
436 @}
437 @end example
438
439 @noindent
440 where the @dots{} should be the name of an engraver.  Here is a simple
441 example which removes @code{Time_signature_engraver} and
442 @code{Clef_engraver} from a @code{Staff} context,
443
444 @lilypond[quote,relative=1,verbatim,fragment]
445 <<
446   \new Staff {
447     f2 g
448   }
449   \new Staff \with {
450      \remove "Time_signature_engraver"
451      \remove "Clef_engraver"
452   } {
453     f2 g2
454   }
455 >>
456 @end lilypond
457
458 In the second staff there are no time signature or clef symbols.  This
459 is a rather crude method of making objects disappear since it will affect
460 the entire staff.  This method also influences the spacing, which may or
461 may not be desirable.  More sophisticated methods of blanking objects
462 are shown in @rlearning{Visibility and color of objects}.
463
464 The next example shows a practical application.  Bar lines and time
465 signatures are normally synchronized across the score.  This is done
466 by the @code{Timing_translator} and @code{Default_bar_line_engraver}.
467 This plug-in keeps an administration of time signature, location
468 within the measure, etc.  By moving these engraver from @code{Score} to
469 @code{Staff} context, we can have a score where each staff has its own
470 time signature.
471
472 @cindex polymetric scores
473 @cindex Time signatures, multiple
474
475 @lilypond[quote,relative=1,ragged-right,verbatim,fragment]
476 \new Score \with {
477   \remove "Timing_translator"
478   \remove "Default_bar_line_engraver"
479 } <<
480   \new Staff \with {
481     \consists "Timing_translator"
482     \consists "Default_bar_line_engraver"
483   } {
484       \time 3/4
485       c4 c c c c c
486   }
487   \new Staff \with {
488     \consists "Timing_translator"
489     \consists "Default_bar_line_engraver"
490   } {
491        \time 2/4
492        c4 c c c c c
493   }
494 >>
495 @end lilypond
496
497
498 @node Changing context default settings
499 @subsection Changing context default settings
500
501 The adjustments of the previous subsections (
502 @ref{The \set command}, @ref{Modifying context plug-ins}, and
503 @ref{Overview of modifying properties}) can also be entered
504 separately from the music in the @code{\layout} block,
505
506 @example
507 \layout @{
508   @dots{}
509   \context @{
510     \Staff
511
512     \set fontSize = #-2
513     \override Stem #'thickness = #4.0
514     \remove "Time_signature_engraver"
515   @}
516 @}
517 @end example
518
519 The @code{\Staff} command brings in the existing definition of the
520 staff context so that it can be modified.
521
522 The statements
523 @example
524 \set fontSize = #-2
525 \override Stem #'thickness = #4.0
526 \remove "Time_signature_engraver"
527 @end example
528
529 @noindent
530 affect all staves in the score.  Other contexts can be modified
531 analogously.
532
533 The @code{\set} keyword is optional within the @code{\layout} block, so
534
535 @example
536 \context @{
537   @dots{}
538   fontSize = #-2
539 @}
540 @end example
541
542 @noindent
543 will also work.
544
545
546
547 @knownissues
548
549 It is not possible to collect context changes in a variable and apply
550 them to a @code{\context} definition by referring to that variable.
551
552 The @code{\RemoveEmptyStaffContext} will overwrite your current
553 @code{\Staff} settings.  If you wish to change the defaults for a
554 staff which uses @code{\RemoveEmptyStaffContext}, you must do so
555 after calling @code{\RemoveEmptyStaffContext}, ie
556
557 @example
558 \layout @{
559   \context @{
560     \RemoveEmptyStaffContext
561
562     \override Stem #'thickness = #4.0
563   @}
564 @}
565 @end example
566
567 TODO: add \with in here.
568
569
570
571 @node Defining new contexts
572 @subsection Defining new contexts
573
574 Specific contexts, like @code{Staff} and @code{Voice}, are made of
575 simple building blocks.  It is possible to create new types of
576 contexts with different combinations of engraver plug-ins.
577
578 The next example shows how to build a different type of
579 @code{Voice} context from scratch.  It will be similar to
580 @code{Voice}, but only prints centered slash note heads.  It can be used
581 to indicate improvisation in jazz pieces,
582
583 @lilypond[quote,ragged-right]
584 \layout { \context {
585   \name ImproVoice
586   \type "Engraver_group"
587   \consists "Note_heads_engraver"
588   \consists "Text_engraver"
589   \consists Pitch_squash_engraver
590   squashedPosition = #0
591   \override NoteHead #'style = #'slash
592   \override Stem #'transparent = ##t
593   \alias Voice
594 }
595 \context { \Staff
596   \accepts "ImproVoice"
597 }}
598
599 \relative c'' {
600   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c
601    c4 c^"undress" c_"while playing :)" c }
602   a1
603 }
604 @end lilypond
605
606
607 These settings are defined within a @code{\context} block inside a
608 @code{\layout} block,
609
610 @example
611 \layout @{
612   \context @{
613     @dots{}
614   @}
615 @}
616 @end example
617
618 In the following discussion, the example input shown should go in place
619 of the @dots{} in the previous fragment.
620
621 First it is necessary to define a name for the new context:
622
623 @example
624 \name ImproVoice
625 @end example
626
627 Since it is similar to the @code{Voice}, we want commands that work
628 on (existing) @code{Voice}s to remain working.  This is achieved by
629 giving the new context an alias @code{Voice},
630
631 @example
632 \alias Voice
633 @end example
634
635 The context will print notes and instructive texts, so we need to add
636 the engravers which provide this functionality,
637
638 @example
639 \consists Note_heads_engraver
640 \consists Text_engraver
641 @end example
642
643 but we only need this on the center line,
644
645 @example
646 \consists Pitch_squash_engraver
647 squashedPosition = #0
648 @end example
649
650 The @rinternals{Pitch_squash_engraver} modifies note heads (created
651 by @rinternals{Note_heads_engraver}) and sets their vertical
652 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
653 the center line.
654
655 The notes look like a slash, and have no stem,
656
657 @example
658 \override NoteHead #'style = #'slash
659 \override Stem #'transparent = ##t
660 @end example
661
662 All these plug-ins have to cooperate, and this is achieved with a
663 special plug-in, which must be marked with the keyword @code{\type}.
664 This should always be @rinternals{Engraver_group},
665
666 @example
667 \type "Engraver_group"
668 @end example
669
670 Put together, we get
671
672 @example
673 \context @{
674   \name ImproVoice
675   \type "Engraver_group"
676   \consists "Note_heads_engraver"
677   \consists "Text_engraver"
678   \consists Pitch_squash_engraver
679   squashedPosition = #0
680   \override NoteHead #'style = #'slash
681   \override Stem #'transparent = ##t
682   \alias Voice
683 @}
684 @end example
685
686 @funindex \accepts
687 Contexts form hierarchies.  We want to hang the @code{ImproVoice}
688 under @code{Staff}, just like normal @code{Voice}s.  Therefore, we
689 modify the @code{Staff} definition with the @code{\accepts}
690 command,
691
692 @example
693 \context @{
694   \Staff
695   \accepts ImproVoice
696 @}
697 @end example
698
699 @funindex \denies
700 The opposite of @code{\accepts} is @code{\denies},
701 which is sometimes needed when reusing existing context definitions.
702
703 Putting both into a @code{\layout} block, like
704
705 @example
706 \layout @{
707   \context @{
708     \name ImproVoice
709     @dots{}
710   @}
711   \context @{
712     \Staff
713     \accepts "ImproVoice"
714   @}
715 @}
716 @end example
717
718 Then the output at the start of this subsection can be entered as
719
720 @example
721 \relative c'' @{
722   a4 d8 bes8
723   \new ImproVoice @{
724     c4^"ad lib" c
725     c4 c^"undress"
726     c c_"while playing :)"
727   @}
728   a1
729 @}
730 @end example
731
732
733 @node Aligning contexts
734 @subsection Aligning contexts
735
736 New contexts may be aligned above or below existing contexts.  This
737 could be useful in setting up a vocal staff (@rlearning{Vocal ensembles}) and
738 in ossia,
739
740 @c TODO Better example needed.  Ref LM, and expand on it.
741
742 @cindex ossia
743 @findex alignAboveContext
744 @findex alignBelowContext
745
746 @lilypond[quote,ragged-right]
747 ossia = { f4 f f f }
748 \score{
749   \relative c' \new Staff = "main" {
750     c4 c c c
751     <<
752       \new Staff \with {alignAboveContext=main} \ossia
753       { d8 f d f d f d f }
754     >>
755   }
756 }
757 @end lilypond
758
759
760 @node Explaining the Internals Reference
761 @section Explaining the Internals Reference
762
763
764 @menu
765 * Navigating the program reference::  
766 * Layout interfaces::           
767 * Determining the grob property::  
768 * Naming conventions::          
769 @end menu
770
771 @node Navigating the program reference
772 @subsection Navigating the program reference
773
774 @c TODO remove this (it's in the LM)
775 @c Replace with more factual directions
776
777 Suppose we want to move the fingering indication in the fragment
778 below:
779
780 @lilypond[quote,fragment,relative=2,verbatim]
781 c-2
782 \stemUp
783 f
784 @end lilypond
785
786 If you visit the documentation on fingering instructions (in
787 @ref{Fingering instructions}), you will notice:
788
789 @quotation
790 @strong{See also}
791
792 Internals Reference: @rinternals{Fingering}.
793
794 @end quotation
795
796
797 @c  outdated info; probably will delete.
798 @ignore
799 This fragment points to two parts of the program reference: a page
800 on @code{FingerEvent} and one on @code{Fingering}.
801
802 The page on @code{FingerEvent} describes the properties of the music
803 expression for the input @code{-2}.  The page contains many links
804 forward.  For example, it says
805
806 @quotation
807 Accepted by: @rinternals{Fingering_engraver},
808 @end quotation
809
810 @noindent
811 That link brings us to the documentation for the Engraver, the
812 plug-in, which says
813
814 @quotation
815 This engraver creates the following layout objects: @rinternals{Fingering}.
816 @end quotation
817
818 In other words, once the @code{FingerEvent}s are interpreted, the
819 @code{Fingering_engraver} plug-in will process them.
820 @end ignore
821
822 @ignore
823 @c  I can't figure out what this is supposed to mean.  -gp
824
825 The @code{Fingering_engraver} is also listed to create
826 @rinternals{Fingering} objects,
827
828 @c  old info?  it doesn't make any sense to me with our current docs.
829 This is also the
830 second bit of information listed under @b{See also} in the Notation
831 manual.
832 @end ignore
833
834 @ifnothtml
835 The programmer's reference is available as an HTML document.  It is
836 highly recommended that you read it in HTML form, either online or
837 by downloading the HTML documentation.  This section will be much more
838 difficult to understand if you are using the
839 PDF manual.
840 @end ifnothtml
841
842 Follow the link to @rinternals{Fingering}.  At the top of the
843 page, you will see
844
845 @quotation
846 Fingering objects are created by: @rinternals{Fingering_engraver} and
847 @rinternals{New_fingering_engraver}.
848 @end quotation
849
850 By following related links inside the program reference, we can follow the
851 flow of information within the program:
852
853 @itemize
854
855 @item @rinternals{Fingering}:
856 @rinternals{Fingering} objects are created by:
857 @rinternals{Fingering_engraver}
858
859 @item @rinternals{Fingering_engraver}:
860 Music types accepted: @rinternals{fingering-event}
861
862 @item @rinternals{fingering-event}:
863 Music event type @code{fingering-event} is in Music expressions named
864 @rinternals{FingerEvent}
865 @end itemize
866
867 This path goes against the flow of information in the program: it
868 starts from the output, and ends at the input event.  You could
869 also start at an input event, and read with the flow of
870 information, eventually ending up at the output object(s).
871
872 The program reference can also be browsed like a normal document.  It
873 contains chapters on
874 @ifhtml
875 @rinternals{Music definitions},
876 @end ifhtml
877 @ifnothtml
878 @code{Music definitions}
879 @end ifnothtml
880 on @rinternals{Translation}, and the @rinternals{Backend}.  Every
881 chapter lists all the definitions used and all properties that may be
882 tuned.
883
884
885 @node Layout interfaces
886 @subsection Layout interfaces
887
888 @cindex interface, layout
889 @cindex layout interface
890 @cindex grob
891
892 The HTML page that we found in the previous section describes the
893 layout object called @rinternals{Fingering}.  Such an object is a
894 symbol within the score.  It has properties that store numbers (like
895 thicknesses and directions), but also pointers to related objects.  A
896 layout object is also called a @emph{Grob}, which is short for Graphical
897 Object.  For more details about Grobs, see @rinternals{grob-interface}.
898
899 The page for @code{Fingering} lists the definitions for the
900 @code{Fingering} object.  For example, the page says
901
902 @quotation
903 @code{padding} (dimension, in staff space):
904
905 @code{0.5}
906 @end quotation
907
908 @noindent
909 which means that the number will be kept at a distance of at least 0.5
910 of the note head.
911
912
913 Each layout object may have several functions as a notational or
914 typographical element.  For example, the Fingering object
915 has the following aspects
916
917 @itemize
918 @item
919 Its size is independent of the horizontal spacing, unlike slurs or beams.
920
921 @item
922 It is a piece of text.  Granted, it is usually a very short text.
923
924 @item
925 That piece of text is typeset with a font, unlike slurs or beams.
926
927 @item
928 Horizontally, the center of the symbol should be aligned to the
929 center of the note head.
930
931 @item
932 Vertically, the symbol is placed next to the note and the staff.
933
934 @item
935 The vertical position is also coordinated with other superscript
936 and subscript symbols.
937 @end itemize
938
939 Each of these aspects is captured in so-called @emph{interface}s,
940 which are listed on the @rinternals{Fingering} page at the bottom
941
942 @quotation
943 This object supports the following interfaces:
944 @rinternals{item-interface},
945 @rinternals{self-alignment-interface},
946 @rinternals{side-position-interface}, @rinternals{text-interface},
947 @rinternals{text-script-interface}, @rinternals{font-interface},
948 @rinternals{finger-interface}, and @rinternals{grob-interface}.
949 @end quotation
950
951 Clicking any of the links will take you to the page of the respective
952 object interface.  Each interface has a number of properties.  Some of
953 them are not user-serviceable (@q{Internal properties}), but others
954 can be modified.
955
956 We have been talking of @emph{the} @code{Fingering} object, but actually it
957 does not amount to much.  The initialization file (see
958 @rlearning{Other sources of information})
959 @file{scm/@/define@/-grobs@/.scm} shows the soul of the @q{object},
960
961 @example
962 (Fingering
963   . ((padding . 0.5)
964      (avoid-slur . around)
965      (slur-padding . 0.2)
966      (staff-padding . 0.5)
967      (self-alignment-X . 0)
968      (self-alignment-Y . 0)
969      (script-priority . 100)
970      (stencil . ,ly:text-interface::print)
971      (direction . ,ly:script-interface::calc-direction)
972      (font-encoding . fetaNumber)
973      (font-size . -5)           ; don't overlap when next to heads.
974      (meta . ((class . Item)
975      (interfaces . (finger-interface
976                     font-interface
977                     text-script-interface
978                     text-interface
979                     side-position-interface
980                     self-alignment-interface
981                     item-interface))))))
982 @end example
983
984 @noindent
985 As you can see, the @code{Fingering} object is nothing more than a
986 bunch of variable settings, and the webpage in the Internals Reference
987 is directly generated from this definition.
988
989
990 @node Determining the grob property
991 @subsection Determining the grob property
992
993 @c TODO remove this (it's in the LM)
994 @c Replace with more factual directions
995
996 Recall that we wanted to change the position of the @b{2} in
997
998 @lilypond[quote,fragment,relative=2,verbatim]
999 c-2
1000 \stemUp
1001 f
1002 @end lilypond
1003
1004 Since the @b{2} is vertically positioned next to its note, we have to
1005 meddle with the interface associated with this positioning.  This is
1006 done using @code{side-position-interface}.  The page for this interface
1007 says
1008
1009 @quotation
1010 @code{side-position-interface}
1011
1012 Position a victim object (this one) next to other objects (the
1013 support).  The property @code{direction} signifies where to put the
1014 victim object relative to the support (left or right, up or down?)
1015 @end quotation
1016
1017 @cindex padding
1018 @noindent
1019 Below this description, the variable @code{padding} is described as
1020
1021 @quotation
1022 @table @code
1023 @item padding
1024 (dimension, in staff space)
1025
1026 Add this much extra space between objects that are next to each other.
1027 @end table
1028 @end quotation
1029
1030 By increasing the value of @code{padding}, we can move the
1031 fingering away from the note head.  The following command inserts
1032 3 staff spaces of white
1033 between the note and the fingering:
1034 @example
1035 \once \override Voice.Fingering #'padding = #3
1036 @end example
1037
1038 Inserting this command before the Fingering object is created,
1039 i.e., before @code{c2}, yields the following result:
1040
1041 @lilypond[quote,relative=2,fragment,verbatim]
1042 \once \override Voice.Fingering #'padding = #3
1043 c-2
1044 \stemUp
1045 f
1046 @end lilypond
1047
1048
1049 In this case, the context for this tweak is @code{Voice}.  This
1050 fact can also be deduced from the program reference, for the page for
1051 the @rinternals{Fingering_engraver} plug-in says
1052
1053 @quotation
1054 Fingering_engraver is part of contexts: @dots{} @rinternals{Voice}
1055 @end quotation
1056
1057
1058 @node Naming conventions
1059 @subsection Naming conventions
1060
1061 Another thing that is needed, is an overview of the various naming
1062 conventions: 
1063
1064     scheme functions: lowercase-with-hyphens (incl. one-word
1065 names)
1066     scheme functions: ly:plus-scheme-style
1067     music events, music classes and music properties:
1068 as-scheme-functions
1069     Grob interfaces: scheme-style
1070     backend properties: scheme-style (but X and Y!)
1071     contexts (and MusicExpressions and grobs): Capitalized or
1072 CamelCase
1073     context properties: lowercaseFollowedByCamelCase
1074     engravers:
1075 Capitalized_followed_by_lowercase_and_with_underscores
1076
1077 Which of these are conventions and which are rules?
1078 Which are rules of the underlying language, and which are
1079 LP-specific?
1080
1081
1082 @node Modifying properties
1083 @section Modifying properties
1084
1085 @menu
1086 * Overview of modifying properties::  
1087 * The \set command::            
1088 * The \override command::       
1089 * \set versus \override::       
1090 * Objects connected to the input::  
1091 @end menu
1092
1093
1094 @node Overview of modifying properties
1095 @subsection Overview of modifying properties
1096
1097 Each context is responsible for creating certain types of graphical
1098 objects.  The settings used for printing these objects are also stored by
1099 context.  By changing these settings, the appearance of objects can be
1100 altered.
1101
1102 The syntax for this is
1103
1104 @example
1105 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1106 @end example
1107
1108 Here @var{name} is the name of a graphical object, like
1109 @code{Stem} or @code{NoteHead}, and @var{property} is an internal
1110 variable of the formatting system (@q{grob property} or @q{layout
1111 property}).  The latter is a symbol, so it must be quoted.  The
1112 subsection @ref{Modifying properties}, explains what to fill in
1113 for @var{name}, @var{property}, and @var{value}.  Here we only
1114 discuss the functionality of this command.
1115
1116 The command
1117
1118 @verbatim
1119 \override Staff.Stem #'thickness = #4.0
1120 @end verbatim
1121
1122 @noindent
1123 makes stems thicker (the default is 1.3, with staff line thickness as a
1124 unit).  Since the command specifies @code{Staff} as context, it only
1125 applies to the current staff.  Other staves will keep their normal
1126 appearance.  Here we see the command in action:
1127
1128 @lilypond[quote,verbatim,relative=2,fragment]
1129 c4
1130 \override Staff.Stem #'thickness = #4.0
1131 c4
1132 c4
1133 c4
1134 @end lilypond
1135
1136 The @code{\override} command changes the definition of the @code{Stem}
1137 within the current @code{Staff}.  After the command is interpreted
1138 all stems are thickened.
1139
1140 Analogous to @code{\set}, the @var{context} argument may be left out,
1141 causing the default context @code{Voice} to be used.  Adding
1142 @code{\once} applies the change during one timestep only.
1143
1144 @lilypond[quote,fragment,verbatim,relative=2]
1145 c4
1146 \once \override Stem #'thickness = #4.0
1147 c4
1148 c4
1149 @end lilypond
1150
1151 The @code{\override} must be done before the object is
1152 started.  Therefore, when altering @emph{Spanner} objects such as slurs
1153 or beams, the @code{\override} command must be executed at the moment
1154 when the object is created.  In this example,
1155
1156 @lilypond[quote,fragment,verbatim,relative=2]
1157 \override Slur #'thickness = #3.0
1158 c8[( c
1159 \override Beam #'thickness = #0.6
1160 c8 c])
1161 @end lilypond
1162
1163 @noindent
1164 the slur is fatter but the beam is not.  This is because the command for
1165 @code{Beam} comes after the Beam is started, so it has no effect.
1166
1167 Analogous to @code{\unset}, the @code{\revert} command for a context
1168 undoes an @code{\override} command; like with @code{\unset}, it only
1169 affects settings that were made in the same context.  In other words, the
1170 @code{\revert} in the next example does not do anything.
1171
1172 @example
1173 \override Voice.Stem #'thickness = #4.0
1174 \revert Staff.Stem #'thickness
1175 @end example
1176
1177 Some tweakable options are called @q{subproperties} and reside inside
1178 properties.  To tweak those, use commands of the form
1179
1180 @c leave this as a long long
1181 @example
1182 \override @var{context}.@var{name} #'@var{property} #'@var{subproperty} = #@var{value}
1183 @end example
1184
1185 @noindent
1186 such as
1187
1188 @example
1189 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1190 @end example
1191
1192
1193 @seealso
1194
1195 Internals: @rinternals{OverrideProperty}, @rinternals{RevertProperty},
1196 @rinternals{PropertySet}, @rinternals{Backend}, and
1197 @rinternals{All layout objects}.
1198
1199
1200 @knownissues
1201
1202 The back-end is not very strict in type-checking object properties.
1203 Cyclic references in Scheme values for properties can cause hangs
1204 or crashes, or both.
1205
1206
1207
1208 @node The \set command
1209 @subsection The @code{\set} command
1210
1211 @cindex properties
1212 @funindex \set
1213 @cindex changing properties
1214
1215 Each context can have different @emph{properties}, variables contained
1216 in that context.  They can be changed during the interpretation step.
1217 This is achieved by inserting the @code{\set} command in the music,
1218
1219 @example
1220 \set @var{context}.@var{prop} = #@var{value}
1221 @end example
1222
1223 For example,
1224 @lilypond[quote,verbatim,relative=2,fragment]
1225 R1*2
1226 \set Score.skipBars = ##t
1227 R1*2
1228 @end lilypond
1229
1230 This command skips measures that have no notes.  The result is that
1231 multi-rests are condensed.  The value assigned is a Scheme object.  In
1232 this case, it is @code{#t}, the boolean True value.
1233
1234 If the @var{context} argument is left out, then the current bottom-most
1235 context (typically @code{ChordNames}, @code{Voice}, or
1236 @code{Lyrics}) is used.  In this example,
1237
1238 @lilypond[quote,verbatim,relative=2,fragment]
1239 c8 c c c
1240 \set autoBeaming = ##f
1241 c8 c c c
1242 @end lilypond
1243
1244 @noindent
1245 the @var{context} argument to @code{\set} is left out, so automatic
1246 beaming is switched off in the current @rinternals{Voice}.  Note that
1247 the bottom-most context does not always contain the property that you
1248 wish to change -- for example, attempting to set the @code{skipBars}
1249 property (of the bottom-most context, in this case @code{Voice}) will
1250 have no effect.
1251
1252 @lilypond[quote,verbatim,relative=2,fragment]
1253 R1*2
1254 \set skipBars = ##t
1255 R1*2
1256 @end lilypond
1257
1258 Contexts are hierarchical, so if a bigger context was specified, for
1259 example @code{Staff}, then the change would also apply to all
1260 @code{Voice}s in the current stave.  The change is applied
1261 @q{on-the-fly}, during the music, so that the setting only affects the
1262 second group of eighth notes.
1263
1264 @funindex \unset
1265
1266 There is also an @code{\unset} command,
1267 @example
1268 \unset @var{context}.@var{prop}
1269 @end example
1270
1271 @noindent
1272 which removes the definition of @var{prop}.  This command removes
1273 the definition only if it is set in @var{context}, so
1274
1275 @example
1276 \set Staff.autoBeaming = ##f
1277 @end example
1278
1279 @noindent
1280 introduces a property setting at @code{Staff} level.  The setting also
1281 applies to the current @code{Voice}.  However,
1282
1283 @example
1284 \unset Voice.autoBeaming
1285 @end example
1286
1287 @noindent
1288 does not have any effect.  To cancel this setting, the @code{\unset}
1289 must be specified on the same level as the original @code{\set}.  In
1290 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
1291 requires
1292 @example
1293 \unset Staff.autoBeaming
1294 @end example
1295
1296 Like @code{\set}, the @var{context} argument does not have to be
1297 specified for a bottom context, so the two statements
1298
1299 @example
1300 \set Voice.autoBeaming = ##t
1301 \set autoBeaming = ##t
1302 @end example
1303
1304 @noindent
1305 are equivalent.
1306
1307
1308 @cindex \once
1309 Settings that should only apply to a single time-step can be entered
1310 with @code{\once}, for example in
1311
1312 @lilypond[quote,verbatim,relative=2,fragment]
1313 c4
1314 \once \set fontSize = #4.7
1315 c4
1316 c4
1317 @end lilypond
1318
1319 the property @code{fontSize} is unset automatically after the second
1320 note.
1321
1322 A full description of all available context properties is in the
1323 program reference, see
1324 @ifhtml
1325 @rinternals{Tunable context properties}.
1326 @end ifhtml
1327 @ifnothtml
1328 Translation @expansion{} Tunable context properties.
1329 @end ifnothtml
1330
1331
1332
1333 @node The \override command
1334 @subsection The @code{\override} command
1335
1336 Commands which change output generally look like
1337
1338 @example
1339 \override Voice.Stem #'thickness = #3.0
1340 @end example
1341
1342 @noindent
1343 To construct this tweak we must determine these bits of information:
1344
1345 @itemize
1346 @item the context: here @code{Voice}.
1347 @item the layout object: here @code{Stem}.
1348 @item the layout property: here @code{thickness}.
1349 @item a sensible value: here @code{3.0}.
1350 @end itemize
1351
1352 Some tweakable options are called @q{subproperties} and reside inside
1353 properties.  To tweak those, use commands in the form
1354
1355 @example
1356 \override Stem #'details #'beamed-lengths = #'(4 4 3)
1357 @end example
1358
1359 @cindex internal documentation
1360 @cindex finding graphical objects
1361 @cindex graphical object descriptions
1362 @cindex tweaking
1363 @funindex \override
1364 @cindex internal documentation
1365
1366 For many properties, regardless of the data type of the property, setting the
1367 property to false ( @code{##f} ) will result in turning it off, causing
1368 LilyPond to ignore that property entirely.  This is particularly useful for
1369 turning off grob properties which may otherwise be causing problems.
1370
1371 We demonstrate how to glean this information from the notation manual
1372 and the program reference.
1373
1374
1375 @node \set versus \override
1376 @subsection @code{\set} vs. @code{\override}
1377
1378 We have seen two methods of changing properties: @code{\set} and
1379 @code{\override}.  There are actually two different kinds of
1380 properties.
1381
1382 Contexts can have properties, which are usually named in
1383 @code{studlyCaps}.  They mostly control the translation from
1384 music to notation, eg. @code{localKeySignature} (for determining
1385 whether to print accidentals), @code{measurePosition} (for
1386 determining when to print a bar line).  Context properties can
1387 change value over time while interpreting a piece of music;
1388 @code{measurePosition} is an obvious example of
1389 this.  Context properties are modified with @code{\set}.
1390
1391 There is a special type of context property: the element
1392 description.  These properties are named in @code{StudlyCaps}
1393 (starting with capital letters).  They contain the
1394 @q{default settings} for said graphical object as an
1395 association list.  See @file{scm/@/define@/-grobs@/.scm}
1396 to see what kind of settings there are.  Element descriptions
1397 may be modified with @code{\override}.
1398
1399 @code{\override} is actually a shorthand;
1400
1401 @example
1402 \override @var{context}.@var{name} #'@var{property} = #@var{value}
1403 @end example
1404
1405 @noindent
1406 is more or less equivalent to
1407
1408 @c  leave this long line -gp
1409 @example
1410 \set @var{context}.@var{name} #'@var{property} = #(cons (cons '@var{property} @var{value}) <previous value of @var{context})
1411 @end example
1412
1413 The value of @code{context} (the alist) is used to initialize
1414 the properties of individual grobs.  Grobs also have
1415 properties, named in Scheme style, with
1416 @code{dashed-words}.  The values of grob properties change
1417 during the formatting process: formatting basically amounts
1418 to computing properties using callback functions.
1419
1420 @code{fontSize} is a special property: it is equivalent to
1421 entering @code{\override ... #'font-size} for all pertinent
1422 objects.  Since this is a common change, the special
1423 property (modified with @code{\set}) was created.
1424
1425
1426 @node Objects connected to the input
1427 @subsection Objects connected to the input
1428
1429 TODO: can't use \tweak in a variable
1430
1431 @funindex \tweak
1432
1433 In some cases, it is possible to take a short-cut for tuning graphical
1434 objects.  For objects that result directly from a piece of the input,
1435 you can use the @code{\tweak} function, for example
1436
1437 @lilypond[relative=2,fragment,verbatim,ragged-right]
1438 <
1439   c
1440   \tweak #'color #red d
1441   g
1442   \tweak #'duration-log #1  a
1443 >4-\tweak #'padding #10 -.
1444 @end lilypond
1445
1446 As you can see, properties are set in the objects directly,
1447 without mentioning the grob name or context where this should be
1448 applied.
1449
1450 This technique only works for objects that are directly connected to
1451 an @rinternals{Event} from the input, for example
1452
1453 @itemize
1454 @item note heads, caused by chord-pitch (i.e., notes inside a chord)
1455 @item articulation signs, caused by articulation instructions
1456 @end itemize
1457
1458 It notably does not work for stems and accidentals (these are caused
1459 by note heads, not by music events) or clefs (these are not caused by
1460 music inputs, but rather by the change of a property value).
1461
1462 There are very few objects which are @emph{directly} connected to
1463 output.  A normal note (like @code{c4}) is not directly connected
1464 to output, so
1465
1466 @example
1467 \tweak #'color #red c4
1468 @end example
1469
1470 @noindent
1471 does not change color.  See @ref{Displaying music expressions}, for
1472 details.
1473
1474
1475 @node Useful concepts and properties
1476 @section Useful concepts and properties
1477
1478
1479 @menu
1480 * Input modes::
1481 * Direction and placement::
1482 * Distances and measurements::
1483 * Spanners::
1484 @end menu
1485
1486 @node Input modes
1487 @subsection Input modes
1488
1489 The way in which the notation contained within an input file is
1490 interpreted is determined by the current input mode.
1491
1492 @strong{Chord mode}
1493
1494 This is activated with the @code{\chordmode} command, and causes
1495 input to be interpreted with the syntax of chord notation, see
1496 @ref{Chord notation}.  Chords are rendered as notes on a staff.
1497
1498 Chord mode is also activated with the @code{\chords} command.
1499 This also creates a new @code{ChordNames} context and
1500 causes the following input to be interpreted with the syntax of
1501 chord notation and rendered as chord names in the @code{ChordNames}
1502 context, see @ref{Printing chord names}.
1503
1504 @strong{Drum mode}
1505
1506 This is activated with the @code{\drummode} command, and causes
1507 input to be interpreted with the syntax of drum notation, see
1508 @ref{Basic percussion notation}.
1509
1510 Drum mode is also activated with the @code{\drums} command.
1511 This also creates a new @code{DrumStaff} context and causes the
1512 following input to be interpreted with the syntax of drum notation
1513 and rendered as drum symbols on a drum staff, see @ref{Basic
1514 percussion notation}.
1515
1516 @strong{Figure mode}
1517
1518 This is activated with the @code{\figuremode} command, and causes
1519 input to be interpreted with the syntax of figured bass, see
1520 @ref{Entering figured bass}.
1521
1522 Figure mode is also activated with the @code{\figures} command.
1523 This also creates a new @code{FiguredBass} context and causes the
1524 following input to be interpreted with the figured bass syntax
1525 and rendered as figured bass symbols in the @code{FiguredBass}
1526 context, see @ref{Introduction to figured bass}.
1527
1528 @strong{Fret and tab modes}
1529
1530 There are no special input modes for entering fret and tab symbols.
1531
1532 To create tab diagrams, enter notes or chords in note mode and
1533 render them in a @code{TabStaff} context, see
1534 @ref{Default tablatures}.
1535
1536 To create fret diagrams above a staff, you have two choices.
1537 You can either use the @code{FretBoards} context (see
1538 @ref{Automatic fret diagrams} or you can enter them as a markup
1539 above the notes using the @code{\fret-diagram} command (see
1540 @ref{Fret diagram markups}).
1541
1542 @strong{Lyrics mode}
1543
1544 This is activated with the @code{\lyricmode} command, and causes
1545 input to be interpreted as lyric syllables with optional durations
1546 and associated lyric modifiers, see @ref{Vocal music}.
1547
1548 Lyric mode is also activated with the @code{\addlyrics} command.
1549 This also creates a new @code{Lyrics} context and an implicit
1550 @code{\lyricsto} command which associates the following lyrics
1551 with the preceding music.
1552
1553 @strong{Markup mode}
1554
1555 This is activated with the @code{\markup} command, and causes
1556 input to be interpreted with the syntax of markup, see
1557 @ref{Text markup commands}.
1558
1559 @c silly work-around for texinfo broken-ness
1560 @c (@strong{Note...} causes a spurious cross-reference in Info)
1561 @b{Note mode}
1562
1563 This is the default mode or it may be activated with the
1564 @code{\notemode} command.  Input is interpreted as pitches,
1565 durations, markup, etc and typeset as musical notation on a staff.
1566
1567 It is not normally necessary to specify note mode explicitly, but
1568 it may be useful to do so in certain situations, for example if you
1569 are in lyric mode, chord mode or any other mode and want to insert
1570 something that only can be done with note mode syntax.
1571
1572 For example, to indicate dynamic markings for the verses of a
1573 choral pieces it is necessary to enter note mode to interpret
1574 the markings:
1575
1576 @lilypond[verbatim,relative=2,quote]
1577 { c4 c4 c4 c4 }
1578 \addlyrics {
1579   \notemode{\set stanza = \markup{ \dynamic f 1. } }
1580   To be sung loudly
1581 }
1582 \addlyrics {
1583   \notemode{\set stanza = \markup{ \dynamic p 2. } }
1584   To be sung quietly
1585 }
1586 @end lilypond
1587
1588
1589
1590 @node Direction and placement
1591 @subsection Direction and placement
1592
1593 In typesetting music the direction and placement of many items is
1594 a matter of choice.  For example, the stems of notes can
1595 be directed up or down; lyrics, dynamics, and other expressive
1596 marks may be placed above or below the staff; text may be aligned
1597 left, right or center; etc.  Most of these choices may be left to
1598 be determined automatically by LilyPond, but in some cases it may
1599 be desirable to force a particular direction or placement.
1600
1601 @strong{Default actions}
1602
1603 By default some directions are always up or always down (e.g.
1604 dynamics or fermata), while other things can alternate between
1605 up or down based on the stem direction (like slurs or accents).
1606
1607 @c TODO Add table showing these
1608
1609 @strong{Context layout}
1610
1611 Contexts are positioned in a system from top to bottom in the
1612 order in which they are encountered.  Note, however, that a
1613 context will be created implicitly if a command is encountered
1614 when there is no suitable context available to contain it.
1615
1616 @c TODO Add example ?
1617
1618 The default order in which contexts are laid out can be changed,
1619 see @ref{Aligning contexts}
1620
1621 @strong{Articulation direction indicators}
1622
1623 When adding articulations to notes the direction indicator,
1624 @code{^} (meaning @qq{up}), @code{_} (meaning @qq{down}) or
1625 @code{-} (meaning @qq{use default direction}), can usually be
1626 omitted, in which case @code{-} is assumed.  But a direction
1627 indicator is @strong{always} required before
1628
1629 @itemize
1630 @item @code{\tweak} commands
1631 @item @code{\markup} commands
1632 @item @code{\tag} commands
1633 @item string markups, e.g. -"string"
1634 @item fingering instructions, e.g. @code{-1}
1635 @item articulation shortcuts, e.g. @code{-.}, @code{->}, @code{--}
1636 @end itemize
1637
1638 @strong{The direction property}
1639
1640 The position or direction of many layout objects is controlled
1641 by the @code{direction} property.
1642
1643 The value of the @code{direction} property may be
1644 set to @code{1}, meaning @qq{up} or @qq{above}, or to @code{-1},
1645 meaning @qq{down} or @qq{below}.  The symbols @code{UP} and
1646 @code{DOWN} may be used instead of @code{1} and @code{-1}
1647 respectively.  The default direction may be specified by setting
1648 @code{direction} to @code{0} or @code{CENTER}.  Alternatively,
1649 in many cases predefined commands
1650 exist to specify the direction.  These are all of the form
1651
1652 @noindent
1653 @code{\xxxUp}, @code{xxxDown}, @code{xxxNeutral}
1654
1655 @noindent
1656 where @code{xxxNeutral} means @qq{use the default direction}.
1657 See @rlearning{Within-staff objects}.
1658
1659 In a few cases, arpeggio being the only common example, the value
1660 of the @code{direction} property specifies whether the object
1661 is to be placed to the right or left of the parent object.  In
1662 this case @code{-1} or @code{LEFT} means @qq{to the left} and
1663 @code{1} or @code{RIGHT} means @qq{to the right}.  @code{0}
1664 or @code{CENTER} means @qq{use the default} direction, as before.
1665
1666 @ignore
1667 These all have side-axis set to #X
1668 AmbitusAccidental - direction has no effect
1669 Arpeggio - works
1670 StanzaNumber - not tried
1671 TrillPitchAccidental - not tried
1672 TrillPitchGroup - not tried
1673 @end ignore
1674
1675
1676
1677 @node Distances and measurements
1678 @subsection Distances and measurements
1679
1680 DISCUSS after working on other sections.
1681
1682 TODO: staff spaces.  Maybe move into tweaks?
1683
1684
1685 @node Spanners
1686 @subsection Spanners
1687
1688 Many objects of musical notation extend over several notes or even
1689 several bars.  Examples are crescendi, trills, tuplet brackets, and
1690 volta repeat brackets.  Such objects are called @qq{spanners}, and
1691 have special properties to control their appearance and behaviour.
1692 Some of these properties are common to all spanners; others are
1693 restricted to a sub-set of the spanners.
1694
1695
1696 @node Common properties
1697 @section Common properties
1698
1699 @menu
1700 * Controlling visibility of objects::
1701 * Line styles::
1702 * Rotating objects::
1703 * Aligning objects::
1704 @end menu
1705
1706 @node Controlling visibility of objects
1707 @subsection Controlling visibility of objects
1708
1709 @c FIXME Write this section
1710
1711 @node Line styles
1712 @subsection Line styles
1713
1714 @c TODO: split the following explanations between expressive marks and
1715 @c text-related stuff. Perhaps create a new subsection named
1716 @c "Spanner limits", "Spanner boundaries"? -vv
1717
1718 Some performance indications, e.g., @i{rallentando} and
1719 @i{accelerando} and @i{trills} are written as text and are
1720 extended over many measures with lines, sometimes dotted or wavy.
1721
1722 These all use the same routines as the glissando for drawing the
1723 texts and the lines, and tuning their behavior is therefore also
1724 done in the same way.  It is done with a spanner, and the routine
1725 responsible for drawing the spanners is
1726 @code{ly:line-interface::print}.  This routine determines the
1727 exact location of the two @i{span points} and draws a line in
1728 between, in the style requested.
1729
1730 Here is an example of the different line styles available, and how
1731 to tune them.
1732
1733 @lilypond[relative=2,ragged-right,verbatim,fragment]
1734 d2 \glissando d'2
1735 \once \override Glissando #'style = #'dashed-line
1736 d,2 \glissando d'2
1737 \override Glissando #'style = #'dotted-line
1738 d,2 \glissando d'2
1739 \override Glissando #'style = #'zigzag
1740 d,2 \glissando d'2
1741 \override Glissando #'style = #'trill
1742 d,2 \glissando d'2
1743 @end lilypond
1744
1745 The information that determines the end-points is computed
1746 on-the-fly for every graphic object, but it is possible to
1747 override these. 
1748
1749 @lilypond[relative=2,ragged-right,verbatim,fragment]
1750 e2 \glissando f
1751 \once \override Glissando #'bound-details #'right #'Y = #-2
1752 e2 \glissando f
1753 @end lilypond
1754
1755 The @code{Glissando} object, like any other using the
1756 @code{ly:line-interface::print} routine, carries a nested
1757 association list.  In the above statement, the value for @code{Y}
1758 is set to @code{-2} for the association list corresponding to the
1759 right end point.  Of course, it is also possible to adjust the
1760 left side with @code{left} instead of @code{right}.
1761
1762 If @code{Y} is not set, the value is computed from the vertical
1763 position of right attachment point of the spanner. 
1764
1765 In case of a line break, the values for the span-points are
1766 extended with contents of the @code{left-broken} and
1767 @code{right-broken} sublists, for example
1768
1769 @lilypond[relative=2,ragged-right,verbatim,fragment]
1770 \override Glissando #'breakable = ##T 
1771 \override Glissando #'bound-details #'right-broken #'Y = #-3
1772 c1 \glissando \break
1773 f1
1774 @end lilypond
1775
1776 The following properties can be used for the
1777
1778 @table @code
1779 @item Y
1780 This sets the Y-coordinate of the end point, in staff space.  By
1781 default, it is the center of the bound object, so for a glissando
1782 it points to the vertical center of the note head.
1783
1784 For horizontal spanners, such as text spanner and trill spanners,
1785 it is hardcoded to 0.
1786
1787 @item attach-dir
1788 This determines where the line starts and ends in X-direction,
1789 relative to the bound object.  So, a value of @code{-1} (or
1790 @code{LEFT}) makes the line start/end at the left side of the note
1791 head it is attached to.
1792
1793 @item X
1794 This is the absolute coordinate of the end point.  It is usually
1795 computed on the fly, and there is little use in overriding it. 
1796
1797 @item stencil
1798 Line spanners may have symbols at the beginning or end, which is
1799 contained in this sub-property.  This is for internal use, it is
1800 recommended to use @code{text}.
1801
1802 @item text
1803 This is a markup that is evaluated to yield stencil.  It is used
1804 to put @i{cresc.} and @i{tr} on horizontal spanners.
1805
1806 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
1807 \override TextSpanner #'bound-details #'left #'text
1808    = \markup { \small \bold Slower }
1809 c2\startTextSpan b c a\stopTextSpan
1810 @end lilypond
1811
1812 @item stencil-align-dir-y
1813 @item stencil-offset
1814 Without setting this, the stencil is simply put there at the
1815 end-point, as defined by the @code{X} and @code{Y} sub properties.
1816 Setting either @code{stencil-align-dir-y} or @code{stencil-offset}
1817 will move the symbol at the edge relative to the end point of the
1818 line
1819
1820 @lilypond[relative=1,fragment,verbatim]
1821 \override TextSpanner #'bound-details
1822   #'left #'stencil-align-dir-y = #DOWN
1823 \override TextSpanner #'bound-details
1824   #'right #'stencil-align-dir-y = #UP
1825
1826 \override TextSpanner #'bound-details
1827   #'left #'text = #"gggg"
1828 \override TextSpanner #'bound-details
1829   #'right #'text = #"hhhh"
1830 c4^\startTextSpan c c c \stopTextSpan
1831 @end lilypond
1832
1833 @item arrow
1834 Setting this sub property to @code{#t} produce an arrowhead at the
1835 end of the line.
1836
1837 @item padding
1838 This sub property controls the space between the specified
1839 end-point of the line and the actual end.  Without padding, a
1840 glissando would start and end in the center of each note head.
1841
1842 @end table
1843
1844 @c TODO: Move to 5.4.4
1845
1846 The music function \endSpanners terminates spanners and hairpins
1847 after exactly one note.
1848
1849 @lilypond[verbatim,quote,ragged-right,relative=2,fragment]
1850 \endSpanners
1851 c2 \startTextSpan c2
1852 c2 \< c2
1853 @end lilypond
1854
1855 When using \endSpanners it is not necessary to close
1856 \startTextSpan with \stopTextSpan, nor is it necessary to close
1857 hairpins with \!.
1858
1859
1860
1861 @seealso
1862
1863 Internals Reference: @rinternals{TextSpanner},
1864 @rinternals{Glissando}, @rinternals{VoiceFollower},
1865 @rinternals{TrillSpanner},
1866 @rinternals{line-spanner-interface}.
1867
1868
1869 @node Rotating objects
1870 @subsection Rotating objects
1871
1872 @c FIXME Write this section
1873
1874 @node Aligning objects
1875 @subsection Aligning objects
1876
1877 @c FIXME Write this section
1878
1879
1880 @node Advanced tweaks
1881 @section Advanced tweaks
1882
1883 @menu
1884 * Vertical grouping of grobs::
1885 * Modifying ends of spanners::
1886 * Modifying stencils::
1887 @end menu
1888
1889
1890
1891
1892 @node Vertical grouping of grobs
1893 @subsection Vertical grouping of grobs
1894
1895 @c FIXME Expand this section
1896
1897 The VerticalAlignment and VerticalAxisGroup grobs work together.
1898 VerticalAxisGroup groups together different grobs like Staff, Lyrics,
1899 etc.  VerticalAlignment then vertically aligns the different grobs
1900 grouped together by VerticalAxisGroup.  There is usually only one
1901 VerticalAlignment per score but every Staff, Lyrics, etc. has its own
1902 VerticalAxisGroup.
1903
1904
1905 @node Modifying ends of spanners
1906 @subsection Modifying ends of spanners
1907
1908 @c FIXME Write this section
1909
1910 @node Modifying stencils
1911 @subsection Modifying stencils
1912
1913 @c FIXME Write this section
1914
1915
1916 @node Discussion of specific tweaks
1917 @section Discussion of specific tweaks
1918
1919 @menu
1920 * old Contexts explained::
1921 @end menu
1922
1923
1924 @node old Contexts explained
1925 @subsection old Contexts explained
1926
1927 @c FIXME Delete this section?  It is in LM
1928 @c Or leave heading and go on from LM?
1929
1930 When music is printed, a lot of notational elements must be added to the
1931 output.  For example, compare the input and output of the following example:
1932
1933 @lilypond[quote,verbatim,relative=2,fragment]
1934 cis4 cis2. g4
1935 @end lilypond
1936
1937 The input is rather sparse, but in the output, bar lines, accidentals,
1938 clef, and time signature are added.  LilyPond @emph{interprets} the
1939 input.  During this step, the musical information is inspected in time
1940 order, similar to reading a score from left to right.  While reading
1941 the input, the program remembers where measure boundaries are, and which
1942 pitches require explicit accidentals.  This information can be presented on
1943 several levels.  For example, the effect of an accidental is limited
1944 to a single staff, while a bar line must be synchronized across the
1945 entire score.
1946
1947 Within LilyPond, these rules and bits of information are grouped in
1948 @emph{Contexts}.  Some examples of contexts are @code{Voice},
1949 @code{Staff}, and @code{Score}.  They are hierarchical, for
1950 example: a @code{Staff} can contain many @code{Voice}s, and a
1951 @code{Score} can contain many @code{Staff} contexts.
1952
1953 @quotation
1954 @sourceimage{context-example,5cm,,}
1955 @end quotation
1956
1957 Each context has the responsibility for enforcing some notation rules,
1958 creating some notation objects and maintaining the associated
1959 properties.  For example, the @code{Voice} context may introduce an
1960 accidental and then the @code{Staff} context maintains the rule to
1961 show or suppress the accidental for the remainder of the measure.  The
1962 synchronization of bar lines is handled at @code{Score} context.
1963
1964 However, in some music we may not want the bar lines to be
1965 synchronized -- consider a polymetric score in 4/4 and 3/4 time.  In
1966 such cases, we must modify the default settings of the @code{Score}
1967 and @code{Staff} contexts.
1968
1969 For very simple scores, contexts are created implicitly, and you need
1970 not be aware of them.  For larger pieces, such as anything with more
1971 than one staff, they must be
1972 created explicitly to make sure that you get as many staves as you
1973 need, and that they are in the correct order.  For typesetting pieces
1974 with specialized notation, it can be useful to modify existing or
1975 to define new contexts.
1976
1977
1978 A complete description of all available contexts is in the program
1979 reference, see
1980 @ifhtml
1981 @rinternals{Contexts}.
1982 @end ifhtml
1983 @ifnothtml
1984 Translation @expansion{} Context.
1985 @end ifnothtml
1986
1987 @c [TODO: describe propagation]
1988
1989
1990