1 @c -*- coding: utf-8; mode: texinfo; -*-
3 @chapter Running LilyPond
5 This chapter details the technicalities of running LilyPond.
11 * Updating files with convert-ly::
15 * Including LilyPond files::
18 @node Invoking lilypond
19 @section Invoking lilypond
20 @cindex Invoking LilyPond
21 @cindex command line options
22 @cindex options, command line
26 The @code{lilypond} executable may be called as follows from the command line.
29 lilypond [@var{option}]@dots{} @var{file}@dots{}
33 When invoked with a filename that has no extension, the @file{.ly}
34 extension is tried first. To read input from stdin, use a
35 dash (@code{-}) for @var{file}.
37 When @file{filename.ly} is processed it will produce
38 @file{filename.tex} as output (or @file{filename.ps} for PostScript
39 output). If @file{filename.ly} contains more than one @code{\score}
40 block, then the rest of the scores will be output in numbered files,
41 starting with @file{filename-1.tex}. Several files can be specified;
42 they will each be processed independently. @footnote{The status of
43 GUILE is not reset after processing a @code{.ly} file, so be careful
44 not to change any system defaults from within Scheme.}
47 @section Command line options
49 The following options are supported:
53 @item -e,--evaluate=@var{expr}
54 Evaluate the Scheme @var{expr} before parsing any @file{.ly} files.
55 Multiple @code{-e} options may be given, they will be evaluated
58 @item -f,--format=@var{format}
59 which formats should be written. Choices are @code{svg}, @code{ps},
60 @code{pdf}, @code{png}, @code{tex}, @code{dvi}.
62 @item -b,--backend=@var{format}
63 the output format to use for the back-end. Choices are
66 for @TeX{} output, to be processed with La@TeX{}. If present, the file
67 @file{file.textmetrics} is read to determine text extents.
69 dump text strings to @file{.texstr} file, which can be run through
70 (La)@TeX{}, resulting in a @code{.textmetrics} file, which contains the
71 extents of strings of text.
74 @cindex PostScript output
76 Postscript files include TTF, Type1 and OTF fonts. No subsetting of
77 these fonts is done. When using oriental character sets, this can
81 for encapsulated PostScript. This dumps every page (system) as a separate
82 @file{EPS} file, without fonts, and as one collated @file{EPS} file with
83 all pages (systems) including fonts.
85 This mode is used by default by lilypond-book.
88 for SVG (Scalable Vector Graphics)
89 @cindex SVG (Scalable Vector Graphics)
91 for a dump of the raw, internal Scheme-based drawing commands.
95 @cindex output format, setting
97 @item -d,--define-default=@var{var}=@var{val}
98 This sets the internal program option @var{var} to the Scheme value
99 @var{val}. If @var{val} is not supplied, then @var{#t} is used. To
100 switch off an option, @code{no-} may be prefixed to @var{var}, eg.
108 -dpoint-and-click='#f'
111 @cindex point and click
113 Setting the @code{help} option will print a summary of the options
117 Show a summary of usage.
119 @item --include, -I=@var{directory}
120 Add @var{directory} to the search path for input files.
121 @cindex file searching
124 @item -i,--init=@var{file}
125 Set init file to @var{file} (default: @file{init.ly}).
127 @item -o,--output=@var{FILE}
128 Set the default output file to @var{FILE}. The appropriate
129 suffix will be added (ie @code{.pdf} for pdf, @code{.tex}
136 Generate DVI files. In this case, the @TeX{} backend should be
137 specified, i.e., @code{-b tex}.
140 Generate pictures of each page, in PNG format. This implies
141 @code{--ps}. The resolution in DPI of the image may be set with
147 Generate PDF. This implies @code{--ps}.
150 Generate an output file containing the titles and the first system
153 Do not generate the full pages. Useful in combination with
157 Do not trust the @code{.ly} input.
159 When LilyPond formatting is available through a web server, either the
160 @code{--safe} or the @code{--jail} option @b{MUST} be passed. The
161 @code{--safe} option will prevent inline Scheme code from wreaking
164 When LilyPond formatting is available through a web server, the
165 @code{--safe} @b{MUST} be passed. This will prevent inline Scheme
166 code from wreaking havoc, for example
172 c4^#(ly:export (ly:gulp-file "/etc/passwd"))
177 The @code{--safe} option works by evaluating in-line Scheme
178 expressions in a special safe module. This safe module is derived from
179 GUILE @file{safe-r5rs} module, but adds a number of functions of the
180 LilyPond API. These functions are listed in @file{scm/@/safe@/-lily@/.scm}.
182 In addition, @code{--safe} disallows @code{\include} directives and
183 disables the use of backslashes in @TeX{} strings.
185 In @code{--safe} mode, it is not possible to import LilyPond variables
188 @code{--safe} does @emph{not} detect resource overuse. It is still
189 possible to make the program hang indefinitely, for example by feeding
190 cyclic data structures into the backend. Therefore, if using LilyPond
191 on a publicly accessible webserver, the process should be limited in
192 both CPU and memory usage.
194 Note that @code{--safe} will prevent many useful LilyPond snippets from
195 being compiled. For a softer but secure alternative you can use the
196 @code{--jail} option.
199 @item -j,--jail=@var{user},@var{group},@var{jail},@var{dir}
200 Run LilyPond in a chroot jail.
202 The @code{--jail} option provides a more flexible alternative to
203 @code{--safe} when LilyPond formatting is available through a web
204 server or whenever LilyPond executes externally provided
207 The @code{--jail} option works by changing the root of LilyPond to
208 @var{jail} just before starting the actual compilation process. The user
209 and group are then changed to match those provided, and the current
210 directory is changed to @var{dir}. This setup guarantees that it is not
211 possible (at least in theory) to escape from the jail. Note that for
212 @code{--jail} to work LilyPond must be run as root, which is usually
213 accomplished in a safe way using @command{sudo}.
215 Setting up a jail is a slightly delicate matter, as we must be sure that
216 LilyPond is able to find whatever it needs to compile the source
217 @emph{inside the jail}. A typical setup comprises the following items:
220 @item Setting up a separate filesystem
221 A separate filesystem should be created for LilyPond, so that it can be
222 mounted with safe options such as @code{noexec}, @code{nodev}, and
223 @code{nosuid}. In this way, it is impossible to run executables or to
224 write directly to a device from LilyPond. If you do not want to create a
225 separate partition, just create a file of reasonable size and use it to
226 mount a loop device. A separate filesystem also guarantees that LilyPond
227 cannot write more space than it is allowed.
229 @item Setting up a separate user
230 A separate user and group (say, @samp{lily}/@samp{lily}) with low
231 privileges should be used to run LilyPond inside the jail. There should
232 be a single directory writable by this user, which should be passed in
235 @item Preparing the jail
236 LilyPond needs to read a number of files while running. All these files
237 are to be copied into the jail, under the same path they apper in the
238 real root filesystem. The entire content of the LilyPond installation
239 (e.g., @file{/usr/share/lilypond})
242 If problems arise, the simplest way to trace them down is to run
243 LilyPond using @command{strace}, which will allow you to determine which
246 @item Running LilyPond
247 In a jail mounted with @code{noexec} it is impossible to execute any external
248 program. Therefore LilyPond must be run with a backend that does not
249 require any such program. As we already mentioned, it must be also run
250 with superuser privileges (which, of course, it will lose immediately),
251 possibly using @command{sudo}. It is a good idea to limit the number of
252 seconds of CPU time LilyPond can use (e.g., using @command{ulimit
253 -t}), and, if your operating system supports it, the amount of memory
254 that can be allocated.
259 Show version information.
262 Be verbose: show full paths of all files read, and give timing
266 Show the warranty with which GNU LilyPond comes. (It comes with
267 @strong{NO WARRANTY}!)
271 @section Environment variables
275 @cindex LILYPONDPREFIX
277 @code{Lilypond} recognizes the following environment variables:
280 This specifies a directory where locale messages and
281 data files will be looked up by default. The directory should contain
282 subdirectories called @file{ly/}, @file{ps/}, @file{tex/}, etc.
285 This selects the language for the warning messages.
287 @item LILYPOND_GC_YIELD
288 With this variable the memory footprint and performance can be
289 adjusted. It is a percentage tunes memory management behavior. With
290 higher values, the program uses more memory, with smaller values, it
291 uses more CPU time. The default value is @code{70}.
297 @section Error messages
299 @cindex error messages
300 Different error messages can appear while compiling a file:
306 Something looks suspect. If you are requesting something out of the
307 ordinary then you will understand the message, and can ignore it.
308 However, warnings usually indicate that something is wrong with the
312 Something is definitely wrong. The current processing step (parsing,
313 interpreting, or formatting) will be finished, but the next step will
319 Something is definitely wrong, and LilyPond cannot continue. This
320 happens rarely. The most usual cause is misinstalled fonts.
322 @cindex trace, Scheme
326 Errors that occur while executing Scheme code are caught by the Scheme
327 interpreter. If running with the verbose option (@code{-V} or
328 @code{--verbose}) then a call trace of the offending
329 function call is printed.
331 @cindex Programming error
332 @item Programming error
333 There was some internal inconsistency. These error messages are
334 intended to help the programmers and debuggers. Usually, they can be
335 ignored. Sometimes, they come in such big quantities that they obscure
336 other output. In this case, file a bug-report.
338 @item Aborted (core dumped)
339 This signals a serious programming error that caused the program to
340 crash. Such errors are considered critical. If you stumble on one,
346 @cindex errors, message format
347 If warnings and errors can
348 be linked to some part of the input file, then error messages have the
352 @var{filename}:@var{lineno}:@var{columnno}: @var{message}
353 @var{offending input line}
356 A line-break is inserted in the offending line to indicate the column
357 where the error was found. For example,
360 test.ly:2:19: error: not a duration: 5:
365 These locations are LilyPond's best guess about where the warning or
366 error occured, but (by their very nature) warnings and errors occur
367 when something unexpected happens. If you can't see an error in the
368 indicated line of your input file, try checking one or two lines
369 above the indicated position.
372 @node Updating files with convert-ly
373 @section Updating with @command{convert-ly}
375 @cindex Updating a LilyPond file
376 @cindex @code{convert-ly}
378 The LilyPond input syntax is routinely changed to simplify it or improve
379 it in different ways. As a side effect of this, the LilyPond interpreter
380 often is no longer compatible with older input files. To remedy this,
381 the program @command{convert-ly} can be used to deal with most of the
382 syntax changes between LilyPond versions.
384 It uses @code{\version} statements in the input files to detect the
385 old version number. In most cases, to upgrade your input file it is
386 sufficient to run@footnote{MacOS X users may execute this command
387 under the menu entry @samp{Compile > Update syntax}.}
390 convert-ly -e myfile.ly
393 If there are no changes to myfile.ly and file called myfile.ly.NEW
394 is created, then myfile.ly is already updated.
396 @command{convert-ly} always converts up to the last syntax change handled by
397 it. This means that the @code{\version} number left in the file is
398 usually lower than the version of @command{convert-ly} itself.
400 To upgrade LilyPond fragments in texinfo files, use
403 convert-ly --from=... --to=... --no-version *.itely
406 To upgrade many files at once, combine @code{convert-ly} with
407 standard unix commands. This example will upgrade all @code{.ly}
408 files in the current directory
411 for f in *.ly; do convert-ly -e $f; done;
414 In general, the program is invoked as follows:
417 convert-ly [@var{option}]@dots{} @var{file}@dots{}
421 The following options can be given:
425 Do an inline edit of the input file. Overrides @code{--output}.
427 @item -f,--from=@var{from-patchlevel}
428 Set the version to convert from. If this is not set, @command{convert-ly}
429 will guess this, on the basis of @code{\version} strings in the file.
431 @item -n,--no-version
432 Normally, @command{convert-ly} adds a @code{\version} indicator
433 to the output. Specifying this option suppresses this.
435 @item -s, --show-rules
436 Show all known conversions and exit.
438 @item --to=@var{to-patchlevel}
439 Set the goal version of the conversion. It defaults to the latest
449 Not all language changes are handled. Only one output option can be
453 @c We might want to make this a completely new section, along with more
454 @c info about how to upgrade old input files. -gp
457 Copy and paste from CVS, last updated
460 http://savannah.gnu.org/cgi-bin/viewcvs/*checkout*/lilypond/lily-bugs/bugs/convert-ly.txt?rev=HEAD&content-type=text/plain
464 There are a few things that the convert-ly cannot handle. Here's a list of limitations
465 that the community has complained about.
467 This bug report structure has been chosen because convert-ly has a structure that doesn't
468 allow to smoothly implement all needed changes. Thus this is just a wishlist, placed
472 Doesn't always convert figured bass correctly, specifically things like {< >}. Mats' comment on working around this:
473 To be able to run convert-ly
474 on it, I first replaced all occurencies of '{<' to some dummy like '{#'
475 and similarly I replaced '>}' with '&}'. After the conversion, I could
476 then change back from '{ #' to '{ <' and from '& }' to '> }'.
477 Doesn't convert all text markup correctly. In the old markup syntax,
478 it was possible to group a number of markup commands together within parentheses, e.g.
479 -#'((bold italic) "string")
480 This will incorrectly be converted into
481 -\markup{{\bold italic} "string"}
482 instead of the correct
483 -\markup{\bold \italic "string"}
485 Doesn't handle \partcombine
486 Doesn't do \addlyrics => \lyricsto, this breaks some scores with multiple stanzas.
488 \magnify isn't changed to \fontsize.
489 - \magnify #m => \fontsize #f, where f = 6ln(m)/ln(2)
490 remove-tag isn't changed.
491 - \applyMusic #(remove-tag '. . .) => \keepWithTag #'. . .
492 firstpagenumber isn't changed.
493 - firstpagenumber no => printfirstpagenumber = ##f
494 Line breaks in header strings aren't converted.
495 - \\\\ as line break in \header strings => \markup \center-align <
496 "First Line" "Second Line" >
497 Crescendo and decrescendo terminators aren't converted.
501 \turnOff (used in \set Staff.VoltaBracket = \turnOff) is not properly converted.
503 \markup{ \center-align <{ ... }> } should be converted to:
504 \markup{ \center-align {\line { ... }} }
505 but now, \line is missing.
507 Special LaTeX characters such as $~$ in text are not converted to UTF8.
513 @section Reporting bugs
516 @cindex reporting bugs
518 If you have input that results in a crash or an erroneous output, then
519 that is a bug. We try to respond to bug-reports promptly, and fix them as
520 soon as possible. Help us by sending a defective input file, so we can
521 reproduce the problem. Make it small, so we can easily debug the
522 problem. Don't forget to tell which version of LilyPond you use! Send
523 the report to @email{bug-lilypond@@gnu.org}.
526 @c the bug database is not up to date enough.
528 When you've found a bug, have a look at our
529 @uref{http://@/lilypond@/.org/@/doc/@/v2.5/@/bugs/,bug database} to see if
530 it has already been reported. You could also try to do a few searches
531 on the mailing list for the bug. Sometimes the bug will have already
532 been reported and a fix or workaround is already known.
535 Here is an example of a good bug report:
538 It seems that placement of accidentals is broken. In the
539 following example, the accidental touches the note head.
541 Using Mac OSX 10.3.7, fink package lilypond-devel
552 \override Accidental #'extra-offset = #'(1.0 . 0)
558 @section Editor support
563 @cindex modes, editor
564 @cindex syntax coloring
565 @cindex coloring, syntax
567 There is support from different editors for LilyPond.
571 Emacs has a @file{lilypond-mode}, which provides keyword
572 autocompletion, indentation, LilyPond specific parenthesis matching
573 and syntax coloring, handy compile short-cuts and reading LilyPond
574 manuals using Info. If @file{lilypond-mode} is not installed on your
575 platform, then read the
577 @uref{source/Documentation/topdocs/INSTALL.html,installation instructions}.
580 installation instructions.
585 For @uref{http://@/www@/.vim@/.org,VIM}, a @file{vimrc} is supplied, along
586 with syntax coloring tools. For more information, refer to the
588 @uref{source/Documentation/topdocs/INSTALL.html,installation instructions}.
591 installation instructions.
597 The @uref{http://@/www@/.jedit@/.org@/,jEdit} editor has a LilyPond plugin.
598 This plugin includes a DVI viewer, integrated help and viewing via
599 GhostScript. It can be installed by doing @key{Plugins > Plugin
600 Manager}, and selecting @code{LilyTool} from the @key{Install} tab.
604 All these editors can be made to jump into the input file to the source
605 of a symbol in the graphical output. See @ref{Point and click}.
609 @section File structure
611 The major part of this manual is concerned with entering various
612 forms of music in LilyPond. However, many music expressions are not
613 valid input on their own, for example, a @code{.ly} file containing
620 will result in a parsing error. Instead, music should be inside other
621 expressions, which may be put in a file by themselves. Such
622 expressions are called toplevel expressions. This section enumerates
625 A @code{.ly} file contains any number of toplevel expressions, where a
626 toplevel expression is one of the following
630 An output definition, such as @code{\paper}, @code{\midi}, and
631 @code{\layout}. Such a definition at the toplevel changes the default
632 settings for the block entered.
635 A @code{\header} block. This sets the global header block. This
636 is the block containing the definitions for book-wide settings, like
637 composer, title, etc.
640 An @code{\addquote} statement. See @ref{Quoting other voices}
641 for more information.
644 A @code{\score} block. This score will be collected with other
645 toplevel scores, and combined as a single @code{\book}.
647 This behavior can be changed by setting the variable
648 @code{toplevel-score-handler} at toplevel. The default handler is
649 defined in the init file @file{scm/@/lily@/.scm}.
651 The @code{\score} must begin with music, and may contain only
655 A @code{\book} block logically combines multiple movements
656 (i.e., multiple @code{\score} blocks) in one document. A number of
657 @code{\scores} creates a single output file, where all movement are
660 This behavior can be changed by setting the variable
661 @code{toplevel-book-handler} at toplevel. The default handler is
662 defined in the init file @file{scm/@/lily@/.scm}.
665 A compound music expression, such as
670 This will add the piece in a @code{\score} and format it in a
671 single book together with all other toplevel @code{\score}s and music
674 This behavior can be changed by setting the variable
675 @code{toplevel-music-handler} at toplevel. The default handler is
676 defined in the init file @file{scm/@/lily@/.scm}.
679 A markup text, a verse for example
682 2. The first line verse two.
686 Markup texts are rendered above, between or below the scores or music
687 expressions, wherever they appear.
690 An indentifier, such as
695 This can be used later on in the file by entering @code{\foo}. The
696 name of an identifier should have alphabetic characters only; no
697 numbers, underscores or dashes.
701 The following example shows three things that may be entered at
706 % movements are non-justified by default
718 At any point in a file, any of the following lexical instructions can
722 @item @code{\version}
723 @item @code{\include}
724 @item @code{\renameinput}
728 @node Including LilyPond files
729 @section Including LilyPond files
731 @cindex @code{\include}
732 @cindex including files
734 A large project may be split up into separate files. To refer to another
738 \include "otherfile.ly"
741 The line @code{\include "file.ly"} is equivalent to pasting the contents
742 of file.ly into the current file at the place where you have the
743 \include. For example, for a large project you might write separate files
744 for each instrument part and create a ``full score'' file which brings
745 together the individual instrument files.
747 The initialization of LilyPond is done in a number of files that are
748 included by default when you start the program, normally transparent to the
749 user. Run lilypond --verbose to see a list of paths and files that Lily
752 Files placed in directory @file{PATH/TO/share/lilypond/VERSION/ly/} (where
753 VERSION is in the form ``2.6.1'') are on the path and available to
754 @code{\include}. Files in the
755 current working directory are available to \include, but a file of the same
756 name in LilyPond's installation takes precedence. Files are
757 available to \include from directories in the search path specified as an
758 option when invoking @code{lilypond --include=DIR} which adds DIR to the search
761 The @code{\include} statement can use full path information, but with the Unix
762 convention @code{"/"} rather than the DOS/Windows @code{"\"}. For example,
763 if @file{stuff.ly} is located one directory higher than the current working
767 \include "../stuff.ly"