Open dotlambda opened 7 years ago
Is this an reveal.js issue?
Yes, because when using MathJax CHTML output on a blank website without reveal.js, it works just fine.
I just had the same problem and found a partial solution: You have to disable the style reset for in reveal's CSS, i.e., remove ".reveal span" from line 11 of reveal.js/css/reveal.css. This solved the font and spacing issues for me.
However, it seems that on slide changes equations are not always properly typeset. The equations appear way too small. Reloading that slide triggers a correct typesetting. No clue what the problem is, since the plugin math.js seems to trigger MathJax typeset on slide change events.
The issue comes from the way that reveal.js does the reset styles.
the reset only applies to subclasses of the div with a class reveal
.
Sadly, this adds specificity for the css parser. It's more specific to set a property on .reveal span
than on .MJX-char
for example. So it overrides the font usage.
A good solution for that would be to reset all html elements instead of only the ones in the reveal div.
I've come across the same issue and ended up with the same solution as @mbotsch. However, the solution proposed by @NuclearCookie would be a more permanent solution for the future usage of reveal.js + MathJax
I use Reveal for teaching math-heavy courses and found the CommonHTML output of MathJax to be more consistent between browsers and between operating systems than the old HTML output. Since the default output of MathJax is CommonHTML since version 2.7, it would be really cool if Reveal could switch to that.
Here's the solution that worked for me:
1) Remove the style reset for .reveal span
from reveal.css. I agree that the solution of @NuclearCookie is probably better.
2) Even then I had problems that with fonts being way too small when I set Reveal's viewDistance to a small value (which I have to for some performance reasons) and then switch to a slide with equations that becomes visible but was not visible at the time of (re)loading the slides. This problem is caused by MathJax trying to adjust its font size in order to match the text's actual, rendered font size. I just disabled the font size adjustment, which also resolved the problem that the same equation on two successive slides might slightly change its size. I had to adjust the MathJax config like this:
MathJax.Hub.Config({ jax: ["input/TeX","output/CommonHTML"], "CommonHTML": { matchFontHeight: false } });
With these two adjustments, which could probably be integrated easily, the CommonHTML works like a charme.
KaTeX fonts are also being overriden by .reveal span
. This results in ugly typesetting.
This solution appears to work, where the font size is consistent at first load.
math: {
mathjax: 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.6/MathJax.js',
config: 'TeX-MML-AM_CHTML-full',
// pass other options into MathJax.Hub.Config()
TeX: { Macros: { RR: "{\bf R}" } , equationNumbers: { autoNumber: "AMS" }},
jax: ["input/TeX","output/CommonHTML"],"CommonHTML": { matchFontHeight: false, scale: 120 }
},
I have no idea why the math displayed in reveal.js using MathJax's CommonHTML output (which is the deafult since MathJax v2.6.) looks like that: The source code for this is: