orsharir / github-mathjax

Chrome extension for rendering LaTeX equations in GitHub with MathJax
Other
153 stars 49 forks source link

Failure to render inline equations in some cases #11

Closed aphirst closed 7 years ago

aphirst commented 7 years ago

I can't seem to work out what might be causing this problem, but I can post a snippet of a .md file from one of my private repositories which fails to render correctly, despite having no issues in "enhanced" markdown editors like Remarkable.

* `Surface` class defining a cubic B-Spline surface on the $[0,1]$ interval.
    * $\mathbf{s}(u,v)$, partial derivatives $\mathbf{s}_{u,v,uu,uv,vv}(u,v)$ are self-explanatory, as is the surface normal $\mathbf{N}(u,v)$ and its partial derivatives $\mathbf{N}_{u,v}(u,v)$.

This bug also seems to be present in the Chrome extensions "BitBucket with MathJax" and "Math Anywhere" and I've already reported it to their trackers here and here respectively.

orsharir commented 7 years ago

The reason is that you have two underlines in the sentence, which under Markdown's syntax it is converted to an italicized test, for example _Test_ turns to Test. Since my extension runs only after Markdown is processed by Github, these underlines becomes invisible to it, rendering the second expression unreadable. The solution is simply to escape underlines in this case using slash before it, for example A_{i,j} = x_i +y_j should be written as A\_{i,j} = x\_i + y\_j which will be rendered correctly: $A_{i,j} = x_i + y_j$.

When I'll get around to it, I'll see if it's sufficiently simple to use the original text before Markdown is processed for rendering the equations, and then you would no longer have to escape underlines as above.

aphirst commented 7 years ago

Mm, that would seem to be a workaround, but then my objection would be that the resulting documents are no longer compatible (no longer render correctly) with offline markdown tools (as mentioned, I use Remarkable, but I collaborate with people who use Haroopad and Typora).

As subscripts are somewhat vital in many fields of mathematics/physics, it would be a shame if this were to remain irreparably crippled. For when you have the time, good luck with the investigation!

orsharir commented 7 years ago

Reading a bit more about it, the solution would be to write my own MathJax preprocessor to handle this specific case. Perhaps in the summer I'll get to it, or if you have the time to fix it yourself, then I'd be happy to merge your patch.

More generally though, there's a limit to what I can do with a local extension, when GitHub process the Markdown first on their server. E.g. there's a related issue of when using double slash for newlines, which (because of processing it first as Markdown) converts any double slash to a single slash, since in Markdown double slash is used to escape a single slash. Ideally, GitHub will one day bring back their internal support to LaTeX, and my extension would no longer be necessary.