[icon]

GNU LilyPond

Welcome to the home of the GNU Music Typesetter

What is LilyPond
General information
Simple examples
Complex examples
Download
GNU/Linux binaries
Windows
Source code
Documentation
Tutorial
Manual
Glossary
other ...

Support
Mailing lists
Search
WikiWiki
FAQs

External sites
lilypond.org/development
lilypond.org/stable
ftp.lilypond.org
Mutopia
Other music online

Node:Integrating text and music, Next:, Previous:Other ways to run LilyPond, Up:Tutorial



Integrating text and music

Sometimes, you might want to use music examples in a text that you are writing. For example, if you are writing a musicological treatise, a songbook, or (like us) the LilyPond manual. You can make such texts by hand, simply by importing a PostScript figure into your wordprocessor. However, there is a also an automated procedure:

If you use LaTeX or texinfo, you can mix text and LilyPond code. A script called lilypond-book will extract the music fragments, run LilyPond on them, and put back the resulting notation. lilypond-book is described fully in lilypond-book, but here we show a small example. Since the example also contains explanatory text, we won't comment on the contents.

\documentclass[a4paper]{article}
\begin{document}

In a lilypond-book document, you can freely mix music and text. For
example:
\begin{lilypond}
  \score { \notes \relative c' {
     c2 g'2 \times 2/3 { f8 e d } c'2 g4
  } }
\end{lilypond}
Notice that the music line length matches the margin settings of the
document.

If you have no \verb+\score+ block in the fragment,
\texttt{lilypond-book} will supply one:

\begin{lilypond}
  c'4
\end{lilypond}

In the example you see here, a number of things happened: a
\verb+\score+ block was added, and the line width was set to natural
length. You can specify many more options using  \LaTeX style options
in brackets:

\begin[verbatim,11pt,singleline,
  fragment,relative,intertext="hi there!"]{lilypond}
  c'4 f bes es
\end{lilypond}

\texttt{verbatim} also shows the LilyPond code, \texttt{11pt} selects
the default music size, \texttt{fragment} adds a score block,
\texttt{relative} uses relative mode for the fragment, and
\texttt{intertext} specifies what to print between the
\texttt{verbatim} code and the music.

If you include large examples into the text, it may be more convenient
to put the example in a separate file:

\lilypondfile[printfilename]{sammartini.ly}

The \texttt{printfilename} option adds the file name to the output.

\end{document}

Under Unix, you can view the results as follows.

$ cd input/tutorial
$ lilypond-book --outdir=out/ lilbook.tex
lilypond-book (GNU LilyPond) 1.3.146
Reading `/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/lilbook.tex'
Reading
`/home/hanwen/usr/src/lilypond-1.3.146/input/tutorial/sammartini.ly'
lots of stuff deleted
Writing `out/lilbook.latex'
$ cd out
$ latex lilbook.latex
lots of stuff deleted
$ xdvi lilbook

Notice the outdir option to lilypond-book. Running lilypond-book and running latex creates a lot of temporary files, and you wouldn't want those to clutter up your working directory. Hence, we have them created in a separate subdirectory.

The result more or less looks like this:

***

In a lilypond-book document, you can freely mix music and text. For example:

[picture of music] Notice that the music line length matches the margin settings of the document.

If you have no \score block in the fragment, lilypond-book will supply one:

[picture of music]

In the example you see here, a number of things happened: a \score block was added, and the line width was set to natural length. You can specify many more options using LaTeX style options in brackets:

  c'4 f bes es

hi there!

[picture of music]

verbatim also shows the LilyPond code, 11pt selects the default music size, fragment adds a score block, relative uses relative mode for the fragment, and intertext specifies what to print between the verbatim code and the music.

If you include large examples into the text, it may be more convenient to put the example in a separate file:

../.././input/tutorial/sammartini.ly:

[picture of music]

The printfilename option adds the file name to the output.

Go back to index of LilyPond.

Please send GNU LilyPond questions and comments to lilypond-user@gnu.org.

Please send comments on these web pages to lilypond@packages.debian.org

Copyright (c) 1997--2001 Han-Wen Nienhuys and Jan Nieuwenhuizen.

Verbatim copying and distribution of this entire article is permitted in any medium, provided this notice is preserved.


This page was built from LilyPond-1.4.12 (stable-branch) by

Anthony Fok <lilypond@packages.debian.org>, Tue Mar 12 01:35:39 2002 HKT.