# lilypond LaTeX integration

I use LaTex comfortably and lilypond but am working on a project that requires music excerpts in latex and I'm having a hard time integrating latex and lilypond. I am able to produce a pdf file from either but the command prompt for lilypond won't allow me to input any commands. Any suggestions?

• Hi and welcome to TeX.SX! You can have a look at our starter guide to familiarize yourself further with our format. Have you seen lilypond-book?
– yo'
Sep 27 '14 at 4:51

Your question didn't describe much about what you tried or your system, so I can only guess. But based on my own involvement in project using a lilypond precompile of a latex document heres what I can recommend:

MainDev.lytex

\documentclass{article}

\usepackage{import}
\usepackage{graphics}

\begin{document}

\section{LilyPond Code integrated}

Test content

\begin{lilypond}
\relative c' {
c2 e2 \tuplet 3/2 { f8 a b } a2 e4 c2 e2 \tuplet 3/2 { f8 a b } a2 e4 c2 e2
\tuplet 3/2 { f8 a b } a2 e4 c2 e2 \tuplet 3/2 { f8 a b } a2 e4 c2 e2 \tuplet
3/2 { f8 a b } a2 e4 c2 e2 \tuplet 3/2 { f8 a b } a2 e4 c2 e2 \tuplet 3/2 { f8
a b } a2 e4 }
\end{lilypond}

End of document

\end{document}


To compile:

1. I place this file in the root directory of your project
2. Root level also contains a folder called "LilyPondPrecompile"
3. Root level also contains a folder called "src" - I recomend putting all files except the main file in here.
4. On windows 7 running MiKTeX you can create a bat file that will precompile your document using:

FOR %%A IN (*.lytex) DO ^
(ECHO %%~nxA & "lilypond-book" --pdf -f LaTeX ^
--include "src" ^
--output "LilyPondPrecompile" "%%~nxA")

5. You then compile the root tex file in the newly created folder "LilyPondPrecompile" (Note – it may be necessary to routinely clear this folder as lilypond seems to be designed to update files, not overwrite by default.)

• @seanallred Thanks for the edit. What is the difference between a windows bat file new line connection ^ vs &_? May 22 '15 at 3:16
• How to with Unix system: 1/ go to your working directory 2/ lilypond-book --pdf --format=latex --include=part --output=LilyPondPrecompile MainDev.lytex 3/ cd LilyPondPrecompile 4/ pdflatex MainDev.tex Nov 27 '15 at 11:33
• (note that I had to modify all \tuplet commands with \times.) Nov 27 '15 at 12:00