Open wspr opened 6 years ago
The problem is that fontspec/unicode-math reads font dimens with luacode. And while catcodes in the tex code are frozen when the code is read this is not true for values you get from directlua. So when trying to setup the font in the middle of lstlisting (which activates all chars) things explodes.
The problem can be resolved by explicitly setting the catcode table when reading the dimens in the first argument of tex.sprint:
\documentclass{article}
\usepackage{unicode-math}
\RequirePackage{luacode}
\begin{luacode}
local latexcatcodetable = luatexbase.registernumber("catcodetable@latex")
function fontspec.mathfontdimen(fnt, str)
local mathdimens = luaotfload.aux.get_math_dimension(fnt, str)
if mathdimens then
tex.sprint(latexcatcodetable,mathdimens)
tex.sprint(latexcatcodetable,"sp")
else
tex.sprint(latexcatcodetable,"0pt")
end
end
\end{luacode}
\usepackage{listings}
\lstset{basicstyle=\scriptsize}
\begin{document}
\begin{lstlisting}
-
\end{lstlisting}
\end{document}
you shouldn't need luatexbase packae
\catcodetable@latex
is pre-defined in the format, see
https://github.com/wspr/fontspec/issues/230
which was same issue in fontspec
On 29 March 2018 at 10:09, u-fischer notifications@github.com wrote:
The problem is that fontspec/unicode-math reads font dimens with luacode. And while catcodes in the tex code are frozen when the code is read this is not true for values you get from directlua. So when trying to setup the font in the middle of lstlisting (which activates all chars) things explodes.
The problem can be resolved by explicitly setting the catcode table when reading the dimens in the first argument of tex.sprint:
\documentclass{article} \usepackage{unicode-math} \RequirePackage{luacode} \begin{luacode}
function fontspec.mathfontdimen(fnt, str) local mathdimens = luaotfload.aux.get_math_dimension(fnt, str) if mathdimens then tex.sprint(luatexbase.catcodetables.latex,mathdimens) tex.sprint(luatexbase.catcodetables.latex,"sp") else tex.sprint(luatexbase.catcodetables.latex,"0pt") end end \end{luacode}
\usepackage{listings}
\lstset{basicstyle=\scriptsize} \begin{document}
\begin{lstlisting}
\end{lstlisting}
\end{document}
(this needs the luatexbase package, I'm not sure how to get the table with kernel code alone.)
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/wspr/unicode-math/issues/454#issuecomment-377172982, or mute the thread https://github.com/notifications/unsubscribe-auth/ABNcAnMKOIOu6jQ3-DEUPwUfes-sPaG6ks5tjKS3gaJpZM4S_wqW .
Description
Unicode-math and/or listings has a problem if
basicstyle=\scriptsize
is set and the maths fonts haven't been initialised. (IMO I don't think listings should be using maths characters, but maybe there's a good reason.)Check/indicate
Minimal example demonstrating the issue
Further details
Workaround:
\AtBeginDocument{\sbox0{\scriptsize $x$}}
or similar.