]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
* scripts/lilypond-book.py (output_dict): remove support for the
[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[26pt]
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[11pt]@{<c' e' g'>@}
89 @end example
90
91 @noindent
92 produces
93
94 @lilypond[11pt]{ <c' e' g'> }
95
96 @command{lilypond-book} knows the default margins and a few paper
97 sizes.  One of these commands should be in the beginning of the document:
98
99 @itemize @bullet
100 @item @code{@@afourpaper}
101 @item @code{@@afourlatex}
102 @item @code{@@afourwide}
103 @item @code{@@smallbook}
104 @end itemize
105
106 @noindent
107 @code{@@pagesizes} are not yet supported.
108
109 When producing texinfo, lilypond-book also generates bitmaps of the
110 music, so you can make a HTML document with embedded music.
111
112
113 @c @TeX{} in node name seems to barf
114 @node Integrating LaTeX and music
115 @section Integrating LaTeX and music
116
117
118 For La@TeX{}, music is entered using
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 Running lilypond-book yields a file that can be processed with
138 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
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 produces
161
162 @lilypond[11pt]{<c' e' g'>}
163
164 The linewidth of the music will be adjust by examining the commands in
165 the document preamble, the part of the document before
166 @code{\begin@{document@}}: @command{lilypond-book} sends these to
167 La@TeX{} to find out how wide the text is. The line width variable for
168 the music fragments are adjusted to the text width.
169
170 After @code{\begin@{document@}}, the column changing commands
171 @code{\onecolumn} , @code{\twocolumn} commands and the
172 @code{multicols} environment from the multicol package are also
173 interpreted.
174
175 The titling from the @code{\header} section of the fragments can be
176 imported by adding the following to the top of the La@TeX{} file:
177
178 @example
179 \input titledefs.tex
180 \def\preLilyPondExample@{\def\mustmakelilypondtitle@{@}@}
181 @end example
182
183 The music will be surrounded by @code{\preLilyPondExample} and
184 @code{\postLilyPondExample}, which are defined to be empty by default.
185
186 @node Integrating HTML and music
187 @section Integrating HTML and music
188
189 Music is entered using
190
191 @example
192 <lilypond relative1 verbatim>
193   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
194 </lilypond>
195 @end example
196
197 @noindent
198 of which lilypond-book will produce a HTML with appropriate image tags for the
199 music fragments:
200  
201 @example
202 <lilypond relative1 verbatim>
203   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
204 </lilypond>
205 @end example
206
207 @lilypond[relative1]
208   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
209 @end lilypond
210
211 For inline pictures, use @code{<lilypond ... />} syntax, eg.
212 @example
213 Some music in <lilypond a b c/> a line of text.
214 @end example
215
216 A special feature not (yet) available in other output formats, is the
217 @code{<ly2dvifile>} tag, for example,
218 @example
219   <ly2dvifile>trip.ly</ly2dvifile>
220 @end example
221 This runs @file{trip.ly} through @code{lilypond} (see also @ref{Invoking
222 lilypond}), and substitutes a preview image in the output. The image
223 links to a separate HTML file, so clicking it will take the viewer to
224 a menu, with links to images, midi and printouts.
225
226 @cindex titling in THML
227 @cindex preview image
228 @cindex thumbnail
229
230 @node Music fragment options
231 @section Music fragment options
232
233 The commands for lilypond-book have room to specify one or more of the
234 following options:
235
236 @table @code
237 @item verbatim
238 CONTENTS is copied into the source enclosed in a verbatim block,
239 followed by any text given with the @code{intertext} option, then
240 the actual music is displayed.  This option does not work with
241 the short version of the music blocks:
242
243 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
244
245 @item smallverbatim
246 works like @code{verbatim}, but in a smaller font.
247
248 @item intertext="@var{text}"
249 is used in conjunction with @code{verbatim} option: This puts
250 @var{text} between the code and the music (without indentation).
251
252 @item filename="@var{filename}"
253 saves the LilyPond code to @var{filename}.  By default, a hash value
254 of the code is used.
255
256 @item 11pt
257 @lilypond[11pt]
258 \relative c' {
259   r16 c[ d e] f[ d e c] g'8[ c] b[\prall c] |
260   d16[ g, a b] c[ a b g] d'8[ g f\prall g]
261 }
262 @end lilypond
263
264 @item 13pt
265 @lilypond[13pt]
266 \relative c' {
267   r16 c[ d e] f[ d e c] g'8[ c] b[\prall c] |
268   d16[ g, a b] c[ a b g] d'8[ g f\prall g]
269 }
270 @end lilypond
271
272 @item 16pt
273 @lilypond[16pt]
274 \relative c' {
275   r16 c[ d e] f[ d e c] g'8[ c] b[\prall c] |
276 }
277 @end lilypond
278
279 @item 20pt
280 @lilypond[20pt]
281 \relative c' {
282   r16 c[ d e] f[ d e c] g'8[ c] b[\prall c] |
283 }
284 @end lilypond
285
286 @item 26pt
287 @lilypond[26pt]
288 \relative c' {
289   r16 c[ d e] f[ d e c] g'8[ c] b[\prall c] |
290 }
291 @end lilypond
292
293 @item raggedright
294 produces naturally spaced lines (i.e., @code{raggedright = ##t}); this
295 works well for small music fragments.
296
297 @item multiline
298 is the opposite of @code{singleline}: it justifies and breaks lines.
299
300 @item linewidth=@var{size}@var{unit}
301 sets linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
302 This option affects LilyPond output, not the text layout.
303
304 @item notime
305 prevents printing time signature.
306
307 @item fragment
308 @itemx nofragment
309 overrides @command{lilypond-book} auto detection of what type of code is
310 in the LilyPond block, voice contents or complete code.
311
312 @item indent=@var{size}@var{unit}
313 sets indentation of the first music system to @var{size},
314 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
315 not the text layout.  For single-line fragments the default is to
316 use no indentation.
317
318 @item noindent
319 sets indentation of the first music system to zero.  This option
320 affects LilyPond, not the text layout.
321
322 @item notexidoc
323 prevents including @code{texidoc}. This is only for Texinfo output.
324
325 In Texinfo, the music fragment is normally preceded by the
326 @code{texidoc} field from the @code{\header}. The LilyPond test
327 documents are composed from small @file{.ly} files in this way:
328
329 @example
330   \header @{
331     texidoc = "this file demonstrates a single note"
332   @}
333   \score @{ \notes @{ c'4 @} @} 
334 @end example
335
336 @item quote
337 instructs @command{lilypond-book} to put La@TeX{} and Texinfo output
338 into a quotation block.
339
340 @item printfilename
341 prints the file name before the music example.  Useful in conjunction
342 with @code{\lilypondfile}.
343
344 @item relative, relative @var{N}
345 uses relative octave mode.  By default, notes are specified relative
346 central C.  The optional integer argument specifies the octave of the
347 starting note, where the default @code{1} is central C.
348 @end table
349
350
351 @node Invoking lilypond-book
352 @section Invoking lilypond-book
353
354 Running @command{lilypond-book} generates lots of small files that
355 LilyPond will process.  To avoid all that garbage in the source
356 directory, it is advisable to change to a temporary directory first:
357 @example
358 cd out && lilypond-book ../yourfile.tex
359 @end example
360
361 @noindent
362 or to use the @option{--outdir} command line option, and change to
363 that director before running La@TeX{} or @file{makeinfo}:
364
365 @example
366 lilypond-book --outdir=out yourfile.tex
367 cd out  && latex yourfile.latex
368 @end example
369
370 For La@TeX{} input, the file to give to La@TeX{} has extension @file{.latex}.
371 Texinfo input will be written to a file with extension @file{.texi}.
372
373 @cindex titling and lilypond-book
374 @cindex lilypond-book and titling
375 @cindex @code{\header} in La@TeX{} documents
376
377 To add titling from the @code{\header} section of the files, add the
378 following to the top of the La@TeX{} file:
379 @example
380 \input titledefs.tex
381 \def\preLilyPondExample@{\def\mustmakelilypondtitle@{@}@}
382 @end example
383
384 @cindex outline fonts
385 @cindex type1 fonts
386 @cindex dvips
387 @cindex invoking dvips
388
389 For printing the LaTeX  document, you will need  to use dvips. For
390 producing PS  with scalable fonts, add the following options to the dvips
391 command line:
392 @example
393  -Ppdf -u +lilypond.map
394 @end example 
395
396
397
398 @command{lilypond-book} accepts the following command line options:
399
400 @table @code
401 @item @option{-f @var{format}}, @option{--format=@var{format}}
402 Specify the document type to process: @code{html}, @code{latex} or
403 @code{texi} (the default).  @command{lilypond-book} usually figures this
404 out automatically.
405
406 The @code{texi} document type produces a texinfo file with music
407 fragments in the DVI output only. For getting images in the HTML
408 version,  the format 
409 @code{texi-html} must be used.
410
411 @item @option{--default-music-fontsize=@var{sz}pt}
412 Set the music font size to use if no fontsize is given as option.
413
414 @item @option{--force-music-fontsize=@var{sz}pt}
415 Force all music to use this fontsize, overriding options given to
416 @code{\begin@{lilypond@}}.
417
418 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
419 Add @var{DIR} to the include path.
420
421 @item @option{-M}, @option{--dependencies}
422 Write dependencies to @file{filename.dep}.
423
424 @item @option{--dep-prefix=@var{pref}}
425 Prepend @var{pref} before each @option{-M} dependency.
426
427 @item @option{-n}, @option{--no-lily}
428 Generate the @code{.ly} files, but do not process them.
429
430 @item @option{--no-music}
431 Strip all music from the input file.
432
433 @item @option{--no-pictures}
434 Do not generate pictures when processing Texinfo.
435
436 @item @option{--outname=@var{file}}
437 The name of La@TeX{} file to output.  If this option is not given,
438 the output name is derived from the input name.
439
440 @item @option{--outdir=@var{dir}}
441 Place generated files in @var{dir}.
442
443 @item @option{--version}
444 Print version information.
445
446 @item @option{--help}
447 Print a short help message.
448 @end table
449
450
451
452 @section Bugs
453
454 The La@TeX{} @code{\includeonly@{...@}} command is ignored.
455
456 The Texinfo command @code{pagesize} is not interpreted. Almost all
457 La@TeX{} commands that change margins and line widths are ignored.
458
459 Only the first @code{\score} of a LilyPond block is processed.
460
461 The size of a music block is limited to 1.5 kb, due to technical
462 problems with the Python regular expression engine. For longer files,
463 use @code{\lilypondfile}.  Using @code{\lilypondfile} also makes
464 upgrading files (through convert-ly, see @ref{Invoking convert-ly})
465 easier.
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.
472