]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/usage/running.itely
Docs: Usage: -fsvg is not a valid option.
[lilypond.git] / Documentation / usage / running.itely
1 @c -*- coding: utf-8; mode: texinfo; -*-
2
3 @ignore
4     Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
5
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..
9 @end ignore
10
11 @c \version "2.12.0"
12
13
14 @node Running lilypond
15 @chapter Running @command{lilypond}
16
17 This chapter details the technicalities of running LilyPond.
18
19 @menu
20 * Normal usage::
21 * Command-line usage::
22 * Error messages::
23 * Common errors::
24 @end menu
25
26
27 @node Normal usage
28 @section Normal usage
29
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
33 program.
34
35
36 @node Command-line usage
37 @section Command-line usage
38
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.
43
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}.
49
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.
53
54 @menu
55 * Invoking lilypond::
56 * Command line options for lilypond::
57 * Environment variables::
58 @end menu
59
60 @node Invoking lilypond
61 @unnumberedsubsec Invoking @command{lilypond}
62
63 The @command{lilypond} executable may be called as follows from
64 the command line.
65
66 @example
67 lilypond [@var{option}]@dots{} @var{file}@dots{}
68 @end example
69
70
71 When invoked with a filename that has no extension, the @file{.ly}
72 extension is tried first.  To read input from stdin, use a
73 dash (@code{-}) for @var{file}.
74
75 When @file{filename.ly} is processed it will produce @file{filename.ps}
76 and @file{filename.pdf} as output.  Several files can be specified;
77 they will each be processed independently.  @footnote{The status of
78 GUILE is not reset after processing a @code{.ly} file, so be careful
79 not to change any system defaults from within Scheme.}
80
81 If @file{filename.ly} contains more than one @code{\book}
82 block, then the rest of the scores will be output in numbered files,
83 starting with @file{filename-1.pdf}.  In addition, the value of
84 @code{output-suffix} will be inserted between the basename and the
85 number.  An input file containing
86
87 @example
88 #(define output-suffix "violin")
89 \score @{ @dots{} @}
90 #(define output-suffix "cello")
91 \score @{ @dots{} @}
92 @end example
93
94 @noindent
95 will output @var{base}@file{-violin.pdf} and
96 @var{base}@file{-cello-1.pdf}.
97
98
99 @node Command line options for lilypond
100 @unnumberedsubsec Command line options for @command{lilypond}
101
102 @cindex Invoking @command{lilypond}
103 @cindex command line options for @command{lilypond}
104 @cindex options, command line
105 @cindex switches
106
107 The following options are supported:
108
109 @table @code
110
111 @item -e,--evaluate=@var{expr}
112 Evaluate the Scheme @var{expr} before parsing any @file{.ly} files.
113 Multiple @code{-e} options may be given, they will be evaluated
114 sequentially.
115
116 The expression will be evaluated in the @code{guile-user} module, so
117 if you want to use definitions in @var{expr}, use
118
119 @example
120 lilypond -e '(define-public a 42)'
121 @end example
122
123 @noindent
124 on the command-line, and include
125
126 @example
127 #(use-modules (guile-user))
128 @end example
129
130 @noindent
131 at the top of the @code{.ly} file.
132
133 @item -f,--format=@var{format}
134 which formats should be written.  Choices for @code{format} are
135 @code{ps}, @code{pdf}, and @code{png}.
136
137 Example: @code{lilypond -fpng @var{filename}.ly}
138
139
140
141 @item -d,--define-default=@var{var}=@var{val}
142 This sets the internal program option @var{var} to the Scheme value
143 @var{val}.  If @var{val} is not supplied, then @var{#t} is used.  To
144 switch off an option, @code{no-} may be prefixed to @var{var}, e.g.
145
146 @cindex point and click, command line
147
148 @example
149 -dno-point-and-click
150 @end example
151
152 @noindent
153 is the same as
154 @example
155 -dpoint-and-click='#f'
156 @end example
157
158 Here are a few interesting options.
159
160 @cindex help, command line
161
162 @table @samp
163 @item help
164 Running @code{lilypond -dhelp} will print all of the @code{-d} options
165 available.
166
167 @cindex paper-size, command line
168
169 @item paper-size
170 This option sets the default paper-size,
171 @example
172 -dpaper-size=\"letter\"
173 @end example
174
175 @noindent
176 Note that the string must be enclosed in escaped quotes ( @code{\"} ).
177 @c Match " in previous line to help context-sensitive editors
178
179 @cindex safe, command line
180
181 @item safe
182 Do not trust the @code{.ly} input.
183
184 When LilyPond formatting is available through a web server, either the
185 @code{--safe} or the @code{--jail} option @b{MUST} be passed.  The
186 @code{--safe} option will prevent inline Scheme code from wreaking
187 havoc, for example
188
189 @quotation
190 @verbatim
191 #(system "rm -rf /")
192 {
193   c4^#(ly:export (ly:gulp-file "/etc/passwd"))
194 }
195 @end verbatim
196 @end quotation
197
198 The @code{-dsafe} option works by evaluating in-line Scheme
199 expressions in a special safe module.  This safe module is derived from
200 GUILE @file{safe-r5rs} module, but adds a number of functions of the
201 LilyPond API.  These functions are listed in @file{scm/@/safe@/-lily@/.scm}.
202
203 In addition, safe mode disallows @code{\include} directives and
204 disables the use of backslashes in @TeX{} strings.
205
206 In safe mode, it is not possible to import LilyPond variables
207 into Scheme.
208
209 @code{-dsafe} does @emph{not} detect resource overuse.  It is still possible to
210 make the program hang indefinitely, for example by feeding cyclic data
211 structures into the backend.  Therefore, if using LilyPond on a
212 publicly accessible webserver, the process should be limited in both
213 CPU and memory usage.
214
215 The safe mode will prevent many useful LilyPond snippets from being
216 compiled.  The @code{--jail} is a more secure alternative, but
217 requires more work to set up.
218
219 @cindex output format, setting
220 @item backend
221 the output format to use for the back-end.  Choices for @code{format} are
222 @table @code
223 @item ps
224 @cindex PostScript output
225  for PostScript.
226
227   Postscript files include TTF, Type1 and OTF fonts.  No subsetting of
228   these fonts is done.  When using oriental character sets, this can
229   lead to huge files.
230
231 @item eps
232
233 @cindex Postscript, encapulated
234 @cindex EPS (Encapsulated PostScript)
235
236  for encapsulated PostScript.  This dumps every page (system) as a separate
237 @file{EPS} file, without fonts, and as one collated @file{EPS} file with
238 all pages (systems) including fonts.
239
240 This mode is used by default by @command{lilypond-book}.
241
242 @item svg
243
244 @cindex SVG (Scalable Vector Graphics)
245
246  for SVG (Scalable Vector Graphics).
247
248  This creates a single SVG file, without embedded fonts, for every
249  page of output.  It is recommended to install the Century
250  Schoolbook fonts, included with your LilyPond installation, for
251  optimal rendering.  Under UNIX, simply copy these fonts from the
252  LilyPond directory (typically
253  @file{/usr/share/lilypond/VERSION/fonts/otf/}) to
254  @file{~/.fonts/}.  The SVG output should be compatible with any
255  SVG editor or user agent.
256
257 @item scm
258
259 @cindex Scheme dump
260
261  for a dump of the raw, internal Scheme-based drawing commands.
262
263 @item null
264  do not output a printed score; has the same effect as @code{-dno-print-pages}.
265 @end table
266
267 Example: @code{lilypond -dbackend=svg @var{filename}.ly}
268
269 @item preview
270 @cindex preview, command line
271 Generate an output file containing the titles and the first system
272
273 @item print-pages
274 Generate the full pages, the default.  @code{-dno-print-pages} is
275 useful in combination with @code{-dpreview}.
276
277 @end table
278
279
280
281 @item -h,--help
282 Show a summary of usage.
283
284 @item -H,--header=@var{FIELD}
285 Dump a header field to file @file{BASENAME.@var{FIELD}}.
286
287 @item --include, -I=@var{directory}
288 Add @var{directory} to the search path for input files.
289 @cindex file searching
290 @cindex search path
291
292 @item -i,--init=@var{file}
293 Set init file to @var{file} (default: @file{init.ly}).
294
295 @item -o,--output=@var{FILE}
296 Set the default output file to @var{FILE}.  The appropriate
297 suffix will be added (e.g. @code{.pdf} for pdf)
298
299 @cindex PostScript output
300
301 @item --ps
302 Generate PostScript.
303
304 @cindex Portable Network Graphics (PNG) output
305
306 @item --png
307 Generate pictures of each page, in PNG format.  This implies
308 @code{--ps}.  The resolution in DPI of the image may be set with
309 @example
310 -dresolution=110
311 @end example
312
313 @cindex Portable Document Format (PDF) output
314
315 @item --pdf
316 Generate PDF.  This implies @code{--ps}.
317
318
319
320 @item -j,--jail=@var{user},@var{group},@var{jail},@var{dir}
321 Run @command{lilypond} in a chroot jail.
322
323 The @code{--jail} option provides a more flexible alternative to
324 @code{--safe} when LilyPond formatting is available through a web
325 server or whenever LilyPond executes externally provided
326 sources.
327
328 The @code{--jail} option works by changing the root of @command{lilypond} to
329 @var{jail} just before starting the actual compilation process.  The user
330 and group are then changed to match those provided, and the current
331 directory is changed to @var{dir}.  This setup guarantees that it is not
332 possible (at least in theory) to escape from the jail.  Note that for
333 @code{--jail} to work @command{lilypond} must be run as root, which is usually
334 accomplished in a safe way using @command{sudo}.
335
336 Setting up a jail is a slightly delicate matter, as we must be sure that
337 LilyPond is able to find whatever it needs to compile the source
338 @emph{inside the jail}.  A typical setup comprises the following items:
339
340 @table @asis
341 @item Setting up a separate filesystem
342 A separate filesystem should be created for LilyPond, so that it can be
343 mounted with safe options such as @code{noexec}, @code{nodev}, and
344 @code{nosuid}.  In this way, it is impossible to run executables or to
345 write directly to a device from LilyPond.  If you do not want to create a
346 separate partition, just create a file of reasonable size and use it to
347 mount a loop device.  A separate filesystem also guarantees that LilyPond
348 cannot write more space than it is allowed.
349
350 @item Setting up a separate user
351 A separate user and group (say, @code{lily}/@code{lily}) with low
352 privileges should be used to run LilyPond inside the jail.  There should
353 be a single directory writable by this user, which should be passed in
354 @var{dir}.
355
356 @item Preparing the jail
357 LilyPond needs to read a number of files while running.  All these files
358 are to be copied into the jail, under the same path they appear in the
359 real root filesystem.  The entire content of the LilyPond installation
360 (e.g., @file{/usr/share/lilypond})
361 should be copied.
362
363 If problems arise, the simplest way to trace them down is to run
364 LilyPond using @command{strace}, which will allow you to determine which
365 files are missing.
366
367 @item Running LilyPond
368 In a jail mounted with @code{noexec} it is impossible to execute any external
369 program.  Therefore LilyPond must be run with a backend that does not
370 require any such program.  As we already mentioned, it must be also run
371 with superuser privileges (which, of course, it will lose immediately),
372 possibly using @command{sudo}.  It is a good idea to limit the number of
373 seconds of CPU time LilyPond can use (e.g., using @command{ulimit
374 -t}), and, if your operating system supports it, the amount of memory
375 that can be allocated.
376 @end table
377
378
379 @item -v,--version
380 Show version information.
381
382 @item -V,--verbose
383 Be verbose: show full paths of all files read, and give timing
384 information.
385
386 @item -w,--warranty
387 Show the warranty with which GNU LilyPond comes. (It comes with
388 @strong{NO WARRANTY}!)
389 @end table
390
391 @node Environment variables
392 @unnumberedsubsec Environment variables
393
394
395 @cindex LANG
396 @cindex LILYPOND_DATADIR
397
398 @command{lilypond} recognizes the following environment variables:
399 @table @code
400 @item LILYPOND_DATADIR
401 This specifies a directory where locale messages and
402 data files will be looked up by default.  The directory should contain
403 subdirectories called @file{ly/}, @file{ps/}, @file{tex/}, etc.
404
405 @item LANG
406 This selects the language for the warning messages.
407
408 @item LILYPOND_GC_YIELD
409 With this variable the memory footprint and performance can be
410 adjusted.  It is a percentage tunes memory management behavior.  With
411 higher values, the program uses more memory, with smaller values, it
412 uses more CPU time.  The default value is @code{70}.
413
414 @end table
415
416
417 @node Error messages
418 @section Error messages
419
420 @cindex error messages
421 Different error messages can appear while compiling a file:
422
423 @table @emph
424
425 @item Warning
426 @cindex warning
427 Something looks suspect.  If you are requesting something out of the
428 ordinary then you will understand the message, and can ignore it.
429 However, warnings usually indicate that something is wrong with the
430 input file.
431
432 @item Error
433 @cindex error
434 Something is definitely wrong.  The current processing step (parsing,
435 interpreting, or formatting) will be finished, but the next step will
436 be skipped.
437
438 @item Fatal error
439 @cindex fatal error
440 Something is definitely wrong, and LilyPond cannot continue.  This
441 happens rarely.  The most usual cause is misinstalled fonts.
442
443 @item Scheme error
444 @cindex trace, Scheme
445 @cindex call trace
446 @cindex Scheme error
447 Errors that occur while executing Scheme code are caught by the Scheme
448 interpreter.  If running with the verbose option (@code{-V} or
449 @code{--verbose}) then a call trace of the offending
450 function call is printed.
451
452 @item Programming error
453 @cindex Programming error
454 There was some internal inconsistency.  These error messages are
455 intended to help the programmers and debuggers.  Usually, they can be
456 ignored.  Sometimes, they come in such big quantities that they obscure
457 other output.
458
459 @item Aborted (core dumped)
460 @cindex Aborted (core dumped)
461 This signals a serious programming error that caused the program to
462 crash.  Such errors are considered critical.  If you stumble on one,
463 send a bug-report.
464 @end table
465
466 @cindex errors, message format
467 If warnings and errors can
468 be linked to some part of the input file, then error messages have the
469 following form
470
471 @example
472 @var{filename}:@var{lineno}:@var{columnno}: @var{message}
473 @var{offending input line}
474 @end example
475
476 A line-break is inserted in the offending line to indicate the column
477 where the error was found.  For example,
478
479 @example
480 test.ly:2:19: error: not a duration: 5
481   @{ c'4 e'
482            5 g' @}
483 @end example
484
485 These locations are LilyPond's best guess about where the warning or
486 error occurred, but (by their very nature) warnings and errors occur
487 when something unexpected happens.  If you can't see an error in the
488 indicated line of your input file, try checking one or two lines
489 above the indicated position.
490
491 More information about errors is given in @ref{Common errors}.
492
493
494 @node Common errors
495 @section Common errors
496
497 The error conditions described below occur often, yet the cause
498 is not obvious or easily found.  Once seen and understood, they
499 are easily handled.
500
501
502 @menu
503 * Music runs off the page::
504 * An extra staff appears::
505 * Apparent error in ../ly/init.ly::
506 * Error message Unbound variable %::
507 * Error message FT_Get_Glyph_Name::
508 @end menu
509
510 @node Music runs off the page
511 @unnumberedsubsec Music runs off the page
512
513 Music running off the page over the right margin or appearing
514 unduly compressed is almost always due to entering an incorrect
515 duration on a note, causing the final note in a measure to extend
516 over the bar line.  It is not invalid if the final note in a
517 measure does not end on the automatically entered bar line, as the
518 note is simply assumed to carry over into the next measure.  But
519 if a long sequence of such carry-over measures occurs the music
520 can appear compressed or may flow off the page because automatic
521 line breaks can be inserted only at the end of complete measures,
522 i.e., where all notes end before or at the end of the measure.
523
524 @warning{An incorrect duration can cause line breaks to be
525 inhibited, leading to a line of highly compressed music or
526 music which flows off the page.}
527
528 The incorrect duration can be found easily if bar checks are used,
529 see @ruser{Bar and bar number checks}.
530
531 If you actually intend to have a series of such carry-over measures
532 you will need to insert an invisible bar line where you want the
533 line to break.  For details, see @ruser{Bar lines}.
534
535
536 @node An extra staff appears
537 @unnumberedsubsec An extra staff appears
538
539 If contexts are not created explicitly with @code{\new} they will be
540 silently created as soon as a command is encountered which cannot
541 be applied to an existing context.  In simple scores the automatic
542 creation of contexts is useful, and most of the examples in the
543 LilyPond manuals take advantage of this simplification.  But
544 occasionally the silent creation of contexts can give rise to
545 unexpected new staves or scores.  For example, it might be expected
546 that the following code would cause all note heads within the
547 following staff to be colored red, but in fact it results in two
548 staves with the note heads remaining the default black in the lower
549 staff.
550
551 @lilypond[quote,verbatim,relative=2]
552 \override Staff.NoteHead #'color = #red
553 \new Staff { a }
554 @end lilypond
555
556 This is because a @code{Staff} context does not exist when the
557 override is processed, so one is implicitly created and the override
558 is applied to it, but then the @code{\new Staff} command creates
559 another, separate, staff into which the notes are placed.  The
560 correct code to color all note heads red is
561
562 @lilypond[quote,verbatim,relative=2]
563 \new Staff {
564   \override Staff.NoteHead #'color = #red
565   a
566 }
567 @end lilypond
568
569 As a second example, if a @code{\relative} command is placed inside
570 a @code{\repeat} command two staves result, the second offset from
571 the first, because the @code{\repeat} command generates two
572 @code{\relative} blocks, which each implicitly create @code{Staff}
573 and @code{Voice} blocks.
574
575 @lilypond[quote,verbatim]
576 \repeat unfold 2 {
577   \relative c' { c d e f }
578 }
579 @end lilypond
580
581 The correct way is to reverse the @code{\repeat} and
582 @code{\relative} commands, like this:
583
584 @lilypond[quote,verbatim]
585 \relative c' {
586   \repeat unfold 2 { c d e f }
587 }
588 @end lilypond
589
590
591 @node Apparent error in ../ly/init.ly
592 @unnumberedsubsec Apparent error in @code{../ly/init.ly}
593
594 Various obscure error messages may appear about syntax errors in
595 @code{../ly/init.ly} if the input file is not correctly formed,
596 for example, if it does not contain correctly
597 matched braces or quote signs.
598
599 The most common error is a missing brace, (@code{@}}), at the end of
600 a @code{score} block.  Here the solution is obvious: check the
601 @code{score} block is correctly terminated.  The correct structure
602 of an input file is described in @rlearning{How LilyPond input files work}.
603 Using an editor which automatically highlights matching brackets and
604 braces is helpful to avoid such errors.
605
606 A second common cause is no white space between the last syllable
607 of a lyrics block and the terminating brace, (@code{@}}).  Without
608 this separation the brace is taken to be part of the syllable.  It
609 is always advisable to ensure there is white space before and after
610 @emph{every} brace.  For the importance of this when using lyrics,
611 see @ruser{Lyrics explained}.
612
613 This error message can also appear if a terminating quote sign,
614 (@code{"}), is omitted.  In this case an accompanying error message
615 @c keep "-matching straight in fancy editors
616 should give a line number close to the line in error.  The
617 mismatched quote will usually be on the line one or two above.
618
619 @node Error message Unbound variable %
620 @unnumberedsubsec Error message Unbound variable %
621
622 This error message will appear at the bottom of the console
623 output or log file together with a @qq{GUILE signalled an error ...}
624 message every time a Scheme routine is called which (invalidly)
625 contains a @emph{LilyPond} rather than a @emph{Scheme} comment.
626
627 LilyPond comments begin with a percent sign, (@code{%}), and must
628 not be used within Scheme routines.  Scheme comments begin with a
629 semi-colon, (@code{;}).
630
631 @node Error message FT_Get_Glyph_Name
632 @unnumberedsubsec Error message FT_Get_Glyph_Name
633
634 This error messages appears in the console output or log file if
635 an input file contains a non-ASCII character and was not saved in
636 UTF-8 encoding.  For details, see @ruser{Text encoding}.
637
638
639