]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
*** empty log message ***
[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 @node Integrating text and music with lilypond-book
15 @chapter Integrating text and music with lilypond-book
16
17 If you want to add pictures of music to a document, you can simply do
18 it the way you would do with other types of pictures.  You write
19 LilyPond code, process it separately to embedded PostScript or
20 @code{png}, and include it as a picture into your La@TeX{} or
21 @code{html} source.
22
23 @command{lilypond-book} provides you with a way to automate this
24 process: This program extracts snippets of music from your document,
25 runs LilyPond on them, and outputs your document with the resulting
26 pictures substituted for the music you entered.  The line width and
27 font size definitions for the music are adjusted to match the layout
28 of your document.
29
30 It can work on La@TeX{}, @code{html} or texinfo documents.  A tutorial
31 on using lilypond-book is in @ref{Integrating text and music}.
32
33 @menu
34 * Integrating Texinfo and music::
35 * Integrating La@TeX{} and music::
36 * Integrating HTML and music::
37 * Music fragment options::
38 * Invoking lilypond-book::
39 @end menu
40
41
42 @cindex texinfo
43 @cindex latex
44 @cindex texinfo
45 @cindex @code{texi}
46 @cindex html
47 @cindex documents, adding music to
48
49
50 @node Integrating Texinfo and music
51 @section Integrating Texinfo and music
52
53 You specify the LilyPond code like this:
54
55 @example
56 @@lilypond[options, go, here]
57   YOUR LILYPOND CODE
58 @@end lilypond
59 @@lilypond[options, go, here]@{ YOUR LILYPOND CODE @}
60 @@lilypondfile[options, go, here]@{@var{filename}@}
61 @end example
62
63 Then you run lilypond-book on it, and the result is a file you can
64 process with texinfo. We show two simple examples here.  First a
65 complete block:
66
67 @example
68 @@lilypond[26pt]
69   c' d' e' f' g'2 g'
70 @@end lilypond
71 @end example
72
73 @noindent
74 produces this music:
75
76 @lilypond
77   c' d' e' f' g'2 g'
78 @end lilypond
79
80 Then the short version:
81
82 @example
83 @@lilypond[11pt]@{<<c' e' g'>>@}
84 @end example
85
86 @noindent
87 and its music:
88
89 @lilypond[11pt]{ <<c' e' g'>> }
90
91 @command{lilypond-book} knows the default margins and a few paper
92 sizes.  One of these commands should be in the beginning of the document:
93
94 @itemize @bullet
95 @item @code{@@afourpaper}
96 @item @code{@@afourlatex}
97 @item @code{@@afourwide}
98 @item @code{@@smallbook}
99 @end itemize
100
101 @noindent
102 @code{@@pagesizes} are not yet supported.
103
104 When producing texinfo, lilypond-book also generates bitmaps of the
105 music, so you can make a HTML document with embedded music.
106
107
108 @node Integrating La@TeX{} and music
109 @section Integrating La@TeX{} and music
110
111
112   You specify LilyPond code like this:
113
114 @example
115 \begin[options, go, here]@{lilypond@}
116   YOUR LILYPOND CODE
117 \end@{lilypond@}
118 @end example
119
120 @example
121 \lilypondfile[options, go,here]@{@var{filename}@}
122 @end example
123
124 @noindent
125 or
126
127 @example
128 \lilypond@{ YOUR LILYPOND CODE @}
129 @end example
130
131 Then you run lilypond-book on it, and the result is a file you can
132 process with La@TeX{}. We show some examples here.
133
134 @example
135 \begin[26pt]@{lilypond@}
136   c' d' e' f' g'2 g'2
137 \end@{lilypond@}
138 @end example
139
140 @noindent
141 produces this music:
142
143 @lilypond[26pt]
144   c' d' e' f' g'2 g'2
145 @end lilypond
146
147 Then the short version:
148
149 @example
150 \lilypond[11pt]@{<<c' e' g'>>@}
151 @end example
152
153 @noindent
154 and its music:
155
156 @lilypond[11pt]{<<c' e' g'>>}
157
158 You can use whatever commands you like in the document preamble,
159 the part of the document before @code{\begin@{document@}}.
160 @command{lilypond-book} will send it to La@TeX{} to find out how wide
161 the text is and adjust the linewidth variable in the paper definition of
162 your music according to that.
163
164 After @code{\begin@{document@}} you must be a little more careful
165 when you use commands that change the width of the text and how
166 many columns there are.  @command{lilypond-book} knows about the
167 @code{\onecolumn} and @code{\twocolumn} commands and the @code{multicols}
168 environment from the multicol package.
169
170 The music will be surrounded by @code{\preLilypondExample} and
171 @code{\postLilypondExample}.  The variables are
172 defined to nothing by default, and the user can redefine them
173 to whatever he wants.
174
175
176 @node Integrating HTML and music
177 @section Integrating HTML and music
178
179 You specify LilyPond code like this:
180
181 @example
182 <lilypond relative1 verbatim>
183   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
184 </lilypond>
185 @end example
186
187 @noindent
188 Then you run lilypond-book on it, and the result is a file you can
189 process with La@TeX{}. The final result look like
190
191 @example
192 <lilypond relative1 verbatim>
193   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
194 </lilypond>
195 @end example
196
197 @lilypond[relative1]
198   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
199 @end lilypond
200
201 For inline pictures, use @code{<lilypond ... />} syntax, eg.
202 @example
203 Some music in <lilypond a b c/> a line of text.
204 @end example
205
206
207 @node Music fragment options
208 @section Music fragment options
209
210 The commands for lilypond-book have room to specify options.  These are
211 all of the options:
212
213 @table @code
214 @item eps
215 This will create the music as eps graphics and include it into the
216 document with the @code{\includegraphics} command.  It works in
217 La@TeX{} only.
218
219 This enables you to place music examples in the running text (and not in
220 a separate paragraph).  To avoid that La@TeX{} places the music on a line
221 of its own, there should be no empty lines between the normal text and
222 the LilyPond environment. For inline music, you probably also need a
223 smaller music font size (e.g.@: 11@dmn{pt} or 13@dmn{pt})
224
225 @item verbatim
226 CONTENTS is copied into the source enclosed in a verbatim block,
227 followed by any text given with the @code{intertext} option, then
228 the actual music is displayed.  This option does not work with
229 the short version of the LilyPond blocks:
230
231 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
232
233 @item smallverbatim
234 Like @code{verbatim}, but in a smaller font.
235
236 @item intertext="@var{text}"
237 Used in conjunction with @code{verbatim} option: This puts
238 @var{text} between the code and the music (without indentation).
239
240 @item filename="@var{filename}"
241 Save the LilyPond code to @var{filename}.  By default, a hash value
242 of the code is used.
243
244 @item 11pt
245 @lilypond[11pt, eps]
246 \relative c' {
247   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
248   [d16 g, a b][c a b g][d'8 g f-\prall g]
249 }
250 @end lilypond
251
252 @item 13pt
253 @lilypond[13pt, eps]
254 \relative c' {
255   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
256   [d16 g, a b][c a b g][d'8 g f-\prall g]
257 }
258 @end lilypond
259
260 @item 16pt
261 @lilypond[16pt, eps]
262 \relative c' {
263   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
264 }
265 @end lilypond
266
267 @item 20pt
268 @lilypond[20pt, eps]
269 \relative c' {
270   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
271 }
272 @end lilypond
273
274 @item 26pt
275 @lilypond[26pt, eps]
276 \relative c' {
277   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
278 }
279 @end lilypond
280
281 @item singleline
282 Produce a single, naturally spaced, unjustified line
283 (i.e., linewidth = @minus{}1).
284
285 @item multiline
286 The opposite of @code{singleline}: Justify and break lines.
287
288 @item linewidth=@var{size}@var{unit}
289 Set linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
290 This option affects LilyPond output, not the text layout.
291
292 @item notime
293 Don't print time signature.
294
295 @item fragment
296 @itemx nofragment
297 Override @command{lilypond-book} auto detection of what type of code is
298 in the LilyPond block, voice contents or complete code.
299
300 @item indent=@var{size}@var{unit}
301 Set indentation of the first music system to @var{size},
302 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
303 not the text layout.  For single-line fragments the default is to
304 use no indentation.
305
306 @item noindent
307 Set indentation of the first music system to zero.  This option
308 affects LilyPond, not the text layout.
309
310 @item noquote
311 By default, @command{lilypond-book} puts both La@TeX{} and texinfo output
312 into a quotation block.  Using this option prevents this; no indentation
313 will be used.
314
315 @item printfilename
316 Prints the file name before the music example.  Useful in conjunction
317 with @code{\lilypondfile}.
318
319 @item relative, relative @var{N}
320 Use relative octave mode.  By default, notes are specified relative
321 central C.  The optional integer argument specifies how many octaves
322 higher (positive number) or lower (negative number) to place the
323 starting note.
324 @end table
325
326
327 @node Invoking lilypond-book
328 @section Invoking lilypond-book
329
330 When you run @command{lilypond-book} it will generate lots of small
331 files that LilyPond will process.  To avoid all the garbage in
332 your source directory, you should either change to a temporary
333 directory, or use the @option{--outdir} command line options:
334
335 @code{cd out && lilypond-book ../yourfile.tex}
336
337 @code{lilypond-book --outdir=out yourfile.tex}
338
339 For La@TeX{} input, the file to give to La@TeX{} has extension @file{.latex}.
340 Texinfo input will be written to a file with extension @file{.texi}.
341
342 If you use @option{--outdir}, you should also @code{cd} to that directory
343 before running La@TeX{} or @command{makeinfo}.  This may seem a little
344 kludgy, but both La@TeX{} and @command{makeinfo} expect picture files
345 (the music) to be in the current working directory.  Moreover, if you do
346 this, La@TeX{} will not clutter your normal working directory with output
347 files.
348
349 @cindex titling and lilypond-book
350 @cindex lilypond-book and titling
351 @cindex @code{\header} in La@TeX{} documents
352
353 If you want to add titling from the @code{\header} section of the
354 files, you should add the following to the top of your La@TeX{} file:
355
356 @example
357 \input titledefs.tex
358 \def\preLilypondExample@{\def\mustmakelilypondtitle@{@}@}
359 @end example
360
361 @command{lilypond-book} accepts the following command line options:
362
363 @table @code
364 @item @option{-f @var{format}}, @option{--format=@var{format}}
365 Specify the document type to process: @code{html}, @code{latex} or
366 @code{texi} (the default).  @command{lilypond-book} usually figures this
367 out automatically.
368
369 Note that the @code{texi} document type produces a DVI file; to
370 convert a texinfo document to @code{html}, you should use the additional
371 format @code{texi-html} instead of @code{texi} to convert lilypond
372 fragments to PNG images.
373
374 @item @option{--default-music-fontsize=@var{sz}pt}
375 Set the fontsize to use for LilyPond if no fontsize is given
376 as option.
377
378 @item @option{--force-music-fontsize=@var{sz}pt}
379 Force all LilyPond code to use this fontsize, overriding options
380 given to @code{\begin@{lilypond@}}.
381
382 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
383 Add @var{DIR} to the include path.
384
385 @item @option{-M}, @option{--dependencies}
386 Write dependencies to @file{filename.dep}.
387
388 @item @option{--dep-prefix=@var{pref}}
389 Prepend @var{pref} before each @option{-M} dependency.
390
391 @item @option{-n}, @option{--no-lily}
392 Don't run LilyPond, but do generate the @code{.ly} files.
393
394 @item @option{--no-music}
395 Strip all  LilyPond blocks from the file.
396
397 @item @option{--no-pictures}
398 Don't generate pictures when processing Texinfo.
399
400 @item @option{--read-lys}
401 Don't write ly files.  This way you can do
402
403 @example
404 lilypond-book file.tely
405 convert-ly
406 lilypond-book --read-lys
407 @end example
408
409 @item @option{--outname=@var{file}}
410 The name of La@TeX{} file to output.  If this option is not given,
411 the output name is derived from the input name.
412
413 @item @option{--outdir=@var{dir}}
414 Place generated files in @var{dir}.
415
416 @item @option{--version}
417 Print version information.
418
419 @item @option{--help}
420 Print a short help message.
421 @end table
422
423
424 @section Bugs
425
426 The La@TeX{} @code{\includeonly@{...@}} command is ignored.
427
428 The Texinfo command @code{pagesize} is on the TODO list for LilyPond
429 1.8, but changing the linewidth in other ways will not give you a
430 straight right margin.
431
432 Almost all La@TeX{} commands that change margins and line widths are
433 ignored.
434
435 There is no way to automatically apply @command{convert-ly} only to fragments
436 inside a lilypond-book file.
437
438 @command{lilypond-book} processes all music fragments in one big run.  The
439 state of the GUILE interpreter is not reset between fragments; this
440 means that global GUILE definitions, e.g., done with @code{#(define @dots{})}
441 and @code{#(set! @dots{})} can leak from one fragment into the next fragment.