JuliaPlots / MakieTeX.jl

TeX integration in Makie
MIT License
86 stars 12 forks source link

Use `tectonic_jll` instead of local `LaTeX` distribution #30

Closed greimel closed 2 years ago

greimel commented 2 years ago

Have you looked into tectonic? It's a modernized version of XeLaTeX and it's available via tectonic_jll.

It's not suitable for fancy graph grawing in tikZ (need LuaTeX for that). But I guess it would be a nice default option for this package, so that it works even without a local LaTeX distribution.

Here's a MWE

using tectonic_jll
using Poppler_jll

basefile = tempname()

buffer = """
\\documentclass{standalone}
\\usepackage{amsmath}
\\usepackage{standalone}

\\begin{document}

\$x \\in X \$ 

\\end{document}
""" |> String;

texfile = basefile * ".tex"
pdffile = basefile * ".pdf"
write(texfile, buffer)

tectonic() do bin
        run(`$bin $texfile`)
end

# taken from MakieTeX
function pdf2svg(pdf::Vector{UInt8}; kwargs...)
     pdftocairo = Poppler_jll.pdftocairo() do exe
         open(`$exe -f 1 -l 1 -svg - -`, "r+")
     end

     write(pdftocairo, pdf)

     close(pdftocairo.in)

     return read(pdftocairo.out, String)
 end

pdf2svg(pdf::String) = pdf2svg(Vector{UInt8}(pdf))

pdf2svg(read(pdffile))
asinghvi17 commented 2 years ago

Huh, this is pretty neat! With the new Poppler pipeline, this would be even easier since I can convert straight from PDF.

I would lean towards using this as a fallback renderer in case latexmk is not found on the system, simply because if the user wants to use fancy local packages, advanced tikz, syntax highlighting, etc. it should "just work" (haha, as if that ever happened with latex).

The Poppler pipeline works quite well now, although some PDFs bug out in Preview (but not Chrome). I want to integrate this into text! a la MathTeXEngine, but after that this should be essentially stable barring changes in Makie.

greimel commented 2 years ago

I want to integrate this into text! a la MathTeXEngine

That would be amazing!