]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/user/lilypond-book.itely
(process_music): set
[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  Integrating text and music
16 @chapter Integrating text and music
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 introduction 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
49 @node An example of a musicological document
50 @section  An example of a musicological document
51
52 @cindex musicology
53 @cindex La@TeX{}, music in
54 @cindex HTML, music in
55 @cindex Texinfo, music in
56 Some texts contain music examples.  These texts are musicological
57 treatises, songbooks or manuals like this.  Such texts can be made by
58 hand, simply by importing a PostScript figure into the word processor.
59 However, there is an automated procedure to reduce the amount of work
60 involved HTML, La@TeX{}, and Texinfo documents.
61
62 A script called @code{lilypond-book} will extract the music fragments,
63 format them, and put back the resulting notation.  Here we show a
64 small example for use with @LaTeX{}.  The example also contains explanatory text, so we will
65 not comment on it further
66
67 @verbatim
68 \documentclass[a4paper]{article}
69 \begin{document}
70
71 Documents for lilypond-book may freely mix music and text.  For
72 example,
73
74 \begin{lilypond}
75 \relative {
76   c2 g'2 \times 2/3 { f8 e d } c'2 g4
77 }
78 \end{lilypond}
79
80 Options are put in brackets.
81
82 \begin[fragment,quote,staffsize=26,verbatim]{lilypond}
83   c'4 f16
84 \end{lilypond}
85
86 Larger examples can be put in a separate file, and introduced with
87 \verb+\lilypondfile+.
88
89 \lilypondfile[quote,noindent]{screech-boink.ly}
90
91 \end{document}
92 @end verb+
93
94 Under Unix, you can view the results as follows
95
96 @example
97 cd input/tutorial
98 mkdir -p out/
99 lilypond-book --output=out/ lilybook.tex
100 @emph{lilypond-book (GNU LilyPond) 2.3.11}
101 @emph{Reading `input/tutorial/lilybook.tex'}
102 @emph{..lots of stuff deleted..}
103 @emph{Compiling `out//lilybook.tex'
104 cd out
105 latex lilybook
106 @emph{lots of stuff deleted}
107 xdvi lilybook 
108 @end example
109
110 To convert the file into a nice PDF document, run the following
111 commands
112
113 @example
114 dvips -Ppdf -u+lilypond -u+ec-mftrace lilybook
115 ps2pdf lilybook.ps
116 @end example
117
118 Running lilypond-book and running latex creates a lot of temporary
119 files, which would clutter up the working directory.  To remedy this,
120 use the @code{--output=@var{dir}} option.  It will create the files in
121 a separate subdirectory @file{dir}.
122
123 Finally the result of the La@TeX{} example shown above.@footnote{ This
124 tutorial is processed with Texinfo, so the example is as well.  This
125 gives slightly different results in layout.}  This finishes the
126 tutorial section.
127
128 @page
129
130 Documents for lilypond-book may freely mix music and text.  For
131 example,
132
133 @lilypond
134 \relative c' {
135   c2 g'2 \times 2/3 { f8 e d } c'2 g4
136 }
137 @end lilypond
138
139 Options are put in brackets.
140
141 @lilypond[fragment,quote,staffsize=26,verbatim]
142 c'4 f16
143 @end lilypond
144
145 Larger examples can be put in a separate file, and introduced with
146 @code{\lilypondfile}.
147
148 @lilypondfile[quote,noindent]{screech-boink.ly}
149
150
151 @cindex texinfo
152 @cindex latex
153 @cindex texinfo
154 @cindex @code{texi}
155 @cindex html
156 @cindex documents, adding music to
157
158
159 @node Integrating Texinfo and music
160 @section Integrating Texinfo and music
161
162 Music is specified like this:
163
164 @example
165 @@lilypond[options,go,here]
166   YOUR LILYPOND CODE
167 @@end lilypond
168 @@lilypond[options,go,here]@{ YOUR LILYPOND CODE @}
169 @@lilypondfile[options,go,here]@{@var{filename}@}
170 @end example
171
172 When lilypond-book is run on it, this results in a texinfo file. We
173 show two simple examples here.  First a complete block:
174
175 @example
176 @@lilypond[staffsize=26]
177   c' d' e' f' g'2 g'
178 @@end lilypond
179 @end example
180
181 @noindent
182 produces
183
184 @lilypond[fragment]
185   c' d' e' f' g'2 g'
186 @end lilypond
187
188 Then the short version:
189
190 @example
191 @@lilypond[staffsize=11]@{<c' e' g'>@}
192 @end example
193
194 @noindent
195 produces
196
197 @lilypond[fragment,staffsize=11]{ <c' e' g'> }
198
199 When producing texinfo, lilypond-book also generates bitmaps of the
200 music, so you can make a HTML document with embedded music.
201
202 @c @TeX{} in node name seems to barf
203 @node Integrating LaTeX and music
204 @section Integrating LaTeX and music
205
206
207 For La@TeX{}, music is entered using
208
209 @example
210 \begin[options,go,here]@{lilypond@}
211   YOUR LILYPOND CODE
212 \end@{lilypond@}
213 @end example
214
215 @example
216 \lilypondfile[options,go,here]@{@var{filename}@}
217 @end example
218
219 @noindent
220 or
221
222 @example
223 \lilypond@{ YOUR LILYPOND CODE @}
224 @end example
225
226 Running lilypond-book yields a file that can be processed with
227 La@TeX{}.
228
229
230 We show some examples here:
231
232 @example
233 \begin[staffsize=26]@{lilypond@}
234   c' d' e' f' g'2 g'2
235 \end@{lilypond@}
236 @end example
237
238 @noindent
239 produces
240
241 @lilypond[fragment,staffsize=26]
242   c' d' e' f' g'2 g'2
243 @end lilypond
244
245 Then the short version:
246
247 @example
248 \lilypond[staffsize=11]@{<c' e' g'>@}
249 @end example
250
251 @noindent
252 produces
253
254 @lilypond[fragment,staffsize=11]{<c' e' g'>}
255
256 The linewidth of the music will be adjust by examining the commands in
257 the document preamble, the part of the document before
258 @code{\begin@{document@}}: @command{lilypond-book} sends these to
259 La@TeX{} to find out how wide the text is. The line width variable for
260 the music fragments are adjusted to the text width.
261
262 After @code{\begin@{document@}}, the column changing commands
263 @code{\onecolumn}, @code{\twocolumn} commands
264 @ignore 
265 and the
266 @code{multicols} environment from the multicol package
267 @end ignore
268 are also interpreted.
269
270 @cindex titling and lilypond-book
271 @cindex @code{\header} in La@TeX{} documents
272
273
274 The music will be surrounded by @code{\preLilyPondExample} and
275 @code{\postLilyPondExample}, which are defined to be empty by default.
276
277 @cindex outline fonts
278 @cindex type1 fonts
279 @cindex dvips
280 @cindex invoking dvips
281
282 For printing the LaTeX document, you will need to use dvips. For
283 producing PostScript with scalable fonts, add the following options to
284 the dvips command line:
285 @example
286  -Ppdf -u+lilypond.map -u+ec-mftrace.map
287 @end example 
288
289 @noindent
290 PDF can then be produced with @code{ps2pdf}.
291
292 @cindex international characters
293 @cindex latin1
294
295 LilyPond does not use the LaTeX font handling scheme for lyrics and text
296 markups, so if you use characters in your lilypond-book
297 documents that are not included in the standard US-ASCII character set,
298 include @code{\usepackage[latin1]@{inputenc@}} in the file 
299 header but do not include @code{\usepackage[[T1]@{fontenc@}}. Character
300 sets other than latin1 are not supported directly but may be handled by
301 explicitly specifying the @code{font-name} property in LilyPond and
302 using the corresponding LaTeX packages. Please consult the mailing list
303 for more details.
304
305
306
307
308
309 @node Integrating HTML and music
310 @section Integrating HTML and music
311
312 Music is entered using
313
314 @example
315 <lilypond relative=1 verbatim>
316   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
317 </lilypond>
318 @end example
319
320 @noindent
321 of which lilypond-book will produce a HTML with appropriate image tags for the
322 music fragments:
323  
324 @example
325 <lilypond relative=2 verbatim>
326   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
327 </lilypond>
328 @end example
329
330 @lilypond[fragment,relative=2]
331   \key c \minor r8 c16 b c8 g as c16 b c8 d | g,4
332 @end lilypond
333
334 For inline pictures, use @code{<lilypond ... />} syntax, e.g.
335 @example
336 Some music in <lilypond a b c/> a line of text.
337 @end example
338
339 A special feature not (yet) available in other output formats, is the
340 @code{<lilypondfile>} tag, for example,
341 @example
342   <lilypondfile>trip.ly</lilypondfile>
343 @end example
344 This runs @file{trip.ly} through @code{lilypond} (see also
345 @ref{Invoking lilypond}), and substitutes a preview image in the
346 output. The image links to a separate HTML file, so clicking it will
347 take the viewer to a menu, with links to images, midi and printouts.
348
349 @cindex titling in THML
350 @cindex preview image
351 @cindex thumbnail
352
353 @node Music fragment options
354 @section Music fragment options
355
356 The commands for lilypond-book have room to specify one or more of the
357 following options:
358
359 @table @code
360 @item verbatim
361 @var{contents} is copied into the source, enclosed in a verbatim block;
362 followed by any text given with the @code{intertext} option; then
363 the actual music is displayed.  This option does not work with
364 the short version of the music blocks:
365
366 @code{ @@lilypond@{ CONTENTS @} } and @code{ \lilypond@{ CONTENTS @} }
367
368 @item filename=@var{filename}
369 This names the file for the @code{printfilename} option. The argument
370 should be unquoted.
371
372 @item staffsize=@var{ht}
373 Sets the staff height to @var{ht}, which is measured in points.
374
375 @item raggedright
376 produces naturally spaced lines (i.e., @code{raggedright = ##t}); this
377 works well for small music fragments.
378
379 @item linewidth=@var{size}\@var{unit}
380 sets linewidth to @var{size}, where @var{unit} = cm, mm, in, or pt.
381 This option affects LilyPond output, not the text layout.
382
383 @item notime
384 prevents printing time signature.
385
386 @item fragment
387 @item nofragment
388 overrides @command{lilypond-book} auto detection of what type of code is
389 in the LilyPond block, voice contents, or complete code.
390
391 @item indent=@var{size}\@var{unit}
392 sets indentation of the first music system to @var{size},
393 where @var{unit} = cm, mm, in, or pt.  This option affects LilyPond,
394 not the text layout.  For single-line fragments, the default is to
395 use no indentation.
396
397 For example
398 @example
399   \begin[indent=5\cm,raggedright]@{lilypond@}
400   ...
401   \end@{lilypond@}
402 @end example
403
404
405 @item noindent
406 sets indentation of the first music system to zero.  This option
407 affects LilyPond, not the text layout.
408
409 @item quote
410 sets linewidth to the width of a quotation and puts the output
411 in a quotation block.
412
413 @item texidoc
414 Includes the @code{texidoc} field, if defined in the file. This is
415 only for Texinfo output.
416
417 In Texinfo, the music fragment is normally preceded by the
418 @code{texidoc} field from the @code{\header}. The LilyPond test
419 documents are composed from small @file{.ly} files in this way:
420
421 @example
422   \header @{
423     texidoc = "this file demonstrates a single note"
424   @}
425   @{ c'4 @}
426 @end example
427
428 @item relative, relative=@var{N}
429 uses relative octave mode.  By default, notes are specified relative
430 to middle C.  The optional integer argument specifies the octave of the
431 @item relative, relative=@var{N}
432 uses relative octave mode.  By default, notes are specified relative
433 to middle C.  The optional integer argument specifies the octave of the
434 starting note, where the default @code{1} is middle C.
435 @end table
436
437
438 @node Invoking lilypond-book
439 @section Invoking lilypond-book
440
441
442 Running @command{lilypond-book} generates lots of small files that
443 LilyPond will process.  To avoid all that garbage in the source
444 directory use the @option{--output} command line option, and change to
445 that directory before running La@TeX{} or @file{makeinfo}:
446
447 @example
448 lilypond-book --output=out yourfile.lytex
449 cd out && latex yourfile.tex
450 @end example
451
452
453 @command{lilypond-book} accepts the following command line options:
454
455 @table @code
456 @item @option{-f @var{format}}, @option{--format=@var{format}}
457 Specify the document type to process: @code{html}, @code{latex} or
458 @code{texi} (the default).  @command{lilypond-book}  figures this
459 out automatically.
460
461 The @code{texi} document type produces a texinfo file with music
462 fragments in the DVI output only. For getting images in the HTML
463 version,  the format 
464 @code{texi-html} must be used.
465
466 @item @option{-F @var{filter}}, @option{--filter=@var{filter}}
467 Pipe snippets through @var{filter}.
468
469 For example:
470 @example
471     lilypond-book --filter='convert-ly --from=2.0.0' my-book.tely
472 @end example
473
474 @item @option{--help}
475 Print a short help message.
476
477 @item @option{-I @var{dir}}, @option{--include=@var{dir}}
478 Add @var{DIR} to the include path.
479
480 @item @option{-o @var{dir}}, @option{--output=@var{dir}}
481 Place generated files in @var{dir}.
482
483 @item @option{-P @var{process}}, @option{--process=@var{COMMAND}}
484 Process lilypond snippets using @var{command}.  The default command is
485 @code{lilypond}.
486
487 @item @option{--verbose}
488 Be verbose.
489
490 @item @option{--version}
491 Print version information.
492 @end table
493
494 For La@TeX{} input, the file to give to La@TeX{} has extension
495 @file{.latex}.  Texinfo input will be written to a file with extension
496 @file{.texi}.
497
498
499
500 @section Bugs
501
502 The La@TeX{} @code{\includeonly@{...@}} command is ignored.
503
504 The Texinfo command @code{pagesize} is not interpreted. Almost all
505 La@TeX{} commands that change margins and line widths are ignored.
506
507 Only the first @code{\score} of a LilyPond block is processed.
508
509 @c CHECKME--FIXME
510 The size of a music block is limited to 1.5 KB, due to technical
511 problems with the Python regular expression engine.  For longer files,
512 use @code{\lilypondfile}.
513