@c -*- coding: utf-8; mode: texinfo; -*-

@ignore
    Translation of GIT committish: FILL-IN-HEAD-COMMITTISH

    When revising a translation, copy the HEAD committish of the
    version that you are working on.  For details, see the Contributors'
    Guide, node Updating translation committishes..
@end ignore

@c \version "2.17.6"


@node Running lilypond
@chapter Running @command{lilypond}

This chapter details the technicalities of running LilyPond.

@menu
* Normal usage::
* Command-line usage::
* Error messages::
* Common errors::
@end menu


@node Normal usage
@section Normal usage

Most users run LilyPond through a GUI; if you have not done so
already, please read the @rlearning{Tutorial}.  If you use an alternate
editor to write LilyPond files, see the documentation for that
program.


@node Command-line usage
@section Command-line usage

This section contains extra information about using LilyPond on the
command-line.  This may be desirable to pass extra options to the
program.  In addition, there are certain extra @q{helper} programs (such
as @code{midi2ly}) which are only available on the command-line.

By @q{command-line}, we mean the command line in the operating system.
Windows users might be more familiar with the terms @q{DOS shell} or
@q{command shell}.  MacOS@tie{}X users might be more familiar with the terms
@q{terminal} or @q{console}.

Describing how to use this part of an operating system is outside the
scope of this manual; please consult other documentation on this topic
if you are unfamiliar with the command-line.

@menu
* Invoking LilyPond::
* Basic command line options for LilyPond::
* Advanced command line options for LilyPond::
* Environment variables::
* Relocation::
* LilyPond in chroot jail::
@end menu

@node Invoking LilyPond
@unnumberedsubsec Invoking @command{lilypond}

The @command{lilypond} executable may be called as follows from
the command line.

@example
lilypond [@var{option}]@dots{} @var{file}@dots{}
@end example

When invoked with a filename that has no extension, the @file{.ly}
extension is tried first.  To read input from stdin, use a
dash (@code{-}) for @var{file}.

@warning{On Windows prior to Windows 10 1903, LilyPond cannot handle Unicode
file names.}

When @file{filename.ly} is processed it produces
@file{filename.pdf} as output by default.  Several files can be specified;
they are each processed independently.@footnote{The status of
GUILE is not reset after processing a @file{.ly} file, so be careful
not to change any system defaults from within Scheme.}

If @file{filename.ly} contains more than one @code{\book}
block, the rest of the scores is output in numbered files,
starting with @file{filename-1.pdf}.  In addition, the value of
@code{output-suffix} is inserted between the basename and the
number.  For example, if @file{filename.ly} contains

@example
#(define output-suffix "violin")
\score @{ @dots{} @}
#(define output-suffix "cello")
\score @{ @dots{} @}
@end example

@noindent
LilyPond outputs @file{filename-violin.pdf} and
@file{filename-cello-1.pdf}.


@unnumberedsubsubsec Using LilyPond with standard shell features

Since LilyPond is a command line application, features of the @q{shell}
used for calling LilyPond can also be put to good use.

For example,

@example
lilypond *.ly
@end example

@noindent
processes all LilyPond files in the current directory.

Redirecting the console output (e.g., to a file) may also be useful:

@example
lilypond file.ly 1> stdout.txt
lilypond file.ly 2> stderr.txt
lilypond file.ly &> all.txt
@end example

@noindent
The above commands divert @q{normal} output, @q{errors} only, or @q{everything},
respectively, to text files.  Consult the documentation for your
particular shell, Command (Windows), Terminal or Console
applications (MacOS X) to check whether output redirection is supported or if
the syntax is different.

The following example searches and processes all input files in the
current directory and all directories below it recursively.  The output
files are located in the same directory that the command was run in,
rather than in the same directories as the original input files.

@example
find . -name '*.ly' -exec lilypond '@{@}' \;
@end example

@noindent
This should also work for MacOS@tie{}X users.

A Windows user would run

@example
forfiles /s /M *.ly /c "cmd /c lilypond @@file"
@end example

@noindent
entering these commands in a @code{command prompt} usually found under
@code{Start > Accessories > Command Prompt}, or
by typing in the search window @q{command prompt}.

Alternatively, an explicit path to the top-level of your folder
containing all the sub-folders that have input files in them can be
stated using the @code{/p} option;

@example
forfiles /s /p C:\Documents\MyScores /M *.ly /c "cmd /c lilypond @@file"
@end example

If there are spaces in the path to the top-level folder, then the whole
path needs to be inside double quotes;

@example
forfiles /s /p "C:\Documents\My Scores" /M *.ly /c "cmd /c lilypond @@file"
@end example


@node Basic command line options for LilyPond
@unnumberedsubsec Basic command line options for LilyPond

@cindex Invoking @command{lilypond}
@cindex command line options for @command{lilypond}
@cindex options, command line
@cindex switches

The following options are supported.

@table @asis

@item @code{-d}, @code{--define-default=}@var{var}[@code{=}@var{val}]
See @ref{Advanced command line options for LilyPond}.

@cindex Scheme, expression evaluation
@cindex expression evaluation, Scheme

@item @code{-e}, @code{--evaluate=}@var{expr}
Evaluate the Scheme @var{expr} before parsing any @file{.ly} files.
Multiple @option{-e} options may be given, they are evaluated
sequentially.

The expression is evaluated in the @code{guile-user} module, so
if you want to use a definition like @code{(define-public a 42)} as
@var{expr}, use

@example
lilypond -e '(define-public a 42)'
@end example

@noindent
on the command-line, and include

@example
#(use-modules (guile-user))
@end example

@noindent
at the top of the @file{.ly} file.

@warning{Windows users must use double quotes instead of single quotes.}

@item @code{-E}, @code{--eps}
Generate EPS files.

This option is equivalent to specifying
@code{-dseparate-page-formats=eps -dtall-page-formats=eps}.

@cindex output, format
@cindex format, output

@item @code{-f}, @code{--format=}@var{format}
The format of the (main) output file or files.  Possible values for
@var{format} are @code{ps}, @code{pdf}, @code{png} or @code{svg}.

Example: @code{lilypond -fpng foo.ly}

SVG internally uses a specific backend, and therefore cannot be
obtained in the same run as other formats; using @w{@code{-fsvg}} or
@code{--svg} is actually equivalent to using the
@code{-dbackend=svg} option.
See @ref{Advanced command line options for LilyPond}.

@item @code{-h}, @code{--help}
Show a summary of usage.

@item @code{-H}, @code{--header=}@var{field}
Dump a header field to file @file{BASENAME.@var{field}}.

As an example, let's assume that you have an input file @file{foo.ly}
containing

@example
\header @{ title = "bar" @}
\score @{ c1 @}
@end example

@noindent
The command

@example
lilypond -H title foo.ly
@end example

@noindent
then creates a plain text file @file{foo.title} containing the string
@code{bar}.

@item @code{-i}, @code{--init=}@var{file}
Set init file to @var{file} (default: @file{init.ly}).

@cindex file searching
@cindex search path

@item @code{-I}, @code{--include=}@var{directory}
Append @var{directory} to the search path for input files with
relative paths.  By default, only the current working directory gets
searched.

Multiple @option{-I} options may be given.  The search starts in
the current working directory, and if the file to be included is not
found the search continues in the directory given by the first
@option{-I} option, then the directory in the second @option{-I}
option, and so on.

@warning{Using the tilde character (@code{~}) with the @option{-I}
switch may produce unexpected results in some shells.

Windows users need to include a trailing slash for the directory's
path.}

@cindex chroot jail, running inside

@item @code{-j}, @code{--jail=}@var{user}@code{,}@var{group}@code{,}@var{jail}@code{,}@var{dir}
[This option is only available if your operating system supports the
@code{chroot} functionality.  In particular, Windows doesn't support it.]

Run @command{lilypond} in a chroot jail.

The @option{--jail} option can be used for security when LilyPond
formatting is being provided via a web server, or whenever LilyPond executes
commands sent by external sources (see @ref{Advanced command
line options for LilyPond}).  Because LilyPond provides the ability
to run Guile programs, it is essential in such scenarios to run it
in a sandboxed way so that the file being compiled does not wreak
havoc on the system, for example with

@example
% too dangerous to write correctly
#(s ystem "rm -rf /")
% malicious but not destructive
@{ c4^$(ly:gulp-file "/etc/passwd") @}
@end example

@option{--jail} is one way to achieve sandboxing.  Another one is
running LilyPond in a Docker container.

The @option{--jail} option works by changing the root of @command{lilypond}
to @var{jail} just before starting the actual compilation process.
The user and group are then changed to match those provided, and the
current directory is changed to @var{dir}.  This setup guarantees that
it is not possible (at least in theory) to escape from the jail.
Note that for @option{--jail} to work, @command{lilypond} must be run
as root, which is usually accomplished in a safe way using @command{sudo}.

Setting up a jail can be a relatively complex matter, as we must be sure
that LilyPond is able to find whatever it needs to compile the source
@emph{inside} the jail itself.  A typical chroot jail comprises the
following steps:

@table @asis

@item Setting up a separate filesystem
A separate filesystem should be created for LilyPond, so that it can be
mounted with safe options such as @code{noexec}, @code{nodev}, and
@code{nosuid}.  In this way, it is impossible to run executables or to
write directly to a device from LilyPond.  If you do not want to create a
separate partition, just create a file of reasonable size and use it to
mount a loop device.  A separate filesystem also guarantees that LilyPond
cannot write more space than it is allowed.

@item Setting up a separate user
A separate user and group (say, @code{lily}/@code{lily}) with low
privileges should be used to run LilyPond inside the jail.  There should
be a single directory writable by this user, which should be passed in
@var{dir}.

@item Preparing the jail
LilyPond needs to read a number of files while running.  All these files
are to be copied into the jail, under the same path they appear in the
real root filesystem.  The entire content of the LilyPond installation
(e.g., @file{/usr/share/lilypond}) should be copied.

If problems arise, the simplest way to trace them down is to run
LilyPond using @command{strace}, which allows you to determine which
files are missing.

@item Running LilyPond
In a jail mounted with @code{noexec} it is impossible to execute any
external program.  Therefore LilyPond must be run with a backend that
does not require any such program.  As we have already mentioned, it
must be run with superuser privileges (which, of course, it loses
immediately), possibly using @command{sudo}.  It is also good practice
to limit the number of seconds of CPU time LilyPond can use (e.g., using
@command{ulimit@tie{}-t}), and, if your operating system supports it,
the amount of memory that can be allocated.  Also see
@ref{LilyPond in chroot jail}.
@end table

@cindex loglevel
@cindex output, verbosity

@item @code{-l}, @code{--loglevel=}@var{level}
Set the verbosity of the console output to @var{level}.  Possible values
are:

@table @code

@item NONE
No output at all, not even error messages.

@item ERROR
Only error messages, no warnings or progress messages.

@item WARN
Warnings and error messages, no progress.

@item BASIC_PROGRESS
Basic progress messages (success), warnings and errors.

@item PROGRESS
All progress messages, warnings and errors.

@item INFO
Progress messages, warnings, errors and further execution information.
This is the default.

@item DEBUG
All possible messages, including verbose debug output.

@end table

@cindex directory, redirect output
@cindex output, setting filename
@cindex output, directory

@item @code{-o}, @code{--output=}@var{file}
@itemx @code{-o}, @code{--output=}@var{folder}
Set the default output file to @var{file} or, if a folder with that name
exists, direct the output to @var{folder}, taking the file name from the
input file.  The appropriate suffix is added (e.g., @file{.pdf} for
PDF) in both cases.

@item @code{-O}, @code{--pspdfopt=}@var{key}
@cindex pspdfopt

Set the PS/PDF output optimization to @var{key}.  Possible values are:

@table @code

@item size
Generate a very small PS/EPS/PDF document.  This is the default.

Using this value is equivalent to setting LilyPond's Scheme command
line options @code{-dmusic-@/font-@/encodings=@/'#f'} and
@code{-dgs-@/never-@/embed-@/fonts=@/'#f'}.

@item TeX
Produce files that are optimized for inclusion in pdf@TeX{}, Lua@TeX{}, or
Xe@TeX{} documents.

Using this value is equivalent to setting LilyPond's Scheme command
line options @code{-dmusic-@/font-@/encodings=@/'#t'} and
@code{-dgs-@/never-@/embed-@/fonts=@/'#f'}.

@item TeX-GS
If you want to include more than one PDF generated by LilyPond in a
TeX document, use this option and postprocess the PDF generated by
TeX with Ghostscript.

Using this value is equivalent to setting LilyPond's Scheme command
line options @code{-dmusic-@/font-@/encodings=@/'#t'} and
@code{-dgs-@/never-@/embed-@/fonts=@/'#t'}.

@end table

@cindex PS (PostScript), output
@cindex PostScript (PS), output
@cindex output, PS (PostScript)

@item @code{--ps}
Generate PostScript.  This option is equivalent to @code{-fps}.

@cindex PNG (Portable Network Graphics), output
@cindex output, PNG (Portable Network Graphics)

@item @code{--png}
Generate pictures of each page, in PNG format.  This option is
equivalent to @w{@code{-fpng}}.

The resolution of the image may be set to @var{N}@tie{}DPI with
@example
-dresolution=@var{N}
@end example

@cindex PDF (Portable Document Format), output
@cindex output, PDF (Portable Document Format)

@item @code{--pdf}
Generate PDF.  This is the default, being equivalent to @w{@code{-fpdf}}.

@item @code{-s}, @code{--silent}
Show no progress, only error messages.  This is equivalent to
@code{-lERROR}.

@cindex SVG (Scalable Vector Graphics), output
@cindex output, SVG (Scalable Vector Graphics)
@cindex HTML, embeddable SVG scores
@cindex web pages, SVG scores embeddable

@item @code{--svg}
Generate SVG files for each page.  This option is equivalent to @w{@code{-fsvg}}.

@item @code{-v}, @code{--version}
Show version information.

@item @code{-V}, @code{--verbose}
Be verbose: show full paths of all files read, give timing
information, etc.  It is equivalent to @code{-lDEBUG}.

@item @code{-w}, @code{--warranty}
Show the warranty with which GNU LilyPond comes.  (It comes with
@strong{NO WARRANTY}!)

@end table


@node Advanced command line options for LilyPond
@unnumberedsubsec Advanced command line options for LilyPond

Option @option{-d} is the command-line interface to LilyPond's Scheme
function @code{ly:set-option}.  This means that all options listed
here can also be set within @file{.ly} files.

@table @asis

@item @code{-d}, @code{--define-default=}@var{option-name}[@code{=}@var{value}]
@itemx @code{-d}, @code{--define-default=no-}@var{option-name}
Set the equivalent internal Scheme symbol @var{option-name} to
@var{value}.  For example, the command-line option

@example
-dbackend=svg
@end example

@noindent
is equivalent to

@example
#(ly:set-option 'backend 'svg)
@end example

@noindent
in a LilyPond input file.

If @var{value} is not supplied, use @code{#t} as the value (which might
produce strange results if the expected @var{value} type is not boolean).
The prefix @code{no-} may be added to @var{option-name} to switch @q{off} an
option, providing @code{#f} as the value.  For example,

@cindex point and click, command line

@example
-dpoint-and-click='#f'
@end example

@noindent
is the same as
@example
-dno-point-and-click
@end example
@end table

[Note that the @samp{#} character introduces a comment in many shells.
For this reason it is recommended to always quote expressions that
contain it.]

The following table lists all supported option names together with
its values.  Within Scheme code, option values can be read using
function @code{ly:get-option}.

@table @asis

@item @code{anti-alias-factor} @var{num}
Render at a higher resolution (using factor @var{num}, which must
be a positive integer @leq{}8) and scale down the result to
prevent @q{jaggies} in PNG images.  Default: @code{1}.

@item @code{aux-files} @var{bool}
If @var{bool} is @code{#t}, create @file{.tex}, @file{.texi}, and
@file{.count} files.  This option is mostly for use by
@command{lilypond-book}.  Default: @code{#f}.

@item @code{backend} @var{symbol}
Use @var{symbol} as the backend for LilyPond output.  Possible values
are:

@table @code

@item ps
This is the default setting.  PostScript files include
TTF, Type1, and OTF fonts.  No @q{subsetting} of
these fonts is done.  Be aware that using @q{oriental} character sets
like Japanese can lead to very large file sizes.

For PDF output, the @code{ps} backend is used, too; the resulting
PS data is post-processed by Ghostscript's @code{ps2pdf} script,
which also does font subsetting by default.

@item cairo
This creates graphics output throught the Cairo library, if
support was compiled in. This backend can output @code{ps},
@code{eps}, @code{pdf}, @code{png} and @code{svg}.

@item svg
Scalable Vector Graphics.
A single SVG file is created for every page of output.  Music glyphs
are encoded as vector graphics, but text fonts are @emph{not} embedded
in the SVG files.  Any SVG viewer will therefore need the relevant text
fonts to be available to it for proper rendering of both text and
lyrics.  It is recommended to not use font @q{lists} or @q{aliases}
in case an SVG viewer is unable to handle them.  When using
@emph{Web Open Font Format} (WOFF) files the additional
@code{-dsvg-woff} switch is required.

@end table

@item @code{clip-systems} @var{bool}
If @var{bool} is @code{#t}, extract music fragments out of a score.
This requires that the @code{clip-regions} function has been defined
within the @code{\layout} block.  See @ruser{Extracting fragments of
music}.  No fragments are extracted though if used with the
@option{-dno-print-pages} option.  Default: @code{#f}.

@item @code{compile-scheme-code} @var{bool}
Use the Guile compiler to run Scheme code, instead of the evaluator.
For more information, see @rextend{Debugging Scheme code}.

@item @code{crop} @var{bool}

If @var{bool} is @code{#t}, a second PDF file gets created (with
extension @file{.cropped.pdf}), together with a rendered image of it
(with extension @file{.cropped.png}).  This output file fits all the
music and headers, without margins, into a single, possibly tall page.
If option @option{--svg} is set, an additional SVG file (with extension
@file{.cropped.svg}) is produced instead.  If option @option{--eps} or
@option{--ps} is set, a cropped EPS file (with extension
@file{.cropped.eps}) is produced instead of a cropped PDF.  Default:
@code{#f}.

Note that currently this option is not well suited for multi-system
output since vertical space between systems gets removed.

@item @code{datadir}
Prefix for data files.  This is a read-only option; setting it has no
effect.

@item @code{debug-eval} @var{bool}
If @var{bool} is @code{#t}, use the debugging Scheme evaluator,
which prints backtraces with line numbers on errors.
Default: @code{#f}, or @code{#t} when using @code{--verbose}.

@item @code{debug-skylines} @var{bool}
If @var{bool} is @code{#t}, debug skylines.
Default: @code{#f}.

@item @code{delete-intermediate-files} @var{bool}
If @var{bool} is @code{#t}, delete the unusable, intermediate
@file{.ps} files created during
compilation.
Default: @code{#t}.

@item @code{embed-source-code} @var{bool}
If @var{bool} is @code{#t}, embed the LilyPond source files inside
the generated PDF document.
Default: @code{#f}.

@item @code{eps-box-padding} @var{num}
Pad left edge of the output EPS bounding box by @var{num} millimeters.
Default: @code{#f} (meaning no bounding box padding).

@item @code{font-export-dir} @var{string}
Set directory for exporting fonts as PostScript files to @var{string}.
This is useful when you want to create a PDF without embedded fonts first
and later embed the fonts with Ghostscript as shown below.

@example
$ lilypond -dfont-export-dir=fontdir -dgs-never-embed-fonts foo.ly
$ gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \
     -sOutputFile=foo.embedded.pdf foo.pdf fontdir/*.font.ps
@end example

@noindent
Note: Unlike @code{font-ps-resdir},
this method cannot embed CID fonts with Ghostscript 9.26 and later.

@noindent
Note: Same as @code{font-ps-resdir}, this option skips TrueType fonts
because embedding TrueType fonts later causes garbled characters.
To avoid garbling characters, use
@code{gs-never-embed-fonts}, as this embeds TrueType fonts
despite its name.

@noindent
Default: @code{#f} (meaning not to export).

@item @code{font-ps-resdir} @var{string}
Set directory (as @var{string}) to build a subset of the PostScript resource
directory to be used for embedding fonts later.
This is useful when you want to create a PDF without embedded fonts first
and later embed the fonts with Ghostscript as shown below.

@example
$ lilypond -dfont-ps-resdir=resdir -dgs-never-embed-fonts foo.ly
$ gs -q -dBATCH -dNOPAUSE -sDEVICE=pdfwrite \
     -I resdir -I resdir/Font \
     -sOutputFile=foo.embedded.pdf foo.pdf
@end example

@noindent
Note: It is better not to specify the directory
that contains the name @file{Resource} because it has a special meaning
when specified with the @code{-I} option for Ghostscript.

@noindent
Note: Unlike @code{font-export-dir},
this method can embed CID fonts with Ghostscript 9.26 and later.

@noindent
Note: Same as @code{font-export-dir}, this option skips TrueType fonts
because embedding TrueType fonts later causes garbled characters.
To avoid garbling characters, use
@code{gs-never-embed-fonts}, as this embeds TrueType fonts
despite its name.

@noindent
Default: @code{#f} (meaning not to build).

@item @code{gs-load-fonts} @var{bool}
If @var{bool} is @code{#t}, load fonts via Ghostscript.  This option
makes LilyPond's output files contain only references to all fonts,
which must be resolved to real fonts in a post-processing step by
Ghostscript.
Default: @code{#f}.

@item @code{gs-load-lily-fonts} @var{bool}
If @var{bool} is @code{#t}, load LilyPond fonts via Ghostscript.
This option makes LilyPond's output files contain only references to
its music fonts, which must be resolved to real fonts in a
post-processing step by Ghostscript.  All other fonts are still
output as usual.
Default: @code{#f}.

@item @code{gs-never-embed-fonts} @var{bool}
If @var{bool} is @code{#t}, make Ghostscript embed only TrueType
fonts and no other font format.
Default: @code{#f}.

@item @code{help} @var{bool}
If @var{bool} is @code{#t}, show this help.
Default: @code{#f}.

@item @code{include-book-title-preview} @var{bool}
If @var{bool} is @code{#t}, include book titles in preview images.
Default: @code{#t}.

@item @code{include-eps-fonts} @var{bool}
If @var{bool} is @code{#t}, include fonts in separate-system EPS files.
Default: @code{#t}.

@item @code{include-settings} @var{string}
Include file @var{string} for global settings, which is included before the
score is processed.
Default: @code{#f} (meaning no global settings file).

@item @code{job-count} @var{num}
Process in parallel, using @var{num} jobs.
Default: @code{#f} (meaning no parallel processing).

@item @code{log-file} @var{string}
Redirect output to the log file @file{@var{string}.log}.
Default: @code{#f} (meaning no log file).

@item @code{max-markup-depth} @var{num}
Set maximum depth for the markup tree to value @var{num}.  If a
markup has more levels, assume it will not terminate on its own,
print a warning, and return a null markup instead.
Default: @code{1024}.

@item @code{midi-extension} @var{string}
Set the default file extension for MIDI output files to
@file{.@var{string}}.
Default: @code{"midi"}.

@item @code{music-strings-to-paths} @var{bool}
If @var{bool} is @code{#t}, convert text strings to paths when glyphs
belong to a music font.
Default: @code{#f}.

@item @code{paper-size} @var{extra-quoted-string}
Set default paper size to @var{extra-quoted-string}.  Note that the
string must be enclosed in escaped double quotes.
Default: @code{"\"a4\""}.

@item @code{pixmap-format} @var{symbol}
Set Ghostscript's output format for pixel images to @var{symbol}.
Default: @code{png16m}.

@item @code{png-width} @var{width}
@itemx @code{png-height} @var{height}
For PNG output, set the width and height (in pixels) of the
created image file.  If one of the options is missing, the other
dimension is computed according to the EPS bounding box, retaining
the aspect ratio.

In addition to @option{--png}, either @option{--eps},
@option{-dcrop}, or @option{-dpreview} should be used to get
proper image scaling without clipping.

Option @option{-dresolution} is ignored.

Note that there is a bug in ghostscript versions up to 9.52 for
these two options: It produces empty PNG images if the height is
larger than the width.

@item @code{point-and-click} @var{bool}
If @var{bool} is @code{#t}, add @q{point & click} links to PDF and
SVG output.  See @ref{Point and click}.
Default: @code{#t}.

@item @code{preview} @var{bool}
If @var{bool} is @code{#t}, create preview images in addition to
normal output.
Default: @code{#f}.

For input file name @var{file} and output format @var{fmt}, it
generates an output file having the name
@file{@var{file}@code{.preview.}@var{fmt}}, containing the
titles and the first system of music.  If @code{\book} or
@code{\bookpart} blocks are used, the titles of @code{\book},
@code{\bookpart} or @code{\score} will appear in the output,
including the first system of every @code{\score} block if the
@code{\paper} variable @code{print-all-headers} is set to
@code{#t}.

To suppress the usual output, use the @option{-dprint-pages} or
@option{-dno-print-pages} options according to your requirements.

@item @code{print-pages} @var{bool}
If @var{bool} is @code{#t}, generate full pages.
Default: @code{#t}.

Option @option{-dno-print-pages} is useful in combination with
@option{-dpreview} or @option{-dcrop}.

@item @code{protected-scheme-parsing} @var{bool}
If @var{bool} is @code{#t}, continue when errors in inline Scheme
code are caught in the parser.  If set to @code{#f}, halt on errors
and print a stack trace.
Default: @code{#t}.

@item @code{relative-includes} @var{bool}
When processing an @code{\include} command, look for the included
file relative to the current file if @var{bool} is @code{#t}.  If set
to @code{#f}, look for the file relative to the root file.
Default: @code{#t}.

@item @code{resolution} @var{num}
Set resolution for generating @code{PNG} pixmaps to @var{num} dpi.
Default: @code{101}.

@item @code{separate-log-files} @var{bool}
For input files @file{file1.ly}, @file{file2.ly}, @dots{}, output log
data to files @file{file1.log}, @file{file2.log}, @dots{}, if
@var{bool} is @code{#t}.
Default: @code{#f}.

@item @code{separate-page-formats} @var{symbol}
Comma-separated list of formats (@code{svg}, @code{pdf},
@code{png}, or @code{eps}) to use for the separate page
images in @code{lilypond-book}.

@item @code{show-available-fonts} @var{bool}
If @var{bool} is @code{#t}, list available font names as delivered by
the fontconfig library.  Appended to this list LilyPond displays the
configuration settings of fontconfig itself.
Default: @code{#f}.

@item @code{strip-output-dir} @var{bool}
If @var{bool} is @code{#t}, don't use the directory part from input
file paths while constructing output file names.
Default: @code{#t}.

@item @code{strokeadjust} @var{bool}
If @var{bool} is @code{#t}, force PostScript stroke adjustment.  This
option is mostly relevant when a PDF is generated from PostScript
output (stroke adjustment is usually enabled automatically for
low-resolution bitmap devices).  Without this option, PDF previewers
tend to produce widely inconsistent stem widths at resolutions
typical for screen display.  However, the option does not noticeably
affect print quality and causes large file size increases in PDF
files.
Default: @code{#f}.

@item @code{svg-woff} @var{bool}
This option is required when using Web Open Font Format (WOFF) font
files with the @code{svg} backend.  If @var{bool} is @code{#t}, a
single SVG file is created for every page of output.  Apart from
LilyPond's own music glyphs, no other font information will be
included.  Any SVG viewer will therefore require the fonts be
available to it for the proper rendering of both text and lyrics.  It
is also recommended not to use any font @q{aliases} or @q{lists} in
case the SVG viewer cannot handle them.
Default: @code{#f}.

@item @code{tall-page-formats} @var{symbol}
Comma-separated list of formats (@code{svg}, @code{pdf},
@code{png}, or @code{eps}) to use for the `tall page' image in
@code{lilypond-book}.

@item @code{use-paper-size-for-page} @var{bool}
If @var{bool} is @code{#t} (the default), each page is set to the
paper size, possibly cropping parts that extend beyond the
paper. Setting it @code{#f} will resize the page to contain the
content as necessary.

@item @code{verbose}
Verbosity level.  This is a read-only option; setting it has no
effect.

@item @code{warning-as-error} @var{bool}
If @var{bool} is @code{#t}, change all warning and @q{programming
error} messages into errors.
Default: @code{#f}.

@end table


@node Environment variables
@unnumberedsubsec Environment variables

@cindex LANG
@cindex LILYPOND_DATADIR
@cindex LILYPOND_LOCALEDIR
@cindex LILYPOND_RELOCDIR
@cindex LILYPOND_LOGLEVEL

@command{lilypond} recognizes the following environment variables:

@table @code

@item LILYPOND_DATADIR
This specifies a directory where locale messages and data files
are looked up by default, overriding locations defined either
at compile-time or computed dynamically at run-time (see
@ref{Relocation}).  The directory should contain subdirectories
called @file{ly}, @file{ps}, @file{tex}, etc.

@item LILYPOND_LOCALEDIR
Specify the directory where locale-specific files are located.
This overrides the value derived from @code{LILYPOND_DATADIR}.

@item LILYPOND_RELOCDIR
Specify the directory where relocation files are located.  This
overrides the value derived from the location of the
@command{lilypond} binary.

@item LANG
The language for LilyPond data sent to @code{stdout} and
@code{stderr}, for example progress reports, warning messages, or
debug output.  Example: @code{LANG=de}.

@item LILYPOND_LOGLEVEL
The default loglevel.  If LilyPond is called without an explicit
loglevel (i.e., no @option{--loglevel} command line option), this
value is used.

@item LILYPOND_GC_YIELD
A variable, as a percentage, that tunes memory management
behavior.  A higher values means the program uses more memory, a
smaller value means more CPU time is used.  The default value is
@code{70}.

@item TMPDIR
This specifies the temporary directory in GNU/Linux and Mac.
Default is @file{/tmp}.  It is the directory where intermediate
files (such as PostScript files) are saved during compilation.
Overriding this variable might be useful, for example, if the
user running lilypond does not have write access to the default
temporary directory.  Example: @code{TMPDIR=~/foo}.
@end table


@node Relocation
@unnumberedsubsec Relocation

@cindex relocation

Most programs in the Unix world use default directories for its
data that are determined at configure time before compilation.
LilyPond is no exception; for example, a typical installation puts
the @file{lilypond} binary into @file{/usr/@/bin} and all files
specific to LilyPond into subdirectories of
@file{/usr/@/share/@/lilypond/@/2.21.0/} (assuming that the
current version is 2.21.0).

While this approach works fine for manual compilation and
platforms that come with standardized package managers, it can
cause issues where such managers are not common or not used by
default.  Typical examples of such platforms are Windows and
MacOS, where users expect that application bundles can be
installed anywhere.

The common solution to this problem is relocation support: Instead
of using hard-coded paths to data files, locations of the
necessary support files are computed at run time @emph{relative to
the executed binary}.


@menu
* Relocation files::
* Relocation algorithm::
@end menu


@node Relocation files
@unnumberedsubsubsec Relocation files

There's actually a second mechanism for run-time configuration:
LilyPond heavily relies on external programs and libraries, in
particular the @q{FontConfig} and @q{GUILE} libraries to find
system fonts and handle Scheme files, respectively, and the
@command{gs} program to convert PS data to PDF files.  All of them
must be configured also to locate its relevant data files.  To do
that, the @command{lilypond} program parses all files in a
directory called @file{relocate} (if it exists; see below where
this directory is searched for) to manipulate environment
variables, which in turn control those external libraries and
programs.  The format of such relocation files is simple; each
line has the syntax

@example
@var{command} @var{key}=@var{value}
@end example

@noindent
and empty lines get ignored.

The @var{command} directive is one of the following.

@table @code

@item set
Uncondionally set environment variable @var{key} to @var{value}.
This overrides a previously set value.

@item set?
Set environment variable @var{key} to @var{value} only if
@var{key} isn't defined yet.  In other words, it doesn't override
a previously set value.

@item setdir
If @var{value} is a directory, unconditionally set environent
variable @var{key} to @var{value}.  Otherwise, emit a warning.

@item setfile
If @var{value} is a file, unconditionally set environent variable
@var{key} to @var{value}.  Otherwise, emit a warning.

@item prependdir
Prepend directory @var{value} to the list of directories in
environment variable @var{key}.  If @var{key} doesn't exist it
gets created.

@end table

Environment variables (marked with a leading dollar sign) are
allowed in @var{value} and get expanded before the directive is
executed.

Here are two examples of relocation file entries.

@example
set? FONTCONFIG_FILE=$INSTALLER_PREFIX/etc/fonts/fonts.conf
prependdir GUILE_LOAD_PATH=$INSTALLER_PREFIX/share/guile/1.8
@end example

Multiple lines setting the same environment variable should be
avoided in relocation files since the parsing order of files in
the @file{relocate} directory is arbitrary.


@node Relocation algorithm
@unnumberedsubsubsec Relocation algorithm

LilyPond uses the following algorithm to find its data files.

@enumerate

@item
Compute the directory where the currently executed
@command{lilypond} binary is located.  Let's call this
@code{bindir}.  Set (internal) environment variable
@code{INSTALLER_PREFIX} to @file{@var{bindir}/..} (i.e., the
parent directory of @code{bindir}).

@item
Check environment variable @code{LILYPOND_DATADIR}.  If it is set,
use its value for LilyPond's data directory, @code{datadir}.
Otherwise use either
@file{$INSTALLER_PREFIX/@/share/@/lilypond/@/@var{version}} (with
@var{version} being the current LilyPond version) or
@file{$INSTALLER_PREFIX/@/share/@/lilypond/@/current}.

@item
Check environment variable @code{LILYPOND_LOCALEDIR}.  If it is
set, use its value for LilyPond's locale data directory,
@code{localedir}.  Otherwise use
@file{$INSTALLER_PREFIX/@/share/@/locale}.

@item
Check environment variable @code{LILYPOND_RELOCDIR}.  If it is
set, use its value for the directory of LilyPond's relocation
files, @code{relocdir}.  Otherwise use
@file{$INSTALLER_PREFIX/@/etc/@/relocate}.

@item
If @code{datadir} doesn't exist, use a compile-time value instead.
Ditto for @code{localedir} (but not for @code{relocdir}, since it
doesn't make sense to have that).

@item
If @code{relocdir} exists, process all files in this directory as
described in @ref{Relocation files}.

@end enumerate


@node LilyPond in chroot jail
@unnumberedsubsec LilyPond in chroot jail

Setting up the server to run LilyPond in a chroot jail is a complicated
task.  The steps are listed below.  Examples in the steps are from
Ubuntu GNU/Linux, and may require the use of @code{sudo} as appropriate.

@itemize

@item Install the necessary packages: LilyPond, Ghostscript, and ImageMagick.

@item Create a new user by the name of @code{lily}:

@example
adduser lily
@end example

@noindent
This will create a new group for the @code{lily} user as well, and a
home folder, @code{/home/lily}

@item In the home folder of the @code{lily} user create a file to use as a
separate filesystem:

@example
dd if=/dev/zero of=/home/lily/loopfile bs=1k count= 200000
@end example

@noindent
This example creates a 200MB file for use as the jail filesystem.

@item Create a loop device, make a file system and mount it, then create
a folder that can be written by the @code{lily} user:

@example
mkdir /mnt/lilyloop
losetup /dev/loop0 /home/lily/loopfile
mkfs -t ext3 /dev/loop0 200000
mount -t ext3 /dev/loop0 /mnt/lilyloop
mkdir /mnt/lilyloop/lilyhome
chown lily /mnt/lilyloop/lilyhome
@end example

@item In the configuration of the servers, the JAIL will be @code{/mnt/lilyloop}
and the DIR will be @code{/lilyhome}.

@item Create a big directory tree in the jail by copying the necessary files, as
shown in the sample script below.

You can use @code{sed} to create the necessary copy commands for a given
executable:

@example
for i in "/usr/local/lilypond/usr/bin/lilypond" "/bin/sh" "/usr/bin/;  \
  do ldd $i | sed 's/.*=> \/\(.*\/\)\([^(]*\).*/mkdir -p \1 \&\&  \
    cp -L \/\1\2 \1\2/' | sed 's/\t\/\(.*\/\)\(.*\) (.*)$/mkdir -p  \
      \1 \&\& cp -L \/\1\2 \1\2/' | sed '/.*=>.*/d'; done
@end example

@end itemize

@subheading Example script for 32-bit Ubuntu 8.04

@example
#!/bin/sh
## defaults set here

username=lily
home=/home
loopdevice=/dev/loop0
jaildir=/mnt/lilyloop
# the prefix (without the leading slash!)
lilyprefix=usr/local
# the directory where lilypond is installed on the system
lilydir=/$lilyprefix/lilypond/

userhome=$home/$username
loopfile=$userhome/loopfile
adduser $username
dd if=/dev/zero of=$loopfile bs=1k count=200000
mkdir $jaildir
losetup $loopdevice $loopfile
mkfs -t ext3 $loopdevice 200000
mount -t ext3 $loopdevice $jaildir
mkdir $jaildir/lilyhome
chown $username $jaildir/lilyhome
cd $jaildir

mkdir -p bin usr/bin usr/share usr/lib usr/share/fonts $lilyprefix tmp
chmod a+w tmp

cp -r -L $lilydir $lilyprefix
cp -L /bin/sh /bin/rm bin
cp -L /usr/bin/convert /usr/bin/gs usr/bin
cp -L /usr/share/fonts/truetype usr/share/fonts

# Now the library copying magic
for i in "$lilydir/usr/bin/lilypond" "$lilydir/usr/bin/guile" "/bin/sh"  \
  "/bin/rm" "/usr/bin/gs" "/usr/bin/convert"; do ldd $i | sed 's/.*=>  \
    \/\(.*\/\)\([^(]*\).*/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/' | sed  \
      's/\t\/\(.*\/\)\(.*\) (.*)$/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/'  \
        | sed '/.*=>.*/d'; done | sh -s

# The shared files for Ghostscript...
      cp -L -r /usr/share/ghostscript usr/share
# The shared files for ImageMagick
      cp -L -r /usr/lib/ImageMagick* usr/lib

### Now, assuming that you have test.ly in /mnt/lilyloop/lilyhome,
### you should be able to run:
### Note that /$lilyprefix/bin/lilypond is a script, which sets the
### LD_LIBRARY_PATH - this is crucial
      /$lilyprefix/bin/lilypond -jlily,lily,/mnt/lilyloop,/lilyhome test.ly
@end example

@c " keep quote signs balanced for context-sensitive editors

@node Error messages
@section Error messages

@cindex error messages
Different error messages can appear while compiling a file:

@table @emph

@item Warning
@cindex warning
Something looks suspect.  If you are requesting something out of the
ordinary then you will understand the message, and can ignore it.
However, warnings usually indicate that something is wrong with the
input file.

@item Error
@cindex error
Something is definitely wrong.  The current processing step (parsing,
interpreting, or formatting) will be finished, but the next step will
be skipped.

@item Fatal error
@cindex fatal error
Something is definitely wrong, and LilyPond cannot continue.  This
happens rarely.  The most usual cause is misinstalled fonts.

@item Scheme error
@cindex trace, Scheme
@cindex call trace
@cindex Scheme error
Errors that occur while executing Scheme code are caught by the Scheme
interpreter.  If running with the verbose option (@option{-V} or
@option{--verbose}) then a call trace of the offending
function call is printed.

@item Programming error
@cindex Programming error
There was some internal inconsistency.  These error messages are
intended to help the programmers and debuggers.  Usually, they can be
ignored.  Sometimes, they come in such big quantities that they obscure
other output.

@item Aborted (core dumped)
@cindex Aborted (core dumped)
This signals a serious programming error that caused the program to
crash.  Such errors are considered critical.  If you stumble on one,
send a bug-report.
@end table

@cindex errors, message format
If warnings and errors can be linked to some part of the input file,
then error messages have the following form

@example
@var{filename}:@var{lineno}:@var{columnno}: @var{message}
@var{offending input line}
@end example

A line-break is inserted in the offending line to indicate the column
where the error was found.  For example,

@example
test.ly:2:19: error: not a duration: 5
  @{ c'4 e'
           5 g' @}
@end example

These locations are LilyPond's best guess about where the warning or
error occurred, but (by their very nature) warnings and errors occur
when something unexpected happens.  If you can't see an error in the
indicated line of your input file, try checking one or two lines
above the indicated position.

Please note that diagnostics can be triggered at any point during the
many stages of processing.  For example if there are parts of the input
that are processed multiple times (i.e., in midi and layout output), or
if the same music variable is used in multiple contexts the same message
may appear several times.  Diagnostics produced at a @q{late} stage (i.e.,
bar checks) might also be issued multiple times.

More information about errors is given in @ref{Common errors}.


@node Common errors
@section Common errors

The error conditions described below occur often, yet the cause
is not obvious or easily found.  Once seen and understood, they
are easily handled.


@menu
* Music runs off the page::
* An extra staff appears::
* Error message Unbound variable %::
* Error message FT_Get_Glyph_Name::
* Warning staff affinities should only decrease::
* Error message unexpected new::
* Warning this voice needs a voiceXx or shiftXx setting::
@end menu

@node Music runs off the page
@unnumberedsubsec Music runs off the page

Music running off the page over the right margin or appearing
unduly compressed is almost always due to entering an incorrect
duration on a note, causing the final note in a measure to extend
over the bar line.  It is not invalid if the final note in a
measure does not end on the automatically entered bar line, as the
note is simply assumed to carry over into the next measure.  But
if a long sequence of such carry-over measures occurs the music
can appear compressed or may flow off the page because automatic
line breaks can be inserted only at the end of complete measures,
i.e., where all notes end before or at the end of the measure.

@warning{An incorrect duration can cause line breaks to be
inhibited, leading to a line of highly compressed music or
music which flows off the page.}

The incorrect duration can be found easily if bar checks are used,
see @ruser{Bar and bar number checks}.

If you actually intend to have a series of such carry-over measures
you will need to insert an invisible bar line where you want the
line to break.  For details, see @ruser{Bar lines}.


@node An extra staff appears
@unnumberedsubsec An extra staff appears

If contexts are not created explicitly with @code{\new} or
@code{\context}, they will be silently created as soon as a
command is encountered which cannot be applied to an existing
context.  In simple scores the automatic creation of contexts is
useful, and most of the examples in the LilyPond manuals take
advantage of this simplification.  But occasionally the silent
creation of contexts can give rise to unexpected new staves or
scores.  For example, it might be expected that the following code
would cause all note heads within the following staff to be
colored red, but in fact it results in two staves with the note
heads remaining the default black in the lower staff.

@lilypond[quote,verbatim,fragment]
\override Staff.NoteHead.color = #red
\new Staff { a' }
@end lilypond

This is because a @code{Staff} context does not exist when the
override is processed, so one is implicitly created and the override
is applied to it, but then the @code{\new Staff} command creates
another, separate, staff into which the notes are placed.  The
correct code to color all note heads red is

@lilypond[quote,verbatim]
\new Staff {
  \override Staff.NoteHead.color = #red
  a'
}
@end lilypond

@node Error message Unbound variable %
@unnumberedsubsec Error message Unbound variable %

This error message will appear at the bottom of the console
output or log file together with a @qq{GUILE signalled an error @dots{}}
message every time a Scheme routine is called which (invalidly)
contains a @emph{LilyPond} rather than a @emph{Scheme} comment.

LilyPond comments begin with a percent sign, (@code{%}), and must
not be used within Scheme routines.  Scheme comments begin with a
semi-colon, (@code{;}).

@node Error message FT_Get_Glyph_Name
@unnumberedsubsec Error message FT_Get_Glyph_Name

This error messages appears in the console output or log file if
an input file contains a non-ASCII character and was not saved in
UTF-8 encoding.  For details, see @ruser{Text encoding}.


@node Warning staff affinities should only decrease
@unnumberedsubsec Warning staff affinities should only decrease

This warning can appear if there are no staves in the printed
output, for example if there are just a @code{ChordName} context
and a @code{Lyrics} context as in a lead sheet.  The warning
messages can be avoided by making one of the contexts behave as a
staff by inserting

@example
\override VerticalAxisGroup.staff-affinity = ##f
@end example

@noindent
at its start.  For details, see @qq{Spacing of non-staff lines} in
@ruser{Flexible vertical spacing within systems}.


@node Error message unexpected new
@unnumberedsubsec Error message unexpected @code{\new}

A @code{\score} block must contain a @emph{single} music expression.
If instead it contains several @code{\new Staff},
@code{\new StaffGroup} or similar contexts introduced with @code{\new}
without them being enclosed in either curly brackets,
@code{@{ @dots{} @}}, or double angle brackets, @code{<< @dots{} >>},
like this:

@example
\score @{
  % Invalid! Generates error: syntax error, unexpected \new
  \new Staff @{ @dots{} @}
  \new Staff @{ @dots{} @}
@}
@end example

@noindent
the error message will be produced.

To avoid the error, enclose all the @code{\new} statements in
curly or double angle brackets.

Using curly brackets will introduce the @code{\new} statements
sequentially:

@lilypond[quote,verbatim]
\score {
  {
    \new Staff { a' a' a' a' }
    \new Staff { g' g' g' g' }
  }
}
@end lilypond

@noindent
but more likely you should be using double angle brackets so the new
staves are introduced in parallel, i.e., simultaneously:

@lilypond[quote,verbatim]
\score {
  <<
    \new Staff { a' a' a' a' }
    \new Staff { g' g' g' g' }
  >>
}
@end lilypond

@node Warning this voice needs a voiceXx or shiftXx setting
@unnumberedsubsec Warning this voice needs a @code{\voiceXx} or @code{\shiftXx} setting

If notes from two different voices with stems in the same direction
occur at the same musical moment, but the voices have no
voice-specific shifts specified, the warning message
@samp{warning: this voice needs a \voiceXx or \shiftXx setting} will appear
when compiling the LilyPond file.  This warning will appear even when
the notes have no visible stems, e.g., whole notes, if the stems for
shorter notes at the same pitch would be in the same direction.

Remember that the stem direction depends on the position of the
note on the staff unless the stem direction is specified, for example
by using @code{\voiceOne}, etc.  In this case the warning will appear
only when the stems happen to be in the same direction, i.e., when the
notes are in the same half of the staff.

By placing the notes in voices with stem directions and shifts
specified, for example by using @code{\voiceOne}, etc., these warnings
may be avoided.

Notes in higher numbered voices, @code{\voiceThree}, etc., are
automatically shifted to avoid clashing note columns.  This causes a
visible shift for notes with stems, but whole notes are not visibly
shifted unless an actual clash of the note heads occurs, or when the
voices cross over from their natural order (when @code{\voiceThree}
is higher than @code{\voiceOne}, etc.).

@morerefs
@rlearning{Explicitly instantiating voices},
@rlearning{Real music example},
@ruser{Single-staff polyphony},
@ruser{Collision resolution}.
@endmorerefs
