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