I am trying to incorporate Lilypond files into LaTeX. I use MacOS Sonoma 14.1.1. TexShop (5.2.2) and write my Lilypond files in Frescobaldi 3.3.0, where they compile into pdf files without a problem.

This question has been asked before, I am incorporating the answer of How to run `--shell-escape` for LuaLaTeX in Texshop, in particular the steps:

I just have an Engine file to do this, or use the arara engine. Save the following file as lualatex-shell.engine in ~/Library/TeXShop/Engines.


set path= ($path /usr/texbin /usr/local/bin)
lualatex --shell-escape --file-line-error --synctex=1 "$1"

In the Terminal type:

chmod +x ~/Library/TeXShop/Engines/lualatex-shell.engine

Then restart TeXShop and you can invoke it either by choosing it from the Program item in the Macros menu, or by adding a magic comment line:

% !TEX TS-program = lualatex-shell

I follow all these steps diligently and apply this to several lilypond examples, e.g. my file test4.tex

!TEX TS-program = lualatex-shell
\relative{\time 8/4       \key g \major   g'4 a b c d e fis g}

But when I Typeset it in TeXshop or use the terminal I get the following error

(lyluatex) Compiling score tmp-ly/e0245313228d92c30cf69cc0a8ddc120 with LilyPond executable 'lilypond'. ...ocal/t exlive/2023/texmf-dist/tex/latex/base/ltluatex.lua:110: Module lyluatex Error: LilyPond could not be started. (lyluatex) Please check that LuaLaTeX is started with the (lyluatex) --shell-escape option, and that 'program' (lyluatex) points to a valid LilyPond executable. (lyluatex) on input line 9

stack traceback: [C]: in function 'error' ...ocal/texlive/2023/texmf-dist/tex/latex/base/ltluatex.lua:110: in function < ...ocal/texlive/2023/texmf-dist/tex/latex/base/ltluatex.lua:109> (...tail calls...) ./lyluatex.lua:1106: in method 'process' [\directlua]:1: in main chunk. \ly@compilescore ...directlua {ly.score:process()}

l.9 \end{lilypond}

I am complete at a loss here as it seems to know the lyluatex package but find an error in a lilypond code.

Can anyone help me resolve this.

Please note that I am not a (La)TeX expert keep it simple if you can !

  • In your MWE, the line \begin{lilypond} is missing. It looks like the lyluatex package can't find Lilypond. Did you check the lyluatex manual? Commented Nov 24, 2023 at 15:03
  • 1
    The manual says: "By default lyLuaTEX invokes LilyPond simply as lilypond." If you type this command in the command line (Terminal on macOS), does Lilypond start up? If not, you might need to tell lyluatex where it should look for LilyPond using the program option. Commented Nov 24, 2023 at 15:06
  • @JasperHabicht that's a typo in my question! now corrected. Commented Nov 24, 2023 at 15:28
  • @JasperHabicht When I type "lilypond" or "lilypond test4" or "lyluatex" in terminal. It says command not found. What do I need to do? Commented Nov 24, 2023 at 15:35

1 Answer 1


So there are two issues here. The first is how your lilypond is installed. I have it installed using homebrew, and so the location of my lilypond executable is in /opt/homebrew/bin. If you didn't install it that way, then your executable maybe somewhere else, and you need to be able to tell your Engine file where to find it. If you install lilypond with homebrew you simply need to add /opt/homebrew/bin to the path in the Engine file:

set path= ($path /usr/texbin /usr/local/bin /opt/homebrew/bin)
lualatex --shell-escape --file-line-error --synctex=1 "$1"

And then you can use this Engine to compile your file. But until you have a way to run lilypond from the command line it won't work. Once you do get it running, then you need to replace the /opt/homebrew/bin path with whatever is the actual path of your lilypond executable.

If you installed lilypond by simply unzipping the .zip file from the lilypond.org download page, then you have a folder lilypond-2.24.3 (the actual version number might be different) somewhere in your machine. Assuming you put this into your Applications folder, then the path to lilypond you would put into the Engine would be:


This will not let you run lilypond from the command line without further adding this path to your shell .profile (or equivalent). For this reason, I would recommend installing lilypond with homebrew, since it will correctly set the path for any homebrew installed software.

  • I don't understand. I have a lilypond.exe file in a ~/Documents/Music/_Lilypond/bin directory, but even if I try to run it from there in the terminal I get a "command not found". But if I click on lilypond.exe in Finder it starts a process and ends it with no apparent error. ?? Commented Nov 24, 2023 at 16:32
  • 2
    @Oбжорoв Well there's your problem right there. If the file is really called lilypond.exe then it's a Windows executable and won't run on your Mac at all. I would recommend first installing Homebrew from here and then using brew install lilypond from the terminal to install lilypond. Then the instructions I give at the beginning of this answer should work. Lilypond is not a program that is designed to be run from the Finder.
    – Alan Munn
    Commented Nov 24, 2023 at 17:30
  • fyi. I have once more downloaded lilypond.org and moved the lilypond-2.24.3 folder to my applications. I have added the address /Applications/lilypond-2.24.3/bin to the lualatex-shell.engine file and entered chmod +x ~/Library/TeXShop/Engines/lualatex-shell.engine in the terminal. I have exit TexShop (and Mac even) and restarted it . Still the same error. Commented Nov 24, 2023 at 17:37
  • @Oбжорoв Another reason to use homebrew to install. When you install lilypond the way you did, the MacOS will issue an error saying that it comes from an unknown developer, and will not let you run it. To overcome this, you need to navigate to the /Applications/lilypond-2.24.3/bin folder, select the lilypond command, and control click and choose "Open". This will then ask you if you trust the developer. Choose yes, and things should work. But I suspect the other executables within that folder will also pose problems, so I reiterate my suggestion to use Homebrew to install lilypond.
    – Alan Munn
    Commented Nov 24, 2023 at 17:47
  • 1
    @Oбжорoв I think I'll just leave the answer as is. As I said, I think the best solution to this problem is to make sure lilypond is installed with Homebrew, and the answer as it stands should work for others. It's not entirely clear why it's still not working in your particular setup.
    – Alan Munn
    Commented Nov 24, 2023 at 19:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .