{"action":"created","issue":{"url":"https://api.github.com/repos/ipython/ipython/issues/8112","labels_url":"https://api.github.com/repos/ipython/ipython/issues/8112/labels{/name}","comments_url":"https://api.github.com/repos/ipython/ipython/issues/8112/comments","events_url":"https://api.github.com/repos/ipython/ipython/issues/8112/events","html_url":"https://github.com/ipython/ipython/issues/8112","id":63580255,"number":8112,"title":"No reasonable way to add MathJax configuration?","user":{"login":"mforbes","id":1028433,"avatar_url":"https://avatars.githubusercontent.com/u/1028433?v=3","gravatar_id":"","url":"https://api.github.com/users/mforbes","html_url":"https://github.com/mforbes","followers_url":"https://api.github.com/users/mforbes/followers","following_url":"https://api.github.com/users/mforbes/following{/other_user}","gists_url":"https://api.github.com/users/mforbes/gists{/gist_id}","starred_url":"https://api.github.com/users/mforbes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mforbes/subscriptions","organizations_url":"https://api.github.com/users/mforbes/orgs","repos_url":"https://api.github.com/users/mforbes/repos","events_url":"https://api.github.com/users/mforbes/events{/privacy}","received_events_url":"https://api.github.com/users/mforbes/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-22T21:55:06Z","updated_at":"2015-03-23T19:14:23Z","closed_at":null,"body":"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.\r\n\r\nOne suggestion would be to add a hook just before this call in``mathjaxutils.js`` :\r\n\r\n```python\r\n            events.trigger('mathjax_configured.Notebook');\r\n            MathJax.Hub.Configured();\r\n```\r\n\r\nThis at least allows one to include MathJax customization in the ``custom.js`` file.\r\n\r\nHowever, 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?\r\n\r\nAs a simple test, one can try to configure a new macro:\r\n\r\n```javascript\r\nMathJax.Hub.Config({ TeX: { Macros: { vect: [\"{\\\\vec #1}\",1]} } });\r\n```\r\n\r\nand then see if ``$$\\vect{x}$$`` renders properly with an arrow."},"comment":{"url":"https://api.github.com/repos/ipython/ipython/issues/comments/85154304","html_url":"https://github.com/ipython/ipython/issues/8112#issuecomment-85154304","issue_url":"https://api.github.com/repos/ipython/ipython/issues/8112","id":85154304,"user":{"login":"mforbes","id":1028433,"avatar_url":"https://avatars.githubusercontent.com/u/1028433?v=3","gravatar_id":"","url":"https://api.github.com/users/mforbes","html_url":"https://github.com/mforbes","followers_url":"https://api.github.com/users/mforbes/followers","following_url":"https://api.github.com/users/mforbes/following{/other_user}","gists_url":"https://api.github.com/users/mforbes/gists{/gist_id}","starred_url":"https://api.github.com/users/mforbes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mforbes/subscriptions","organizations_url":"https://api.github.com/users/mforbes/orgs","repos_url":"https://api.github.com/users/mforbes/repos","events_url":"https://api.github.com/users/mforbes/events{/privacy}","received_events_url":"https://api.github.com/users/mforbes/received_events","type":"User","site_admin":false},"created_at":"2015-03-23T19:14:23Z","updated_at":"2015-03-23T19:14:23Z","body":"@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?\r\n\r\nInjecting configurations explicitly with either ``%%javascript`` or ``HTML`` still fails, but I at least have a work-around now:\r\n\r\n1. 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:\r\n\r\n```javascript\r\nMathJax.Hub.Config({\r\n  \"HTML-CSS\": {\r\n      availableFonts: [\"Neo-Euler\"], preferredFont: \"Neo-Euler\",\r\n      webFont: \"Neo-Euler\",\r\n      mtextFontInherit: true,\r\n      matchFontHeight: true,\r\n      scale: 85, // Euler is a bit big.\r\n  },\r\n  \"SVG\": {\r\n      font: \"Neo-Euler\",\r\n  },\r\n  \"TeX\": {\r\n    Macros: {\r\n      d: [\"\\\\mathrm{d}\"],\r\n      vect: [\"{\\\\vec #1}\",1],\r\n      abs: [\"{\\\\lvert #1 \\\\rvert}\",1]\r\n    }\r\n  }\r\n});\r\n```\r\n2. 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:\r\n\r\n```HTML\r\n<script type=\"text/javascript\">\r\nMathJax.Hub.Config({\r\n  \"HTML-CSS\": {\r\n      availableFonts: [\"Neo-Euler\"], preferredFont: \"Neo-Euler\",\r\n      webFont: \"Neo-Euler\",\r\n      mtextFontInherit: true,\r\n      matchFontHeight: true,\r\n      scale: 85, // Euler is a bit big.\r\n  },\r\n  \"SVG\": {\r\n      font: \"Neo-Euler\",\r\n  },\r\n  \"TeX\": {\r\n    Macros: {\r\n      d: [\"\\\\mathrm{d}\"],\r\n      vect: [\"{\\\\vec #1}\",1],\r\n      abs: [\"{\\\\lvert #1 \\\\rvert}\",1]\r\n    }\r\n  }\r\n});\r\n</script>\r\n\r\n3. Include any customizations in a LaTeX style file for latex conversion.\r\n\r\n```latex\r\n\\usepackage[small]{eulervm}\r\n\\newcommand{\\vect}[1]{\\vec{#1}}\r\n\\newcommand{\\abs}[1]{\\lvert#1\\rvert|}\r\n\\let\\d\\relax  % \\d already defined and there is no \\RedeclareMathOperator\r\n\\DeclareMathOperator{\\d}{d}\r\n```\r\n\r\nIt 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.\r\n\r\nThe 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.)"}}