]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/changing-defaults.itely
* input/regression/new-markup-scheme.ly: oops. font-family=music
[lilypond.git] / Documentation / user / changing-defaults.itely
1 @c -*- coding: latin-1; mode: texinfo; -*-
2 @node Changing defaults
3 @chapter Changing defaults
4
5
6 The purpose of LilyPond's design is to provide the finest output
7 quality as a default.  Nevertheless, it may happen that you need to
8 change this default layout.  The layout is controlled through a large
9 number of proverbial ``knobs and switches.''  This chapter does not
10 list each and every knob.  Rather, it outlines what groups of controls
11 are available and explains how to lookup which knob to use for a
12 particular effect.
13
14
15 @cindex Program reference
16
17 The controls available for tuning are described in a separate
18 document, the @internalsref{Program reference} manual.  That manual
19 lists all different variables, functions and options available in
20 LilyPond.  It is written as a HTML document, which is available
21 @uref{http://@/lilypond@/.org/@/doc/@/Documentation/@/user/@/out@/-www/@/lilypond@/-internals/,on@/-line},
22 but is also included with the LilyPond documentation package.
23
24 There are three areas where the default settings may be changed:
25
26 @itemize @bullet
27 @item
28 Output: changing the appearance of individual
29 objects.  For example, changing stem directions or the location of
30 subscripts.
31   
32 @item
33 Context: changing aspects of the translation from music events to
34 notation.  For example, giving each staff a separate time signature. 
35   
36 @item
37 Global layout: changing the appearance of the spacing, line
38 breaks, and page dimensions.
39 @end itemize
40
41 Then there are separate systems for typesetting text (like
42 @emph{ritardando}) and selecting different fonts.  This chapter also
43 discusses these.
44
45 Internally, LilyPond uses Scheme (a LISP dialect) to provide
46 infrastructure.  Overriding layout decisions in effect accesses the
47 program internals, which requires Scheme input.  Scheme elements are
48 introduced in a @code{.ly} file with the hash mark
49 @code{#}.@footnote{@ref{Scheme tutorial} contains a short tutorial
50 on entering numbers, lists, strings, and symbols in Scheme.}
51
52
53 @menu
54 * Interpretation contexts::     
55 * The \override command::       
56 * Fonts::                       
57 * Text markup::                 
58 * Global layout::               
59 * File structure::              
60 @end menu
61
62  
63 @node Interpretation contexts
64 @section Interpretation contexts
65
66 When music is printed, a lot of notational elements must be added to the
67 input, which is often bare bones.  For example, compare the input and
68 output of the following example:
69
70 @lilypond[quote,verbatim,relative=2,fragment]
71 cis4 cis2. g4
72 @end lilypond
73
74 The input is rather sparse, but in the output, bar lines, accidentals,
75 clef, and time signature are added.  LilyPond @emph{interprets} the
76 input.  During this step, the musical information is inspected in time
77 order, similar to reading a score from left to right.  While reading,
78 the input, the program remembers where measure boundaries are, and what
79 pitches need explicit accidentals.  This information can be presented on
80 several levels.  For example, the effect of an accidental is limited
81 to a single staff, while a bar line must be synchronized across the
82 entire score.
83
84 Within LilyPond, these rules and bits of information are grouped in
85 so-called Contexts.  Examples of context are @context{Voice},
86 @context{Staff}, and @context{Score}.  They are hierarchical, for
87 example, a @context{Staff} can contain many @context{Voice}s, and a
88 @context{Score} can contain many @context{Staff} contexts.
89
90 Each context has the responsibility for enforcing some notation rules,
91 creating some notation objects and maintaining the associated
92 properties.  So, the synchronization of bar lines is handled at
93 @context{Score} context.  The @context{Voice} may introduce an
94 accidental and then the @context{Staff} context maintains the rule to
95 show or suppress the accidental for the remainder of the measure.
96
97 For simple scores, contexts are created implicitly, and you need not
98 be aware of them.  For larger pieces, such as piano music, they must be
99 created explicitly to make sure that you get as many staves as you
100 need, and that they are in the correct order.  For typesetting pieces
101 with specialized notation, it can be useful to modify existing or
102 to define new contexts.
103
104
105 A complete description of all available contexts is in the program
106 reference, see
107 @ifhtml
108 @internalsref{Contexts}.
109 @end ifhtml
110 @ifnothtml 
111 Translation @arrow{} Context.
112 @end ifnothtml
113
114 @c [TODO: describe propagation]
115
116
117 @menu
118 * Creating contexts::           
119 * Changing context properties on the fly::  
120 * Modifying context plug-ins::  
121 * Layout tunings within contexts::  
122 * Changing context default settings::  
123 * Defining new contexts::      
124 @end menu
125
126 @node Creating contexts
127 @subsection Creating contexts
128
129 For scores with only one voice and one staff, correct contexts are
130 created automatically.  For more complex scores, it is necessary to
131 create them by hand.  There are three commands that do this.
132
133 The easiest command is @code{\new}, and it also the quickest to type.
134 It is prepended to a music expression, for example
135
136 @cindex @code{\new}
137 @cindex new contexts
138 @cindex Context, creating
139
140 @example
141 \new @var{type} @var{music expression}
142 @end example
143
144 @noindent
145 where @var{type} is a context name (like @code{Staff} or
146 @code{Voice}).  This command creates a new context, and starts
147 interpreting the @var{music expression} with that.
148
149 A practical application of @code{\new} is a score with many
150 staves.  Each part that should be on its own staff, is preceded with 
151 @code{\new Staff}.
152
153 @lilypond[quote,verbatim,relative=2,raggedright,fragment]
154 << \new Staff { c4 c }
155    \new Staff { d4 d }
156 >>
157 @end lilypond
158
159 @cindex @code{\context}
160
161 Like @code{\new}, the @code{\context} command also directs a music
162 expression to a context object, but gives the context an extra name.  The
163 syntax is
164
165 @example
166 \context @var{type} = @var{id} @var{music}
167 @end example
168
169 This form will search for an existing context of type @var{type}
170 called @var{id}.  If that context does not exist yet, it is created.
171 This is useful if the context is referred to later on.  For example, when
172 setting lyrics the melody is in a named context
173
174 @example
175 \context Voice = "@b{tenor}" @var{music}
176 @end example
177
178 @noindent
179 so the texts can be properly aligned to its notes,
180
181 @example
182 \new Lyrics \lyricsto "@b{tenor}" @var{lyrics} 
183 @end example
184
185 @noindent
186
187 Another possibility is funneling two different music expressions into
188 one context.  In the following example, articulations and notes are
189 entered separately,
190
191 @example
192 music = @{ c4 c4 @}
193 arts = @{ s4-. s4-> @}
194 @end example
195
196 They are combined by sending both to the same @context{Voice} context,
197
198 @example
199 << \new Staff \context Voice = "A" \music
200    \context Voice = "A" \arts
201 >>
202 @end example
203 @lilypond[quote,raggedright]
204 music = { c4 c4 }
205 arts = { s4-. s4-> }
206 \relative c'' <<
207   \new Staff \context Voice = "A" \music
208   \context Voice = "A" \arts
209 >>
210 @end lilypond
211
212 With this mechanism, it is possible to define an Urtext (original
213 edition), with the option to put several distinct articulations on the
214 same notes.
215
216 @cindex @code{\context}
217 @cindex creating contexts
218
219 The third command for creating contexts is
220 @example
221 \context @var{type} @var{music}
222 @end example
223
224
225 @noindent
226 This is similar to @code{\context} with @code{= @var{id}}, but matches
227 any context of type @var{type}, regardless of its given name.
228
229 This variant is used with music expressions that can be interpreted at
230 several levels.  For example, the @code{\applyoutput} command (see
231 @ref{Running a function on all layout objects}).  Without an explicit
232 @code{\context}, it is usually applied to @context{Voice}
233
234 @example
235 \applyoutput #@var{function}   % apply to Voice
236 @end example
237
238 To have it interpreted at the @context{Score} or @context{Staff} level use
239 these forms
240
241 @example
242 \context Score \applyoutput #@var{function}
243 \context Staff \applyoutput #@var{function}
244 @end example
245
246
247 @node Changing context properties on the fly
248 @subsection Changing context properties on the fly
249
250 @cindex properties
251 @cindex @code{\set}
252 @cindex changing properties
253
254 Each context can have different @emph{properties}, variables contained
255 in that context.  They can be changed during the interpretation step.
256 This is achieved by inserting the @code{\set} command in the music,
257
258 @example
259 \set @var{context}.@var{prop} = #@var{value}
260 @end example
261
262 For example,
263 @lilypond[quote,verbatim,relative=2,fragment]
264 R1*2 
265 \set Score.skipBars = ##t
266 R1*2
267 @end lilypond
268
269 This command skips measures that have no notes.  The result is that
270 multi-rests are condensed.  The value assigned is a Scheme object.  In
271 this case, it is @code{#t}, the boolean True value.
272
273 If the @var{context} argument is left out, then the current bottom-most
274 context (typically @context{ChordNames}, @context{Voice}, or
275 @context{Lyrics}) is used.  In this example,
276
277 @lilypond[quote,verbatim,relative=2,fragment]
278 c8 c c c
279 \set autoBeaming = ##f
280 c8 c c c
281 @end lilypond
282
283 @noindent
284 the @var{context} argument to @code{\set} is left out, so automatic
285 beaming is switched off in the current @internalsref{Voice}.  Note that
286 the bottom-most context does not always contain the property that you
287 wish to change -- for example, attempting to set the @code{skipBars}
288 property (of the bottom-most context, in this case @code{Voice}) will
289 have no effect.
290
291 @lilypond[quote,verbatim,relative=2,fragment]
292 R1*2 
293 \set skipBars = ##t
294 R1*2
295 @end lilypond
296
297 Contexts are hierarchical, so if a bigger context was specified, for
298 example @context{Staff}, then the change would also apply to all
299 @context{Voice}s in the current stave.  The change is applied
300 `on-the-fly', during the music, so that the setting only affects the
301 second group of eighth notes.
302
303 @cindex @code{\unset} 
304
305 There is also an @code{\unset} command,
306 @example
307 \unset @var{context}.@var{prop}
308 @end example
309
310 @noindent
311 which removes the definition of @var{prop}.  This command removes
312 the definition only if it is set in @var{context}, so
313
314 @example
315 \set Staff.autoBeaming = ##f
316 @end example
317
318 @noindent
319 introduces a property setting at @code{Staff} level.  The setting also
320 applies to the current @code{Voice}.  However,
321
322 @example
323 \unset Voice.autoBeaming
324 @end example
325
326 @noindent
327 does not have any effect.  To cancel this setting, the @code{\unset}
328 must be specified on the same level as the original @code{\set}.  In
329 other words, undoing the effect of @code{Staff.autoBeaming = ##f}
330 requires
331 @example
332 \unset Staff.autoBeaming
333 @end example
334
335 Like @code{\set}, the @var{context} argument does not have to be
336 specified for a bottom context, so the two statements
337
338 @example
339 \set Voice.autoBeaming = ##t 
340 \set autoBeaming = ##t 
341 @end example 
342
343 @noindent
344 are equivalent.
345
346
347 @cindex \once
348 Settings that should only apply to a single time-step can be entered
349 with @code{\once}, for example in
350
351 @lilypond[quote,verbatim,relative=2,fragment]
352 c4
353 \once \set fontSize = #4.7
354 c4
355 c4
356 @end lilypond
357
358 the property @code{fontSize} is unset automatically after the second
359 note.
360
361 A full description of all available context properties is in the
362 program reference, see
363 @ifhtml
364 @internalsref{Tunable context properties}.
365 @end ifhtml
366 @ifnothtml
367 Translation @arrow{} Tunable context properties.
368 @end ifnothtml
369
370
371 @node Modifying context plug-ins
372 @subsection Modifying context plug-ins
373
374 Notation contexts (like Score and Staff) not only store properties,
375 they also contain plug-ins, called ``engravers'' that create notation
376 elements.  For example, the Voice context contains a
377 @code{Note_head_engraver} and the Staff context contains a
378 @code{Key_signature_engraver}.
379
380 For a full a description of each plug-in, see 
381 @ifhtml
382 @internalsref{Engravers}.
383 @end ifhtml
384 @ifnothtml
385 Program reference @arrow Translation @arrow{} Engravers.
386 @end ifnothtml
387 Every context described in
388 @ifhtml
389 @internalsref{Contexts}
390 @end ifhtml
391 @ifnothtml 
392 Program reference @arrow Translation @arrow{} Context.
393 @end ifnothtml
394 lists the engravers used for that context.
395
396
397 It can be useful to shuffle around these plug-ins.  This is done by
398 starting a new context, with @code{\new} or @code{\context}, and
399 modifying it like this, 
400
401 @example
402 \new @var{context} \with @{
403   \consists @dots{}
404   \consists @dots{}
405   \remove @dots{}
406   \remove @dots{}
407   @emph{etc.}
408 @}
409 @emph{..music..}
410 @end example
411
412 @noindent
413 where the @dots{} should be the name of an engraver.  Here is a simple
414 example which removes @code{Time_signature_engraver} and
415 @code{Clef_engraver} from a @code{Staff} context,
416
417 @lilypond[quote,relative=1,verbatim,fragment]
418 << \new Staff {
419     f2 g
420   }
421   \new Staff \with {
422      \remove "Time_signature_engraver"
423      \remove "Clef_engraver"
424   } {
425     f2 g2
426   }
427 >>
428 @end lilypond
429
430 In the second staff there are no time signature or clef symbols.  This
431 is a rather crude method of making objects disappear since it will affect
432 the entire staff.  The spacing is adversely influenced too.  A more
433 sophisticated method of blanking objects is shown in @ref{Common tweaks}.
434
435 The next example shows a practical application.  Bar lines and time
436 signatures are normally synchronized across the score.  This is done
437 by the @code{Timing_engraver}.  This plug-in keeps an administration of
438 time signature, location within the measure, etc.  By moving the
439 @code{Timing_engraver} engraver from @code{Score} to @code{Staff}
440 context, we can have a score where each staff has its own time
441 signature.
442
443 @cindex polymetric scores
444 @cindex Time signatures, multiple
445
446 @lilypond[quote,relative=1,raggedright,verbatim,fragment]
447 \new Score \with {
448   \remove "Timing_engraver"
449 } <<
450   \new Staff \with {
451     \consists "Timing_engraver"
452   } {
453       \time 3/4
454       c4 c c c c c
455   }
456   \new Staff \with {
457     \consists "Timing_engraver"
458   } {
459        \time 2/4
460        c4 c c c c c
461   }
462 >>
463 @end lilypond
464
465
466 @node Layout tunings within contexts
467 @subsection Layout tunings within contexts
468
469 Each context is responsible for creating certain types of graphical
470 objects.  The settings used for printing these objects are also stored by
471 context.  By changing these settings, the appearance of objects can be
472 altered.
473  
474 The syntax for this is
475
476 @example
477 \override @var{context}.@var{name} #'@var{property} = #@var{value}
478 @end example
479
480 Here @var{name} is the name of a graphical object, like @code{Stem} or
481 @code{NoteHead}, and @var{property} is an internal variable of the
482 formatting system (`grob property' or `layout property').  The latter is a
483 symbol, so it must be quoted.  The subsection @ref{Constructing a
484 tweak} explains what to fill in for @var{name}, @var{property}, and
485 @var{value}.  Here we only discuss the functionality of this command.
486
487 The command
488
489 @verbatim
490 \override Staff.Stem #'thickness = #4.0 
491 @end verbatim
492
493 @noindent
494 makes stems thicker (the default is 1.3, with staff line thickness as a
495 unit).  Since the command specifies @context{Staff} as context, it only
496 applies to the current staff.  Other staves will keep their normal
497 appearance.  Here we see the command in action:
498
499 @lilypond[quote,verbatim,relative=2,fragment]
500 c4
501 \override Staff.Stem #'thickness = #4.0 
502 c4
503 c4
504 c4
505 @end lilypond
506
507 The @code{\override} command changes the definition of the @code{Stem}
508 within the current @context{Staff}.  After the command is interpreted
509 all stems are thickened.
510
511 Analogous to @code{\set}, the @var{context} argument may be left out,
512 causing it to default to @context{Voice}, and adding @code{\once} applies
513 the change during one timestep only 
514
515 @lilypond[quote,fragment,verbatim,relative=2]
516 c4
517 \once \override Stem #'thickness = #4.0 
518 c4
519 c4 
520 @end lilypond
521
522 The @code{\override} must be done before the object is
523 started.  Therefore, when altering @emph{Spanner} objects, like slurs or
524 beams, the @code{\override} command must be executed at the moment when
525 the object is created.  In this example,
526
527
528 @lilypond[quote,fragment,verbatim,relative=2]
529 \override Slur #'thickness = #3.0
530 c8[( c
531 \override Beam #'thickness = #0.6
532 c8 c]) 
533 @end lilypond
534
535 @noindent
536 the slur is fatter but the beam is not.  This is because the command for
537 @code{Beam} comes after the Beam is started.  Therefore it has no effect.
538
539 Analogous to @code{\unset}, the @code{\revert} command for a context
540 undoes an @code{\override} command; like with @code{\unset}, it only
541 affects settings that were made in the same context.  In other words, the
542 @code{\revert} in the next example does not do anything.
543
544 @example
545 \override Voice.Stem #'thickness = #4.0
546 \revert Staff.Stem #'thickness
547 @end example
548
549
550
551
552 @seealso
553
554 Internals: @internalsref{OverrideProperty}, @internalsref{RevertProperty},
555 @internalsref{PropertySet}, @internalsref{All-backend-properties}, and
556 @internalsref{All layout objects}.
557
558
559 @refbugs
560
561 The back-end is not very strict in type-checking object properties.
562 Cyclic references in Scheme values for properties can cause hangs
563 or crashes, or both.
564
565
566 @node Changing context default settings
567 @subsection Changing context default settings
568
569 The adjustments of the previous subsections (@ref{Changing context
570 properties on the fly}, @ref{Modifying context plug-ins}, and
571 @ref{Layout tunings within contexts}) can also be entered separately
572 from the music, in the @code{\layout} block,
573
574 @example
575 \layout @{
576   @dots{}
577   \context @{
578     \Staff
579
580     \set fontSize = #-2
581     \override Stem #'thickness = #4.0
582     \remove "Time_signature_engraver"
583   @}
584 @}
585 @end example
586
587 Here
588 @example
589 \Staff
590 @end example
591
592 @noindent
593 takes the existing definition for context @context{Staff} from the
594 identifier @code{\Staff}. 
595
596 The statements
597 @example
598 \set fontSize = #-2
599 \override Stem #'thickness = #4.0
600 \remove "Time_signature_engraver"
601 @end example
602
603 @noindent
604 affect all staves in the score.
605
606 Other contexts can be modified analogously.
607
608 The @code{\set} keyword is optional within the @code{\layout} block, so
609
610 @example
611 \context @{
612   @dots{}
613   fontSize = #-2
614 @}
615 @end example
616
617 @noindent
618 will also work.
619
620
621
622 @refbugs
623
624 It is not possible to collect context changes in a variable, and apply
625 them to one @code{\context} definition by referring to that variable.
626
627
628 @node Defining new contexts
629 @subsection Defining new contexts
630
631 Specific contexts, like @context{Staff} and @code{Voice}, are made of
632 simple building blocks, and it is possible to compose engraver
633 plug-ins in different combinations, thereby creating new types of
634 contexts.
635
636 The next example shows how to build a different type of
637 @context{Voice} context from scratch.  It will be similar to
638 @code{Voice}, but prints centered slash noteheads only.  It can be used
639 to indicate improvisation in Jazz pieces,
640
641 @lilypond[quote,raggedright]
642 \layout { \context {
643   \name ImproVoice
644   \type "Engraver_group_engraver"
645   \consists "Note_heads_engraver"
646   \consists "Text_engraver"
647   \consists Pitch_squash_engraver
648   squashedPosition = #0
649   \override NoteHead #'style = #'slash
650   \override Stem #'transparent = ##t
651   \alias Voice
652 }
653 \context { \Staff
654   \accepts "ImproVoice"
655 }}
656
657 \relative c'' {
658   a4 d8 bes8 \new ImproVoice { c4^"ad lib" c 
659    c4 c^"undress" c_"while playing :)" c } 
660   a1 
661 }
662 @end lilypond
663
664
665 These settings are again done within a @code{\context} block inside a
666 @code{\layout} block,
667
668 @example
669 \layout @{
670   \context @{
671     @dots{}
672   @}
673 @}
674 @end example
675
676 In the following discussion, the example input shown should go on the
677 @dots{} in the previous fragment.
678
679 First, the context gets a name.  Instead of @context{Voice} it
680 will be called @context{ImproVoice},
681
682 @example
683 \name ImproVoice
684 @end example
685
686 Since it is similar to the @context{Voice}, we want commands that work
687 on (existing) @context{Voice}s to remain working.  This is achieved by
688 giving the new context an alias @context{Voice},
689
690 @example
691 \alias Voice
692 @end example
693
694 The context will print notes, and instructive texts
695
696 @example
697 \consists Note_heads_engraver
698 \consists Text_engraver
699 @end example
700
701 but only on the center line,
702
703 @example
704 \consists Pitch_squash_engraver
705 squashedPosition = #0
706 @end example
707
708 The @internalsref{Pitch_squash_engraver} modifies note heads (created
709 by @internalsref{Note_heads_engraver}) and sets their vertical
710 position to the value of @code{squashedPosition}, in this case@tie{}@code{0},
711 the center line.
712
713 The notes look like a slash, without a stem,
714
715 @example
716 \override NoteHead #'style = #'slash
717 \override Stem #'transparent = ##t
718 @end example
719
720
721 All these plug-ins have to cooperate, and this is achieved with a
722 special plug-in, which must be marked with the keyword @code{\type}.
723 This should always be @internalsref{Engraver_group_engraver},
724
725 @example
726 \type "Engraver_group_engraver"
727 @end example
728
729 Put together, we get
730
731 @example
732 \context @{
733   \name ImproVoice
734   \type "Engraver_group_engraver"
735   \consists "Note_heads_engraver"
736   \consists "Text_engraver"
737   \consists Pitch_squash_engraver
738   squashedPosition = #0
739   \override NoteHead #'style = #'slash
740   \override Stem #'transparent = ##t
741   \alias Voice
742 @}
743 @end example
744
745 Contexts form hierarchies.  We want to hang the @context{ImproVoice}
746 under @context{Staff}, just like normal @code{Voice}s.  Therefore, we
747 modify the @code{Staff} definition with the @code{\accepts}
748 command,@footnote{The opposite of @code{\accepts} is @code{\denies},
749 which is sometimes needed when reusing existing context definitions.}
750
751
752
753 @example
754 \context @{
755   \Staff
756   \accepts ImproVoice    
757 @}
758 @end example
759
760 Putting both into a @code{\layout} block, like
761
762 @example
763 \layout @{
764   \context @{
765     \name ImproVoice
766     @dots{}
767   @}
768   \context @{
769     \Staff
770     \accepts "ImproVoice"
771   @}
772 @}
773 @end example
774
775 Then the output at the start of this subsection can be entered as
776
777 @example
778 \relative c'' @{
779   a4 d8 bes8
780   \new ImproVoice @{
781     c4^"ad lib" c 
782     c4 c^"undress"
783     c c_"while playing :)"
784   @}
785   a1
786 @}
787 @end example
788   
789
790     
791
792 @node The \override command
793 @section The \override command
794
795 In the previous section, we have already touched on a command that
796 changes layout details: the @code{\override} command.  In this section,
797 we will look in more detail at how to use the command in practice.
798 First, we will give a few versatile commands that are sufficient
799 for many situations.  The next section will discuss the general use of
800 @code{\override}.
801
802
803 @menu
804 * Common tweaks::               
805 * Constructing a tweak::        
806 * Navigating the program reference::  
807 * Layout interfaces::           
808 * Determining the grob property::  
809 * Difficult tweaks::            
810 @end menu
811
812
813
814 @node Common tweaks
815 @subsection Common tweaks
816
817 @c  Should we point at ly/property-init.ly ?  -gp
818 Some overrides are so common that predefined commands are provided as
819 short-cuts, for example, @code{\slurUp} and @code{\stemDown}.  These
820 commands are described in
821 @ifhtml
822 the
823 @end ifhtml
824 @ref{Notation manual}, under the sections for slurs and stems
825 respectively.
826
827 The exact tuning possibilities for each type of layout object are
828 documented in the program reference of the respective
829 object.  However, many layout objects share properties, which can be
830 used to apply generic tweaks.  We mention a few of these:
831
832 @itemize @bullet
833 @item The @code{extra-offset} property, which
834 @cindex @code{extra-offset}
835 has a pair of numbers as value, moves objects around in the printout.
836 The first number controls left-right movement; a positive number will
837 move the object to the right.  The second number controls up-down
838 movement; a positive number will move it higher.  The units of these
839 offsets are staff-spaces.  The @code{extra-offset} property is a
840 low-level feature: the formatting engine is completely oblivious to
841 these offsets.
842
843 In the following example, the second fingering is moved a little to
844 the left, and 1.8 staff space downwards:
845
846 @cindex setting object properties
847
848 @lilypond[quote,fragment,relative=1,verbatim]
849 \stemUp
850 f-5
851 \once \override Fingering
852     #'extra-offset = #'(-0.3 . -1.8) 
853 f-5
854 @end lilypond
855
856 @item
857 Setting the @code{transparent} property will cause an object to be printed
858 in `invisible ink': the object is not printed, but all its other
859 behavior is retained.  The object still takes up space, it takes part in
860 collisions, and slurs, ties, and beams can be attached to it.
861
862 @cindex transparent objects
863 @cindex removing objects
864 @cindex hiding objects
865 @cindex invisible objects
866 The following example demonstrates how to connect different voices
867 using ties.  Normally, ties only connect two notes in the same
868 voice.  By introducing a tie in a different voice,
869
870 @lilypond[quote,fragment,relative=2]
871 << {
872   b8~ b8\noBeam
873 } \\ {
874   b[ g8]
875 } >>
876 @end lilypond
877
878 @noindent
879 and blanking the first up-stem in that voice, the tie appears to cross
880 voices:
881
882 @lilypond[quote,fragment,relative=2,verbatim]
883 << {
884   \once \override Stem #'transparent = ##t
885   b8~ b8\noBeam
886 } \\ {
887   b[ g8]
888 } >>
889 @end lilypond
890
891 @item
892 The @code{padding} property for objects with
893 @cindex @code{padding}
894 @code{side-position-interface} can be set to increase the distance between
895 symbols that are printed above or below notes.  We only give an
896 example; a more elaborate explanation is in @ref{Constructing a
897 tweak}:
898
899 @lilypond[quote,fragment,relative=1,verbatim]
900 c2\fermata
901 \override Script #'padding = #3
902 b2\fermata
903 @end lilypond
904
905 @end itemize
906
907 More specific overrides are also possible.  The next section
908 discusses in depth how to figure out these statements for yourself.
909
910
911 @node Constructing a tweak
912 @subsection Constructing a tweak
913
914 The general procedure of changing output, that is, entering
915 a command like
916
917 @example
918 \override Voice.Stem #'thickness = #3.0
919 @end example
920
921 @noindent
922 means that we have to determine these bits of information:
923
924 @itemize
925 @item the context: here @context{Voice}.
926 @item the layout object: here @code{Stem}.
927 @item the layout property: here @code{thickness}
928 @item a sensible value: here @code{3.0}
929 @end itemize  
930
931
932 @cindex internal documentation
933 @cindex finding graphical objects
934 @cindex graphical object descriptions 
935 @cindex tweaking
936 @cindex @code{\override}
937 @cindex internal documentation
938
939 We demonstrate how to glean this information from the notation manual
940 and the program reference.
941
942 @node Navigating the program reference
943 @subsection Navigating the program reference
944
945 Suppose we want to move the fingering indication in the fragment
946 below:
947
948 @lilypond[quote,fragment,relative=2,verbatim]
949 c-2
950 \stemUp
951 f
952 @end lilypond
953
954 If you visit the documentation on fingering instructions (in
955 @ref{Fingering instructions}), you will notice that there is written:
956
957 @quotation
958 @seealso
959
960 Program reference: @internalsref{FingerEvent} and @internalsref{Fingering}.
961
962 @end quotation
963
964
965
966 This fragment points to two parts of the program reference: a page
967 on @code{FingerEvent} and one on @code{Fingering}.
968
969 The page on @code{FingerEvent} describes the properties of the music
970 expression for the input @code{-2}.  The page contains many links
971 forward.  For example, it says
972
973 @quotation
974 Accepted by: @internalsref{Fingering_engraver},
975 @end quotation 
976
977 @noindent
978 That link brings us to the documentation for the Engraver, the
979 plug-in, which says
980
981 @quotation
982 This engraver creates the following layout objects: @internalsref{Fingering}.
983 @end quotation
984
985 In other words, once the @code{FingerEvent}s are interpreted, the
986 @code{Fingering_engraver} plug-in will process them.
987 The @code{Fingering_engraver} is also listed to create
988 @internalsref{Fingering} objects,
989
990
991 Lo and behold, that is also the
992 second bit of information listed under @b{See also} in the Notation
993 manual.  By clicking around in the program reference, we can follow the
994 flow of information within the program, either forward (like we did
995 here), or backwards, following links like this:
996
997 @itemize @bullet
998
999 @item @internalsref{Fingering}:
1000 @internalsref{Fingering} objects are created by:
1001 @b{@internalsref{Fingering_engraver}}
1002
1003 @item @internalsref{Fingering_engraver}:
1004 Music types accepted: @b{@internalsref{fingering-event}}
1005
1006 @item @internalsref{fingering-event}:
1007 Music event type @code{fingering-event} is in Music expressions named
1008 @b{@internalsref{FingerEvent}}
1009 @end itemize
1010
1011 This path goes against the flow of information in the program: it
1012 starts from the output, and ends at the input event.
1013
1014 The program reference can also be browsed like a normal document.  It
1015 contains a chapter on
1016 @ifhtml
1017 @internalsref{Music definitions},
1018 @end ifhtml
1019 @ifnothtml
1020 @code{Music definitions}
1021 @end ifnothtml
1022 on @internalsref{Translation}, and the @internalsref{Backend}.  Every
1023 chapter lists all the definitions used, and all properties that may be
1024 tuned.
1025
1026  
1027 @node Layout interfaces
1028 @subsection Layout interfaces
1029
1030 @cindex interface, layout
1031 @cindex layout interface
1032
1033 The HTML page that we found in the previous section, describes the
1034 layout object called @internalsref{Fingering}.  Such an object is a
1035 symbol within the score.  It has properties that store numbers (like
1036 thicknesses and directions), but also pointers to related objects.  A
1037 layout object is also called @emph{grob},
1038 @cindex grob
1039 which is short for Graphical Object.
1040
1041
1042 The page for @code{Fingering} lists the definitions for the
1043 @code{Fingering} object.  For example, the page says
1044
1045 @quotation
1046 @code{padding} (dimension, in staff space):
1047   
1048 @code{0.6}
1049 @end quotation
1050
1051 @noindent
1052 which means that the number will be kept at a distance of at least 0.6
1053 of the note head.
1054
1055
1056 Each layout object may have several functions as a notational or
1057 typographical element.  For example, the Fingering object
1058 has the following aspects
1059
1060 @itemize @bullet
1061 @item
1062 Its size is independent of the horizontal spacing, unlike slurs or beams.
1063
1064 @item
1065 It is a piece of text.  Granted, it is usually a very short text.
1066
1067 @item
1068 That piece of text is typeset with a font, unlike slurs or beams.
1069
1070 @item
1071 Horizontally, the center of the symbol should be aligned to the
1072 center of the notehead.
1073
1074 @item
1075 Vertically, the symbol is placed next to the note and the staff.
1076
1077 @item
1078 The vertical position is also coordinated with other super- and subscript
1079 symbols.
1080 @end itemize
1081
1082 Each of these aspects is captured in so-called @emph{interface}s,
1083 which are listed on the @internalsref{Fingering} page at the bottom
1084
1085 @quotation
1086 This object supports the following interfaces:
1087 @internalsref{item-interface},
1088 @internalsref{self-alignment-interface},
1089 @internalsref{side-position-interface}, @internalsref{text-interface},
1090 @internalsref{text-script-interface}, @internalsref{font-interface},
1091 @internalsref{finger-interface}, and @internalsref{grob-interface}.
1092 @end quotation
1093
1094 Clicking any of the links will take you to the page of the respective
1095 object interface.  Each interface has a number of properties.  Some of
1096 them are not user-serviceable (``Internal properties''), but others
1097 are.
1098
1099 We have been talking of @emph{the} @code{Fingering} object, but actually it
1100 does not amount to much.  The initialization file
1101 @file{scm/@/define@/-grobs@/.scm} shows the soul of the `object',
1102
1103 @example
1104 (Fingering
1105   . ((print-function . ,Text_interface::print)
1106      (padding . 0.6)
1107      (staff-padding . 0.6)
1108      (self-alignment-X . 0)
1109      (self-alignment-Y . 0)
1110      (script-priority . 100)
1111      (font-encoding . number)
1112      (font-size . -5)
1113      (meta . ((interfaces . (finger-interface font-interface
1114                              text-script-interface text-interface
1115                              side-position-interface
1116                              self-alignment-interface
1117                              item-interface))))))
1118 @end example
1119
1120 @noindent
1121 As you can see, the @code{Fingering} object is nothing more than a
1122 bunch of variable settings, and the webpage in the Program Reference
1123 is directly generated from this definition.
1124
1125 @node Determining the grob property
1126 @subsection Determining the grob property
1127
1128
1129 Recall that we wanted to change the position of the @b{2} in 
1130
1131 @lilypond[quote,fragment,relative=2,verbatim]
1132 c-2
1133 \stemUp
1134 f
1135 @end lilypond
1136
1137 Since the @b{2} is vertically positioned next to its note, we have to
1138 meddle with the interface associated with this positioning.  This is
1139 done using @code{side-position-interface}.  The page for this interface 
1140 says
1141
1142 @quotation
1143 @code{side-position-interface}
1144
1145 Position a victim object (this one) next to other objects (the
1146 support).  The property @code{direction} signifies where to put the
1147 victim object relative to the support (left or right, up or down?)
1148 @end quotation
1149
1150 @cindex padding
1151 @noindent
1152 below this description, the variable @code{padding} is described as
1153
1154 @quotation
1155 @table @code
1156 @item padding
1157 (dimension, in staff space)
1158
1159 Add this much extra space between objects that are next to each other. 
1160 @end table
1161 @end quotation
1162
1163 By increasing the value of @code{padding}, we can move away the
1164 fingering.  The following command inserts 3 staff spaces of white
1165 between the note and the fingering:
1166 @example
1167 \once \override Voice.Fingering #'padding = #3
1168 @end example
1169
1170 Inserting this command before the Fingering object is created,
1171 i.e., before @code{c2}, yields the following result:
1172
1173 @lilypond[quote,relative=2,fragment,verbatim]
1174 \once \override Voice.Fingering #'padding = #3
1175 c-2
1176 \stemUp
1177 f
1178 @end lilypond
1179
1180
1181 In this case, the context for this tweak is @context{Voice}.  This
1182 fact can also be deduced from the program reference, for the page for
1183 the @internalsref{Fingering_engraver} plug-in says
1184
1185 @quotation
1186 Fingering_engraver is part of contexts: @dots{} @b{@internalsref{Voice}}
1187 @end quotation
1188
1189 @node Difficult tweaks
1190 @subsection Difficult tweaks
1191
1192 There are two classes of difficult adjustments.  First, when there are
1193 several of the same objects at one point, and you want to adjust only
1194 one.  For example, if you want to change only one note head in a chord.
1195
1196 In this case, the @code{\applyoutput} function must be used.  The
1197 next example defines a Scheme function @code{set-position-font-size}
1198 that sets the @code{font-size} property, but only  
1199 on objects that have @internalsref{note-head-interface} and are at the
1200 right Y-position.
1201
1202 @lilypond[quote,verbatim]
1203 #(define ((set-position-font-size pos size) grob origin current)
1204   (let*
1205       ((interfaces (ly:grob-property grob 'interfaces))
1206        (position (ly:grob-property grob 'staff-position)))
1207    (if (and
1208         ; is this a note head?
1209         (memq 'note-head-interface interfaces)
1210
1211         ; is the Y coordinate right?
1212         (= pos position))
1213
1214       ; then do it.
1215       (set! (ly:grob-property grob 'font-size) size))))
1216
1217 \relative {
1218   c
1219   \applyoutput #(set-position-font-size -2 4)
1220   <c e g>
1221 }
1222 @end lilypond
1223
1224 @noindent
1225 A similar technique can be used for accidentals.  In that case, the
1226 function should check for @code{accidental-interface}.
1227
1228 Another difficult adjustment is the appearance of spanner objects,
1229 such as slur and tie.  Initially, only one of these objects is created,
1230 and they can be adjusted with the normal mechanism.  However, in some
1231 cases the spanners cross line breaks.  If this happens, these objects
1232 are cloned.  A separate object is created for every system that it is
1233 in.  These are clones of the original object and inherit all
1234 properties, including @code{\override}s.
1235
1236 In other words, an @code{\override} always affects all pieces of a
1237 broken spanner.  To change only one part of a spanner at a line break,
1238 it is necessary to hook into the formatting process.  The
1239 @code{after-line-breaking-callback} property contains the Scheme procedure
1240 that is called after the line breaks have been determined, and layout
1241 objects have been split over different systems.
1242
1243 In the following example, we define a procedure
1244 @code{my-callback}.  This procedure
1245  
1246 @itemize @bullet
1247 @item
1248 determines if we have been split across line breaks
1249 @item
1250 if yes, retrieves all the split objects
1251 @item
1252 checks if we are the last of the split objects
1253 @item
1254 if yes, it sets @code{extra-offset}.
1255 @end itemize
1256
1257 This procedure is installed into @internalsref{Tie}, so the last part
1258 of the broken tie is translated up.
1259
1260
1261 @lilypond[quote,verbatim,raggedright]
1262 #(define (my-callback grob)
1263   (let* (
1264          ; have we been split? 
1265          (orig (ly:grob-original grob))
1266
1267          ; if yes, get the split pieces (our siblings)
1268          (siblings (if (ly:grob? orig)
1269                      (ly:spanner-broken-into orig) '() )))
1270
1271    (if (and (>= (length siblings) 2)
1272              (eq? (car (last-pair siblings)) grob))
1273      (ly:grob-set-property! grob 'extra-offset '(-2 . 5)))))
1274
1275 \relative c'' { 
1276   \override Tie #'after-line-breaking-callback =
1277   #my-callback
1278   c1 ~ \break c2 ~ c
1279 }
1280 @end lilypond
1281
1282 @noindent
1283 When applying this trick, the new @code{after-line-breaking-callback}
1284 should also call the old @code{after-line-breaking-callback}, if there
1285 is one.  For example, if using this with @code{Slur},
1286 @code{Slur::after_line_breaking} should also be called.
1287
1288 @node Fonts
1289 @section Fonts
1290
1291 This section details the ways that the font can be changed.
1292
1293 @menu
1294 * Selecting font sizes::        
1295 * Font selection::              
1296 @end menu
1297
1298
1299
1300 @node Selecting font sizes
1301 @subsection Selecting font sizes
1302
1303
1304 The easiest method of setting the font size of any context, is by
1305 setting the @code{fontSize} property.
1306
1307 @lilypond[quote,fragment,relative=1,verbatim]
1308 c8
1309 \set fontSize = #-4
1310 c f
1311 \set fontSize = #3
1312 g
1313 @end lilypond
1314
1315 @noindent
1316 It does not change the size of variable symbols, such as beams or
1317 slurs.
1318
1319 Internally, the @code{fontSize} context property will cause the
1320 @code{font-size} property to be set in all layout objects.  The value
1321 of @code{font-size} is a number indicating the size relative to the
1322 standard size for the current staff height.  Each step up is an
1323 increase of approximately 12% of the font size.  Six steps is exactly a
1324 factor two.  The Scheme function @code{magstep} converts a
1325 @code{font-size} number to a scaling factor.
1326
1327 @lilypond[quote,fragment,relative=1,verbatim]
1328 c8
1329 \override NoteHead #'font-size = #-4
1330 c f
1331 \override NoteHead #'font-size = #3
1332 g
1333 @end lilypond
1334
1335 LilyPond has fonts in different design sizes.  The music fonts for
1336 smaller sizes are chubbier, while the text fonts are relatively wider.
1337 Font size changes are achieved by scaling the design size that is
1338 closest to the desired size.  The standard font size (for
1339 @code{font-size} equals 0), depends on the standard staff height.  For
1340 a 20pt staff, a 10pt font is selected.
1341
1342 The @code{font-size} mechanism does not work for fonts selected
1343 through @code{font-name}.  These may be scaled with
1344 @code{font-magnification}.  The @code{font-size} property can only be
1345 set on layout objects that use fonts; these are the ones supporting
1346 the @internalsref{font-interface} layout interface.
1347
1348 @refcommands
1349
1350 The following commands set @code{fontSize} for the current voice:
1351
1352 @cindex @code{\tiny}
1353 @code{\tiny}, 
1354 @cindex @code{\small}
1355 @code{\small}, 
1356 @cindex @code{\normalsize}
1357 @code{\normalsize}.
1358
1359
1360
1361 @cindex magnification
1362 @cindex cue notes
1363
1364
1365 @node Font selection
1366 @subsection Font selection
1367
1368
1369
1370 @cindex font selection
1371 @cindex font magnification
1372 @cindex @code{font-interface}
1373
1374 By setting the object properties described below, you can select a
1375 font from the preconfigured font families.  LilyPond has default
1376 support for the feta music fonts and @TeX{}'s Computer Modern text
1377 fonts.
1378
1379
1380 @itemize @bullet
1381 @item @code{font-encoding}
1382 is a symbol that sets layout of the glyphs.  Choices include @code{ec}
1383 for @TeX{} EC font encoding, @code{fetaBraces} for piano staff
1384 braces, @code{fetaMusic} the standard music font, including ancient
1385 glyphs, @code{fetaDynamic} for dynamic signs and @code{fetaNumber}
1386 for the number font.
1387
1388 @item @code{font-family}
1389 is a symbol indicating the general class of the typeface.  Supported are
1390 @code{roman} (Computer Modern), @code{sans}, and @code{typewriter}.
1391   
1392 @item @code{font-shape}
1393 is a symbol indicating the shape of the font.  There are typically
1394 several font shapes available for each font family.  Choices are
1395 @code{italic}, @code{caps}, and @code{upright}.
1396
1397 @item @code{font-series}
1398 is a symbol indicating the series of the font.  There are typically
1399 several font series for each font family and shape.  Choices are
1400 @code{medium} and @code{bold}. 
1401
1402 @end itemize
1403
1404 Fonts selected in the way sketched above come from a predefined style
1405 sheet.
1406
1407 The font used for printing a object can be selected by setting
1408 @code{font-name}, e.g.,
1409 @example
1410 \override Staff.TimeSignature
1411     #'font-name = #"cmr17"
1412 @end example
1413
1414 @noindent
1415 Any font can be used, as long as it is available to @TeX{}.  Possible
1416 fonts include foreign fonts or fonts that do not belong to the
1417 Computer Modern font family.  The size of fonts selected in this way
1418 can be changed with the @code{font-magnification} property.  For
1419 example, @code{2.0} blows up all letters by a factor 2 in both
1420 directions.
1421
1422 @cindex font size
1423 @cindex font magnification
1424
1425
1426
1427 @seealso
1428
1429 Init files: @file{ly/@/declarations@/-init@/.ly} contains hints how new
1430 fonts may be added to LilyPond.
1431
1432
1433
1434 @node Text markup
1435 @section Text markup
1436 @cindex text markup
1437 @cindex markup text
1438
1439
1440 @cindex typeset text
1441
1442 The internal mechanism to typeset texts is accessed with the keyword
1443 @code{\markup}.  Within markup mode, you can enter texts similar to
1444 lyrics.  They are simply entered, while commands use the backslash @code{\}.
1445 @cindex markup
1446
1447 @lilypond[quote,verbatim,fragment,relative=1]
1448 c1^\markup { hello }
1449 c1_\markup { hi there }
1450 c1^\markup { hi \bold there, is \italic anyone home? }
1451 @end lilypond
1452
1453 @cindex font switching
1454
1455 The markup in the example demonstrates font switching commands.  The
1456 command @code{\bold} and @code{\italic} apply to the first following 
1457 word only; enclose a set of texts with braces to apply a command
1458 to more words:
1459 @example
1460 \markup @{ \bold @{ hi there @} @}
1461 @end example
1462
1463 @noindent
1464 For clarity, you can also do this for single arguments, e.g.,
1465
1466 @example
1467 \markup @{ is \italic @{ anyone @} home @}
1468 @end example
1469
1470 @cindex font size, texts
1471
1472
1473 In markup mode you can compose expressions, similar to mathematical
1474 expressions, XML documents, and music expressions. You can stack
1475 expressions grouped vertically with the command @code{\column}.
1476 Similarly, @code{\center-align} aligns texts by their center lines:
1477
1478 @lilypond[quote,verbatim,fragment,relative=1]
1479 c1^\markup { \column { a bbbb \line { c d } } }
1480 c1^\markup { \center-align { a bbbb c } }
1481 c1^\markup { \line { a b c } }
1482 @end lilypond
1483
1484
1485 Markups can be stored in variables and these variables
1486 may be attached to notes, like
1487 @example
1488 allegro = \markup @{ \bold \large @{ Allegro @} @}
1489  @{ a^\allegro b c d @}
1490 @end example
1491
1492
1493 Some objects have alignment procedures of their own, which cancel out
1494 any effects of alignments applied to their markup arguments as a
1495 whole.  For example, the @internalsref{RehearsalMark} is horizontally
1496 centered, so using @code{\mark \markup @{ \left-align .. @}} has no
1497 effect.
1498
1499 Similarly, for moving whole texts over notes with
1500 @code{\raise}, use the following trick:
1501 @lilypond[quote,verbatim]
1502 {
1503   c'^\markup { \raise #0.5 not-raised }
1504   c'^\markup { "" \raise #0.5 raised }
1505 }
1506 @end lilypond
1507
1508 On the second note, the text @code{raised} is moved relative to the
1509 empty string @code{""} which is not visible.  Alternatively, complete
1510 objects can be moved with layout properties such as @code{padding} and
1511 @code{extra-offset}.
1512
1513
1514
1515
1516 @seealso
1517
1518 Init files: @file{scm/@/new@/-markup@/.scm}.
1519
1520
1521 @refbugs
1522
1523 Kerning or generation of ligatures is only done when the @TeX{}
1524 backend is used.  In this case, LilyPond does not account for them so
1525 texts will be spaced slightly too wide.
1526
1527 Syntax errors for markup mode are confusing.
1528
1529
1530 @menu
1531 * Text encoding::               
1532 * Nested scores::               
1533 * Overview of text markup commands::  
1534 * New dynamic marks::
1535 @end menu
1536
1537 @node Text encoding
1538 @subsection Text encoding
1539
1540 [FIXME: OBSOLETE, use UTF8 for input files.]
1541
1542
1543 Texts can be entered in different encodings.  The encoding of the
1544 file can be set with @code{\encoding}.
1545
1546 @example
1547 \encoding "latin1"
1548 @end example
1549
1550 This command may be placed anywhere in the input file.  The current
1551 encoding is passed as an extra argument to @code{\markup} commands,
1552 and is passed similarly to lyric syllables.
1553
1554 If no @code{\encoding} has been specified, then the encoding is taken
1555 from the @code{\layout} block (or @code{\paper}, if @code{\layout}
1556 does not specify encoding).  The variable @code{inputencoding} may be
1557 set to a string or symbol specifying the encoding, e.g.,
1558
1559 @example
1560 \layout @{
1561   inputencoding = "latin1"
1562 @} 
1563 @end example
1564
1565 Normal strings are unaffected by @code{\encoding}.  This means that
1566 the following will usually not produce `Baßtuba' in the title.
1567
1568 @example
1569 \header @{
1570   title = "Grazing cow"
1571   instrument = "Baßtuba"
1572 @}
1573 @end example
1574
1575 @noindent
1576 Rather, you should say
1577 @example
1578 instrument = \markup @{ Baßtuba @}
1579 @end example
1580
1581 @noindent
1582 or set @code{inputencoding} in the @code{\paper} block. 
1583
1584 There is a special encoding, called @code{TeX}.  This encoding does not
1585 reencode text for the font used.  Rather, it tries to guess the width
1586 of @TeX{} commands, such as @code{\"}.  Strings encoded with @code{TeX}
1587 are passed to the output back-end verbatim.
1588
1589 @cindex encoding
1590 @cindex @code{\encoding}
1591 @cindex inputencoding
1592 @cindex @TeX{} commands in strings
1593
1594
1595 @node Nested scores
1596 @subsection Nested scores
1597
1598 It is possible to nest music inside markups, by adding a @code{\score}
1599 block to a markup expression.  Such a score must contain a @code{\layout}
1600 block.
1601
1602 @lilypond[quote,verbatim,raggedright]
1603 \relative {
1604   c4 d^\markup {
1605     \score {
1606       \relative { c4 d e f }
1607       \layout { }
1608     }
1609   }
1610   e f
1611 }
1612 @end lilypond
1613  
1614
1615
1616 @node Overview of text markup commands
1617 @subsection Overview of text markup commands
1618
1619 The following commands can all be used inside @code{\markup @{ @}}.
1620
1621 @include markup-commands.tely
1622
1623
1624 @node New dynamic marks
1625 @subsection New dynamic marks
1626
1627 It is possible to print new dynamic marks or text that should be aligned
1628 with dynamics.  Use @code{make-dynamic-script} to create these marks.
1629
1630 @cindex make-dynamic-script
1631
1632 @lilypond[quote,verbatim,raggedright]
1633 sfzp = #(make-dynamic-script "sfzp")
1634 \relative c' {
1635   c4 c c\sfzp c
1636 }
1637 @end lilypond
1638
1639
1640 @node Global layout
1641 @section Global layout
1642
1643 The global layout is determined by three factors: the page layout, the
1644 line breaks, and the spacing.  These all influence each other.  The
1645 choice of spacing determines how densely each system of music is set.
1646 This influences where line breaks are chosen, and thus ultimately, how
1647 many pages a piece of music takes.
1648
1649 Globally spoken, this procedure happens in three steps: first,
1650 flexible distances (``springs'') are chosen, based on durations.  All
1651 possible line breaking combinations are tried, and the one with the
1652 best results -- a layout that has uniform density and requires as
1653 little stretching or cramping as possible -- is chosen.
1654
1655 After spacing and linebreaking, the systems are distributed across
1656 pages, taking into account the size of the page, and the size of the
1657 titles.
1658
1659
1660
1661 @menu
1662 * Setting global staff size::   
1663 * Paper size::                  
1664 * Page layout::                 
1665 * Vertical spacing of piano staves::  
1666 * Vertical spacing::            
1667 * Horizontal spacing::          
1668 * Line length::                 
1669 * Line breaking::               
1670 * Page breaking::               
1671 * Multiple movements::          
1672 * Creating titles::             
1673 @end menu
1674
1675
1676 @node Setting global staff size
1677 @subsection Setting global staff size
1678
1679 @cindex font size, setting
1680 @cindex staff size, setting
1681 @cindex @code{layout} file
1682
1683 To set the global staff size, use @code{set-global-staff-size}.
1684
1685 @example
1686 #(set-global-staff-size 14)
1687 @end example
1688
1689 @noindent
1690 This sets the global default size to 14pt staff height and scales all
1691 fonts accordingly.
1692
1693 The Feta font provides musical symbols at eight different
1694 sizes.  Each font is tuned for a different staff size: at a smaller size
1695 the font becomes heavier, to match the relatively heavier staff lines.
1696 The recommended font sizes are listed in the following table:
1697
1698 @quotation
1699 @multitable @columnfractions .15 .2 .22 .2
1700
1701 @item @b{font name}
1702 @tab @b{staff height (pt)}
1703 @tab @b{staff height (mm)}
1704 @tab @b{use}
1705
1706 @item feta11
1707 @tab 11.22
1708 @tab 3.9 
1709 @tab pocket scores
1710
1711 @item feta13
1712 @tab 12.60
1713 @tab 4.4
1714 @tab
1715  
1716 @item feta14
1717 @tab 14.14
1718 @tab 5.0
1719 @tab 
1720
1721 @item feta16
1722 @tab 15.87
1723 @tab 5.6
1724 @tab 
1725
1726 @item feta18
1727 @tab 17.82
1728 @tab 6.3
1729 @tab song books
1730
1731 @item feta20
1732 @tab 20
1733 @tab 7.0
1734 @tab standard parts 
1735
1736 @item feta23
1737 @tab 22.45 
1738 @tab 7.9
1739 @tab 
1740
1741 @item feta26
1742 @tab 25.2 
1743 @tab 8.9
1744 @tab
1745 @c modern rental material?
1746
1747 @end multitable
1748 @end quotation
1749
1750 These fonts are available in any sizes.  The context property
1751 @code{fontSize} and the layout property @code{staff-space} (in
1752 @internalsref{StaffSymbol}) can be used to tune the size for individual
1753 staves.  The sizes of individual staves are relative to the global size.
1754
1755 @example
1756
1757 @end example
1758
1759 @seealso
1760
1761 This manual: @ref{Selecting font sizes}.
1762
1763
1764 @node Paper size
1765 @subsection Paper size
1766
1767 @cindex paper size
1768 @cindex page size
1769 @cindex @code{papersize}
1770
1771 To change the paper size, there are two equal commands,
1772 @example
1773 #(set-default-paper-size "a4")
1774 \paper @{
1775   #(set-paper-size "a4")
1776 @}
1777 @end example
1778
1779 The first command sets the size of all pages.  The second command sets the size
1780 of the pages that the @code{\paper} block applies to -- if the @code{\paper}
1781 block is at the top of the file, then it will apply to all pages.  If the
1782 @code{\paper} block is inside a @code{\score}, then the paper size will only
1783 apply to that score.
1784
1785 The following paper sizes are supported: @code{a6}, @code{a5}, @code{a4},
1786 @code{a3}, @code{legal}, @code{letter}, @code{tabloid}.
1787
1788 @cindex orientation
1789 @cindex landscape
1790
1791 If the symbol @code{landscape} is supplied as an argument to
1792 @code{set-default-paper-size}, the pages will be rotated by 90 degrees,
1793 and wider line widths will be set correspondingly.
1794
1795 @example
1796 #(set-default-paper-size "a6" 'landscape)
1797 @end example 
1798
1799 @node Page layout
1800 @subsection Page layout
1801
1802 @cindex page layout
1803 @cindex margins
1804 @cindex header, page
1805 @cindex footer, page
1806
1807 LilyPond will do page layout, set margins, and add headers and
1808 footers to each page.
1809
1810 The default layout responds to the following settings in the
1811 @code{\paper} block.
1812
1813 @cindex \paper
1814
1815 @quotation
1816 @table @code
1817 @item firstpagenumber
1818 The value of the page number of the first page.  Default is@tie{}1.
1819
1820 @item printfirstpagenumber
1821 If set to true, will print the page number in the first page.  Default is
1822 false.
1823
1824 @item hsize
1825 The width of the page.
1826
1827 @item vsize
1828 The height of the page.
1829
1830 @item topmargin
1831 Margin between header and top of the page.
1832
1833 @item bottommargin
1834 Margin between footer and bottom of the page.
1835
1836 @item leftmargin
1837 Margin between the left side of the page and the beginning of the music.
1838
1839 @item linewidth
1840 The length of the systems.
1841
1842 @item headsep
1843 Distance between the top-most music system and the page header.
1844
1845 @item footsep
1846 Distance between the bottom-most music system and the page footer.
1847
1848 @item raggedbottom
1849 If set to true, systems will not be spread across the page.
1850
1851 This should be set false for pieces that have only two or three
1852 systems per page, for example orchestral scores.
1853  
1854 @item raggedlastbottom
1855 If set to false, systems will be spread to fill the last page.
1856
1857 Pieces that amply fill two pages or more should have this set to
1858 true.
1859
1860 @item betweensystemspace
1861 This dimensions determines the distance between systems.  It is the
1862 ideal distance between the center of the bottom staff of one system
1863 and the center of the top staff of the next system.
1864
1865 Increasing this will provide a more even appearance of the page at the
1866 cost of using more vertical space.
1867
1868 @item betweensystempadding
1869 This dimension is the minimum amount of white space that will always
1870 be present between the bottom-most symbol of one system, and the
1871 top-most of the next system.
1872
1873 Increasing this will put systems whose bounding boxes almost touch
1874 farther apart.
1875
1876 @item aftertitlespace
1877 Amount of space between the title and the first system.
1878
1879 @item beforetitlespace 
1880 Amount of space between the last system of the previous piece and the
1881 title of the next.
1882
1883 @item betweentitlespace
1884 Amount of space between consecutive titles (e.g., the title of the
1885 book and the title of a piece).
1886
1887 @end table
1888 @end quotation
1889
1890 Example:
1891
1892 @example
1893 \paper@{
1894   hsize = 2\cm
1895   topmargin = 3\cm
1896   bottommargin = 3\cm
1897   raggedlastbottom = ##t
1898 @}
1899 @end example
1900
1901 You can also define these values in Scheme.  In that case @code{mm},
1902 @code{in}, @code{pt}, and @code{cm} are variables defined in
1903 @file{paper-defaults.ly} with values in millimeters.  That's why the
1904 value has to be multiplied in the example
1905
1906 @example
1907 \paper @{
1908   #(define bottommargin (* 2 cm)) 
1909 @}
1910 @end example
1911
1912 @cindex copyright
1913 @cindex tagline
1914
1915 The default footer is empty, except for the first page, where the
1916 @code{copyright} field from @code{\header} is inserted, and the last
1917 page, where @code{tagline} from @code{\header} is added.  The default
1918 tagline is ``Engraved by LilyPond (@var{version})''.@footnote{Nicely
1919 printed parts are good PR for us, so please leave the tagline if you
1920 can.}
1921
1922 The header and footer are created by the functions @code{make-footer}
1923 and @code{make-header}, defined in @code{\paper}.  The default
1924 implementations are in @file{scm/@/page@/-layout@/.scm}.
1925
1926 The following settings influence the header and footer layout.
1927
1928 @quotation
1929 @table @code
1930 @item printpagenumber
1931   this boolean controls whether a pagenumber is printed. 
1932 @end table
1933 @end quotation
1934
1935 The page layout itself is done by two functions in the
1936 @code{\paper} block, @code{page-music-height} and
1937 @code{page-make-stencil}.  The former tells the line-breaking algorithm
1938 how much space can be spent on a page, the latter creates the actual
1939 page given the system to put on it.
1940
1941
1942 @refbugs
1943
1944 The option rightmargin is defined but doesn't set the right margin
1945 yet.  The value for the right margin has to be defined adjusting the
1946 values of the leftmargin and linewidth.
1947
1948 The default page header puts the page number and the @code{instrument}
1949 field from the @code{\header} block on a line.
1950
1951
1952
1953 @node Vertical spacing of piano staves
1954 @subsection Vertical spacing of piano staves
1955
1956 The distance between staves of a @internalsref{PianoStaff} cannot be
1957 computed during formatting.  Rather, to make cross-staff beaming work
1958 correctly, that distance has to be fixed beforehand.
1959  
1960 The distance of staves in a @code{PianoStaff} is set with the
1961 @code{forced-distance} property of the
1962 @internalsref{VerticalAlignment} object, created in
1963 @internalsref{PianoStaff}.
1964
1965 It can be adjusted as follows
1966 @example
1967 \new PianoStaff \with @{
1968   \override VerticalAlignment #'forced-distance = #7
1969 @} @{
1970   ...
1971 @}
1972 @end example
1973
1974 @noindent
1975 This would bring the staves together at a distance of 7 staff spaces,
1976 measured from the center line of each staff.
1977
1978 The difference is demonstrated in the following example,
1979 @lilypond[quote,verbatim]
1980 \relative <<
1981   \new PianoStaff \with {
1982     \override VerticalAlignment #'forced-distance = #7
1983   } <<
1984     \new Staff { c1 }
1985     \new Staff { c }
1986   >>
1987   \new PianoStaff <<
1988     \new Staff { c }
1989     \new Staff { c }
1990   >>
1991 >>    
1992 @end lilypond
1993
1994
1995
1996 @refbugs
1997
1998 @code{forced-distance} cannot be changed per system.
1999
2000 @node Vertical spacing
2001 @subsection Vertical spacing
2002
2003 @cindex vertical spacing
2004 @cindex distance between staves
2005 @cindex staff distance
2006 @cindex between staves, distance
2007 @cindex staves per page
2008 @cindex space between staves
2009
2010 The height of each system is determined automatically.  To prevent
2011 systems from bumping into each other, some minimum distances are set.
2012 By changing these, you can put staves closer together, and thus put
2013 more systems onto one page.
2014
2015 Normally staves are stacked vertically.  To make staves maintain a
2016 distance, their vertical size is padded.  This is done with the
2017 property @code{minimumVerticalExtent}.  It takes a pair of numbers, so
2018 if you want to make it smaller than its default, then you could set
2019
2020 @example
2021 \set Staff.minimumVerticalExtent = #'(-4 . 4)
2022 @end example
2023
2024 @noindent
2025 This sets the vertical size of the current staff to 4 staff spaces on
2026 either side of the center staff line.  The argument of
2027 @code{minimumVerticalExtent} is interpreted as an interval, where the
2028 center line is the 0, so the first number is generally negative.  The
2029 staff can be made larger at the bottom by setting it to @code{(-6 . 4)}. 
2030
2031
2032 @seealso
2033
2034 Internals: Vertical alignment of staves is handled by the
2035 @internalsref{VerticalAlignment} object.
2036
2037 @refbugs
2038
2039 @code{minimumVerticalExtent} is syntactic sugar for setting
2040 @code{minimum-Y-extent} of the @internalsref{VerticalAxisGroup} of the
2041 current context.  It can only be changed score wide.
2042
2043
2044
2045 @node Horizontal spacing
2046 @subsection Horizontal Spacing
2047
2048 The spacing engine translates differences in durations into
2049 stretchable distances (``springs'') of differring lengths.  Longer
2050 durations get more space, shorter durations get less.  The shortest
2051 durations get a fixed amount of space (which is controlled by
2052 @code{shortest-duration-space} in the @internalsref{SpacingSpanner} object). 
2053 The longer the duration, the more space it gets: doubling a
2054 duration adds a fixed amount (this amount is controlled by
2055 @code{spacing-increment}) of space to the note.
2056
2057 For example, the following piece contains lots of half, quarter, and
2058 8th notes; the eighth note is followed by 1 note head width (NHW). 
2059 The quarter note is followed by 2 NHW, the half by 3 NHW, etc.
2060
2061 @lilypond[quote,fragment,verbatim,relative=1]
2062 c2 c4. c8 c4. c8 c4. c8 c8
2063 c8 c4 c4 c4
2064 @end lilypond
2065
2066 Normally, @code{spacing-increment} is set to 1.2 staff space, which is
2067 approximately the width of a note head, and
2068 @code{shortest-duration-space} is set to 2.0, meaning that the
2069 shortest note gets 2.4 staff space (2.0 times the
2070 @code{spacing-increment}) of horizontal space.  This space is counted
2071 from the left edge of the symbol, so the shortest notes are generally
2072 followed by one NHW of space.
2073
2074 If one would follow the above procedure exactly, then adding a single
2075 32nd note to a score that uses 8th and 16th notes, would widen up the
2076 entire score a lot.  The shortest note is no longer a 16th, but a 32nd,
2077 thus adding 1 NHW to every note.  To prevent this, the shortest
2078 duration for spacing is not the shortest note in the score, but rather
2079 the one which occurs most frequently.
2080
2081
2082 The most common shortest duration is determined as follows: in every
2083 measure, the shortest duration is determined.  The most common shortest
2084 duration is taken as the basis for the spacing, with the stipulation
2085 that this shortest duration should always be equal to or shorter than
2086 an 8th note.  The shortest duration is printed when you run
2087 @code{lilypond} with the @code{--verbose} option.
2088
2089 These durations may also be customized.  If you set the
2090 @code{common-shortest-duration} in @internalsref{SpacingSpanner}, then
2091 this sets the base duration for spacing.  The maximum duration for this
2092 base (normally an 8th), is set through @code{base-shortest-duration}.
2093
2094 @cindex @code{common-shortest-duration}
2095 @cindex @code{base-shortest-duration}
2096 @cindex @code{stem-spacing-correction}
2097 @cindex @code{spacing}
2098
2099 Notes that are even shorter than the common shortest note are
2100 followed by a space that is proportional to their duration relative to
2101 the common shortest note.  So if we were to add only a few 16th notes
2102 to the example above, they would be followed by half a NHW:
2103
2104 @lilypond[quote,fragment,verbatim,relative=2]
2105 c2 c4. c8 c4. c16[ c] c4. c8 c8 c8 c4 c4 c4
2106 @end lilypond
2107
2108
2109 In the introduction (see @ref{Engraving}), it was explained that stem
2110 directions influence spacing.  This is controlled with the
2111 @code{stem-spacing-correction} property in the
2112 @internalsref{NoteSpacing}, object.  These are generated for every
2113 @internalsref{Voice} context.  The @code{StaffSpacing} object
2114 (generated in @internalsref{Staff} context) contains the same property
2115 for controlling the stem/bar line spacing.  The following example shows
2116 these corrections, once with default settings, and once with
2117 exaggerated corrections:
2118
2119 @lilypond[quote,raggedright]
2120 {
2121   c'4 e''4 e'4 b'4 |
2122   b'4 e''4 b'4 e''4|
2123   \override Staff.NoteSpacing #'stem-spacing-correction = #1.5
2124   \override Staff.StaffSpacing #'stem-spacing-correction = #1.5
2125   c'4 e''4 e'4 b'4 |
2126   b'4 e''4 b'4 e''4|      
2127 }
2128 @end lilypond
2129
2130
2131 @seealso
2132
2133 Internals: @internalsref{SpacingSpanner}, @internalsref{NoteSpacing},
2134 @internalsref{StaffSpacing}, @internalsref{SeparationItem}, and
2135 @internalsref{SeparatingGroupSpanner}.
2136
2137 @refbugs
2138
2139 Spacing is determined on a score wide basis.  If you have a score that
2140 changes its character (measured in durations) halfway during the
2141 score, the part containing the longer durations will be spaced too
2142 widely.
2143
2144 There is no convenient mechanism to manually override spacing.  The
2145 following work-around may be used to insert extra space into a score.
2146 @example
2147  \once \override Score.SeparationItem #'padding = #1
2148 @end example
2149
2150 No work-around exists for decreasing the amount of space.
2151
2152 @node Line length
2153 @subsection Line length
2154
2155 @cindex page breaks
2156 @cindex breaking pages
2157
2158 @cindex @code{indent}
2159 @cindex @code{linewidth}
2160
2161 @c Although linewidth can be set in \layout, it should be set in paper
2162 @c block, to get page layout right.
2163 @c Setting indent in \paper block makes not much sense, but it works.
2164
2165 @c Bit verbose and vague, use examples?
2166 The most basic settings influencing the spacing are @code{indent} and
2167 @code{linewidth}.  They are set in the @code{\layout} block.  They
2168 control the indentation of the first line of music, and the lengths of
2169 the lines.
2170
2171 If @code{raggedright} is set to true in the @code{\layout} block, then
2172 the lines are justified at their natural length.  This is useful for
2173 short fragments, and for checking how tight the natural spacing is.
2174
2175 @cindex page layout
2176 @cindex vertical spacing
2177
2178 The option @code{raggedlast} is similar to @code{raggedright}, but
2179 only affects the last line of the piece.  No restrictions are put on
2180 that line.  The result is similar to formatting text paragraphs.  In a
2181 paragraph, the last line simply takes its natural length.
2182 @c Note that for text there are several options for the last line.
2183 @c While Knuth TeX uses natural length, lead typesetters use the same
2184 @c stretch as the previous line.  eTeX uses \lastlinefit to
2185 @c interpolate between both these solutions.
2186
2187 @node Line breaking
2188 @subsection Line breaking
2189
2190 @cindex line breaks
2191 @cindex breaking lines
2192
2193 Line breaks are normally computed automatically.  They are chosen so
2194 that lines look neither cramped nor loose, and that consecutive lines
2195 have similar density.
2196
2197 Occasionally you might want to override the automatic breaks; you can
2198 do this by specifying @code{\break}.  This will force a line break at
2199 this point.  Line breaks can only occur at places where there are bar
2200 lines.  If you want to have a line break where there is no bar line,
2201 you can force an invisible bar line by entering @code{\bar
2202 ""}.  Similarly, @code{\noBreak} forbids a line break at a 
2203 point.
2204
2205
2206 @cindex regular line breaks
2207 @cindex four bar music. 
2208
2209 For line breaks at regular intervals use @code{\break} separated by
2210 skips and repeated with @code{\repeat}:
2211 @example
2212 << \repeat unfold 7 @{
2213          s1 \noBreak s1 \noBreak
2214          s1 \noBreak s1 \break @}
2215    @emph{the real music}
2216 >> 
2217 @end example
2218
2219 @noindent
2220 This makes the following 28 measures (assuming 4/4 time) be broken every
2221 4 measures, and only there.
2222
2223 @refcommands
2224
2225 @code{\break}, and @code{\noBreak}.
2226 @cindex @code{\break}
2227 @cindex @code{\noBreak}
2228
2229 @seealso
2230
2231 Internals: @internalsref{BreakEvent}.
2232
2233
2234 @node Page breaking
2235 @subsection Page breaking
2236
2237 The default page breaking may be overriden by inserting
2238 @code{\pageBreak} or @code{\noPageBreak} commands.  These commands are
2239 analogous to @code{\break} and @code{\noBreak}.  They should be
2240 inserted at a bar line.  These commands force and forbid a page-break
2241 from happening.  Of course, the @code{\pageBreak} command also forces
2242 a line break.
2243
2244 Page breaks are computed by the @code{page-breaking} function in the
2245 @code{\paper} block. 
2246
2247 @refcommands
2248
2249 @cindex @code{\pageBreak}
2250 @code{\pageBreak}
2251 @cindex @code{\noPageBreak} 
2252 @code{\noPageBreak} 
2253
2254
2255 @node Multiple movements
2256 @subsection Multiple movements
2257
2258 @cindex bibliographic information
2259 @cindex titles
2260 @cindex composer
2261 @cindex Engraved by LilyPond
2262
2263 A document may contain multiple pieces of music.  Examples of these
2264 are an etude book, or an orchestral part with multiple movements.
2265 Each movement is entered with a @code{\score} block,
2266
2267 @example
2268 \score @{
2269   @var{..music..}
2270 @}
2271 @end example
2272
2273 The movements are combined together in a @code{\book} block, like
2274
2275 @example
2276 \book @{
2277   \score @{
2278     @var{..}
2279   @}
2280   \score @{
2281     @var{..}
2282   @}
2283 @}
2284 @end example
2285
2286
2287 The header for each piece of music can be put inside the @code{\score}
2288 block.  The @code{piece} name from the header will be printed before
2289 each movement.  The title for the entire book can be put inside the
2290 @code{\book}, but if it is not present, the @code{\header} which is at
2291 the top of the file is inserted.
2292
2293 @cindex Engraved by LilyPond
2294 @cindex signature line
2295
2296 @example 
2297 \book @{
2298   \header @{
2299     title = "Eight miniatures" 
2300     composer = "Igor Stravinsky"
2301   @}
2302   \score @{
2303     @dots{}
2304     \header @{ piece = "Romanze" @}
2305   @}
2306   \score @{
2307     @dots{}
2308     \header @{ piece = "Menuetto" @}
2309   @}
2310 @}
2311 @end example
2312
2313
2314 @node Creating titles
2315 @subsection Creating titles
2316
2317 Titles are created for each @code{\score} block, and over a
2318 @code{\book}.
2319
2320 The contents of the titles are taken from the @code{\header} blocks.
2321 The header block for a book supports the following
2322 @table @code
2323 @item title
2324 The title of the music.  Centered on top of the first page.
2325
2326 @item subtitle
2327 Subtitle, centered below the title.
2328
2329 @item subsubtitle
2330 Subsubtitle, centered below the subtitle.
2331
2332 @item poet
2333 Name of the poet, flush-left below the subtitle.
2334
2335 @item composer
2336 Name of the composer, flush-right below the subtitle.
2337
2338 @item meter
2339 Meter string, flush-left below the poet.
2340
2341 @item opus
2342 Name of the opus, flush-right below the composer.
2343
2344 @item arranger
2345 Name of the arranger, flush-right below the opus.
2346
2347 @item instrument
2348 Name of the instrument, centered below the arranger.
2349
2350 @item dedication            
2351 To whom the piece is dedicated.
2352
2353 @item piece
2354 Name of the piece, flush-left below the instrument.
2355
2356 @cindex page breaks, forcing
2357 @item breakbefore
2358   This forces the title to start on a new page.
2359 @end table
2360
2361 Here is a demonstration of the fields available, 
2362
2363 @lilypond[quote,verbatim,linewidth=11.0\cm]
2364 \paper {
2365   linewidth = 9.0\cm
2366   vsize = 10.0\cm
2367 }
2368
2369 \book {
2370   \header {
2371     title = "Title,"
2372     subtitle = "the subtitle,"
2373     subsubtitle = "and the sub sub title"
2374     poet = "Poet"
2375     composer = "Composer"
2376     texttranslator = "Text Translator"
2377     meter = "Meter"
2378     arranger = "Arranger"
2379     instrument = "Instrument"
2380     piece = "Piece"
2381   }
2382
2383   \score {
2384     \header {
2385       piece = "piece1"
2386       opus = "opus1" 
2387     }
2388     { c'1 }
2389   }
2390   \score {
2391     \header {
2392       piece = "piece2"
2393       opus = "opus2" 
2394     }
2395     { c'1 }
2396   }
2397 }
2398 @end lilypond
2399
2400 Different fonts may be selected for each element by using
2401 @code{\markup}, e.g.,
2402
2403 @example
2404 \header @{
2405   title = \markup @{ \italic @{ The italic title @} @}
2406 @}
2407 @end example
2408
2409 A more advanced option is to change the definitions of the following
2410 variables in the @code{\paper} block. The init file
2411 @file{ly/titling-init.ly} lists the default layout.
2412
2413 @table @code
2414 @item bookTitleMarkup
2415   This is the title put over an entire @code{\book} block. Typically,
2416   it has the composer and the title of the piece
2417   
2418 @item scoreTitleMarkup
2419   This is the title put over a @code{\score} block within a
2420 @code{\book}. Typically, it has the name of the movement (@code{piece}
2421 field).
2422
2423 @item oddHeaderMarkup
2424   This is the page header for odd-numbered pages. 
2425
2426   @item evenHeaderMarkup
2427   This is the page header for even-numbered pages.  If unspecified,
2428   the odd header is used instead.
2429
2430   By default, headers are defined such that the page number is on the
2431   outside edge, and the instrument is centered.
2432
2433 @item oddFooterMarkup
2434   This is the page footer for odd-numbered pages. 
2435   
2436 @item evenFooterMarkup
2437   This is the page footer for even-numbered pages.  If unspecified,
2438   the odd header is used instead.
2439
2440   By default, the footer has the copyright notice on the first, and
2441   the tagline on the last page.
2442 @end table
2443
2444
2445 @cindex \paper
2446 @cindex header
2447 @cindex footer
2448 @cindex page layout
2449 @cindex titles
2450
2451 The following definition will put the title flush left, and the
2452 composer flush right on a single line.
2453
2454 @verbatim
2455 \paper {
2456   bookTitleMarkup = \markup {
2457    \fill-line @{
2458      \fromproperty #'header:title
2459      \fromproperty #'header:composer
2460    @}
2461   }
2462 }
2463 @end verbatim
2464
2465
2466
2467 @node File structure
2468 @section File structure
2469
2470 The major part of this manual is concerned with entering various
2471 forms of music in LilyPond.  However, many music expressions are not
2472 valid input on their own, for example, a @code{.ly} file containing
2473 only a note
2474 @example
2475 c'4
2476 @end example
2477
2478 @noindent
2479 will result in a parsing error.  Instead, music should be inside other
2480 expressions, which may be put in a file by themselves.  Such
2481 expressions are called toplevel expressions.  This section enumerates
2482 them all.
2483
2484 A @code{.ly} file contains any number of toplevel expressions, where a
2485 toplevel expression is one of the following
2486
2487 @itemize @bullet
2488 @item
2489 An output definition, such as @code{\paper}, @code{\midi}, and
2490 @code{\layout}.  Such a definition at the toplevel changes the default
2491 settings for the block entered.
2492
2493 @item
2494 A @code{\header} block.  This sets the global header block.  This
2495 is the block containing the definitions for book-wide settings, like
2496 composer, title, etc. 
2497
2498 @item
2499 An @code{\addquote} statement.  See @ref{Quoting other voices}
2500 for more information.
2501
2502 @item
2503 A @code{\score} block.  This score will be collected with other
2504 toplevel scores, and combined as a single @code{\book}.
2505
2506 This behavior can be changed by setting the variable
2507 @code{toplevel-score-handler} at toplevel.  The default handler is
2508 defined in the init file @file{scm/@/lily@/.scm}.
2509
2510 @item
2511 A @code{\book} block logically combines multiple movements
2512 (i.e., multiple @code{\score} blocks) in one document.  A number of
2513 @code{\scores} creates a single output file, where all movement are
2514 concatenated.
2515
2516 This behavior can be changed by setting the variable
2517 @code{toplevel-book-handler} at toplevel.  The default handler is
2518 defined in the init file @file{scm/@/lily@/.scm}.
2519
2520 @item A compound music expression, such as
2521 @example
2522 @{ c'4 d' e'2 @}
2523 @end example
2524
2525 This will add the piece in a @code{\score} and format it in a
2526 single book together with all other toplevel @code{\score}s and music
2527 expressions.
2528  
2529 This behavior can be changed by setting the variable
2530 @code{toplevel-music-handler} at toplevel.  The default handler is
2531 defined in the init file @file{scm/@/lily@/.scm}.
2532
2533 @item An indentifier, such as
2534 @example
2535 foo = @{ c4 d e d @}
2536 @end example
2537
2538 This can be used later on in the file by entering @code{\foo}.
2539
2540 @end itemize
2541
2542 The following example shows three things that may be entered at
2543 toplevel
2544
2545 @example
2546 \layout @{
2547   % movements are non-justified by default    
2548   raggedright = ##t
2549 @}
2550
2551 \header @{
2552    title = "Do-re-mi"
2553 @}
2554    
2555 @{ c'4 d' e2 @}
2556 @end example
2557
2558
2559 At any point in a file, any of the following lexical instructions can
2560 be entered:
2561
2562 @itemize @bullet
2563 @item @code{\version}
2564 @item @code{\include}
2565 @item @code{\encoding}
2566 @item @code{\renameinput}
2567 @end itemize