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