Skip to content

Commit 951523d

Browse files
committed
Support rendering tex even when global MathJax rendering mode is not SVG
1. Specify the SVG font 2. Set rendering mode to SVG just prior to typesetting, then restore it to it's original value just afterwards With this change, latex rendering works in the following MathJax configurations: - TeX-MML-AM_CHTML - TeX-MML-AM_HTMLorMML - TeX-MML-AM_SVG - TeX-AMS-MML_HTMLorMML - TeX-AMS_CHTML - TeX-AMS_SVG - TeX-AMS_HTML - TeX-AMS-MML_SVG (It still does not work if the global MathJax TeX extensions are not loaded.) Previously it only worked in the TeX-AMS-MML_SVG configuration. Also, with these changes latex rendering works without any additional configuration when used from Python (and probably R) inside the Jupyter Notebook.
1 parent 2a667d0 commit 951523d

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/fonts/mathjax_config.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ if(typeof MathJax !== 'undefined') {
2222
displayAlign: 'left',
2323
tex2jax: {
2424
inlineMath: [['$', '$'], ['\\(', '\\)']]
25-
}
25+
},
26+
SVG: {font: 'STIX-Web'},
2627
});
2728

2829
MathJax.Hub.Configured();

src/lib/svg_text_utils.js

+13-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,19 @@ function texToSVG(_texString, _config, _callback) {
170170
.style({'font-size': _config.fontSize + 'px'})
171171
.text(cleanEscapesForTex(_texString));
172172

173-
MathJax.Hub.Queue(['Typeset', MathJax.Hub, tmpDiv.node()], function() {
173+
var originalRenderer;
174+
MathJax.Hub.Queue(function() {
175+
// Get original renderer
176+
originalRenderer = MathJax.Hub.config.menuSettings.renderer;
177+
},
178+
['setRenderer', MathJax.Hub, 'SVG'],
179+
['Typeset', MathJax.Hub, tmpDiv.node()],
180+
function() {
181+
// Restore original renderer if not SVG
182+
if(originalRenderer !== 'SVG') {
183+
MathJax.Hub.Queue(['setRenderer', MathJax.Hub, originalRenderer]);
184+
}
185+
174186
var glyphDefs = d3.select('body').select('#MathJax_SVG_glyphs');
175187

176188
if(tmpDiv.select('.MathJax_SVG').empty() || !tmpDiv.select('svg').node()) {

0 commit comments

Comments
 (0)