]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/text.itely
2eca283eaf1eeee916726400ed54a8658f8b6182
[lilypond.git] / Documentation / user / text.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @ignore
3     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
4
5     When revising a translation, copy the HEAD committish of the
6     version that you are working on.  See TRANSLATION for details.
7 @end ignore
8
9 @c \version "2.11.38"
10
11 @node Text
12 @section Text
13
14 @lilypondfile[quote]{text-headword.ly}
15
16 This section explains how to include text (with various
17 formatting) in your scores.
18
19 @noindent
20 Some text elements that are not dealt with here are discussed in other
21 specific sections: @ref{Vocal music}, @ref{Titles and headers}.
22
23
24 @cindex Text, other languages
25 @warning{To write accented and special text (such as characters
26 from other languages), simply insert the characters directly into
27 the LilyPond file.  The file must be saved as UTF-8.  For more
28 information, see @ref{Text encoding}.}
29
30 @menu
31 * Writing text::                
32 * Formatting text::                 
33 @end menu
34
35
36 @node Writing text
37 @subsection Writing text
38
39 @menu     
40 * Text scripts::                
41 * Text spanners::               
42 * Text marks::                  
43 * Separate text::                  
44 @end menu
45
46
47 @node Text scripts
48 @subsubsection Text scripts
49
50 @cindex Text scripts
51 @cindex text items, non-empty
52 @cindex non-empty texts
53
54 It is possible to add arbitrary text indications
55 to a score, as demonstrated in the following example.
56 Such indications can also be manually placed
57 above or below the staff, using the
58 simple syntax described in @ref{Controlling direction and
59 placement}.
60
61 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
62 d8^"pizz." e f g a4-"scherz." f
63 @end lilypond
64
65 In LilyPond, such text strings are called @command{markup}
66 objects.  This syntax is actually a shorthand; more complex text
67 formatting may be added to a note by explicitly using a
68 @code{\markup} block, as described in @ref{Formatting text}.
69
70 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
71 d8^\markup { \italic pizz. } e f g 
72 a4_\markup { \tiny scherz. \bold molto } f
73 @end lilypond
74
75 By default, text indications do not influence the note spacing.
76 However, their widths can be taken into account:
77 in the following example, the first text string does not affect 
78 spacing, whereas the second one does.
79
80 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
81 d8^"pizz." e f g \textLengthOn a4_"scherzando" f
82 @end lilypond
83
84 @predefined
85
86 @funindex \textLengthOn
87 @code{\textLengthOn},
88 @funindex \textLengthOff
89 @code{\textLengthOff}
90
91
92 @seealso
93
94 Notation Reference: @ref{Formatting text},
95 @ref{Controlling direction and placement}.
96
97 Snippets: @lsrdir{Text,Text}
98
99 Internals Reference: @internalsref{TextScript}.
100
101 @knownissues
102
103 Checking to make sure that text scripts and lyrics are within the
104 margins is a relatively large computational task.  To speed up
105 processing, LilyPond does not perform such calculations by
106 default; to enable it, use
107
108 @example
109 \override Score.PaperColumn #'keep-inside-line = ##t
110 @end example
111
112
113 @node Text spanners
114 @subsubsection Text spanners
115
116 @cindex Text spanners
117
118 Some performance indications, e.g., @i{rallentando} or
119 @i{accelerando}, are written as text and are extended over many
120 measures with dotted lines.
121
122 Such objects, called @q{spanners}, may be created
123 from one note to another by using the following syntax:
124
125 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
126 \override TextSpanner #'bound-details #'left #'text = "rit." 
127 b1\startTextSpan 
128 e,\stopTextSpan
129 @end lilypond
130
131 @noindent
132 The string to be printed is set through
133 object properties. By default it is printed in italic characters,
134 but different formatting can be obtained using
135 @code{\markup} blocks:
136
137 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
138 \override TextSpanner #'bound-details #'left #'text =
139   \markup { \upright "rit." } 
140 b1\startTextSpan c
141 e,\stopTextSpan
142 @end lilypond
143
144 The line style, as well as the text string, can be defined as an
145 object property. This syntax is described in @ref{Line styles}.
146
147 @predefined
148
149 @funindex textSpannerUp
150 @code{\textSpannerUp},
151 @funindex textSpannerDown
152 @code{\textSpannerDown},
153 @funindex textSpannerNeutral
154 @code{\textSpannerNeutral}
155
156 @seealso
157
158 Notation Reference: @ref{Line styles}.
159
160 Snippets: @lsrdir{Text,Text}
161
162 Internals Reference: @internalsref{TextSpanner}.
163
164
165 @node Text marks
166 @subsubsection Text marks
167
168 @cindex coda on bar line
169 @cindex segno on bar line
170 @cindex fermata on bar line
171 @cindex bar lines, symbols on
172 @funindex \mark
173
174 Various text elements can be added to a score using
175 the syntax described in @ref{Rehearsal marks}:
176
177 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
178 c4\mark "dolce" c c c
179 @end lilypond
180
181 This syntax makes possible to put any text on a bar line;
182 more complex text formatting may be added using a @code{\markup}
183 block, as described in @ref{Formatting text}.  This can be used to print
184 signs like coda, segno or fermata, by specifying the appropriate
185 symbol name:
186
187 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
188 c1 \mark \markup { \musicglyph #"scripts.ufermata" }
189 c1
190 @end lilypond
191
192 @noindent
193 Such objects are only typeset above the top staff of the score; they
194 can be placed above the bar line or between notes, depending on whether
195 you specify it at the end or the middle of a bar. When specified at the
196 beginning of a score or at a line break, the mark will be printed at
197 the beginning of the line (the next line, in case of a line break).
198
199 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
200 \mark "dolce" c1
201 c\mark "assai" \break
202 c c
203 @end lilypond
204
205
206 @snippets
207
208 @lilypondfile[verbatim,lilyquote,ragged-right,texidoc]
209 {printing-marks-at-the-end-of-a-line-or-a-score.ly}
210
211 @lilypondfile[verbatim,lilyquote,ragged-right,texidoc]
212 {aligning-marks-with-various-notation-objects.ly}
213
214 @lilypondfile[verbatim,lilyquote,ragged-right,texidoc]
215 {printing-marks-on-every-staff.ly}
216
217 @seealso
218
219 Notation Reference: @ref{Rehearsal marks},
220 @ref{Formatting text}, @ref{The Feta font}.
221
222 Snippets: @lsrdir{Text,Text}
223
224 Internals Reference: @internalsref{RehearsalMark}.
225
226 @knownissues
227 @c  IMO this is a bug; hopefully it'll be fixed soon, so I can
228 @c  delete this sentence.   -gp
229 @c  A workaround is suggested in the first @snippets item -vv
230
231 If a mark is entered at the end of the last bar of the score (where
232 there is no next line), then the mark will not be printed at
233 all.
234
235 @node Separate text
236 @subsubsection Separate text
237
238 @cindex separate text
239 @cindex standalone text
240 @cindex top-level text
241 @cindex text, standalone
242 @funindex \markup
243
244 A @code{\markup} block can exist by itself, outside of any
245 any @code{\score} block.  This syntax is called a @q{top-level
246 expression}, and is described in @code{File structure}.
247
248 @c TODO: turn this into a @lilypond example
249
250 @example
251 \markup @{
252   @var{..}
253 @}
254 @end example
255
256 @noindent
257 This allows to print text separately
258 from the music, which is particularly 
259 useful when the input file contains
260 several music pieces, as described in
261 @ref{Multiple scores in a book}.
262
263 @example
264 \score @{
265   @var{..}
266 @}
267 \markup @{
268   @var{..}
269 @}
270 \score @{
271   @var{..}
272 @}
273 @end example
274
275 Using a specific syntax, text blocks can be spread
276 over multiple pages, making possible to print
277 text documents or books -- and therefore to
278 use LilyPond as a word processor.  This syntax is described in
279 @ref{Page wrapping text}.
280
281 @ignore
282 @snippets
283
284 TODO: add convenient snippets, e.g.
285 "Inserting large plain text sections"
286 (this requires the LSR to be updated) -vv
287 @end ignore
288
289 @seealso
290
291 Notation Reference: @code{Formatting text},
292 @code{File structure}, 
293 @ref{Multiple scores in a book},
294 @ref{Page wrapping text}.
295
296 Snippets: @lsrdir{Text,Text}.
297
298 Internals Reference: @internalsref{TextScript}.
299
300 @predefined
301
302 @funindex \markup
303 @code{\markup},
304 @funindex \markuplines
305 @code{\markuplines}
306
307
308 @node Formatting text
309 @subsection Formatting text
310
311 @menu
312 * Text markup introduction::    
313 * Nested scores::               
314 * Page wrapping text::          
315 * Font selection::              
316 @end menu
317
318 @node Text markup introduction
319 @subsubsection Text markup introduction
320
321 @cindex markup
322 @cindex text markup
323 @cindex markup text
324 @cindex typeset text
325
326 A @code{\markup} block is used to typeset text with an extensible syntax,
327 called @q{markup mode}.
328 Specific commands can be entered in this mode, using the
329 backslash @code{\} character.
330 @c TODO: move the following sentence (and add an example?) -vv
331 To @emph{print} such characters as
332 @code{\} and @code{#} in the output, use double
333 quotation marks.
334
335 @lilypond[quote,verbatim,fragment,relative=1]
336 c1^\markup { hello }
337 c1_\markup { hi there }
338 c1^\markup { hi \bold there, is \italic {anyone home?} }
339 c1_\markup { "\special {weird} #characters" }
340 @end lilypond
341
342 @noindent
343 An exhaustive list of @code{\markup}-specific commands can be found in
344 @ref{Text markup commands}.
345
346 @code{\markup} blocks can be used anywhere text is called,
347 and not only for @internalsref{TextScript}s objects.
348
349 @lilypond[quote,verbatim]
350 \header{ title = \markup{ \bold { foo \italic { bar! } } } }
351 \score{
352   \relative c'' {
353     \override Score.RehearsalMark
354       #'break-visibility = #begin-of-line-invisible
355     \override Score.RehearsalMark #'self-alignment-X = #right
356
357     \set Staff.instrumentName = \markup{ \column{ Alto solo } }
358     c2^\markup{ don't be \flat }
359     \override TextSpanner #'bound-details #'left #'text = \markup{\italic rit }
360     b2\startTextSpan
361     a2\mark \markup{ \large \bold Fine }
362     r2\stopTextSpan
363     \bar "||"
364   }
365   \addlyrics { bar, foo \markup{ \italic bar! } }
366 }
367 @end lilypond
368
369 A @code{\markup} block can also be printed on its own at the top-level
370 of the input file, away from
371 any @code{\score} block. This syntax is described in
372 @ref{Multiple scores in a book}.
373
374 @lilypond[quote,ragged-right,verbatim]
375 \markup{ Here is some text. }
376 @end lilypond
377
378 @cindex font switching
379
380 Some font switching commands are demonstrated here. Such commands
381 apply only to the first following word; several words may be affected
382 by enclosing them in braces.
383
384 @example
385 \markup @{ \bold @{ hi there @} @}
386 @end example
387
388 @c TODO: remove the following line and example? -vv
389 @noindent
390 For clarity, you can also do this for single arguments, e.g.,
391
392 @example
393 \markup @{ is \italic @{ anyone @} home @}
394 @end example
395
396 The markup mode can be used to compose expressions, similar to
397 mathematical expressions, XML documents, and music expressions.
398 Such expressions can be vertically stacked, horizontally centered, 
399 or aligned in different ways:
400
401 @lilypond[quote,verbatim,fragment,relative=1]
402 c1^\markup { \column { a bbbb \line { c d } } }
403 c1^\markup { \center-align { a bbbb c } }
404 c1^\markup { \line { a b c } }
405 @end lilypond
406
407 Lists with no previous command are not kept distinct.  In
408 the following example, the two @code{\markup} expressions
409 are equivalent:
410
411 @c TODO: merge these two examples in a @lilypond example -vv
412
413 @example
414 \center-align @{ @{ a b @} @{ c d @} @}
415 \center-align @{ a b c d @}
416 @end example
417
418 @noindent
419
420 To keep lists of words distinct, please use quotes @code{"} or
421 the @code{\line} command
422
423 @lilypond[quote,verbatim,fragment,relative=1]
424 \textLengthOn
425 c4^\markup{ \center-align { on three lines } }
426 c4^\markup{ \center-align { "all one line" } }
427 c4^\markup{ \center-align { { on three lines } } }
428 c4^\markup{ \center-align { \line { on one line } } }
429 @end lilypond
430
431 Markups can be stored in variables and these variables may be
432 attached to notes, like
433
434 @example
435 allegro = \markup @{ \bold \large @{ Allegro @} @}
436  @{ a^\allegro b c d @}
437 @end example
438
439 Some objects have alignment procedures of their own, which cancel
440 out any effects of alignments applied to their markup arguments as
441 a whole.  For example, the @internalsref{RehearsalMark} is
442 horizontally centered, so using @code{\mark \markup @{ \left-align
443 .. @}} has no effect.
444
445 In addition, vertical placement is performed after creating the
446 text markup object.  If you wish to move an entire piece of
447 markup, you need to use the #'padding property or create an
448 @q{anchor} point inside the markup (generally with @code{\hspace
449 #0}).
450
451 @lilypond[quote,verbatim,fragment,relative=1]
452 \textLengthOn
453 c'4^\markup{ \raise #5 "not raised" }
454 \once \override TextScript #'padding = #3
455 c'4^\markup{ raised }
456 c'4^\markup{ \hspace #0 \raise #1.5 raised }
457 @end lilypond
458
459 Some situations (such as dynamic marks) have preset font-related
460 properties.  If you are creating text in such situations, it is
461 advisable to cancel those properties with @code{normal-text}.  See
462 @ref{Text markup commands}, for more details.
463
464
465 @seealso
466
467 This manual: @ref{Text markup commands}.
468
469 Snippets: @lsrdir{Text,Text}
470
471 Internals Reference: @internalsref{TextScript}.
472
473 Init files: @file{scm/@/new@/-markup@/.scm}.
474
475
476 @knownissues
477
478 Kerning or generation of ligatures is only done when the @TeX{}
479 backend is used.  In this case, LilyPond does not account for them
480 so texts will be spaced slightly too wide.
481
482 Syntax errors for markup mode are confusing.
483
484
485 @node Nested scores
486 @subsubsection Nested scores
487
488 It is possible to nest music inside markups, by adding a
489 @code{\score} block to a markup expression.  Such a score must
490 contain a @code{\layout} block.
491
492 @lilypond[quote,verbatim,ragged-right]
493 \relative {
494   c4 d^\markup {
495     \score {
496       \relative { c4 d e f }
497       \layout { }
498     }
499   }
500   e f
501 }
502 @end lilypond
503
504 @seealso
505
506 Snippets: @lsrdir{Text,Text}
507
508 @node Page wrapping text
509 @subsubsection Page wrapping text
510
511 Whereas @code{\markup} is used to enter a non-breakable block of
512 text, @code{\markuplines} can be used at top-level to enter lines
513 of text that can spread over multiple pages:
514
515 @verbatim
516 \markuplines {
517   \justified-lines {
518     A very long text of justified lines.
519     ...
520   }
521   \justified-lines {
522     An other very long paragraph.
523     ...
524   }
525   ...
526 }
527 @end verbatim
528
529 @code{\markuplines} accepts a list of markup, that is either the
530 result of a markup list command, or a list of markups or of markup
531 lists.  The built-in markup list commands are described in
532 @ref{Text markup list commands}.
533
534 @seealso
535
536 This manual: @ref{Text markup list commands}, @ref{New
537 markup list command definition}.
538
539 Snippets: @lsrdir{Text,Text}
540
541 @predefined
542
543 @funindex \markuplines
544 @code{\markuplines}
545
546 @node Font selection
547 @subsubsection Font selection
548
549 @cindex font selection
550 @cindex font magnification
551 @funindex font-interface
552
553 By setting the object properties described below, you can select a
554 font from the preconfigured font families.  LilyPond has default
555 support for the feta music fonts.  Text fonts are selected through
556 Pango/FontConfig.  The serif font defaults to New Century
557 Schoolbook, the sans and typewriter to whatever the Pango
558 installation defaults to.
559
560
561 @itemize
562 @item @code{font-encoding}
563 is a symbol that sets layout of the glyphs.  This should only be
564 set to select different types of non-text fonts, e.g.
565
566 @code{fetaBraces} for piano staff braces, @code{fetaMusic} the
567 standard music font, including ancient glyphs, @code{fetaDynamic}
568 for dynamic signs and @code{fetaNumber} for the number font.
569
570 @item @code{font-family}
571 is a symbol indicating the general class of the typeface.
572 Supported are @code{roman} (Computer Modern), @code{sans}, and
573 @code{typewriter}.
574
575 @item @code{font-shape}
576 is a symbol indicating the shape of the font.  There are typically
577 several font shapes available for each font family.  Choices are
578 @code{italic}, @code{caps}, and @code{upright}.
579
580 @item @code{font-series}
581 is a symbol indicating the series of the font.  There are
582 typically several font series for each font family and shape.
583 Choices are @code{medium} and @code{bold}.
584
585 @end itemize
586
587 Fonts selected in the way sketched above come from a predefined
588 style sheet.  If you want to use a font from outside the style
589 sheet, then set the @code{font-name} property,
590
591 @lilypond[fragment,verbatim]
592 {
593   \override Staff.TimeSignature #'font-name = #"Charter"
594   \override Staff.TimeSignature #'font-size = #2
595   \time 3/4
596   c'1_\markup {
597     \override #'(font-name . "Vera Bold")
598       { This text is in Vera Bold }
599   }
600 }
601 @end lilypond
602
603 @noindent
604 Any font can be used, as long as it is available to
605 Pango/FontConfig.  To get a full list of all available fonts, run
606 the command
607
608 @example
609 lilypond -dshow-available-fonts blabla
610 @end example
611
612 (the last argument of the command can be anything, but has to be
613 present).
614
615
616 The size of the font may be set with the @code{font-size}
617 property.  The resulting size is taken relative to the
618 @code{text-font-size} as defined in the @code{\paper} block.
619
620 @cindex font size
621 @cindex font magnification
622
623
624 It is also possible to change the default font family for the
625 entire document.  This is done by calling the
626 @code{make-pango-font-tree} from within the @code{\paper} block.
627 The function takes names for the font families to use for roman,
628 sans serif and monospaced text.  For example,
629
630 @cindex font families, setting
631 @cindex Pango
632
633
634 @lilypond[verbatim]
635 \paper  {
636   myStaffSize = #20
637
638   #(define fonts
639     (make-pango-font-tree "Times New Roman"
640                           "Nimbus Sans"
641                           "Luxi Mono"
642                            (/ myStaffSize 20)))
643 }
644
645 {
646   c'^\markup { roman: foo \sans bla \typewriter bar }
647 }
648 @end lilypond
649
650 @c we don't do Helvetica / Courier, since GS incorrectly loads
651 @c Apple TTF fonts
652
653
654
655 @seealso
656
657 Snippets: @lsrdir{Text,Text}
658
659