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