I'm new here (i.e., pardon my ignorance). But I've been tootling around the LuaLatex and I've come across some bizarre behavior. The following code
\documentclass{article}
\usepackage{luatextra}
\usepackage{xparse}
\begin{luacode*}
function record (m,n)
file = assert(io.open("test2.dat","a"))
file:write(string.format("%s %s",m,n),"\n")
end
\end{luacode*}
\newcounter{prob}
\setcounter{prob}{1}
\DeclareDocumentCommand{\problem}{m}{%
\noindent \textbf{Problem \theprob:} (#1 points)
\directlua{record(\theprob ,#1)} \stepcounter{prob}
}
\begin{document}
\problem{2} Who is your Daddy and what does he do?
$42$
\end{document}
produces the following error:
...MikTex 2.9/tex/luatex/luaotfload/fontloader-2016-06-1 6.lua:10601:
attempt to call field 'suffix' (a nil value).
<to be read again>
relax
1.24 $4
2$
?
Here comes the bizarre part. When the above code is augmented to include anything in math mode before the "problem" command is invoked, everything compiles fine. For example
\begin{document}
$ $
\problem{2} Who is your Daddy and what does he do?
$42$
\end{document}
compiles with no error. What's the story here? Thanks in advance for your input.
EDIT: The issue appears to have something to do with fontspec since replacing the package luatextra with luacode AND fontspec still exhibits the same behavior.