[icon]

GNU LilyPond

-- --

What is LilyPond
Home
Examples
Templates
Download
GNU/Linux binaries
Windows binaries
Source code
Documentation
Tutorial
Manual
Glossary
Index

Support
Mailing lists
Search
WikiWiki

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

Integrating text and music

Sometimes you might want to use music examples in a text that you are writing (for example 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 word processor. However, there is an automated procedure to reduce the amount of work.

If you use HTML, 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. This program is fully described in the chapter Integrating text and music with lilypond-book. 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, two 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} prints the LilyPond code in addition to the
     graphical score,
     \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 want to 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
     $ mkdir -p out/
     $ lilypond-book --outdir=out/ lilbook.tex
     lilypond-book (GNU LilyPond) 1.6.1
     Reading `input/tutorial/lilbook.tex'
     Reading `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 looks more or less 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 (address unknown)

Copyright (c) 1997--2002 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.7.14 (development-branch) by

Buchan Milne <(address unknown)>, Thu Mar 6 21:11:35 2003 CET.