Home > Software engineering >  How to suppress the carriage return mathjaxr adds when `mjeqn` starts a line?
How to suppress the carriage return mathjaxr adds when `mjeqn` starts a line?

Time:11-15

If I begin a line (i.e. a paragraph) in the details section of my .Rd file with \mjeqn a new line immediately follows the expression (anti-bonus points: the added new line seems to have wider line spacing than 'ordinary' new lines). How can I suppress this behavior when I want to start a line with inline mathy stuff using \mjeqn?

Sketched out example:

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

Gives me something like the below when parsed (into html preview):

foo^bar

estimates bas.

I am just using mathjaxr, not roxygen2.

CodePudding user response:

I don't know why that happens, but it looks like a bug, maybe in the R help rendering engine, maybe in the mathjaxr macro, or maybe in MathJax. A simple workaround is to put something invisible on the line ahead of the math, e.g.

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

Edited to add:

Digging into the rendering code, it seems the problem is that the \mjeqn macro expands into something that R ignores when trying to determine paragraphs, so it thinks the paragraph starts after that. Putting \emph{} ahead of it tells R that the paragraph has started and everything is fine. This has been incorporated into the package, so if you download the Github version, or wait for the next CRAN release, you won't need the workaround.

  •  Tags:  
  • r
  • Related