jupyter / notebook

Jupyter Interactive Notebook
https://jupyter-notebook.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
11.55k stars 4.84k forks source link

Jupyter Notebook overrides user Mathjax settings from custom.js #4514

Open sindzicat opened 5 years ago

sindzicat commented 5 years ago

Hello!

I found recently that my settings for Mathjax stopped to work.

It seems to me I understand correctly why.

When the web page of Jupyter Notebook is loading we load Mathjax first:

<script type="text/javascript" src="/static/components/MathJax/MathJax.js?config=TeX-AMS-MML_HTMLorMML-full,Safe&delayStartupUntil=configured" charset="utf-8"></script>

I see StartupUntil=configured at the end. According documentation this means that Mathjax will wait instrtuction MathJax.Hub.Configured().

I found such instruction only in one file — mathjaxutils.js (code line).

Then I found that mathjaxutils.js are called by script main.min.js at the end of <body>. File mathjaxutils.js contains own MathJax.Hub.Config, that called after user MathJax.Hub.Config from custom.js. So user settings for Mathjax will be overriden.

Of course I can change local mathjaxutils.js after installation and even write own python script that will watch this file... But it's not a good way. Please fix this.

-- Andrey.

sindzicat commented 5 years ago

Sorry, I found how to solve my problem.

In custom.js you need to use

MathJax.Hub.Config({
    tex2jax: {
        inlineMath: [["$", "$"], ["\\(", "\\)"]],
        displayMath: [["$$", "$$"], ["\\[", "\\]"]],
        processEscapes: true,
    },
    TeX: {
        Macros: {
            Alpha: "\\mbox{A}",
            Beta: "\\mbox{B}",
            Epsilon: "\\mbox{E}",
            Zeta: "\\mbox{Z}",
            Eta: "\\mbox{H}",
            Iota: "\\mbox{I}",
            Kappa: "\\mbox{K}",
            Mu: "\\mbox{M}",
            Nu: "\\mbox{N}",
            Omicron: "\\mbox{O}",
            Rho: "\\mbox{P}",
            Tau: "\\mbox{T}",
            Chi: "\\mbox{X}",
            and: "\\mbox{&}",
            or: "\\lor",
            exist: "\\exists",
            empty: "\\emptyset",
            P: "\\mbox{P}",
            tan: "\\operatorname{tg}",   // tangent
            tg: "\\operatorname{tg}",    // tangent
            cot: "\\operatorname{ctg}",  // cotangent
            ctg: "\\operatorname{ctg}",  // cotangent
            csc: "\\operatorname{cosec}",     // cosecant
            cosec: "\\operatorname{cosec}",   // cosecant
            arctan: "\\operatorname{arctg}",  // arctangent
            arctg: "\\operatorname{arctg}",   // arctangent
            arccot: "\\operatorname{arcctg}",      // arc cotangent
            arcctg: "\\operatorname{arcctg}",      // arc cotangent
            arcsec: "\\operatorname{arcsec}",      // arc secant
            arccsc: "\\operatorname{arccosec}",    // arc cosecant
            arccosec: "\\operatorname{arccosec}",  // arc cosecant
            sh: "\\operatorname{sh}",     // hyperbolic sine
            ch: "\\operatorname{ch}",     // hyperbolic cosine
            th: "\\operatorname{th}",     // hyperbolic tangent
            cth: "\\operatorname{cth}",   // hyperbolic cotangent
            sinh: "\\operatorname{sh}",   // hyperbolic синус
            cosh: "\\operatorname{ch}",   // hyperbolic cosine
            tanh: "\\operatorname{th}",   // hyperbolic tangent
            coth: "\\operatorname{cth}",  // hyperbolic cotangent
            sgn: "\\operatorname{sgn}",
            mod: "\\operatorname{mod}",
            ge: "\\geqslant",
            le: "\\leqslant",
            geq: "\\geqslant",
            leq: "\\leqslant",
            N: "\\mathbb{N}",
            R: "\\mathbb{R}",
            Q: "\\mathbb{Q}",
            Z: "\\mathbb{Z}",
            C: "\\mathbb{C}",
            H: "\\mathbb{H}",
            P: "\\mathbb{P}",
            dmtr: "\\unicode{x2300}", // diameter sign
            deg: "\\unicode{xb0}",    // degree sign
            celdeg: "\\unicode{x2103}"   // degree Celsius sign
        },
        // AutoNumbering of displayed formulas
        equationNumbers: { autoNumber: "AMS" },
        // All mathjax extensions:
        // http://docs.mathjax.org/en/latest/tex.html#tex-and-latex-extensions
        // Source code for all extensions:
        // https://github.com/mathjax/MathJax/tree/master/extensions/TeX
        extensions: [
            "color.js", // Color support in LaTeX
            "autobold.js", // support for \boldsymbol{...}
            "AMSmath.js",
            "AMSsymbols.js",
            "AMScd.js", // http://www.jmilne.org/not/Mamscd.pdf
            "bbox.js", // support for \bbox[options]{math}
            // "begingroup.js", // mainly for formulas localization
            "cancel.js" // support for strikethrough formulas
            // "HTML.js" // works by default
            // "mhchem.js" // chemical formulas
            // "uniconde.js" // works by default
        ]
    }
});
// http://docs.mathjax.org/en/latest/configuration.html#configuring-mathjax-after-it-is-loaded
MathJax.Hub.Configured()

The last line MathJax.Hub.Configure() must be presented. Now all works for me fine. The only I cannot understand — why this didn't work yesterday???

-- Andrey

sindzicat commented 5 years ago

Hm... After page reload doesn't work again...

sindzicat commented 5 years ago

I tried to add

TeX: {
    Macros: {
        tg: "\\operatorname{tg}"
    }
}

to main.min.js in MathJax.Hub.Config. Now \tg(x) works fine. But why only after that hack?

image

sindzicat commented 5 years ago

Is anybody here?