]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
($(outdir)/%.pdf): add DVIPS_FLAGS. This will
[lilypond.git] / Documentation / user / lilypond-book.itely
1 \version "2.1.22"
2 @c -*-texinfo-*-
3
4 @ignore
5
6 TODO: cleanup
7
8 ** AARGH.e We also have tutorial.itely: Integrating text and music.
9
10    Could also do with a cleanup.  Lost inspiration to fix this manual
11    where to describe what?
12
13 @end ignore
14
15
16 @node lilypond-book manual
17 @chapter lilypond-book manual
18
19 If you want to add pictures of music to a document, you can simply do
20 it the way you would do with other types of pictures.  The pictures
21 are created separately, yielding PostScript pictures or PNG images,
22 and those are included into a La@TeX{} or HTML document.
23
24 @command{lilypond-book} provides a way to automate this process: this
25 program extracts snippets of music from your document, runs LilyPond
26 on them, and outputs the document with pictures substituted for the
27 music.  The line width and font size definitions for the music are
28 adjusted to match the layout of your document.
29
30 This procedure may be applied to La@TeX{}, @code{html} or Texinfo
31 documents.  A tutorial on using lilypond-book is in @ref{Integrating
32 text and music}.  For more information about La@TeX{}
33 @uref{http://www.ctan.org/tex-archive/info/lshort/english/,The not so
34 Short Introduction to LaTeX} provides a introction to using La@TeX{}.
35
36
37
38
39 @menu
40 * Integrating Texinfo and music::  
41 * Integrating LaTeX and music::  
42 * Integrating HTML and music::  
43 * Music fragment options::      
44 * Invoking lilypond-book::      
45 @end menu
46
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 Music is specified 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 When lilypond-book is run on it, this results in a texinfo file. We
71 show two simple examples here.  First a complete block:
72
73 @example
74 @@lilypond[staffsize=26]
75   c' d' e' f' g'2 g'
76 @@end lilypond
77 @end example
78
79 @noindent
80 produces
81
82 @lilypond
83   c' d' e' f' g'2 g'
84 @end lilypond
85
86 Then the short version:
87
88 @example
89 @@lilypond[staffsize=11]@{<c' e' g'>@}
90 @end example
91
92 @noindent
93 produces
94
95 @lilypond[staffsize=11]{ <c' e' g'> }
96
97 When producing texinfo, lilypond-book also generates bitmaps of the
98 music, so you can make a HTML document with embedded music.
99
100 @c @TeX{} in node name seems to barf
101 @node Integrating LaTeX and music
102 @section Integrating LaTeX and music
103
104
105 For La@TeX{}, music is entered using
106
107 @example
108 \begin[options,go,here]@{lilypond@}
109   YOUR LILYPOND CODE
110 \end@{lilypond@}
111 @end example
112
113 @example
114 \lilypondfile[options,go,here]@{@var{filename}@}
115 @end example
116
117 @noindent
118 or
119
120 @example
121 \lilypond@{ YOUR LILYPOND CODE @}
122 @end example
123
124 Running lilypond-book yields a file that can be processed with
125 La@TeX{}.
126
127
128 We show some examples here:
129
130 @example
131 \begin[staffsize=26]@{lilypond@}
132   c' d' e' f' g'2 g'2
133 \end@{lilypond@}
134 @end example
135
136 @noindent
137 produces
138
139 @lilypond[staffsize=26]
140   c' d' e' f' g'2 g'2
141 @end lilypond
142
143 Then the short version:
144
145 @example
146 \lilypond[staffsize=11]@{<c' e' g'>@}
147 @end example
148
149 @noindent
150 produces
151
152 @lilypond[staffsize=11]{<c' e' g'>}
153
154 The linewidth of the music will be adjust by examining the commands in
155 the document preamble, the part of the document before
156 @code{\begin@{document@}}: @command{lilypond-book} sends these to
157 La@TeX{} to find out how wide the text is. The line width variable for
158 the music fragments are adjusted to the text width.
159
160 After @code{\begin@{document@}}, the column changing commands
161 @code{\onecolumn}, @code{\twocolumn} commands
162 @ignore 
163 and the
164 @code{multicols} environment from the multicol package
165 @end ignore
166 are also interpreted.
167
168 The titling from the @code{\header} section of the fragments can be
169 imported by adding the following to the top of the La@TeX{} file:
170
171 @example
172 \input titledefs.tex
173 \def\preLilyPondExample@{\def\mustmakelilypondtitle@{@}@}
174 @end example
175
176 The music will be surrounded by @code{\preLilyPondExample} and
177 @code{\postLilyPondExample}, which are defined to be empty by default.
178
179 @cindex titling and lilypond-book
180 @cindex lilypond-book and titling
181 @cindex @code{\header} in La@TeX{} documents
182
183 To add titling from the @code{\header} section of the files, add the
184 following to the top of the La@TeX{} file:
185 @example
186 \input titledefs.tex
187 \def\preLilyPondExample@{\def\mustmakelilypondtitle@{@}@}
188 @end example
189
190 @cindex outline fonts
191 @cindex type1 fonts
192 @cindex dvips
193 @cindex invoking dvips
194
195 For printing the LaTeX document, you will need to use dvips. For
196 producing PostScript with scalable fonts, add the following options to
197 the dvips command line:
198 @example
199  -Ppdf -u +lilypond.map
200 @end example 
201
202 @noindent
203 PDF can then be produced with @code{ps2pdf}.
204
205
206 @node Integrating HTML and music
207 @section Integrating HTML and music
208
209 Music is entered using
210
211 @example
212 <lilypond relative=1 verbatim>
213   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
214 </lilypond>
215 @end example
216
217 @noindent
218 of which lilypond-book will produce a HTML with appropriate image tags for the
219 music fragments:
220  
221 @example
222 <lilypond relative=1 verbatim>
223   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
224 </lilypond>
225 @end example
226
227 @lilypond[relative=1]
228   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
229 @end lilypond
230
231 For inline pictures, use @code{<lilypond ... />} syntax, eg.
232 @example
233 Some music in <lilypond a b c/> a line of text.
234 @end example
235
236 A special feature not (yet) available in other output formats, is the
237 @code{<lilypondfile>} tag, for example,
238 @example
239   <lilypondfile>trip.ly</lilypondfile>
240 @end example
241 This runs @file{trip.ly} through @code{lilypond} (see also
242 @ref{Invoking lilypond}), and substitutes a preview image in the
243 output. The image links to a separate HTML file, so clicking it will
244 take the viewer to a menu, with links to images, midi and printouts.
245
246 @cindex titling in THML
247 @cindex preview image
248 @cindex thumbnail
249
250 @node Music fragment options
251 @section Music fragment options
252
253 The commands for lilypond-book have room to specify one or more of the
254 following options:
255
256 @table @code
257 @item verbatim
258 CONTENTS is copied into the source enclosed in a verbatim block,
259 followed by any text given with the @code{intertext} option, then
260 the actual music is displayed.  This option does not work with
261 the short version of the music blocks:
262
263 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
264
265 @item filename=@var{filename}
266 name the file (for @code{printfilename} option). The argument should
267 be unquoted. 
268
269 @item staffsize=POINTS
270 @lilypond[staffsize=31.41592658]
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
277 @item raggedright
278 produces naturally spaced lines (i.e., @code{raggedright = ##t}); this
279 works well for small music fragments.
280
281 @item linewidth=@var{size}\\@var{unit}
282 sets linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
283 This option affects LilyPond output, not the text layout.
284
285 @item notime
286 prevents printing time signature.
287
288 @item fragment
289 @item nofragment
290 overrides @command{lilypond-book} auto detection of what type of code is
291 in the LilyPond block, voice contents or complete code.
292
293 @item indent=@var{size}\\@var{unit}
294 sets indentation of the first music system to @var{size},
295 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
296 not the text layout.  For single-line fragments the default is to
297 use no indentation.
298
299 For example
300 @example
301   \begin[indent=\\5cm,raggedright]@{lilypond@}
302   ...
303   \end@{lilypond@}
304 @end example
305
306
307 @item noindent
308 sets indentation of the first music system to zero.  This option
309 affects LilyPond, not the text layout.
310
311 @item texidoc
312 Includes the @code{texidoc} field, if defined in the file. This is
313 only for Texinfo output.
314
315 In Texinfo, the music fragment is normally preceded by the
316 @code{texidoc} field from the @code{\header}. The LilyPond test
317 documents are composed from small @file{.ly} files in this way:
318
319 @example
320   \header @{
321     texidoc = "this file demonstrates a single note"
322   @}
323   \score @{ \notes @{ c'4 @} @} 
324 @end example
325
326 @item relative, relative=@var{N}
327 uses relative octave mode.  By default, notes are specified relative
328 central C.  The optional integer argument specifies the octave of the
329 starting note, where the default @code{1} is central C.
330 @end table
331
332
333 @node Invoking lilypond-book
334 @section Invoking lilypond-book
335
336
337 Running @command{lilypond-book} generates lots of small files that
338 LilyPond will process.  To avoid all that garbage in the source
339 directory, it is advisable to change to a temporary directory first:
340 @example
341 cd out && lilypond-book ../yourfile.tex
342 @end example
343
344 @noindent
345 or to use the @option{--output} command line option, and change to
346 that director before running La@TeX{} or @file{makeinfo}:
347
348 @example
349 lilypond-book --output=out yourfile.lytex
350 cd out && latex yourfile.tex
351 @end example
352
353
354 @command{lilypond-book} accepts the following command line options:
355
356 @table @code
357 @item @option{-f @var{format}}, @option{--format=@var{format}}
358 Specify the document type to process: @code{html}, @code{latex} or
359 @code{texi} (the default).  @command{lilypond-book} usually figures this
360 out automatically.
361
362 The @code{texi} document type produces a texinfo file with music
363 fragments in the DVI output only. For getting images in the HTML
364 version,  the format 
365 @code{texi-html} must be used.
366
367 @item @option{-F @var{filter}}, @option{--filter=@var{filter}}
368 Pipe snippets through @var{filter}.
369
370 For example:
371 @example
372     lilypond-book --filter='convert-ly --from=2.0.0' my-book.tely
373 @end example
374
375 @item @option{--help}
376 Print a short help message.
377
378 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
379 Add @var{DIR} to the include path.
380
381 @item @option{-o @var{dir}}, @option{--output=@var{dir}}
382 Place generated files in @var{dir}.
383
384 @item @option{-P @var{process}}, @option{--process=@var{COMMAND}}
385 Process lilypond snippets using @var{command}.  The default command is
386 @var{lilypon-bin}.
387
388 @item @option{--verbose}
389 Be verbose.
390
391 @item @option{--version}
392 Print version information.
393 @end table
394
395 For La@TeX{} input, the file to give to La@TeX{} has extension
396 @file{.latex}.  Texinfo input will be written to a file with extension
397 @file{.texi}.
398
399
400
401 @section Bugs
402
403 The La@TeX{} @code{\includeonly@{...@}} command is ignored.
404
405 The Texinfo command @code{pagesize} is not interpreted. Almost all
406 La@TeX{} commands that change margins and line widths are ignored.
407
408 Only the first @code{\score} of a LilyPond block is processed.
409
410 @c CHECKME--FIXME
411 The size of a music block is limited to 1.5 kb, due to technical
412 problems with the Python regular expression engine.  For longer files,
413 use @code{\lilypondfile}.
414
415 @command{lilypond-book} processes all music fragments in one big run.
416 The state of the GUILE interpreter is not reset between fragments;
417 this means that changes made to global GUILE definitions, e.g. done
418 with @code{set!} or @code{set-cdr!}, can leak from one fragment into
419 the next fragment.
420