1 @c -*- coding: utf-8; mode: texinfo; -*-
4 Translation of GIT committish: FILL-IN-HEAD-COMMITTISH
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..
13 @node Suggestions for writing files
14 @chapter Suggestions for writing files
16 Now you're ready to begin writing larger LilyPond input files --
17 not just the little examples in the tutorial, but whole pieces.
18 But how should you go about doing it?
20 As long as LilyPond can understand your input files and produce
21 the output that you want, it doesn't matter what your input files
22 look like. However, there are a few other things to consider when
23 writing LilyPond input files.
26 @item What if you make a mistake? The structure of a LilyPond
27 file can make certain errors easier (or harder) to find.
29 @item What if you want to share your input files with somebody
30 else? In fact, what if you want to alter your own input files in
31 a few years? Some LilyPond input files are understandable at
32 first glance; others may leave you scratching your head
35 @item What if you want to upgrade your LilyPond file for use
36 with a later version of LilyPond? The input syntax changes
37 occasionally as LilyPond improves. Most changes can be
38 done automatically with @code{convert-ly}, but some changes
39 might require manual assistance. LilyPond input files can be
40 structured in order to be easier (or harder) to update.
45 * General suggestions::
46 * Typesetting existing music::
49 * Make and Makefiles::
53 @node General suggestions
54 @section General suggestions
56 Here are a few suggestions that can help you to avoid or fix
60 @item @strong{Include @code{\version} numbers in every file}. Note that all
61 templates contain @code{\version} information. We
62 highly recommend that you always include the @code{\version}, no matter
63 how small your file is. Speaking from personal experience, it's
64 quite frustrating to try to remember which version of LilyPond you were
65 using a few years ago. @command{convert-ly} requires you to declare
66 which version of LilyPond you used.
68 @item @strong{Include checks}: @ruser{Bar and bar number checks},
69 @ruser{Octave checks}. If you include checks every so often, then
70 if you make a mistake, you can pinpoint it quicker. How often is
71 @q{every so often}? It depends on the complexity of the music.
72 For very simple music, perhaps just once or twice. For very
73 complex music, perhaps every bar.
75 @item @strong{One bar per line of text}. If there is anything complicated,
77 itself or in the output you desire, it's often good to write only one bar
78 per line. Saving screen space by cramming eight bars per line just isn't
79 worth it if you have to @q{debug} your input files.
81 @item @strong{Comment your input files}. Use either bar numbers
83 references to musical themes (@q{second theme in violins,} @q{fourth
84 variation,} etc.). You may not need comments when you're writing the piece
85 for the first time, but if you want to go back to change something two or
86 three years later, or if you pass the source over to a friend, it will
88 challenging to determine your intentions or how your file is structured if
89 you didn't comment the file.
91 @item @strong{Indent your braces}. A lot of problems are caused by an
93 in the number of @code{@{} and @code{@}}.
95 @item @strong{Explicitly add durations} at the beginnings of sections
96 and variables. If you specify @code{c4 d e} at the beginning of a
97 phrase (instead of just @code{c d e}) you can save yourself some
98 problems if you rearrange your music later.
100 @item @strong{Separate tweaks} from music definitions. See
101 @rlearning{Saving typing with variables and functions}, and
102 @rlearning{Style sheets}.
107 @node Typesetting existing music
108 @section Typesetting existing music
110 If you are entering music from an existing score (i.e., typesetting a
111 piece of existing sheet music),
115 @item Enter the manuscript (the physical copy of the music) into
116 LilyPond one system at a time (but still only one bar per line of text),
117 and check each system when you finish it. You may use the
118 @code{showLastLength} or @code{showFirstLength} properties to speed up
119 processing -- see @ruser{Skipping corrected music}.
121 @item Define @code{mBreak = @{ \break @}} and insert @code{\mBreak}
122 in the input file whenever the manuscript has a line break. This
123 makes it much easier to compare the LilyPond music to the original
124 music. When you are finished proofreading your score, you may
125 define @code{mBreak = @{ @}} to remove all those line breaks. This
126 will allow LilyPond to place line breaks wherever it feels are
129 @item When entering a part for a transposing instrument into a
130 variable, it is recommended that the notes are wrapped in
133 \transpose c natural-pitch @{...@}
137 (where @code{natural-pitch} is the open pitch of the instrument) so
138 that the music in the variable is effectively in C. You can transpose
139 it back again when the variable is used, if required, but you might
140 not want to (e.g., when printing a score in concert pitch,
141 converting a trombone part from treble to bass clef, etc.)
142 Mistakes in transpositions are less likely if all the music in
143 variables is at a consistent pitch.
145 Also, only ever transpose to/from C. That means that the only other
146 keys you will use are the natural pitches of the instruments - bes
147 for a B-flat trumpet, aes for an A-flat clarinet, etc.
153 @section Large projects
155 When working on a large project, having a clear structure to your
156 lilypond input files becomes vital.
160 @item @strong{Use a variable for each voice}, with a minimum of
161 structure inside the definition. The structure of the
162 @code{\score} section is the most likely thing to change;
163 the @code{violin} definition is extremely unlikely to change
164 in a new version of LilyPond.
167 violin = \relative c'' @{
180 @item @strong{Separate tweaks from music definitions}. This
181 point was made previously, but for large
182 projects it is absolutely vital. We might need to change
183 the definition of @code{fthenp}, but then we only need
184 to do this once, and we can still avoid touching anything
185 inside @code{violin}.
189 \dynamic f \italic \small @{ 2nd @} \hspace #0.1 \dynamic p @}
190 violin = \relative c'' @{
198 @node Troubleshooting
199 @section Troubleshooting
201 Sooner or later, you will write a file that LilyPond cannot
202 compile. The messages that LilyPond gives may help
203 you find the error, but in many cases you need to do some
204 investigation to determine the source of the problem.
206 The most powerful tools for this purpose are the
207 single line comment (indicated by @code{%}) and the block
208 comment (indicated by @code{%@{ ... %@}}). If you don't
209 know where a problem is, start commenting out huge portions
210 of your input file. After you comment out a section, try
211 compiling the file again. If it works, then the problem
212 must exist in the portion you just commented. If it doesn't
213 work, then keep on commenting out material until you have
214 something that works.
216 In an extreme case, you might end up with only
230 (in other words, a file without any music)
232 If that happens, don't give up. Uncomment a bit -- say,
233 the bass part -- and see if it works. If it doesn't work,
234 then comment out all of the bass music (but leave
235 @code{\bass} in the @code{\score} uncommented.
238 bass = \relative c' @{
246 Now start slowly uncommenting more and more of the
247 @code{bass} part until you find the problem line.
249 Another very useful debugging technique is constructing
250 @rweb{Tiny examples}.
253 @node Make and Makefiles
254 @section Make and Makefiles
259 Pretty well all the platforms Lilypond can run on support a software
260 facility called @code{make}. This software reads a special file called a
261 @code{Makefile} that defines what files depend on what others and what
262 commands you need to give the operating system to produce one file from
263 another. For example the makefile would spell out how to produce
264 @file{ballad.pdf} and @file{ballad.midi} from @file{ballad.ly} by
267 There are times when it is a good idea to create a @code{Makefile}
268 for your project, either for your own convenience or
269 as a courtesy to others who might have access to your source files.
270 This is true for very large projects with many included files and
271 different output options (e.g. full score, parts, conductor's
272 score, piano reduction, etc.), or for projects that
273 require difficult commands to build them (such as
274 @code{lilypond-book} projects). Makefiles vary greatly in
275 complexity and flexibility, according to the needs and skills of
276 the authors. The program GNU Make comes installed on GNU/Linux
277 distributions and on MacOS X, and it is also available for Windows.
279 See the @strong{GNU Make Manual} for full details on using
280 @code{make}, as what follows here gives only a glimpse of what it
283 The commands to define rules in a makefile differ
284 according to platform; for instance the various forms of Linux and
285 MacOS use @code{bash}, while Windows uses @code{cmd}. Note that on
286 MacOS X, you need to configure the system to use the command-line
287 interpreter. Here are some example makefiles, with versions for both
288 Linux/MacOS and Windows.
290 The first example is for an orchestral work in four
291 movements with a directory structure as follows:
308 | |-- symphony-cello.ly
309 | |-- symphony-horn.ly
310 | |-- symphony-oboes.ly
311 | |-- symphony-viola.ly
312 | |-- symphony-violinOne.ly
313 | `-- symphony-violinTwo.ly
323 The @file{.ly} files in the @file{Scores} and
324 @file{Parts} directories get their notes from @file{.ily}
325 files in the @file{Notes} directory:
328 %%% top of file "symphony-cello.ly"
329 \include ../symphonyDefs.ily
330 \include ../Notes/cello.ily
333 The makefile will have targets of @code{score} (entire piece in
334 full score), @code{movements} (individual movements in full score),
335 and @code{parts} (individual parts for performers). There
336 is also a target @code{archive} that will create a tarball of
337 the source files, suitable for sharing via web or email. Here is
338 the makefile for GNU/Linux or MacOS X. It should be saved with the
339 name @code{Makefile} in the top directory of the project:
341 @warning{When a target or pattern rule is defined, the
342 subsequent lines must begin with tabs, not spaces.}
345 # the name stem of the output files
347 # determine how many processors are present
348 CPU_CORES=`cat /proc/cpuinfo | grep -m1 "cpu cores" | sed s/".*: "//`
349 # The command to run lilypond
350 LILY_CMD = lilypond -ddelete-intermediate-files \
351 -dno-point-and-click -djob-count=$(CPU_CORES)
353 # The suffixes used in this Makefile.
354 .SUFFIXES: .ly .ily .pdf .midi
356 # Input and output files are searched in the directories listed in
357 # the VPATH variable. All of them are subdirectories of the current
358 # directory (given by the GNU make variable `CURDIR').
365 # The pattern rule to create PDF and MIDI files from a LY input file.
366 # The .pdf output files are put into the `PDF' subdirectory, and the
367 # .midi files go into the `MIDI' subdirectory.
369 $(LILY_CMD) $<; \ # this line begins with a tab
370 if test -f "$*.pdf"; then \
373 if test -f "$*.midi"; then \
374 mv "$*.midi" MIDI/; \
385 # The dependencies of the movements.
386 $(piece)I.pdf: $(piece)I.ly $(notes)
387 $(piece)II.pdf: $(piece)II.ly $(notes)
388 $(piece)III.pdf: $(piece)III.ly $(notes)
389 $(piece)IV.pdf: $(piece)IV.ly $(notes)
391 # The dependencies of the full score.
392 $(piece).pdf: $(piece).ly $(notes)
394 # The dependencies of the parts.
395 $(piece)-cello.pdf: $(piece)-cello.ly cello.ily
396 $(piece)-horn.pdf: $(piece)-horn.ly horn.ily
397 $(piece)-oboes.pdf: $(piece)-oboes.ly oboe.ily
398 $(piece)-viola.pdf: $(piece)-viola.ly viola.ily
399 $(piece)-violinOne.pdf: $(piece)-violinOne.ly violinOne.ily
400 $(piece)-violinTwo.pdf: $(piece)-violinTwo.ly violinTwo.ily
402 # Type `make score' to generate the full score of all four
403 # movements as one file.
407 # Type `make parts' to generate all parts.
408 # Type `make foo.pdf' to generate the part for instrument `foo'.
409 # Example: `make symphony-cello.pdf'.
411 parts: $(piece)-cello.pdf \
412 $(piece)-violinOne.pdf \
413 $(piece)-violinTwo.pdf \
418 # Type `make movements' to generate files for the
419 # four movements separately.
421 movements: $(piece)I.pdf \
426 all: score parts movements
429 tar -cvvf stamitz.tar \ # this line begins with a tab
430 --exclude=*pdf --exclude=*~ \
431 --exclude=*midi --exclude=*.tar \
436 There are special complications on the Windows platform. After
437 downloading and installing GNU Make for Windows, you must set the
438 correct path in the system's environment variables so that the
439 DOS shell can find the Make program. To do this, right-click on
440 "My Computer," then choose @code{Properties} and
441 @code{Advanced}. Click @code{Environment Variables}, and then
442 in the @code{System Variables} pane, highlight @code{Path}, click
443 @code{edit}, and add the path to the GNU Make executable file, which
444 will look something like this:
447 C:\Program Files\GnuWin32\bin
450 The makefile itself has to be altered to handle different shell
451 commands and to deal with spaces that are present
452 in some default system directories. The @code{archive} target
453 is eliminated since Windows does not have the @code{tar} command,
454 and Windows also has a different default extension for midi files.
461 LILY_CMD = lilypond -ddelete-intermediate-files \
462 -dno-point-and-click \
463 -djob-count=$(NUMBER_OF_PROCESSORS)
465 #get the 8.3 name of CURDIR (workaround for spaces in PATH)
466 workdir = $(shell for /f "tokens=*" %%b in ("$(CURDIR)") \
469 .SUFFIXES: .ly .ily .pdf .mid
478 $(LILY_CMD) $< # this line begins with a tab
479 if exist "$*.pdf" move /Y "$*.pdf" PDF/ # begin with tab
480 if exist "$*.mid" move /Y "$*.mid" MIDI/ # begin with tab
492 $(piece)I.pdf: $(piece)I.ly $(notes)
493 $(piece)II.pdf: $(piece)II.ly $(notes)
494 $(piece)III.pdf: $(piece)III.ly $(notes)
495 $(piece)IV.pdf: $(piece)IV.ly $(notes)
497 $(piece).pdf: $(piece).ly $(notes)
499 $(piece)-cello.pdf: $(piece)-cello.ly cello.ily
500 $(piece)-horn.pdf: $(piece)-horn.ly horn.ily
501 $(piece)-oboes.pdf: $(piece)-oboes.ly oboe.ily
502 $(piece)-viola.pdf: $(piece)-viola.ly viola.ily
503 $(piece)-violinOne.pdf: $(piece)-violinOne.ly violinOne.ily
504 $(piece)-violinTwo.pdf: $(piece)-violinTwo.ly violinTwo.ily
510 parts: $(piece)-cello.pdf \
511 $(piece)-violinOne.pdf \
512 $(piece)-violinTwo.pdf \
518 movements: $(piece)I.pdf \
523 all: score parts movements
527 The next Makefile is for a @command{lilypond-book} document done in
528 LaTeX. This project has an index, which requires that the
529 @command{latex} command be run twice to update links. Output files are
530 all stored in the @code{out} directory for .pdf output and in the
531 @code{htmlout} directory for the html output.
540 LILYBOOK_PDF=lilypond-book --output=$(OUTDIR) --pdf $(FILE).lytex
541 LILYBOOK_HTML=lilypond-book --output=$(WEBDIR) $(FILE).lytex
542 PDF=cd $(OUTDIR) && pdflatex $(FILE)
543 HTML=cd $(WEBDIR) && latex2html $(FILE)
544 INDEX=cd $(OUTDIR) && makeindex $(FILE)
545 PREVIEW=$(VIEWER) $(OUTDIR)/$(FILE).pdf &
550 $(LILYBOOK_PDF) # begin with tab
551 $(PDF) # begin with tab
552 $(INDEX) # begin with tab
553 $(PDF) # begin with tab
554 $(PREVIEW) # begin with tab
557 $(LILYBOOK_HTML) # begin with tab
558 $(HTML) # begin with tab
559 cp -R $(WEBDIR)/$(FILE)/ ./ # begin with tab
560 $(BROWSER) $(FILE)/$(FILE).html & # begin with tab
563 cp $(OUTDIR)/$(FILE).pdf $(FILE).pdf # begin with tab
566 rm -rf $(OUTDIR) # begin with tab
569 rm -rf $(WEBDIR) # begin with tab
572 tar -cvvf myproject.tar \ # begin this line with tab
574 --exclude=htmlout/* \
575 --exclude=myproject/* \
582 TODO: make this thing work on Windows
584 The previous makefile does not work on Windows. An alternative
585 for Windows users would be to create a simple batch file
586 containing the build commands. This will not
587 keep track of dependencies the way a makefile does, but it at
588 least reduces the build process to a single command. Save the
589 following code as @command{build.bat} or @command{build.cmd}.
590 The batch file can be run at the DOS prompt or by simply
591 double-clicking its icon.
594 lilypond-book --output=out --pdf myproject.lytex
600 copy out\myproject.pdf MyProject.pdf
607 @ref{Command-line usage},