Skip to content

Commit

Permalink
Merge pull request #84 from dylan-asmar/master
Browse files Browse the repository at this point in the history
Updates to work on apple silicon

@JuliaRegistrator register()
  • Loading branch information
dylan-asmar authored Jul 2, 2023
2 parents 230d8e1 + 0d7c34c commit ce1e2ea
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
fail-fast: false
matrix:
version:
- "1.3" # earliest version supported
- "1.6" # earliest version supported
- "1" # Latest Release
os:
- ubuntu-latest
Expand Down
10 changes: 5 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
name = "TikzPictures"
uuid = "37f6aa50-8035-52d0-81c2-5a1d08754b2d"
license = "MIT"
version = "3.4.2"
version = "3.5.0"

[deps]
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
Poppler_jll = "9c32591e-4766-534b-9725-b71a8799265b"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Tectonic = "9ac5f52a-99c6-489f-af81-462ef484790f"
tectonic_jll = "d7dd28d6-a5e6-559c-9131-7eb760cdacc5"

[compat]
LaTeXStrings = "1.1"
Poppler_jll = "0.87"
Poppler_jll = "21.9"
Requires = "1.1"
Tectonic = "0.8"
julia = "1.3"
tectonic_jll = "0.13"
julia = "1.6"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@

This library allows one to create Tikz pictures and save in various formats. It integrates with IJulia, outputting SVG images to the notebook.

This library will try to use the lualatex package already installed on the system. Lualatex may be installed through the texlive and miktex distributions. You should have dvisvgm installed. On Ubuntu, you can get these, if not already present, by running `sudo apt-get install texlive-latex-base` and `sudo apt-get install texlive-binaries`. If the library cannot run lualatex, it will fall back to trying to use tectonic for the compilation.
This library will try to use the lualatex package already installed on the system. If the library cannot run lualatex, it will fall back to trying to use tectonic for the compilation.

Lualatex may be installed through the texlive and miktex distributions. You should have dvisvgm installed. On Ubuntu, you can get the required packages, if not already present, by running `sudo apt-get install pdf2svg texlive-latex-base texlive-binaries texlive-pictures texlive-latex-extra texlive-luatex`.

Note: this package will attempt to turn off interpolation in the generated SVG, but this currently only works in Chrome.

Expand Down
28 changes: 21 additions & 7 deletions src/TikzPictures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module TikzPictures
export TikzPicture, PDF, TEX, TIKZ, SVG, save, tikzDeleteIntermediate, tikzCommand, tikzUseTectonic, TikzDocument, push!
import Base: push!
import LaTeXStrings: LaTeXString, @L_str
import Tectonic: tectonic
import tectonic_jll: tectonic
export LaTeXString, @L_str

_tikzDeleteIntermediate = true
Expand Down Expand Up @@ -97,6 +97,20 @@ function removeExtension(filename::AbstractString, extension::AbstractString)
end
end

function bool_success(cmd::Cmd)
successful = false
try
successful = success(cmd)
catch ex
if ex isa Base.IOError
successful = false
else
rethrow()
end
end
return successful
end

abstract type SaveType end

mutable struct PDF <: SaveType
Expand Down Expand Up @@ -134,8 +148,8 @@ function execute(cmd::Cmd)
close(out.in)
close(err.in)
(
stdout = String(read(out)),
stderr = String(read(err)),
stdout = String(read(out)),
stderr = String(read(err)),
code = process.exitcode
)
end
Expand Down Expand Up @@ -277,7 +291,7 @@ function _run(tp::TikzPicture, temp_dir::AbstractString, temp_filename::Abstract
arg = String[tikzCommand()]
latexSuccess = false
texlog = ""
if tikzUseTectonic() || !success(`$(tikzCommand()) -v`)
if tikzUseTectonic() || !bool_success(`$(tikzCommand()) -v`)
tectonic() do tectonic_bin
if dvi
error("Tectonic does not currently support dvi backend")
Expand All @@ -290,7 +304,7 @@ function _run(tp::TikzPicture, temp_dir::AbstractString, temp_filename::Abstract
result = execute(`$(arg) $(temp_filename*".tex")`)
latexSuccess = (result.code == 0)
texlog = result.stderr
end
end
else
if tp.enableWrite18
push!(arg, "--enable-write18")
Expand All @@ -299,12 +313,12 @@ function _run(tp::TikzPicture, temp_dir::AbstractString, temp_filename::Abstract
push!(arg, "--output-format=dvi")
end
push!(arg, "--output-directory=$(temp_dir)")
latexSuccess = success(`$(arg) $(temp_filename*".tex")`)
latexSuccess = bool_success(`$(arg) $(temp_filename*".tex")`)
try
texlog = read(temp_filename * ".log", String)
catch
texlog = read(_joinpath(temp_dir,"texput.log"), String)
end
end
end
return latexSuccess, texlog
end
Expand Down
24 changes: 20 additions & 4 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@ for file in ["testPic.pdf", "testPic.svg", "testDoc.pdf", "testDoc.tex", first.(
end
end

# redfining bool_success so we don't have to export it from TikzPictures
function bool_success(cmd::Cmd)
successful = false
try
successful = success(cmd)
catch ex
if ex isa Base.IOError
successful = false
else
rethrow()
end
end
return successful
end

# Run tests
data = "\\draw (0,0) -- (10,10);\n\\draw (10,0) -- (0,10);\n\\node at (5,5) {tikz \$\\sqrt{\\pi}\$};"
tp = TikzPicture(data, options="scale=0.25", preamble="")
Expand Down Expand Up @@ -60,9 +75,10 @@ filecontent = join(readlines("testPic.tex", keep=true))
@test !has_environment(filecontent, "document")

save(TEX("testPic"), tp) # save again with limit_to=:all
if success(`lualatex -v`)
save(PDF("testPic"), tp)
@test isfile("testPic.pdf")

if bool_success(`lualatex -v`)
save(PDF("testPic"), tp)
@test isfile("testPic.pdf")

save(SVG("testPic"), tp)
@test isfile("testPic.svg") # default SVG backend
Expand Down Expand Up @@ -101,7 +117,7 @@ filecontent = join(readlines("testCD.tex", keep=true)) # read with line breaks
@test has_environment(filecontent, "tikzcd")
@test has_environment(filecontent, "document")

if success(`lualatex -v`)
if bool_success(`lualatex -v`)
save(PDF("testCD"), tp)
@test isfile("testCD.pdf")

Expand Down

2 comments on commit ce1e2ea

@dylan-asmar
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register()

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/86691

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v3.5.0 -m "<description of version>" ce1e2ea28845a78132f5bc3520bc7e7fb9dd64a3
git push origin v3.5.0

Please sign in to comment.