\texttt{SOME\_CONSTANT} does not display properly \_

57 views
Skip to first unread message

Vincent Belaïche

unread,
Mar 1, 2022, 4:45:46 AM3/1/22
to MathJax Users
Hello,

I have a formula that mixes some math and some computer C language symbol SOME_CONSTANT, as follows :

--------8<-----------8<-----------8<-----------8<-----------8<-------
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="fr" xml:lang="fr">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Minimum working example</title>
<meta name="author" content="Vincent" />
<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
        displayAlign: "center",
        displayIndent: "0em",

        "HTML-CSS": { scale: 100,
                        linebreaks: { automatic: "false" },
                        webFont: "TeX"
                       },
        SVG: {scale: 100,
              linebreaks: { automatic: "false" },
              font: "TeX"},
        NativeMML: {scale: 100},
        TeX: { equationNumbers: {autoNumber: "AMS"},
               MultLineWidth: "85%",
               TagSide: "right",
               TagIndent: ".8em"
             }
});
</script>
<script type="text/javascript" id="MathJax-script" async
  src="https://cdn.jsdelivr.net/npm/mathjax@3/es5/tex-mml-chtml.js?config=TeX-AMS_HTML">
</script>
</head>
<body>
This: \(-2^{\texttt{SOME\_CONSTANT}}\).
</body>
</html>
--------8<-----------8<-----------8<-----------8<-----------8<-------
 
Now the \_ does not display as just _, but as \_.

To tell the context, I generate the page from some Emacs OrgMode document, and therefore I need some syntax that works both with the OrgMode LaTeX export and with the OrgMode HTML export, the latter using MathJax.

I can find some  OrgMode based work-around with some hook preprocessing the content of formulas, or by changing the option how OrgMode processes the ^/_ (super/under)scripts. But I was wondering whether there is some mathjax based setting to do this also.

Thanks in advance for any clue.
  Vincent. 

Vincent Belaïche

unread,
Mar 1, 2022, 5:57:52 AM3/1/22
to MathJax Users
Just for information, answering to myself, the fix I used was just to replace \_ by _ in the formulae text parts, and configure OrgMode to insert \usepackage{underscore} into the LaTeX export.

  V.

Davide Cervone

unread,
Mar 1, 2022, 12:05:36 PM3/1/22
to mathja...@googlegroups.com
Since MathJax is designed to handle mathematics, MathJax doesn't process macros in text-mode by default.  That includes the contents of things like \texttt{}.  MathJax version 3 includes an extension that allows it to handle a number of text-mode macros, however, so if you use that, you would be able to get what you want.

Your example code mixes a version 2 configuration with a script tag that loads version 3 of MathJax.  MathJax version 3 has a different API, and so the version 2 configuration has no effect on the version of MathJax you are loading.  Most of what you have in your configuration is the default behavior for MathJax (both version 2 and version 3), so very little of that is necessary.  Also, although you have indicated that your page is XHTML, the script tag that loads MathJax is not valid XHTML:  the async attribute would need to have an explicit value in XHTML, so async="true" would be needed.

Here is a configuration and script to load MathJax that should do what you need:

<script>
  MathJax = {
    loader: {load: ['[tex]/textmacros']},
    tex: {
      tags: "ams",
      packages: {'[+]': ['textmacros']}
    }
  };
</script>
<script type="text/javascript" id="MathJax-script" async="true"
</script>

The rest of the configuration just restates the default behavior, so is unneeded.  Since you has specified the TeX-AMS_HTML v2 configuration, I have changed to the tex-chtml.js v3 component, since you don't seem to need MathML input.

Davide


--
You received this message because you are subscribed to the Google Groups "MathJax Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mathjax-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/mathjax-users/63e15bd7-ff38-41b5-8545-1ede0261727bn%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages