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