]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
Fix typo.
[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=2 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 @c  why the second example?  -gp
343 @example
344 <lilypond relative=2 verbatim>
345   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
346 </lilypond>
347 @end example
348
349 @lilypond[fragment,relative=2]
350   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
351 @end lilypond
352
353 For inline pictures, use @code{<lilypond ... />} syntax, e.g.
354 @example
355 Some music in <lilypond a b c/> a line of text.
356 @end example
357
358 @c  FIXME: check if this feature is coming soon; if not, @ignore this stuff.
359 A special feature not (yet) available in other output formats, is the
360 @code{<lilypondfile>} tag, for example,
361 @example
362   <lilypondfile>trip.ly</lilypondfile>
363 @end example
364 This runs @file{trip.ly} through @code{lilypond} (see also
365 @ref{Invoking lilypond}), and substitutes a preview image in the
366 output. The image links to a separate HTML file, so clicking it will
367 take the viewer to a menu, with links to images, midi and printouts.
368
369 @cindex titling in THML
370 @cindex preview image
371 @cindex thumbnail
372
373 @node Music fragment options
374 @section Music fragment options
375
376 The commands for lilypond-book have room to specify one or more of the
377 following options:
378
379 @table @code
380 @item verbatim
381 @var{contents} is copied into the source, enclosed in a verbatim block;
382 followed by any text given with the @code{intertext} option; then
383 the actual music is displayed.  This option does not work with
384 the short version of the music blocks:
385
386 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
387
388 @item filename=@var{filename}
389 This names the file for the @code{printfilename} option. The argument
390 should be unquoted.
391
392 @item staffsize=@var{ht}
393 Sets the staff height to @var{ht}, which is measured in points.
394
395 @item raggedright
396 produces naturally spaced lines (i.e., @code{raggedright = ##t}); this
397 works well for small music fragments.
398
399 @item linewidth=@var{size}\@var{unit}
400 sets linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
401 This option affects LilyPond output, not the text layout.
402
403 @item notime
404 prevents printing time signature.
405
406 @item fragment
407 adds some boilerplate code, so you can enter like
408
409 @example
410   c'4
411 @end example 
412
413 @noindent
414 without @code{\layout}, @code{\score} or other red tape.
415
416 @item indent=@var{size}\@var{unit}
417 sets indentation of the first music system to @var{size},
418 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
419 not the text layout.  For single-line fragments, the default is to
420 use no indentation.
421
422 For example
423 @example
424   \begin[indent=5\cm,raggedright]@{lilypond@}
425   ...
426   \end@{lilypond@}
427 @end example
428
429
430 @item noindent
431 sets indentation of the first music system to zero.  This option
432 affects LilyPond, not the text layout.
433
434 @item quote
435 sets linewidth to the width of a quotation and puts the output
436 in a quotation block.
437
438 @item texidoc
439 Includes the @code{texidoc} field, if defined in the file. This is
440 only for Texinfo output.
441
442 In Texinfo, the music fragment is normally preceded by the
443 @code{texidoc} field from the @code{\header}. The LilyPond test
444 documents are composed from small @file{.ly} files in this way:
445
446 @example
447   \header @{
448     texidoc = "this file demonstrates a single note"
449   @}
450   @{ c'4 @}
451 @end example
452
453 @item relative, relative=@var{N}
454 uses relative octave mode.  By default, notes are specified relative
455 to middle C.  The optional integer argument specifies the octave of the
456 starting note, where the default @code{1} is middle C.
457 @end table
458
459
460 @node Invoking lilypond-book
461 @section Invoking lilypond-book
462
463
464 Running @command{lilypond-book} generates lots of small files that
465 LilyPond will process.  To avoid all that garbage in the source
466 directory use the @option{--output} command line option, and change to
467 that directory before running La@TeX{} or @file{makeinfo}:
468
469 @example
470 lilypond-book --output=out yourfile.lytex
471 cd out
472 @end example
473
474 This will produce a .tex or .texi file.  To produce a pdf from the
475 .tex file, you should do
476
477 @example
478 latex yourfile.tex
479 dvips -Ppdf -u+ec-mftrace.map -u+lilypond.map yourfile.dvi
480 ps2pdf yourfile.ps
481 @end example
482
483 To produce a texinfo document (in any output format), follow the normal
484 procedures for texinfo.
485
486 @command{lilypond-book} accepts the following command line options:
487
488 @table @code
489 @item @option{-f @var{format}}, @option{--format=@var{format}}
490 Specify the document type to process: @code{html}, @code{latex} or
491 @code{texi} (the default).  @command{lilypond-book}  figures this
492 out automatically.
493
494 The @code{texi} document type produces a texinfo file with music
495 fragments in the DVI output only. For getting images in the HTML
496 version,  the format 
497 @code{texi-html} must be used.
498
499 @item @option{-F @var{filter}}, @option{--filter=@var{filter}}
500 Pipe snippets through @var{filter}.
501
502 For example:
503 @example
504   lilypond-book --filter='convert-ly --from=2.0.0' my-book.tely
505 @end example
506
507 @item @option{--help}
508 Print a short help message.
509
510 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
511 Add @var{DIR} to the include path.
512
513 @item @option{-o @var{dir}}, @option{--output=@var{dir}}
514 Place generated files in @var{dir}.
515
516 @item @option{-P @var{process}}, @option{--process=@var{COMMAND}}
517 Process lilypond snippets using @var{command}.  The default command is
518 @code{lilypond}.
519
520 @item @option{--verbose}
521 Be verbose.
522
523 @item @option{--version}
524 Print version information.
525 @end table
526
527 For La@TeX{} input, the file to give to La@TeX{} has extension
528 @file{.latex}.  Texinfo input will be written to a file with extension
529 @file{.texi}.
530
531
532
533 @refbugs
534
535 The Texinfo command @code{pagesize} is not interpreted. Almost all
536 La@TeX{} commands that change margins and line widths are ignored.
537
538 Only the first @code{\score} of a LilyPond block is processed.
539
540 @c CHECKME--FIXME
541 The size of a music block is limited to 1.5 KB, due to technical
542 problems with the Python regular expression engine.  For longer files,
543 use @code{\lilypondfile}.
544
545
546 @node Filename extensions
547 @section Filename extensions
548
549 You can use any filename extension, but if you do not use the
550 recommended extension, you may need to manually specify what output
551 format you want.  See @ref{Invoking lilypond-book} for details.
552
553 @code{Lilypond-book} automatically selects the output format based
554 on the filename.
555
556 @table @code
557
558 @item @emph{.html} produces html output
559
560 @item @emph{.itely} produces texinfo output
561
562 @item @emph{.lytex} produces latex output
563
564 @end table