Next: , Previous: An example of a musicological document, Up: LilyPond-book



12.2 Integrating LaTeX and music

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.

Music is entered using

\begin[options,go,here]{lilypond}
  YOUR LILYPOND CODE
\end{lilypond}

or

\lilypondfile[options,go,here]{filename}

or

\lilypond{ YOUR LILYPOND CODE }

Running lilypond-book yields a file that can be further processed with LaTeX. Since lilypond-book produces lilypond snippets as \includegraphics{NAME.eps}, you must add

\usepackage{graphics}

or

\usepackage{graphicx}

to the preamble of the LaTeX document.

We show some examples here. The lilypond environment

\begin[quote,fragment,staffsize=26]{lilypond}
  c' d' e' f' g'2 g'2
\end{lilypond}

produces

[image of music]

The short version

\lilypond[quote,fragment,staffsize=11]{<c' e' g'>}

produces

[image of music]

Currently, you cannot include { or } within \lilypond{}, so this command is only useful with the fragment option.

The default linewidth of the music will be adjusted by examining the commands in the document preamble, 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 the 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 linewidth music fragment option.

Each snippet will call the following macros if they have been defined by the user:

\preLilyPondExample called before the music

\postLilyPondExample called after the music

\betweenLilyPondSystem[1] is called between systems if lilypond-book has split the snippet into several postscript files. It must be defined as taking one parameter and will be passed the number of files already included in this snippet.

For printing the LaTeX document you need a DVI to PostScript translator like dvips. To use dvips to produce a PostScript file, add the following options to the dvips command line:

-o -Ppdf -h file.psfonts

where the filepsfonts file is obtained from lilypond-book, See Invoking lilypond-book for details. PDF can then be produced with a PostScript to PDF translator like ps2pdf (which is part of GhostScript). Running dvips will produce some warnings about fonts; these are harmless and may be ignored.

This page is for LilyPond-2.6.3 (stable-branch).

Report errors to <bug-lilypond@gnu.org>.

Other languages: English.
Using automatic language selection.