]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
* lily/key-performer.cc (create_audio_elements): always use major
[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.  You write
20 LilyPond code, process it separately to embedded PostScript or
21 @code{png}, and include it as a picture into your La@TeX{} or
22 @code{html} source.
23
24 @command{lilypond-book} provides you with a way to automate this
25 process: This program extracts snippets of music from your document,
26 runs LilyPond on them, and outputs your document with the resulting
27 pictures substituted for the music you entered.  The line width and
28 font size definitions for the music are adjusted to match the layout
29 of your document.
30
31 This procedure may be applied to La@TeX{}, @code{html} or Texinfo
32 documents.  A tutorial on using lilypond-book is in @ref{Integrating
33 text and music}.  In case that you do not know La@TeX{}, then
34 @uref{http://www.ctan.org/tex-archive/info/lshort/english/,The not so
35 Short Introduction to LaTeX} provides a introction to using La@TeX{}.
36
37
38 @menu
39 * Integrating Texinfo and music::  
40 * Integrating La@TeX{} 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 You specify the LilyPond code 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 Then you run lilypond-book on it, and the result is a file you can
70 process with texinfo. We show two simple examples here.  First a
71 complete block:
72
73 @example
74 @@lilypond[26pt]
75   c' d' e' f' g'2 g'
76 @@end lilypond
77 @end example
78
79 @noindent
80 produces this music:
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[11pt]@{<<c' e' g'>>@}
90 @end example
91
92 @noindent
93 and its music:
94
95 @lilypond[11pt]{ <<c' e' g'>> }
96
97 @command{lilypond-book} knows the default margins and a few paper
98 sizes.  One of these commands should be in the beginning of the document:
99
100 @itemize @bullet
101 @item @code{@@afourpaper}
102 @item @code{@@afourlatex}
103 @item @code{@@afourwide}
104 @item @code{@@smallbook}
105 @end itemize
106
107 @noindent
108 @code{@@pagesizes} are not yet supported.
109
110 When producing texinfo, lilypond-book also generates bitmaps of the
111 music, so you can make a HTML document with embedded music.
112
113
114 @node Integrating La@TeX{} and music
115 @section Integrating La@TeX{} and music
116
117
118   You specify LilyPond code like this:
119
120 @example
121 \begin[options, go, here]@{lilypond@}
122   YOUR LILYPOND CODE
123 \end@{lilypond@}
124 @end example
125
126 @example
127 \lilypondfile[options, go,here]@{@var{filename}@}
128 @end example
129
130 @noindent
131 or
132
133 @example
134 \lilypond@{ YOUR LILYPOND CODE @}
135 @end example
136
137 Then you run lilypond-book on it, and the result is a file you can
138 process with La@TeX{}. We show some examples here.
139
140 @example
141 \begin[26pt]@{lilypond@}
142   c' d' e' f' g'2 g'2
143 \end@{lilypond@}
144 @end example
145
146 @noindent
147 produces this music:
148
149 @lilypond[26pt]
150   c' d' e' f' g'2 g'2
151 @end lilypond
152
153 Then the short version:
154
155 @example
156 \lilypond[11pt]@{<<c' e' g'>>@}
157 @end example
158
159 @noindent
160 and its music:
161
162 @lilypond[11pt]{<<c' e' g'>>}
163
164 You can use whatever commands you like in the document preamble,
165 the part of the document before @code{\begin@{document@}}.
166 @command{lilypond-book} will send it to La@TeX{} to find out how wide
167 the text is and adjust the linewidth variable in the paper definition of
168 your music according to that.
169
170 After @code{\begin@{document@}} you must be a little more careful
171 when you use commands that change the width of the text and how
172 many columns there are.  @command{lilypond-book} knows about the
173 @code{\onecolumn} and @code{\twocolumn} commands and the @code{multicols}
174 environment from the multicol package.
175
176
177 If you want to add titling from the @code{\header} section of the
178 files, you should add the following to the top of your La@TeX{} file:
179
180 @example
181 \input titledefs.tex
182 \def\preLilypondExample@{\def\mustmakelilypondtitle@{@}@}
183 @end example
184
185 The music will be surrounded by @code{\preLilypondExample} and
186 @code{\postLilypondExample}, which are defined to be empty by default.
187
188 @node Integrating HTML and music
189 @section Integrating HTML and music
190
191 You specify LilyPond code like this:
192
193 @example
194 <lilypond relative1 verbatim>
195   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
196 </lilypond>
197 @end example
198
199 @noindent
200 Then you run lilypond-book on it, and the result is a file you can
201 process with La@TeX{}. The final result look like
202
203 @example
204 <lilypond relative1 verbatim>
205   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
206 </lilypond>
207 @end example
208
209 @lilypond[relative1]
210   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
211 @end lilypond
212
213 For inline pictures, use @code{<lilypond ... />} syntax, eg.
214 @example
215 Some music in <lilypond a b c/> a line of text.
216 @end example
217
218 A special feature not (yet) available in other output formats, is the
219 @code{<ly2dvifile>} tag, for example
220 @example
221   <ly2dvifile>trip.ly</ly2dvifile>
222 @end example
223 This runs @file{trip.ly} through ly2dvi (See also @ref{Invoking
224 ly2dvi}), and substitutes a preview image in the output. The image
225 links to a separate HTML file, so clicking it will take the viewer to
226 a menu, with links to images, midi and printouts.
227
228 @cindex ly2dvi
229 @cindex titling in THML
230 @cindex preview image
231 @cindex thumbnail
232
233 @node Music fragment options
234 @section Music fragment options
235
236 The commands for lilypond-book have room to specify one or more of the
237 following options:
238
239 @table @code
240 @item eps
241 This will create the music as eps graphics and include it into the
242 document with the @code{\includegraphics} command.  It works in
243 La@TeX{} only.
244
245
246 This enables you to place music examples in the running text (and not in
247 a separate paragraph).  To avoid that La@TeX{} places the music on a line
248 of its own, there should be no empty lines between the normal text and
249 the LilyPond environment. For inline music, you probably also need a
250 smaller music font size (e.g.@: 11@dmn{pt} or 13@dmn{pt})
251
252 @item verbatim
253 CONTENTS is copied into the source enclosed in a verbatim block,
254 followed by any text given with the @code{intertext} option, then
255 the actual music is displayed.  This option does not work with
256 the short version of the LilyPond blocks:
257
258 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
259
260 @item smallverbatim
261 Like @code{verbatim}, but in a smaller font.
262
263 @item intertext="@var{text}"
264 Used in conjunction with @code{verbatim} option: This puts
265 @var{text} between the code and the music (without indentation).
266
267 @item filename="@var{filename}"
268 Save the LilyPond code to @var{filename}.  By default, a hash value
269 of the code is used.
270
271 @item 11pt
272 @lilypond[11pt, eps]
273 \relative c' {
274   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
275   [d16 g, a b][c a b g][d'8 g f-\prall g]
276 }
277 @end lilypond
278
279 @item 13pt
280 @lilypond[13pt, eps]
281 \relative c' {
282   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
283   [d16 g, a b][c a b g][d'8 g f-\prall g]
284 }
285 @end lilypond
286
287 @item 16pt
288 @lilypond[16pt, 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 20pt
295 @lilypond[20pt, eps]
296 \relative c' {
297   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
298 }
299 @end lilypond
300
301 @item 26pt
302 @lilypond[26pt, eps]
303 \relative c' {
304   r16 [c d e][f d e c] [g'8 c][b-\prall c] |
305 }
306 @end lilypond
307
308 @item raggedright
309 Produce naturally spaced lines (i.e., @code{raggedright = ##t}); this
310 works well for small music fragments.
311
312 @item multiline
313 The opposite of @code{singleline}: Justify and break lines.
314
315 @item linewidth=@var{size}@var{unit}
316 Set linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
317 This option affects LilyPond output, not the text layout.
318
319 @item notime
320 Do not print time signature.
321
322 @item fragment
323 @itemx nofragment
324 Override @command{lilypond-book} auto detection of what type of code is
325 in the LilyPond block, voice contents or complete code.
326
327 @item indent=@var{size}@var{unit}
328 Set indentation of the first music system to @var{size},
329 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
330 not the text layout.  For single-line fragments the default is to
331 use no indentation.
332
333 @item noindent
334 Set indentation of the first music system to zero.  This option
335 affects LilyPond, not the text layout.
336
337 @item notexidoc
338 Do not include @code{texidoc}. This is only for Texinfo output.
339
340 In Texinfo, the music fragment is normally preceded by the
341 @code{texidoc} field from the @code{\header}. The LilyPond test
342 documents are composed from small @file{.ly} files in this way,
343
344 @example
345   \header @{
346     texidoc = "this file demonstrates a single note"
347   @}
348   \score @{ \notes @{ c'4 @} @} 
349 @end example
350
351 @item quote
352 Instruct @command{lilypond-book} to put La@TeX{} and Texinfo output
353 into a quotation block.
354
355 @item printfilename
356 Prints the file name before the music example.  Useful in conjunction
357 with @code{\lilypondfile}.
358
359 @item relative, relative @var{N}
360 Use relative octave mode.  By default, notes are specified relative
361 central C.  The optional integer argument specifies the octave of the
362 starting note, where the default @code{1} is central C.
363 @end table
364
365
366 @node Invoking lilypond-book
367 @section Invoking lilypond-book
368
369 When you run @command{lilypond-book} it will generate lots of small
370 files that LilyPond will process.  To avoid all the garbage in
371 your source directory, you should either change to a temporary
372 directory, or use the @option{--outdir} command line options:
373
374 @code{cd out && lilypond-book ../yourfile.tex}
375
376 @code{lilypond-book --outdir=out yourfile.tex}
377
378 For La@TeX{} input, the file to give to La@TeX{} has extension @file{.latex}.
379 Texinfo input will be written to a file with extension @file{.texi}.
380
381 If you use @option{--outdir}, you should also @code{cd} to that directory
382 before running La@TeX{} or @command{makeinfo}.  This may seem a little
383 kludgy, but both La@TeX{} and @command{makeinfo} expect picture files
384 (the music) to be in the current working directory.  Moreover, if you do
385 this, La@TeX{} will not clutter your normal working directory with output
386 files.
387
388 @cindex titling and lilypond-book
389 @cindex lilypond-book and titling
390 @cindex @code{\header} in La@TeX{} documents
391
392 If you want to add titling from the @code{\header} section of the
393 files, you should add the following to the top of your La@TeX{} file:
394
395 @example
396 \input titledefs.tex
397 \def\preLilypondExample@{\def\mustmakelilypondtitle@{@}@}
398 @end example
399
400 @command{lilypond-book} accepts the following command line options:
401
402 @table @code
403 @item @option{-f @var{format}}, @option{--format=@var{format}}
404 Specify the document type to process: @code{html}, @code{latex} or
405 @code{texi} (the default).  @command{lilypond-book} usually figures this
406 out automatically.
407
408 The @code{texi} document type produces a DVI file; to convert a
409 Texinfo document to @code{html}, you should use the additional format
410 @code{texi-html} instead of @code{texi} to convert lilypond fragments
411 to PNG images.
412
413 @item @option{--default-music-fontsize=@var{sz}pt}
414 Set the fontsize to use for LilyPond if no fontsize is given
415 as option.
416
417 @item @option{--force-music-fontsize=@var{sz}pt}
418 Force all LilyPond code to use this fontsize, overriding options
419 given to @code{\begin@{lilypond@}}.
420
421 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
422 Add @var{DIR} to the include path.
423
424 @item @option{-M}, @option{--dependencies}
425 Write dependencies to @file{filename.dep}.
426
427 @item @option{--dep-prefix=@var{pref}}
428 Prepend @var{pref} before each @option{-M} dependency.
429
430 @item @option{-n}, @option{--no-lily}
431 Do not run LilyPond, but do generate the @code{.ly} files.
432
433 @item @option{--no-music}
434 Strip all  LilyPond blocks from the file.
435
436 @item @option{--no-pictures}
437 Do not generate pictures when processing Texinfo.
438
439 @item @option{--outname=@var{file}}
440 The name of La@TeX{} file to output.  If this option is not given,
441 the output name is derived from the input name.
442
443 @item @option{--outdir=@var{dir}}
444 Place generated files in @var{dir}.
445
446 @item @option{--version}
447 Print version information.
448
449 @item @option{--help}
450 Print a short help message.
451 @end table
452
453
454 @section Bugs
455
456 The La@TeX{} @code{\includeonly@{...@}} command is ignored.
457
458 The Texinfo command @code{pagesize} is not interpreted. Almost all
459 La@TeX{} commands that change margins and line widths are ignored.
460
461 The size of a lilypond block is limited to 1.5 kb, due to technical
462 problems with Python's regular expressions. For longer files, use
463 @code{\lilypondfile}.  Using @code{\lilypondfile} also makes upgrading
464 files (through convert-ly, see @ref{Invoking convert-ly}) easier.
465
466
467 @command{lilypond-book} processes all music fragments in one big run.
468 The state of the GUILE interpreter is not reset between fragments;
469 this means that changes made to global GUILE definitions, e.g., done
470 with @code{set!} or @code{set-cdr!}, can leak from one fragment into
471 the next fragment.