]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/input.itely
Split WWW target in two stages WWW-1 and WWW-2
[lilypond.git] / Documentation / user / input.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2 @c This file is part of lilypond.tely
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
6     When revising a translation, copy the HEAD committish of the
7     version that you are working on.  See TRANSLATION for details.
8 @end ignore
9
10 @c \version "2.11.38"
11
12 @node Input syntax
13 @chapter Input syntax
14
15 This section deals with general LilyPond input syntax issues,
16 rather than specific notation.
17
18 FIXME: don't complain about anything in this chapter.  It's still
19 under heavy development.
20
21 @menu
22 * Input structure::
23 * Useful concepts and properties::
24 * Titles and headers::
25 * Working with input files::
26 * Controlling output::
27 @end menu
28
29
30 @node Input structure
31 @section Input structure
32
33 The main format of input for LilyPond are text files.  By convention,
34 these files end with @code{.ly}.
35
36 @menu
37 * Structure of a score::
38 * Multiple scores in a book::
39 * File structure::
40 @end menu
41
42
43 @node Structure of a score
44 @subsection Structure of a score
45
46 @funindex \score
47
48 A @code{\score} block must contain a single music expression
49 delimited by curly brackets:
50
51 @example
52 \score @{
53 ...
54 @}
55 @end example
56
57 @warning{There must be @strong{only one} outer music expression in
58 a @code{\score} block, and it @strong{must} be surrounded by
59 curly brackets.}
60
61 This single music expression may be of any size, and may contain
62 other music expressions to any complexity.  All of these examples
63 are music expressions:
64
65 @example
66 @{ c'4 c' c' c' @}
67 @end example
68
69 @lilypond[verbatim,quote]
70 {
71   { c'4 c' c' c'}
72   { d'4 d' d' d'}
73 }
74 @end lilypond
75
76 @lilypond[verbatim,quote]
77 <<
78   \new Staff { c'4 c' c' c' }
79   \new Staff { d'4 d' d' d' }
80 >>
81 @end lilypond
82
83 @example
84 @{
85   \new GrandStaff <<
86     \new StaffGroup <<
87       \new Staff @{ \flute @}
88       \new Staff @{ \oboe @}
89     >>
90     \new StaffGroup <<
91       \new Staff @{ \violinI @}
92       \new Staff @{ \violinII @}
93     >>
94   >>
95 @}
96 @end example
97
98 Comments are one exception to this general rule.  (For others see
99 @ref{File structure}.)  Both single-line comments and comments
100 delimited by @code{%@{ .. %@}} may be placed anywhere within an
101 input file.  They may be placed inside or outside a @code{\score}
102 block, and inside or outside the single music expression within a
103 @code{\score} block.
104
105 @seealso
106
107 Learning Manual:
108
109 @rlearning{Working on input files},
110 @rlearning{Music expressions explained},
111 @rlearning{Score is a single (compound) music expression}.
112
113
114 @node Multiple scores in a book
115 @subsection Multiple scores in a book
116
117 @funindex \book
118 @cindex movements, multiple
119
120 A document may contain multiple pieces of music and text.  Examples
121 of these are an etude book, or an orchestral part with multiple
122 movements.  Each movement is entered with a @code{\score} block,
123
124 @example
125 \score @{
126   @var{..music..}
127 @}
128 @end example
129
130 and texts are entered with a @code{\markup} block,
131
132 @example
133 \markup @{
134   @var{..text..}
135 @}
136 @end example
137
138 @funindex \book
139
140 All the movements and texts which appear in the same @code{.ly} file
141 will normally be typeset in the form of a single output file.
142
143 @example
144 \score @{
145   @var{..}
146 @}
147 \markup @{
148   @var{..}
149 @}
150 \score @{
151   @var{..}
152 @}
153 @end example
154
155 However, if you want multiple output files from the same @code{.ly}
156 file, then you can add multiple @code{\book} blocks, where each such
157 @code{\book} block will result in a separate output.  If you do not
158 specify any @code{\book} block in the file, LilyPond will implicitly
159 treat the full file as a single @code{\book} block, see @ref{File
160 structure}.  One important exception is within lilypond-book documents,
161 where you explicitly have to add a @code{\book} block, otherwise only
162 the first @code{\score} or @code{\markup} will appear in the output.
163
164 The header for each piece of music can be put inside the @code{\score}
165 block.  The @code{piece} name from the header will be printed before
166 each movement.  The title for the entire book can be put inside the
167 @code{\book}, but if it is not present, the @code{\header} which is at
168 the top of the file is inserted.
169
170 @example
171 \header @{
172   title = "Eight miniatures"
173   composer = "Igor Stravinsky"
174 @}
175 \score @{
176   @dots{}
177   \header @{ piece = "Romanze" @}
178 @}
179 \markup @{
180    ..text of second verse..
181 @}
182 \markup @{
183    ..text of third verse..
184 @}
185 \score @{
186   @dots{}
187   \header @{ piece = "Menuetto" @}
188 @}
189 @end example
190
191 @node File structure
192 @subsection File structure
193
194 @funindex \paper
195 @funindex \midi
196 @funindex \layout
197 @funindex \header
198 @funindex \score
199 @funindex \book
200
201 A @code{.ly} file may contain any number of toplevel expressions, where a
202 toplevel expression is one of the following:
203
204 @itemize @bullet
205 @item
206 An output definition, such as @code{\paper}, @code{\midi}, and
207 @code{\layout}.  Such a definition at the toplevel changes the default
208 book-wide settings.  If more than one such definition of
209 the same type is entered at the top level any definitions in the later
210 expressions have precedence.
211
212 @item
213 A direct scheme expression, such as
214 @code{#(set-default-paper-size "a7" 'landscape)} or
215 @code{#(ly:set-option 'point-and-click #f)}.
216
217 @item
218 A @code{\header} block.  This sets the global header block.  This
219 is the block containing the definitions for book-wide settings, like
220 composer, title, etc.
221
222 @item
223 A @code{\score} block.  This score will be collected with other
224 toplevel scores, and combined as a single @code{\book}.
225 This behavior can be changed by setting the variable
226 @code{toplevel-score-handler} at toplevel.  The default handler is
227 defined in the init file @file{scm/@/lily@/.scm}.
228
229 @item
230 A @code{\book} block logically combines multiple movements
231 (i.e., multiple @code{\score} blocks) in one document.  If there
232 are a number of @code{\score}s, one output file will be created
233 for each @code{\book} block, in which all corresponding movements
234 are concatenated.  The only reason to explicitly specify
235 @code{\book} blocks in a @code{.ly} file is if you wish to create
236 multiple output files from a single input file.  One exception is
237 within lilypond-book documents, where you explicitly have to add
238 a @code{\book} block if you want more than a single @code{\score}
239 or @code{\markup} in the same example.  This behavior can be
240 changed by setting the variable @code{toplevel-book-handler} at
241 toplevel.  The default handler is defined in the init file
242 @file{scm/@/lily@/.scm}.
243
244 @item
245 A compound music expression, such as
246 @example
247 @{ c'4 d' e'2 @}
248 @end example
249
250 This will add the piece in a @code{\score} and format it in a
251 single book together with all other toplevel @code{\score}s and music
252 expressions.  In other words, a file containing only the above
253 music expression will be translated into
254
255 @example
256 \book @{
257   \score @{
258     \new Staff @{
259       \new Voice @{
260         @{ c'4 d' e'2 @}
261       @}
262     @}
263   @}
264         \layout @{ @}
265         \header @{ @}
266 @}
267 @end example
268
269 This behavior can be changed by setting the variable
270 @code{toplevel-music-handler} at toplevel.  The default handler is
271 defined in the init file @file{scm/@/lily@/.scm}.
272
273 @item
274 A markup text, a verse for example
275 @example
276 \markup @{
277    2.  The first line verse two.
278 @}
279 @end example
280
281 Markup texts are rendered above, between or below the scores or music
282 expressions, wherever they appear.
283
284 @cindex variables
285
286 @item
287 A variable, such as
288 @example
289 foo = @{ c4 d e d @}
290 @end example
291
292 This can be used later on in the file by entering @code{\foo}.  The
293 name of an variable should have alphabetic characters only; no
294 numbers, underscores or dashes.
295
296 @end itemize
297
298 The following example shows three things that may be entered at
299 toplevel
300
301 @example
302 \layout @{
303   % Don't justify the output
304   ragged-right = ##t
305 @}
306
307 \header @{
308    title = "Do-re-mi"
309 @}
310
311 @{ c'4 d' e2 @}
312 @end example
313
314
315 At any point in a file, any of the following lexical instructions can
316 be entered:
317
318 @itemize
319 @item @code{\version}
320 @item @code{\include}
321 @item @code{\sourcefilename}
322 @item @code{\sourcefileline}
323 @item
324 A single-line comment, introduced by a leading @code{%} sign.
325
326 @item
327 A multi-line comment delimited by @code{%@{ .. %@}}.
328
329 @end itemize
330
331 @seealso
332
333 Learning Manual:
334 @rlearning{How LilyPond input files work}.
335
336 @node Useful concepts and properties
337 @section Useful concepts and properties
338
339
340 @menu
341 * Input modes::
342 * Controlling direction and placement::
343 * Distances and measurements::
344 * Spanners::
345 @end menu
346
347 @node Input modes
348 @subsection Input modes
349
350 The way in which the notation contained within an input file is
351 interpreted is determined by the current input mode.
352
353 @strong{Chord mode}
354
355 This is activated with the @code{\chordmode} command, and causes
356 input to be interpreted with the syntax of chord notation, see
357 @ref{Chord notation}.  Chords are rendered as notes on a staff.
358
359 Chord mode is also activated with the @code{\chords} command.
360 This also creates a new @code{ChordNames} context and
361 causes the following input to be interpreted with the syntax of
362 chord notation and rendered as chord names in the @code{ChordNames}
363 context, see @ref{Printing chord names}.
364
365 @strong{Drum mode}
366
367 This is activated with the @code{\drummode} command, and causes
368 input to be interpreted with the syntax of drum notation, see
369 @ref{Basic percussion notation}.
370
371 Drum mode is also activated with the @code{\drums} command.
372 This also creates a new @code{DrumStaff} context and causes the
373 following input to be interpreted with the syntax of drum notation
374 and rendered as drum symbols on a drum staff, see @ref{Basic
375 percussion notation}.
376
377 @strong{Figure mode}
378
379 This is activated with the @code{\figuremode} command, and causes
380 input to be interpreted with the syntax of figured bass, see
381 @ref{Entering figured bass}.
382
383 Figure mode is also activated with the @code{\figures} command.
384 This also creates a new @code{FiguredBass} context and causes the
385 following input to be interpreted with the figured bass syntax
386 and rendered as figured bass symbols in the @code{FiguredBass}
387 context, see @ref{Introduction to figured bass}.
388
389 @strong{Fret and tab modes}
390
391 There are no special input modes for entering fret and tab symbols.
392
393 To create tab diagrams, enter notes or chords in note mode and
394 render them in a @code{TabStaff} context, see
395 @ref{Default tablatures}.
396
397 To create fret diagrams above a staff, enter them as markup
398 above the notes using the @code{\fret-diagram} command, see
399 @ref{Fret diagrams}.
400
401 @strong{Lyrics mode}
402
403 This is activated with the @code{\lyricmode} command, and causes
404 input to be interpreted as lyric syllables with optional durations
405 and associated lyric modifiers, see @ref{Vocal music}.
406
407 Lyric mode is also activated with the @code{\addlyrics} command.
408 This also creates a new @code{Lyrics} context and an implicit
409 @code{\lyricsto} command which associates the following lyrics
410 with the preceding music.
411
412 @strong{Markup mode}
413
414 This is activated with the @code{\markup} command, and causes
415 input to be interpreted with the syntax of markup, see
416 @ref{Text markup commands}.
417
418 @c silly work-around for texinfo broken-ness
419 @c (@strong{Note...} causes a spurious cross-reference in Info)
420 @b{Note mode}
421
422 This is the default mode or it may be activated with the
423 @code{\notemode} command.  Input is interpreted as pitches,
424 durations, markup, etc and typeset as musical notation on a staff.
425
426 It is not normally necessary to specify note mode explicitly, but
427 it may be useful to do so in certain situations, for example if you
428 are in lyric mode, chord mode or any other mode and want to insert
429 something that only can be done with note mode syntax.
430
431 For example, to indicate dynamic markings for the verses of a
432 choral pieces it is necessary to enter note mode to interpret
433 the markings:
434
435 @lilypond[verbatim,relative=2,quote]
436 { c4 c4 c4 c4 }
437 \addlyrics {
438   \notemode{\set stanza = \markup{ \dynamic f 1. } }
439   To be sung loudly
440 }
441 \addlyrics {
442   \notemode{\set stanza = \markup{ \dynamic p 2. } }
443   To be sung quietly
444 }
445 @end lilypond
446
447
448
449 @node Controlling direction and placement
450 @subsection Controlling direction and placement
451
452 TODO: Maybe rename section to "directions".
453
454 In typesetting music the direction and placement of many items is
455 a matter of choice.  For example, the stems of notes can
456 be directed up or down; lyrics, dynamics, and other expressive
457 marks may be placed above or below the staff; text may be aligned
458 left, right or center; etc.  Most of these choices may be left to
459 be determined automatically by LilyPond, but in some cases it may
460 be desirable to force a particular direction or placement.
461
462 @strong{Default actions}
463
464 By default some directions are always up or always down (e.g.
465 dynamics or fermata), while other things can alternate between
466 up or down based on the stem direction (like slurs or accents).
467
468 @c TODO Add table showing these
469
470 @strong{Context layout}
471
472 Contexts are positioned in a system from top to bottom in the
473 order in which they are encountered.  Note, however, that a
474 context will be created implicitly if a command is encountered
475 when there is no suitable context available to contain it.
476
477 @c TODO Add example ?
478
479 The default order in which contexts are laid out can be changed,
480 see @ref{Aligning contexts}
481
482 @strong{Articulation direction indicators}
483
484 When adding articulations to notes the direction indicator,
485 @code{^} (meaning @qq{up}), @code{_} (meaning @qq{down}) or
486 @code{-} (meaning @qq{use default direction}), can usually be
487 omitted, in which case @code{-} is assumed.  But a direction
488 indicator is @strong{always} required before
489
490 @itemize
491 @item @code{\tweak} commands
492 @item @code{\markup} commands
493 @item @code{\tag} commands
494 @item string markups, e.g. -"string"
495 @item fingering instructions, e.g. @code{-1}
496 @item articulation shortcuts, e.g. @code{-.}, @code{->}, @code{--}
497 @end itemize
498
499 @strong{The direction property}
500
501 The position or direction of many layout objects is controlled
502 by the @code{direction} property.
503
504 The value of the @code{direction} property may be
505 set to @code{1}, meaning @qq{up} or @qq{above}, or to @code{-1},
506 meaning @qq{down} or @qq{below}.  The symbols @code{UP} and
507 @code{DOWN} may be used instead of @code{1} and @code{-1}
508 respectively.  The default direction may be specified by setting
509 @code{direction} to @code{0} or @code{CENTER}.  Alternatively,
510 in many cases predefined commands
511 exist to specify the direction.  These are all of the form
512
513 @noindent
514 @code{\xxxUp}, @code{xxxDown}, @code{xxxNeutral}
515
516 @noindent
517 where @code{xxxNeutral} means @qq{use the default direction}.
518 See @rlearning{Within-staff objects}.
519
520 In a few cases, arpeggio being the only common example, the value
521 of the @code{direction} property specifies whether the object
522 is to be placed to the right or left of the parent object.  In
523 this case @code{-1} or @code{LEFT} means @qq{to the left} and
524 @code{1} or @code{RIGHT} means @qq{to the right}.  @code{0}
525 or @code{CENTER} means @qq{use the default} direction, as before.
526
527 @ignore
528 These all have side-axis set to #X
529 AmbitusAccidental - direction has no effect
530 Arpeggio - works
531 StanzaNumber - not tried
532 TrillPitchAccidental - not tried
533 TrillPitchGroup - not tried
534 @end ignore
535
536
537
538 @node Distances and measurements
539 @subsection Distances and measurements
540
541 DISCUSS after working on other sections.
542
543 TODO: staff spaces.  Maybe move into tweaks?
544
545
546 @node Spanners
547 @subsection Spanners
548
549
550 @node Titles and headers
551 @section Titles and headers
552
553 Almost all printed music includes a title and the composer's name;
554 some pieces include a lot more information.
555
556 @menu
557 * Creating titles::
558 * Custom titles::
559 * Reference to page numbers::
560 * Table of contents::
561 @end menu
562
563
564 @node Creating titles
565 @subsection Creating titles
566
567 Titles are created for each @code{\score} block, as well as for the full
568 input file (or @code{\book} block).
569
570 The contents of the titles are taken from the @code{\header} blocks.
571 The header block for a book supports the following
572
573
574 @table @code
575 @funindex dedication
576 @item dedication
577 The dedicatee of the music, centered at the top of the first page.
578
579 @funindex title
580 @item title
581 The title of the music, centered just below the dedication.
582
583 @funindex subtitle
584 @item subtitle
585 Subtitle, centered below the title.
586
587 @funindex subsubtitle
588 @item subsubtitle
589 Subsubtitle, centered below the subtitle.
590
591 @funindex poet
592 @item poet
593 Name of the poet, flush-left below the subtitle.
594
595 @funindex composer
596 @item composer
597 Name of the composer, flush-right below the subtitle.
598
599 @funindex meter
600 @item meter
601 Meter string, flush-left below the poet.
602
603 @funindex opus
604 @item opus
605 Name of the opus, flush-right below the composer.
606
607 @funindex arranger
608 @item arranger
609 Name of the arranger, flush-right below the opus.
610
611 @funindex instrument
612 @item instrument
613 Name of the instrument, centered below the arranger.  Also
614 centered at the top of pages (other than the first page).
615
616 @funindex piece
617 @item piece
618 Name of the piece, flush-left below the instrument.
619
620 @cindex page breaks, forcing
621 @funindex breakbefore
622 @item breakbefore
623 This forces the title to start on a new page (set to ##t or ##f).
624
625 @funindex copyright
626 @item copyright
627 Copyright notice, centered at the bottom of the first page.  To
628 insert the copyright symbol, see @ref{Text encoding}.
629
630 @funindex tagline
631 @item tagline
632 Centered at the bottom of the last page.
633
634 @end table
635
636 Here is a demonstration of the fields available.  Note that you
637 may use any @ref{Formatting text}, commands in the header.
638
639 @lilypond[quote,verbatim,line-width=11.0\cm]
640 \paper {
641   line-width = 9.0\cm
642   paper-height = 10.0\cm
643 }
644
645 \book {
646   \header {
647     dedication = "dedicated to me"
648     title = \markup \center-align { "Title first line" "Title second line,
649 longer" }
650     subtitle = "the subtitle,"
651     subsubtitle = #(string-append "subsubtitle LilyPond version "
652 (lilypond-version))
653     poet = "Poet"
654     composer =  \markup \center-align { "composer" \small "(1847-1973)" }
655     texttranslator = "Text Translator"
656     meter = \markup { \teeny "m" \tiny "e" \normalsize "t" \large "e" \huge
657 "r" }
658     arranger = \markup { \fontsize #8.5 "a" \fontsize #2.5 "r" \fontsize
659 #-2.5 "r" \fontsize #-5.3 "a" \fontsize #7.5 "nger" }
660     instrument = \markup \bold \italic "instrument"
661     piece = "Piece"
662   }
663
664   \score {
665     { c'1 }
666     \header {
667       piece = "piece1"
668       opus = "opus1"
669     }
670   }
671   \markup {
672       and now...
673   }
674   \score {
675     { c'1 }
676     \header {
677       piece = "piece2"
678       opus = "opus2"
679     }
680   }
681 }
682 @end lilypond
683
684 As demonstrated before, you can use multiple @code{\header} blocks.
685 When same fields appear in different blocks, the latter is used.
686 Here is a short example.
687
688 @example
689 \header @{
690   composer = "Composer"
691 @}
692 \header @{
693   piece = "Piece"
694 @}
695 \score @{
696   \new Staff @{ c'4 @}
697   \header @{
698     piece = "New piece"  % overwrite previous one
699   @}
700 @}
701 @end example
702
703 If you define the @code{\header} inside the @code{\score} block, then
704 normally only the @code{piece} and @code{opus} headers will be printed.
705 Note that the music expression must come before the @code{\header}.
706
707 @lilypond[quote,verbatim,line-width=11.0\cm]
708 \score {
709   { c'4 }
710   \header {
711     title = "title"  % not printed
712     piece = "piece"
713     opus = "opus"
714   }
715 }
716 @end lilypond
717
718 @funindex printallheaders
719 @noindent
720 You may change this behavior (and print all the headers when defining
721 @code{\header} inside @code{\score}) by using
722
723 @example
724 \paper@{
725   printallheaders=##t
726 @}
727 @end example
728
729 @cindex copyright
730 @cindex tagline
731
732 The default footer is empty, except for the first page, where the
733 @code{copyright} field from @code{\header} is inserted, and the last
734 page, where @code{tagline} from @code{\header} is added.  The default
735 tagline is @qq{Music engraving by LilyPond (@var{version})}.@footnote{Nicely
736 printed parts are good PR for us, so please leave the tagline if you
737 can.}
738
739 Headers may be completely removed by setting them to false.
740
741 @example
742 \header @{
743   tagline = ##f
744   composer = ##f
745 @}
746 @end example
747
748
749 @node Custom titles
750 @subsection Custom titles
751
752 A more advanced option is to change the definitions of the following
753 variables in the @code{\paper} block.  The init file
754 @file{ly/titling-init.ly} lists the default layout.
755
756 @table @code
757 @funindex bookTitleMarkup
758 @item bookTitleMarkup
759   This is the title added at the top of the entire output document.
760 Typically, it has the composer and the title of the piece
761
762 @funindex scoreTitleMarkup
763 @item scoreTitleMarkup
764   This is the title put over a @code{\score} block.  Typically, it has
765 the name of the movement (@code{piece} field).
766
767 @funindex oddHeaderMarkup
768 @item oddHeaderMarkup
769   This is the page header for odd-numbered pages.
770
771 @funindex evenHeaderMarkup
772 @item evenHeaderMarkup
773   This is the page header for even-numbered pages.  If unspecified,
774   the odd header is used instead.
775
776   By default, headers are defined such that the page number is on the
777   outside edge, and the instrument is centered.
778
779 @funindex oddFooterMarkup
780 @item oddFooterMarkup
781   This is the page footer for odd-numbered pages.
782
783 @funindex evenFooterMarkup
784 @item evenFooterMarkup
785   This is the page footer for even-numbered pages.  If unspecified,
786   the odd header is used instead.
787
788   By default, the footer has the copyright notice on the first, and
789   the tagline on the last page.
790 @end table
791
792
793 @cindex \paper
794 @cindex header
795 @cindex footer
796 @cindex page layout
797 @cindex titles
798
799 The following definition will put the title flush left, and the
800 composer flush right on a single line.
801
802 @verbatim
803 \paper {
804   bookTitleMarkup = \markup {
805    \fill-line {
806      \fromproperty #'header:title
807      \fromproperty #'header:composer
808    }
809   }
810 }
811 @end verbatim
812
813 @node Reference to page numbers
814 @subsection Reference to page numbers
815
816 A particular place of a score can be marked using the @code{\label}
817 command, either at top-level or inside music.  This label can then be
818 referred to in a markup, to get the number of the page where the marked
819 point is placed, using the @code{\page-ref} markup command.
820
821 @lilypond[verbatim,line-width=11.0\cm]
822 \header { tagline = ##f }
823 \book {
824   \label #'firstScore
825   \score {
826     {
827       c'1
828       \pageBreak \mark A \label #'markA
829       c'
830     }
831   }
832
833   \markup { The first score begins on page \page-ref #'firstScore "0" "?" }
834   \markup { Mark A is on page \page-ref #'markA "0" "?" }
835 }
836 @end lilypond
837
838 The @code{\page-ref} markup command takes three arguments:
839 @enumerate
840 @item the label, a scheme symbol, eg. @code{#'firstScore};
841 @item a markup that will be used as a gauge to estimate the dimensions
842 of the markup;
843 @item a markup that will be used in place of the page number if the label 
844 is not known;
845 @end enumerate
846
847 The reason why a gauge is needed is that, at the time markups are
848 interpreted, the page breaking has not yet occurred, so the page numbers
849 are not yet known.  To work around this issue, the actual markup
850 interpretation is delayed to a later time; however, the dimensions of
851 the markup have to be known before, so a gauge is used to decide these
852 dimensions.  If the book has between 10 and 99 pages, it may be "00",
853 ie. a two digit number.
854
855 @predefined
856
857 @funindex \label
858 @code{\label}
859 @funindex \page-ref
860 @code{\page-ref}
861
862 @node Table of contents
863 @subsection Table of contents
864 A table of contents is included using the @code{\markuplines \table-of-contents}
865 command.  The elements which should appear in the table of contents are
866 entered with the @code{\tocItem} command, which may be used either at
867 top-level, or inside a music expression.
868
869 @verbatim
870 \markuplines \table-of-contents
871 \pageBreak
872
873 \tocItem \markup "First score"
874 \score { 
875   {
876     c'  % ...
877     \tocItem \markup "Some particular point in the first score"
878     d'  % ... 
879   }
880 }
881
882 \tocItem \markup "Second score"
883 \score {
884   {
885     e' % ...
886   }
887 }
888 @end verbatim
889
890 The markups which are used to format the table of contents are defined
891 in the @code{\paper} block.  The default ones are @code{tocTitleMarkup},
892 for formatting the title of the table, and @code{tocItemMarkup}, for
893 formatting the toc elements, composed of the element title and page
894 number.  These variables may be changed by the user:
895
896 @verbatim
897 \paper {
898   %% Translate the toc title into French:
899   tocTitleMarkup = \markup \huge \column {
900     \fill-line { \null "Table des matières" \null }
901     \hspace #1
902   }
903   %% use larger font size
904   tocItemMarkup = \markup \large \fill-line {
905     \fromproperty #'toc:text \fromproperty #'toc:page
906   }
907 }
908 @end verbatim
909
910 Note how the toc element text and page number are referred to in
911 the @code{tocItemMarkup} definition.
912
913 New commands and markups may also be defined to build more elaborated
914 table of contents:
915 @itemize
916 @item first, define a new markup variable in the @code{\paper} block
917 @item then, define a music function which aims at adding a toc element
918 using this markup paper variable.
919 @end itemize
920
921 In the following example, a new style is defined for entering act names
922 in the table of contents of an opera:
923
924 @verbatim
925 \paper {
926   tocActMarkup = \markup \large \column {
927     \hspace #1
928     \fill-line { \null \italic \fromproperty #'toc:text \null }
929     \hspace #1
930   }
931 }
932
933 tocAct = 
934 #(define-music-function (parser location text) (markup?)
935    (add-toc-item! 'tocActMarkup text))
936 @end verbatim
937
938 @lilypond[line-width=11.0\cm]
939 \header { tagline = ##f }
940 \paper {
941   tocActMarkup = \markup \large \column {
942     \hspace #1
943     \fill-line { \null \italic \fromproperty #'toc:text \null }
944     \hspace #1
945   }
946 }
947
948 tocAct = 
949 #(define-music-function (parser location text) (markup?)
950    (add-toc-item! 'tocActMarkup text))
951
952 \book {
953   \markuplines \table-of-contents
954   \tocAct \markup { Atto Primo }
955   \tocItem \markup { Coro. Viva il nostro Alcide }
956   \tocItem \markup { Cesare. Presti omai l'Egizzia terra }
957   \tocAct \markup { Atto Secondo }
958   \tocItem \markup { Sinfonia }
959   \tocItem \markup { Cleopatra. V'adoro, pupille, saette d'Amore }
960   \markup \null
961 }
962 @end lilypond
963
964 @seealso
965
966 Init files: @file{ly/@/toc@/-init@/.ly}.
967
968 @predefined
969
970 @funindex \table-of-contents
971 @code{\table-of-contents}
972 @funindex \tocItem
973 @code{\tocItem}
974
975
976 @node Working with input files
977 @section Working with input files
978
979 @menu
980 * Including LilyPond files::    
981 * Different editions from one source::  
982 * Text encoding::               
983 * Displaying LilyPond notation::  
984 @end menu
985
986
987 @node Including LilyPond files
988 @subsection Including LilyPond files
989
990 @funindex \include
991 @cindex including files
992
993 A large project may be split up into separate files.  To refer to another
994 file, use
995
996 @example
997 \include "otherfile.ly"
998 @end example
999
1000 The line @code{\include "file.ly"} is equivalent to pasting the contents
1001 of file.ly into the current file at the place where you have the
1002 \include.  For example, for a large project you might write separate files
1003 for each instrument part and create a @q{full score} file which brings
1004 together the individual instrument files.
1005
1006 The initialization of LilyPond is done in a number of files that are
1007 included by default when you start the program, normally transparent to the
1008 user.  Run @code{lilypond --verbose} to see a list of paths and files that Lily
1009 finds.
1010
1011 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
1012 VERSION is in the form @q{2.6.1}) are on the path and available to
1013 @code{\include}.  Files in the
1014 current working directory are available to \include, but a file of the same
1015 name in LilyPond's installation takes precedence.  Files are
1016 available to \include from directories in the search path specified as an
1017 option when invoking @code{lilypond --include=DIR} which adds DIR to the
1018 search path.
1019
1020 The @code{\include} statement can use full path information, but with the UNIX
1021 convention @code{/} rather than the DOS/Windows @code{\}.  For example,
1022 if @file{stuff.ly} is located one directory higher than the current working
1023 directory, use
1024
1025 @example
1026 \include "../stuff.ly"
1027 @end example
1028
1029
1030 @node Different editions from one source
1031 @subsection Different editions from one source
1032
1033 @funindex \tag
1034 @cindex tag
1035
1036 The @code{\tag} command marks music expressions with a name.  These
1037 tagged expressions can be filtered out later.  With this mechanism it
1038 is possible to make different versions of the same music source.
1039
1040 In the following example, we see two versions of a piece of music, one
1041 for the full score, and one with cue notes for the instrumental part
1042
1043 @example
1044 c1
1045 <<
1046   \tag #'part <<
1047     R1 \\
1048     @{
1049       \set fontSize = #-1
1050       c4_"cue" f2 g4 @}
1051   >>
1052   \tag #'score R1
1053 >>
1054 c1
1055 @end example
1056
1057 The same can be applied to articulations, texts, etc.: they are
1058 made by prepending
1059 @example
1060 -\tag #@var{your-tag}
1061 @end example
1062 to an articulation, for example,
1063 @example
1064 c1-\tag #'part ^4
1065 @end example
1066
1067 This defines a note with a conditional fingering indication.
1068
1069 @cindex keepWithTag
1070 @cindex removeWithTag
1071 By applying the @code{\keepWithTag} and @code{\removeWithTag}
1072 commands, tagged expressions can be filtered.  For example,
1073 @example
1074 <<
1075   @var{the music}
1076   \keepWithTag #'score @var{the music}
1077   \keepWithTag #'part @var{the music}
1078 >>
1079 @end example
1080 would yield
1081
1082 @c FIXME: broken
1083 @c @lilypondfile[ragged-right,quote]{tag-filter.ly}
1084
1085 The arguments of the @code{\tag} command should be a symbol
1086 (such as @code{#'score} or @code{#'part}), followed by a
1087 music expression.  It is possible to put multiple tags on
1088 a piece of music with multiple @code{\tag} entries,
1089
1090 @example
1091   \tag #'original-part \tag #'transposed-part @dots{}
1092 @end example
1093
1094
1095 @knownissues
1096
1097 Multiple rests are not merged if you create the score with both tagged
1098 sections.
1099
1100
1101 @node Text encoding
1102 @subsection Text encoding
1103
1104 LilyPond uses the Pango library to format multi-lingual texts, and
1105 does not perform any input-encoding conversions.  This means that any
1106 text, be it title, lyric text, or musical instruction containing
1107 non-ASCII characters, must be utf-8.  The easiest way to enter such text is
1108 by using a Unicode-aware editor and saving the file with utf-8 encoding.  Most
1109 popular modern editors have utf-8 support, for example, vim, Emacs,
1110 jEdit, and GEdit do.
1111
1112 @c  Currently not working
1113 @ignore
1114 Depending on the fonts installed, the following fragment shows Hebrew
1115 and Cyrillic lyrics,
1116
1117 @cindex Cyrillic
1118 @cindex Hebrew
1119 @cindex ASCII, non
1120
1121 @li lypondfile[fontload]{utf-8.ly}
1122
1123 The @TeX{} backend does not handle encoding specially at all.  Strings
1124 in the input are put in the output as-is.  Extents of text items in the
1125 @TeX{} backend, are determined by reading a file created via the
1126 @file{texstr} backend,
1127
1128 @example
1129 lilypond -dbackend=texstr input/les-nereides.ly
1130 latex les-nereides.texstr
1131 @end example
1132
1133 The last command produces @file{les-nereides.textmetrics}, which is
1134 read when you execute
1135
1136 @example
1137 lilypond -dbackend=tex input/les-nereides.ly
1138 @end example
1139
1140 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
1141 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
1142 interpreting non-ASCII strings.
1143
1144 @end ignore
1145
1146 To use a Unicode escape sequence, use
1147
1148 @example
1149 #(ly:export (ly:wide-char->utf-8 #x2014))
1150 @end example
1151
1152
1153 @node Displaying LilyPond notation
1154 @subsection Displaying LilyPond notation
1155
1156 @funindex \displayLilyMusic
1157 Displaying a music expression in LilyPond notation can be
1158 done using the music function @code{\displayLilyMusic}.  For example,
1159
1160 @example
1161 @{
1162   \displayLilyMusic \transpose c a, @{ c e g a bes @}
1163 @}
1164 @end example
1165
1166 will display
1167
1168 @example
1169 @{ a, cis e fis g @}
1170 @end example
1171
1172 By default, LilyPond will print these messages to the console along
1173 with all the other messages.  To split up these messages and save
1174 the results of @code{\display@{STUFF@}}, redirect the output to
1175 a file.
1176
1177 @example
1178 lilypond file.ly >display.txt
1179 @end example
1180
1181
1182
1183 @node Controlling output
1184 @section Controlling output
1185
1186 @menu
1187 * Extracting fragments of notation::  
1188 * Skipping corrected music::    
1189 @end menu
1190
1191 @node Extracting fragments of notation
1192 @subsection Extracting fragments of notation
1193
1194 It is possible to quote small fragments of a large score directly from
1195 the output.  This can be compared to clipping a piece of a paper score
1196 with scissors.
1197
1198 This is done by defining the measures that need to be cut out
1199 separately.  For example, including the following definition
1200
1201
1202 @verbatim
1203 \layout {
1204   clip-regions
1205   = #(list
1206       (cons
1207        (make-rhythmic-location 5 1 2)
1208        (make-rhythmic-location 7 3 4)))
1209 }       
1210 @end verbatim
1211
1212 @noindent
1213 will extract a fragment starting halfway the fifth measure, ending in
1214 the seventh measure.  The meaning of @code{5 1 2} is: after a 1/2 note
1215 in measure 5, and @code{7 3 4} after 3 quarter notes in measure 7.
1216
1217 More clip regions can be defined by adding more pairs of
1218 rhythmic-locations to the list. 
1219
1220 In order to use this feature, LilyPond must be invoked with
1221 @code{-dclip-systems}.  The clips are output as EPS files, and are
1222 converted to PDF and PNG if these formats are switched on as well.
1223
1224 For more information on output formats, see @rprogram{Invoking lilypond}.
1225
1226 @node Skipping corrected music
1227 @subsection Skipping corrected music
1228
1229
1230 @funindex skipTypesetting
1231 @funindex showLastLength
1232
1233 When entering or copying music, usually only the music near the end (where
1234 you
1235 are adding notes) is interesting to view and correct.  To speed up
1236 this correction process, it is possible to skip typesetting of all but
1237 the last few measures.  This is achieved by putting
1238
1239 @verbatim
1240 showLastLength = R1*5
1241 \score { ... }
1242 @end verbatim
1243
1244 @noindent
1245 in your source file.  This will render only the last 5 measures
1246 (assuming 4/4 time signature) of every @code{\score} in the input
1247 file.  For longer pieces, rendering only a small part is often an order
1248 of magnitude quicker than rendering it completely
1249
1250 Skipping parts of a score can be controlled in a more fine-grained
1251 fashion with the property @code{Score.skipTypesetting}.  When it is
1252 set, no typesetting is performed at all.
1253
1254 This property is also used to control output to the MIDI file.  Note that
1255 it skips all events, including tempo and instrument changes.  You have
1256 been warned.
1257
1258 @lilypond[quote,fragment,ragged-right,verbatim]
1259 \relative c'' {
1260   c8 d
1261   \set Score.skipTypesetting = ##t
1262   e e e e e e e e
1263   \set Score.skipTypesetting = ##f
1264   c d b bes a g c2 }
1265 @end lilypond
1266
1267 In polyphonic music, @code{Score.skipTypesetting} will affect all
1268 voices and staves, saving even more time.
1269
1270