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

No reasonable way to add MathJax configuration? #8112

Closed
mforbes opened this issue Mar 22, 2015 · 4 comments
Closed

No reasonable way to add MathJax configuration? #8112

mforbes opened this issue Mar 22, 2015 · 4 comments
Labels
Milestone

Comments

@mforbes
Copy link

mforbes commented Mar 22, 2015

MathJax seems to be loaded too early to allow for any user customization. Unfortunately, once it is loaded there seems to be no easy way to change the configuration. It is loaded early in templates/notebook.html with the delayStartupUntil=configured flag which in principle should allow customization, but then MathJax.Hub.Configured() is called in static/notebook/js/mathjaxutils.js before any hooks are called, so there is no reasonable place to insert ones own customization in time.

One suggestion would be to add a hook just before this call inmathjaxutils.js :

            events.trigger('mathjax_configured.Notebook');
            MathJax.Hub.Configured();

This at least allows one to include MathJax customization in the custom.js file.

However, there should also be a solution that allows people to include customization from a notebook cell, i.e. so that it can be used by NBViewer, or distributed in a notebook cell. Is there a way to delay the call to MathJax.Hub.Configured() until after the last cell in a notebook so that a customization could be injected with an HTML() tag, or will that seriously break something?

As a simple test, one can try to configure a new macro:

MathJax.Hub.Config({ TeX: { Macros: { vect: ["{\\vec #1}",1]} } });

and then see if $$\vect{x}$$ renders properly with an arrow.

@mforbes
Copy link
Author

mforbes commented Mar 22, 2015

I discussed this issue a bit on SO and should clarify a point. Injecting HTML() in the notebook will work on NBViewer and when static HTML pages are generated, but I cannot figure out how to get this to work in live notebooks for some reason.

@juhasch
Copy link
Contributor

juhasch commented Mar 22, 2015

This works for me in custom.js if you add quotes:

MathJax.Hub.Config({ "TeX": { Macros: { vect: ["{\\vec #1}",1]} } });

@mforbes
Copy link
Author

mforbes commented Mar 23, 2015

@juhasch ???!!! Thanks! That does work... no idea why. Note that the MathJax documentation has no quotes. Also, how does this work when custom.js is loaded after the Configured() call?

Injecting configurations explicitly with either %%javascript or HTML still fails, but I at least have a work-around now:

  1. Include the relevant configuration in custom.js with the quotes. This will configure the notebook in the live server. For example, the following enables the Neo-Euler font scaled to match Palatino as the body font:
MathJax.Hub.Config({
  "HTML-CSS": {
      availableFonts: ["Neo-Euler"], preferredFont: "Neo-Euler",
      webFont: "Neo-Euler",
      mtextFontInherit: true,
      matchFontHeight: true,
      scale: 85, // Euler is a bit big.
  },
  "SVG": {
      font: "Neo-Euler",
  },
  "TeX": {
    Macros: {
      d: ["\\mathrm{d}"],
      vect: ["{\\vec #1}",1],
      abs: ["{\\lvert #1 \\rvert}",1]
    }
  }
});
  1. Include a <script> tag in the markdown as the last cell of the notebook. This will get rendered in the HTML file produced by NBConvert for viewing on NBServer:
<script type="text/javascript">
MathJax.Hub.Config({
  "HTML-CSS": {
      availableFonts: ["Neo-Euler"], preferredFont: "Neo-Euler",
      webFont: "Neo-Euler",
      mtextFontInherit: true,
      matchFontHeight: true,
      scale: 85, // Euler is a bit big.
  },
  "SVG": {
      font: "Neo-Euler",
  },
  "TeX": {
    Macros: {
      d: ["\\mathrm{d}"],
      vect: ["{\\vec #1}",1],
      abs: ["{\\lvert #1 \\rvert}",1]
    }
  }
});
</script>

3. Include any customizations in a LaTeX style file for latex conversion.

```latex
\usepackage[small]{eulervm}
\newcommand{\vect}[1]{\vec{#1}}
\newcommand{\abs}[1]{\lvert#1\rvert|}
\let\d\relax  % \d already defined and there is no \RedeclareMathOperator
\DeclareMathOperator{\d}{d}

It would still be nice if there was a solution that worked without having to modify a users custom.js file or NBConvert templayes, but perhaps that is all reasonable via an extension (have not fully figured that out yet.) In any case, this at least gives a way forward.

The issue about the quotes needs to be addressed somewhere though. Should I open a new ticket? (I really have no idea at this point why it works with quotes.)

@takluyver takluyver added this to the not ipython milestone Jan 26, 2016
@Carreau
Copy link
Member

Carreau commented Jul 23, 2017

Closing as this issue is not in IPython itself and if still problematic and relevant should be opened on the right repository. This will allow to keep the number of opened issue on the IPython repo under control.

Feel free to keep commenting or reopen if necessary.

Thanks.

@Carreau Carreau closed this as completed Jul 23, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants