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

How to define \symrm in Mathjax 2.7 #3218

Open
wangzhen89 opened this issue Apr 14, 2024 · 3 comments
Open

How to define \symrm in Mathjax 2.7 #3218

wangzhen89 opened this issue Apr 14, 2024 · 3 comments
Labels
Code Example Contains an illustrative code example, solution, or work-around Question v2

Comments

@wangzhen89
Copy link

wangzhen89 commented Apr 14, 2024

Hi guys, I want to write bold but non-Italic Greek letters in bookdown html (rendered by Mathjax 2.7). One solution may be the commond \symrm, but it is not supported in Mathjax 2.7. And new version of Mathjax is not well supported in bookdown, see this issue.

So my problem is how to define \symrm in Mathjax 2.7.

Thanks!

@dpvc
Copy link
Member

dpvc commented Apr 15, 2024

The default MathJax-TeX fonts in v2 don't include upright versions of the Greek letters, bold or otherwise, so in order to accomplish this, you would need to use one of the other fonts. The STIX font does include the needed characters, so you could use that. Because the v2 CommonHTML output only supports MathJax-TeX, you would need to use either the older HTML-CSS output, or the SVG output renderer.

Here is a MathJax configuration that defines a version of \symbf that could be used to get bold upright Greek letters:

<script type="text/x-mathjax-config">
MathJax.Hub.Config({
  "HTML-CSS": {
    fonts: ["STIX-Web"]
  },
  SVG: {
    font: "STIX-Web"
  },
  TeX: {Augment: {
    Definitions: {macros: {symbf: 'Symbf'}},
    Parse: {prototype: {
      csMathchar0mi: function (name, mchar) {
        var MML = MathJax.ElementJax.mml;
        var def = {};
        if (Array.isArray(mchar)) {def = mchar[1]; mchar = mchar[0]}
        this.Push(this.mmlToken(MML.mi(MML.entity("#x"+mchar)).With(def)));
      },
      Symbf: function (name) {
        var MML = MathJax.ElementJax.mml;
        var math = this.ParseArg(name);
        this.Push(MML.mstyle(math).With({mathvariant: "bold"}));
      }
    }}
  }}
});
</script>
<script src="https://cdn.jsdelivr.net/npm/mathjax@2.7.9/unpacked/MathJax.js?config=TeX-AMS_SVG"></script>

The csMathchar0mi function is overriden to not include an explicit mathvariant="italic" that is in the original version, so that that mstyle element's mathvariant will be applied. This shouldn't hurt anything else, I think.

@dpvc dpvc added Question v2 Code Example Contains an illustrative code example, solution, or work-around labels Apr 15, 2024
@wangzhen89
Copy link
Author

Thanks! I am completely clueless about Mathjax, HTML, and JavaScript. But your codes run for me!
But how to set the default output as HTML-CSS so that I don't have to right-click on the formula and select it.
Really appreciated.

@dpvc
Copy link
Member

dpvc commented Apr 15, 2024

The example I have above uses SVG output, which should work for you. If you want to use HTML-CSS, then you have to change TeX-AMS_SVG to TeX-AMS_HTML.

It looks like bookdown has TeX-MML-AM_CHTML as the default in some of its templates (e.g., here, so you have to edit that to be TeX-AMS_HTML. It also looks like there may be some sort of mathjax variable that can be set to the URL of the MathJax you want to load. If you can change that value to

https://cdn.jsdelivr.net/npm/mathjax@2.7.9/unpacked/MathJax.js?config=TeX-AMS_HTML

that should also do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Code Example Contains an illustrative code example, solution, or work-around Question v2
Projects
None yet
Development

No branches or pull requests

2 participants