5

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?

  • 3
    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
7

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:

To start with:

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.)

  6. Use your conventional approach to compile your tex file.

Explanatory note: The structure and command line example above are derived from my practice of storing no more than 1 main compilable file for a given document in a root directory so that any collection of documents can be compiled simultaneously without generating errors from sub files that aren't recognized as independently compilable files.

  • @seanallred Thanks for the edit. What is the difference between a windows bat file new line connection ^ vs &_? – EngBIRD May 22 '15 at 3:16
  • I honestly have no clue – it was just the first result on google :) – Sean Allred May 22 '15 at 3:37
  • 1
    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 – ebosi Nov 27 '15 at 11:33
  • (note that I had to modify all \tuplet commands with \times.) – ebosi Nov 27 '15 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.