1

Sorry if this will turn out to be noob-ish, but apparently I can't integrate Lilypond scores into my LaTeX document (well, neither ABC ones, but that's another question).

I have this MWE:

\documentclass[a4paper]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}

\begin{document}

\begin{lilypond}[quote,fragment,staffsize=26] c' d' e' f' g'2 g'2 \end{lilypond}

\end{document}

When I run pdflatex, I got:

ERROR: LaTeX Error: Environment lilypond undefined.

--- TeX said ---

See the LaTeX manual or LaTeX Companion for explanation. Type H <return> for immediate help. ...

l.35 \begin{lilypond} [quote,fragment,staffsize=26] --- HELP --- LaTeX has encountered a \begin command for a nonexistent environment. You probably misspelled the environment name.

What am I doing wrong?

I'm on Arch Linux, and I got these packages installed:

[alessandro@commodoroII MMDC]$ pacman -Qe | grep texlive
texlive-bibtexextra 2022.63023-1
texlive-core 2022.63035-1
texlive-fontsextra 2022.62977-1
texlive-formatsextra 2022.62529-1
texlive-games 2022.62102-1
texlive-humanities 2022.62929-1
texlive-latexextra 2022.63034-1
texlive-music 2022.62533-1
texlive-pictures 2022.62992-1
texlive-pstricks 2022.62977-1
texlive-publishers 2022.63013-1
texlive-science 2022.62977-1

Thanks!

  • 1
    You need \usepackage{lyluatex} and compile with LuaLaTeX instead of pdfLaTeX. Also you need to have Lilypond itself installed. See the lyluatex documentation for details. – Marijn Feb 06 '23 at 13:05
  • 1
    Alternatively you can use lilypond-book, see http://lilypond.org/doc/v2.18/Documentation/usage/an-example-of-a-musicological-document. The idea there is that you use Lilypond as a preprocessor first, and run LaTeX (for example pdfLaTeX) afterwards. – Marijn Feb 06 '23 at 13:09
  • And don't forget to install lilypond. – cabohah Feb 06 '23 at 13:37
  • Thanks! lilypond-book works, but I wonder: does it run latexmk under the hood? Do I have to call it multiple times if I have cross references too? lyluatex OTOH doesn't work, the process lualatex --shell-escape test.tex never terminates. – Alessandro Bertulli Feb 06 '23 at 14:26

1 Answers1

2

Here is how to do this with lyluatex: here is the content of document.tex:

\documentclass[a4paper]{article}
% Lyluatex needs LuaLaTeX, so fonspec here instead of inputenc and fontenc.
% You may put a font package here ("libertine" or "ebgaramond" for example)
% instead of "fontspec", as they depend on it.
\usepackage{fontspec}
% "pass-fonts" ensures coherent fonts (for lyrics) between the document and the scores.
\usepackage[pass-fonts]{lyluatex}

\begin{document}

\begin{lilypond} c' d' e' f' g'2 g'2 \end{lilypond}

\end{document}

Then compile with lualatex:

lualatex --shell-escape document

shell-escape is required to allow spawning lilypond processes. Otherwise, you may add lilypond to shell-restricted commands, but it is beyond the scope of this small howto.

On Windows with MiKTeX, use LilyPond <= 2.22 till this bug finds anyone to fix it.

The documentation lists the options. The best place in case of bugs or questions is the issue tracker.

jperon
  • 109
  • 1
  • 7