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

Bug: underscore not handled correctly in \text{} macro #1770

Closed
pkienzle opened this issue Jun 15, 2017 · 5 comments
Closed

Bug: underscore not handled correctly in \text{} macro #1770

pkienzle opened this issue Jun 15, 2017 · 5 comments
Labels
Expected Behavior This is how MathJax works

Comments

@pkienzle
Copy link

Issue Summary

With the amsmath package, LaTeX raises an error on \text{underscore_separated} unless there is a leading backslash before the underscore. Mathjax renders with and without the backslash, but shows the backslash if it is included. This means that you cannot use the same input for both html and latex markup.

Steps to Reproduce

  1. paste the following into the mathjax live demo page

    erfc is the complementary error function $1 - \text{error_function}(x)$.

  2. Compare this to the same markup in LaTeX (via overleaf shared latex editor):

    https://www.overleaf.com/read/xdcwcrkkwkns

Technical details

@pkra pkra added the Expected Behavior This is how MathJax works label Jun 16, 2017
@pkra
Copy link
Contributor

pkra commented Jun 16, 2017

That is expected behavior, cf. http://docs.mathjax.org/en/latest/tex.html#mathjax-tex-and-latex-support.

@dpvc
Copy link
Member

dpvc commented Jun 16, 2017

See also this forum post for a possible work-around.

@pkienzle
Copy link
Author

Seems awkward. In practice, I should be using \mathrm or \operatorname instead so that the fonts are correct, and these can be done with the same syntax in latex (both with the backslash before the underscore).

On further investigation of font issues, the following renders using the same font in latex, but on the mathjax demo page (OS/X firefox) the first character is serif and the second is sans serif:

$\text{i}$i

The first character renders with style="font-family: STIXGeneral;" in the text span, and style="... font-size: 120%;" in the $$ span. The second character inherits font-family and font-size directly from body. Latex renders these both with \familydefault.

@dpvc
Copy link
Member

dpvc commented Jun 16, 2017

Yes, \operatorname (or \mathrm) is to be preferred, and both will work in MathJax. Note, however, that both are working with math-mode material, while \textworks with text-mode material. MathJax does not implement any macros in text-mode material, as Peter points out. It will look for embedded math (e.g., \text{some math: $x+1$.}, and also \$, \{, and \}, as these are needed to override the default processing of $, {, and } within the text-mode material, but that is all. If you view the MathML generated from \mathrm{error\_function} and \text{error_function} you will see a significant difference between the two. The processing needed for text-mode material is very different from the needed for math-mode material, and that is outside MathJax's scope.

As I pointed out, you can override the InternalText() function to handle additional situations if you wish.

As for your example of $\text{i}$i, MathJax only handles the material between the dollar signs, not the rest of the page, so the second "i" is handled by the browser and the CSS that applies to it. MathJax does not affect that. You can configure MathJax to use the surrounding font for any text-mode material that it produces (see the mtextFontInherit option), but our demo page doesn't do that.

MathJax is not LaTeX, and it only handles math content. The rest of the page is marked up using HTML, and MathJax lives within that large ecosystem. The fact that the math font and the surrounding text font are different is not a bug, it is the expected behavior.

@pkienzle
Copy link
Author

The other option is to support underscore in latex text mode without the leading backslash. This can be done by adding a latex preamble to support underscores without backslashes:

\usepackage{underscore}
\usepackage[T1]{fontenc}

I'm including it for those who have the same problem in future and stumble across this discussion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Expected Behavior This is how MathJax works
Projects
None yet
Development

No branches or pull requests

3 participants