Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I use lilypond-book to include music examples in my TeX document, but it seems that fontspec breaks the horizontal spacing between the notes:

without fontspec
without fontspec

with fontspec
with fontspec

This MWE shows the error



This is a \lilypond[notime,fragment,staffsize=15]{bes' a' c' b'} test

when compiled with

lilypond-book test.lytex
xelatex text.tex

I guess that fontspec changes a certain font setting, which lilypond expect to have an other value. Maybe this can be fixed by adding something to \preLilyPondExample

share|improve this question

1 Answer 1

up vote 9 down vote accepted

Try compiling with:

lilypond-book --latex-program=xelatex test.lytex
xelatex test.tex

Using xelatex all the way through the compilation should solve your problems.

Using your MWE, this produces:

Nicely formatted lilypond example with XeLaTeX

Which is what you'd expect. We can also use some nice OpenType features (isn't fontspec great?):


\defaultfontfeatures{Mapping=tex-text, Ligatures={Discretionary, Common, Rare}}

This is a \lilypond[notime,fragment,staffsize=15]{bes' a' c' b'} test

and everything still works:

LilyPond book with XeLaTeX and Calluna

share|improve this answer
Great, thanks! I tried latex-programm but missed the -- before the option O:-) BTW: Is it possible to set the options notime,fragment,staffsize=15 global? –  Tobi Sep 13 '13 at 21:29
Not that I'm aware of; I always just use \begin{lilypond}[options]; maybe you could define a \lilypondoptions macro and just pass that in everytime you need options (so you at least have the ability to update options in a single place). –  Sam Whited Sep 13 '13 at 21:58
Unfortunately this won’t work since the .lytex file is preprocessed with lilypond-book which isn’t aware of LaTeXs macro expansion. –  Tobi Sep 14 '13 at 9:30
Oh, right, oops. You still might be able to do it; you'd just have to run it through xelatex first (with some sort of dummy environment specified for the lilypond environment) and have it do some pre-expansion and spit out a temp file for lilypond-book to process... probably not worth it at that point. –  Sam Whited Sep 14 '13 at 12:36
Hm … two precompilings are too much in that case, then I’ll type the option verbatim and use search’n’replace if I want to change them … –  Tobi Sep 14 '13 at 12:38

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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