Skip to content

Commit

Permalink
Added alias pgfsave = save, docs for save.
Browse files Browse the repository at this point in the history
Fixes #69.
  • Loading branch information
tpapp committed Feb 23, 2018
1 parent 362f58d commit 9071f44
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/src/examples/axislike.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
```@setup pgf
using PGFPlotsX
savefigs = (figname, obj) -> begin
PGFPlotsX.save(figname * ".pdf", obj)
pgfsave(figname * ".pdf", obj)
run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`)
PGFPlotsX.save(figname * ".tex", obj);
pgfsave(figname * ".tex", obj);
return nothing
end
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/coordinates.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
```@setup pgf
using PGFPlotsX
savefigs = (figname, obj) -> begin
PGFPlotsX.save(figname * ".pdf", obj)
pgfsave(figname * ".pdf", obj)
run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`)
PGFPlotsX.save(figname * ".tex", obj);
pgfsave(figname * ".tex", obj);
return nothing
end
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/gallery.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ This is a work in progress.
```@setup pgf
using PGFPlotsX
savefigs = (figname, obj) -> begin
PGFPlotsX.save(figname * ".pdf", obj)
pgfsave(figname * ".pdf", obj)
run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`)
PGFPlotsX.save(figname * ".tex", obj);
pgfsave(figname * ".tex", obj);
return nothing
end
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/juliatypes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ There is some support to directly use Julia objects from different popular packa
```@setup pgf
using PGFPlotsX
savefigs = (figname, obj) -> begin
PGFPlotsX.save(figname * ".pdf", obj)
pgfsave(figname * ".pdf", obj)
run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`)
PGFPlotsX.save(figname * ".tex", obj);
pgfsave(figname * ".tex", obj);
return nothing
end
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/examples/tables.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
```@setup pgf
using PGFPlotsX
savefigs = (figname, obj) -> begin
PGFPlotsX.save(figname * ".pdf", obj)
pgfsave(figname * ".pdf", obj)
run(`pdf2svg $(figname * ".pdf") $(figname * ".svg")`)
PGFPlotsX.save(figname * ".tex", obj);
pgfsave(figname * ".tex", obj);
return nothing
end
```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/man/save.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ If you wish to disable this, run `pgf.enable_interactive(false)`.
Figures can be exported to files using

```jlcon
PGFPlotsX.save(filename::String, figure; include_preamble::Bool = true, dpi = 150)
pgfsave(filename::String, figure; include_preamble::Bool = true, dpi = 150)
```

where the file extension of `filename` determines the file type (can be `pdf`, `svg` or `tex`, or the standalone `tikz` file extensions below), `include_preamble` sets if the preamble should be included in the output (only relevant for `tex` export) and `dpi` determines the dpi of the figure (only relevant for `png` export).
Expand Down
3 changes: 2 additions & 1 deletion src/PGFPlotsX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ export TikzDocument, TikzPicture
export Axis, GroupPlot, PolarAxis
export Plot, PlotInc, Plot3, Plot3Inc, Expression, EmptyLine, Coordinates,
Table, Graphics, Legend, LegendEntry
export @pgf, print_tex, latexengine, latexengine!, CUSTOM_PREAMBLE, push_preamble!
export @pgf, pgfsave, print_tex, latexengine, latexengine!, CUSTOM_PREAMBLE,
push_preamble!

const DEBUG = haskey(ENV, "PGFPLOTSX_DEBUG")
const CUSTOM_PREAMBLE_PATH = joinpath(@__DIR__, "..", "deps", "custom_preamble.tex")
Expand Down
12 changes: 12 additions & 0 deletions src/tikzdocument.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@ extensions should be recognized by `\\includegraphics` when the
"""
const STANDALONE_TIKZ_FILEEXTS = [".tikz", ".TIKZ", ".TikZ", ".pgf", ".PGF"]

"""
$SIGNATURES
Save the argument (either [`TikzDocument`](@ref), or some other type which is
wrapped in one automatically, eg [`TikzPicture`](@ref), [`Axis`](@ref), or
[`Plot`](@ref)) to `filename`, guessing the format from the file extension.
Keywords specify options, some specific to some output formats.
`pgfsave` is an alias which is exported.
"""
function save(filename::String, td::TikzDocument;
include_preamble::Bool = true,
latex_engine = latexengine(),
Expand Down Expand Up @@ -65,6 +75,8 @@ function save(filename::String, td::TikzDocument;
return
end

const pgfsave = save

# TeX
function savetex(filename::String, td::TikzDocument;
include_preamble::Bool = true)
Expand Down
12 changes: 6 additions & 6 deletions test/test_build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,16 +56,16 @@ end
mktempdir() do dir
cd(dir) do
a = Axis(Plot(Expression("x^2")))
PGFPlotsX.save("$tmp.tex", a)
pgfsave("$tmp.tex", a)
@test is_tex_document("$tmp.tex")
println(readstring("$tmp.tex"))
PGFPlotsX.save("$tmp.png", a)
pgfsave("$tmp.png", a)
@test is_png_file("$tmp.png")
PGFPlotsX.save("$tmp.pdf", a)
pgfsave("$tmp.pdf", a)
@test is_pdf_file("$tmp.pdf")
PGFPlotsX.save("$tmp.svg", a)
pgfsave("$tmp.svg", a)
@test is_svg_file("$tmp.svg")
PGFPlotsX.save("$tmp.tikz", a)
pgfsave("$tmp.tikz", a)
@test is_tikz_standalone("$tmp.tikz")

let tikz_lines = readlines("$tmp.tikz")
Expand Down Expand Up @@ -101,7 +101,7 @@ end
samples = 40,
},
Expression(expr)))
PGFPlotsX.save(tmp_pdf, p)
pgfsave(tmp_pdf, p)
@test is_pdf_file(tmp_pdf)
rm(tmp_pdf)
end
Expand Down

0 comments on commit 9071f44

Please sign in to comment.