2

Apologies if this has been asked before, but I have not found the relevant question.

I am trying to use LilyPond in a LaTeX environment.

From ChatGPT I should be able to use a simple file such as:

\documentclass{article}
\usepackage{lilypond-book}

\begin{document}

\begin{lilypond}
\relative{\time 4/4 \tempo 
          c'4 d e f g a b c } 
\end{lilypond}

\end{document}

But compiling this, using TeXShop I get an error message:

./test.tex:6: LaTeX Error: Environment lilypond undefined.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              
                                                  
l.6 \begin{lilypond}
                    
? 

The lilypond-book executable file is in the same directory as my TeX file.

It may be more appropriate to ask this in the TeX SE, but I guess my chances of an answer may be slightly better here.

4
  • You/ChatGPT hasn't set the tempo correctly. It needs to be something like \tempo 4=120 Commented Nov 22, 2023 at 9:19
  • I see that now, but that is not related to my problem. It seems not to find the lilypond-book file. Commented Nov 22, 2023 at 9:33
  • 1
    Instead of asking ChatGPT, why not read plain old documentation? Commented Nov 22, 2023 at 17:38
  • @JeanAbouSamra Thank You that is a very helpful and constructive comment. I have done that and it doesn't work. Commented Nov 22, 2023 at 17:40

2 Answers 2

5

lilypond-book does not work like that. It is not a TeX module, but a preprocessor that will compile the sources, split and crop the resulting images and create a tex file with these images inserted. E.g.

\documentclass{article}

\begin{document}

\begin{lilypond}
\relative{
    \time 4/4 \tempo 4=60
    c'4 d e f g a b c
} 
\end{lilypond}

\end{document}

compiled using lilypond-book gives a tex file like this

\documentclass{article}

\usepackage{graphics}
\begin{document}

{%
\parindent 0pt
\noindent
\ifx\preLilyPondExample \undefined
\else
  \expandafter\preLilyPondExample
\fi
\def\lilypondbook{}%
\input{0c/lily-dd5e2542-systems.tex}%
\ifx\postLilyPondExample \undefined
\else
  \expandafter\postLilyPondExample
\fi
}

\end{document}

(the included file includes the eps graphics).

If you wish to use a different workflow you can use a different approach (as long as you are using LuaTeX). There is the package lyluatex which allows you to do

\documentclass{article}
\usepackage{lyluatex}

\begin{document}

\begin{lilypond}
\relative{
    \time 4/4 \tempo 4=60
    c'4 d e f g a b c
} 
\end{lilypond}

\end{document}

directly in LuaLaTeX.

2
  • I am trying your 2nd method and using LuaLaTex, but still get an error ! LaTeX Error: File `lyluatex.sty' not found. Type X to quit or <RETURN> to proceed, or enter new name. (Default extension: sty) Enter file name: x Commented Nov 22, 2023 at 11:15
  • 1
    @Oбжорoв This means you do not have the package installed: ctan.org/pkg/lyluatex It is shipped in texlive-music.
    – Lazy
    Commented Nov 22, 2023 at 11:25
0

Mixing lilypond and LaTeX is a bit sturdy. I have a solution here and that's, what I'm basically doing for years now: Lilypond with LaTeX

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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