Katex: Incorrect rendering of \^ in text mode

Created on 27 May 2018  路  6Comments  路  Source: KaTeX/KaTeX

Try

\text{a\^{}b}

in KaTeX vs LaTeX. In the latter \^{} is a proper caret character, whereas in the former.. well, I'm not quite sure what's going on, maybe it's only a spacing issue, but the result certainly looks wrong.
(Replacing \text with \texttt may help see the problem)

bug

All 6 comments

Interesting, thanks for spotting. I need to understand when accented characters take the width of the accent (perhaps empty base character is a special case?) and when they take the width of the base character (as in \^\i).

any progress on this?

@edemaine it looks like it's a text mode thing. Here's what quicklatex.com produces:

\text{a^{}b}
Screen Shot 2020-12-11 at 5 05 29 PM

a^{}b
Screen Shot 2020-12-11 at 5 05 18 PM

The second one is actual an error. I didn't notice it at first because quicklatex.com doesn't enable error reporting by default.

I hadn't realized that \^ is equivalent to \textasciicircum. I'll make a quick PR! Sorry, I misspoke.

\^ is a text-mode accent command. The issue is with accent commands having empty arguments. In KaTeX, a blank argument is treated like a zero-width box, so the accent gets centered on top. In LaTeX, a blank argument seems to behave the same as something like a space, but I'm not sure by what mechanism it does so (minimum width? special case of {} argument?). Perhaps this is done at the TeX level? Without knowing the mechanism, it's difficult to implement...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

trollanfer picture trollanfer  路  5Comments

StaloneLab picture StaloneLab  路  3Comments

asmeurer picture asmeurer  路  3Comments

shaunc picture shaunc  路  4Comments

pvnr0082t picture pvnr0082t  路  4Comments