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