]> git.donarmstrong.com Git - lilypond.git/blob - Documentation/usage/running.itely
Doc: Two doc improvements for LP CLI 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.  For details, see the Contributors'
8     Guide, node Updating translation committishes..
9 @end ignore
10
11 @c \version "2.15.18"
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 * LilyPond in chroot jail::
59 @end menu
60
61 @node Invoking lilypond
62 @unnumberedsubsec Invoking @command{lilypond}
63
64 The @command{lilypond} executable may be called as follows from
65 the command line.
66
67 @example
68 lilypond [@var{option}]@dots{} @var{file}@dots{}
69 @end example
70
71
72 When invoked with a filename that has no extension, the @file{.ly}
73 extension is tried first.  To read input from stdin, use a
74 dash (@code{-}) for @var{file}.
75
76 When @file{filename.ly} is processed it will produce @file{filename.ps}
77 and @file{filename.pdf} as output.  Several files can be specified;
78 they will each be processed independently.  @footnote{The status of
79 GUILE is not reset after processing a @code{.ly} file, so be careful
80 not to change any system defaults from within Scheme.}
81
82 If @file{filename.ly} contains more than one @code{\book}
83 block, then the rest of the scores will be output in numbered files,
84 starting with @file{filename-1.pdf}.  In addition, the value of
85 @code{output-suffix} will be inserted between the basename and the
86 number.  An input file containing
87
88 @example
89 #(define output-suffix "violin")
90 \score @{ @dots{} @}
91 #(define output-suffix "cello")
92 \score @{ @dots{} @}
93 @end example
94
95 @noindent
96 will output @var{base}@file{-violin.pdf} and
97 @var{base}@file{-cello-1.pdf}.
98
99
100 @unnumberedsubsubsec Standard shell commands
101
102 If your shell (i.e. command window) supports normal redirects,
103 then you might find it useful to use the following commands to
104 redirect console output to a file:
105
106 @itemize
107
108 @item
109 @code{lilypond file.ly 1>stdout.log} to redirect normal output
110
111 @item
112 @code{lilypond file.ly 2>stderr.log} to redirect error messages
113
114 @item
115 @code{lilypond file.ly &>all.log} to redirect all output
116
117 @end itemize
118
119 Consult the documentation for your shell to see if it supports these
120 options, or if the syntax is different.  Note that these are shell
121 commands and have nothing to do with lilypond.
122
123
124 @node Command line options for lilypond
125 @unnumberedsubsec Command line options for @command{lilypond}
126
127 @cindex Invoking @command{lilypond}
128 @cindex command line options for @command{lilypond}
129 @cindex options, command line
130 @cindex switches
131
132 The following options are supported:
133
134 @table @code
135
136 @item -e,--evaluate=@var{expr}
137 Evaluate the Scheme @var{expr} before parsing any @file{.ly} files.
138 Multiple @option{-e} options may be given, they will be evaluated
139 sequentially.
140
141 The expression will be evaluated in the @code{guile-user} module, so
142 if you want to use definitions in @var{expr}, use
143
144 @example
145 lilypond -e '(define-public a 42)'
146 @end example
147
148 @noindent
149 on the command-line, and include
150
151 @example
152 #(use-modules (guile-user))
153 @end example
154
155 @noindent
156 at the top of the @code{.ly} file.
157
158 @item -f,--format=@var{format}
159 which formats should be written.  Choices for @code{format} are
160 @code{ps}, @code{pdf}, and @code{png}.
161
162 Example: @code{lilypond -fpng @var{filename}.ly}
163
164
165
166 @item -d,--define-default=@var{var}=@var{val}
167 This sets the internal program option @var{var} to the Scheme value
168 @var{val}.  If @var{val} is not supplied, then @var{#t} is used.  To
169 switch off an option, @code{no-} may be prefixed to @var{var}, e.g.
170
171 @cindex point and click, command line
172
173 @example
174 -dno-point-and-click
175 @end example
176
177 @noindent
178 is the same as
179 @example
180 -dpoint-and-click='#f'
181 @end example
182
183 The following options are supported:
184
185 @cindex help, command line
186
187 @table @code
188
189 @item help
190 Running @code{lilypond -dhelp} will print all of the @option{-d} options
191 available.
192
193 @cindex paper-size, command line
194
195 @item paper-size
196 This option sets the default paper-size,
197 @example
198 -dpaper-size=\"letter\"
199 @end example
200
201 @noindent
202 Note that the string must be enclosed in escaped quotes ( @code{\"} ).
203 @c Match " in previous line to help context-sensitive editors
204
205 @cindex safe, command line
206
207 @item safe
208 Do not trust the @code{.ly} input.
209
210 When LilyPond formatting is available through a web server, either the
211 @option{--safe} or the @option{--jail} option @b{MUST} be passed.  The
212 @option{--safe} option will prevent inline Scheme code from wreaking
213 havoc, for example
214
215 @quotation
216 @verbatim
217 #(system "rm -rf /")
218 {
219   c4^$(ly:gulp-file "/etc/passwd")
220 }
221 @end verbatim
222 @end quotation
223
224 The @option{-dsafe} option works by evaluating in-line Scheme
225 expressions in a special safe module.  This safe module is derived from
226 GUILE @file{safe-r5rs} module, but adds a number of functions of the
227 LilyPond API.  These functions are listed in @file{scm/safe-lily.scm}.
228
229 In addition, safe mode disallows @code{\include} directives and
230 disables the use of backslashes in @TeX{} strings.
231
232 In safe mode, it is not possible to import LilyPond variables into
233 Scheme.
234
235 @option{-dsafe} does @emph{not} detect resource overuse.  It is still
236 possible to make the program hang indefinitely, for example by feeding
237 cyclic data structures into the backend.  Therefore, if using LilyPond
238 on a publicly accessible webserver, the process should be limited in
239 both CPU and memory usage.
240
241 Safe mode will prevent many useful LilyPond snippets from being
242 compiled.  The @option{--jail} is a more secure alternative, but
243 requires more work to set up.
244
245 @cindex output format, setting
246
247 @item backend
248 the output format to use for the backend.  Choices for @code{format}
249 are:
250
251 @table @code
252 @item ps
253
254 @cindex PostScript output
255
256 for PostScript.
257
258 Postscript files include TTF, Type1 and OTF fonts.  No subsetting of
259 these fonts is done.  When using oriental character sets, this can lead
260 to huge files.
261
262 @item eps
263
264 @cindex Postscript, encapsulated
265 @cindex EPS (Encapsulated PostScript)
266
267 for encapsulated PostScript.  This dumps every page (system) as a
268 separate @file{EPS} file, without fonts, and as one collated @file{EPS}
269 file with all pages (systems) including fonts.
270
271 This mode is used by default by @command{lilypond-book}.
272
273 @item svg
274
275 @cindex SVG (Scalable Vector Graphics)
276
277 for SVG (Scalable Vector Graphics).
278
279 This creates a single SVG file, without embedded fonts, for every page
280 of output.  It is recommended to install the Century Schoolbook fonts,
281 included with your LilyPond installation, for optimal rendering.  Under
282 UNIX, simply copy these fonts from the LilyPond directory (typically
283 @file{/usr/share/lilypond/VERSION/fonts/otf/}) to @file{~/.fonts/}.  The
284 SVG output should be compatible with any SVG editor or user agent.
285
286 @item scm
287
288 @cindex Scheme dump
289
290 for a dump of the raw, internal Scheme-based drawing commands.
291
292 @item null
293 do not output a printed score; has the same effect as
294 @option{-dno-print-pages}.
295 @end table
296
297 Example: @code{lilypond -dbackend=svg @var{filename}.ly}
298
299 @item preview
300
301 @cindex preview, command line
302
303 This option is supported by all backends; @code{pdf}, @code{png},
304 @code{ps}, @code{eps} and @code{svg}, but not @code{scm} and generates
305 an output file containing the titles and the first system of music.  If
306 @code{\bookpart} blocks are used, the titles and first system of every
307 @code{\bookpart} will appear in the output.
308
309 An additional file in the form @code{myFile.preview.extensio} is
310 generated, to avoid this use the additional @option{-dprint-pages} or
311 @option{-dno-print-pages} options according to your requirements.
312
313 @item gui
314 Runs silently and redirect all output to a log file.
315
316 Note to Windows users: By default @code{lilypond.exe} outputs all
317 progress information to the command window, @code{lilypond-windows.exe}
318 does not and returns a prompt, with no progress information, immediately
319 at the command line.  The @option{-dgui} option can be used in this case
320 to redirect output to a log file.
321
322 @item print-pages
323 Generate the full pages, the default.  @option{-dno-print-pages} is
324 useful in combination with @option{-dpreview}.
325
326 @end table
327
328 @item -h,--help
329 Show a summary of usage.
330
331 @item -H,--header=@var{FIELD}
332 Dump a header field to file @file{BASENAME.@var{FIELD}}.
333
334 @cindex file searching
335 @cindex search path
336
337 @item --include, -I=@var{directory}
338 Add @var{directory} to the search path for input files.
339
340 Multiple -I options may be given.  The search will start in the first
341 defined directory, and if the file to be included is not found the
342 search will continue in subsequent directories.
343
344 @item -i,--init=@var{file}
345 Set init file to @var{file} (default: @file{init.ly}).
346
347 @cindex loglevel
348 @cindex output verbosity, setting
349
350 @item -l,--loglevel=@var{LEVEL}
351 Set the verbosity of the console output to @var{LEVEL}. Possible values
352 are:
353
354 @table @code
355
356 @item NONE
357 No output at all, not even error messages.
358
359 @item ERROR
360 Only error messages, no warnings or progress messages.
361
362 @item WARN
363 Warnings and error messages, no progress.
364
365 @item BASIC_PROGRESS
366 Basic progress messages (success), warnings and errors.
367
368 @item PROGRESS
369 All progress messages, warnings and errors.
370
371 @item INFO (default)
372 Progress messages, warnings, errors and further execution information.
373
374 @item DEBUG
375 All possible messages, including verbose debug output.
376 @end table
377
378 @cindex folder, directing output to
379 @cindex output filename, setting
380
381 @item -o,--output=@var{FILE} or @var{FOLDER}
382 Set the default output file to @var{FILE} or, if a folder with that name
383 exists, direct the output to @var{FOLDER}, taking the file name from the
384 input file.  The appropriate suffix will be added (e.g. @code{.pdf} for
385 pdf) in both cases.
386
387
388 @cindex PostScript output
389
390 @item --ps
391 Generate PostScript.
392
393 @cindex Portable Network Graphics (PNG) output
394
395 @item --png
396 Generate pictures of each page, in PNG format.  This implies
397 @option{--ps}.  The resolution in DPI of the image may be set with
398 @example
399 -dresolution=110
400 @end example
401
402 @cindex Portable Document Format (PDF) output
403
404 @item --pdf
405 Generate PDF.  This implies @option{--ps}.
406
407
408
409 @item -j,--jail=@var{user},@var{group},@var{jail},@var{dir}
410 Run @command{lilypond} in a chroot jail.
411
412 The @option{--jail} option provides a more flexible alternative to
413 @option{--safe} when LilyPond formatting is available through a web
414 server or whenever LilyPond executes externally provided
415 sources.
416
417 The @option{--jail} option works by changing the root of
418 @command{lilypond} to @var{jail} just before starting the actual
419 compilation process.  The user and group are then changed to match those
420 provided, and the current directory is changed to @var{dir}.  This setup
421 guarantees that it is not possible (at least in theory) to escape from
422 the jail.  Note that for @option{--jail} to work @command{lilypond} must
423 be run as root, which is usually accomplished in a safe way using
424 @command{sudo}.
425
426 Setting up a jail is a slightly delicate matter, as we must be sure that
427 LilyPond is able to find whatever it needs to compile the source
428 @emph{inside the jail}.  A typical setup comprises the following items:
429
430 @table @asis
431 @item Setting up a separate filesystem
432 A separate filesystem should be created for LilyPond, so that it can be
433 mounted with safe options such as @code{noexec}, @code{nodev}, and
434 @code{nosuid}.  In this way, it is impossible to run executables or to
435 write directly to a device from LilyPond.  If you do not want to create a
436 separate partition, just create a file of reasonable size and use it to
437 mount a loop device.  A separate filesystem also guarantees that LilyPond
438 cannot write more space than it is allowed.
439
440 @item Setting up a separate user
441 A separate user and group (say, @code{lily}/@code{lily}) with low
442 privileges should be used to run LilyPond inside the jail.  There should
443 be a single directory writable by this user, which should be passed in
444 @var{dir}.
445
446 @item Preparing the jail
447 LilyPond needs to read a number of files while running.  All these files
448 are to be copied into the jail, under the same path they appear in the
449 real root filesystem.  The entire content of the LilyPond installation
450 (e.g., @file{/usr/share/lilypond})
451 should be copied.
452
453 If problems arise, the simplest way to trace them down is to run
454 LilyPond using @command{strace}, which will allow you to determine which
455 files are missing.
456
457 @item Running LilyPond
458 In a jail mounted with @code{noexec} it is impossible to execute any external
459 program.  Therefore LilyPond must be run with a backend that does not
460 require any such program.  As we already mentioned, it must be also run
461 with superuser privileges (which, of course, it will lose immediately),
462 possibly using @command{sudo}.  It is a good idea to limit the number of
463 seconds of CPU time LilyPond can use (e.g., using @command{ulimit
464 -t}), and, if your operating system supports it, the amount of memory
465 that can be allocated.
466 @end table
467
468
469 @item -v,--version
470 Show version information.
471
472 @item -V,--verbose
473 Be verbose: show full paths of all files read, and give timing
474 information.
475
476 @item -w,--warranty
477 Show the warranty with which GNU LilyPond comes.  (It comes with
478 @strong{NO WARRANTY}!)
479 @end table
480
481
482 @node Environment variables
483 @unnumberedsubsec Environment variables
484
485
486 @cindex LANG
487 @cindex LILYPOND_DATADIR
488
489 @command{lilypond} recognizes the following environment variables:
490 @table @code
491 @item LILYPOND_DATADIR
492 This specifies a directory where locale messages and
493 data files will be looked up by default.  The directory should contain
494 subdirectories called @file{ly/}, @file{ps/}, @file{tex/}, etc.
495
496 @item LANG
497 This selects the language for the warning messages.
498
499 @item LILYPOND_LOGLEVEL
500 The default loglevel. If LilyPond is called without an explicit loglevel (i.e.
501 no @option{--loglevel} command line option), this value is used.
502
503 @item LILYPOND_GC_YIELD
504 A variable, as a percentage, that tunes memory management
505 behavior.  A higher values means the program uses more memory, a
506 smaller value means more CPU time is used.  The default value is
507 @code{70}.
508
509 @end table
510
511
512 @node LilyPond in chroot jail
513 @unnumberedsubsec LilyPond in chroot jail
514
515 Setting up the server to run LilyPond in a chroot jail is a complicated
516 task.  The steps are listed below.  Examples in the steps are from
517 Ubuntu Linux, and may require the use of @code{sudo} as appropriate.
518
519 @itemize
520
521 @item Install the necessary packages: LilyPond, GhostScript, and ImageMagick.
522
523 @item Create a new user by the name of @code{lily}:
524
525 @example
526 adduser lily
527 @end example
528
529 @noindent
530 This will create a new group for the @code{lily} user as well, and a home folder,
531 @code{/home/lily}
532
533 @item In the home folder of the @code{lily} user create a file to use as a
534 separate filesystem:
535
536 @example
537 dd if=/dev/zero of=/home/lily/loopfile bs=1k count= 200000
538 @end example
539
540 @noindent
541 This example creates a 200MB file for use as the jail filesystem.
542
543 @item Create a loop device, make a file system and mount it, then create
544 a folder that can be written by the @code{lily} user:
545
546 @example
547 mkdir /mnt/lilyloop
548 losetup /dev/loop0 /home/lily/loopfile
549 mkfs -t ext3 /dev/loop0 200000
550 mount -t ext3 /dev/loop0 /mnt/lilyloop
551 mkdir /mnt/lilyloop/lilyhome
552 chown lily /mnt/lilyloop/lilyhome
553 @end example
554
555 @item In the configuration of the servers, the JAIL will be @code{/mnt/lilyloop}
556 and the DIR will be @code{/lilyhome}.
557
558 @item Create a big directory tree in the jail by copying the necessary files, as
559 shown in the sample script below.
560
561 You can use @code{sed} to create the necessary copy commands for a given
562 executable:
563
564 @example
565 for i in "/usr/local/lilypond/usr/bin/lilypond" "/bin/sh" "/usr/bin/;  \
566   do ldd $i | sed 's/.*=> \/\(.*\/\)\([^(]*\).*/mkdir -p \1 \&\&  \
567     cp -L \/\1\2 \1\2/' | sed 's/\t\/\(.*\/\)\(.*\) (.*)$/mkdir -p  \
568       \1 \&\& cp -L \/\1\2 \1\2/' | sed '/.*=>.*/d'; done
569 @end example
570
571 @end itemize
572
573 @subheading Example script for 32-bit Ubuntu 8.04
574
575 @example
576 #!/bin/sh
577 ## defaults set here
578
579 username=lily
580 home=/home
581 loopdevice=/dev/loop0
582 jaildir=/mnt/lilyloop
583 # the prefix (without the leading slash!)
584 lilyprefix=usr/local
585 # the directory where lilypond is installed on the system
586 lilydir=/$lilyprefix/lilypond/
587
588 userhome=$home/$username
589 loopfile=$userhome/loopfile
590 adduser $username
591 dd if=/dev/zero of=$loopfile bs=1k count=200000
592 mkdir $jaildir
593 losetup $loopdevice $loopfile
594 mkfs -t ext3 $loopdevice 200000
595 mount -t ext3 $loopdevice $jaildir
596 mkdir $jaildir/lilyhome
597 chown $username $jaildir/lilyhome
598 cd $jaildir
599
600 mkdir -p bin usr/bin usr/share usr/lib usr/share/fonts $lilyprefix tmp
601 chmod a+w tmp
602
603 cp -r -L $lilydir $lilyprefix
604 cp -L /bin/sh /bin/rm bin
605 cp -L /usr/bin/convert /usr/bin/gs usr/bin
606 cp -L /usr/share/fonts/truetype usr/share/fonts
607
608 # Now the library copying magic
609 for i in "$lilydir/usr/bin/lilypond" "$lilydir/usr/bin/guile" "/bin/sh"  \
610   "/bin/rm" "/usr/bin/gs" "/usr/bin/convert"; do ldd $i | sed 's/.*=>  \
611     \/\(.*\/\)\([^(]*\).*/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/' | sed  \
612       's/\t\/\(.*\/\)\(.*\) (.*)$/mkdir -p \1 \&\& cp -L \/\1\2 \1\2/'  \
613         | sed '/.*=>.*/d'; done | sh -s
614
615 # The shared files for ghostscript...
616       cp -L -r /usr/share/ghostscript usr/share
617 # The shared files for ImageMagick
618       cp -L -r /usr/lib/ImageMagick* usr/lib
619
620 ### Now, assuming that you have test.ly in /mnt/lilyloop/lilyhome,
621 ### you should be able to run:
622 ### Note that /$lilyprefix/bin/lilypond is a script, which sets the
623 ### LD_LIBRARY_PATH - this is crucial
624       /$lilyprefix/bin/lilypond -jlily,lily,/mnt/lilyloop,/lilyhome test.ly
625 @end example
626
627 @c " keep quote signs balanced for context-sensitive editors
628
629 @node Error messages
630 @section Error messages
631
632 @cindex error messages
633 Different error messages can appear while compiling a file:
634
635 @table @emph
636
637 @item Warning
638 @cindex warning
639 Something looks suspect.  If you are requesting something out of the
640 ordinary then you will understand the message, and can ignore it.
641 However, warnings usually indicate that something is wrong with the
642 input file.
643
644 @item Error
645 @cindex error
646 Something is definitely wrong.  The current processing step (parsing,
647 interpreting, or formatting) will be finished, but the next step will
648 be skipped.
649
650 @item Fatal error
651 @cindex fatal error
652 Something is definitely wrong, and LilyPond cannot continue.  This
653 happens rarely.  The most usual cause is misinstalled fonts.
654
655 @item Scheme error
656 @cindex trace, Scheme
657 @cindex call trace
658 @cindex Scheme error
659 Errors that occur while executing Scheme code are caught by the Scheme
660 interpreter.  If running with the verbose option (@option{-V} or
661 @option{--verbose}) then a call trace of the offending
662 function call is printed.
663
664 @item Programming error
665 @cindex Programming error
666 There was some internal inconsistency.  These error messages are
667 intended to help the programmers and debuggers.  Usually, they can be
668 ignored.  Sometimes, they come in such big quantities that they obscure
669 other output.
670
671 @item Aborted (core dumped)
672 @cindex Aborted (core dumped)
673 This signals a serious programming error that caused the program to
674 crash.  Such errors are considered critical.  If you stumble on one,
675 send a bug-report.
676 @end table
677
678 @cindex errors, message format
679 If warnings and errors can
680 be linked to some part of the input file, then error messages have the
681 following form
682
683 @example
684 @var{filename}:@var{lineno}:@var{columnno}: @var{message}
685 @var{offending input line}
686 @end example
687
688 A line-break is inserted in the offending line to indicate the column
689 where the error was found.  For example,
690
691 @example
692 test.ly:2:19: error: not a duration: 5
693   @{ c'4 e'
694            5 g' @}
695 @end example
696
697 These locations are LilyPond's best guess about where the warning or
698 error occurred, but (by their very nature) warnings and errors occur
699 when something unexpected happens.  If you can't see an error in the
700 indicated line of your input file, try checking one or two lines
701 above the indicated position.
702
703 More information about errors is given in @ref{Common errors}.
704
705
706 @node Common errors
707 @section Common errors
708
709 The error conditions described below occur often, yet the cause
710 is not obvious or easily found.  Once seen and understood, they
711 are easily handled.
712
713
714 @menu
715 * Music runs off the page::
716 * An extra staff appears::
717 * Apparent error in ../ly/init.ly::
718 * Error message Unbound variable %::
719 * Error message FT_Get_Glyph_Name::
720 * Warning staff affinities should only decrease::
721 @end menu
722
723 @node Music runs off the page
724 @unnumberedsubsec Music runs off the page
725
726 Music running off the page over the right margin or appearing
727 unduly compressed is almost always due to entering an incorrect
728 duration on a note, causing the final note in a measure to extend
729 over the bar line.  It is not invalid if the final note in a
730 measure does not end on the automatically entered bar line, as the
731 note is simply assumed to carry over into the next measure.  But
732 if a long sequence of such carry-over measures occurs the music
733 can appear compressed or may flow off the page because automatic
734 line breaks can be inserted only at the end of complete measures,
735 i.e., where all notes end before or at the end of the measure.
736
737 @warning{An incorrect duration can cause line breaks to be
738 inhibited, leading to a line of highly compressed music or
739 music which flows off the page.}
740
741 The incorrect duration can be found easily if bar checks are used,
742 see @ruser{Bar and bar number checks}.
743
744 If you actually intend to have a series of such carry-over measures
745 you will need to insert an invisible bar line where you want the
746 line to break.  For details, see @ruser{Bar lines}.
747
748
749 @node An extra staff appears
750 @unnumberedsubsec An extra staff appears
751
752 If contexts are not created explicitly with @code{\new} or
753 @code{\context}, they will be silently created as soon as a
754 command is encountered which cannot be applied to an existing
755 context.  In simple scores the automatic creation of contexts is
756 useful, and most of the examples in the LilyPond manuals take
757 advantage of this simplification.  But occasionally the silent
758 creation of contexts can give rise to unexpected new staves or
759 scores.  For example, it might be expected that the following code
760 would cause all note heads within the following staff to be
761 colored red, but in fact it results in two staves with the note
762 heads remaining the default black in the lower staff.
763
764 @lilypond[quote,verbatim,relative=2]
765 \override Staff.NoteHead #'color = #red
766 \new Staff { a }
767 @end lilypond
768
769 This is because a @code{Staff} context does not exist when the
770 override is processed, so one is implicitly created and the override
771 is applied to it, but then the @code{\new Staff} command creates
772 another, separate, staff into which the notes are placed.  The
773 correct code to color all note heads red is
774
775 @lilypond[quote,verbatim,relative=2]
776 \new Staff {
777   \override Staff.NoteHead #'color = #red
778   a
779 }
780 @end lilypond
781
782 As a second example, if a @code{\relative} command is placed inside
783 a @code{\repeat} command, two staves result, the second offset from
784 the first, because the @code{\repeat} command generates two
785 @code{\relative} blocks, which each implicitly create @code{Staff}
786 and @code{Voice} blocks.
787
788 @lilypond[quote,verbatim]
789 \repeat unfold 2 {
790   \relative c' { c4 d e f }
791 }
792 @end lilypond
793
794 Explicitly instantiating the @code{Voice} context fixes the
795 problem:
796
797 @lilypond[quote,verbatim]
798 \new Voice {
799   \repeat unfold 2 {
800     \relative c' { c4 d e f }
801   }
802 }
803 @end lilypond
804
805
806 @node Apparent error in ../ly/init.ly
807 @unnumberedsubsec Apparent error in @code{../ly/init.ly}
808
809 Various obscure error messages may appear about syntax errors in
810 @file{../ly/init.ly} if the input file is not correctly formed,
811 for example, if it does not contain correctly
812 matched braces or quote signs.
813
814 The most common error is a missing brace, (@code{@}}), at the end of
815 a @code{score} block.  Here the solution is obvious: check the
816 @code{score} block is correctly terminated.  The correct structure
817 of an input file is described in @rlearning{How LilyPond input files work}.
818 Using an editor which automatically highlights matching brackets and
819 braces is helpful to avoid such errors.
820
821 A second common cause is no white space between the last syllable
822 of a lyrics block and the terminating brace, (@code{@}}).  Without
823 this separation the brace is taken to be part of the syllable.  It
824 is always advisable to ensure there is white space before and after
825 @emph{every} brace.  For the importance of this when using lyrics,
826 see @ruser{Entering lyrics}.
827
828 This error message can also appear if a terminating quote sign,
829 (@code{"}), is omitted.  In this case an accompanying error message
830 @c keep "-matching straight in fancy editors
831 should give a line number close to the line in error.  The
832 mismatched quote will usually be on the line one or two above.
833
834 @node Error message Unbound variable %
835 @unnumberedsubsec Error message Unbound variable %
836
837 This error message will appear at the bottom of the console
838 output or log file together with a @qq{GUILE signalled an error @dots{}}
839 message every time a Scheme routine is called which (invalidly)
840 contains a @emph{LilyPond} rather than a @emph{Scheme} comment.
841
842 LilyPond comments begin with a percent sign, (@code{%}), and must
843 not be used within Scheme routines.  Scheme comments begin with a
844 semi-colon, (@code{;}).
845
846 @node Error message FT_Get_Glyph_Name
847 @unnumberedsubsec Error message FT_Get_Glyph_Name
848
849 This error messages appears in the console output or log file if
850 an input file contains a non-ASCII character and was not saved in
851 UTF-8 encoding.  For details, see @ruser{Text encoding}.
852
853
854 @node Warning staff affinities should only decrease
855 @unnumberedsubsec Warning staff affinities should only decrease
856 This warning can appear if there are no staves in the printed
857 output, for example if there are just a @code{ChordName} context
858 and a @code{Lyrics} context as in a lead sheet.  The warning
859 messages can be avoided by making one of the contexts behave as a
860 staff by inserting
861
862 @example
863 \override VerticalAxisGroup #'staff-affinity = ##f
864 @end example
865
866 @noindent
867 at its start.  For details, see @qq{Spacing of non-staff lines} in
868 @ruser{Flexible vertical spacing within systems}.