]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/input.itely
Merge branch 'master' of ssh+git://hanwen@git.sv.gnu.org/srv/git/lilypond
[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 @strong{Note mode}
419
420 This is the default mode or it may be activated with the
421 @code{\notemode} command.  Input is interpreted as pitches,
422 durations, markup, etc and typeset as musical notation on a staff.
423
424 It is not normally necessary to specify note mode explicitly, but
425 it may be useful to do so in certain situations, for example if you
426 are in lyric mode, chord mode or any other mode and want to insert
427 something that only can be done with note mode syntax.
428
429 For example, to indicate dynamic markings for the verses of a
430 choral pieces it is necessary to enter note mode to interpret
431 the markings:
432
433 @lilypond[verbatim,relative=2,quote]
434 { c4 c4 c4 c4 }
435 \addlyrics {
436   \notemode{\set stanza = \markup{ \dynamic f 1. } }
437   To be sung loudly
438 }
439 \addlyrics {
440   \notemode{\set stanza = \markup{ \dynamic p 2. } }
441   To be sung quietly
442 }
443 @end lilypond
444
445
446
447 @node Controlling direction and placement
448 @subsection Controlling direction and placement
449
450 TODO: Maybe rename section to "directions".
451
452 In typesetting music the direction and placement of many items is
453 a matter of choice.  For example, the stems of notes can
454 be directed up or down; lyrics, dynamics, and other expressive
455 marks may be placed above or below the staff; text may be aligned
456 left, right or center; etc.  Most of these choices may be left to
457 be determined automatically by LilyPond, but in some cases it may
458 be desirable to force a particular direction or placement.
459
460 @strong{Default actions}
461
462 By default some directions are always up or always down (e.g.
463 dynamics or fermata), while other things can alternate between
464 up or down based on the stem direction (like slurs or accents).
465
466 @c TODO Add table showing these
467
468 @strong{Context layout}
469
470 Contexts are positioned in a system from top to bottom in the
471 order in which they are encountered.  Note, however, that a
472 context will be created implicitly if a command is encountered
473 when there is no suitable context available to contain it.
474
475 @c TODO Add example ?
476
477 The default order in which contexts are laid out can be changed,
478 see @ref{Aligning contexts}
479
480 @strong{Articulation direction indicators}
481
482 When adding articulations to notes the direction indicator,
483 @code{^} (meaning @qq{up}), @code{_} (meaning @qq{down}) or
484 @code{-} (meaning @qq{use default direction}), can usually be
485 omitted, in which case @code{-} is assumed.  But a direction
486 indicator is @strong{always} required before
487
488 @itemize
489 @item @code{\tweak} commands
490 @item @code{\markup} commands
491 @item @code{\tag} commands
492 @item string markups, e.g. -"string"
493 @item fingering instructions, e.g. @code{-1}
494 @item articulation shortcuts, e.g. @code{-.}, @code{->}, @code{--}
495 @end itemize
496
497 @strong{The direction property}
498
499 The position or direction of many layout objects is controlled
500 by the @code{direction} property.
501
502 The value of the @code{direction} property may be
503 set to @code{1}, meaning @qq{up} or @qq{above}, or to @code{-1},
504 meaning @qq{down} or @qq{below}.  The symbols @code{UP} and
505 @code{DOWN} may be used instead of @code{1} and @code{-1}
506 respectively.  The default direction may be specified by setting
507 @code{direction} to @code{0} or @code{CENTER}.  Alternatively,
508 in many cases predefined commands
509 exist to specify the direction.  These are all of the form
510
511 @noindent
512 @code{\xxxUp}, @code{xxxDown}, @code{xxxNeutral}
513
514 @noindent
515 where @code{xxxNeutral} means @qq{use the default direction}.
516 See @rlearning{Within-staff objects}.
517
518 In a few cases, arpeggio being the only common example, the value
519 of the @code{direction} property specifies whether the object
520 is to be placed to the right or left of the parent object.  In
521 this case @code{-1} or @code{LEFT} means @qq{to the left} and
522 @code{1} or @code{RIGHT} means @qq{to the right}.  @code{0}
523 or @code{CENTER} means @qq{use the default} direction, as before.
524
525 @ignore
526 These all have side-axis set to #X
527 AmbitusAccidental - direction has no effect
528 Arpeggio - works
529 StanzaNumber - not tried
530 TrillPitchAccidental - not tried
531 TrillPitchGroup - not tried
532 @end ignore
533
534
535
536 @node Distances and measurements
537 @subsection Distances and measurements
538
539 DISCUSS after working on other sections.
540
541 TODO: staff spaces.  Maybe move into tweaks?
542
543
544 @node Spanners
545 @subsection Spanners
546
547
548 @node Titles and headers
549 @section Titles and headers
550
551 Almost all printed music includes a title and the composer's name;
552 some pieces include a lot more information.
553
554 @menu
555 * Creating titles::
556 * Custom titles::
557 * Reference to page numbers::
558 * Table of contents::
559 @end menu
560
561
562 @node Creating titles
563 @subsection Creating titles
564
565 Titles are created for each @code{\score} block, as well as for the full
566 input file (or @code{\book} block).
567
568 The contents of the titles are taken from the @code{\header} blocks.
569 The header block for a book supports the following
570
571
572 @table @code
573 @funindex dedication
574 @item dedication
575 The dedicatee of the music, centered at the top of the first page.
576
577 @funindex title
578 @item title
579 The title of the music, centered just below the dedication.
580
581 @funindex subtitle
582 @item subtitle
583 Subtitle, centered below the title.
584
585 @funindex subsubtitle
586 @item subsubtitle
587 Subsubtitle, centered below the subtitle.
588
589 @funindex poet
590 @item poet
591 Name of the poet, flush-left below the subtitle.
592
593 @funindex composer
594 @item composer
595 Name of the composer, flush-right below the subtitle.
596
597 @funindex meter
598 @item meter
599 Meter string, flush-left below the poet.
600
601 @funindex opus
602 @item opus
603 Name of the opus, flush-right below the composer.
604
605 @funindex arranger
606 @item arranger
607 Name of the arranger, flush-right below the opus.
608
609 @funindex instrument
610 @item instrument
611 Name of the instrument, centered below the arranger.  Also
612 centered at the top of pages (other than the first page).
613
614 @funindex piece
615 @item piece
616 Name of the piece, flush-left below the instrument.
617
618 @cindex page breaks, forcing
619 @funindex breakbefore
620 @item breakbefore
621 This forces the title to start on a new page (set to ##t or ##f).
622
623 @funindex copyright
624 @item copyright
625 Copyright notice, centered at the bottom of the first page.  To
626 insert the copyright symbol, see @ref{Text encoding}.
627
628 @funindex tagline
629 @item tagline
630 Centered at the bottom of the last page.
631
632 @end table
633
634 Here is a demonstration of the fields available.  Note that you
635 may use any @ref{Formatting text}, commands in the header.
636
637 @lilypond[quote,verbatim,line-width=11.0\cm]
638 \paper {
639   line-width = 9.0\cm
640   paper-height = 10.0\cm
641 }
642
643 \book {
644   \header {
645     dedication = "dedicated to me"
646     title = \markup \center-align { "Title first line" "Title second line,
647 longer" }
648     subtitle = "the subtitle,"
649     subsubtitle = #(string-append "subsubtitle LilyPond version "
650 (lilypond-version))
651     poet = "Poet"
652     composer =  \markup \center-align { "composer" \small "(1847-1973)" }
653     texttranslator = "Text Translator"
654     meter = \markup { \teeny "m" \tiny "e" \normalsize "t" \large "e" \huge
655 "r" }
656     arranger = \markup { \fontsize #8.5 "a" \fontsize #2.5 "r" \fontsize
657 #-2.5 "r" \fontsize #-5.3 "a" \fontsize #7.5 "nger" }
658     instrument = \markup \bold \italic "instrument"
659     piece = "Piece"
660   }
661
662   \score {
663     { c'1 }
664     \header {
665       piece = "piece1"
666       opus = "opus1"
667     }
668   }
669   \markup {
670       and now...
671   }
672   \score {
673     { c'1 }
674     \header {
675       piece = "piece2"
676       opus = "opus2"
677     }
678   }
679 }
680 @end lilypond
681
682 As demonstrated before, you can use multiple @code{\header} blocks.
683 When same fields appear in different blocks, the latter is used.
684 Here is a short example.
685
686 @example
687 \header @{
688   composer = "Composer"
689 @}
690 \header @{
691   piece = "Piece"
692 @}
693 \score @{
694   \new Staff @{ c'4 @}
695   \header @{
696     piece = "New piece"  % overwrite previous one
697   @}
698 @}
699 @end example
700
701 If you define the @code{\header} inside the @code{\score} block, then
702 normally only the @code{piece} and @code{opus} headers will be printed.
703 Note that the music expression must come before the @code{\header}.
704
705 @lilypond[quote,verbatim,line-width=11.0\cm]
706 \score {
707   { c'4 }
708   \header {
709     title = "title"  % not printed
710     piece = "piece"
711     opus = "opus"
712   }
713 }
714 @end lilypond
715
716 @funindex printallheaders
717 @noindent
718 You may change this behavior (and print all the headers when defining
719 @code{\header} inside @code{\score}) by using
720
721 @example
722 \paper@{
723   printallheaders=##t
724 @}
725 @end example
726
727 @cindex copyright
728 @cindex tagline
729
730 The default footer is empty, except for the first page, where the
731 @code{copyright} field from @code{\header} is inserted, and the last
732 page, where @code{tagline} from @code{\header} is added.  The default
733 tagline is @qq{Music engraving by LilyPond (@var{version})}.@footnote{Nicely
734 printed parts are good PR for us, so please leave the tagline if you
735 can.}
736
737 Headers may be completely removed by setting them to false.
738
739 @example
740 \header @{
741   tagline = ##f
742   composer = ##f
743 @}
744 @end example
745
746
747 @node Custom titles
748 @subsection Custom titles
749
750 A more advanced option is to change the definitions of the following
751 variables in the @code{\paper} block.  The init file
752 @file{ly/titling-init.ly} lists the default layout.
753
754 @table @code
755 @funindex bookTitleMarkup
756 @item bookTitleMarkup
757   This is the title added at the top of the entire output document.
758 Typically, it has the composer and the title of the piece
759
760 @funindex scoreTitleMarkup
761 @item scoreTitleMarkup
762   This is the title put over a @code{\score} block.  Typically, it has
763 the name of the movement (@code{piece} field).
764
765 @funindex oddHeaderMarkup
766 @item oddHeaderMarkup
767   This is the page header for odd-numbered pages.
768
769 @funindex evenHeaderMarkup
770 @item evenHeaderMarkup
771   This is the page header for even-numbered pages.  If unspecified,
772   the odd header is used instead.
773
774   By default, headers are defined such that the page number is on the
775   outside edge, and the instrument is centered.
776
777 @funindex oddFooterMarkup
778 @item oddFooterMarkup
779   This is the page footer for odd-numbered pages.
780
781 @funindex evenFooterMarkup
782 @item evenFooterMarkup
783   This is the page footer for even-numbered pages.  If unspecified,
784   the odd header is used instead.
785
786   By default, the footer has the copyright notice on the first, and
787   the tagline on the last page.
788 @end table
789
790
791 @cindex \paper
792 @cindex header
793 @cindex footer
794 @cindex page layout
795 @cindex titles
796
797 The following definition will put the title flush left, and the
798 composer flush right on a single line.
799
800 @verbatim
801 \paper {
802   bookTitleMarkup = \markup {
803    \fill-line {
804      \fromproperty #'header:title
805      \fromproperty #'header:composer
806    }
807   }
808 }
809 @end verbatim
810
811 @node Reference to page numbers
812 @subsection Reference to page numbers
813
814 A particular place of a score can be marked using the @code{\label}
815 command, either at top-level or inside music.  This label can then be
816 referred to in a markup, to get the number of the page where the marked
817 point is placed, using the @code{\page-ref} markup command.
818
819 @lilypond[verbatim,line-width=11.0\cm]
820 \header { tagline = ##f }
821 \book {
822   \label #'firstScore
823   \score {
824     {
825       c'1
826       \pageBreak \mark A \label #'markA
827       c'
828     }
829   }
830
831   \markup { The first score begins on page \page-ref #'firstScore "0" "?" }
832   \markup { Mark A is on page \page-ref #'markA "0" "?" }
833 }
834 @end lilypond
835
836 The @code{\page-ref} markup command takes three arguments:
837 @enumerate
838 @item the label, a scheme symbol, eg. @code{#'firstScore};
839 @item a markup that will be used as a gauge to estimate the dimensions
840 of the markup;
841 @item a markup that will be used in place of the page number if the label 
842 is not known;
843 @end enumerate
844
845 The reason why a gauge is needed is that, at the time markups are
846 interpreted, the page breaking has not yet occurred, so the page numbers
847 are not yet known.  To work around this issue, the actual markup
848 interpretation is delayed to a later time; however, the dimensions of
849 the markup have to be known before, so a gauge is used to decide these
850 dimensions.  If the book has between 10 and 99 pages, it may be "00",
851 ie. a two digit number.
852
853 @predefined
854
855 @funindex \label
856 @code{\label}
857 @funindex \page-ref
858 @code{\page-ref}
859
860 @node Table of contents
861 @subsection Table of contents
862 A table of contents is included using the @code{\markuplines \table-of-contents}
863 command.  The elements which should appear in the table of contents are
864 entered with the @code{\tocItem} command, which may be used either at
865 top-level, or inside a music expression.
866
867 @verbatim
868 \markuplines \table-of-contents
869 \pageBreak
870
871 \tocItem \markup "First score"
872 \score { 
873   {
874     c'  % ...
875     \tocItem \markup "Some particular point in the first score"
876     d'  % ... 
877   }
878 }
879
880 \tocItem \markup "Second score"
881 \score {
882   {
883     e' % ...
884   }
885 }
886 @end verbatim
887
888 The markups which are used to format the table of contents are defined
889 in the @code{\paper} block.  The default ones are @code{tocTitleMarkup},
890 for formatting the title of the table, and @code{tocItemMarkup}, for
891 formatting the toc elements, composed of the element title and page
892 number.  These variables may be changed by the user:
893
894 @verbatim
895 \paper {
896   %% Translate the toc title into French:
897   tocTitleMarkup = \markup \huge \column {
898     \fill-line { \null "Table des matières" \null }
899     \hspace #1
900   }
901   %% use larger font size
902   tocItemMarkup = \markup \large \fill-line {
903     \fromproperty #'toc:text \fromproperty #'toc:page
904   }
905 }
906 @end verbatim
907
908 Note how the toc element text and page number are referred to in
909 the @code{tocItemMarkup} definition.
910
911 New commands and markups may also be defined to build more elaborated
912 table of contents:
913 @itemize
914 @item first, define a new markup variable in the @code{\paper} block
915 @item then, define a music function which aims at adding a toc element
916 using this markup paper variable.
917 @end itemize
918
919 In the following example, a new style is defined for entering act names
920 in the table of contents of an opera:
921
922 @verbatim
923 \paper {
924   tocActMarkup = \markup \large \column {
925     \hspace #1
926     \fill-line { \null \italic \fromproperty #'toc:text \null }
927     \hspace #1
928   }
929 }
930
931 tocAct = 
932 #(define-music-function (parser location text) (markup?)
933    (add-toc-item! 'tocActMarkup text))
934 @end verbatim
935
936 @lilypond[line-width=11.0\cm]
937 \header { tagline = ##f }
938 \paper {
939   tocActMarkup = \markup \large \column {
940     \hspace #1
941     \fill-line { \null \italic \fromproperty #'toc:text \null }
942     \hspace #1
943   }
944 }
945
946 tocAct = 
947 #(define-music-function (parser location text) (markup?)
948    (add-toc-item! 'tocActMarkup text))
949
950 \book {
951   \markuplines \table-of-contents
952   \tocAct \markup { Atto Primo }
953   \tocItem \markup { Coro. Viva il nostro Alcide }
954   \tocItem \markup { Cesare. Presti omai l'Egizzia terra }
955   \tocAct \markup { Atto Secondo }
956   \tocItem \markup { Sinfonia }
957   \tocItem \markup { Cleopatra. V'adoro, pupille, saette d'Amore }
958   \markup \null
959 }
960 @end lilypond
961
962 @seealso
963
964 Init files: @file{ly/@/toc@/-init@/.ly}.
965
966 @predefined
967
968 @funindex \table-of-contents
969 @code{\table-of-contents}
970 @funindex \tocItem
971 @code{\tocItem}
972
973
974 @node Working with input files
975 @section Working with input files
976
977 @menu
978 * Including LilyPond files::    
979 * Different editions from one source::  
980 * Text encoding::               
981 * Displaying LilyPond notation::  
982 @end menu
983
984
985 @node Including LilyPond files
986 @subsection Including LilyPond files
987
988 @funindex \include
989 @cindex including files
990
991 A large project may be split up into separate files.  To refer to another
992 file, use
993
994 @example
995 \include "otherfile.ly"
996 @end example
997
998 The line @code{\include "file.ly"} is equivalent to pasting the contents
999 of file.ly into the current file at the place where you have the
1000 \include.  For example, for a large project you might write separate files
1001 for each instrument part and create a @q{full score} file which brings
1002 together the individual instrument files.
1003
1004 The initialization of LilyPond is done in a number of files that are
1005 included by default when you start the program, normally transparent to the
1006 user.  Run @code{lilypond --verbose} to see a list of paths and files that Lily
1007 finds.
1008
1009 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
1010 VERSION is in the form @q{2.6.1}) are on the path and available to
1011 @code{\include}.  Files in the
1012 current working directory are available to \include, but a file of the same
1013 name in LilyPond's installation takes precedence.  Files are
1014 available to \include from directories in the search path specified as an
1015 option when invoking @code{lilypond --include=DIR} which adds DIR to the
1016 search path.
1017
1018 The @code{\include} statement can use full path information, but with the UNIX
1019 convention @code{/} rather than the DOS/Windows @code{\}.  For example,
1020 if @file{stuff.ly} is located one directory higher than the current working
1021 directory, use
1022
1023 @example
1024 \include "../stuff.ly"
1025 @end example
1026
1027
1028 @node Different editions from one source
1029 @subsection Different editions from one source
1030
1031 @funindex \tag
1032 @cindex tag
1033
1034 The @code{\tag} command marks music expressions with a name.  These
1035 tagged expressions can be filtered out later.  With this mechanism it
1036 is possible to make different versions of the same music source.
1037
1038 In the following example, we see two versions of a piece of music, one
1039 for the full score, and one with cue notes for the instrumental part
1040
1041 @example
1042 c1
1043 <<
1044   \tag #'part <<
1045     R1 \\
1046     @{
1047       \set fontSize = #-1
1048       c4_"cue" f2 g4 @}
1049   >>
1050   \tag #'score R1
1051 >>
1052 c1
1053 @end example
1054
1055 The same can be applied to articulations, texts, etc.: they are
1056 made by prepending
1057 @example
1058 -\tag #@var{your-tag}
1059 @end example
1060 to an articulation, for example,
1061 @example
1062 c1-\tag #'part ^4
1063 @end example
1064
1065 This defines a note with a conditional fingering indication.
1066
1067 @cindex keepWithTag
1068 @cindex removeWithTag
1069 By applying the @code{\keepWithTag} and @code{\removeWithTag}
1070 commands, tagged expressions can be filtered.  For example,
1071 @example
1072 <<
1073   @var{the music}
1074   \keepWithTag #'score @var{the music}
1075   \keepWithTag #'part @var{the music}
1076 >>
1077 @end example
1078 would yield
1079
1080 @c FIXME: broken
1081 @c @lilypondfile[ragged-right,quote]{tag-filter.ly}
1082
1083 The arguments of the @code{\tag} command should be a symbol
1084 (such as @code{#'score} or @code{#'part}), followed by a
1085 music expression.  It is possible to put multiple tags on
1086 a piece of music with multiple @code{\tag} entries,
1087
1088 @example
1089   \tag #'original-part \tag #'transposed-part @dots{}
1090 @end example
1091
1092
1093 @knownissues
1094
1095 Multiple rests are not merged if you create the score with both tagged
1096 sections.
1097
1098
1099 @node Text encoding
1100 @subsection Text encoding
1101
1102 LilyPond uses the Pango library to format multi-lingual texts, and
1103 does not perform any input-encoding conversions.  This means that any
1104 text, be it title, lyric text, or musical instruction containing
1105 non-ASCII characters, must be utf-8.  The easiest way to enter such text is
1106 by using a Unicode-aware editor and saving the file with utf-8 encoding.  Most
1107 popular modern editors have utf-8 support, for example, vim, Emacs,
1108 jEdit, and GEdit do.
1109
1110 @c  Currently not working
1111 @ignore
1112 Depending on the fonts installed, the following fragment shows Hebrew
1113 and Cyrillic lyrics,
1114
1115 @cindex Cyrillic
1116 @cindex Hebrew
1117 @cindex ASCII, non
1118
1119 @li lypondfile[fontload]{utf-8.ly}
1120
1121 The @TeX{} backend does not handle encoding specially at all.  Strings
1122 in the input are put in the output as-is.  Extents of text items in the
1123 @TeX{} backend, are determined by reading a file created via the
1124 @file{texstr} backend,
1125
1126 @example
1127 lilypond -dbackend=texstr input/les-nereides.ly
1128 latex les-nereides.texstr
1129 @end example
1130
1131 The last command produces @file{les-nereides.textmetrics}, which is
1132 read when you execute
1133
1134 @example
1135 lilypond -dbackend=tex input/les-nereides.ly
1136 @end example
1137
1138 Both @file{les-nereides.texstr} and @file{les-nereides.tex} need
1139 suitable LaTeX wrappers to load appropriate La@TeX{} packages for
1140 interpreting non-ASCII strings.
1141
1142 @end ignore
1143
1144 To use a Unicode escape sequence, use
1145
1146 @example
1147 #(ly:export (ly:wide-char->utf-8 #x2014))
1148 @end example
1149
1150
1151 @node Displaying LilyPond notation
1152 @subsection Displaying LilyPond notation
1153
1154 @funindex \displayLilyMusic
1155 Displaying a music expression in LilyPond notation can be
1156 done using the music function @code{\displayLilyMusic}.  For example,
1157
1158 @example
1159 @{
1160   \displayLilyMusic \transpose c a, @{ c e g a bes @}
1161 @}
1162 @end example
1163
1164 will display
1165
1166 @example
1167 @{ a, cis e fis g @}
1168 @end example
1169
1170 By default, LilyPond will print these messages to the console along
1171 with all the other messages.  To split up these messages and save
1172 the results of @code{\display@{STUFF@}}, redirect the output to
1173 a file.
1174
1175 @example
1176 lilypond file.ly >display.txt
1177 @end example
1178
1179
1180
1181 @node Controlling output
1182 @section Controlling output
1183
1184 @menu
1185 * Extracting fragments of notation::  
1186 * Skipping corrected music::    
1187 @end menu
1188
1189 @node Extracting fragments of notation
1190 @subsection Extracting fragments of notation
1191
1192 It is possible to quote small fragments of a large score directly from
1193 the output.  This can be compared to clipping a piece of a paper score
1194 with scissors.
1195
1196 This is done by defining the measures that need to be cut out
1197 separately.  For example, including the following definition
1198
1199
1200 @verbatim
1201 \layout {
1202   clip-regions
1203   = #(list
1204       (cons
1205        (make-rhythmic-location 5 1 2)
1206        (make-rhythmic-location 7 3 4)))
1207 }       
1208 @end verbatim
1209
1210 @noindent
1211 will extract a fragment starting halfway the fifth measure, ending in
1212 the seventh measure.  The meaning of @code{5 1 2} is: after a 1/2 note
1213 in measure 5, and @code{7 3 4} after 3 quarter notes in measure 7.
1214
1215 More clip regions can be defined by adding more pairs of
1216 rhythmic-locations to the list. 
1217
1218 In order to use this feature, LilyPond must be invoked with
1219 @code{-dclip-systems}.  The clips are output as EPS files, and are
1220 converted to PDF and PNG if these formats are switched on as well.
1221
1222 For more information on output formats, see @rprogram{Invoking lilypond}.
1223
1224 @node Skipping corrected music
1225 @subsection Skipping corrected music
1226
1227
1228 @funindex skipTypesetting
1229 @funindex showLastLength
1230
1231 When entering or copying music, usually only the music near the end (where
1232 you
1233 are adding notes) is interesting to view and correct.  To speed up
1234 this correction process, it is possible to skip typesetting of all but
1235 the last few measures.  This is achieved by putting
1236
1237 @verbatim
1238 showLastLength = R1*5
1239 \score { ... }
1240 @end verbatim
1241
1242 @noindent
1243 in your source file.  This will render only the last 5 measures
1244 (assuming 4/4 time signature) of every @code{\score} in the input
1245 file.  For longer pieces, rendering only a small part is often an order
1246 of magnitude quicker than rendering it completely
1247
1248 Skipping parts of a score can be controlled in a more fine-grained
1249 fashion with the property @code{Score.skipTypesetting}.  When it is
1250 set, no typesetting is performed at all.
1251
1252 This property is also used to control output to the MIDI file.  Note that
1253 it skips all events, including tempo and instrument changes.  You have
1254 been warned.
1255
1256 @lilypond[quote,fragment,ragged-right,verbatim]
1257 \relative c'' {
1258   c8 d
1259   \set Score.skipTypesetting = ##t
1260   e e e e e e e e
1261   \set Score.skipTypesetting = ##f
1262   c d b bes a g c2 }
1263 @end lilypond
1264
1265 In polyphonic music, @code{Score.skipTypesetting} will affect all
1266 voices and staves, saving even more time.
1267
1268