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