]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/text.itely
Standardize introduciton of snippets.
[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 music 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 * Fonts::                       
34 @end menu
35
36
37 @node Writing text
38 @subsection Writing text
39
40 This section introduces different ways of adding text to a score.
41
42 @menu
43 * Text scripts::                
44 * Text spanners::               
45 * Text marks::                  
46 * Separate text::               
47 @end menu
48
49
50 @node Text scripts
51 @subsubsection Text scripts
52
53 @cindex Text scripts
54 @cindex text items, non-empty
55 @cindex non-empty texts
56
57 It is possible to add arbitrary text indications
58 to a score, as demonstrated in the following example.
59 Such indications can also be manually placed
60 above or below the staff, using the
61 simple syntax described in @ref{Controlling direction and
62 placement}.
63
64 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
65 d8^"pizz." e f g a4-"scherz." f
66 @end lilypond
67
68 In LilyPond, such text strings are called @command{markup}
69 objects.  This syntax is actually a shorthand; more complex text
70 formatting may be added to a note by explicitly using a
71 @code{\markup} block, as described in @ref{Formatting text}.
72
73 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
74 d8^\markup { \italic pizz. } e f g 
75 a4_\markup { \tiny scherz. \bold molto } f
76 @end lilypond
77
78 By default, text indications do not influence the note spacing.
79 However, their widths can be taken into account:
80 in the following example, the first text string does not affect 
81 spacing, whereas the second one does.
82
83 @lilypond[quote,fragment,ragged-right,verbatim,relative=1]
84 d8^"pizz." e f g \textLengthOn a4_"scherzando" f
85 @end lilypond
86
87 @predefined
88
89 @funindex \textLengthOn
90 @code{\textLengthOn},
91 @funindex \textLengthOff
92 @code{\textLengthOff}
93
94
95 @seealso
96
97 Notation Reference: @ref{Formatting text},
98 @ref{Controlling direction and placement}.
99
100 Snippets:
101 @lsrdir{Text,Text}
102
103 Internals Reference: @internalsref{TextScript}.
104
105 @knownissues
106
107 Checking to make sure that text scripts and lyrics are within the
108 margins is a relatively large computational task.  To speed up
109 processing, LilyPond does not perform such calculations by
110 default; to enable it, use
111
112 @example
113 \override Score.PaperColumn #'keep-inside-line = ##t
114 @end example
115
116
117 @node Text spanners
118 @subsubsection Text spanners
119
120 @cindex Text spanners
121
122 Some performance indications, e.g., @i{rallentando} or
123 @i{accelerando}, are written as text and are extended over many
124 measures with dotted lines.
125
126 Such objects, called @q{spanners}, may be created
127 from one note to another by using the following syntax:
128
129 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
130 \override TextSpanner #'bound-details #'left #'text = "rit." 
131 b1\startTextSpan 
132 e,\stopTextSpan
133 @end lilypond
134
135 @noindent
136 The string to be printed is set through
137 object properties. By default it is printed in italic characters,
138 but different formatting can be obtained using
139 @code{\markup} blocks:
140
141 @lilypond[quote,ragged-right,fragment,relative=2,verbatim]
142 \override TextSpanner #'bound-details #'left #'text =
143   \markup { \upright "rit." } 
144 b1\startTextSpan c
145 e,\stopTextSpan
146 @end lilypond
147
148 The line style, as well as the text string, can be defined as an
149 object property. This syntax is described in @ref{Line styles}.
150
151 @predefined
152
153 @funindex textSpannerUp
154 @code{\textSpannerUp},
155 @funindex textSpannerDown
156 @code{\textSpannerDown},
157 @funindex textSpannerNeutral
158 @code{\textSpannerNeutral}
159
160 @seealso
161
162 Notation Reference: @ref{Line styles}.
163
164 Snippets:
165 @lsrdir{Text,Text}
166
167 Internals Reference: @internalsref{TextSpanner}.
168
169
170 @node Text marks
171 @subsubsection Text marks
172
173 @cindex coda on bar line
174 @cindex segno on bar line
175 @cindex fermata on bar line
176 @cindex bar lines, symbols on
177 @funindex \mark
178
179 Various text elements can be added to a score using
180 the syntax described in @ref{Rehearsal marks}:
181
182 @lilypond[verbatim,quote,ragged-right,fragment,relative=2]
183 c4\mark "dolce" c c c
184 @end lilypond
185
186 This syntax makes possible to put any text on a bar line;
187 more complex text formatting may be added using a @code{\markup}
188 block, as described in @ref{Formatting text}.  This can be used to print
189 signs like coda, segno or fermata, by specifying the appropriate
190 symbol name:
191
192 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
193 c1 \mark \markup { \musicglyph #"scripts.ufermata" }
194 c1
195 @end lilypond
196
197 @noindent
198 Such objects are only typeset above the top staff of the score; they
199 can be placed above the bar line or between notes, depending on whether
200 you specify it at the end or the middle of a bar. When specified at the
201 beginning of a score or at a line break, the mark will be printed at
202 the beginning of the line (the next line, in case of a line break).
203
204 @lilypond[fragment,quote,ragged-right,verbatim,relative=2]
205 \mark "dolce" c1
206 c\mark "assai" \break
207 c c
208 @end lilypond
209
210
211 @snippets
212
213 @lilypondfile[verbatim,lilyquote,ragged-right,texidoc]
214 {printing-marks-at-the-end-of-a-line-or-a-score.ly}
215
216 @lilypondfile[verbatim,lilyquote,ragged-right,texidoc]
217 {aligning-marks-with-various-notation-objects.ly}
218
219 @lilypondfile[verbatim,lilyquote,ragged-right,texidoc]
220 {printing-marks-on-every-staff.ly}
221
222 @seealso
223
224 Notation Reference: @ref{Rehearsal marks},
225 @ref{Formatting text}, @ref{The Feta font}.
226
227 Snippets:
228 @lsrdir{Text,Text}
229
230 Internals Reference: @internalsref{RehearsalMark}.
231
232 @knownissues
233 @c  IMO this is a bug; hopefully it'll be fixed soon, so I can
234 @c  delete this sentence.   -gp
235 @c  A workaround is suggested in the first @snippets item -vv
236
237 If a mark is entered at the end of the last bar of the score (where
238 there is no next line), then the mark will not be printed at
239 all.
240
241 @node Separate text
242 @subsubsection Separate text
243
244 @cindex separate text
245 @cindex standalone text
246 @cindex top-level text
247 @cindex text, standalone
248 @funindex \markup
249
250 A @code{\markup} block can exist by itself, outside of any
251 any @code{\score} block, as a @qq{top-level
252 expression}.  This syntax is described in @ref{File structure}.
253
254 @lilypond[quote,ragged-right,verbatim]
255 \markup {
256   Tomorrow, and tomorrow, and tomorrow...
257 }
258 @end lilypond
259
260 @noindent
261 This allows to print text separately
262 from the music, which is particularly 
263 useful when the input file contains
264 several music pieces, as described in
265 @ref{Multiple scores in a book}.
266
267 @lilypond[quote,ragged-right,verbatim]
268 \score {
269   c'1
270 }
271 \markup {
272   Tomorrow, and tomorrow, and tomorrow...
273 }
274 \score {
275   c'1
276 }
277 @end lilypond
278
279 Using a specific syntax, text blocks can be spread
280 over multiple pages, making possible to print
281 text documents or books -- and therefore to
282 use LilyPond as a word processor.  This syntax is described in
283 @ref{Multi-page markup}.
284
285 @ignore
286 @snippets
287
288 TODO: add convenient snippets in input/new -vv
289 @end ignore
290
291 @seealso
292
293 Notation Reference: @code{Formatting text},
294 @code{File structure}, 
295 @ref{Multiple scores in a book},
296 @ref{Multi-page markup}.
297
298 Snippets:
299 @lsrdir{Text,Text}
300
301 Internals Reference: @internalsref{TextScript}.
302
303 @predefined
304
305 @funindex \markup
306 @code{\markup},
307 @funindex \markuplines
308 @code{\markuplines}
309
310
311 @node Formatting text
312 @subsection Formatting text
313
314 This section presents basic and advanced text formatting,
315 using the @code{\markup} mode specific syntax.
316
317 @menu
318 * Text markup introduction::    
319 * Common markup commands::      
320 * Text alignment::              
321 * Graphic notation inside markup::  
322 * Music notation inside markup::  
323 * Multi-page markup::          
324 @end menu
325
326 @node Text markup introduction
327 @subsubsection Text markup introduction
328
329 @cindex markup
330 @cindex text markup
331 @cindex markup text
332 @cindex typeset text
333
334 A @code{\markup} block is used to typeset text with an extensible syntax,
335 called @q{markup mode}.
336 Specific commands can be entered in this mode, using the
337 backslash @code{\} character.
338 @c TODO: move the following sentence (and add an example?) -vv
339 To @emph{print} such characters as
340 @code{\} and @code{#} in the output, use double
341 quotation marks.
342
343 @lilypond[quote,verbatim,fragment,relative=1]
344 c1^\markup { hello }
345 c1_\markup { hi there }
346 c1^\markup { hi \bold there, is \italic {anyone home?} }
347 c1_\markup { "\special {weird} #characters" }
348 @end lilypond
349
350 @noindent
351 An exhaustive list of @code{\markup}-specific commands can be found in
352 @ref{Text markup commands}.
353
354
355 @lilypond[quote,verbatim]
356 \header{ title = \markup{ \bold { foo \italic { bar! } } } }
357 \score{
358   \relative c'' {
359     \override Score.RehearsalMark
360       #'break-visibility = #begin-of-line-invisible
361     \override Score.RehearsalMark #'self-alignment-X = #right
362
363     \set Staff.instrumentName = \markup{ \column{ Alto solo } }
364     c2^\markup{ don't be \flat }
365     \override TextSpanner #'bound-details #'left #'text = \markup{\italic rit }
366     b2\startTextSpan
367     a2\mark \markup{ \large \bold Fine }
368     r2\stopTextSpan
369     \bar "||"
370   }
371   \addlyrics { bar, foo \markup{ \italic bar! } }
372 }
373 @end lilypond
374
375
376
377 @cindex font switching
378
379 Some font switching commands are demonstrated here. Such commands
380 apply only to the first following word; several words may be affected
381 by enclosing them in braces.
382
383 @example
384 \markup @{ \bold @{ hi there @} @}
385 @end example
386
387 @c TODO: remove the following line and example? -vv
388 @noindent
389 For clarity, you can also do this for single arguments, e.g.,
390
391 @example
392 \markup @{ is \italic @{ anyone @} home @}
393 @end example
394
395 The markup mode can be used to compose expressions, similar to
396 mathematical expressions, XML documents, and music expressions.
397 Such expressions can be vertically stacked, horizontally centered, 
398 or aligned in different ways:
399
400 @lilypond[quote,verbatim,fragment,relative=1]
401 c1^\markup { \column { a bbbb \line { c d } } }
402 c1^\markup { \center-align { a bbbb c } }
403 c1^\markup { \line { a b c } }
404 @end lilypond
405
406 Lists with no previous command are not kept distinct.  In
407 the following example, the two @code{\markup} expressions
408 are equivalent:
409
410 @c TODO: merge these two examples in a @lilypond example -vv
411
412 @example
413 \center-align @{ @{ a b @} @{ c d @} @}
414 \center-align @{ a b c d @}
415 @end example
416
417 @noindent
418
419 To keep lists of words distinct, please use quotes @code{"} or
420 the @code{\line} command
421
422 @lilypond[quote,verbatim,fragment,relative=1]
423 \textLengthOn
424 c4^\markup{ \center-align { on three lines } }
425 c4^\markup{ \center-align { "all one line" } }
426 c4^\markup{ \center-align { { on three lines } } }
427 c4^\markup{ \center-align { \line { on one line } } }
428 @end lilypond
429
430 Markups can be stored in variables and these variables may be
431 attached to notes, like
432
433 @example
434 allegro = \markup @{ \bold \large @{ Allegro @} @}
435  @{ a^\allegro b c d @}
436 @end example
437
438 Some objects have alignment procedures of their own, which cancel
439 out any effects of alignments applied to their markup arguments as
440 a whole.  For example, the @internalsref{RehearsalMark} is
441 horizontally centered, so using @code{\mark \markup @{ \left-align
442 .. @}} has no effect.
443
444 In addition, vertical placement is performed after creating the
445 text markup object.  If you wish to move an entire piece of
446 markup, you need to use the #'padding property or create an
447 @q{anchor} point inside the markup (generally with @code{\hspace
448 #0}).
449
450 @lilypond[quote,verbatim,fragment,relative=1]
451 \textLengthOn
452 c'4^\markup{ \raise #5 "not raised" }
453 \once \override TextScript #'padding = #3
454 c'4^\markup{ raised }
455 c'4^\markup{ \hspace #0 \raise #1.5 raised }
456 @end lilypond
457
458 Some situations (such as dynamic marks) have preset font-related
459 properties.  If you are creating text in such situations, it is
460 advisable to cancel those properties with @code{normal-text}.  See
461 @ref{Text markup commands}, for more details.
462
463 @ignore
464 TODO: here are some commands that could be described here.
465 I'm putting them in bulk, prior to working on this section. -vv
466
467 \simple
468
469 \char
470 \fraction
471
472 \combine
473 \concat
474 \put-adjacent
475
476
477 \page-ref (see also "Table of contents")
478 \fromproperty
479 \verbatim-file
480 \with-url
481
482 \on-the-fly 
483 \override
484
485
486 \null
487 \hspace
488
489 \lower
490 \raise 
491 \translate 
492 \translate-scaled
493 \rotate
494 \transparent
495 \whiteout
496
497 @end ignore
498
499 @seealso
500
501 This manual: @ref{Text markup commands}.
502
503 Snippets:
504 @lsrdir{Text,Text}
505
506 Internals Reference: @internalsref{TextScript}.
507
508 Init files: @file{scm/@/new@/-markup@/.scm}.
509
510
511 @knownissues
512
513 Kerning or generation of ligatures is only done when the @TeX{}
514 backend is used.  In this case, LilyPond does not account for them
515 so texts will be spaced slightly too wide.
516
517 Syntax errors for markup mode are confusing.
518
519 @node Common markup commands
520 @subsubsection Common markup commands
521
522 Some basic formatting can be used blah blah
523
524 \italic 
525 \upright
526 \bold 
527 \medium 
528 \underline
529         
530
531 @c TODO: what's the difference between the following commands? -vv
532 \smallCaps      
533 \caps 
534 \fontCaps
535
536
537 Some alternate font families can easily be selected:
538
539 \sans
540 \typewriter
541 \roman
542 \number (only for numbers, such as fingerings and time signatures)
543 @c TODO: add \slashed-digit here? -vv
544
545 The size can be blah blah blah
546
547 \fontsize
548
549 Some predefined font sizes can be used blah blah
550
551 \teeny
552 \tiny
553 \small  
554 \normalsize
555 \large
556 \huge
557
558 Some shorcuts allow to change the font size relatively to its previous value 
559
560 \smaller
561 \bigger
562 \larger
563
564 \magnify
565
566 Text may be printed as subscript or superscript:
567
568 \sub 
569 \super
570
571 To obtain subscripts or superscripts in a normal text size, use
572 \normal-size-sub
573 \normal-size-super
574
575 All these settings (except the size) can be reverted to the default font:
576
577 \normal-text 
578
579
580 @node Text alignment
581 @subsubsection Text alignment
582
583 Alignment basics:
584 \left-align
585 \center-align
586 \right-align
587
588 Horizontal alignment:
589 \hcenter
590 \general-align
591 \halign 
592
593
594 Vertical alignment: 
595 \vcenter
596 \column 
597 \dir-column 
598
599 Building a "large" markup:
600
601 \line
602
603 \fill-line
604
605 \hcenter-in
606         
607 \pad-around
608 \pad-markup
609 \pad-to-box
610 \pad-x
611         
612 Alignment inside a "large" markup:
613
614 \justify-field 
615 \justify
616 \justify-string
617
618 \wordwrap-field
619 \wordwrap
620 \wordwrap-string
621
622 @node Graphic notation inside markup
623 @subsubsection Graphic notation inside markup
624 Graphics around text:
625 \box
626 \circle
627
628 \bracket
629 \hbracket
630
631 "Standalone" graphics:
632
633 \arrow-head
634 \draw-line
635 \draw-circle
636 \filled-box
637 \triangle
638 \strut
639
640 \with-color
641
642
643 Advanced graphics:
644 \stencil
645
646 \postscript
647 \epsfile
648
649 \with-dimensions
650
651 @node Music notation inside markup
652 @subsubsection Music notation inside markup
653
654 Notes can be printed in markup mode blah blah:
655
656 \note   
657 \note-by-number
658
659 Accidental symbols can be obtained easily:
660
661 \doubleflat
662 \sesquiflat
663 \flat
664 \semiflat
665 \natural
666 \semisharp
667 \sharp
668 \sesquisharp
669 \doublesharp
670
671 Some other notation objects blah blah
672
673 \beam
674 \finger
675 \dynamic
676 \tied-lyric
677 \markalphabet
678 \markletter
679 @c TODO: add \text here? -vv
680
681 Any musical symbol can be printed
682
683 \musicglyph
684 @c TODO: add \lookup here? -vv
685
686
687 The markup mode has support for fret diagrams:
688
689 \fret-diagram 
690 \fret-diagram-terse
691 \fret-diagram-verbose
692
693 An entire @code{\score} block can even be nested in a @code{\markup}
694 block.  In such a case, the @code{\score} must contain a @code{\layout} block.
695
696
697 \score
698
699
700 @lilypond[quote,verbatim,ragged-right]
701 \relative {
702   c4 d^\markup {
703     \score {
704       \relative { c4 d e f }
705       \layout { }
706     }
707   }
708   e f
709 }
710 @end lilypond
711
712 @seealso
713
714 Snippets:
715 @lsrdir{Text,Text}
716
717 @node Multi-page markup
718 @subsubsection Multi-page markup
719
720 Whereas @code{\markup} is used to enter a non-breakable block of
721 text, @code{\markuplines} can be used at top-level to enter lines
722 of text that can spread over multiple pages:
723
724 @verbatim
725 \markuplines {
726   \justified-lines {
727     A very long text of justified lines.
728     ...
729   }
730   \justified-lines {
731     An other very long paragraph.
732     ...
733   }
734   ...
735 }
736 @end verbatim
737
738 @code{\markuplines} accepts a list of markup, that is either the
739 result of a markup list command, or a list of markups or of markup
740 lists.  The built-in markup list commands are described in
741 @ref{Text markup list commands}.
742
743 @seealso
744
745 This manual: @ref{Text markup list commands}, @ref{New
746 markup list command definition}.
747
748 Snippets:
749 @lsrdir{Text,Text}
750
751 @predefined
752
753 @funindex \markuplines
754 @code{\markuplines}
755
756
757
758 @c TODO: move the following subsubsec into NR3 -vv
759 @c maybe.  -gp
760 @node Fonts
761 @subsection Fonts
762
763 @menu
764 * Entire document fonts::       
765 * Single entry fonts::          
766 @end menu
767
768 @node Entire document fonts
769 @subsubsection Entire document fonts
770
771 It is also possible to change the default font family for the
772 entire document.  This is done by calling the
773 @code{make-pango-font-tree} from within the @code{\paper} block.
774 The function takes names for the font families to use for roman,
775 sans serif and monospaced text.  For example,
776
777 @cindex font families, setting
778 @cindex Pango
779
780
781 @lilypond[verbatim]
782 \paper  {
783   myStaffSize = #20
784
785   #(define fonts
786     (make-pango-font-tree "Times New Roman"
787                           "Nimbus Sans"
788                           "Luxi Mono"
789                            (/ myStaffSize 20)))
790 }
791
792 {
793   c'^\markup { roman: foo \sans bla \typewriter bar }
794 }
795 @end lilypond
796
797 @c we don't do Helvetica / Courier, since GS incorrectly loads
798 @c Apple TTF fonts
799
800
801 @node Single entry fonts
802 @subsubsection Single entry fonts
803
804 @cindex font selection
805 @cindex font magnification
806 @funindex font-interface
807
808 By setting the object properties described below, you can select a
809 font from the preconfigured font families.  LilyPond has default
810 support for the feta music fonts.  Text fonts are selected through
811 Pango/FontConfig.  The serif font defaults to New Century
812 Schoolbook, the sans and typewriter to whatever the Pango
813 installation defaults to.
814
815
816 @itemize
817 @item @code{font-encoding}
818 is a symbol that sets layout of the glyphs.  This should only be
819 set to select different types of non-text fonts, e.g.
820
821 @code{fetaBraces} for piano staff braces, @code{fetaMusic} the
822 standard music font, including ancient glyphs, @code{fetaDynamic}
823 for dynamic signs and @code{fetaNumber} for the number font.
824
825 @item @code{font-family}
826 is a symbol indicating the general class of the typeface.
827 Supported are @code{roman} (Computer Modern), @code{sans}, and
828 @code{typewriter}.
829
830 @item @code{font-shape}
831 is a symbol indicating the shape of the font.  There are typically
832 several font shapes available for each font family.  Choices are
833 @code{italic}, @code{caps}, and @code{upright}.
834
835 @item @code{font-series}
836 is a symbol indicating the series of the font.  There are
837 typically several font series for each font family and shape.
838 Choices are @code{medium} and @code{bold}.
839
840 @end itemize
841
842 Fonts selected in the way sketched above come from a predefined
843 style sheet.  If you want to use a font from outside the style
844 sheet, then set the @code{font-name} property,
845
846 @lilypond[fragment,verbatim]
847 {
848   \override Staff.TimeSignature #'font-name = #"Charter"
849   \override Staff.TimeSignature #'font-size = #2
850   \time 3/4
851   c'1_\markup {
852     \override #'(font-name . "Vera Bold")
853       { This text is in Vera Bold }
854   }
855 }
856 @end lilypond
857
858 @noindent
859 Any font can be used, as long as it is available to
860 Pango/FontConfig.  To get a full list of all available fonts, run
861 the command
862
863 @example
864 lilypond -dshow-available-fonts blabla
865 @end example
866
867 (the last argument of the command can be anything, but has to be
868 present).
869
870
871 The size of the font may be set with the @code{font-size}
872 property.  The resulting size is taken relative to the
873 @code{text-font-size} as defined in the @code{\paper} block.
874
875 @cindex font size
876 @cindex font magnification
877
878
879
880
881 @seealso
882
883 Snippets:
884 @lsrdir{Text,Text}
885
886