Skip to content

Commit

Permalink
Fix init and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
asinghvi17 committed Feb 16, 2024
1 parent 1896965 commit c3c8823
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 26 deletions.
44 changes: 24 additions & 20 deletions src/MakieTeX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,35 @@ function __init__()
Defaulting to the bundled `tectonic` renderer for now.
"""
CURRENT_TEX_ENGINE[] = `tectonic`
end

t1 = try_tex_engine(CURRENT_TEX_ENGINE[])
if isnothing(t1)

@warn("""
The specified TeX engine $(CURRENT_TEX_ENGINE[]) is not available.
Trying pdflatex:
"""
)

CURRENT_TEX_ENGINE[] = `pdflatex`
else
return
end
t1 = try_tex_engine(CURRENT_TEX_ENGINE[]) # by default `lualatex`

t2 = try_tex_engine(CURRENT_TEX_ENGINE[])
if isnothing(t2)
if !isnothing(t1)

@warn "Could not find a TeX engine; defaulting to bundled `tectonic`"
CURRENT_TEX_ENGINE[] = `tectonic`
else
return
@warn("""
The specified TeX engine $(CURRENT_TEX_ENGINE[]) is not available.
Trying pdflatex:
"""
)

CURRENT_TEX_ENGINE[] = `pdflatex`
else
return
end

t2 = try_tex_engine(CURRENT_TEX_ENGINE[])
if !isnothing(t2)

@warn "Could not find a TeX engine; defaulting to bundled `tectonic`"
CURRENT_TEX_ENGINE[] = `tectonic`
else
return
end

end



# TODO: Once the correct tex engine is found, load the rendering extensions
# (currently CairoMakie, but we may do WGLMakie in the future since it can display SVG)

Expand Down
28 changes: 28 additions & 0 deletions src/recipe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,34 @@ $(Makie.ATTRIBUTES)
)
end

# First, handle the case of one or more abstract strings passed in!
# These are themable.

# Makie.used_attributes(::Type{<: TeXImg}, string_s::Union{<: AbstractString, AbstractVector{<: AbstractString}}) = (:font, :fontsize, :justification, :color, :word_wrap_width, :lineheight)
# Makie.convert_arguments(::Type{<: TeXImg}, string::AbstractString) = Makie.convert_arguments(TeXImg, [string])

# function Makie.convert_arguments(
# ::Type{<: TeXImg},
# strings::AbstractVector{<: AbstractString};
# font = Makie.texfont(),
# fontsize = 14,
# justification = Makie.automatic,
# color = :black,
# word_wrap_width = -1,
# lineheight = 1.0,
# )

# # This function will convert the strings to CachedTeX, so that it can track changes in attributes.
# # It will have to handle the case where the parameters given are for all strings in an array, or per string,
# # using Makie's `broadcast_foreach` function.

# # First, we need to convert the strings to CachedTeX.
# # This is done by using the `CachedTeX` constructor, which will render the LaTeX and store it in a CachedTeX object.
# # This is then stored in an array, which is then returned.


# end

function Makie.boundingbox(x::T) where T <: TeXImg
Makie.boundingbox(
x[1][] isa CachedTeX ? [x[1][]] : x[1][],
Expand Down
6 changes: 3 additions & 3 deletions src/rendering.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end
function compile_latex(
document::AbstractString;
tex_engine = CURRENT_TEX_ENGINE[],
options = `-file-line-error -halt-on-error`
options = `-file-line-error`
)

use_tex_engine=tex_engine
Expand Down Expand Up @@ -46,7 +46,7 @@ function compile_latex(
run(pipeline(ignorestatus(`$bin temp.tex`), stdout=out, stderr=err))
end
else # latexmk
latex_cmd = `latexmk $options --shell-escape -$use_tex_engine -cd -interaction=nonstopmode temp.tex`
latex_cmd = `latexmk $options --shell-escape -cd -$use_tex_engine -interaction=nonstopmode temp.tex`
run(pipeline(ignorestatus(latex_cmd), stdout=out, stderr=err))
end
suc = success(latex)
Expand Down Expand Up @@ -80,7 +80,7 @@ function compile_latex(
redirect_stdout(devnull) do
Ghostscript_jll.gs() do gs_exe
mtperl() do perl_exe
run(`$perl_exe $pdfcrop --margin $crop_margins $() --gscmd $gs_exe temp.pdf temp_cropped.pdf`)
run(`$perl_exe $pdfcrop --margin $crop_margins --gscmd $gs_exe temp.pdf temp_cropped.pdf`)
return read("temp_cropped.pdf", String)
end
end
Expand Down
7 changes: 4 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ function render_texample(url)

fig = Figure()

lt = LTeX(fig[1, 1], CachedTeX(TeXDocument(read(Downloads.download(url), String))))
lt = LTeX(fig[1, 1], CachedTeX(TeXDocument(read(Downloads.download(url), String), false)))

@test true

resize_to_layout!(fig)

filename = splitdir(splitext(url)[1])[2]

save_test(joinpath(texample, filename), fig)
save_test(joinpath("texample", filename), fig)

@test true

Expand Down Expand Up @@ -72,7 +72,8 @@ end

fig = Figure()

@test_warn r"The PDF has more than 1 page! Choosing the first page." Label(fig[1, 1], CachedTeX(TeXDocument(read(Downloads.download("https://texample.net/media/tikz/examples/TEX/mandala.tex"), String))))
# @test_warn r"The PDF has more than 1 page! Choosing the first page." LTeX(fig[1, 1], CachedTeX(TeXDocument(read(Downloads.download("https://texample.net/media/tikz/examples/TEX/mandala.tex"), String))))
@test_nowarn LTeX(fig[1, 1], CachedTeX(TeXDocument(read(Downloads.download("https://texample.net/media/tikz/examples/TEX/mandala.tex"), String))))

resize_to_layout!(fig)

Expand Down

0 comments on commit c3c8823

Please sign in to comment.