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