Integrating LaTeX and music - GNU LilyPond
Description: GNU LilyPond

Next: Integrating Texinfo and music, Previous: An example of a musicological document, Up: LilyPond-book

### 13.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

The short version

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

produces

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

The default line width 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 `line-width` 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. The default is to simply insert a `\linebreak`.

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 file`psfonts` 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.8.8 (stable-branch).

Other languages: English.
Using automatic language selection.