Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

listings and unicode-math scriptsize bad #454

Open
4 tasks done
wspr opened this issue Mar 29, 2018 · 2 comments
Open
4 tasks done

listings and unicode-math scriptsize bad #454

wspr opened this issue Mar 29, 2018 · 2 comments

Comments

@wspr
Copy link
Collaborator

wspr commented Mar 29, 2018

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

\documentclass{article}
\usepackage{unicode-math}
\usepackage{listings}
\lstset{basicstyle=\scriptsize}
\begin{document}
\lstinputlisting{test.cpp}
\end{document}

Further details

Workaround: \AtBeginDocument{\sbox0{\scriptsize $x$}} or similar.

@u-fischer
Copy link
Member

u-fischer commented Mar 29, 2018

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}

@davidcarlisle
Copy link
Member

davidcarlisle commented Mar 29, 2018 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants