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