1 @c -*- coding: utf-8; 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}
68 Documents for @command{lilypond-book} may freely mix music and text.
73 c2 g'2 \times 2/3 { f8 e d } c'2 g4
77 Options are put in brackets.
79 \begin[fragment,quote,staffsize=26,verbatim]{lilypond}
83 Larger examples can be put into a separate file, and introduced with
86 \lilypondfile[quote,noindent]{screech-boink.ly}
92 Under Unix, you can view the results as follows
97 lilypond-book --output=out --psfonts lilybook.tex
98 @emph{lilypond-book (GNU LilyPond) 2.6.0}
99 @emph{Reading lilybook.tex...}
100 @emph{..lots of stuff deleted..}
101 @emph{Compiling out/lilybook.tex...}
104 @emph{lots of stuff deleted}
108 To convert the file into a PDF document, run the following commands
111 dvips -o -Ppdf -h lilybook.psfonts lilybook
115 Running @command{lilypond-book} and @command{latex} creates a lot of
116 temporary files, which would clutter up the working directory. To
117 remedy this, use the @code{--output=@var{dir}} option. It will create
118 the files in a separate subdirectory @file{dir}.
120 Running dvips will produce many warnings about fonts. They are not
121 harmful; please ignore them.
123 Finally the result of the La@TeX{} example shown above.@footnote{This
124 tutorial is processed with Texinfo, so the example gives slightly
125 different results in layout.} This finishes the tutorial section.
129 Documents for @command{lilypond-book} may freely mix music and text.
134 c2 g'2 \times 2/3 { f8 e d } c'2 g4
138 Options are put in brackets.
140 @lilypond[fragment,quote,staffsize=26,verbatim]
144 Larger examples can be put into a separate file, and introduced with
145 @code{\lilypondfile}.
147 @lilypondfile[quote,noindent]{screech-boink.ly}
156 @cindex documents, adding music to
159 @node Integrating LaTeX and music
160 @section Integrating La@TeX{} and music
162 La@TeX{} is the de-facto standard for publishing layouts in the exact
163 sciences. It is built on top of the @TeX{} typesetting engine,
164 providing the best typography available anywhere.
167 @uref{http://@/www@/.ctan@/.org/@/tex@/-archive/@/info/@/lshort/@/english/,
168 @emph{The Not So Short Introduction to La@TeX{}}} for an overview on how
171 Music is entered using
174 \begin[options,go,here]@{lilypond@}
183 \lilypondfile[options,go,here]@{@var{filename}@}
190 \lilypond@{ YOUR LILYPOND CODE @}
193 Running @command{lilypond-book} yields a file that can be further
194 processed with La@TeX{}.
196 We show some examples here. The lilypond environment
199 \begin[quote,fragment,staffsize=26]@{lilypond@}
207 @lilypond[quote,fragment,staffsize=26]
214 \lilypond[quote,fragment,staffsize=11]@{<c' e' g'>@}
220 @lilypond[quote,fragment,staffsize=11]{<c' e' g'>}
223 Currently, you cannot include @code{@{} or @code{@}} within
224 @code{\lilypond@{@}}, so this command is only useful with the
225 @code{fragment} option.
227 The default line-width of the music will be adjusted by examining the
228 commands in the document preamble, the part of the document before
229 @code{\begin@{document@}}. The @command{lilypond-book} command sends
230 these to La@TeX{} to find out how wide the text is. The line width for
231 the music fragments is then adjusted to the text width. Note that this
232 heuristic algorithm can fail easily; in such cases it is necessary to
233 use the @code{line-width} music fragment option.
235 @cindex titling and lilypond-book
236 @cindex @code{\header} in La@TeX{} documents
238 Each snippet will call the following macros if they have been defined by
241 @code{\preLilyPondExample} called before the music
243 @code{\postLilyPondExample} called after the music
245 @code{\betweenLilyPondSystem[1]} is called between systems if
246 @code{lilypond-book} has split the snippet into several postscript
247 files. It must be defined as taking one parameter and will be
248 passed the number of files already included in this snippet.
249 The default is to simply insert a @code{\linebreak}.
254 @cindex Latex, feta symbols
257 To include feta symbols (such as flat, segno, etc) in a LaTeX
258 document, use @code{\input@{titledefs@}}
261 \documentclass[a4paper]@{article@}
272 The font symbol names are defined in the file feta20.tex; to find
273 the location of this file, use the command
281 @cindex outline fonts
284 @cindex invoking dvips
286 For printing the La@TeX{} document you need a DVI to PostScript
287 translator like @command{dvips}. To use @command{dvips} to produce
288 a PostScript file, add the following options to the @command{dvips}
292 -o -Ppdf -h @var{file}.psfonts
296 where the @var{file}@command{psfonts} file is obtained from
297 @command{lilypond-book}, @xref{Invoking lilypond-book}, for details. PDF
298 can then be produced with a PostScript to PDF translator like
299 @code{ps2pdf} (which is part of GhostScript). Running @command{dvips}
300 will produce some warnings about fonts; these are harmless and may
303 @cindex international characters
307 @node Integrating Texinfo and music
308 @section Integrating Texinfo and music
310 Texinfo is the standard format for documentation of the GNU project. An
311 example of a Texinfo document is this manual. The HTML, PDF, and Info
312 versions of the manual are made from the Texinfo document.
314 In the input file, music is specified with
317 @@lilypond[options,go,here]
326 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
333 @@lilypondfile[options,go,here]@{@var{filename}@}
336 When @command{lilypond-book} is run on it, this results in a Texinfo
337 file (with extension @file{.texi}) containing @code{@@image} tags for
338 HTML and info output. For the printed edition, the raw @TeX{} output of
339 LilyPond is included in the main document.
341 We show two simple examples here. A @code{lilypond} environment
359 @@lilypond[fragment,staffsize=11]@{<c' e' g'>@}
365 @lilypond[fragment,staffsize=11]{<c' e' g'>}
367 Contrary to La@TeX{}, @code{@@lilypond@{...@}} does not generate an
368 in-line image. It always gets a paragraph of its own.
370 When using the Texinfo output format, @command{lilypond-book} also
371 generates bitmaps of the music (in PNG format), so you can make an HTML
372 document with embedded music.
375 @node Integrating HTML and music
376 @section Integrating HTML and music
378 Music is entered using
381 <lilypond fragment relative=2>
382 \key c \minor c4 es g2
387 @command{lilypond-book} then produces an HTML file with appropriate image
388 tags for the music fragments:
390 @lilypond[fragment,relative=2]
391 \key c \minor c4 es g2
394 For inline pictures, use @code{<lilypond ... />}, where the options
395 are separated by a colon from the music, for example
398 Some music in <lilypond relative=2: a b c/> a line of text.
401 To include separate files, say
404 <lilypondfile @var{option1} @var{option2} ...>@var{filename}</lilypondfile>
407 @cindex titling in HTML
408 @cindex preview image
412 @node Music fragment options
413 @section Music fragment options
415 In the following, a ``LilyPond command'' refers to any command described
416 in the previous sections which is handled by @command{lilypond-book} to
417 produce a music snippet. For simplicity, LilyPond commands are only
418 shown in La@TeX{} syntax.
420 Note that the option string is parsed from left to right; if an option
421 occurs multiple times, the last one is taken.
423 The following options are available for LilyPond commands:
426 @item staffsize=@var{ht}
427 Set staff size to @var{ht}, which is measured in points.
430 Produce ragged-right lines with natural spacing (i.e., @code{ragged-right
431 = ##t} is added to the LilyPond snippet). This is the default for the
432 @code{\lilypond@{@}} command if no @code{line-width} option is present.
433 It is also the default for the @code{lilypond} environment if the
434 @code{fragment} option is set, and no line width is explicitly
438 Produce lines with packed spacing (i.e., @code{packed = ##t} is added
439 to the LilyPond snippet).
442 @itemx line-width=@var{size}\@var{unit}
443 Set line width to @var{size}, using @var{unit} as units. @var{unit} is
444 one of the following strings: @code{cm}, @code{mm}, @code{in}, or
445 @code{pt}. This option affects LilyPond output (this is, the staff
446 length of the music snippet), not the text layout.
448 If used without an argument, set line width to a default value (as
449 computed with a heuristic algorithm).
451 If no @code{line-width} option is given, @command{lilypond-book} tries to
452 guess a default for @code{lilypond} environments which don't use the
453 @code{ragged-right} option.
456 Do not print the time signature, and turns off the timing (key signature,
457 bar lines) in the score.
460 Make @command{lilypond-book} add some boilerplate code so that you can
468 without @code{\layout}, @code{\score}, etc.
471 Don't add additional code to complete LilyPond code in music snippets.
472 Since this is the default, @code{nofragment} is redundant normally.
474 @item indent=@var{size}\@var{unit}
475 Set indentation of the first music system to @var{size}, using
476 @var{unit} as units. @var{unit} is one of the following strings:
477 @code{cm}, @code{mm}, @code{in}, or @code{pt}. This option affects
478 LilyPond, not the text layout.
481 Set indentation of the first music system to zero. This option affects
482 LilyPond, not the text layout. Since no indentation is the default,
483 @code{noindent} is redundant normally.
486 Reduce line length of a music snippet by @math{2*0.4}@dmn{in} and put
487 the output into a quotation block. The value `0.4@dmn{in}' can be
488 controlled with the @code{exampleindent} option.
491 Set the amount by which the @code{quote} option indents a music snippet.
494 @itemx relative=@var{n}
495 Use relative octave mode. By default, notes are specified relative to
496 middle@tie{}C. The optional integer argument specifies the octave of
497 the starting note, where the default @code{1} is middle C.
500 LilyPond also uses @command{lilypond-book} to produce its own
501 documentation. To do that, some more obscure music fragment options are
506 The argument of a LilyPond command is copied to the output file and
507 enclosed in a verbatim block, followed by any text given with the
508 @code{intertext} option (not implemented yet); then the actual music is
509 displayed. This option does not work well with @code{\lilypond@{@}} if
510 it is part of a paragraph.
513 (Only for Texinfo output.) If @command{lilypond} is called with the
514 @option{--header=@/texidoc} option, and the file to be processed is
515 called @file{foo@/.ly}, it creates a file @file{foo@/.texidoc} if there
516 is a @code{texidoc} field in the @code{\header}. The @code{texidoc}
517 option makes @command{lilypond-book} include such files, adding its
518 contents as a documentation block right before the music snippet.
520 Assuming the file @file{foo@/.ly} contains
524 texidoc = "This file demonstrates a single note."
530 and we have this in our Texinfo document @file{test.texinfo}
533 @@lilypondfile[texidoc]@{foo.ly@}
537 the following command line gives the expected result
540 lilypond-book --process="lilypond --format=tex --tex \
541 --header=texidoc test.texinfo
544 Most LilyPond test documents (in the @file{input} directory of the
545 distribution) are small @file{.ly} files which look exactly like this.
548 If a LilyPond input file is included with @code{\lilypondfile}, print
549 the file name right before the music snippet. For HTML output, this is
553 This option includes fonts in all of the generated EPS-files for this
554 snippet. This should be used if the snippet uses any font that LaTeX
555 cannot find on its own.
560 @node Invoking lilypond-book
561 @section Invoking @command{lilypond-book}
563 @command{lilypond-book} produces a file with one of the following
564 extensions: @file{.tex}, @file{.texi}, or @file{.html}, depending on the
565 output format. Both @file{.tex} and @file{.texi} files need further
568 @command{lilypond-book} can also create a PSFONTS file, which is required
569 by @command{dvips} to produce Postscript and PDF files. You can call
570 this file whatever you want as long as you refer to the same file when
571 you call @command{dvips}.
573 To produce PDF output from the lilypond-book file (here called
574 @code{yourfile.lytex}), you should do
577 lilypond-book --psfonts yourfile.lytex
579 dvips -o -h yourfile.psfonts -Ppdf yourfile.dvi
583 To produce a Texinfo document (in any output format), follow the normal
584 procedures for Texinfo (this is, either call @command{texi2dvi} or
585 @command{makeinfo}, depending on the output format you want to
588 @xref{Format with texi2dvi, , , texinfo, GNU Texinfo}, and @ref{Creating
589 an Info File, , , texinfo, GNU Texinfo}.
592 See the documentation of Texinfo for further details.
596 @command{lilypond-book} accepts the following command line options:
599 @item -f @var{format}
600 @itemx --format=@var{format}
601 Specify the document type to process: @code{html}, @code{latex}, or
602 @code{texi} (the default). If this option is missing,
603 @command{lilypond-book} tries to detect the format automatically.
605 The @code{texi} document type produces a Texinfo file with music
606 fragments in the DVI output only. For getting images in the HTML
607 version, the format @code{texi-html} must be used instead.
609 [Note: Currently, @code{texi} is the same as @code{texi-html}.]
611 @item -F @var{filter}
612 @itemx --filter=@var{filter}
613 Pipe snippets through @var{filter}. @code{lilypond-book} will
614 not --filter and --process at the same time.
618 lilypond-book --filter='convert-ly --from=2.0.0 -' my-book.tely
623 Print a short help message.
626 @itemx --include=@var{dir}
627 Add @var{dir} to the include path.
630 @itemx --output=@var{dir}
631 Place generated files in directory @var{dir}. Running
632 @command{lilypond-book} generates lots of small files that LilyPond will
633 process. To avoid all that garbage in the source directory use the
634 @option{--output} command line option, and change to that directory
635 before running @command{latex} or @command{makeinfo}:
638 lilypond-book --output=out yourfile.lytex
643 @item -P @var{process}
644 @itemx --process=@var{command}
645 Process LilyPond snippets using @var{command}. The default command is
646 @code{lilypond}. @code{lilypond-book} will not --filter and --process
650 extract all PostScript fonts into @file{@var{file}.psfonts} for dvips.
651 This is necessary for @command{dvips -h @var{file}.psfonts}.
659 Print version information.
664 The Texinfo command @code{@@pagesizes} is not interpreted. Similarly,
665 La@TeX{} commands that change margins and line widths after the preamble
668 Only the first @code{\score} of a LilyPond block is processed.
671 @node Filename extensions
672 @section Filename extensions
674 You can use any filename extension for the input file, but if you do not
675 use the recommended extension for a particular format you may need to
676 manually specify the output format. @xref{Invoking lilypond-book}, for
677 details. Otherwise, @command{lilypond-book} automatically selects the
678 output format based on the input filename's extension.
681 @multitable @columnfractions .2 .5
682 @item @strong{extension} @tab @strong{output format}
684 @item @file{.html} @tab HTML
685 @item @file{.itely} @tab Texinfo
686 @item @file{.latex} @tab La@TeX{}
687 @item @file{.lytex} @tab La@TeX{}
688 @item @file{.tely} @tab Texinfo
689 @item @file{.tex} @tab La@TeX{}
690 @item @file{.texi} @tab Texinfo
691 @item @file{.texinfo} @tab Texinfo
692 @item @file{.xml} @tab HTML