fonsp / Pluto.jl

🎈 Simple reactive notebooks for Julia
https://plutojl.org/
MIT License
4.94k stars 285 forks source link

latexstring not working in Markdown mode #1218

Closed dorn-gerhard closed 3 years ago

dorn-gerhard commented 3 years ago

I experienced a change in the behavior of latexstring in markdown environment in pluto. Basically it does not work anymore.

I would like to use Markdown + Variables + LaTeX The best workaround so far was to use a) md""" $(latexstring("y =")) $(variable) $(latexstring("x+d" )) """ since the Latex-Markdown variant with $\int...$ did not work with preceeding variables: b) md""" $y$ = $(variable) $x + d$ """

Unfortunately latexstring does not work in the markdown environment anymore. Does this depend on the mentioned changes in the LaTeXStrings package or in Pluto #359 #488 #1164?

grafik

I am using LaTeXStrings v1.2.1 and Pluto v0.14.7 and tested on two machines / installations

What will be the future strategy or best practise to use Markdown + Variables + LaTeX?

disberd commented 3 years ago

I am not 100% sure this is what you wanted to achieve, but I remember seeing in another issue/discourse thread a suggestion to use directly Markdown.parse

image

Is the result here in-line with what you wanted?

dorn-gerhard commented 3 years ago

Thank you for your suggestion, I also just found out about the backtick solution in Markdown. My initial request was just having Latex and Variables separated in one Markdown block.

grafik which works with md""" and the double backtick solution for latex (cannot write backticks here since in Github markdown they are used for code^^)

Actually you proposed an additional task: integration of julia variables in a Latex formula (like in the exponent) in a Markdown environment which indeed can be realized with Markdown.parse though backslashes and $ for latex mode have to be escaped but which helps to distinguish between variables and Latex environments:

grafik

It's interesting to explore that the backtick solution is inline whereas $ $ can be used for a display math mode (full size of integrals, sums, etc...) if it starts a line. alternatively one can use an align environment in the latex part

But to come back to my initial issue: latexstring is not working anymore in the markdown environment (md""" """). though using Markdown.parse works. Btw: latexstring also can be used to integrate variables in latex Code: grafik

For me this issue and the future strategy of how to combine latex and markdown and variables is important since I used the latexstring method in md""" """ mode a lot in my teaching notebooks.

fonsp commented 3 years ago

@dorn-gerhard I don't think that this is supposed to work. In markdown, you can interpolate objects, which will be rendered as HTML when available (e.g. when interpolating an image or plot into markdown), and as text/plain otherwise. LaTeXString does not define an html display, and what you see in your first screenshot is the text/plain display (i.e. the same as in a terminal).

I don't think LaTeXStrings.jl is in the position to define an html show method that will work on all environments, but you can add one to your notebook. I can send some pointers if you are interested.

fonsp commented 3 years ago

The reason that it 'worked' before is because of an escaping bug that was fixed. This bug happened to make your use case work. Sorry!

fonsp commented 3 years ago

More discussion in: https://github.com/fonsp/Pluto.jl/issues/1237