LaTeX rendering in the Julia REPL

I watched the Latexify demonstration at JuliaCon here.

It seems from the video that simply entering something like latexify("x/y") into the terminal will result in output that looks like proper LaTeX.

However, when I tried on my terminal I ended up with this:
Screenshot from 2020-07-22 01-00-51

My version of the Julia REPL appears to simply display the raw version of the LaTeX, and also does so even when I try using show. Has something changed between then and now, or am I not displaying it properly?

AFAIK there’s no way to display proper LaTeX inside terminal emulator without rendering it out as some sort of image and then display with some image protocol.

It works in IJulia (Jupyter Notebook) though.

3 Likes

Thanks for your reply.
I was worried that was the only option though, since I was afraid making Jupyter Notebook a prerequisite to my package would decrease user-friendliness and ease of use.
I’ll think about it though.

I recently added a render function to latexify.jl. It’s still very much a beta-feature, but the idea is to generate an image with the relevant equation and open it in a new window.

I don’t have any completely satisfactory solutions for the REPL but this is better than nothing.

7 Likes

Are there any requirements for render? Would using it just look something like render(latexify("x/y"))?

render(latexify("x/y")), or my own favourite, latexify("x/y") |> render is correct usage. For it to work, however, you will need to have LuaLaTeX installed (+ some fairly basic packages). One day, I might make it more liberal such that it can use latex or pdflatex instead but currently it is pretty crude.

The code can (at the time of writing) be found here.

1 Like

@korsbo, is this working in Julia’s 1.6.0 REPL?

well, there is no support for displaying rich media in any arbitrary REPL. render in Latexify.jl will, however, try to create an image from the maths and open that in an external viewer. It also works nicely with the VSCode plotpane if you’re in VSCode.

1 Like

there is also GitHub - MichaelHatherly/MathJaxRenderer.jl

its still very new but it’s something that I’ve been eyeballing as a potential replacement for the render function inside Latexify.jl.

3 Likes

is there some reason why you specify 1.6? Any new features in that REPL that I’ve missed?

No special reason, thank you.
Trying to visualize in VS Code this amazing post showing a continued fraction.
Quick attempts using Latexify.jl have not succeeded, yet.

5 Likes

@korsbo, excellent.
Thank you for your time showing the way.

1 Like

@korsbo, fyi, in order to plot to an external Plots.jl window, found this useful:

using Latexify, Plots; gr()
plot(framestyle = :none) 
title!(latexify(ex), titlefontsize=10)  # adjust font size

Plots_gr_GKS_QtTerm_Latex_continued_fraction

There should be a better way though, that automatically adjusts the font size.

1 Like

There is also GitHub - simonschoelly/KittyTerminalImages.jl: A package that allows Julia to display images in the kitty terminal editor, with LaTeX rendering on their TODOs.

Why not over-engineer it? :stuck_out_tongue:

using RecipesBase, LaTeXStrings
@recipe function f(::Type{LaTeXString}, s::LaTeXString)
       framestyle := :none
       titlefontsize --> 10
       title := s
       legend := false
       ([0],[0])
end

using Plots
plot(L"x^7-3x+4")

probably also better to make it an annotation than a title, then it won’t look as strange in plotly, for instance.

2 Likes