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