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