]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/usage/lilypond-book.itely
2fd6d4fe0a3bcb5d5d2ecb40390628855271e5a5
[lilypond.git] / Documentation / usage / lilypond-book.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
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.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.14.0"
12
13 @c Note: keep this node named so that `info lilypond-book' brings you here.
14 @node lilypond-book
15 @chapter Running @command{lilypond-book}
16
17 If you want to add pictures of music to a document, you can simply do it
18 the way you would do with other types of pictures.  The pictures are
19 created separately, yielding PostScript output or PNG images, and those
20 are included into a @LaTeX{} or HTML document.
21
22 @command{lilypond-book} provides a way to automate this process: This
23 program extracts snippets of music from your document, runs
24 @command{lilypond} on them, and outputs the document with pictures
25 substituted for the music.  The line width and font size definitions for
26 the music are adjusted to match the layout of your document.
27
28 This is a separate program from @command{lilypond} itself, and is run
29 on the command line; for more information, see @ref{Command-line
30 usage}.  If you have MacOS 10.3 or 10.4 and you have trouble running
31 @code{lilypond-book}, see @rweb{MacOS X}.
32
33 This procedure may be applied to @LaTeX{}, HTML, Texinfo or DocBook
34 documents.
35
36 @cindex texinfo
37 @cindex latex
38 @cindex texinfo
39 @cindex texi
40 @cindex html
41 @cindex docbook
42 @cindex documents, adding music to
43 @cindex HTML, music in
44 @cindex Texinfo, music in
45 @cindex DocBook, music in
46 @cindex @LaTeX{}, music in
47
48 @menu
49 * An example of a musicological document::
50 * Integrating music and text::
51 * Music fragment options::
52 * Invoking lilypond-book::
53 * Filename extensions::
54 * lilypond-book templates::
55 * Sharing the table of contents::
56 * Alternate methods of mixing text and music::
57 @end menu
58
59
60 @node An example of a musicological document
61 @section An example of a musicological document
62
63 @cindex musicology
64 Some texts contain music examples.  These texts are musicological
65 treatises, songbooks, or manuals like this.  Such texts can be made by
66 hand, simply by importing a PostScript figure into the word processor.
67 However, there is an automated procedure to reduce the amount of work
68 involved in HTML, @LaTeX{}, Texinfo and DocBook documents.
69
70 A script called @code{lilypond-book} will extract the music fragments,
71 format them, and put back the resulting notation.  Here we show a small
72 example for use with @LaTeX{}.  The example also contains explanatory
73 text, so we will not comment on it further.
74
75 @subheading Input
76
77 @quotation
78 @verbatim
79 \documentclass[a4paper]{article}
80
81 \begin{document}
82
83 Documents for \verb+lilypond-book+ may freely mix music and text.
84 For example,
85
86 \begin{lilypond}
87 \relative c' {
88   c2 e2 \times 2/3 { f8 a b } a2 e4
89 }
90 \end{lilypond}
91
92 Options are put in brackets.
93
94 \begin{lilypond}[fragment,quote,staffsize=26,verbatim]
95   c'4 f16
96 \end{lilypond}
97
98 Larger examples can be put into a separate file, and introduced with
99 \verb+\lilypondfile+.
100
101 \lilypondfile[quote,noindent]{screech-boink.ly}
102
103 (If needed, replace @file{screech-boink.ly} by any @file{.ly} file
104 you put in the same directory as this file.)
105
106 \end{document}
107 @end verbatim
108 @end quotation
109
110 @subheading Processing
111
112 Save the code above to a file called @file{lilybook.lytex}, then in a
113 terminal run
114
115 @c keep space after @version{} so TeX doesn't choke
116 @example
117 lilypond-book --output=out --pdf lilybook.lytex
118 @emph{lilypond-book (GNU LilyPond) @version{} }
119 @emph{Reading lilybook.lytex...}
120 @emph{..lots of stuff deleted..}
121 @emph{Compiling lilybook.tex...}
122 cd out
123 pdflatex lilybook
124 @emph{..lots of stuff deleted..}
125 xpdf lilybook
126 @emph{(replace @command{xpdf} by your favorite PDF viewer)}
127 @end example
128
129 Running @command{lilypond-book} and @command{latex} creates a lot of
130 temporary files, which would clutter up the working directory.  To
131 remedy this, use the @option{--output=@var{dir}} option.  It will create
132 the files in a separate subdirectory @file{dir}.
133
134 Finally the result of the @LaTeX{} example shown above.@footnote{This
135 tutorial is processed with Texinfo, so the example gives slightly
136 different results in layout.}  This finishes the tutorial section.
137
138 @page
139
140 @subheading Output
141
142 Documents for @command{lilypond-book} may freely mix music and text.
143 For example,
144
145 @lilypond
146 \relative c' {
147   c2 e2 \times 2/3 { f8 a b } a2 e4
148 }
149 @end lilypond
150
151 Options are put in brackets.
152
153 @lilypond[fragment,quote,staffsize=26,verbatim]
154 c'4 f16
155 @end lilypond
156
157 Larger examples can be put into a separate file, and introduced with
158 @code{\lilypondfile}.
159
160 @lilypondfile[quote,noindent]{screech-boink.ly}
161
162 If a @code{tagline} is required, either default or custom, then the
163 entire snippet must be enclosed in a @code{\book @{ @}} construct.
164
165 @lilypond[papersize=a8,verbatim]
166 \book{
167   \header{
168     title = "A scale in LilyPond"
169   }
170
171   \relative c' {
172     c d e f g a b c
173   }
174 }
175 @end lilypond
176
177 @page
178
179 @node Integrating music and text
180 @section Integrating music and text
181
182 Here we explain how to integrate LilyPond with various output formats.
183
184 @menu
185 * LaTeX::
186 * Texinfo::
187 * HTML::
188 * DocBook::
189 @end menu
190
191 @node LaTeX
192 @subsection @LaTeX{}
193
194 @LaTeX{} is the de-facto standard for publishing layouts in the exact
195 sciences.  It is built on top of the @TeX{} typesetting engine,
196 providing the best typography available anywhere.
197
198 See
199 @uref{http://@/www@/.ctan@/.org/@/tex@/-archive/@/info/@/lshort/@/english/,
200 @emph{The Not So Short Introduction to @LaTeX{}}} for an overview on how
201 to use @LaTeX{}.
202
203 @code{lilypond-book} provides the following commands and environments to include
204 music in @LaTeX{} files:
205
206 @itemize @bullet
207 @item the @code{\lilypond@{...@}} command, where you can directly enter short lilypond code
208 @item the @code{\begin@{lilypond@}...\end@{lilypond@}} environment, where you can directly enter longer lilypond code
209 @item the @code{\lilypondfile@{...@}} command to insert a lilypond file
210 @item the @code{\musicxmlfile@{...@}} command to insert a MusicXML file, which will be processed by @code{musicxml2ly} and @code{lilypond}.
211 @end itemize
212
213 In the input file, music is specified with
214
215 @example
216 \begin@{lilypond@}[options,go,here]
217   YOUR LILYPOND CODE
218 \end@{lilypond@}
219 @end example
220
221 @noindent
222 or
223
224 @example
225 \lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
226 @end example
227 or
228
229 @example
230 \lilypondfile[options,go,here]@{@var{filename}@}
231 @end example
232 or
233
234 @example
235 \musicxmlfile[options,go,here]@{@var{filename}@}
236 @end example
237
238
239 @noindent
240
241 Additionally, @code{\lilypondversion} displays the current version
242 of lilypond.
243 Running @command{lilypond-book} yields a file that can be further
244 processed with @LaTeX{}.
245
246 We show some examples here.  The @code{lilypond} environment
247
248 @example
249 \begin@{lilypond@}[quote,fragment,staffsize=26]
250   c' d' e' f' g'2 g'2
251 \end@{lilypond@}
252 @end example
253
254 @noindent
255 produces
256
257 @lilypond[quote,fragment,staffsize=26]
258 c' d' e' f' g'2 g'2
259 @end lilypond
260
261 The short version
262
263 @example
264 \lilypond[quote,fragment,staffsize=11]@{<c' e' g'>@}
265 @end example
266
267 @noindent
268 produces
269
270 @lilypond[quote,fragment,staffsize=11]{<c' e' g'>}
271
272 @noindent
273 Currently, you cannot include @code{@{} or @code{@}} within
274 @code{\lilypond@{@}}, so this command is only useful with the
275 @code{fragment} option.
276
277 The default line width of the music will be adjusted by examining the
278 commands in the document preamble, the part of the document before
279 @code{\begin@{document@}}.  The @command{lilypond-book} command sends
280 these to @LaTeX{} to find out how wide the text is.  The line width for
281 the music fragments is then adjusted to the text width.  Note that this
282 heuristic algorithm can fail easily; in such cases it is necessary to
283 use the @code{line-width} music fragment option.
284
285 @cindex titling and lilypond-book
286 @cindex \header in @LaTeX{} documents
287
288 Each snippet will call the following macros if they have been defined by
289 the user:
290
291 @itemize @bullet
292 @item @code{\preLilyPondExample} called before the music,
293
294 @item @code{\postLilyPondExample} called after the music,
295
296 @item @code{\betweenLilyPondSystem[1]} is called between systems if
297 @code{lilypond-book} has split the snippet into several PostScript
298 files.  It must be defined as taking one parameter and will be
299 passed the number of files already included in this snippet.
300 The default is to simply insert a @code{\linebreak}.
301 @end itemize
302
303 @ignore
304 Broken stuff.  :(
305
306 @cindex Latex, feta symbols
307 @cindex fetachar
308
309 To include feta symbols (such as flat, segno, etc) in a LaTeX
310 document, use @code{\input@{titledefs@}}
311
312 @example
313 \documentclass[a4paper]@{article@}
314
315 \input@{titledefs@}
316
317 \begin@{document@}
318
319 \fetachar\fetasharp
320
321 \end@{document@}
322 @end example
323
324 The font symbol names are defined in the file feta20.tex; to find
325 the location of this file, use the command
326
327 @example
328 kpsewhich feta20.tex
329 @end example
330
331 @end ignore
332
333 @snippets
334
335 Sometimes it is useful to display music elements (such as ties and slurs)
336 as if they continued after the end of the fragment.  This can be done by
337 breaking the staff and suppressing inclusion of the rest of the LilyPond
338 output.
339
340 In @LaTeX{}, define @code{\betweenLilyPondSystem} in such a way that
341 inclusion of other systems is terminated once the required number of
342 systems are included.  Since @code{\betweenLilyPondSystem} is first
343 called @emph{after} the first system, including only the first system
344 is trivial.
345
346 @example
347 \def\betweenLilyPondSystem#1@{\endinput@}
348
349 \begin@{lilypond@}[fragment]
350   c'1\( e'( c'~ \break c' d) e f\)
351 \end@{lilypond@}
352 @end example
353
354 If a greater number of systems is requested, a @TeX{} conditional must
355 be used before the @code{\endinput}.  In this example, replace @q{2} by
356 the number of systems you want in the output.
357
358 @example
359 \def\betweenLilyPondSystem#1@{
360     \ifnum#1<2\else\expandafter\endinput\fi
361 @}
362 @end example
363
364 @noindent
365 (Since @code{\endinput} immediately stops the processing of the current
366 input file we need @code{\expandafter} to delay the call of @code{\endinput}
367 after executing @code{\fi} so that the @code{\if}-@code{\fi} clause is
368 balanced.)
369
370 Remember that the definition of @code{\betweenLilyPondSystem} is
371 effective until @TeX{} quits the current group (such as the @LaTeX{}
372 environment) or is overridden by another definition (which is, in
373 most cases, for the rest of the document).  To reset your
374 definition, write
375
376 @example
377 \let\betweenLilyPondSystem\undefined
378 @end example
379
380 @noindent
381 in your @LaTeX{} source.
382
383 This may be simplified by defining a @TeX{} macro
384
385 @example
386 \def\onlyFirstNSystems#1@{
387     \def\betweenLilyPondSystem##1@{%
388       \ifnum##1<#1\else\expandafter\endinput\fi@}
389 @}
390 @end example
391
392 @noindent
393 and then saying only how many systems you want before each fragment,
394
395 @example
396 \onlyFirstNSystems@{3@}
397 \begin@{lilypond@}...\end@{lilypond@}
398 \onlyFirstNSystems@{1@}
399 \begin@{lilypond@}...\end@{lilypond@}
400 @end example
401
402
403 @seealso
404 There are specific @command{lilypond-book} command line options and
405 other details to know when processing @LaTeX{} documents, see
406 @ref{Invoking lilypond-book}.
407
408
409 @node Texinfo
410 @subsection Texinfo
411
412 Texinfo is the standard format for documentation of the GNU project.  An
413 example of a Texinfo document is this manual.  The HTML, PDF, and Info
414 versions of the manual are made from the Texinfo document.
415
416 @code{lilypond-book} provides the following commands and environments to include
417 music into Texinfo files:
418
419 @itemize @bullet
420 @item the @code{@@lilypond@{...@}} command, where you can directly enter short lilypond code
421 @item the @code{@@lilypond...@@end lilypond} environment, where you can directly enter longer lilypond code
422 @item the @code{@@lilypondfile@{...@}} command to insert a lilypond file
423 @item the @code{@@musicxmlfile@{...@}} command to insert a MusicXML file, which will be processed by @code{musicxml2ly} and @code{lilypond}.
424 @end itemize
425
426 In the input file, music is specified with
427
428 @example
429 @@lilypond[options,go,here]
430   YOUR LILYPOND CODE
431 @@end lilypond
432 @end example
433
434 @noindent
435 or
436
437 @example
438 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
439 @end example
440
441 @noindent
442 or
443
444 @example
445 @@lilypondfile[options,go,here]@{@var{filename}@}
446 @end example
447 or
448
449 @example
450 @@musicxmlfile[options,go,here]@{@var{filename}@}
451 @end example
452
453 Additionally, @code{@@lilypondversion} displays the current version
454 of lilypond.
455
456 When @command{lilypond-book} is run on it, this results in a Texinfo
457 file (with extension @file{.texi}) containing @code{@@image} tags for
458 HTML, Info and printed output.  @command{lilypond-book} generates images
459 of the music in EPS and PDF formats for use in the printed output, and
460 in PNG format for use in HTML and Info output.
461
462 We show two simple examples here.  A @code{lilypond} environment
463
464 @example
465 @@lilypond[fragment]
466 c' d' e' f' g'2 g'
467 @@end lilypond
468 @end example
469
470 @noindent
471 produces
472
473 @lilypond[fragment]
474 c' d' e' f' g'2 g'
475 @end lilypond
476
477 The short version
478
479 @example
480 @@lilypond[fragment,staffsize=11]@{<c' e' g'>@}
481 @end example
482
483 @noindent
484 produces
485
486 @lilypond[fragment,staffsize=11]{<c' e' g'>}
487
488 Contrary to @LaTeX{}, @code{@@lilypond@{...@}} does not generate an
489 in-line image.  It always gets a paragraph of its own.
490
491
492 @node HTML
493 @subsection HTML
494
495 @code{lilypond-book} provides the following commands and environments to include
496 music in HTML files:
497
498 @itemize @bullet
499 @item the @code{<lilypond .... />} command, where you can directly enter short lilypond code
500 @item the @code{<lilyond>...</lilypond>} environment, where you can directly enter longer lilypond code
501 @item the @code{<lilypondfile>...</lilypondfile>} command to insert a lilypond file
502 @item the @code{<musicxmlfile>...</musicxmlfile>} command to insert a MusicXML file, which will be processed by @code{musicxml2ly} and @code{lilypond}.
503 @end itemize
504
505 Music is entered using
506
507 @example
508 <lilypond fragment relative=2>
509 \key c \minor c4 es g2
510 </lilypond>
511 @end example
512
513 @noindent
514 @command{lilypond-book} then produces an HTML file with appropriate image
515 tags for the music fragments:
516
517 @lilypond[fragment,relative=2]
518 \key c \minor c4 es g2
519 @end lilypond
520
521 For inline pictures, use @code{<lilypond ... />}, where the options
522 are separated by a colon from the music, for example
523
524 @example
525 Some music in <lilypond relative=2: a b c/> a line of text.
526 @end example
527
528 To include separate files, say
529
530 @example
531 <lilypondfile @var{option1} @var{option2} ...>@var{filename}</lilypondfile>
532 @end example
533
534 @code{<musicxmlfile>} uses the same syntax as @code{<lilypondfile>}, but simply
535 references a MusicXML file rather than a LilyPond file.
536
537 For a list of options to use with the @code{lilypond} or
538 @code{lilypondfile} tags, see @ref{Music fragment options}.
539
540 Additionally, @code{<lilypondversion/>} displays the current version
541 of lilypond.
542
543
544 @cindex titling in HTML
545 @cindex preview image
546 @cindex thumbnail
547
548 @node DocBook
549 @subsection DocBook
550
551 For inserting LilyPond snippets it is good to keep the conformity of our
552 DocBook document, thus allowing us to use DocBook editors, validation
553 etc.  So we don't use custom tags, only specify a convention based on the
554 standard DocBook elements.
555
556 @subheading Common conventions
557
558 For inserting all type of snippets we use the @code{mediaobject} and
559 @code{inlinemediaobject} element, so our snippets can be formatted
560 inline or not inline.  The snippet formatting options are always
561 provided in the @code{role} property of the innermost element (see in
562 next sections).  Tags are chosen to allow DocBook editors format the
563 content gracefully.  The DocBook files to be processed with
564 @command{lilypond-book} should have the extension @file{.lyxml}.
565
566 @subheading Including a LilyPond file
567
568 This is the most simple case.  We must use the @file{.ly} extension for
569 the included file, and insert it as a standard @code{imageobject}, with
570 the following structure:
571
572 @example
573 <mediaobject>
574   <imageobject>
575     <imagedata fileref="music1.ly" role="printfilename" />
576   </imageobject>
577 </mediaobject>
578 @end example
579
580 Note that you can use @code{mediaobject} or @code{inlinemediaobject}
581 as the outermost element as you wish.
582
583 @subheading Including LilyPond code
584
585 Including LilyPond code is possible by using a @code{programlisting},
586 where the language is set to @code{lilypond} with the following
587 structure:
588
589 @example
590 <inlinemediaobject>
591   <textobject>
592     <programlisting language="lilypond" role="fragment verbatim staffsize=16 ragged-right relative=2">
593 \context Staff \with @{
594   \remove Time_signature_engraver
595   \remove Clef_engraver@}
596   @{ c4( fis) @}
597     </programlisting>
598   </textobject>
599 </inlinemediaobject>
600 @end example
601
602 As you can see, the outermost element is a @code{mediaobject} or
603 @code{inlinemediaobject}, and there is a @code{textobject} containing
604 the @code{programlisting} inside.
605
606 @subheading Processing the DocBook document
607
608 Running @command{lilypond-book} on our @file{.lyxml} file will create a
609 valid DocBook document to be further processed with @file{.xml}
610 extension.  If you use
611 @uref{http://@/dblatex@/.sourceforge@/.net@/,dblatex}, it will create a
612 PDF file from this document automatically.  For HTML (HTML Help,
613 JavaHelp etc.) generation you can use the official DocBook XSL
614 stylesheets, however, it is possible that you have to make some
615 customization for it.
616
617
618 @node Music fragment options
619 @section Music fragment options
620
621 In the following, a @q{LilyPond command} refers to any command described
622 in the previous sections which is handled by @command{lilypond-book} to
623 produce a music snippet.  For simplicity, LilyPond commands are only
624 shown in @LaTeX{} syntax.
625
626 Note that the option string is parsed from left to right; if an option
627 occurs multiple times, the last one is taken.
628
629 The following options are available for LilyPond commands:
630
631 @table @code
632 @item staffsize=@var{ht}
633 Set staff size to @var{ht}, which is measured in points.
634
635 @item ragged-right
636 Produce ragged-right lines with natural spacing, i.e.,
637 @code{ragged-right = ##t} is added to the LilyPond snippet.  This is the
638 default for the @code{\lilypond@{@}} command if no @code{line-width}
639 option is present.  It is also the default for the @code{lilypond}
640 environment if the @code{fragment} option is set, and no line width is
641 explicitly specified.
642
643 @item noragged-right
644 For single-line snippets, allow the staff length to be stretched to
645 equal that of the line width, i.e., @code{ragged-right = ##f} is
646 added to the LilyPond snippet.
647
648 @item line-width
649 @itemx line-width=@var{size}\@var{unit}
650 Set line width to @var{size}, using @var{unit} as units.  @var{unit} is
651 one of the following strings: @code{cm}, @code{mm}, @code{in}, or
652 @code{pt}.  This option affects LilyPond output (this is, the staff
653 length of the music snippet), not the text layout.
654
655 If used without an argument, set line width to a default value (as
656 computed with a heuristic algorithm).
657
658 If no @code{line-width} option is given, @command{lilypond-book} tries to
659 guess a default for @code{lilypond} environments which don't use the
660 @code{ragged-right} option.
661
662 @item papersize=@var{string}
663 Where @var{string} is a paper size defined in @file{scm/paper.scm} i.e.
664 @code{a5}, @code{quarto}, @code{11x17} etc.
665
666 Values not defined in @file{scm/paper.scm} will be ignored, a warning
667 will be posted and the snippet will be printed using the default
668 @code{a4} size.
669
670 @item notime
671 Do not print the time signature, and turns off the timing (time signature,
672 bar lines) in the score.
673
674 @item fragment
675 Make @command{lilypond-book} add some boilerplate code so that you can
676 simply enter, say,
677
678 @example
679 c'4
680 @end example
681
682 @noindent
683 without @code{\layout}, @code{\score}, etc.
684
685 @item nofragment
686 Do not add additional code to complete LilyPond code in music snippets.
687 Since this is the default, @code{nofragment} is redundant normally.
688
689 @item indent=@var{size}\@var{unit}
690 Set indentation of the first music system to @var{size}, using
691 @var{unit} as units.  @var{unit} is one of the following strings:
692 @code{cm}, @code{mm}, @code{in}, or @code{pt}.  This option affects
693 LilyPond, not the text layout.
694
695 @item noindent
696 Set indentation of the first music system to zero.  This option affects
697 LilyPond, not the text layout.  Since no indentation is the default,
698 @code{noindent} is redundant normally.
699
700 @item quote
701 Reduce line length of a music snippet by @math{2*0.4}@dmn{in} and put
702 the output into a quotation block.  The value @q{0.4@dmn{in}} can be
703 controlled with the @code{exampleindent} option.
704
705 @item exampleindent
706 Set the amount by which the @code{quote} option indents a music snippet.
707
708 @item relative
709 @itemx relative=@var{n}
710 Use relative octave mode.  By default, notes are specified relative to
711 middle@tie{}C.  The optional integer argument specifies the octave of
712 the starting note, where the default @code{1} is middle C.
713 @code{relative} option only works when @code{fragment} option is set,
714 so @code{fragment} is automatically implied by @code{relative},
715 regardless of the presence of any @code{(no)fragment} option in the
716 source.
717 @end table
718
719 LilyPond also uses @command{lilypond-book} to produce its own
720 documentation.  To do that, some more obscure music fragment options are
721 available.
722
723 @table @code
724 @item verbatim
725 The argument of a LilyPond command is copied to the output file and
726 enclosed in a verbatim block, followed by any text given with the
727 @code{intertext} option (not implemented yet); then the actual music is
728 displayed.  This option does not work well with @code{\lilypond@{@}} if
729 it is part of a paragraph.
730
731 If @code{verbatim} is used in a @code{lilypondfile} command, it is
732 possible to enclose verbatim only a part of the source file.  If the
733 source file contain a comment containing @samp{begin verbatim} (without
734 quotes), quoting the source in the verbatim block will start after the
735 last occurrence of such a comment; similarly, quoting the source verbatim
736 will stop just before the first occurrence of a comment containing
737 @samp{end verbatim}, if there is any.  In the following source file
738 example, the music will be interpreted in relative mode, but the
739 verbatim quote will not show the @code{relative} block, i.e.
740
741 @example
742 \relative c' @{ % begin verbatim
743   c4 e2 g4
744   f2 e % end verbatim
745 @}
746 @end example
747
748 @noindent
749 will be printed with a verbatim block like
750
751 @example
752   c4 e2 g4
753   f2 e
754 @end example
755
756 @noindent
757 If you would like to translate comments and variable names in verbatim
758 output but not in the sources, you may set the environment variable
759 @code{LYDOC_LOCALEDIR} to a directory path; the directory should
760 contain a tree of @file{.mo} message catalogs with @code{lilypond-doc}
761 as a domain.
762
763 @item addversion
764 (Only for Texinfo output.)  Prepend line @code{\version
765 @@w@{"@@version@{@}"@}} to @code{verbatim} output.
766
767 @item texidoc
768 (Only for Texinfo output.)  If @command{lilypond} is called with the
769 @option{--header=@/texidoc} option, and the file to be processed is
770 called @file{foo.ly}, it creates a file @file{foo.texidoc} if there
771 is a @code{texidoc} field in the @code{\header}.  The @code{texidoc}
772 option makes @command{lilypond-book} include such files, adding its
773 contents as a documentation block right before the music snippet.
774
775 Assuming the file @file{foo.ly} contains
776
777 @example
778 \header @{
779   texidoc = "This file demonstrates a single note."
780 @}
781 @{ c'4 @}
782 @end example
783
784 @noindent
785 and we have this in our Texinfo document @file{test.texinfo}
786
787 @example
788 @@lilypondfile[texidoc]@{foo.ly@}
789 @end example
790
791 @noindent
792 the following command line gives the expected result
793
794 @example
795 lilypond-book --pdf --process="lilypond \
796   -dbackend=eps --header=texidoc" test.texinfo
797 @end example
798
799 Most LilyPond test documents (in the @file{input} directory of the
800 distribution) are small @file{.ly} files which look exactly like this.
801
802 For localization purpose, if the Texinfo document contains
803 @code{@@documentlanguage @var{LANG}} and @file{foo.ly} header
804 contains a @code{texidoc@var{LANG}} field, and if @command{lilypond}
805 is called with @option{--header=@/texidoc@var{LANG}}, then
806 @file{foo.texidoc@var{LANG}} will be included instead of
807 @file{foo.texidoc}.
808
809 @item lilyquote
810 (Only for Texinfo output.)  This option is similar to quote, but only
811 the music snippet (and the optional verbatim block implied by
812 @code{verbatim} option) is put into a quotation block.  This option is
813 useful if you want to @code{quote} the music snippet but not the
814 @code{texidoc} documentation block.
815
816 @item doctitle
817 (Only for Texinfo output.) This option works similarly to
818 @code{texidoc} option: if @command{lilypond} is called with the
819 @option{--header=@/doctitle} option, and the file to be processed is
820 called @file{foo.ly} and contains a @code{doctitle} field in the
821 @code{\header}, it creates a file @file{foo.doctitle}.  When
822 @code{doctitle} option is used, the contents of @file{foo.doctitle},
823 which should be a single line of @var{text}, is inserted in the
824 Texinfo document as @code{@@lydoctitle @var{text}}.
825 @code{@@lydoctitle} should be a macro defined in the Texinfo document.
826 The same remark about @code{texidoc} processing with localized
827 languages also applies to @code{doctitle}.
828
829 @item nogettext
830 (Only for Texinfo output.) Do not translate comments and variable
831 names in the snippet quoted verbatim.
832
833 @item printfilename
834 If a LilyPond input file is included with @code{\lilypondfile}, print
835 the file name right before the music snippet.  For HTML output, this
836 is a link.  Only the base name of the file is printed, i.e. the
837 directory part of the file path is stripped.
838
839 @end table
840
841
842 @node Invoking lilypond-book
843 @section Invoking @command{lilypond-book}
844
845 @command{lilypond-book} produces a file with one of the following
846 extensions: @file{.tex}, @file{.texi}, @file{.html} or @file{.xml},
847 depending on the output format.  All of @file{.tex}, @file{.texi} and
848 @file{.xml} files need further processing.
849
850 @subheading Format-specific instructions
851
852 @subsubheading @LaTeX{}
853
854 There are two ways of processing your @LaTeX{} document for printing or
855 publishing: getting a PDF file directly with PDF@LaTeX{}, or getting a
856 PostScript file with @LaTeX{} via a DVI to PostScript translator like
857 @command{dvips}.  The first way is simpler and recommended@footnote{Note
858 that PDF@LaTeX{} and @LaTeX{} may not be both usable to compile any
859 @LaTeX{} document, that is why we explain the two ways.}, and whichever
860 way you use, you can easily convert between PostScript and PDF with
861 tools, like @command{ps2pdf} and @command{pdf2ps} included in
862 Ghostscript package.
863
864 To produce a PDF file through PDF@LaTeX{}, use
865
866 @example
867 lilypond-book --pdf yourfile.lytex
868 pdflatex yourfile.tex
869 @end example
870
871 @cindex outline fonts
872 @cindex type1 fonts
873 @cindex dvips
874 @cindex invoking dvips
875 To produce PDF output via @LaTeX{}/@command{dvips}/@command{ps2pdf}, you
876 should do
877
878 @example
879 lilypond-book yourfile.lytex
880 latex yourfile.tex
881 dvips -Ppdf yourfile.dvi
882 ps2pdf yourfile.ps
883 @end example
884
885 @noindent
886 The @file{.dvi} file created by this process will not contain
887  note heads.  This is normal; if you follow the instructions, they
888 will be included in the @file{.ps} and @file{.pdf} files.
889
890 Running @command{dvips} may produce some warnings about fonts; these
891 are harmless and may be ignored.  If you are running @command{latex} in
892 twocolumn mode, remember to add @option{-t landscape} to the
893 @command{dvips} options.
894
895 @subsubheading Texinfo
896
897 To produce a Texinfo document (in any output format), follow the normal
898 procedures for Texinfo; this is, either call @command{texi2pdf} or
899 @command{texi2dvi} or @command{makeinfo}, depending on the output format
900 you want to create.
901 @ifinfo
902 @xref{Format with texi2dvi, , , texinfo, GNU Texinfo}, and @ref{Creating
903 an Info File, , , texinfo, GNU Texinfo}.
904 @end ifinfo
905 @ifnotinfo
906 See the documentation of Texinfo for further details.
907 @end ifnotinfo
908
909
910 @subheading Command line options
911
912 @command{lilypond-book} accepts the following command line options:
913
914 @table @code
915 @item -f @var{format}
916 @itemx --format=@var{format}
917 Specify the document type to process: @code{html}, @code{latex},
918 @code{texi} (the default) or @code{docbook}.  If this option is missing,
919 @command{lilypond-book} tries to detect the format automatically, see
920 @ref{Filename extensions}.  Currently, @code{texi} is the same as
921 @code{texi-html}.
922
923 @c This complicated detail is not implemented, comment it out -jm
924 @ignore
925 The @code{texi} document type produces a Texinfo file with music
926 fragments in the printed output only.  For getting images in the HTML
927 version, the format @code{texi-html} must be used instead.
928 @end ignore
929
930 @item -F @var{filter}
931 @itemx --filter=@var{filter}
932 Pipe snippets through @var{filter}.  @code{lilypond-book} will
933 not --filter and --process at the same time.  For example,
934
935 @example
936 lilypond-book --filter='convert-ly --from=2.0.0 -' my-book.tely
937 @end example
938
939 @item -h
940 @itemx --help
941 Print a short help message.
942
943 @item -I @var{dir}
944 @itemx --include=@var{dir}
945 Add @var{dir} to the include path.  @command{lilypond-book} also looks
946 for already compiled snippets in the include path, and does not write
947 them back to the output directory, so in some cases it is necessary to
948 invoke further processing commands such as @command{makeinfo} or
949 @command{latex} with the same @option{-I @var{dir}} options.
950
951 @item -o @var{dir}
952 @itemx --output=@var{dir}
953 Place generated files in directory @var{dir}.  Running
954 @command{lilypond-book} generates lots of small files that LilyPond will
955 process.  To avoid all that garbage in the source directory, use the
956 @option{--output} command line option, and change to that directory
957 before running @command{latex} or @command{makeinfo}.
958
959 @example
960 lilypond-book --output=out yourfile.lytex
961 cd out
962 ...
963 @end example
964
965 @itemx --skip-lily-check
966 Do not fail if no lilypond output is found.  It is used for LilyPond
967 Info documentation without images.
968
969 @itemx --skip-png-check
970 Do not fail if no PNG images are found for EPS files.  It is used for
971 LilyPond Info documentation without images.
972
973 @itemx --lily-output-dir=@var{dir}
974 Write lily-XXX files to directory @var{dir}, link into @option{--output}
975 directory.  Use this option to save building time for documents in
976 different directories which share a lot of identical snippets.
977
978 @itemx --info-images-dir=@var{dir}
979 Format Texinfo output so that Info will look for images of music in
980 @var{dir}.
981
982 @itemx --latex-program=@var{prog}
983 Run executable @command{prog} instead of @command{latex}.  This is
984 useful if your document is processed with @command{xelatex}, for
985 example.
986
987 @itemx --left-padding=@var{amount}
988 Pad EPS boxes by this much.  @var{amount} is measured in millimeters,
989 and is 3.0 by default.  This option should be used if the lines of
990 music stick out of the right margin.
991
992 The width of a tightly clipped system can vary, due to notation
993 elements that stick into the left margin, such as bar numbers and
994 instrument names.  This option will shorten each line and move each
995 line to the right by the same amount.
996
997 @item -P @var{command}
998 @itemx --process=@var{command}
999 Process LilyPond snippets using @var{command}.  The default command is
1000 @code{lilypond}.  @code{lilypond-book} will not @option{--filter} and
1001 @option{--process} at the same time.
1002
1003 @item --pdf
1004 Create PDF files for use with PDF@LaTeX{}.
1005
1006 @item --redirect-lilypond-output
1007 By default, output is displayed on the terminal.  This option redirects
1008 all output to log files in the same directory as the source files.
1009
1010 @itemx --use-source-file-names
1011 Write snippet output files with the same base name as their source file.
1012 This option works only for snippets included with @code{lilypondfile}
1013 and only if directories implied by @option{--output-dir} and
1014 @option{--lily-output-dir} options are different.
1015
1016 @item -V
1017 @itemx --verbose
1018 Be verbose.
1019
1020 @item -v
1021 @itemx --version
1022 Print version information.
1023 @end table
1024
1025 @knownissues
1026
1027 The Texinfo command @code{@@pagesizes} is not interpreted.  Similarly,
1028 @LaTeX{} commands that change margins and line widths after the preamble
1029 are ignored.
1030
1031 Only the first @code{\score} of a LilyPond block is processed.
1032
1033
1034 @node Filename extensions
1035 @section Filename extensions
1036
1037 You can use any filename extension for the input file, but if you do not
1038 use the recommended extension for a particular format you may need to
1039 manually specify the output format; for details, see @ref{Invoking
1040 lilypond-book}.  Otherwise, @command{lilypond-book} automatically
1041 selects the output format based on the input filename's extension.
1042
1043 @quotation
1044 @multitable @columnfractions .2 .5
1045 @item @strong{extension} @tab @strong{output format}
1046 @item
1047 @item @file{.html} @tab HTML
1048 @item @file{.htmly} @tab HTML
1049 @item @file{.itely} @tab Texinfo
1050 @item @file{.latex} @tab @LaTeX{}
1051 @item @file{.lytex} @tab @LaTeX{}
1052 @item @file{.lyxml} @tab DocBook
1053 @item @file{.tely} @tab Texinfo
1054 @item @file{.tex} @tab @LaTeX{}
1055 @item @file{.texi} @tab Texinfo
1056 @item @file{.texinfo} @tab Texinfo
1057 @item @file{.xml} @tab HTML
1058 @end multitable
1059 @end quotation
1060
1061 If you use the same filename extension for the input file than the
1062 extension @command{lilypond-book} uses for the output file, and if the
1063 input file is in the same directory as @command{lilypond-book} working
1064 directory, you must use @option{--output} option to make
1065 @command{lilypond-book} running, otherwise it will exit with an error
1066 message like @qq{Output would overwrite input file}.
1067
1068
1069 @node lilypond-book templates
1070 @section lilypond-book templates
1071
1072 These templates are for use with @code{lilypond-book}.  If you're not familiar
1073 with this program, please refer to
1074 @ref{lilypond-book}.
1075
1076 @subsection LaTeX
1077
1078 You can include LilyPond fragments in a LaTeX document.
1079
1080 @example
1081 \documentclass[]@{article@}
1082
1083 \begin@{document@}
1084
1085 Normal LaTeX text.
1086
1087 \begin@{lilypond@}
1088 \relative c'' @{
1089   a4 b c d
1090 @}
1091 \end@{lilypond@}
1092
1093 More LaTeX text, and options in square brackets.
1094
1095 \begin@{lilypond@}[fragment,relative=2,quote,staffsize=26,verbatim]
1096 d4 c b a
1097 \end@{lilypond@}
1098 \end@{document@}
1099 @end example
1100
1101 @subsection Texinfo
1102
1103 You can include LilyPond fragments in Texinfo; in fact, this entire manual
1104 is written in Texinfo.
1105
1106 @example
1107 \input texinfo @c -*-texinfo-*-
1108 @@node Top
1109 @@top
1110
1111 Texinfo text
1112
1113 @@lilypond
1114 \relative c' @{
1115   a4 b c d
1116 @}
1117 @@end lilypond
1118
1119 More Texinfo text, and options in brackets.
1120
1121 @@lilypond[verbatim,fragment,ragged-right]
1122 d4 c b a
1123 @@end lilypond
1124
1125 @@bye
1126 @end example
1127
1128
1129 @subsection html
1130
1131 @example
1132 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
1133 <!-- header_tag -->
1134 <HTML>
1135 <body>
1136
1137 <p>
1138 Documents for lilypond-book may freely mix music and text.  For
1139 example,
1140 <lilypond>
1141 \relative c'' @{
1142   a4 b c d
1143 @}
1144 </lilypond>
1145 </p>
1146
1147 <p>
1148 Another bit of lilypond, this time with options:
1149
1150 <lilypond fragment quote staffsize=26 verbatim>
1151 a4 b c d
1152 </lilypond>
1153 </p>
1154
1155 </body>
1156 </html>
1157
1158
1159 @end example
1160
1161 @subsection xelatex
1162
1163 @verbatim
1164 \documentclass{article}
1165 \usepackage{ifxetex}
1166 \ifxetex
1167 %xetex specific stuff
1168 \usepackage{xunicode,fontspec,xltxtra}
1169 \setmainfont[Numbers=OldStyle]{Times New Roman}
1170 \setsansfont{Arial}
1171 \else
1172 %This can be empty if you are not going to use pdftex
1173 \usepackage[T1]{fontenc}
1174 \usepackage[utf8]{inputenc}
1175 \usepackage{mathptmx}%Times
1176 \usepackage{helvet}%Helvetica
1177 \fi
1178 %Here you can insert all packages that pdftex also understands
1179 \usepackage[ngerman,finnish,english]{babel}
1180 \usepackage{graphicx}
1181
1182 \begin{document}
1183 \title{A short document with LilyPond and xelatex}
1184 \maketitle
1185
1186 Normal \textbf{font} commands inside the \emph{text} work,
1187 because they \textsf{are supported by \LaTeX{} and XeteX.}
1188 If you want to use specific commands like \verb+\XeTeX+, you
1189 should include them again in a \verb+\ifxetex+ environment.
1190 You can use this to print the \ifxetex \XeTeX{} command \else
1191 XeTeX command \fi which is not known to normal \LaTeX .
1192
1193 In normal text you can easily use LilyPond commands, like this:
1194
1195 \begin{lilypond}
1196 {a2 b c'8 c' c' c'}
1197 \end{lilypond}
1198
1199 \noindent
1200 and so on.
1201
1202 The fonts of snippets set with LilyPond will have to be set from
1203 inside
1204 of the snippet.  For this you should read the AU on how to use
1205 lilypond-book.
1206
1207 \selectlanguage{ngerman}
1208 Auch Umlaute funktionieren ohne die \LaTeX -Befehle, wie auch alle
1209 anderen
1210 seltsamen Zeichen: __ ______, wenn sie von der Schriftart
1211 unterst__tzt werden.
1212 \end{document}
1213 @end verbatim
1214
1215
1216 @node Sharing the table of contents
1217 @section Sharing the table of contents
1218
1219 These functions already exist in the OrchestralLily package:
1220
1221 @example
1222 @url{http://repo.or.cz/w/orchestrallily.git}
1223 @end example
1224
1225 For greater flexibility in text handling, some users prefer to
1226 export the table of contents from lilypond and read it into
1227 @LaTeX{}.
1228
1229 @subsubheading Exporting the ToC from LilyPond
1230
1231 This assumes that your score has multiple movements in the same lilypond
1232 output file.
1233
1234 @smallexample
1235 #(define (oly:create-toc-file layout pages)
1236   (let* ((label-table (ly:output-def-lookup layout 'label-page-table)))
1237     (if (not (null? label-table))
1238       (let* ((format-line (lambda (toc-item)
1239              (let* ((label (car toc-item))
1240                     (text  (caddr toc-item))
1241                     (label-page (and (list? label-table)
1242                                      (assoc label label-table)))
1243                     (page (and label-page (cdr label-page))))
1244                (format #f "~a, section, 1, @{~a@}, ~a" page text label))))
1245              (formatted-toc-items (map format-line (toc-items)))
1246              (whole-string (string-join formatted-toc-items ",\n"))
1247              (output-name (ly:parser-output-name parser))
1248              (outfilename (format "~a.toc" output-name))
1249              (outfile (open-output-file outfilename)))
1250         (if (output-port? outfile)
1251             (display whole-string outfile)
1252             (ly:warning (_ "Unable to open output file ~a for the TOC information") outfilename))
1253         (close-output-port outfile)))))
1254
1255 \paper @{
1256   #(define (page-post-process layout pages) (oly:create-toc-file layout pages))
1257 @}
1258 @end smallexample
1259
1260 @subsubheading Importing the ToC into LaTeX
1261
1262 In LaTeX, the header should include:
1263
1264 @c no, this doesn't require the smallexample, but since the other
1265 @c two blocks on this page use it, I figured I might as well
1266 @c user it here as well, for consistency. -gp
1267 @smallexample
1268 \usepackage@{pdfpages@}
1269 \includescore@{nameofthescore@}
1270 @end smallexample
1271
1272 @noindent
1273 where @code{\includescore} is defined as:
1274
1275 @smallexample
1276 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1277 % \includescore@{PossibleExtension@}
1278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279
1280 % Read in the TOC entries for a PDF file from the corresponding .toc file.
1281 % This requires some heave latex tweaking, since reading in things from a file
1282 % and inserting it into the arguments of a macro is not (easily) possible
1283
1284 % Solution by Patrick Fimml on #latex on April 18, 2009:
1285 % \readfile@{filename@}@{\variable@}
1286 % reads in the contents of the file into \variable (undefined if file
1287 % doesn't exist)
1288 \newread\readfile@@f
1289 \def\readfile@@line#1@{%
1290 @{\catcode`\^^M=10\global\read\readfile@@f to \readfile@@tmp@}%
1291 \edef\do@{\noexpand\g@@addto@@macro@{\noexpand#1@}@{\readfile@@tmp@}@}\do%
1292 \ifeof\readfile@@f\else%
1293 \readfile@@line@{#1@}%
1294 \fi%
1295 @}
1296 \def\readfile#1#2@{%
1297 \openin\readfile@@f=#1 %
1298 \ifeof\readfile@@f%
1299 \typeout@{No TOC file #1 available!@}%
1300 \else%
1301 \gdef#2@{@}%
1302 \readfile@@line@{#2@}%
1303 \fi
1304 \closein\readfile@@f%
1305 @}%
1306
1307
1308 \newcommand@{\includescore@}[1]@{
1309 \def\oly@@fname@{\oly@@basename\@@ifmtarg@{#1@}@{@}@{_#1@}@}
1310 \let\oly@@addtotoc\undefined
1311 \readfile@{\oly@@xxxxxxxxx@}@{\oly@@addtotoc@}
1312 \ifx\oly@@addtotoc\undefined
1313 \includepdf[pages=-]@{\oly@@fname@}
1314 \else
1315 \edef\includeit@{\noexpand\includepdf[pages=-,addtotoc=@{\oly@@addtotoc@}]
1316 @{\oly@@fname@}@}\includeit
1317 \fi
1318 @}
1319 @end smallexample
1320
1321
1322 @node Alternate methods of mixing text and music
1323 @section Alternative methods of mixing text and music
1324
1325 Other means of mixing text and music (without
1326 @command{lilypond-book}) are discussed in
1327 @ref{LilyPond output in other programs}.
1328
1329