Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpolating LaTeXString into Markdown #1237

Closed
zfengg opened this issue Jun 9, 2021 · 7 comments
Closed

Interpolating LaTeXString into Markdown #1237

zfengg opened this issue Jun 9, 2021 · 7 comments

Comments

@zfengg
Copy link

zfengg commented Jun 9, 2021

Recently I find the output of latexify() doesn't render well in markdown cell at the new versions included v0.14.8 and v0.14.7. However, it works well in v0.14.5.

Comparison.

v0.14.5
plutov5

VS

v0.14.8
plutov8

env

Both run in Chrome on Windows 10.

Also, the render doesn't work on Binder on which the Pluto version is 0.14.7.

remark

Right now I pin to 0.14.5 but I hope I can walk around this in the future versions to enjoy the amazing Pluto! Thanks.

@fonsp fonsp changed the title v"0.14.8" The output of latexify() doesn't render well in markdown cell Interpolating LaTeXString into Markdown Jun 9, 2021
@fonsp
Copy link
Owner

fonsp commented Jun 9, 2021

Unfortunately, this 'worked' because of a bug, and I fixed that bug: https://github.com/fonsp/Pluto.jl/pull/1164/files#diff-98c649aba98aa3bee0202b56f4e1d1e44ae620b564690ad53b114b49b03d69fcL351-R351

Markdown interpolation does not support latex objects (it will render them as text), you have to wrap them in a Markdown.LaTeX. You can use this helper function:

latexify_md(args...; kwargs...) = Markdown.LaTeX(repr(MIME"text/latex"(), latexify(args...; kwargs...)))

or more general for LaTeXStrings:

wrap_tex(x) = Markdown.LaTeX(repr(MIME"text/latex"(), x))

Schermafbeelding 2021-06-09 om 10 49 28

@zfengg
Copy link
Author

zfengg commented Jun 9, 2021

I see. Thanks a lot!

@zfengg zfengg closed this as completed Jun 9, 2021
@gustaphe
Copy link

Can you think of a good way to use this as a html show method?

Base.show(io, m::MIME"text/html", x::LaTeXString) = show(io, m, Markdown.LaTeX(repr(MIME"text/latex"(), x)))

doesn't work. I don't want to have to define a latexify_md, latexraw_md, latexequation_md when just allowing interpolating a latexstring would give me the full gamut of Latexify.

@fonsp
Copy link
Owner

fonsp commented Jun 10, 2021

@gustaphe You need to wrap the Markdown.LaTeX in a Markdown.MD(...).

The problem them is that you Markdown's ability to automatically switch between display math and inline math, and I don't see a way to resolve that using the html show method. Let me try something else...

Interpolating LaTeX is a missing feature in Markdown, and LaTeXString.jl confuses the ecosystem.

@fonsp
Copy link
Owner

fonsp commented Jun 10, 2021

This works:

begin
	using Latexify
	using LaTeXStrings
	
	Markdown.html(io::IO, ls::LaTeXString) = 
		Markdown.html(io, Markdown.LaTeX(
			repr(MIME"text/latex"(), ls)
		))
	
	Markdown.htmlinline(io::IO, ls::LaTeXString) = 
		Markdown.htmlinline(io, Markdown.LaTeX(
			repr(MIME"text/latex"(), ls)
		))
end

Schermafbeelding 2021-06-10 om 14 47 15

@newptcai
Copy link

This works:

begin
	using Latexify
	using LaTeXStrings
	
	Markdown.html(io::IO, ls::LaTeXString) = 
		Markdown.html(io, Markdown.LaTeX(
			repr(MIME"text/latex"(), ls)
		))
	
	Markdown.htmlinline(io::IO, ls::LaTeXString) = 
		Markdown.htmlinline(io, Markdown.LaTeX(
			repr(MIME"text/latex"(), ls)
		))
end

Schermafbeelding 2021-06-10 om 14 47 15

This works. Cannot you add it to Pluto? It's a bit of complicated to use LaTeXStrings now in Pluto.

@AtheistApe
Copy link

Greetings,

None of these methods seem to work in Pluto notebook v.0.19.29. Can anyone provide modifications of any of these solutions so it continues to work in the newer version of Pluto notebook?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants