3 @node Merging text and music with lilypond-book
4 @chapter Merging text and music with lilypond-book
6 @command{lilypond-book} runs Lilypond on fragments of lilypond in a
7 La@TeX{} or Texinfo file, and includes the results into a document that
8 can be processed with La@TeX{}, @command{makeinfo} or
9 @command{texi2dvi}. The result is a text document containing formatted
12 More precisely, if a La@TeX{} file contains
24 then LilyPond is run on CONTENTS. @command{lilypond-book} puts the
25 result back into the latex file. When you run the result through latex,
26 you get a document that mixes text and music. lilypond-book will insert
27 line width and font size definitions before @code{CONTENTS}, so the
28 music samples will match the layout of your document.
30 Very often, if you mix music and text, the music is only a few
31 notes or at most a few bars. This music should be as short as possible
32 and not stretched to be aligned to the right margin. lilypond-book does
33 this automatically if you don't use a @code{\score} block in
34 @code{CONTENTS}. For example: @code{\lilypond@{\context Voice <c' e' g'>
37 You can also use @code{lilypondfile} to include another file:
39 \lilypondfile@{foo.ly@}
42 All three forms can take several options. They are specified in brackets
45 \lilypondfile[options, go, here]@{ .. @}
46 \begin[options, go, here]@{lilypond@} .. \end@{lilypond@}
47 \lilypond[options, go,here]@{ .. @}
50 In the Texinfo version, bitmaps of the music are also generated, so you
51 can make a HTML document with embedded music.
54 @section Texinfo reference
56 You specify the lilypond code like this:
58 @@lilypond[options, go, here]
61 @@lilypond[option, go, here]@{ YOUR LILYPOND CODE @}
62 @@lilypondfile[options, go,here]@{@var{filename}@}
66 @command{lilypond-book} knows the default margins, and a few paper
67 sizes. One of these commands should be in the beginning of the document:
69 @item @code{@@afourpaper}
70 @item @code{@@afourlatex}
71 @item @code{@@afourwide}
72 @item @code{@@smallbook}
74 @code{@@pagesizes} are not yet supported.
76 We show two simple examples here. First a complete block:
88 Then the short version:
90 @@lilypond[11pt]@{<c' e' g'>@}
95 @lilypond[11pt]{<c' e' g'>}
97 @section La@TeX{} reference
99 You specify the lilypond code like this:
101 \begin[option, go, here]@{lilypond@}
107 \lilypondfile[options, go,here]@{@var{filename}@}
111 \lilypond@{ YOUR LILYPOND CODE @}
114 You can use whatever commands you like in the document preamble,
115 that is the part of the document before @code{\begin@{document@}}.
116 @command{lilypond-book} will send it to La@TeX{} to find out how wide
117 the text is and adjust the linewidth variable in the paper definition of
118 you music according to that.
120 After @code{\begin@{document@}} you must be a little more careful
121 when you use commands that change the width of the text and how
122 many columns there are. @command{lilypond-book} know about the
123 @code{\onecolumn} and @code{\twocolumn} commands and the @code{multicols}
124 environment from the multicol package.
126 The music will be surrounded by @code{\preLilypondExample} and
127 @code{\postLilypondExample}. The variables are
128 defined to nothing by default, and the user can redefine them
129 to whatever he wants.
131 We show some examples here.
134 \begin[26pt]@{lilypond@}
145 Then the short version:
147 \lilypond[11pt]@{<c' e' g'>@}
152 @lilypond[11pt]{<c' e' g'>}
159 This will create the music as eps graphics and include it into the
160 document with the @code{\includegraphics} command. It works in
163 This enables you to place music examples in the running text (and not in
164 a separate paragraph). To avoid that La@TeX{} places the music on a line
165 of its own, there should be no empty lines between the normal text and
166 the lilypond environment. For inline music, you probably also need a
167 smaller music font size (eg. 11 pt or 13 pt)
171 CONTENTS is copied into the source enclosed in a verbatim block,
172 followed by any text given with the @code{intertext} option, then
173 the actual music is displayed. This option does not work with
174 the short version of the lilypond blocks:
176 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
179 like @code{verbatim}, but in a smaller font.
181 @item intertext="@var{text}"
182 Used in conjunction with @code{verbatim} option: this puts
183 @var{text} between the code and the music.
184 @item filename="@var{filename}"
185 Save the lilypond code to @var{filename}. By default, a hash value
191 r16 [c d e][f d e c] [g'8 c][b-\prall c] |
192 [d16 g, a b][c a b g][d'8 g f-\prall g]
198 r16 [c d e][f d e c] [g'8 c][b-\prall c] |
199 [d16 g, a b][c a b g][d'8 g f-\prall g]
205 r16 [c d e][f d e c] [g'8 c][b-\prall c] |
206 [d16 g, a b][c a b g][d'8 g f-\prall g]
212 r16 [c d e][f d e c] [g'8 c][b-\prall c] |
213 [d16 g, a b][c a b g][d'8 g f-\prall g]
219 r16 [c d e][f d e c] [g'8 c][b-\prall c] |
224 Produce a single naturally spaced, unjustified line. (i.e.: linewidth = -1).
226 The opposite of @code{singleline}: justify and break lines.
227 @item linewidth=@var{size}@var{unit}
228 Set linewidth to @var{size}, where @var{unit} = cm, mm, in or pt.
231 Override @command{lilypond-book} auto detection of what type of code is in the
232 lilypond block, voice contents or complete code.
233 @item indent=@var{size}@var{unit}
234 Set first line indent to @var{size}, where @var{unit} = cm, mm, in or pt.
236 Set first line indent to zero.
238 Prints the file name before the music example. Useful in conjunction
239 with @code{\lilypondfile}.
240 @item relative, relative @var{N}
241 Use relative octave mode. By default, notes are specified relative
242 central C. The optional integer argument specifies how many octaves
243 higher (positive number) or lower (negative number) to place the
249 When you run @command{lilypond-book} it will generate lots of small
250 files that Lilypond will process. So to avoid all the garbage in
251 your source directory, you should either change to a temporary
252 directory, or use the @code{--outdir} command line options:
254 @code{cd out && lilypond-book ../yourfile.tex}
256 @code{lilypond-book --outdir=out yourfile.tex}
259 For latex input, the file to give to latex has extension @file{.latex}.
260 Texinfo input will be written to a file with extension @file{.texi}.
262 If you use @code{--outdir}, you should also @code{cd} to that directory
263 before running LaTeX or makeinfo. This may seem a little kludgey, but
264 both Latex and makeinfo expect picture files (the music) to be in the
265 current working directory. Moreover, if you do this, LaTeX will not
266 clutter you normal working directory with output files.
268 @cindex titling and lilypond-book
269 @cindex lilypond-book and titling
270 @cindex \header in LaTeX documents
272 If you want to add titling from the @code{\header} section of the
273 files, you should add the following to the top of your LaTeX
276 \def\preLilypondExample@{\def\mustmakelilypondtitle@{@}@}
279 lilypond-book accepts the following command-line options:
281 @item @option{-f}, @option{--format=}
282 Specify the document type to process, @code{latex} or @code{texi}.
283 @command{lilypond-book} usually figure this out automatically.
284 @item --default-music-fontsize=@var{sz}pt
285 Set the fontsize to use for lilypond if no fontsize is given
287 @item --force-music-fontsize=@var{sz}pt
288 Force all lilypond to use this fontsize, overriding options
289 given to @code{\begin@{lilypond@}}
290 @item -I @var{DIR}, --include=@var{DIR}
291 Add @var{DIR} to the include path.
292 @item -M, --dependencies
293 Write dependencies to @file{filename.dep}
294 @item --dep-prefix=@code{PREF}
295 prepend @code{PREF} before each @code{-M} dependency
297 don't run lilypond, but do generate the @code{.ly} files
299 strip all lilypond blocks from the file.
301 don't generate pictures when processing Texinfo.
303 don't write ly files. This way you can do
305 lilypond-book file.tely
307 lilypond-book --read-lys
310 [TODO not a useful option unless you can undump the input file]
312 @item --outname=@var{FILE}
313 The name of La@TeX{} file to output. If this option is not given,
314 the output name is derived from the input name.
315 @item --outdir=@var{DIR}
316 place generated files in @var{DIR}.
318 print version information
320 Print a short help message
326 The La@TeX{} \includeonly@{...@} command is ignored.
328 The Texinfo command @code{pagesize} is on the TODO list for Lilypond
329 1.6, but changing the linewidth in other ways will not give you a
330 straight right margin.
332 Almost all La@TeX{} commands that change margins and line widths are
335 There is no way to automatically apply convert-ly to fragments inside a