]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
Added more docs for lilypond-book
[lilypond.git] / Documentation / user / lilypond-book.itely
1 @c -*-texinfo-*-
2
3 @ignore
4
5 TODO: cleanup
6
7 ** AARGH.e We also have tutorial.itely: Integrating text and music.
8
9    Could also do with a cleanup.  Lost inspiration to fix this manual
10    where to describe what?
11
12 @end ignore
13
14
15 @node  Integrating text and music
16 @chapter Integrating text and music
17
18 If you want to add pictures of music to a document, you can simply do
19 it the way you would do with other types of pictures.  The pictures
20 are created separately, yielding PostScript pictures or PNG images,
21 and those are included into a La@TeX{} or HTML document.
22
23 @command{lilypond-book} provides a way to automate this process: this
24 program extracts snippets of music from your document, runs LilyPond
25 on them, and outputs the document with pictures substituted for the
26 music.  The line width and font size definitions for the music are
27 adjusted to match the layout of your document.
28
29 This procedure may be applied to La@TeX{}, @code{html} or Texinfo
30 documents.
31
32
33
34
35 @menu
36 * An example of a musicological document::  
37 * Integrating Texinfo and music::  
38 * Integrating LaTeX and music::  
39 * Integrating HTML and music::  
40 * Music fragment options::      
41 * Invoking lilypond-book::
42 * Filename extensions::
43 @end menu
44
45
46
47
48 @node An example of a musicological document
49 @section  An example of a musicological document
50
51 @cindex musicology
52 @cindex La@TeX{}, music in
53 @cindex HTML, music in
54 @cindex Texinfo, music in
55 Some texts contain music examples.  These texts are musicological
56 treatises, songbooks or manuals like this.  Such texts can be made by
57 hand, simply by importing a PostScript figure into the word processor.
58 However, there is an automated procedure to reduce the amount of work
59 involved HTML, La@TeX{}, and Texinfo documents.
60
61 A script called @code{lilypond-book} will extract the music fragments,
62 format them, and put back the resulting notation.  Here we show a
63 small example for use with La@TeX{}.  The example also contains explanatory text, so we will
64 not comment on it further
65
66 @verbatim
67 \documentclass[a4paper]{article}
68 \begin{document}
69
70 Documents for lilypond-book may freely mix music and text.  For
71 example,
72
73 \begin{lilypond}
74 \relative {
75   c2 g'2 \times 2/3 { f8 e d } c'2 g4
76 }
77 \end{lilypond}
78
79 Options are put in brackets.
80
81 \begin[fragment,quote,staffsize=26,verbatim]{lilypond}
82   c'4 f16
83 \end{lilypond}
84
85 Larger examples can be put in a separate file, and introduced with
86 \verb+\lilypondfile+.
87
88 \lilypondfile[quote,noindent]{screech-boink.ly}
89
90 \end{document}
91 @end verbatim
92
93 Under Unix, you can view the results as follows
94
95 @example
96 cd input/tutorial
97 mkdir -p out/
98 lilypond-book --output=out/ lilybook.tex
99 @emph{lilypond-book (GNU LilyPond) 2.3.11}
100 @emph{Reading `input/tutorial/lilybook.tex'}
101 @emph{..lots of stuff deleted..}
102 @emph{Compiling `out//lilybook.tex'}
103 cd out
104 latex lilybook
105 @emph{lots of stuff deleted}
106 xdvi lilybook 
107 @end example
108
109 To convert the file into a nice PDF document, run the following
110 commands
111
112 @example
113 dvips -Ppdf -u+lilypond -u+ec-mftrace lilybook
114 ps2pdf lilybook.ps
115 @end example
116
117 Running lilypond-book and running latex creates a lot of temporary
118 files, which would clutter up the working directory.  To remedy this,
119 use the @code{--output=@var{dir}} option.  It will create the files in
120 a separate subdirectory @file{dir}.
121
122 Finally the result of the La@TeX{} example shown above.@footnote{ This
123 tutorial is processed with Texinfo, so the example is as well.  This
124 gives slightly different results in layout.}  This finishes the
125 tutorial section.
126
127 @page
128
129 Documents for lilypond-book may freely mix music and text.  For
130 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 in a separate file, and introduced with
145 @code{\lilypondfile}.
146
147 @lilypondfile[quote,noindent]{screech-boink.ly}
148
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 @c @TeX{} in node name seems to barf
159 @node Integrating LaTeX and music
160 @section Integrating LaTeX 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, so it
164 provides the best typography available anywhere.
165  
166 For more information about La@TeX{}
167 @uref{http://www.ctan.org/tex-archive/info/lshort/english/,The not so
168 Short Introduction to La@TeX{}} provides a introduction to using
169 La@TeX{}.
170
171 For La@TeX{}, 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 @example
180 \lilypondfile[options,go,here]@{@var{filename}@}
181 @end example
182
183 @noindent
184 or
185
186 @example
187 \lilypond@{ YOUR LILYPOND CODE @}
188 @end example
189
190 Running lilypond-book yields a file that can be processed with
191 La@TeX{}.
192
193
194 We show some examples here:
195
196 @example
197 \begin[staffsize=26]@{lilypond@}
198   c' d' e' f' g'2 g'2
199 \end@{lilypond@}
200 @end example
201
202 @noindent
203 produces
204
205 @lilypond[fragment,staffsize=26]
206   c' d' e' f' g'2 g'2
207 @end lilypond
208
209 Then the short version:
210
211 @example
212 \lilypond[staffsize=11]@{<c' e' g'>@}
213 @end example
214
215 @noindent
216 produces
217
218 @lilypond[fragment,staffsize=11]{<c' e' g'>}
219
220 The linewidth of the music will be adjust by examining the commands in
221 the document preamble, the part of the document before
222 @code{\begin@{document@}}. The @command{lilypond-book} command sends
223 these to La@TeX{} to find out how wide the text is. The line width
224 for the music fragments is then adjusted to the text width.
225
226 After @code{\begin@{document@}}, the column changing commands
227 @code{\onecolumn}, @code{\twocolumn} commands
228 @ignore 
229 and the
230 @code{multicols} environment from the multicol package
231 @end ignore
232 are also interpreted.
233
234 @cindex titling and lilypond-book
235 @cindex @code{\header} in La@TeX{} documents
236
237
238 The music will be surrounded by @code{\preLilyPondExample} and
239 @code{\postLilyPondExample}, which are defined to be empty by default.
240
241 @cindex outline fonts
242 @cindex type1 fonts
243 @cindex dvips
244 @cindex invoking dvips
245
246 For printing the La@TeX{} document, you will need to use dvips. For
247 producing PostScript with scalable fonts, add the following options to
248 the dvips command line:
249 @example
250  -Ppdf -u+lilypond.map -u+ec-mftrace.map
251 @end example 
252
253 @noindent
254 PDF can then be produced with @code{ps2pdf}.
255
256 @cindex international characters
257 @cindex latin1
258
259 LilyPond does not use the La@TeX{} font handling scheme for lyrics and text
260 markups, so if you use characters in your lilypond-book
261 documents that are not included in the standard 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 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
271
272 @node Integrating Texinfo and music
273 @section Integrating Texinfo and music
274
275 Texinfo is the standard format for documentation at the GNU
276 project. An example of a texinfo document is this manual. The HTML,
277 PDF and Info versions of the manual are made from the document.
278
279 When run on a lilypond-book, produces a @file{.texi} file containing
280 @code{@@image} tags for HTML and info. For the printed edition, the
281 raw @TeX{} output of LilyPond is included into the main document.
282
283 In the input file, music is specified like
284
285 @example
286 @@lilypond[options,go,here]
287   YOUR LILYPOND CODE
288 @@end lilypond
289 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
290 @@lilypondfile[options,go,here]@{@var{filename}@}
291 @end example
292
293 When lilypond-book is run on it, this results in a texinfo file. We
294 show two simple examples here.  First a complete block:
295
296 @example
297 @@lilypond[staffsize=26]
298   c' d' e' f' g'2 g'
299 @@end lilypond
300 @end example
301
302 @noindent
303 produces
304
305 @lilypond[fragment]
306   c' d' e' f' g'2 g'
307 @end lilypond
308
309 Then the short version:
310
311 @example
312 @@lilypond[staffsize=11]@{<c' e' g'>@}
313 @end example
314
315 @noindent
316 produces
317
318 @lilypond[fragment,staffsize=11]{ <c' e' g'> }
319
320 When producing texinfo, lilypond-book also generates bitmaps of the
321 music, so you can make a HTML document with embedded music.
322
323
324
325
326
327 @node Integrating HTML and music
328 @section Integrating HTML and music
329
330 Music is entered using
331
332 @example
333 <lilypond relative=1 verbatim>
334   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
335 </lilypond>
336 @end example
337
338 @noindent
339 of which lilypond-book will produce a HTML with appropriate image tags for the
340 music fragments:
341  
342 @example
343 <lilypond relative=2 verbatim>
344   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
345 </lilypond>
346 @end example
347
348 @lilypond[fragment,relative=2]
349   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
350 @end lilypond
351
352 For inline pictures, use @code{<lilypond ... />} syntax, e.g.
353 @example
354 Some music in <lilypond a b c/> a line of text.
355 @end example
356
357 A special feature not (yet) available in other output formats, is the
358 @code{<lilypondfile>} tag, for example,
359 @example
360   <lilypondfile>trip.ly</lilypondfile>
361 @end example
362 This runs @file{trip.ly} through @code{lilypond} (see also
363 @ref{Invoking lilypond}), and substitutes a preview image in the
364 output. The image links to a separate HTML file, so clicking it will
365 take the viewer to a menu, with links to images, midi and printouts.
366
367 @cindex titling in THML
368 @cindex preview image
369 @cindex thumbnail
370
371 @node Music fragment options
372 @section Music fragment options
373
374 The commands for lilypond-book have room to specify one or more of the
375 following options:
376
377 @table @code
378 @item verbatim
379 @var{contents} is copied into the source, enclosed in a verbatim block;
380 followed by any text given with the @code{intertext} option; then
381 the actual music is displayed.  This option does not work with
382 the short version of the music blocks:
383
384 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
385
386 @item filename=@var{filename}
387 This names the file for the @code{printfilename} option. The argument
388 should be unquoted.
389
390 @item staffsize=@var{ht}
391 Sets the staff height to @var{ht}, which is measured in points.
392
393 @item raggedright
394 produces naturally spaced lines (i.e., @code{raggedright = ##t}); this
395 works well for small music fragments.
396
397 @item linewidth=@var{size}\@var{unit}
398 sets linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
399 This option affects LilyPond output, not the text layout.
400
401 @item notime
402 prevents printing time signature.
403
404 @item fragment
405 adds some boilerplate code, so you can enter like
406
407 @example
408   c'4
409 @end example 
410
411 @noindent
412 without @code{\layout}, @code{\score} or other red tape.
413
414 @item indent=@var{size}\@var{unit}
415 sets indentation of the first music system to @var{size},
416 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
417 not the text layout.  For single-line fragments, the default is to
418 use no indentation.
419
420 For example
421 @example
422   \begin[indent=5\cm,raggedright]@{lilypond@}
423   ...
424   \end@{lilypond@}
425 @end example
426
427
428 @item noindent
429 sets indentation of the first music system to zero.  This option
430 affects LilyPond, not the text layout.
431
432 @item quote
433 sets linewidth to the width of a quotation and puts the output
434 in a quotation block.
435
436 @item texidoc
437 Includes the @code{texidoc} field, if defined in the file. This is
438 only for Texinfo output.
439
440 In Texinfo, the music fragment is normally preceded by the
441 @code{texidoc} field from the @code{\header}. The LilyPond test
442 documents are composed from small @file{.ly} files in this way:
443
444 @example
445   \header @{
446     texidoc = "this file demonstrates a single note"
447   @}
448   @{ c'4 @}
449 @end example
450
451 @item relative, relative=@var{N}
452 uses relative octave mode.  By default, notes are specified relative
453 to middle C.  The optional integer argument specifies the octave of the
454 starting note, where the default @code{1} is middle C.
455 @end table
456
457
458 @node Invoking lilypond-book
459 @section Invoking lilypond-book
460
461
462 Running @command{lilypond-book} generates lots of small files that
463 LilyPond will process.  To avoid all that garbage in the source
464 directory use the @option{--output} command line option, and change to
465 that directory before running La@TeX{} or @file{makeinfo}:
466
467 @example
468 lilypond-book --output=out yourfile.lytex
469 cd out && latex yourfile.tex
470 @end example
471
472
473 @command{lilypond-book} accepts the following command line options:
474
475 @table @code
476 @item @option{-f @var{format}}, @option{--format=@var{format}}
477 Specify the document type to process: @code{html}, @code{latex} or
478 @code{texi} (the default).  @command{lilypond-book}  figures this
479 out automatically.
480
481 The @code{texi} document type produces a texinfo file with music
482 fragments in the DVI output only. For getting images in the HTML
483 version,  the format 
484 @code{texi-html} must be used.
485
486 @item @option{-F @var{filter}}, @option{--filter=@var{filter}}
487 Pipe snippets through @var{filter}.
488
489 For example:
490 @example
491   lilypond-book --filter='convert-ly --from=2.0.0' my-book.tely
492 @end example
493
494 @item @option{--help}
495 Print a short help message.
496
497 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
498 Add @var{DIR} to the include path.
499
500 @item @option{-o @var{dir}}, @option{--output=@var{dir}}
501 Place generated files in @var{dir}.
502
503 @item @option{-P @var{process}}, @option{--process=@var{COMMAND}}
504 Process lilypond snippets using @var{command}.  The default command is
505 @code{lilypond}.
506
507 @item @option{--verbose}
508 Be verbose.
509
510 @item @option{--version}
511 Print version information.
512 @end table
513
514 For La@TeX{} input, the file to give to La@TeX{} has extension
515 @file{.latex}.  Texinfo input will be written to a file with extension
516 @file{.texi}.
517
518
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