# fontspec ruins Lilypond's note spacing

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

with fontspec

This MWE shows the error

\documentclass{scrartcl}

%\usepackage{fontspec}

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


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

-

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.

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

\documentclass{scrartcl}

\usepackage{fontspec}
\newcommand*{\defaultfontfamily}{Calluna}
\defaultfontfeatures{Mapping=tex-text, Ligatures={Discretionary, Common, Rare}}
\setmainfont{\defaultfontfamily}

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


and everything still works:

-
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