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

MathJax config #2750

Closed
ickc opened this issue Mar 2, 2016 · 8 comments
Closed

MathJax config #2750

ickc opened this issue Mar 2, 2016 · 8 comments

Comments

@ickc
Copy link
Contributor

ickc commented Mar 2, 2016

Hi,

I want to have a custom setup of MathJax, like this:

<script type="text/x-mathjax-config">
    MathJax.Ajax.config.path["Contrib"] = "https://cdn.mathjax.org/mathjax/contrib";
    MathJax.Hub.Register.StartupHook("TeX Jax Ready",function () {
        MathJax.Hub.Insert(MathJax.InputJax.TeX.Definitions.macros,{
            cancel: ["Extension","cancel"],
            bcancel: ["Extension","cancel"],
            xcancel: ["Extension","cancel"],
            cancelto: ["Extension","cancel"]
        });
    });
    MathJax.Hub.Config({
        TeX: {
            equationNumbers: { autoNumber: "AMS"},
            extensions: ["[Contrib]/physics/physics.js", "[Contrib]/siunitx/siunitx.js"]
        }
    });
</script>

I tried to dig into the documentation and also search through the issues, but there seems to have no reference on it.

Note that according to MathJax, the setup has to come before the MathJax is loaded. So if I put the above code in the beginning of the Markdown file, and using pandoc --mathjax -s -o the mathjax is put in the head and hence the setup will comes after it.

So what's the best way to do this? Template? Are there any way to put something in the head of the html without touching the template? And are there any way to config the mathjax in addition to the link to cdn?

Thanks.

@jgm
Copy link
Owner

jgm commented Mar 2, 2016 via email

@ickc
Copy link
Contributor Author

ickc commented Mar 2, 2016

I see. Thanks!

@ickc ickc closed this as completed Mar 2, 2016
@KeAWang
Copy link

KeAWang commented Dec 17, 2021

Do you have an example of how to do this?

@ickc
Copy link
Contributor Author

ickc commented Dec 18, 2021

First, you need to follow the doc from MathJax to setup your MathJax config.

Assuming you already done that, the problem with using that in pandoc is that the location of loading the MathJax javascript and the header-includes is wrong. I think for a while @jgm has considered to change this ordering (there was a PR somewhere in the past.) But in the end he decided to not change that.

So it means your only bet of getting that work is to have a custom template that you have swap the order of that 2 manually. See Pandoc - Pandoc User’s Guide for more about how you get the template.

If you have more question, provide a reproducible set of files and instructions you have gone through so far that didn't work, and I may be able to give you some more hints.

@ickc
Copy link
Contributor Author

ickc commented Dec 18, 2021

Ah, I found an old commit as an example: ickc/pandoc-templates-legacy@b6732ae

More details:

jgm/pandoc-templates was a separate repository in the past, but is now currently a git subtree of jgm/pandoc. This means that all history in jgm/pandoc-templates was lost.

The above fork was a fork of the old jgm/pandoc-templates. The shown there is an example of what you need to do (to swap the ordering of loading.) On top of that you need to have a header-includes or --include-in-header (see pandoc manual) for your javascript mathjax config.

@KeAWang
Copy link

KeAWang commented Dec 18, 2021

Thank you that worked perfectly!

@jgm
Copy link
Owner

jgm commented Dec 18, 2021

@ickc I don't really recall this issue.
Were you asking for the MathJax script to be moved to the end of the body, instead of the head, in the custom template? Perhaps we should revisit this.

@ickc
Copy link
Contributor Author

ickc commented Jan 14, 2022

I opened #7833 tracking this. This is essentially the same patch at ickc/pandoc-templates-legacy@b6732ae before.
We can move discussion to #7833.

@ickc ickc changed the title MathJax Setup MathJax config Jan 14, 2022
jgm pushed a commit that referenced this issue Jan 14, 2022
MathJax expect the config comes before loading the MathJax script.
This change of order allows one to config MathJax via header-includes,
which loads before the MathJax script.

This potentially is a breaking change.

However, the only kind math supported by pandoc that is configurable
seems to be katex, and according to src/Text/Pandoc/Writers/HTML.hs
the way it is configured is hard-coded (katex doesn't seem to offer
MathJax style config that is independent of loading katex.)
So it seems it is safe to change this order without breaking
others' documents.

c.f. #2750
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants