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