5

The package lilyglyphs provides a set of macros for incorporating Lilypond fonts easily into XeLaTeX files. That package is available here. I am using TeXLive 2013.

With the following MWE it works as expected with XeLaTeX:

\documentclass{memoir}
\usepackage{fontspec}
\usepackage{lilyglyphs}
\begin{document}
\lilyTimeC
\end{document}

Running it with LuaLaTeX results in the following error:

! Undefined control sequence. \lilyGetGlyph #1^^@-\XeTeXglyph
\XeTeXglyphindex "#1"

I traced this back to the core/genericAccess.inp file which contains the following line:

\newcommand*{\lilyGetGlyph}[1]{\XeTeXglyph\XeTeXglyphindex"#1" }

OK, that's a XeTeX-specific command. I need the LuaTeX version in order to make this work with LuaLaTeX. I found this answer which suggests something like this:

\def\lilyGetGlyph#1{\directlua{fonts.otf.char("#1")}}

But when I run LuaLaTeX on the MWE I get the following error:

! LuaTeX error [string "\directlua "]:1: attempt to index field 'otf' (a nil value)
stack traceback:
[string "\directlua "]:1: in main chunk.
\lilyGetGlyph ...\directlua {fonts.otf.char("#1")}

I have no idea what that means but neither do I understand the syntax of my attempted fix (I just keep putting in words and symbols hoping something will work).

So what I'm looking for is the LuaTeX version of that XeLaTeX bit of code that will allow the package lilyglyphs to work with LuaLaTeX. Assuming, of course, that's the proper way to fix this.

1 Answer 1

5

OK, so apparently the \directlua{fonts.otf.char is no longer supported in LuaTeX according to this answer. Fortunately they (@phg) supplied a solution as well:

\usepackage{luaotfload,luacode}
\begin{luacode}
documentdata = documentdata or { }

local stringformat = string.format
local texsprint = tex.sprint
local slot_of_name = luaotfload.aux.slot_of_name

documentdata.fontchar = function (chr)
local chr = slot_of_name(font.current(), chr, false)
if chr and type(chr) == "number" then
texsprint
(stringformat ([[\char"%X"]], chr))
end
end
\end{luacode}
\def\lilyGetGlyph#1{\directlua{documentdata.fontchar "#1"}}

Which I added to the core/genericAccess.inp file and now everything works as it should. I added some tests to check for LuaTeX vs. XeTeX to the original code and will send all of this to the author of the package.

1
  • I haven't marked this as answered as I'm hoping @phg might stop by and point out any further issues I might have, etc.
    – bfootdav
    Jul 14, 2013 at 18:10

You must log in to answer this question.

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