]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
Add \RequirePackage{graphics} info.
[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 --psfonts lilybook.tex
97 @emph{lilypond-book (GNU LilyPond) 2.6.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 PDF document, run the following commands
108
109 @example
110 dvips -Ppdf -h lilybook.psfonts 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 Running dvips will produce many warnings about fonts.  They are not
120 harmful; please ignore them.
121
122 Finally the result of the La@TeX{} example shown above.@footnote{This
123 tutorial is processed with Texinfo, so the example gives slightly
124 different results in layout.}  This finishes the tutorial section.
125
126 @page
127
128 Documents for @command{lilypond-book} may freely mix music and text.
129 For example,
130
131 @lilypond
132 \relative c' {
133   c2 g'2 \times 2/3 { f8 e d } c'2 g4
134 }
135 @end lilypond
136
137 Options are put in brackets.
138
139 @lilypond[fragment,quote,staffsize=26,verbatim]
140 c'4 f16
141 @end lilypond
142
143 Larger examples can be put into a separate file, and introduced with
144 @code{\lilypondfile}.
145
146 @lilypondfile[quote,noindent]{screech-boink.ly}
147
148 @page
149
150 @cindex texinfo
151 @cindex latex
152 @cindex texinfo
153 @cindex @code{texi}
154 @cindex html
155 @cindex documents, adding music to
156
157
158 @node Integrating LaTeX and music
159 @section Integrating La@TeX{} and music
160
161 La@TeX{} is the de-facto standard for publishing layouts in the exact
162 sciences.  It is built on top of the @TeX{} typesetting engine,
163 providing the best typography available anywhere.
164
165 See
166 @uref{http://@/www@/.ctan@/.org/@/tex@/-archive/@/info/@/lshort/@/english/,
167 @emph{The Not So Short Introduction to La@TeX{}}} for an overview on how
168 to use La@TeX{}.
169
170 Music is entered using
171
172 @example
173 \begin[options,go,here]@{lilypond@}
174   YOUR LILYPOND CODE
175 \end@{lilypond@}
176 @end example
177
178 @noindent
179 or
180
181 @example
182 \lilypondfile[options,go,here]@{@var{filename}@}
183 @end example
184
185 @noindent
186 or
187
188 @example
189 \lilypond@{ YOUR LILYPOND CODE @}
190 @end example
191
192 Running @command{lilypond-book} yields a file that can be further
193 processed with La@TeX{}.  Since @command{lilypond-book} produces
194 lilypond snippets as @code{\includegraphics@{NAME.eps@}}, you must
195 add
196
197 @example
198 \RequirePackage@{graphics@}
199 @end example
200
201 @noindent
202 to the preamble of the LaTeX document.
203
204 We show some examples here.  The lilypond environment
205
206 @example
207 \begin[quote,fragment,staffsize=26]@{lilypond@}
208   c' d' e' f' g'2 g'2
209 \end@{lilypond@}
210 @end example
211
212 @noindent
213 produces
214
215 @lilypond[quote,fragment,staffsize=26]
216 c' d' e' f' g'2 g'2
217 @end lilypond
218
219 The short version
220
221 @example
222 \lilypond[quote,fragment,staffsize=11]@{<c' e' g'>@}
223 @end example
224
225 @noindent
226 produces
227
228 @lilypond[quote,fragment,staffsize=11]{<c' e' g'>}
229
230 @noindent
231 Currently, you cannot include @code{@{} or @code{@}} within
232 @code{\lilypond@{@}}, so this command is only useful with the
233 @code{fragment} option.
234
235 The default linewidth of the music will be adjusted by examining the
236 commands in the document preamble, the part of the document before
237 @code{\begin@{document@}}.  The @command{lilypond-book} command sends
238 these to La@TeX{} to find out how wide the text is.  The line width for
239 the music fragments is then adjusted to the text width.  Note that this
240 heuristic algorithm can fail easily; in such cases it is necessary to
241 use the @code{linewidth} music fragment option.
242
243 @cindex titling and lilypond-book
244 @cindex @code{\header} in La@TeX{} documents
245
246 Each snippet will call the following macros if they have been defined by
247 the user:
248
249 @code{\preLilyPondExample} called before the music
250
251 @code{\postLilyPondExample} called after the music
252
253 @code{\betweenLilyPondSystem[1]} is called between systems if
254 @code{lilypond-book} has split the snippet into several postscript
255 files.  It must be defined as taking one parameter and will be
256 passed the number of files already included in this snippet. 
257
258
259 @ignore
260 Broken stuff.  :(
261
262 @cindex Latex, feta symbols
263 @cindex fetachar
264
265 To include feta symbols (such as flat, segno, etc) in a LaTeX
266 document, use @code{\input@{titledefs@}}
267
268 @example
269 \documentclass[a4paper]@{article@}
270
271 \input@{titledefs@}
272
273 \begin@{document@}
274
275 \fetachar\fetasharp
276
277 \end@{document@}
278 @end example
279
280 The font symbol names are defined in the file feta20.tex; to find
281 the location of this file, use the command
282
283 @example
284 kpsewhich feta20.tex
285 @end example
286
287 @end ignore
288
289 @cindex outline fonts
290 @cindex type1 fonts
291 @cindex dvips
292 @cindex invoking dvips
293
294 For printing the La@TeX{} document you need a DVI to PostScript
295 translator like @command{dvips}.  To use @command{dvips} to produce
296 a PostScript file, add the following options to the @command{dvips}
297 command line:
298
299 @example
300 -Ppdf -h @var{file}.psfonts
301 @end example
302
303 @noindent
304 where the @var{file}@command{psfonts} file is obtained from
305 @command{lilypond-book}, @xref{Invoking lilypond-book} for details. PDF
306 can then be produced with a PostScript to PDF translator like
307 @code{ps2pdf} (which is part of GhostScript).  Running @command{dvips}
308 will produce some warnings about fonts; these are harmless and may
309 be ignored.
310
311 @cindex international characters
312 @cindex latin1
313
314
315 @node Integrating Texinfo and music
316 @section Integrating Texinfo and music
317
318 Texinfo is the standard format for documentation of the GNU project.  An
319 example of a Texinfo document is this manual.  The HTML, PDF, and Info
320 versions of the manual are made from the Texinfo document.
321
322 In the input file, music is specified with
323
324 @example
325 @@lilypond[options,go,here]
326   YOUR LILYPOND CODE
327 @@end lilypond
328 @end example
329
330 @noindent
331 or
332
333 @example
334 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
335 @end example
336
337 @noindent
338 or
339
340 @example
341 @@lilypondfile[options,go,here]@{@var{filename}@}
342 @end example
343
344 When @command{lilypond-book} is run on it, this results in a Texinfo
345 file (with extension @file{.texi}) containing @code{@@image} tags for
346 HTML and info output.  For the printed edition, the raw @TeX{} output of
347 LilyPond is included in the main document.
348
349 We show two simple examples here.  A @code{lilypond} environment
350
351 @example
352 @@lilypond[fragment]
353 c' d' e' f' g'2 g'
354 @@end lilypond
355 @end example
356
357 @noindent
358 produces
359
360 @lilypond[fragment]
361 c' d' e' f' g'2 g'
362 @end lilypond
363
364 The short version
365
366 @example
367 @@lilypond[fragment,staffsize=11]@{<c' e' g'>@}
368 @end example
369
370 @noindent
371 produces
372
373 @lilypond[fragment,staffsize=11]{<c' e' g'>}
374
375 Contrary to La@TeX{}, @code{@@lilypond@{...@}} does not generate an
376 in-line image.  It always gets a paragraph of its own.
377
378 When using the Texinfo output format, @command{lilypond-book} also
379 generates bitmaps of the music (in PNG format), so you can make an HTML
380 document with embedded music.
381
382
383 @node Integrating HTML and music
384 @section Integrating HTML and music
385
386 Music is entered using
387
388 @example
389 <lilypond fragment relative=2>
390 \key c \minor c4 es g2
391 </lilypond>
392 @end example
393
394 @noindent
395 @command{lilypond-book} then produces an HTML file with appropriate image
396 tags for the music fragments:
397
398 @lilypond[fragment,relative=2]
399 \key c \minor c4 es g2
400 @end lilypond
401
402 For inline pictures, use @code{<lilypond ... />}, where the options
403 are separated by a colon from the music, for example
404
405 @example
406 Some music in <lilypond relative=2: a b c/> a line of text.
407 @end example
408
409 To include separate files, say
410
411 @example
412 <lilypondfile @var{option1} @var{option2} ...>@var{filename}</lilypondfile>
413 @end example
414
415 @cindex titling in HTML
416 @cindex preview image
417 @cindex thumbnail
418
419
420 @node Music fragment options
421 @section Music fragment options
422
423 In the following, a ``LilyPond command'' refers to any command described
424 in the previous sections which is handled by @command{lilypond-book} to
425 produce a music snippet.  For simplicity, LilyPond commands are only
426 shown in La@TeX{} syntax.
427
428 Note that the option string is parsed from left to right; if an option
429 occurs multiple times, the last one is taken.
430
431 The following options are available for LilyPond commands:
432
433 @table @code
434 @item staffsize=@var{ht}
435 Set staff size to @var{ht}, which is measured in points.
436
437 @item raggedright
438 Produce ragged-right lines with natural spacing (i.e., @code{raggedright
439 = ##t} is added to the LilyPond snippet).  This is the default for the
440 @code{\lilypond@{@}} command if no @code{linewidth} option is present.
441 It is also the default for the @code{lilypond} environment if the
442 @code{fragment} option is set, and no line width is explicitly
443 specified.
444
445 @item packed
446 Produce lines with packed spacing (i.e., @code{packed = ##t} is added
447 to the LilyPond snippet).
448
449 @item linewidth
450 @itemx linewidth=@var{size}\@var{unit}
451 Set line width to @var{size}, using @var{unit} as units.  @var{unit} is
452 one of the following strings: @code{cm}, @code{mm}, @code{in}, or
453 @code{pt}.  This option affects LilyPond output (this is, the staff
454 length of the music snippet), not the text layout.
455
456 If used without an argument, set line width to a default value (as
457 computed with a heuristic algorithm).
458
459 If no @code{linewidth} option is given, @command{lilypond-book} tries to
460 guess a default for @code{lilypond} environments which don't use the
461 @code{raggedright} option.
462
463 @item notime
464 Do not print the time signature.
465
466 @item fragment
467 Make @command{lilypond-book} add some boilerplate code so that you can
468 simply enter, say,
469
470 @example
471 c'4
472 @end example
473
474 @noindent
475 without @code{\layout}, @code{\score}, etc.
476
477 @item nofragment
478 Don't add additional code to complete LilyPond code in music snippets.
479 Since this is the default, @code{nofragment} is redundant normally.
480
481 @item indent=@var{size}\@var{unit}
482 Set indentation of the first music system to @var{size}, using
483 @var{unit} as units. @var{unit} is one of the following strings:
484 @code{cm}, @code{mm}, @code{in}, or @code{pt}.  This option affects
485 LilyPond, not the text layout.
486
487 @item noindent
488 Set indentation of the first music system to zero.  This option affects
489 LilyPond, not the text layout.  Since no indentation is the default,
490 @code{noindent} is redundant normally.
491
492 @item quote
493 Reduce line length of a music snippet by @math{2*0.4}@dmn{in} and put
494 the output into a quotation block.  The value `0.4@dmn{in}' can be
495 controlled with the @code{exampleindent} option.
496
497 @item exampleindent
498 Set the amount by which the @code{quote} option indents a music snippet.
499
500 @item relative
501 @itemx relative=@var{n}
502 Use relative octave mode.  By default, notes are specified relative to
503 middle@tie{}C.  The optional integer argument specifies the octave of
504 the starting note, where the default @code{1} is middle C.
505 @end table
506
507 LilyPond also uses @command{lilypond-book} to produce its own
508 documentation.  To do that, some more obscure music fragment options are
509 available.
510
511 @table @code
512 @item verbatim
513 The argument of a LilyPond command is copied to the output file and
514 enclosed in a verbatim block, followed by any text given with the
515 @code{intertext} option (not implemented yet); then the actual music is
516 displayed.  This option does not work well with @code{\lilypond@{@}} if
517 it is part of a paragraph.
518
519 @item texidoc
520 (Only for Texinfo output.)  If @command{lilypond} is called with the
521 @option{--header=@/texidoc} option, and the file to be processed is
522 called @file{foo@/.ly}, it creates a file @file{foo@/.texidoc} if there
523 is a @code{texidoc} field in the @code{\header}.  The @code{texidoc}
524 option makes @command{lilypond-book} include such files, adding its
525 contents as a documentation block right before the music snippet.
526
527 Assuming the file @file{foo@/.ly} contains
528
529 @example
530 \header @{
531   texidoc = "This file demonstrates a single note."
532 @}
533 @{ c'4 @}
534 @end example
535
536 @noindent
537 and we have this in our Texinfo document @file{test.texinfo}
538
539 @example
540 @@lilypondfile[texidoc]@{foo.ly@}
541 @end example
542
543 @noindent
544 the following command line gives the expected result
545
546 @example
547 lilypond-book --process="lilypond --format=tex --tex \
548               --header=texidoc test.texinfo
549 @end example
550
551 Most LilyPond test documents (in the @file{input} directory of the
552 distribution) are small @file{.ly} files which look exactly like this.
553
554 @item printfilename
555 If a LilyPond input file is included with @code{\lilypondfile}, print
556 the file name right before the music snippet.  For HTML output, this is
557 a link.
558
559 @item fontload
560 This option includes fonts in all of the generated EPS-files for this
561 snippet. This should be used if the snippet uses any font that LaTeX
562 cannot find on its own.
563
564 @end table
565
566
567 @node Invoking lilypond-book
568 @section Invoking @command{lilypond-book}
569
570 @command{lilypond-book} produces a file with one of the following
571 extensions: @file{.tex}, @file{.texi}, or @file{.html}, depending on the
572 output format.  Both @file{.tex} and @file{.texi} files need further
573 processing.
574
575 @command{lilypond-book} can also create a PSFONTS file, which is required
576 by @command{dvips} to produce Postscript and PDF files.  You can call
577 this file whatever you want as long as you refer to the same file when
578 you call @command{dvips}.
579
580 To produce PDF output from the lilypond-book file (here called
581 @code{yourfile.lytex}), you should do
582
583 @example
584 lilypond-book --psfonts yourfile.lytex
585 latex yourfile.tex
586 dvips -h yourfile.psfonts -Ppdf yourfile.dvi
587 ps2pdf yourfile.ps
588 @end example
589
590 To produce a Texinfo document (in any output format), follow the normal
591 procedures for Texinfo (this is, either call @command{texi2dvi} or
592 @command{makeinfo}, depending on the output format you want to
593 create).
594 @ifinfo
595 @xref{Format with texi2dvi, , , texinfo, GNU Texinfo}, and @ref{Creating
596 an Info File, , , texinfo, GNU Texinfo}.
597 @end ifinfo
598 @ifnotinfo
599 See the documentation of Texinfo for further details.
600 @end ifnotinfo
601
602
603 @command{lilypond-book} accepts the following command line options:
604
605 @table @code
606 @item -f @var{format}
607 @itemx --format=@var{format}
608 Specify the document type to process: @code{html}, @code{latex}, or
609 @code{texi} (the default).  If this option is missing,
610 @command{lilypond-book} tries to detect the format automatically.
611
612 The @code{texi} document type produces a Texinfo file with music
613 fragments in the DVI output only.  For getting images in the HTML
614 version, the format @code{texi-html} must be used instead.
615
616 [Note: Currently, @code{texi} is the same as @code{texi-html}.]
617
618 @item -F @var{filter}
619 @itemx --filter=@var{filter}
620 Pipe snippets through @var{filter}.  @code{lilypond-book} will
621 not --filter and --process at the same time.
622
623 Example:
624 @example
625 lilypond-book --filter='convert-ly --from=2.0.0 -' my-book.tely
626 @end example
627
628 @item -h
629 @itemx --help
630 Print a short help message.
631
632 @item -I @var{dir}
633 @itemx --include=@var{dir}
634 Add @var{dir} to the include path.
635
636 @item -o @var{dir}
637 @itemx --output=@var{dir}
638 Place generated files in directory @var{dir}.  Running
639 @command{lilypond-book} generates lots of small files that LilyPond will
640 process.  To avoid all that garbage in the source directory use the
641 @option{--output} command line option, and change to that directory
642 before running @command{latex} or @command{makeinfo}:
643
644 @example
645 lilypond-book --output=out yourfile.lytex
646 cd out
647 ...
648 @end example
649
650 @item -P @var{process}
651 @itemx --process=@var{command}
652 Process LilyPond snippets using @var{command}.  The default command is
653 @code{lilypond}.  @code{lilypond-book} will not --filter and --process
654 at the same time.
655
656 @itemx --psfonts
657 extract all PostScript fonts into @file{@var{file}.psfonts} for dvips.
658 This is necessary for @command{dvips -h @var{file}.psfonts}.
659
660 @item -V
661 @itemx --verbose
662 Be verbose.
663
664 @item -v
665 @itemx --version
666 Print version information.
667 @end table
668
669 @refbugs
670
671 The Texinfo command @code{@@pagesizes} is not interpreted.  Similarly,
672 La@TeX{} commands that change margins and line widths after the preamble
673 are ignored.
674
675 Only the first @code{\score} of a LilyPond block is processed.
676
677
678 @node Filename extensions
679 @section Filename extensions
680
681 You can use any filename extension for the input file, but if you do not
682 use the recommended extension for a particular format you may need to
683 manually specify the output format.  @xref{Invoking lilypond-book}, for
684 details.  Otherwise, @command{lilypond-book} automatically selects the
685 output format based on the input filename's extension.
686
687 @quotation
688 @multitable @columnfractions .2 .5
689 @item @strong{extension} @tab @strong{output format}
690 @item
691 @item @file{.html} @tab HTML
692 @item @file{.itely} @tab Texinfo
693 @item @file{.latex} @tab La@TeX{}
694 @item @file{.lytex} @tab La@TeX{}
695 @item @file{.tely} @tab Texinfo
696 @item @file{.tex} @tab La@TeX{}
697 @item @file{.texi} @tab Texinfo
698 @item @file{.texinfo} @tab Texinfo
699 @item @file{.xml} @tab HTML
700 @end multitable
701 @end quotation