{"action":"created","issue":{"url":"https://api.github.com/repos/plotly/plotly.js/issues/2994","repository_url":"https://api.github.com/repos/plotly/plotly.js","labels_url":"https://api.github.com/repos/plotly/plotly.js/issues/2994/labels{/name}","comments_url":"https://api.github.com/repos/plotly/plotly.js/issues/2994/comments","events_url":"https://api.github.com/repos/plotly/plotly.js/issues/2994/events","html_url":"https://github.com/plotly/plotly.js/pull/2994","id":359091665,"node_id":"MDExOlB1bGxSZXF1ZXN0MjE0NjY2NTY3","number":2994,"title":"Support rendering tex even when global MathJax rendering mode is not SVG","user":{"login":"jonmmease","id":15064365,"node_id":"MDQ6VXNlcjE1MDY0MzY1","avatar_url":"https://avatars1.githubusercontent.com/u/15064365?v=4","gravatar_id":"","url":"https://api.github.com/users/jonmmease","html_url":"https://github.com/jonmmease","followers_url":"https://api.github.com/users/jonmmease/followers","following_url":"https://api.github.com/users/jonmmease/following{/other_user}","gists_url":"https://api.github.com/users/jonmmease/gists{/gist_id}","starred_url":"https://api.github.com/users/jonmmease/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonmmease/subscriptions","organizations_url":"https://api.github.com/users/jonmmease/orgs","repos_url":"https://api.github.com/users/jonmmease/repos","events_url":"https://api.github.com/users/jonmmease/events{/privacy}","received_events_url":"https://api.github.com/users/jonmmease/received_events","type":"User","site_admin":false},"labels":[{"id":330750542,"node_id":"MDU6TGFiZWwzMzA3NTA1NDI=","url":"https://api.github.com/repos/plotly/plotly.js/labels/status:%20in%20progress","name":"status: in progress","color":"b2df8a","default":false},{"id":282886923,"node_id":"MDU6TGFiZWwyODI4ODY5MjM=","url":"https://api.github.com/repos/plotly/plotly.js/labels/type:%20bug","name":"type: bug","color":"e31a1c","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":9,"created_at":"2018-09-11T15:09:14Z","updated_at":"2018-09-13T00:32:11Z","closed_at":null,"author_association":"NONE","pull_request":{"url":"https://api.github.com/repos/plotly/plotly.js/pulls/2994","html_url":"https://github.com/plotly/plotly.js/pull/2994","diff_url":"https://github.com/plotly/plotly.js/pull/2994.diff","patch_url":"https://github.com/plotly/plotly.js/pull/2994.patch"},"body":"This PR makes two small changes, that together make it possible for Plotly.js to successfully render Latex even when the global MathJax rendering mode is not SVG (For example, in the Jupyter Notebook)\r\n\r\nChanges:\r\n 1. Specify the SVG font explicitly\r\n 2. Set rendering mode to SVG just prior to typesetting, then restore it to it's original value just afterwards\r\n\r\nWith this change, latex rendering works in the following MathJax [combined configurations](http://docs.mathjax.org/en/latest/config-files.html):\r\n - TeX-MML-AM_CHTML\r\n - TeX-MML-AM_HTMLorMML\r\n - TeX-MML-AM_SVG\r\n - TeX-AMS-MML_HTMLorMML\r\n - TeX-AMS_CHTML\r\n - TeX-AMS_SVG\r\n - TeX-AMS_HTML\r\n - TeX-AMS-MML_SVG\r\n\r\nPreviously it only worked in the TeX-AMS-MML_SVG configuration.\r\n\r\n(Note: It still does not work if the global MathJax TeX extensions are not loaded, as in the case for the \"AM_SVG\" configuration for example.)\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/plotly/plotly.js/issues/comments/420842893","html_url":"https://github.com/plotly/plotly.js/pull/2994#issuecomment-420842893","issue_url":"https://api.github.com/repos/plotly/plotly.js/issues/2994","id":420842893,"node_id":"MDEyOklzc3VlQ29tbWVudDQyMDg0Mjg5Mw==","user":{"login":"jonmmease","id":15064365,"node_id":"MDQ6VXNlcjE1MDY0MzY1","avatar_url":"https://avatars1.githubusercontent.com/u/15064365?v=4","gravatar_id":"","url":"https://api.github.com/users/jonmmease","html_url":"https://github.com/jonmmease","followers_url":"https://api.github.com/users/jonmmease/followers","following_url":"https://api.github.com/users/jonmmease/following{/other_user}","gists_url":"https://api.github.com/users/jonmmease/gists{/gist_id}","starred_url":"https://api.github.com/users/jonmmease/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jonmmease/subscriptions","organizations_url":"https://api.github.com/users/jonmmease/orgs","repos_url":"https://api.github.com/users/jonmmease/repos","events_url":"https://api.github.com/users/jonmmease/events{/privacy}","received_events_url":"https://api.github.com/users/jonmmease/received_events","type":"User","site_admin":false},"created_at":"2018-09-13T00:32:11Z","updated_at":"2018-09-13T00:32:11Z","author_association":"NONE","body":"#### Some more observations/thoughts.\r\n\r\nIt appears that not all of the config settings can be set and unset successfully.  For example, it doesn't look like it's possible for the outer context to use the `TeX` font and plotly.js to use `STIX-Web`.  So if we don't set `skipStartupTypeset` to `true`, or if we are not the first component to use SVG rendering, then we may not get to choose our own font.\r\n\r\nAlso, if we don't disable startup typesetting then the annoying \"MathJax rendering\" notifications display in the bottom of the browser on load. These are currently disabled by setting `messageStyle` to `'none'` in `mathjax_config`.\r\n\r\n#### Proposal\r\nSo here's a proposal for a compromise between where we are, what we want, and what MathJax can do.\r\n\r\n 1. Keep our current `mathjax_config.js` configuration file but remove the `displayAlign` and `messageStyle` properties.\r\n\r\n```javascript\r\n    MathJax.Hub.Config({\r\n        skipStartupTypeset: true,\r\n        tex2jax: {\r\n                inlineMath: [['$', '$'], ['\\\\(', '\\\\)']]\r\n        },\r\n    });\r\n```\r\n 2. Then for each rendering call we set the renderer to SVG and set the `displayAlign` and `messageStyle` properties as we want them. \r\n\r\n```javascript\r\n        MathJax.Hub.Config({\r\n            messageStyle: 'none',\r\n            displayAlign: 'left',\r\n        })\r\n```\r\nThen we restore the renderer and configuration afterward.\r\n\r\n3. We leave the SVG font unspecified\r\n\r\n#### Rational\r\n1. `skipStartupTypeset: true` and these inline math delimiters are useful defaults that existing plotly.js users may be relying on and they are consistent with those set in the Jupyter notebook.\r\n\r\n2. On the other hand `messageStyle: 'none'` and `displayAlign: 'left'` are settings that are in conflict with those specified by jupyter, and it appears that MathJax allows us to set and unset them successfully.\r\n\r\n3. By not specifying the SVG font explicitly there is no change in default behavior and users still have the option of changing it themselves. And the plotly.js tests shouldn't need to be updated.\r\n\r\n#### Implications\r\n\r\n**for plotly.js users:** This would only be breaking if they were relying on the presence of Plotly.js to set the global alignment to `left` or to disable all MathJax messages.  In exchange, plotly.js will play much better with other MathJax components, especially those with non-SVG rendering modes.\r\n\r\n**for plotly.py:** Plotly.py will be responsible for making sure that MathJax is configured with an available SVG font before invoking plotly.js.  This will be done in a small straightforward bit of extra logic for `plotly.offline.plot`, `plotly.offline.iplot` and `FigureWidget`.\r\n\r\n**for nbconvert / sphnix / etc.:**.   To work with and without plotly.js, I would recommend they too configure MathJax with `skipStartupTypeset: true` and then explicitly call `MathJax.Hub.Queue(['Typeset', MathJax.Hub]);` after everything is loaded.  This isn't ideal, but currently they don't work at all with plotly.js so this will certainly be an improvement.\r\n\r\nIf all three of these projects/groups adapt in these ways, then I think plotly.js latex could finally be widely used in these important technical computing contexts.\r\n"}}
{"actor":{"display_login":"jonmmease"}}