LaTeXStrings.jl icon indicating copy to clipboard operation
LaTeXStrings.jl copied to clipboard

`text/latex` repr

Open zmoon opened this issue 4 years ago • 5 comments

Currently, in Pluto, a LaTeXString is wrapped with \text{} before being passed to MathJax. This lets LaTeXStrings with mixed text and math like the L"an equation: $1 + \alpha^2$" from your readme render properly in Pluto, but causes issues for other packages that use this MIME type targeting MathJax. You can see discussion here: https://github.com/fonsp/Pluto.jl/issues/488.

Maybe instead, Base.show(io::IO, ::MIME"text/latex", s::LaTeXString) could do this, ensuring that LaTeXStrings with mixed text and math get rendered properly in Pluto (and others that use MathJax on the text/latex MIME type).

zmoon avatar May 16 '21 00:05 zmoon

@zmoon Maybe you could clarify exactly what the suggested change is, and how it affects environments other than Pluto?

fonsp avatar May 18 '21 10:05 fonsp

So, in Pluto, the whole LaTeXString is passed to MathJax. And since MathJax is math-first, you have to wrap normal text with \text{} to keep it from being treated as math. So for L"an equation: $1 + \alpha^2$", for it to render as we would expect, \text{an equation: }1 + \alpha^2 or \text{an equation: $1 + \alpha^2$} could be passed to MathJax.

In JupyterLab, for example, the math and text are separated before passing the math to MathJax. Presumably, in our example, if \text{an equation: $1 + \alpha^2$} were used, it would all be passed to MathJax instead of being separated.

zmoon avatar May 25 '21 01:05 zmoon

Maybe Pluto should wrap it in \text{...}, then?

Jupyter also uses MathJax, what does it do for text/latex rendering?

stevengj avatar May 25 '21 01:05 stevengj

In Jupyter, the math and normal text of a LaTeXString are separated and only the math gets passed to MathJax, the normal text gets treated as normal HTML text.

zmoon avatar May 25 '21 01:05 zmoon

Honestly, Jupyter's handling of text/latex seems more correct to me… I'm not sure why one should assume that text/latex content consists only of a single equation.

stevengj avatar Nov 03 '21 13:11 stevengj