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