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