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