Incorrect Spacing Between `\textcolor` inside `\texttt`
Steps to Reproduce:
Code:
\texttt{R~B}
\texttt{R ~ B}
\texttt{R~~~B}
\texttt{R B}
\texttt{\textcolor{red}{R}~\textcolor{blue}{B}}
\texttt{\textcolor{red}{R} ~ \textcolor{blue}{B}}
\texttt{\textcolor{red}{R}~~~\textcolor{blue}{B}}
\texttt{\textcolor{red}{R} \textcolor{blue}{B}}
Github:
$$ \texttt{R~B} \texttt{R ~ B} \texttt{R~~~B} \texttt{R B} \texttt{\textcolor{red}{R}~\textcolor{blue}{B}} \texttt{\textcolor{red}{R} ~ \textcolor{blue}{B}} \texttt{\textcolor{red}{R}~~~\textcolor{blue}{B}} \texttt{\textcolor{red}{R} \textcolor{blue}{B}} $$
Standard Mathjax:
XeLaTeX:
This may be related to #1953?
Technical details:
- MathJax Version: 3.2.2
- Client OS: Windows 11
- Browser: Chrome
Thanks for the report. The issue is caused by MathJax removing spaces at the beginning and ending of the <mtext> elements produces within a \text macro (or one of its relatives like \texttt). These occur whenever MathJax has to break up the content of \text into separate pieces, as is the case for when it contains color commands, but there are many other places that also occurs. The space removal used a regular expression based on \s which matches any space, including the non-breaking space produced by ~.
I will make a PR to correct this, but for now, you can use a configuration like
MathJax = {
loader: {load: ['[tex]/textmacros']},
tex: {
packages: {'[+]': ['textmacros']}
},
startup: {
ready() {
const ParseUtil = MathJax._.input.tex.ParseUtil.default;
ParseUtil.internalText = function (parser, text, def) {
text = text.replace(/\n+/g, ' ').replace(/^ +/, '\u00A0').replace(/ +$/, '\u00A0');
return parser.create('node', 'mtext', [], def, parser.create('text', text));
};
MathJax.startup.defaultReady();
}
}
}
to resolve the problem.
Fixed in v4.0