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

Make Graphics convert to absolute path and expand ~. #295

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/man/data.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ Graphics

Example:

```jldoctest
```jldoctest; filter = r"{.*}"
julia> print_tex(Graphics("img.png"))
graphics {img.png}
```
Expand Down
4 changes: 4 additions & 0 deletions src/axiselements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,10 @@ end
struct Graphics <: OptionType
options::Options
filename::String
function Graphics(options::Options, filename::AbstractString)
# expand path and make it absolute
new(options, abspath(expanduser(filename)))
end
end

function Graphics(filename::AbstractString, args::Vararg{PGFOption})
Expand Down
14 changes: 14 additions & 0 deletions test/test_build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -198,3 +198,17 @@ end
end
end
end

@testset "graphics with relative path" begin
# cf https://github.com/KristofferC/PGFPlotsX.jl/issues/283
tmp_pdf = tempname() * ".pdf"
mktempdir() do dir
cd(dir)
pgfsave("img.png", Plot(Table([0, 1], [0, 1])))
axis = @pgf Axis(Plot(Graphics({ xmin = 0, xmax = 1, ymin = 0, ymax = 1},
"img.png")))
pgfsave(tmp_pdf, axis)
@test is_pdf_file(tmp_pdf)
rm(tmp_pdf)
end
end
6 changes: 4 additions & 2 deletions test/test_elements.jl
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,10 @@ end
@test repr_tex(Expression("x^2")) == "{x^2}"
@test repr_tex(Expression(["x^2", "y^2"])) == "(\n{x^2},\n{y^2})"
# graphics
@test repr_tex(@pgf Graphics({ testopt = 1}, "filename")) ==
"graphics[testopt={1}] {filename}\n"
let gp = abspath("filename")
@test repr_tex(@pgf Graphics({ testopt = 1}, "filename")) ==
"graphics[testopt={1}] {$(gp)}\n"
end
# coordinates, tables, and plot
c = Coordinates([(1, 2), (3, 4)])
@test repr_tex(c) == "coordinates {\n (1,2)\n (3,4)\n}\n"
Expand Down