diff --git a/docs/src/man/data.md b/docs/src/man/data.md index 45c15a61..2fb6b969 100644 --- a/docs/src/man/data.md +++ b/docs/src/man/data.md @@ -157,7 +157,7 @@ Graphics Example: -```jldoctest +```jldoctest; filter = r"{.*}" julia> print_tex(Graphics("img.png")) graphics {img.png} ``` diff --git a/src/axiselements.jl b/src/axiselements.jl index a5e1e9fc..92905749 100644 --- a/src/axiselements.jl +++ b/src/axiselements.jl @@ -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}) diff --git a/test/test_build.jl b/test/test_build.jl index 29881655..d37d826e 100644 --- a/test/test_build.jl +++ b/test/test_build.jl @@ -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 diff --git a/test/test_elements.jl b/test/test_elements.jl index ad6b7582..8ce80483 100644 --- a/test/test_elements.jl +++ b/test/test_elements.jl @@ -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"