I am using two different fonts for math mode as for my main text, so numbers in math mode and in the text do not match in font, which looks bad. Therefore, I want to change the font of only numbers in the text.
I found a way to do this with this answer: https://tex.stackexchange.com/a/10266/127289
Here is my entire project, being compiled on Overleaf with XeTeX:
\documentclass{article}
\usepackage{fontspec}
\XeTeXinterchartokenstate=1
\chardef\CharNormal=0
\makeatletter
% Test for old and new versions of the latex kernel
\ifx\e@alloc@intercharclass@top\@undefined
\chardef\CharBound=255
\else
\chardef\CharBound=\e@alloc@intercharclass@top
\fi
\makeatother
\newXeTeXintercharclass\CharNumbers
\XeTeXcharclass`0=\CharNumbers
\XeTeXcharclass`1=\CharNumbers
\XeTeXcharclass`2=\CharNumbers
\XeTeXcharclass`3=\CharNumbers
\XeTeXcharclass`4=\CharNumbers
\XeTeXcharclass`5=\CharNumbers
\XeTeXcharclass`6=\CharNumbers
\XeTeXcharclass`7=\CharNumbers
\XeTeXcharclass`8=\CharNumbers
\XeTeXcharclass`9=\CharNumbers
\newtoks\TokSetfont
\TokSetfont={\begingroup\fontspec{Latin Modern Mono}}
\XeTeXinterchartoks\CharNormal\CharNumbers=\TokSetfont
\XeTeXinterchartoks\CharBound\CharNumbers=\TokSetfont
\XeTeXinterchartoks\CharNumbers\CharNormal={\endgroup}
\XeTeXinterchartoks\CharNumbers\CharBound={\endgroup}
\begin{document}
test test 12345
\end{document}
However, this seems not to work. I keep getting the same error:
TeX capacity exceeded, sorry [save size=80000].
Since my document is tiny, this is obviously some kind of recursion bug. The log file contains nothing particularly enlightening, to me. There is no repeating error message indicative of a recursion loop.
However, if I change Latin Modern Mono to Arial, then I get this printed in the log file hundreds of times:
.................................................
. fontspec info: "no-scripts"
.
. Font Arial does not contain any OpenType `Script' information.
.................................................
which suggests that the recursion may be happening in the call
\TokSetfont={\begingroup\fontspec{Latin Modern Mono}}? Maybe not related.
Does anyone have any insight into what is going on? Can someone else try to run this in some other environment and tell me the results? No one in the old question that I linked to seemed to be having any problem.
\texttt{}(numbers in string args passed to\texttt{}are rendered with Latin Modern Mono rather than Courier), which is a problem. Can this answer be amended to fix that? – pretzlstyle Mar 01 '18 at 20:23texttt{}like so:
– pretzlstyle Mar 01 '18 at 20:54\newfontfamily\numfontfam{Courier} \texttt{...} \newfontfamily\numfontfam{Latin Modern Mono}... which is a bit of a pain but okay