1 @c -*- coding: latin-1; mode: texinfo; -*-
8 ** AARGH. We also have tutorial.itely: Integrating text and music.
10 Could also do with a cleanup. Lost inspiration to fix this manual
11 where to describe what?
16 @c Note: keep this node named so that `info lilypond-book' brings you here.
18 @chapter @command{lilypond-book}: Integrating text and music
20 If you want to add pictures of music to a document, you can simply do it
21 the way you would do with other types of pictures. The pictures are
22 created separately, yielding PostScript output or PNG images, and those
23 are included into a La@TeX{} or HTML document.
25 @command{lilypond-book} provides a way to automate this process: This
26 program extracts snippets of music from your document, runs
27 @command{lilypond} on them, and outputs the document with pictures
28 substituted for the music. The line width and font size definitions for
29 the music are adjusted to match the layout of your document.
31 This procedure may be applied to La@TeX{}, HTML or Texinfo documents.
34 * An example of a musicological document::
35 * Integrating LaTeX and music::
36 * Integrating Texinfo and music::
37 * Integrating HTML and music::
38 * Music fragment options::
39 * Invoking lilypond-book::
40 * Filename extensions::
44 @node An example of a musicological document
45 @section An example of a musicological document
48 @cindex La@TeX{}, music in
49 @cindex HTML, music in
50 @cindex Texinfo, music in
51 Some texts contain music examples. These texts are musicological
52 treatises, songbooks, or manuals like this. Such texts can be made by
53 hand, simply by importing a PostScript figure into the word processor.
54 However, there is an automated procedure to reduce the amount of work
55 involved in HTML, La@TeX{}, and Texinfo documents.
57 A script called @code{lilypond-book} will extract the music fragments,
58 format them, and put back the resulting notation. Here we show a small
59 example for use with La@TeX{}. The example also contains explanatory
60 text, so we will not comment on it further.
64 \documentclass[a4paper]{article}
67 Documents for @command{lilypond-book} may freely mix music and text.
72 c2 g'2 \times 2/3 { f8 e d } c'2 g4
76 Options are put in brackets.
78 \begin[fragment,quote,staffsize=26,verbatim]{lilypond}
82 Larger examples can be put into a separate file, and introduced with
85 \lilypondfile[quote,noindent]{screech-boink.ly}
91 Under Unix, you can view the results as follows
96 lilypond-book --output=out lilybook.tex
97 @emph{lilypond-book (GNU LilyPond) 2.5.0}
98 @emph{Reading lilybook.tex...}
99 @emph{..lots of stuff deleted..}
100 @emph{Compiling out/lilybook.tex...}
103 @emph{lots of stuff deleted}
107 To convert the file into a PDF document, run the following commands
110 dvips -Ppdf -u+lilypond -u+ec-mftrace lilybook
114 Running @command{lilypond-book} and @command{latex} creates a lot of
115 temporary files, which would clutter up the working directory. To
116 remedy this, use the @code{--output=@var{dir}} option. It will create
117 the files in a separate subdirectory @file{dir}.
119 Finally the result of the La@TeX{} example shown above.@footnote{This
120 tutorial is processed with Texinfo, so the example gives slightly
121 different results in layout.} This finishes the tutorial section.
125 Documents for @command{lilypond-book} may freely mix music and text.
130 c2 g'2 \times 2/3 { f8 e d } c'2 g4
134 Options are put in brackets.
136 @lilypond[fragment,quote,staffsize=26,verbatim]
140 Larger examples can be put into a separate file, and introduced with
141 @code{\lilypondfile}.
143 @lilypondfile[quote,noindent]{screech-boink.ly}
152 @cindex documents, adding music to
155 @node Integrating LaTeX and music
156 @section Integrating La@TeX{} and music
158 La@TeX{} is the de-facto standard for publishing layouts in the exact
159 sciences. It is built on top of the @TeX{} typesetting engine,
160 providing the best typography available anywhere.
163 @uref{http://@/www@/.ctan@/.org/@/tex@/-archive/@/info/@/lshort/@/english/,
164 @emph{The Not So Short Introduction to La@TeX{}}} for an overview on how
167 Music is entered using
170 \begin[options,go,here]@{lilypond@}
179 \lilypondfile[options,go,here]@{@var{filename}@}
186 \lilypond@{ YOUR LILYPOND CODE @}
189 Running @command{lilypond-book} yields a file that can be further
190 processed with La@TeX{}.
192 We show some examples here. The lilypond environment
195 \begin[quote,fragment,staffsize=26]@{lilypond@}
203 @lilypond[quote,fragment,staffsize=26]
210 \lilypond[quote,fragment,staffsize=11]@{<c' e' g'>@}
216 @lilypond[quote,fragment,staffsize=11]{<c' e' g'>}
219 Currently, you cannot include @code{@{} or @code{@}} within
220 @code{\lilypond@{@}}, so this command is only useful with the
221 @code{fragment} option.
223 The default linewidth of the music will be adjusted by examining the
224 commands in the document preamble, the part of the document before
225 @code{\begin@{document@}}. The @command{lilypond-book} command sends
226 these to La@TeX{} to find out how wide the text is. The line width for
227 the music fragments is then adjusted to the text width. Note that this
228 heuristic algorithm can fail easily; in such cases it is necessary to
229 use the @code{linewidth} music fragment option.
231 @cindex titling and lilypond-book
232 @cindex @code{\header} in La@TeX{} documents
234 Each snippet calls @code{\preLilyPondExample} before and
235 @code{\postLilyPondExample} after the music if those macros have been
238 @cindex outline fonts
241 @cindex invoking dvips
243 For printing the La@TeX{} document you need a DVI to PostScript
244 translator like @command{dvips}. To use @command{dvips} to produce
245 a PostScript file, add the following options to the @command{dvips}
249 -Ppdf -u+lilypond.map -u+ec-mftrace.map
253 PDF can then be produced with a PostScript to PDF translator like
254 @code{ps2pdf} (which is part of GhostScript).
256 @cindex international characters
260 [THE FOLLOWING IS OUT OF DATE. ]
262 LilyPond does not use the La@TeX{} font handling scheme for lyrics and
263 text markups; it uses the EC font family and has limited support for
264 selecting an input encoding with the @code{\encoding} keyword if the
265 output is directly processed (these limitations primarily affect
266 LilyPond's native PostScript output). With @command{lilypond-book}, the
267 encoding issues are completely handled by the document which includes
268 LilyPond snippets; @command{lilypond} outputs all text strings without
269 modification. The drawback is that LilyPond always applies the EC font
270 metrics to those strings for computing the locations within the music
271 snippets; this often causes unpleasant horizontal (and vertical) shifts.
272 With other words, support for encodings other than @w{latin-1} is
273 possible but usually yields badly positioned text. Future versions of
274 LilyPond will fix this.
276 Since @w{latin-1} is the default encoding for LilyPond markup and lyrics
277 it is not necessary to explicitly add @code{\encoding "latin1"} to
278 LilyPond snippets. You might also consider the use of @code{\encoding
279 "TeX"} instead which basically makes LilyPond skip @TeX{} commands
280 (starting with a backslash) and braces in text strings -- it is not
281 recommended, though, since LilyPond gives only a rough approximation to
282 the real string length.
284 As a corrolary of the last paragraphs the following two lines should be
285 present in the La@TeX{} document preamble
290 \usepackage[latin1]@{inputenc@}
291 \usepackage[T1]@{fontenc@}
295 and real @w{latin-1} characters should be used in LilyPond snippets; for
296 example, use @code{ß}, not @code{\ss}.
299 @node Integrating Texinfo and music
300 @section Integrating Texinfo and music
302 Texinfo is the standard format for documentation of the GNU project. An
303 example of a Texinfo document is this manual. The HTML, PDF, and Info
304 versions of the manual are made from the Texinfo document.
306 In the input file, music is specified with
309 @@lilypond[options,go,here]
318 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
325 @@lilypondfile[options,go,here]@{@var{filename}@}
328 When @command{lilypond-book} is run on it, this results in a Texinfo
329 file (with extension @file{.texi}) containing @code{@@image} tags for
330 HTML and info output. For the printed edition, the raw @TeX{} output of
331 LilyPond is included in the main document.
333 We show two simple examples here. A @code{lilypond} environment
351 @@lilypond[fragment,staffsize=11]@{<c' e' g'>@}
357 @lilypond[fragment,staffsize=11]{<c' e' g'>}
359 Contrary to La@TeX{}, @code{@@lilypond@{...@}} does not generate an
360 in-line image. It always gets a paragraph of its own.
362 When using the Texinfo output format, @command{lilypond-book} also
363 generates bitmaps of the music (in PNG format), so you can make an HTML
364 document with embedded music.
367 @node Integrating HTML and music
368 @section Integrating HTML and music
370 Music is entered using
373 <lilypond fragment relative=2>
374 \key c \minor c4 es g2
379 @command{lilypond-book} then produces an HTML file with appropriate image
380 tags for the music fragments:
382 @lilypond[fragment,relative=2]
383 \key c \minor c4 es g2
386 For inline pictures, use @code{<lilypond ... />}, where the options
387 are separated by a colon from the music, for example
390 Some music in <lilypond relative=2: a b c/> a line of text.
393 To include separate files, say
396 <lilypondfile @var{option1} @var{option2} ...>@var{filename}</lilypondfile>
399 @cindex titling in HTML
400 @cindex preview image
404 @node Music fragment options
405 @section Music fragment options
407 In the following, a ``LilyPond command'' refers to any command described
408 in the previous sections which is handled by @command{lilypond-book} to
409 produce a music snippet. For simplicity, LilyPond commands are only
410 shown in La@TeX{} syntax.
412 Note that the option string is parsed from left to right; if an option
413 occurs multiple times, the last one is taken.
415 The following options are available for LilyPond commands:
418 @item staffsize=@var{ht}
419 Set staff size to @var{ht}, which is measured in points.
422 Produce ragged-right lines with natural spacing (i.e., @code{raggedright
423 = ##t} is added to the LilyPond snippet). This is the default for the
424 @code{\lilypond@{@}} command if no @code{linewidth} option is present.
425 It is also the default for the @code{lilypond} environment if the
426 @code{fragment} option is set, and no line width is explicitly
430 @itemx linewidth=@var{size}\@var{unit}
431 Set line width to @var{size}, using @var{unit} as units. @var{unit} is
432 one of the following strings: @code{cm}, @code{mm}, @code{in}, or
433 @code{pt}. This option affects LilyPond output (this is, the staff
434 length of the music snippet), not the text layout.
436 If used without an argument, set line width to a default value (as
437 computed with a heuristic algorithm).
439 If no @code{linewidth} option is given, @command{lilypond-book} tries to
440 guess a default for @code{lilypond} environments which don't use the
441 @code{raggedright} option.
444 Do not print the time signature.
447 Make @command{lilypond-book} add some boilerplate code so that you can
455 without @code{\layout}, @code{\score}, etc.
458 Don't add additional code to complete LilyPond code in music snippets.
459 Since this is the default, @code{nofragment} is redundant normally.
461 @item indent=@var{size}\@var{unit}
462 Set indentation of the first music system to @var{size}, using
463 @var{unit} as units. @var{unit} is one of the following strings:
464 @code{cm}, @code{mm}, @code{in}, or @code{pt}. This option affects
465 LilyPond, not the text layout.
468 Set indentation of the first music system to zero. This option affects
469 LilyPond, not the text layout. Since no indentation is the default,
470 @code{noindent} is redundant normally.
473 Reduce line length of a music snippet by @math{2*0.4}@dmn{in} and put
474 the output into a quotation block. The value `0.4@dmn{in}' can be
475 controlled with the @code{exampleindent} option.
478 Set the amount by which the @code{quote} option indents a music snippet.
481 @itemx relative=@var{n}
482 Use relative octave mode. By default, notes are specified relative to
483 middle@tie{}C. The optional integer argument specifies the octave of
484 the starting note, where the default @code{1} is middle C.
487 LilyPond also uses @command{lilypond-book} to produce its own
488 documentation. To do that, some more obscure music fragment options are
493 The argument of a LilyPond command is copied to the output file and
494 enclosed in a verbatim block, followed by any text given with the
495 @code{intertext} option (not implemented yet); then the actual music is
496 displayed. This option does not work well with @code{\lilypond@{@}} if
497 it is part of a paragraph.
500 (Only for Texinfo output.) If @command{lilypond} is called with the
501 @option{--header=@/texidoc} option, and the file to be processed is
502 called @file{foo@/.ly}, it creates a file @file{foo@/.texidoc} if there
503 is a @code{texidoc} field in the @code{\header}. The @code{texidoc}
504 option makes @command{lilypond-book} include such files, adding its
505 contents as a documentation block right before the music snippet.
507 Assuming the file @file{foo@/.ly} contains
511 texidoc = "This file demonstrates a single note."
517 and we have this in our Texinfo document @file{test.texinfo}
520 @@lilypondfile[texidoc]@{foo.ly@}
524 the following command line gives the expected result
527 lilypond-book --process="lilypond --format=tex --tex \
528 --header=texidoc test.texinfo
531 Most LilyPond test documents (in the @file{input} directory of the
532 distribution) are small @file{.ly} files which look exactly like this.
535 If a LilyPond input file is included with @code{\lilypondfile}, print
536 the file name right before the music snippet. For HTML output, this is
541 @node Invoking lilypond-book
542 @section Invoking @command{lilypond-book}
544 @command{lilypond-book} produces a file with one of the following
545 extensions: @file{.tex}, @file{.texi}, or @file{.html}, depending on the
546 output format. Both @file{.tex} and @file{.texi} files need further
549 To produce PDF output from the @file{.tex} file, you should do
553 dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map yourfile.dvi
557 To produce a Texinfo document (in any output format), follow the normal
558 procedures for Texinfo (this is, either call @command{texi2dvi} or
559 @command{makeinfo}, depending on the output format you want to create).
560 @xref{Format with texi2dvi, , , texinfo, GNU Texinfo}, and @ref{Creating
561 an Info File, , , texinfo, GNU Texinfo}.
563 @command{lilypond-book} accepts the following command line options:
566 @item -f @var{format}
567 @itemx --format=@var{format}
568 Specify the document type to process: @code{html}, @code{latex}, or
569 @code{texi} (the default). If this option is missing,
570 @command{lilypond-book} tries to detect the format automatically.
572 The @code{texi} document type produces a Texinfo file with music
573 fragments in the DVI output only. For getting images in the HTML
574 version, the format @code{texi-html} must be used instead.
576 [Note: Currently, @code{texi} is the same as @code{texi-html}.]
578 @item -F @var{filter}
579 @itemx --filter=@var{filter}
580 Pipe snippets through @var{filter}.
584 lilypond-book --filter='convert-ly --from=2.0.0' my-book.tely
589 Print a short help message.
592 @itemx --include=@var{dir}
593 Add @var{dir} to the include path.
596 @itemx --output=@var{dir}
597 Place generated files in directory @var{dir}. Running
598 @command{lilypond-book} generates lots of small files that LilyPond will
599 process. To avoid all that garbage in the source directory use the
600 @option{--output} command line option, and change to that directory
601 before running @command{latex} or @command{makeinfo}:
604 lilypond-book --output=out yourfile.lytex
609 @item -P @var{process}
610 @itemx --process=@var{command}
611 Process LilyPond snippets using @var{command}. The default command is
620 Print version information.
625 The Texinfo command @code{@@pagesizes} is not interpreted. Similarly,
626 La@TeX{} commands that change margins and line widths after the preamble
629 Only the first @code{\score} of a LilyPond block is processed.
632 The size of a music block is limited to 1.5 KB, due to technical
633 problems with the Python regular expression engine. For longer files,
634 use @code{\lilypondfile}.
637 @node Filename extensions
638 @section Filename extensions
640 You can use any filename extension for the input file, but if you do not
641 use the recommended extension for a particular format you may need to
642 manually specify the output format. @xref{Invoking lilypond-book}, for
643 details. Otherwise, @command{lilypond-book} automatically selects the
644 output format based on the input filename's extension.
647 @multitable @columnfractions .2 .5
648 @item @strong{extension} @tab @strong{output format}
650 @item @file{.html} @tab HTML
651 @item @file{.itely} @tab Texinfo
652 @item @file{.latex} @tab La@TeX{}
653 @item @file{.lytex} @tab La@TeX{}
654 @item @file{.tely} @tab Texinfo
655 @item @file{.tex} @tab La@TeX{}
656 @item @file{.texi} @tab Texinfo
657 @item @file{.texinfo} @tab Texinfo
658 @item @file{.xml} @tab HTML