byteclubfr / prez

Generate Reveal.js slideshows from a set of markdowns
228 stars 42 forks source link

Strange math rendering issue #9

Open drewsday opened 9 years ago

drewsday commented 9 years ago

I ran into a strange math rendering issue today which I believe I can only connect to prez.

I had the following equation I was trying to display:

$$ vx = \lim \limits{\Delta t \to 0} \frac{\Delta x}{\Delta t} = \frac{dx}{dt} $$

Testing with just MathJax and with just reveal.js, this renders correctly. Prez will not correctly render. It seems that the underscore after \limits is causing it to fail.

As a temporary fix, I can include the expression as an graphic, but I'm puzzled why this happens in prez.

Delapouite commented 9 years ago

Hi.

I'm pretty sure it has to do with custom headers syntax that can optionnaly be added on top of each markdown documents. They are delimited by $ signs.

https://github.com/lmtm/prez#customize-slide-attributes https://github.com/lmtm/prez/blob/master/lib/slide-properties.js#L46

I'll make a conf option to specify these delimiters soon.

drewsday commented 9 years ago

Based on that info, I did a test, and it looks like the use of two underscores in the equation is causing the expression to get interpreted as not an equation.

My regex knowledge is not great, but I couldn't quite figure out how line 46 in the slide-properties.js would match the particular equation that I had, since there was no : character in it, and I have a zero in it as well as some slashes and brackets that look to me like they won't match the regex pattern.

Is there any other place in the code where using two underscores would be recognized as a type of delimiter? (I wouldn't be surprised if that's the wrong question to ask, but I'd hate to have you make a conf option if it's not needed.)

Delapouite commented 9 years ago

You're right. After a bit of investigation, $ symbols are not guilty but the underscores are. The slides are first converted to markdown before the MathJax plugin kicks in. So the part inside the underscores gets converted to an <em> tag and therefore the equation is then invalid.

drewsday commented 9 years ago

Since that is the case, then I should be able to escape the underscores in the equations and have it rendered as a correct equation. I tried it for my case, and it seemed to work properly. I'm not sure what other cases may or may not be rendered correctly, but I seem to have a better work around for now.

Thanks.

dluciv commented 8 years ago

BTW, to show math, I do so:

Reveal.configure({
    "center": false,
    dependencies: [
        { src: 'plugin/zoom-js/zoom.js', async: true },
        { src: 'plugin/notes/notes.js', async: true },
        { src: 'plugin/math/math.js', async: true }
]});

and then

Reveal.initialize();

In custom.js. Without calling Reveal.initialize myself it does not load MathJax. What's wrong there?..