7 ** AARGH.e We also have tutorial.itely: Integrating text and music.
9 Could also do with a cleanup. Lost inspiration to fix this manual
10 where to describe what?
14 @c @node Merging text and music with lilypond-book
15 @c @chapter Merging text and music with lilypond-book
17 @c fix this node name , this is too long.
19 @node Insert music snippets into your texts using lilypond-book
20 @chapter Insert music snippets into your texts using lilypond-book
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
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
44 @cindex documents, adding music to
47 More precisely, if a La@TeX{} file contains
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.
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'>
72 You can also use @code{lilypondfile} to include another file:
74 \lilypondfile@{foo.ly@}
77 All three forms can take several options. They are specified in brackets
80 \lilypondfile[options, go, here]@{ .. @}
81 \begin[options, go, here]@{lilypond@} .. \end@{lilypond@}
82 \lilypond[options, go,here]@{ .. @}
85 In the Texinfo version, bitmaps of the music are also generated, so you
86 can make a HTML document with embedded music.
89 @section Texinfo reference
91 You specify the LilyPond code like this:
93 @@lilypond[options, go, here]
96 @@lilypond[option, go, here]@{ YOUR LILYPOND CODE @}
97 @@lilypondfile[options, go,here]@{@var{filename}@}
100 We show two simple examples here. First a complete block:
112 Then the short version:
114 @@lilypond[11pt]@{<c' e' g'>@}
119 @lilypond[11pt]{<c' e' g'>}
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:
124 @item @code{@@afourpaper}
125 @item @code{@@afourlatex}
126 @item @code{@@afourwide}
127 @item @code{@@smallbook}
129 @code{@@pagesizes} are not yet supported.
131 @section La@TeX{} reference
133 You specify the LilyPond code like this:
135 \begin[option, go, here]@{lilypond@}
141 \lilypondfile[options, go,here]@{@var{filename}@}
145 \lilypond@{ YOUR LILYPOND CODE @}
148 We show some examples here.
151 \begin[26pt]@{lilypond@}
162 Then the short version:
164 \lilypond[11pt]@{<c' e' g'>@}
169 @lilypond[11pt]{<c' e' g'>}
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.
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.
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.
190 @section HTML reference
192 You specify the LilyPond code like this:
196 <lilypond relative1 verbatim>
197 \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
206 <lilypond relative1 verbatim>
207 \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
211 \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
219 Some music in <lilypond a b c/> a line of text.
223 @c Huh? ugh, can't show inline pictures in texinfo?
225 @c Some music in @lilypond{a b c} a line of text.
233 This will create the music as eps graphics and include it into the
234 document with the @code{\includegraphics} command. It works in
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)
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:
250 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
253 like @code{verbatim}, but in a smaller font.
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
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]
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]
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]
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]
293 r16 [c d e][f d e c] [g'8 c][b-\prall c] |
298 Produce a single naturally spaced, unjustified line. (i.e.: linewidth = -1).
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.
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.
310 Set first line indent to zero.
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
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:
328 @code{cd out && lilypond-book ../yourfile.tex}
330 @code{lilypond-book --outdir=out yourfile.tex}
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}.
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.
342 @cindex titling and lilypond-book
343 @cindex lilypond-book and titling
344 @cindex \header in LaTeX documents
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
350 \def\preLilypondExample@{\def\mustmakelilypondtitle@{@}@}
353 lilypond-book accepts the following command-line options:
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
359 @item --default-music-fontsize=@var{sz}pt
360 Set the fontsize to use for LilyPond if no fontsize is given
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
372 don't run LilyPond, but do generate the @code{.ly} files
374 strip all LilyPond blocks from the file.
376 don't generate pictures when processing Texinfo.
378 don't write ly files. This way you can do
380 lilypond-book file.tely
382 lilypond-book --read-lys
385 [TODO not a useful option unless you can undump the input file]
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}.
393 print version information
395 Print a short help message
401 The La@TeX{} \includeonly@{...@} command is ignored.
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.
407 Almost all La@TeX{} commands that change margins and line widths are
410 There is no way to automatically apply convert-ly to fragments inside a
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.