wviechtb / mathjaxr

R package to make use of Mathjax in Rd files
47 stars 6 forks source link

Putting \mjeqn{} as the first thing in a paragraph renders incorrectly #11

Closed dmurdoch closed 2 years ago

dmurdoch commented 2 years ago

This StackOverflow question shows that R renders HTML incorrectly when an \mjeqn{} macro is the first thing in a paragraph. The example there has a paragraph consisting of this line:

\mjeqn{foo^{bar}}{foo^bar} estimates bas.

which renders as

foo^bar

estimates bas.

This happens because the \mjeqn macro expands into an \out{} macro, which is not considered to be text by the Rd rendering machinery, so R thinks the paragraph starts after the macro. A workaround mentioned on SO is to put \emph{} on the line ahead of the \mjeqn, so that R thinks the \out appears in the middle of a paragraph.

Maybe mathjaxr could do that: instead of emitting a naked \out, it could prefix it with \emph{} or some other invisible text so that R realizes it is in a paragraph.

Another possibility would be to fix the R conversion code, but I think \out could be used in situations where you don't want R to see text, so that would likely have worse side effects.

dmurdoch commented 2 years ago

I just noticed that you addressed this in the README in June, suggesting a different invisible addition: \if{html}{\eqn{}}.

wviechtb commented 2 years ago

Thanks for raising this issue and the suggested solution! Much better than that manual fix I suggested in the README.