[ << Running lilypond-book ] | [Top][Contents][Index] | [ External programs >> ] |
[ < Integrating music and text ] | [ Up : Integrating music and text ] | [ Texinfo > ] |
3.2.1 LaTeX
LaTeX is the de-facto standard for publishing layouts in the exact sciences. It is built on top of the TeX typesetting engine, providing the best typography available anywhere.
See The Not So Short Introduction to LaTeX for an overview on how to use LaTeX.
lilypond-book
provides the following commands and environments to
include music in LaTeX files:
- the
\lilypond{…}
command to directly enter short LilyPond code, - the
\begin{lilypond}…\end{lilypond}
environment to directly enter longer LilyPond code, - the
\lilypondfile{…}
command to insert a LilyPond file, - the
\musicxmlfile{…}
command to insert a MusicXML file, which gets processed bymusicxml2ly
andlilypond
.
In the input file, music is specified with any of the following commands:
\begin{lilypond}[options,go,here] YOUR LILYPOND CODE \end{lilypond} \lilypond[options,go,here]{ YOUR LILYPOND CODE } \lilypondfile[options,go,here]{filename} \musicxmlfile[options,go,here]{filename}
Additionally, \lilypondversion
displays the current version
of LilyPond.
Running lilypond-book
yields a file that can be further
processed with LaTeX.
We show some examples here. The lilypond
environment
\begin{lilypond}[quote,fragment,staffsize=26] c'4 d' e' f' g'2 g' \end{lilypond}
produces
The short version
\lilypond[quote,fragment,staffsize=11]{<c' e' g'>}
produces
The default line width of the music is computed by examining the
commands in the document preamble (that is, the part of the document before
\begin{document}
). The lilypond-book
command sends
these to LaTeX to find out how wide the text is. The line width for
music fragments is then adjusted to the text width. Note that this
heuristic algorithm can fail easily; in such cases it is necessary to
use the line-width
music fragment option.
Note: Make sure that your preamble actually compiles without
errors, otherwise line width detection will fail. You can test
this by directly processing your document with LaTeX, using an
empty \begin{document} ... \end{document}
block.
If you use a landscape paper format, be sure to add the keyword
landscape
to the option list of the \documentclass
macro.6
Each snippet calls the following macros if they have been defined by the user:
-
\preLilyPondExample
is called before the music, -
\postLilyPondExample
is called after the music, -
\betweenLilyPondSystem[1]
is called between systems iflilypond-book
splits the snippet into several chunks. It must be defined as taking one parameter, which is the number of files already included in this snippet. The default is to simply insert\linebreak
.
Selected Snippets
Sometimes it is useful to display music elements (such as ties and slurs) as if they continued after the end of the fragment. This can be done by breaking the staff and suppressing inclusion of the rest of the LilyPond output.
In LaTeX, define \betweenLilyPondSystem
in such a way that
inclusion of other systems is terminated once the required number of
systems are included. Since \betweenLilyPondSystem
is first
called after the first system, including only the first system
is trivial.
\def\betweenLilyPondSystem#1{\endinput} \begin{lilypond}[fragment] c'1\( e'( c'~ \break c' d) e f\) \end{lilypond}
If a greater number of systems is requested, a TeX conditional must
be used before \endinput
. In this example, replace value 2 by
the number of systems you want in the output.
\def\betweenLilyPondSystem#1{ \ifnum#1<2\else\expandafter\endinput\fi }
(Since \endinput
immediately stops the processing of the current
input file we need \expandafter
to delay the call of \endinput
after executing \fi
so that the \if ... \fi
clause is
balanced.)
Remember that the definition of \betweenLilyPondSystem
is
effective until the current group is finished (such as the LaTeX
environment) or is overridden by another definition (which it is, in
most cases, for the rest of the document). To reset your
definition, write
\let\betweenLilyPondSystem\undefined
in your LaTeX source.
This may be simplified by defining a TeX macro
\def\onlyFirstNSystems#1{ \def\betweenLilyPondSystem##1{% \ifnum##1<#1\else\expandafter\endinput\fi} }
and then saying only how many systems you want before each fragment,
\onlyFirstNSystems{3} \begin{lilypond}…\end{lilypond} \onlyFirstNSystems{1} \begin{lilypond}…\end{lilypond}
See also
There are specific lilypond-book
command-line options and
other details to know when processing LaTeX documents, see
Invoking lilypond-book
.
Footnotes
(6)
This is necessary because lilypond-book
adds \usepackage{graphics}
to the preamble if neither the
graphics
nor the graphicx
package gets loaded; this
might change the paper dimensions unexpectedly for some document
classes.
[ << Running lilypond-book ] | [Top][Contents][Index] | [ External programs >> ] |
[ < Integrating music and text ] | [ Up : Integrating music and text ] | [ Texinfo > ] |