4.1 Suggestions for writing LilyPond files
Now you're ready to begin writing larger LilyPond files – not just the
little examples in the tutorial, but whole pieces. But how should you
go about doing it?
The best answer is “however you want to do it.” As long as LilyPond
can understand your files and produces the output that you want, it
doesn't matter what your files look like. That said, sometimes we
make mistakes when writing files. If LilyPond can't understand your
files, or produces output that you don't like, how do you fix the
problem?
Here are a few suggestions that can help you to avoid or fix
problems:
- Include
\version
numbers in every file. Note that all
templates contain a \version "2.8.0"
string. We
highly recommend that you always include the \version
, no matter
how small your file is. Speaking from personal experience, it's
quite frustrating to try to remember which version of LilyPond you were
using a few years ago. convert-ly
requires you to declare
which version of LilyPond you used.
- Include checks: Bar check and Octave check. If
you
include checks every so often, then if you make a mistake, you can pinpoint
it quicker. How often is “every so often”? It depends on the complexity
of the music. For very simple music, perhaps just once or twice. For
very complex music, perhaps every bar.
- One bar per line of text. If there is anything complicated,
either in the music
itself or in the output you desire, it's often good to write only one bar
per line. Saving screen space by cramming eight bars per line just isn't
worth it if you have to `debug' your files.
- Comment your files. Use either bar numbers (every so often)
or
references to musical themes (“second theme in violins,” “fourth
variation”, etc). You may not need comments when you're writing the piece
for the first time, but if you want to go back to change something two or
three years later, or if you pass the source over to a friend, it will
be much more
challenging to determine your intentions or how your file is structured if
you didn't comment the file.
- Indent your braces. A lot of problems are caused by an
imbalance
in the number of
{
and }
.