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