2

As background: I'm a physicist who's very comfortable with LaTeX, and usually use the MiKTeX distribution primarily due to ease of installing packages on the fly compared with TeX Live. As for LaTeX, I really like the look of its output and ease of use compared with other typesetting systems, even when not writing equations and symbols.

Recently, I have come across LilyPond - which looks really nice - and would quite like to do a project involving a LaTeX document with some musical excerpts (just single staves probably). I'm aware that LyLuaTeX has been made with this in mind. My problem with LyLuaTeX stems from its seeming incompatibility with MiKTeX. After trying TeX Live instead, I have got it working**, but it is annoyingly clunky having two distributions. Moreover I am slightly suspicious about its robustness due to the number of bugs I encountered trying to make it work (perhaps it will prove me wrong however). Hence my question:

  • Are there alternatives apart from LyLuaTeX which would provide such integration?

(This has been asked before, but it is 2022 now so things may have changed)

** I got a rawget error - a certain function expects a table as argument. By removing line 814 on lyluatex.lua entirely one bypasses this and then lyluatexseems to work. This seems to be some kind of clash between MiKTeX and LyLuaTeX, both of which are currently installed on my system.

  • 1
    with no example shown it is a bit hard to comment, as far as I know luatex and lilypond should work with miktex, but I've always used texlive personally. As for "installing packages on the fly compared with TeX Live." That may have been an issue in previous times but most texlive users install the full set to start with so on-the-fly install just never comes up. It's not that big, I have several texlives installed, – David Carlisle Jul 15 '22 at 21:56
  • Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. – Community Jul 15 '22 at 22:33
  • No idea? If it seems like a bug in the package then report a bug on the appropriate place and wait/hope they will fix it.. – user202729 Jul 16 '22 at 00:39
  • Side note, if you did some research and come across related questions on the site, do link to them for searchability. – user202729 Jul 16 '22 at 00:40
  • Try the abc package... – Paul Gaborit Jul 16 '22 at 09:37
  • Please elaborate, what kind of music excerpts you want include. Do you want to do it one time, or repeatedly the same musixc in different documents? – MaestroGlanz Aug 05 '22 at 08:33
  • I think, I have the solution to your problem: See my answer here in the music theory forum – MaestroGlanz Oct 05 '22 at 19:53

3 Answers3

4

For a small number of music symbols you could use my musicography LaTeX package; for a wider range, if you don't need pdflatex, there is lilyglyphs.

If you have full music examples, I would treat Lilypond like any other graphics program that will produce images for inclusion in LaTeX. Make all your examples in Lilypond (or Dorico or Finale) and export them to a directory of PDFs or image files, then just \includegraphics to bring the images. You can use the pdfcrop tool to trim the margins around the images you want to include.

Especially if you are new to Lilypond, the "integrated solutions" (lyluatex, lilypond-book) are likely to cause more headaches than you need.

So for example, you have a musical example to be included in a document.

music example source file: music-examples/example1.ly

\version "2.22"
\header { tagline = ##f }
{ c'4 d'4 e'2 }

document: document.tex

\documentclass{article}
\usepackage{graphicx}
\NewDocumentCommand{\includeMusic}{ m }{\includegraphics{build/img/#1}}
\begin{document}
Here is some music:
\includeMusic{example1}
\end{document}

Now you need a Makefile to first create and crop the graphics and then run LaTeX including the graphics.

Makefile

dirs    = aux build build/img
tex_in  = $(wildcard *.tex)
pdf_out = $(addprefix build/,$(tex_in:%.tex=%.pdf))

ly_in = $(wildcard music-examples/*.ly) ly_img = $(addprefix aux/,$(notdir $(ly_in:%.ly=%.pdf))) img_out = $(addprefix build/img/,$(notdir $(ly_img)))

.PHONY : all clean

all : $(pdf_out) $(img_out)

build/%.pdf : aux/%.pdf cp $< $@

aux/%.pdf : %.tex $(img_out) | $(dirs) latexmk -outdir=aux -pdf $<

build/img/%.pdf : aux/%.pdf pdfcrop $< $@

aux/%.pdf : music-examples/%.ly | $(dirs) lilypond --output=aux/ $<

$(dirs) : mkdir -p $(dirs)

clean : rm -rf $(dirs)

If you need to configure the Lilypond output to fit better in your LaTeX document (e.g., setting an optimal text width, indent and margins, using the same font) you can put that in a Lilypond file (e.g., example.ly) and the add \include "example.ly" to all your Lilypond example files.

To compile your document, just type make. The output will be in the build directory.

musarithmia
  • 12,463
  • 1
    While I like this solution (+1), I'm not sure it is actually easier than for example lilypond-book - maybe it would be advisable (for future visitors) to try the integrated solutions first, and use this answer only when those solutions indeed cause problems. – Marijn Nov 04 '22 at 14:19
  • @Marijn I hope someone will post a lyluatex answer. When I established this workflow it was not quite ready for prime time but I think it is fully functional now. This make system is more similar to what lilypond-book does but is in my opinion easier to deal with once it's set up. I think it is easier to configure the two programs (LaTeX & Lilypond) separately; sometimes an integrated solution just adds a third thing to configure. This is a one-tool-per-job approach as opposed to an all-in-one method. – musarithmia Nov 04 '22 at 19:29
3

Main author of lyluatex here. As of 2023, the compatibility problem between lyluatex and MiKTeX should be fixed with LilyPond <= 2.22. There is a known bug for latest LilyPond, which is waiting for pull requests if anyone wants to look at it (quite complicated for me, as I don’t own a Windows machine).

Feel free to fill an issue in case of problems, as I don’t follow tex.stackexchange.

jperon
  • 109
  • 1
  • 7
0

Have alook here Are there similar documents in English about "How to integrate music examples with open source tools in scientific documents"?.

The document cited is written in German, which may be unfortunate. However, the author scanned, tried and evaluated all music-related packages for LaTeX available in 2020. See e.g. his "flowchart" on p. 91, which gives a good impression what's feasable.

For the authors purpose, to assist musicology, he clearly favours the Lilipond flow.

If you are only after typesetting, I found musixtex not that hard to understand and to apply. I run it all the time via pdflatex (MikTeX).

For further examples you may want to check https://tex.stackexchange.com/search?q=musixtex, or a recent power-use of musixtex https://tex.stackexchange.com/search?q=user%3A285170

MS-SPO
  • 11,519