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