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