]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
* Documentation/user/lilypond-book.itely: Finish update.
[lilypond.git] / Documentation / user / lilypond-book.itely
1 @c -*- coding: latin-1; mode: texinfo; -*-
2
3
4 @ignore
5
6 TODO: cleanup
7
8 ** AARGH.  We also have tutorial.itely: Integrating text and music.
9
10    Could also do with a cleanup.  Lost inspiration to fix this manual
11    where to describe what?
12
13 @end ignore
14
15
16 @c Note: keep this node named so that `info lilypond-book' brings you here.
17 @node LilyPond-book
18 @chapter @command{lilypond-book}: Integrating text and music
19
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.
24
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.
30
31 This procedure may be applied to La@TeX{}, HTML or Texinfo documents.
32
33 @menu
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::
41 @end menu
42
43
44 @node An example of a musicological document
45 @section An example of a musicological document
46
47 @cindex musicology
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.
56
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.
61
62 @quotation
63 @verbatim
64 \documentclass[a4paper]{article}
65 \begin{document}
66
67 Documents for @command{lilypond-book} may freely mix music and text.
68 For example,
69
70 \begin{lilypond}
71 \relative c' {
72   c2 g'2 \times 2/3 { f8 e d } c'2 g4
73 }
74 \end{lilypond}
75
76 Options are put in brackets.
77
78 \begin[fragment,quote,staffsize=26,verbatim]{lilypond}
79   c'4 f16
80 \end{lilypond}
81
82 Larger examples can be put into a separate file, and introduced with
83 \verb+\lilypondfile+.
84
85 \lilypondfile[quote,noindent]{screech-boink.ly}
86
87 \end{document}
88 @end verbatim
89 @end quotation
90
91 Under Unix, you can view the results as follows
92
93 @example
94 cd input/tutorial
95 mkdir -p out/
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...}
101 cd out
102 latex lilybook
103 @emph{lots of stuff deleted}
104 xdvi lilybook
105 @end example
106
107 To convert the file into a nice PDF document, run the following commands
108
109 @example
110 dvips -Ppdf -u+lilypond -u+ec-mftrace lilybook
111 ps2pdf lilybook.ps
112 @end example
113
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}.
118
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.
122
123 @page
124
125 Documents for @command{lilypond-book} may freely mix music and text.
126 For example,
127
128 @lilypond
129 \relative c' {
130   c2 g'2 \times 2/3 { f8 e d } c'2 g4
131 }
132 @end lilypond
133
134 Options are put in brackets.
135
136 @lilypond[fragment,quote,staffsize=26,verbatim]
137 c'4 f16
138 @end lilypond
139
140 Larger examples can be put into a separate file, and introduced with
141 @code{\lilypondfile}.
142
143 @lilypondfile[quote,noindent]{screech-boink.ly}
144
145 @page
146
147 @cindex texinfo
148 @cindex latex
149 @cindex texinfo
150 @cindex @code{texi}
151 @cindex html
152 @cindex documents, adding music to
153
154
155 @node Integrating LaTeX and music
156 @section Integrating La@TeX{} and music
157
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.
161
162 See
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
165 to use La@TeX{}.
166
167 Music is entered using
168
169 @example
170 \begin[options,go,here]@{lilypond@}
171   YOUR LILYPOND CODE
172 \end@{lilypond@}
173 @end example
174
175 @noindent
176 or
177
178 @example
179 \lilypondfile[options,go,here]@{@var{filename}@}
180 @end example
181
182 @noindent
183 or
184
185 @example
186 \lilypond@{ YOUR LILYPOND CODE @}
187 @end example
188
189 Running @command{lilypond-book} yields a file that can be further
190 processed with La@TeX{}.
191
192 We show some examples here.  The lilypond environment
193
194 @example
195 \begin[quote,fragment,staffsize=26]@{lilypond@}
196   c' d' e' f' g'2 g'2
197 \end@{lilypond@}
198 @end example
199
200 @noindent
201 produces
202
203 @lilypond[quote,fragment,staffsize=26]
204 c' d' e' f' g'2 g'2
205 @end lilypond
206
207 The short version
208
209 @example
210 \lilypond[quote,fragment,staffsize=11]@{<c' e' g'>@}
211 @end example
212
213 @noindent
214 produces
215
216 @lilypond[quote,fragment,staffsize=11]{<c' e' g'>}
217
218 @noindent
219 Currently, you cannot include @code{@{} or @code{@}} within
220 @code{\lilypond@{@}}, so this command is only useful with the
221 @code{fragment} option.
222
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.
230
231 @cindex titling and lilypond-book
232 @cindex @code{\header} in La@TeX{} documents
233
234 Each snippet calls @code{\preLilyPondExample} before and
235 @code{\postLilyPondExample} after the music if those macros have been
236 defined by the user.
237
238 @cindex outline fonts
239 @cindex type1 fonts
240 @cindex dvips
241 @cindex invoking dvips
242
243 For printing the La@TeX{} document you need a DVI to PostScript
244 translator like @command{dvips}.  For producing PostScript with scalable
245 fonts, add the following options to the @command{dvips} command line:
246
247 @example
248 -Ppdf -u+lilypond.map -u+ec-mftrace.map
249 @end example
250
251 @noindent
252 PDF can then be produced with a PostScript to PDF translator like
253 @code{ps2pdf} (which is part of GhostScript).
254
255 @cindex international characters
256 @cindex latin1
257
258 LilyPond does not use the La@TeX{} font handling scheme for lyrics and
259 text markups; it uses the EC font family and has limited support for
260 selecting an input encoding with the @code{\encoding} keyword if the
261 output is directly processed (these limitations primarily affect
262 LilyPond's native PostScript output).  With @command{lilypond-book}, the
263 encoding issues are completely handled by the document which includes
264 LilyPond snippets; @command{lilypond} outputs all text strings without
265 modification.  The drawback is that LilyPond always applies the EC font
266 metrics to those strings for computing the locations within the music
267 snippets; this often causes unpleasant horizontal (and vertical) shifts.
268 With other words, support for encodings other than @w{latin-1} is
269 possible but usually yields badly positioned text.  Future versions of
270 LilyPond will fix this.
271
272 Since @w{latin-1} is the default encoding for LilyPond markup and lyrics
273 it is not necessary to explicitly add @code{\encoding "latin1"} to
274 LilyPond snippets.  You might also consider the use of @code{\encoding
275 "TeX"} instead which basically makes LilyPond skip @TeX{} commands
276 (starting with a backslash) and braces in text strings -- it is not
277 recommended, though, since LilyPond gives only a rough approximation to
278 the real string length.
279
280 As a corrolary of the last paragraphs the following two lines should be
281 present in the La@TeX{} document preamble
282
283 @example
284 \usepackage[latin1]@{inputenc@}
285 \usepackage[T1]@{fontenc@}
286 @end example
287
288 @noindent
289 and real @w{latin-1} characters should be used in LilyPond snippets; for
290 example, use @code{ß}, not @code{\ss}.
291
292
293 @node Integrating Texinfo and music
294 @section Integrating Texinfo and music
295
296 Texinfo is the standard format for documentation of the GNU project.  An
297 example of a Texinfo document is this manual.  The HTML, PDF, and Info
298 versions of the manual are made from the Texinfo document.
299
300 In the input file, music is specified with
301
302 @example
303 @@lilypond[options,go,here]
304   YOUR LILYPOND CODE
305 @@end lilypond
306 @end example
307
308 @noindent
309 or
310
311 @example
312 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
313 @end example
314
315 @noindent
316 or
317
318 @example
319 @@lilypondfile[options,go,here]@{@var{filename}@}
320 @end example
321
322 When @command{lilypond-book} is run on it, this results in a Texinfo
323 file (with extension @file{.texi}) containing @code{@@image} tags for
324 HTML and info output.  For the printed edition, the raw @TeX{} output of
325 LilyPond is included in the main document.
326
327 We show two simple examples here.  A @code{lilypond} environment
328
329 @example
330 @@lilypond[fragment]
331 c' d' e' f' g'2 g'
332 @@end lilypond
333 @end example
334
335 @noindent
336 produces
337
338 @lilypond[fragment]
339 c' d' e' f' g'2 g'
340 @end lilypond
341
342 The short version
343
344 @example
345 @@lilypond[fragment,staffsize=11]@{<c' e' g'>@}
346 @end example
347
348 @noindent
349 produces
350
351 @lilypond[fragment,staffsize=11]{<c' e' g'>}
352
353 Contrary to La@TeX{}, @code{@@lilypond@{...@}} does not generate an
354 in-line image.  It always gets a paragraph of its own.
355
356 When using the Texinfo output format, @command{lilypond-book} also
357 generates bitmaps of the music (in PNG format), so you can make an HTML
358 document with embedded music.
359
360
361 @node Integrating HTML and music
362 @section Integrating HTML and music
363
364 Music is entered using
365
366 @example
367 <lilypond fragment relative=2>
368 \key c \minor c4 es g2
369 </lilypond>
370 @end example
371
372 @noindent
373 @command{lilypond-book} then produces an HTML file with appropriate image
374 tags for the music fragments:
375
376 @lilypond[fragment,relative=2]
377 \key c \minor c4 es g2
378 @end lilypond
379
380 For inline pictures, use @code{<lilypond ... />}, where the options
381 are separated by a colon from the music, for example
382
383 @example
384 Some music in <lilypond relative=2: a b c/> a line of text.
385 @end example
386
387 To include separate files, say
388
389 @example
390 <lilypondfile @var{option1} @var{option2} ...>@var{filename}</lilypondfile>
391 @end example
392
393 @cindex titling in HTML
394 @cindex preview image
395 @cindex thumbnail
396
397
398 @node Music fragment options
399 @section Music fragment options
400
401 In the following, a ``LilyPond command'' refers to any command described
402 in the previous sections which is handled by @command{lilypond-book} to
403 produce a music snippet.  For simplicity, LilyPond commands are only
404 shown in La@TeX{} syntax.
405
406 Note that the option string is parsed from left to right; if an option
407 occurs multiple times, the last one is taken.
408
409 The following options are available for LilyPond commands:
410
411 @table @code
412 @item staffsize=@var{ht}
413 Set staff size to @var{ht}, which is measured in points.
414
415 @item raggedright
416 Produce ragged-right lines with natural spacing (i.e., @code{raggedright
417 = ##t} is added to the LilyPond snippet).  This is the default for the
418 @code{\lilypond@{@}} command if no @code{linewidth} option is present.
419 It is also the default for the @code{lilypond} environment if the
420 @code{fragment} option is set, and no line width is explicitly
421 specified.
422
423 @item linewidth
424 @itemx linewidth=@var{size}\@var{unit}
425 Set line width to @var{size}, using @var{unit} as units.  @var{unit} is
426 one of the following strings: @code{cm}, @code{mm}, @code{in}, or
427 @code{pt}.  This option affects LilyPond output (this is, the staff
428 length of the music snippet), not the text layout.
429
430 If used without an argument, set line width to a default value (as
431 computed with a heuristic algorithm).
432
433 If no @code{linewidth} option is given, @command{lilypond-book} tries to
434 guess a default for @code{lilypond} environments which don't use the
435 @code{raggedright} option.
436
437 @item notime
438 Do not print the time signature.
439
440 @item fragment
441 Make @command{lilypond-book} add some boilerplate code so that you can
442 simply enter, say,
443
444 @example
445 c'4
446 @end example
447
448 @noindent
449 without @code{\layout}, @code{\score}, etc.
450
451 @item nofragment
452 Don't add additional code to complete LilyPond code in music snippets.
453 Since this is the default, @code{nofragment} is redundant normally.
454
455 @item indent=@var{size}\@var{unit}
456 Set indentation of the first music system to @var{size}, using
457 @var{unit} as units. @var{unit} is one of the following strings:
458 @code{cm}, @code{mm}, @code{in}, or @code{pt}.  This option affects
459 LilyPond, not the text layout.
460
461 @item noindent
462 Set indentation of the first music system to zero.  This option affects
463 LilyPond, not the text layout.  Since no indentation is the default,
464 @code{noindent} is redundant normally.
465
466 @item quote
467 Reduce line length of a music snippet by @math{2*0.4}@dmn{in} and put
468 the output into a quotation block.  The value `0.4@dmn{in}' can be
469 controlled with the @code{exampleindent} option.
470
471 @item exampleindent
472 Set the amount by which the @code{quote} option indents a music snippet.
473
474 @item relative
475 @itemx relative=@var{n}
476 Use relative octave mode.  By default, notes are specified relative to
477 middle@tie{}C.  The optional integer argument specifies the octave of
478 the starting note, where the default @code{1} is middle C.
479 @end table
480
481 LilyPond also uses @command{lilypond-book} to produce its own
482 documentation.  To do that, some more obscure music fragment options are
483 available.
484
485 @table @code
486 @item verbatim
487 The argument of a LilyPond command is copied to the output file and
488 enclosed in a verbatim block, followed by any text given with the
489 @code{intertext} option (not implemented yet); then the actual music is
490 displayed.  This option does not work well with @code{\lilypond@{@}} if
491 it is part of a paragraph.
492
493 @item texidoc
494 (Only for Texinfo output.)  If @command{lilypond} is called with the
495 @option{--header=@/texidoc} option, and the file to be processed is
496 called @file{foo@/.ly}, it creates a file @file{foo@/.texidoc} if there
497 is a @code{texidoc} field in the @code{\header}.  The @code{texidoc}
498 option makes @command{lilypond-book} include such files, adding its
499 contents as a documentation block right before the music snippet.
500
501 Assuming the file @file{foo@/.ly} contains
502
503 @example
504 \header @{
505   texidoc = "This file demonstrates a single note."
506 @}
507 @{ c'4 @}
508 @end example
509
510 @noindent
511 and we have this in our Texinfo document @file{test.texinfo}
512
513 @example
514 @@lilypondfile[texidoc]@{foo.ly@}
515 @end example
516
517 @noindent
518 the following command line gives the expected result
519
520 @example
521 lilypond-book --process="lilypond --format=tex --tex \
522               --header=texidoc test.texinfo
523 @end example
524
525 Most LilyPond test documents (in the @file{input} directory of the
526 distribution) are small @file{.ly} files which look exactly like this.
527
528 @item printfilename
529 If a LilyPond input file is included with @code{\lilypondfile}, print
530 the file name right before the music snippet.  For HTML output, this is
531 a link.
532 @end table
533
534
535 @node Invoking lilypond-book
536 @section Invoking @command{lilypond-book}
537
538 @command{lilypond-book} produces a file with one of the following
539 extensions: @file{.tex}, @file{.texi}, or @file{.html}, depending on the
540 output format.  Both @file{.tex} and @file{.texi} files need further
541 processing.
542
543 To produce PDF output from the @file{.tex} file, you should do
544
545 @example
546 latex yourfile.tex
547 dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map yourfile.dvi
548 ps2pdf yourfile.ps
549 @end example
550
551 To produce a Texinfo document (in any output format), follow the normal
552 procedures for Texinfo (this is, either call @command{texi2dvi} or
553 @command{makeinfo}, depending on the output format you want to create).
554 @xref{Format with texi2dvi, , , texinfo, GNU Texinfo}, and @ref{Creating
555 an Info File, , , texinfo, GNU Texinfo}.
556
557 @command{lilypond-book} accepts the following command line options:
558
559 @table @code
560 @item -f @var{format}
561 @itemx --format=@var{format}
562 Specify the document type to process: @code{html}, @code{latex}, or
563 @code{texi} (the default).  If this option is missing,
564 @command{lilypond-book} tries to detect the format automatically.
565
566 The @code{texi} document type produces a Texinfo file with music
567 fragments in the DVI output only.  For getting images in the HTML
568 version, the format @code{texi-html} must be used instead.
569
570 [Note: Currently, @code{texi} is the same as @code{texi-html}.]
571
572 @item -F @var{filter}
573 @itemx --filter=@var{filter}
574 Pipe snippets through @var{filter}.
575
576 Example:
577 @example
578 lilypond-book --filter='convert-ly --from=2.0.0' my-book.tely
579 @end example
580
581 @item -h
582 @itemx --help
583 Print a short help message.
584
585 @item -I @var{dir}
586 @itemx --include=@var{dir}
587 Add @var{dir} to the include path.
588
589 @item -o @var{dir}
590 @itemx --output=@var{dir}
591 Place generated files in directory @var{dir}.  Running
592 @command{lilypond-book} generates lots of small files that LilyPond will
593 process.  To avoid all that garbage in the source directory use the
594 @option{--output} command line option, and change to that directory
595 before running @command{latex} or @command{makeinfo}:
596
597 @example
598 lilypond-book --output=out yourfile.lytex
599 cd out
600 ...
601 @end example
602
603 @item -P @var{process}
604 @itemx --process=@var{command}
605 Process LilyPond snippets using @var{command}.  The default command is
606 @code{lilypond}.
607
608 @item -V
609 @itemx --verbose
610 Be verbose.
611
612 @item -v
613 @itemx --version
614 Print version information.
615 @end table
616
617 @refbugs
618
619 The Texinfo command @code{@@pagesizes} is not interpreted.  Similarly,
620 La@TeX{} commands that change margins and line widths after the preamble
621 are ignored.
622
623 Only the first @code{\score} of a LilyPond block is processed.
624
625 @c CHECKME--FIXME
626 The size of a music block is limited to 1.5 KB, due to technical
627 problems with the Python regular expression engine.  For longer files,
628 use @code{\lilypondfile}.
629
630
631 @node Filename extensions
632 @section Filename extensions
633
634 You can use any filename extension for the input file, but if you do not
635 use the recommended extension for a particular format you may need to
636 manually specify the output format.  @xref{Invoking lilypond-book}, for
637 details.  Otherwise, @command{lilypond-book} automatically selects the
638 output format based on the input filename's extension.
639
640 @quotation
641 @multitable @columnfractions .2 .5
642 @item @strong{extension} @tab @strong{output format}
643 @item
644 @item @file{.html} @tab HTML
645 @item @file{.itely} @tab Texinfo
646 @item @file{.latex} @tab La@TeX{}
647 @item @file{.lytex} @tab La@TeX{}
648 @item @file{.tely} @tab Texinfo
649 @item @file{.tex} @tab La@TeX{}
650 @item @file{.texi} @tab Texinfo
651 @item @file{.texinfo} @tab Texinfo
652 @item @file{.xml} @tab HTML
653 @end multitable
654 @end quotation