Node:Integrating text and music, Previous:An orchestral part, Up:Tutorial



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 lilypond-book manual. Here we show a small example; since the example contains also explanatory text, we will not comment it further:

     \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}
     
     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  options by putting them in brackets:
     
     \begin[26pt,verbatim]{lilypond}
       c'4 f16
     \end{lilypond}
     
     If you want to include large examples into the text, it is more
     convenient to put it in a separate file:
     
     \lilypondfile{screech-boink.ly}
     
     \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.7.23
     Reading `input/tutorial/lilbook.tex'
     Reading `input/screech-boink6.ly'
     lots of stuff deleted
     Writing `out/lilbook.latex'
     $ cd out
     $ latex lilbook.latex
     lots of stuff deleted
     $ xdvi lilbook
     

Running lilypond-book and running latex creates a lot of temporary files, and you would not want those to clutter up your working directory. The outdir option to lilypond-book creates the temporary files in a separate subdirectory out.

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]

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

[picture of music]

In the example you see here, two things happened: a score block was added, and the line width was set to natural length. You can specify options by putting them in brackets:

       c'4 f16
     

[picture of music]

If you want to include large examples into the text, it is more convenient to put it in a separate file:

[picture of music]


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

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