Skip to content

Commit

Permalink
fix: MathJax equations flickering (openedx#32696)
Browse files Browse the repository at this point in the history
* Revert "Revert "fix: mathjax resize on sindow resize (openedx#32606)""

This reverts commit 9dac65a.

* fix: mathjax wrap overflow and flickering
  • Loading branch information
leangseu-edx authored Jul 11, 2023
1 parent 5c0dddd commit 2025a3b
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cms/djangoapps/pipeline_js/js/xmodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ define(
['\\[', '\\]'],
['[mathjax]', '[/mathjax]']
]
}
},
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
"HTML-CSS": { linebreaks: { automatic: true } },
});

// In order to eliminate all flashing during interactive
Expand All @@ -42,6 +45,25 @@ define(
// the fast preview setting as shown in the context menu.
window.MathJax.Hub.processSectionDelay = 0;
window.MathJax.Hub.Configured();

window.addEventListener('resize', MJrenderer);

let t = -1;
let delay = 1000;
let oldWidth = document.documentElement.scrollWidth;
function MJrenderer() {
// don't rerender if the window is the same size as before
if (t >= 0) {
window.clearTimeout(t);
}
if (oldWidth !== document.documentElement.scrollWidth) {
t = window.setTimeout(function() {
oldWidth = document.documentElement.scrollWidth;
MathJax.Hub.Queue(["Rerender", MathJax.Hub]);
t = -1;
}, delay);
}
};
}
);
window.CodeMirror = CodeMirror;
Expand Down
24 changes: 24 additions & 0 deletions cms/templates/content_libraries/xblock_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@
<!-- Configure and load MathJax -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%' },
},
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
"HTML-CSS": { linebreaks: { automatic: true } },
tex2jax: {
inlineMath: [
["\\(","\\)"],
Expand All @@ -92,6 +98,24 @@
]
}
});
window.addEventListener('resize', MJrenderer);

let t = -1;
let delay = 1000;
let oldWidth = document.documentElement.scrollWidth;
function MJrenderer() {
// don't rerender if the window is the same size as before
if (t >= 0) {
window.clearTimeout(t);
}
if (oldWidth !== document.documentElement.scrollWidth) {
t = window.setTimeout(function() {
oldWidth = document.documentElement.scrollWidth;
MathJax.Hub.Queue(["Rerender", MathJax.Hub]);
t = -1;
}, delay);
}
};
</script>
<script type="text/x-mathjax-config">
MathJax.Hub.signal.Interest(function(message) {
Expand Down
30 changes: 30 additions & 0 deletions common/templates/mathjax_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,26 @@
%if mathjax_mode is not Undefined and mathjax_mode == 'wiki':
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%', },
},
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
"HTML-CSS": { linebreaks: { automatic: true } },
tex2jax: {inlineMath: [ ['$','$'], ["\\(","\\)"]],
displayMath: [ ['$$','$$'], ["\\[","\\]"]]}
});
</script>
%else:
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%', },
},
messageStyle: "none",
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
"HTML-CSS": { linebreaks: { automatic: true } },
tex2jax: {
inlineMath: [
["\\(","\\)"],
Expand Down Expand Up @@ -85,6 +97,24 @@
explorer: true
}
};
window.addEventListener('resize', MJrenderer);

let t = -1;
let delay = 1000;
let oldWidth = document.documentElement.scrollWidth;
function MJrenderer() {
// don't rerender if the window is the same size as before
if (t >= 0) {
window.clearTimeout(t);
}
if (oldWidth !== document.documentElement.scrollWidth) {
t = window.setTimeout(function() {
oldWidth = document.documentElement.scrollWidth;
MathJax.Hub.Queue(["Rerender", MathJax.Hub]);
t = -1;
}, delay);
}
};
</script>

<!-- This must appear after all mathjax-config blocks, so it is after the imports from the other templates.
Expand Down

0 comments on commit 2025a3b

Please sign in to comment.