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