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