]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
Minor clarifications and adding examples.
[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.e 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
17 @node Integrating text and music
18 @chapter Integrating text and music
19
20 If you want to add pictures of music to a document, you can simply do
21 it the way you would do with other types of pictures.  The pictures
22 are created separately, yielding PostScript output or PNG images,
23 and those 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
59 small example for use with La@TeX{}.  The example also contains
60 explanatory 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
108 commands
109
110 @example
111 dvips -Ppdf -u+lilypond -u+ec-mftrace 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 remedy
117 this, use the @code{--output=@var{dir}} option.  It will create the files
118 in a separate subdirectory @file{dir}.
119
120 Finally the result of the La@TeX{} example shown above.@footnote{This
121 tutorial is processed with Texinfo, so the example gives slightly
122 different results in layout.}  This finishes the tutorial section.
123
124 @page
125
126 Documents for @command{lilypond-book} may freely mix music and text.
127 For example,
128
129 @lilypond
130 \relative c' {
131   c2 g'2 \times 2/3 { f8 e d } c'2 g4
132 }
133 @end lilypond
134
135 Options are put in brackets.
136
137 @lilypond[fragment,quote,staffsize=26,verbatim]
138 c'4 f16
139 @end lilypond
140
141 Larger examples can be put into a separate file, and introduced with
142 @code{\lilypondfile}.
143
144 @lilypondfile[quote,noindent]{screech-boink.ly}
145
146 @page
147
148 @cindex texinfo
149 @cindex latex
150 @cindex texinfo
151 @cindex @code{texi}
152 @cindex html
153 @cindex documents, adding music to
154
155
156 @node Integrating LaTeX and music
157 @section Integrating La@TeX{} and music
158
159 La@TeX{} is the de-facto standard for publishing layouts in the exact
160 sciences.  It is built on top of the @TeX{} typesetting engine, providing
161 the best typography available anywhere.
162  
163 See @uref{http://@/www@/.ctan@/.org/@/tex@/-archive/@/info/@/lshort/@/english/,
164 The Not So Short Introduction to La@TeX{}} for an overview on how to use
165 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
190 Running @command{lilypond-book} yields a file that can be further processed
191 with La@TeX{}.
192
193 We show some examples here.  The lilypond environment
194
195 @example
196 \begin[quote,fragment,staffsize=26]@{lilypond@}
197   c' d' e' f' g'2 g'2
198 \end@{lilypond@}
199 @end example
200
201 @noindent
202 produces
203
204 @lilypond[quote,fragment,staffsize=26]
205   c' d' e' f' g'2 g'2
206 @end lilypond
207
208 The short version
209
210 @example
211 \lilypond[quote,fragment,staffsize=11]@{<c' e' g'>@}
212 @end example
213
214 @noindent
215 produces
216
217 @lilypond[quote,fragment,staffsize=11]{<c' e' g'>}
218
219 @noindent
220 You cannot include @{ or @} in the short version of @code{\lilypond@{@}},
221 so it is only useful with the @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
227 for the music fragments is then adjusted to the text width.  Note that
228 this heuristic algorithm can fail easily; in such cases it is necessary
229 to 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 translator
244 like @command{dvips}.  For producing PostScript with scalable fonts, add
245 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 text
259 markups; it uses the EC font family, so if you use characters in your
260 @command{lilypond-book} documents that are not included in the standard
261 US-ASCII character set,
262 include @code{\usepackage[latin1]@{inputenc@}} in the file 
263 header but do not include @code{\usepackage[T1]@{fontenc@}}.  Character
264 sets other than @code{latin1} are not supported directly but may be handled by
265 explicitly specifying the @code{font-name} property in LilyPond and
266 using the corresponding La@TeX{} packages.  Please consult the mailing list
267 for more details.
268
269
270 @node Integrating Texinfo and music
271 @section Integrating Texinfo and music
272
273 Texinfo is the standard format for documentation at the GNU
274 project.  An example of a Texinfo document is this manual.  The HTML,
275 PDF, and Info versions of the manual are made from the Texinfo document.
276
277 In the input file, music is specified like
278
279 @example
280 @@lilypond[options,go,here]
281   YOUR LILYPOND CODE
282 @@end lilypond
283 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
284 @@lilypondfile[options,go,here]@{@var{filename}@}
285 @end example
286
287 When @command{lilypond-book} is run on it, this results in a Texinfo file
288 (with extension @file{.texi}) containing @code{@@image} tags for HTML and
289 info.  For the printed edition, the raw @TeX{} output of LilyPond is
290 included into the main document.
291
292 We show two simple examples here.  A @code{lilypond} environment
293
294 @example
295 @@lilypond[fragment]
296   c' d' e' f' g'2 g'
297 @@end lilypond
298 @end example
299
300 @noindent
301 produces
302
303 @lilypond[fragment]
304   c' d' e' f' g'2 g'
305 @end lilypond
306
307 The short version
308
309 @example
310 @@lilypond[fragment,staffsize=11]@{<c' e' g'>@}
311 @end example
312
313 @noindent
314 produces
315
316 @lilypond[fragment,staffsize=11]{<c' e' g'>}
317
318 When producing Texinfo, @command{lilypond-book} also generates bitmaps of
319 the music (in PNG format), so you can make an HTML document with embedded
320 music.
321
322
323 @node Integrating HTML and music
324 @section Integrating HTML and music
325
326 Music is entered using
327
328 @example
329 <lilypond fragment relative=2>
330   \key c \minor c4 es g2
331 </lilypond>
332 @end example
333
334 @noindent
335 of which @command{lilypond-book} will produce a HTML with appropriate image
336 tags for the music fragments:
337
338 @lilypond[fragment,relative=2]
339   \key c \minor c4 es g2
340 @end lilypond
341
342 For inline pictures, use @code{<lilypond ... />} syntax, where the options
343 are separated by a colon from the music, for example
344
345 @example
346 Some music in <lilypond relative=2: a b c/> a line of text.
347 @end example
348
349 @c FIXME: check if this feature is coming soon; if not, @ignore this stuff.
350 A special feature not (yet) available in other output formats, is the
351 @code{<lilypondfile>} tag, for example,
352 @example
353   <lilypondfile>trip.ly</lilypondfile>
354 @end example
355 This runs @file{trip.ly} through @code{lilypond} (see also
356 @ref{Invoking lilypond}), and substitutes a preview image in the
357 output.  The image links to a separate HTML file, so clicking it will
358 take the viewer to a menu, with links to images, midi output, and printouts.
359
360 @cindex titling in THML
361 @cindex preview image
362 @cindex thumbnail
363
364
365 @node Music fragment options
366 @section Music fragment options
367
368 The commands for @command{lilypond-book} have room to specify one or more
369 of the following options:
370
371 @table @code
372 @item verbatim
373 @var{contents} is copied into the source, enclosed in a verbatim block;
374 followed by any text given with the @code{intertext} option; then
375 the actual music is displayed.  This option does not work with
376 the short version of the music blocks:
377
378 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
379
380 @item filename=@var{filename}
381 This names the file for the @code{printfilename} option. The argument
382 should be unquoted.
383
384 @item staffsize=@var{ht}
385 Sets the staff height to @var{ht}, which is measured in points.
386
387 @item raggedright
388 produces naturally spaced lines (i.e., @code{raggedright = ##t}); this
389 works well for small music fragments.
390
391 @item linewidth=@var{size}\@var{unit}
392 sets linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
393 This option affects LilyPond output, not the text layout.
394
395 @item notime
396 prevents printing the time signature.
397
398 @item fragment
399 adds some boilerplate code, so you can enter like
400
401 @example
402   c'4
403 @end example 
404
405 @noindent
406 without @code{\layout}, @code{\score} or other red tape.
407
408 @item indent=@var{size}\@var{unit}
409 sets indentation of the first music system to @var{size},
410 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
411 not the text layout.  The default is to use no indentation.
412
413 For example
414 @example
415   \begin[indent=5\cm,raggedright]@{lilypond@}
416   ...
417   \end@{lilypond@}
418 @end example
419
420 @item noindent
421 sets indentation of the first music system to zero.  This option
422 affects LilyPond, not the text layout.
423
424 @item quote
425 sets linewidth to the width of a quotation and puts the output
426 in a quotation block.
427
428 @item texidoc
429 Includes the @code{texidoc} field, if defined in the file. This is
430 only for Texinfo output.
431
432 In Texinfo, the music fragment is normally preceded by the
433 @code{texidoc} field from the @code{\header}. The LilyPond test
434 documents are composed from small @file{.ly} files in this way:
435
436 @example
437   \header @{
438     texidoc = "this file demonstrates a single note"
439   @}
440   @{ c'4 @}
441 @end example
442
443 @item relative, relative=@var{N}
444 uses relative octave mode.  By default, notes are specified relative
445 to middle C.  The optional integer argument specifies the octave of the
446 starting note, where the default @code{1} is middle C.
447 @end table
448
449
450 @node Invoking lilypond-book
451 @section Invoking @command{lilypond-book}
452
453 Running @command{lilypond-book} generates lots of small files that
454 LilyPond will process.  To avoid all that garbage in the source
455 directory use the @option{--output} command line option, and change to
456 that directory before running La@TeX{} or @file{makeinfo}:
457
458 @example
459 lilypond-book --output=out yourfile.lytex
460 cd out
461 @end example
462
463 This will produce a @file{.tex} or @file{.texi} file.  To produce pdf
464 output from the @file{.tex} file, you should do
465
466 @example
467 latex yourfile.tex
468 dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map yourfile.dvi
469 ps2pdf yourfile.ps
470 @end example
471
472 To produce a Texinfo document (in any output format), follow the normal
473 procedures for Texinfo.
474
475 @command{lilypond-book} accepts the following command line options:
476
477 @table @code
478 @item @option{-f @var{format}}, @option{--format=@var{format}}
479 Specify the document type to process: @code{html}, @code{latex}, or
480 @code{texi} (the default).  @command{lilypond-book} figures this
481 out automatically.
482
483 The @code{texi} document type produces a Texinfo file with music
484 fragments in the DVI output only. For getting images in the HTML
485 version, the format 
486 @code{texi-html} must be used.
487
488 @item @option{-F @var{filter}}, @option{--filter=@var{filter}}
489 Pipe snippets through @var{filter}.
490
491 For example:
492 @example
493   lilypond-book --filter='convert-ly --from=2.0.0' my-book.tely
494 @end example
495
496 @item @option{--help}
497 Print a short help message.
498
499 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
500 Add @var{DIR} to the include path.
501
502 @item @option{-o @var{dir}}, @option{--output=@var{dir}}
503 Place generated files in @var{dir}.
504
505 @item @option{-P @var{process}}, @option{--process=@var{COMMAND}}
506 Process LilyPond snippets using @var{command}.  The default command is
507 @code{lilypond}.
508
509 @item @option{--verbose}
510 Be verbose.
511
512 @item @option{--version}
513 Print version information.
514 @end table
515
516 For La@TeX{} input, the file to give to La@TeX{} has the extension
517 @file{.latex}.  Texinfo input will be written to a file with the extension
518 @file{.texi}.
519
520 @refbugs
521
522 The Texinfo command @code{pagesize} is not interpreted. Almost all
523 La@TeX{} commands that change margins and line widths are ignored.
524
525 Only the first @code{\score} of a LilyPond block is processed.
526
527 @c CHECKME--FIXME
528 The size of a music block is limited to 1.5 KB, due to technical
529 problems with the Python regular expression engine.  For longer files,
530 use @code{\lilypondfile}.
531
532
533 @node Filename extensions
534 @section Filename extensions
535
536 You can use any filename extension, but if you do not use the
537 recommended extension, you may need to manually specify what output
538 format you want.  See @ref{Invoking lilypond-book} for details.
539
540 @code{Lilypond-book} automatically selects the output format based
541 on the filename.
542
543 @table @code
544
545 @item @emph{.html} produces html output
546
547 @item @emph{.itely} produces texinfo output
548
549 @item @emph{.lytex} produces latex output
550
551 @end table