Next: , Previous: An example of a musicological document, Up: Integrating text and music



9.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.

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]

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 calls \preLilyPondExample before and \postLilyPondExample after the music if those macros have been defined by the user.

For printing the LaTeX document you need a DVI to PostScript translator like dvips. For producing PostScript with scalable fonts, add the following options to the dvips command line:

-Ppdf -u+lilypond.map -u+ec-mftrace.map

PDF can then be produced with a PostScript to PDF translator like ps2pdf (which is part of GhostScript).

LilyPond does not use the LaTeX font handling scheme for lyrics and text markups; it uses the EC font family and

so if you use characters in your lilypond-book documents that are not included in the standard US-ASCII character set, include \usepackage[latin1]{inputenc} in the file header but do not include \usepackage[T1]{fontenc}. Character sets other than latin1 are not supported directly but may be handled by explicitly specifying the font-name property in LilyPond and using the corresponding LaTeX packages. Please consult the mailing list for more details.

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

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

Other languages: English.
Using automatic language selection.