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