]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
Proofreaded (HJJ).
[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 lilypond-book manual
16 @chapter lilypond-book manual
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 introction to using La@TeX{}.
34
35
36 @menu
37 * Integrating Texinfo and music::  
38 * Integrating LaTeX and music::  
39 * Integrating HTML and music::  
40 * Music fragment options::      
41 * Invoking lilypond-book::      
42 @end menu
43
44
45
46 @cindex texinfo
47 @cindex latex
48 @cindex texinfo
49 @cindex @code{texi}
50 @cindex html
51 @cindex documents, adding music to
52
53
54 @node Integrating Texinfo and music
55 @section Integrating Texinfo and music
56
57 Music is specified like this:
58
59 @example
60 @@lilypond[options, go, here]
61   YOUR LILYPOND CODE
62 @@end lilypond
63 @@lilypond[options, go, here]@{ YOUR LILYPOND CODE @}
64 @@lilypondfile[options, go, here]@{@var{filename}@}
65 @end example
66
67 When lilypond-book is run on it, this results in a texinfo file. We
68 show two simple examples here.  First a complete block:
69
70 @example
71 @@lilypond[26pt]
72   c' d' e' f' g'2 g'
73 @@end lilypond
74 @end example
75
76 @noindent
77 produces
78
79 @lilypond
80   c' d' e' f' g'2 g'
81 @end lilypond
82
83 Then the short version:
84
85 @example
86 @@lilypond[11pt]@{<<c' e' g'>>@}
87 @end example
88
89 @noindent
90 produces
91
92 @lilypond[11pt]{ <<c' e' g'>> }
93
94 @command{lilypond-book} knows the default margins and a few paper
95 sizes.  One of these commands should be in the beginning of the document:
96
97 @itemize @bullet
98 @item @code{@@afourpaper}
99 @item @code{@@afourlatex}
100 @item @code{@@afourwide}
101 @item @code{@@smallbook}
102 @end itemize
103
104 @noindent
105 @code{@@pagesizes} are not yet supported.
106
107 When producing texinfo, lilypond-book also generates bitmaps of the
108 music, so you can make a HTML document with embedded music.
109
110
111 @c @TeX{} in node name seems to barf
112 @node Integrating LaTeX and music
113 @section Integrating LaTeX and music
114
115
116 For La@TeX{}, music is entered using
117
118 @example
119 \begin[options, go, here]@{lilypond@}
120   YOUR LILYPOND CODE
121 \end@{lilypond@}
122 @end example
123
124 @example
125 \lilypondfile[options, go,here]@{@var{filename}@}
126 @end example
127
128 @noindent
129 or
130
131 @example
132 \lilypond@{ YOUR LILYPOND CODE @}
133 @end example
134
135 Running lilypond-book yields a file that can be processed with
136 La@TeX{}. We show some examples here:
137
138 @example
139 \begin[26pt]@{lilypond@}
140   c' d' e' f' g'2 g'2
141 \end@{lilypond@}
142 @end example
143
144 @noindent
145 produces
146
147 @lilypond[26pt]
148   c' d' e' f' g'2 g'2
149 @end lilypond
150
151 Then the short version:
152
153 @example
154 \lilypond[11pt]@{<<c' e' g'>>@}
155 @end example
156
157 @noindent
158 produces
159
160 @lilypond[11pt]{<<c' e' g'>>}
161
162 The linewidth of the music will be adjust by examining the commands in
163 the document preamble, the part of the document before
164 @code{\begin@{document@}}: @command{lilypond-book} sends these to
165 La@TeX{} to find out how wide the text is. The line width variable for
166 the music fragments are adjusted to the text width.
167
168 After @code{\begin@{document@}}, the column changing commands
169 @code{\onecolumn} , @code{\twocolumn} commands and the
170 @code{multicols} environment from the multicol package are also
171 interpreted.
172
173 The titling from the @code{\header} section of the fragments can be
174 imported by adding the following to the top of the La@TeX{} file:
175
176 @example
177 \input titledefs.tex
178 \def\preLilypondExample@{\def\mustmakelilypondtitle@{@}@}
179 @end example
180
181 The music will be surrounded by @code{\preLilypondExample} and
182 @code{\postLilypondExample}, which are defined to be empty by default.
183
184 @node Integrating HTML and music
185 @section Integrating HTML and music
186
187 Music is entered using
188
189 @example
190 <lilypond relative1 verbatim>
191   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
192 </lilypond>
193 @end example
194
195 @noindent
196 of which lilypond-book will produce a HTML with appropriate image tags for the
197 music fragments:
198  
199 @example
200 <lilypond relative1 verbatim>
201   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
202 </lilypond>
203 @end example
204
205 @lilypond[relative1]
206   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
207 @end lilypond
208
209 For inline pictures, use @code{<lilypond ... />} syntax, eg.
210 @example
211 Some music in <lilypond a b c/> a line of text.
212 @end example
213
214 A special feature not (yet) available in other output formats, is the
215 @code{<ly2dvifile>} tag, for example,
216 @example
217   <ly2dvifile>trip.ly</ly2dvifile>
218 @end example
219 This runs @file{trip.ly} through ly2dvi (see also @ref{Invoking
220 ly2dvi}), and substitutes a preview image in the output. The image
221 links to a separate HTML file, so clicking it will take the viewer to
222 a menu, with links to images, midi and printouts.
223
224 @cindex ly2dvi
225 @cindex titling in THML
226 @cindex preview image
227 @cindex thumbnail
228
229 @node Music fragment options
230 @section Music fragment options
231
232 The commands for lilypond-book have room to specify one or more of the
233 following options:
234
235 @table @code
236 @item verbatim
237 CONTENTS is copied into the source enclosed in a verbatim block,
238 followed by any text given with the @code{intertext} option, then
239 the actual music is displayed.  This option does not work with
240 the short version of the music blocks:
241
242 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
243
244 @item smallverbatim
245 works like @code{verbatim}, but in a smaller font.
246
247 @item intertext="@var{text}"
248 is used in conjunction with @code{verbatim} option: This puts
249 @var{text} between the code and the music (without indentation).
250
251 @item filename="@var{filename}"
252 saves the LilyPond code to @var{filename}.  By default, a hash value
253 of the code is used.
254
255 @item 11pt
256 @lilypond[11pt, eps]
257 \relative c' {
258   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
259   [d16 g, a b][c a b g][d'8 g f-\prall g]
260 }
261 @end lilypond
262
263 @item 13pt
264 @lilypond[13pt, eps]
265 \relative c' {
266   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
267   [d16 g, a b][c a b g][d'8 g f-\prall g]
268 }
269 @end lilypond
270
271 @item 16pt
272 @lilypond[16pt, eps]
273 \relative c' {
274   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
275 }
276 @end lilypond
277
278 @item 20pt
279 @lilypond[20pt, eps]
280 \relative c' {
281   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
282 }
283 @end lilypond
284
285 @item 26pt
286 @lilypond[26pt, eps]
287 \relative c' {
288   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
289 }
290 @end lilypond
291
292 @item raggedright
293 produces naturally spaced lines (i.e., @code{raggedright = ##t}); this
294 works well for small music fragments.
295
296 @item multiline
297 is the opposite of @code{singleline}: it justifies and breaks lines.
298
299 @item linewidth=@var{size}@var{unit}
300 sets linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
301 This option affects LilyPond output, not the text layout.
302
303 @item notime
304 prevents printing time signature.
305
306 @item fragment
307 @itemx nofragment
308 overrides @command{lilypond-book} auto detection of what type of code is
309 in the LilyPond block, voice contents or complete code.
310
311 @item indent=@var{size}@var{unit}
312 sets indentation of the first music system to @var{size},
313 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
314 not the text layout.  For single-line fragments the default is to
315 use no indentation.
316
317 @item noindent
318 sets indentation of the first music system to zero.  This option
319 affects LilyPond, not the text layout.
320
321 @item notexidoc
322 prevents including @code{texidoc}. This is only for Texinfo output.
323
324 In Texinfo, the music fragment is normally preceded by the
325 @code{texidoc} field from the @code{\header}. The LilyPond test
326 documents are composed from small @file{.ly} files in this way:
327
328 @example
329   \header @{
330     texidoc = "this file demonstrates a single note"
331   @}
332   \score @{ \notes @{ c'4 @} @} 
333 @end example
334
335 @item quote
336 instructs @command{lilypond-book} to put La@TeX{} and Texinfo output
337 into a quotation block.
338
339 @item printfilename
340 prints the file name before the music example.  Useful in conjunction
341 with @code{\lilypondfile}.
342
343 @item relative, relative @var{N}
344 uses relative octave mode.  By default, notes are specified relative
345 central C.  The optional integer argument specifies the octave of the
346 starting note, where the default @code{1} is central C.
347 @end table
348
349
350 @node Invoking lilypond-book
351 @section Invoking lilypond-book
352
353 Running @command{lilypond-book} generates lots of small files that
354 LilyPond will process.  To avoid all that garbage in the source
355 directory, it is advisable to change to a temporary directory first:
356 @example
357 cd out && lilypond-book ../yourfile.tex
358 @end example
359
360 @noindent
361 or to use the @option{--outdir} command line option, and change to
362 that director before running La@TeX{} or @file{makeinfo}:
363
364 @example
365 lilypond-book --outdir=out yourfile.tex
366 cd out  && latex yourfile.latex
367 @end example
368
369 For La@TeX{} input, the file to give to La@TeX{} has extension @file{.latex}.
370 Texinfo input will be written to a file with extension @file{.texi}.
371
372 @cindex titling and lilypond-book
373 @cindex lilypond-book and titling
374 @cindex @code{\header} in La@TeX{} documents
375
376 To add titling from the @code{\header} section of the files, add the
377 following to the top of the La@TeX{} file:
378 @example
379 \input titledefs.tex
380 \def\preLilypondExample@{\def\mustmakelilypondtitle@{@}@}
381 @end example
382
383 @command{lilypond-book} accepts the following command line options:
384
385 @table @code
386 @item @option{-f @var{format}}, @option{--format=@var{format}}
387 Specify the document type to process: @code{html}, @code{latex} or
388 @code{texi} (the default).  @command{lilypond-book} usually figures this
389 out automatically.
390
391 The @code{texi} document type produces a texinfo file with music
392 fragments in the DVI output only. For getting images in the HTML
393 version,  the format 
394 @code{texi-html} must be used.
395
396 @item @option{--default-music-fontsize=@var{sz}pt}
397 Set the music font size to use if no fontsize is given as option.
398
399 @item @option{--force-music-fontsize=@var{sz}pt}
400 Force all music to use this fontsize, overriding options given to
401 @code{\begin@{lilypond@}}.
402
403 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
404 Add @var{DIR} to the include path.
405
406 @item @option{-M}, @option{--dependencies}
407 Write dependencies to @file{filename.dep}.
408
409 @item @option{--dep-prefix=@var{pref}}
410 Prepend @var{pref} before each @option{-M} dependency.
411
412 @item @option{-n}, @option{--no-lily}
413 Generate the @code{.ly} files, but do not process them.
414
415 @item @option{--no-music}
416 Strip all music from the input file.
417
418 @item @option{--no-pictures}
419 Do not generate pictures when processing Texinfo.
420
421 @item @option{--outname=@var{file}}
422 The name of La@TeX{} file to output.  If this option is not given,
423 the output name is derived from the input name.
424
425 @item @option{--outdir=@var{dir}}
426 Place generated files in @var{dir}.
427
428 @item @option{--version}
429 Print version information.
430
431 @item @option{--help}
432 Print a short help message.
433 @end table
434
435
436 @section Bugs
437
438 The La@TeX{} @code{\includeonly@{...@}} command is ignored.
439
440 The Texinfo command @code{pagesize} is not interpreted. Almost all
441 La@TeX{} commands that change margins and line widths are ignored.
442
443 The size of a music block is limited to 1.5 kb, due to technical
444 problems with the Python regular expression engine. For longer files,
445 use @code{\lilypondfile}.  Using @code{\lilypondfile} also makes
446 upgrading files (through convert-ly, see @ref{Invoking convert-ly})
447 easier.
448
449 @command{lilypond-book} processes all music fragments in one big run.
450 The state of the GUILE interpreter is not reset between fragments;
451 this means that changes made to global GUILE definitions, e.g. done
452 with @code{set!} or @code{set-cdr!}, can leak from one fragment into
453 the next fragment.