Skip to content

Commit

Permalink
fix: add correct css and call back for mathjax
Browse files Browse the repository at this point in the history
  • Loading branch information
leangseu-edx committed Jul 24, 2023
1 parent 6bdeb34 commit 6261005
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 28 deletions.
29 changes: 17 additions & 12 deletions cms/djangoapps/pipeline_js/js/xmodule.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ define(
'mathjax',
function() {
window.MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%' },
// This is to resolve for people who use center mathjax with tables
'table>tbody>tr>td>.MathJax_SVG>svg': { 'max-width': 'inherit'},
},
tex2jax: {
inlineMath: [
['\\(', '\\)'],
Expand Down Expand Up @@ -57,19 +62,19 @@ define(
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);
t = window.setTimeout(function() {
oldWidth = document.documentElement.scrollWidth;
MathJax.Hub.Queue(
["Rerender", MathJax.Hub],
[() => $('.MathJax_SVG>svg').toArray().forEach(el => {
if ($(el).width() === 0) {
$(el).css('max-width', 'inherit');
}
})]
);
t = -1;
}, delay);
}

// this is added to compensate for custom css that accidentally hide mathjax
$('.MathJax_SVG>svg').toArray().forEach(el => {
if ($(el).width() === 0) {
$(el).css('max-width', 'inherit');
}
});
};
}
);
Expand Down
18 changes: 10 additions & 8 deletions cms/templates/content_libraries/xblock_iframe.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%' },
// This is to resolve for people who use center mathjax with tables
'table>tbody>tr>td>.MathJax_SVG>svg': { 'max-width': 'inherit'},
},
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
Expand Down Expand Up @@ -111,17 +113,17 @@
if (oldWidth !== document.documentElement.scrollWidth) {
t = window.setTimeout(function() {
oldWidth = document.documentElement.scrollWidth;
MathJax.Hub.Queue(["Rerender", MathJax.Hub]);
MathJax.Hub.Queue(
["Rerender", MathJax.Hub],
[() => $('.MathJax_SVG>svg').toArray().forEach(el => {
if ($(el).width() === 0) {
$(el).css('max-width', 'inherit');
}
})]
);
t = -1;
}, delay);
}

// this is added to compensate for custom css that accidentally hide mathjax
$('.MathJax_SVG>svg').toArray().forEach(el => {
if ($(el).width() === 0) {
$(el).css('max-width', 'inherit');
}
});
};
</script>
<script type="text/x-mathjax-config">
Expand Down
20 changes: 12 additions & 8 deletions common/templates/mathjax_include.html
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%', },
// This is to resolve for people who use center mathjax with tables
'table>tbody>tr>td>.MathJax_SVG>svg': { 'max-width': 'inherit'},
},
CommonHTML: { linebreaks: { automatic: true } },
SVG: { linebreaks: { automatic: true } },
Expand All @@ -44,6 +46,8 @@
MathJax.Hub.Config({
styles: {
'.MathJax_SVG>svg': { 'max-width': '100%', },
// This is to resolve for people who use center mathjax with tables
'table>tbody>tr>td>.MathJax_SVG>svg': { 'max-width': 'inherit'},
},
messageStyle: "none",
CommonHTML: { linebreaks: { automatic: true } },
Expand Down Expand Up @@ -110,17 +114,17 @@
if (oldWidth !== document.documentElement.scrollWidth) {
t = window.setTimeout(function() {
oldWidth = document.documentElement.scrollWidth;
MathJax.Hub.Queue(["Rerender", MathJax.Hub]);
MathJax.Hub.Queue(
["Rerender", MathJax.Hub],
[() => $('.MathJax_SVG>svg').toArray().forEach(el => {
if ($(el).width() === 0) {
$(el).css('max-width', 'inherit');
}
})]
);
t = -1;
}, delay);
}

// this is added to compensate for custom css that accidentally hide mathjax
$('.MathJax_SVG>svg').toArray().forEach(el => {
if ($(el).width() === 0) {
$(el).css('max-width', 'inherit');
}
});
};
</script>

Expand Down

0 comments on commit 6261005

Please sign in to comment.