1 @c -*- coding: utf-8; mode: texinfo; -*-
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
6 When revising a translation, copy the HEAD committish of the
7 version that you are working on. For details, see the Contributors'
8 Guide, node Updating translation committishes..
14 @node Running lilypond
15 @chapter Running @command{lilypond}
17 This chapter details the technicalities of running LilyPond.
21 * Command-line usage::
30 Most users run LilyPond through a GUI; if you have not done so
31 already, please read the @rlearning{Tutorial}. If you use an alternate
32 editor to write lilypond files, see the documentation for that
36 @node Command-line usage
37 @section Command-line usage
39 This section contains extra information about using LilyPond on the
40 command-line. This may be desirable to pass extra options to the
41 program. In addition, there are certain extra @q{helper} programs (such
42 as @code{midi2ly}) which are only available on the command-line.
44 By @q{command-line}, we mean the command line in the operating system.
45 Windows users might be more familiar with the terms @q{DOS shell} or
46 @q{command shell}. MacOS@tie{}X users might be more familiar with the terms
47 @q{terminal} or @q{console}. Some additional setup is required
48 for MacOS@tie{}X users; please see @rweb{MacOS X}.
50 Describing how to use this part of an operating system is outside the
51 scope of this manual; please consult other documentation on this topic
52 if you are unfamiliar with the command-line.
56 * Command line options for lilypond::
57 * Environment variables::
58 * LilyPond in chroot jail::
61 @node Invoking lilypond
62 @unnumberedsubsec Invoking @command{lilypond}
64 The @command{lilypond} executable may be called as follows from
68 lilypond [@var{option}]@dots{} @var{file}@dots{}
72 When invoked with a filename that has no extension, the @file{.ly}
73 extension is tried first. To read input from stdin, use a
74 dash (@code{-}) for @var{file}.
76 When @file{filename.ly} is processed it will produce @file{filename.ps}
77 and @file{filename.pdf} as output. Several files can be specified;
78 they will each be processed independently. @footnote{The status of
79 GUILE is not reset after processing a @code{.ly} file, so be careful
80 not to change any system defaults from within Scheme.}
82 If @file{filename.ly} contains more than one @code{\book}
83 block, then the rest of the scores will be output in numbered files,
84 starting with @file{filename-1.pdf}. In addition, the value of
85 @code{output-suffix} will be inserted between the basename and the
86 number. An input file containing
89 #(define output-suffix "violin")
91 #(define output-suffix "cello")
96 will output @var{base}@file{-violin.pdf} and
97 @var{base}@file{-cello-1.pdf}.
100 @unnumberedsubsubsec Standard shell commands
102 If your shell (i.e. command window) supports normal redirects,
103 then you might find it useful to use the following commands to
104 redirect console output to a file:
109 @code{lilypond file.ly 1>stdout.log} to redirect normal output
112 @code{lilypond file.ly 2>stderr.log} to redirect error messages
115 @code{lilypond file.ly &>all.log} to redirect all output
119 Consult the documentation for your shell to see if it supports these
120 options, or if the syntax is different. Note that these are shell
121 commands and have nothing to do with lilypond.
124 @node Command line options for lilypond
125 @unnumberedsubsec Command line options for @command{lilypond}
127 @cindex Invoking @command{lilypond}
128 @cindex command line options for @command{lilypond}
129 @cindex options, command line
132 The following options are supported:
136 @item -e,--evaluate=@var{expr}
137 Evaluate the Scheme @var{expr} before parsing any @file{.ly} files.
138 Multiple @code{-e} options may be given, they will be evaluated
141 The expression will be evaluated in the @code{guile-user} module, so
142 if you want to use definitions in @var{expr}, use
145 lilypond -e '(define-public a 42)'
149 on the command-line, and include
152 #(use-modules (guile-user))
156 at the top of the @code{.ly} file.
158 @item -f,--format=@var{format}
159 which formats should be written. Choices for @code{format} are
160 @code{ps}, @code{pdf}, and @code{png}.
162 Example: @code{lilypond -fpng @var{filename}.ly}
166 @item -d,--define-default=@var{var}=@var{val}
167 This sets the internal program option @var{var} to the Scheme value
168 @var{val}. If @var{val} is not supplied, then @var{#t} is used. To
169 switch off an option, @code{no-} may be prefixed to @var{var}, e.g.
171 @cindex point and click, command line
180 -dpoint-and-click='#f'
183 Here are a few interesting options.
185 @cindex help, command line
189 Running @code{lilypond -dhelp} will print all of the @code{-d} options
192 @cindex paper-size, command line
195 This option sets the default paper-size,
197 -dpaper-size=\"letter\"
201 Note that the string must be enclosed in escaped quotes ( @code{\"} ).
202 @c Match " in previous line to help context-sensitive editors
204 @cindex safe, command line
207 Do not trust the @code{.ly} input.
209 When LilyPond formatting is available through a web server, either the
210 @code{--safe} or the @code{--jail} option @b{MUST} be passed. The
211 @code{--safe} option will prevent inline Scheme code from wreaking
218 c4^#(ly:export (ly:gulp-file "/etc/passwd"))
223 The @code{-dsafe} option works by evaluating in-line Scheme
224 expressions in a special safe module. This safe module is derived from
225 GUILE @file{safe-r5rs} module, but adds a number of functions of the
226 LilyPond API. These functions are listed in @file{scm/safe-lily.scm}.
228 In addition, safe mode disallows @code{\include} directives and
229 disables the use of backslashes in @TeX{} strings.
231 In safe mode, it is not possible to import LilyPond variables
234 @code{-dsafe} does @emph{not} detect resource overuse. It is still possible to
235 make the program hang indefinitely, for example by feeding cyclic data
236 structures into the backend. Therefore, if using LilyPond on a
237 publicly accessible webserver, the process should be limited in both
238 CPU and memory usage.
240 The safe mode will prevent many useful LilyPond snippets from being
241 compiled. The @code{--jail} is a more secure alternative, but
242 requires more work to set up.
244 @cindex output format, setting
246 the output format to use for the back-end. Choices for @code{format} are
249 @cindex PostScript output
252 Postscript files include TTF, Type1 and OTF fonts. No subsetting of
253 these fonts is done. When using oriental character sets, this can
258 @cindex Postscript, encapsulated
259 @cindex EPS (Encapsulated PostScript)
261 for encapsulated PostScript. This dumps every page (system) as a separate
262 @file{EPS} file, without fonts, and as one collated @file{EPS} file with
263 all pages (systems) including fonts.
265 This mode is used by default by @command{lilypond-book}.
269 @cindex SVG (Scalable Vector Graphics)
271 for SVG (Scalable Vector Graphics).
273 This creates a single SVG file, without embedded fonts, for every
274 page of output. It is recommended to install the Century
275 Schoolbook fonts, included with your LilyPond installation, for
276 optimal rendering. Under UNIX, simply copy these fonts from the
277 LilyPond directory (typically
278 @file{/usr/share/lilypond/VERSION/fonts/otf/}) to
279 @file{~/.fonts/}. The SVG output should be compatible with any
280 SVG editor or user agent.
286 for a dump of the raw, internal Scheme-based drawing commands.
289 do not output a printed score; has the same effect as @code{-dno-print-pages}.
292 Example: @code{lilypond -dbackend=svg @var{filename}.ly}
295 @cindex preview, command line
296 Generate an output file containing the titles and the first system
297 of music. If @code{\bookpart} blocks are used, the titles and
298 first system of every @code{\bookpart} will appear in the output.
299 The @code{ps}, @code{eps}, and @code{svg} backends support this
303 Runs silently and redirect all output to a log file.
305 Note to Windows users: By default @code{lilypond.exe} outputs all
306 progress information to the command window, @code{lilypond-windows.exe}
307 does not and returns a prompt, with no progress information, immediately
308 at the command line. The @code{-dgui} option can be used in this case
309 to redirect output to a log file.
313 Generate the full pages, the default. @code{-dno-print-pages} is
314 useful in combination with @code{-dpreview}.
321 Show a summary of usage.
323 @item -H,--header=@var{FIELD}
324 Dump a header field to file @file{BASENAME.@var{FIELD}}.
326 @cindex file searching
328 @item --include, -I=@var{directory}
329 Add @var{directory} to the search path for input files.
331 Multiple -I options may be given. The search will start in the
332 first defined directory, and if the file to be included is not
333 found the search will continue in subsequent directories.
335 @item -i,--init=@var{file}
336 Set init file to @var{file} (default: @file{init.ly}).
338 @cindex folder, directing output to
339 @cindex output filename, setting
341 @item -o,--output=@var{FILE} or @var{FOLDER}
342 Set the default output file to @var{FILE} or, if a folder with
343 that name exists, direct the output to @var{FOLDER}, taking the
344 file name from the input file. The appropriate suffix will be
345 added (e.g. @code{.pdf} for pdf) in both cases.
348 @cindex PostScript output
353 @cindex Portable Network Graphics (PNG) output
356 Generate pictures of each page, in PNG format. This implies
357 @code{--ps}. The resolution in DPI of the image may be set with
362 @cindex Portable Document Format (PDF) output
365 Generate PDF. This implies @code{--ps}.
369 @item -j,--jail=@var{user},@var{group},@var{jail},@var{dir}
370 Run @command{lilypond} in a chroot jail.
372 The @code{--jail} option provides a more flexible alternative to
373 @code{--safe} when LilyPond formatting is available through a web
374 server or whenever LilyPond executes externally provided
377 The @code{--jail} option works by changing the root of @command{lilypond} to
378 @var{jail} just before starting the actual compilation process. The user
379 and group are then changed to match those provided, and the current
380 directory is changed to @var{dir}. This setup guarantees that it is not
381 possible (at least in theory) to escape from the jail. Note that for
382 @code{--jail} to work @command{lilypond} must be run as root, which is usually
383 accomplished in a safe way using @command{sudo}.
385 Setting up a jail is a slightly delicate matter, as we must be sure that
386 LilyPond is able to find whatever it needs to compile the source
387 @emph{inside the jail}. A typical setup comprises the following items:
390 @item Setting up a separate filesystem
391 A separate filesystem should be created for LilyPond, so that it can be
392 mounted with safe options such as @code{noexec}, @code{nodev}, and
393 @code{nosuid}. In this way, it is impossible to run executables or to
394 write directly to a device from LilyPond. If you do not want to create a
395 separate partition, just create a file of reasonable size and use it to
396 mount a loop device. A separate filesystem also guarantees that LilyPond
397 cannot write more space than it is allowed.
399 @item Setting up a separate user
400 A separate user and group (say, @code{lily}/@code{lily}) with low
401 privileges should be used to run LilyPond inside the jail. There should
402 be a single directory writable by this user, which should be passed in
405 @item Preparing the jail
406 LilyPond needs to read a number of files while running. All these files
407 are to be copied into the jail, under the same path they appear in the
408 real root filesystem. The entire content of the LilyPond installation
409 (e.g., @file{/usr/share/lilypond})
412 If problems arise, the simplest way to trace them down is to run
413 LilyPond using @command{strace}, which will allow you to determine which
416 @item Running LilyPond
417 In a jail mounted with @code{noexec} it is impossible to execute any external
418 program. Therefore LilyPond must be run with a backend that does not
419 require any such program. As we already mentioned, it must be also run
420 with superuser privileges (which, of course, it will lose immediately),
421 possibly using @command{sudo}. It is a good idea to limit the number of
422 seconds of CPU time LilyPond can use (e.g., using @command{ulimit
423 -t}), and, if your operating system supports it, the amount of memory
424 that can be allocated.
429 Show version information.
432 Be verbose: show full paths of all files read, and give timing
436 Show the warranty with which GNU LilyPond comes. (It comes with
437 @strong{NO WARRANTY}!)
441 @node Environment variables
442 @unnumberedsubsec Environment variables
446 @cindex LILYPOND_DATADIR
448 @command{lilypond} recognizes the following environment variables:
450 @item LILYPOND_DATADIR
451 This specifies a directory where locale messages and
452 data files will be looked up by default. The directory should contain
453 subdirectories called @file{ly/}, @file{ps/}, @file{tex/}, etc.
456 This selects the language for the warning messages.
458 @item LILYPOND_GC_YIELD
459 A variable, as a percentage, that tunes memory management
460 behavior. A higher values means the program uses more memory, a
461 smaller value means more CPU time is used. The default value is
467 @node LilyPond in chroot jail
468 @unnumberedsubsec LilyPond in chroot jail
470 Setting up the server to run LilyPond in a chroot jail is a complicated
471 task. The steps are listed below. Examples in the steps are from
472 Ubuntu Linux, and may require the use of @code{sudo} as appropriate.
476 @item Install the necessary packages: LilyPond, GhostScript, and ImageMagick.
478 @item Create a new user by the name of @code{lily}:
485 This will create a new group for the @code{lily} user as well, and a home folder,
488 @item In the home folder of the @code{lily} user create a file to use as a
492 dd if=/dev/zero of=/home/lily/loopfile bs=1k count= 200000
496 This example creates a 200MB file for use as the jail filesystem.
498 @item Create a loop device, make a file system and mount it, then create
499 a folder that can be written by the @code{lily} user:
503 losetup /dev/loop0 /home/lily/loopfile
504 mkfs -t ext3 /dev/loop0 200000
505 mount -t ext3 /dev/loop0 /mnt/lilyloop
506 mkdir /mnt/lilyloop/lilyhome
507 chown lily /mnt/lilyloop/lilyhome
510 @item In the configuration of the servers, the JAIL will be @code{/mnt/lilyloop}
511 and the DIR will be @code{/lilyhome}.
513 @item Create a big directory tree in the jail by copying the necessary files, as
514 shown in the sample script below.
516 You can use @code{sed} to create the necessary copy commands for a given
520 for i in "/usr/local/lilypond/usr/bin/lilypond" "/bin/sh" "/usr/bin/; \
521 do ldd $i | sed 's/.*=> \/\(.*\/\)\([^(]*\).*/mkdir -p \1 \&\& \
522 cp -L \/\1\2 \1\2/' | sed 's/\t\/\(.*\/\)\(.*\) (.*)$/mkdir -p \
523 \1 \&\& cp -L \/\1\2 \1\2/' | sed '/.*=>.*/d'; done
528 @subheading Example script for 32-bit Ubuntu 8.04
536 loopdevice=/dev/loop0
537 jaildir=/mnt/lilyloop
538 # the prefix (without the leading slash!)
540 # the directory where lilypond is installed on the system
541 lilydir=/$lilyprefix/lilypond/
543 userhome=$home/$username
544 loopfile=$userhome/loopfile
546 dd if=/dev/zero of=$loopfile bs=1k count=200000
548 losetup $loopdevice $loopfile
549 mkfs -t ext3 $loopdevice 200000
550 mount -t ext3 $loopdevice $jaildir
551 mkdir $jaildir/lilyhome
552 chown $username $jaildir/lilyhome
555 mkdir -p bin usr/bin usr/share usr/lib usr/share/fonts $lilyprefix tmp
558 cp -r -L $lilydir $lilyprefix
559 cp -L /bin/sh /bin/rm bin
560 cp -L /usr/bin/convert /usr/bin/gs usr/bin
561 cp -L /usr/share/fonts/truetype usr/share/fonts
563 # Now the library copying magic
564 for i in "$lilydir/usr/bin/lilypond" "$lilydir/usr/bin/guile" "/bin/sh" \
565 "/bin/rm" "/usr/bin/gs" "/usr/bin/convert"; do ldd $i | sed 's/.*=> \
566 \/\(.*\/\)\([^(]*\).*/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/' | sed \
567 's/\t\/\(.*\/\)\(.*\) (.*)$/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/' \
568 | sed '/.*=>.*/d'; done | sh -s
570 # The shared files for ghostscript...
571 cp -L -r /usr/share/ghostscript usr/share
572 # The shared files for ImageMagick
573 cp -L -r /usr/lib/ImageMagick* usr/lib
575 ### Now, assuming that you have test.ly in /mnt/lilyloop/lilyhome,
576 ### you should be able to run:
577 ### Note that /$lilyprefix/bin/lilypond is a script, which sets the
578 ### LD_LIBRARY_PATH - this is crucial
579 /$lilyprefix/bin/lilypond -jlily,lily,/mnt/lilyloop,/lilyhome test.ly
582 @c " keep quote signs balanced for context-sensitive editors
585 @section Error messages
587 @cindex error messages
588 Different error messages can appear while compiling a file:
594 Something looks suspect. If you are requesting something out of the
595 ordinary then you will understand the message, and can ignore it.
596 However, warnings usually indicate that something is wrong with the
601 Something is definitely wrong. The current processing step (parsing,
602 interpreting, or formatting) will be finished, but the next step will
607 Something is definitely wrong, and LilyPond cannot continue. This
608 happens rarely. The most usual cause is misinstalled fonts.
611 @cindex trace, Scheme
614 Errors that occur while executing Scheme code are caught by the Scheme
615 interpreter. If running with the verbose option (@code{-V} or
616 @code{--verbose}) then a call trace of the offending
617 function call is printed.
619 @item Programming error
620 @cindex Programming error
621 There was some internal inconsistency. These error messages are
622 intended to help the programmers and debuggers. Usually, they can be
623 ignored. Sometimes, they come in such big quantities that they obscure
626 @item Aborted (core dumped)
627 @cindex Aborted (core dumped)
628 This signals a serious programming error that caused the program to
629 crash. Such errors are considered critical. If you stumble on one,
633 @cindex errors, message format
634 If warnings and errors can
635 be linked to some part of the input file, then error messages have the
639 @var{filename}:@var{lineno}:@var{columnno}: @var{message}
640 @var{offending input line}
643 A line-break is inserted in the offending line to indicate the column
644 where the error was found. For example,
647 test.ly:2:19: error: not a duration: 5
652 These locations are LilyPond's best guess about where the warning or
653 error occurred, but (by their very nature) warnings and errors occur
654 when something unexpected happens. If you can't see an error in the
655 indicated line of your input file, try checking one or two lines
656 above the indicated position.
658 More information about errors is given in @ref{Common errors}.
662 @section Common errors
664 The error conditions described below occur often, yet the cause
665 is not obvious or easily found. Once seen and understood, they
670 * Music runs off the page::
671 * An extra staff appears::
672 * Apparent error in ../ly/init.ly::
673 * Error message Unbound variable %::
674 * Error message FT_Get_Glyph_Name::
675 * Warning staff affinities should only decrease::
678 @node Music runs off the page
679 @unnumberedsubsec Music runs off the page
681 Music running off the page over the right margin or appearing
682 unduly compressed is almost always due to entering an incorrect
683 duration on a note, causing the final note in a measure to extend
684 over the bar line. It is not invalid if the final note in a
685 measure does not end on the automatically entered bar line, as the
686 note is simply assumed to carry over into the next measure. But
687 if a long sequence of such carry-over measures occurs the music
688 can appear compressed or may flow off the page because automatic
689 line breaks can be inserted only at the end of complete measures,
690 i.e., where all notes end before or at the end of the measure.
692 @warning{An incorrect duration can cause line breaks to be
693 inhibited, leading to a line of highly compressed music or
694 music which flows off the page.}
696 The incorrect duration can be found easily if bar checks are used,
697 see @ruser{Bar and bar number checks}.
699 If you actually intend to have a series of such carry-over measures
700 you will need to insert an invisible bar line where you want the
701 line to break. For details, see @ruser{Bar lines}.
704 @node An extra staff appears
705 @unnumberedsubsec An extra staff appears
707 If contexts are not created explicitly with @code{\new} or
708 @code{\context}, they will be silently created as soon as a
709 command is encountered which cannot be applied to an existing
710 context. In simple scores the automatic creation of contexts is
711 useful, and most of the examples in the LilyPond manuals take
712 advantage of this simplification. But occasionally the silent
713 creation of contexts can give rise to unexpected new staves or
714 scores. For example, it might be expected that the following code
715 would cause all note heads within the following staff to be
716 colored red, but in fact it results in two staves with the note
717 heads remaining the default black in the lower staff.
719 @lilypond[quote,verbatim,relative=2]
720 \override Staff.NoteHead #'color = #red
724 This is because a @code{Staff} context does not exist when the
725 override is processed, so one is implicitly created and the override
726 is applied to it, but then the @code{\new Staff} command creates
727 another, separate, staff into which the notes are placed. The
728 correct code to color all note heads red is
730 @lilypond[quote,verbatim,relative=2]
732 \override Staff.NoteHead #'color = #red
737 As a second example, if a @code{\relative} command is placed inside
738 a @code{\repeat} command, two staves result, the second offset from
739 the first, because the @code{\repeat} command generates two
740 @code{\relative} blocks, which each implicitly create @code{Staff}
741 and @code{Voice} blocks.
743 @lilypond[quote,verbatim]
745 \relative c' { c4 d e f }
749 Explicitly instantiating the @code{Voice} context fixes the
752 @lilypond[quote,verbatim]
755 \relative c' { c4 d e f }
761 @node Apparent error in ../ly/init.ly
762 @unnumberedsubsec Apparent error in @code{../ly/init.ly}
764 Various obscure error messages may appear about syntax errors in
765 @file{../ly/init.ly} if the input file is not correctly formed,
766 for example, if it does not contain correctly
767 matched braces or quote signs.
769 The most common error is a missing brace, (@code{@}}), at the end of
770 a @code{score} block. Here the solution is obvious: check the
771 @code{score} block is correctly terminated. The correct structure
772 of an input file is described in @rlearning{How LilyPond input files work}.
773 Using an editor which automatically highlights matching brackets and
774 braces is helpful to avoid such errors.
776 A second common cause is no white space between the last syllable
777 of a lyrics block and the terminating brace, (@code{@}}). Without
778 this separation the brace is taken to be part of the syllable. It
779 is always advisable to ensure there is white space before and after
780 @emph{every} brace. For the importance of this when using lyrics,
781 see @ruser{Entering lyrics}.
783 This error message can also appear if a terminating quote sign,
784 (@code{"}), is omitted. In this case an accompanying error message
785 @c keep "-matching straight in fancy editors
786 should give a line number close to the line in error. The
787 mismatched quote will usually be on the line one or two above.
789 @node Error message Unbound variable %
790 @unnumberedsubsec Error message Unbound variable %
792 This error message will appear at the bottom of the console
793 output or log file together with a @qq{GUILE signalled an error ...}
794 message every time a Scheme routine is called which (invalidly)
795 contains a @emph{LilyPond} rather than a @emph{Scheme} comment.
797 LilyPond comments begin with a percent sign, (@code{%}), and must
798 not be used within Scheme routines. Scheme comments begin with a
799 semi-colon, (@code{;}).
801 @node Error message FT_Get_Glyph_Name
802 @unnumberedsubsec Error message FT_Get_Glyph_Name
804 This error messages appears in the console output or log file if
805 an input file contains a non-ASCII character and was not saved in
806 UTF-8 encoding. For details, see @ruser{Text encoding}.
809 @node Warning staff affinities should only decrease
810 @unnumberedsubsec Warning staff affinities should only decrease
811 This warning can appear if there are no staves in the printed
812 output, for example if there are just a @code{ChordName} context
813 and a @code{Lyrics} context as in a lead sheet. The warning
814 messages can be avoided by making one of the contexts behave as a
818 \override VerticalAxisGroup #'staff-affinity = ##f
822 at its start. For details, see @qq{Spacing of non-staff lines} in
823 @ruser{Flexible vertical spacing within systems}.