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