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