From 9071f44175c84377061e0a47d418bda7848e75b7 Mon Sep 17 00:00:00 2001 From: "Tamas K. Papp" Date: Fri, 23 Feb 2018 20:08:31 +0100 Subject: [PATCH] Added alias pgfsave = save, docs for save. Fixes #69. --- docs/src/examples/axislike.md | 4 ++-- docs/src/examples/coordinates.md | 4 ++-- docs/src/examples/gallery.md | 4 ++-- docs/src/examples/juliatypes.md | 4 ++-- docs/src/examples/tables.md | 4 ++-- docs/src/man/save.md | 2 +- src/PGFPlotsX.jl | 3 ++- src/tikzdocument.jl | 12 ++++++++++++ test/test_build.jl | 12 ++++++------ 9 files changed, 31 insertions(+), 18 deletions(-) diff --git a/docs/src/examples/axislike.md b/docs/src/examples/axislike.md index 8f677369..56202304 100644 --- a/docs/src/examples/axislike.md +++ b/docs/src/examples/axislike.md @@ -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 ``` diff --git a/docs/src/examples/coordinates.md b/docs/src/examples/coordinates.md index af1f0353..306398c9 100644 --- a/docs/src/examples/coordinates.md +++ b/docs/src/examples/coordinates.md @@ -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 ``` diff --git a/docs/src/examples/gallery.md b/docs/src/examples/gallery.md index a5f0c40d..05e6b756 100644 --- a/docs/src/examples/gallery.md +++ b/docs/src/examples/gallery.md @@ -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 ``` diff --git a/docs/src/examples/juliatypes.md b/docs/src/examples/juliatypes.md index 408a4021..bb0ac39c 100644 --- a/docs/src/examples/juliatypes.md +++ b/docs/src/examples/juliatypes.md @@ -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 ``` diff --git a/docs/src/examples/tables.md b/docs/src/examples/tables.md index a9049012..febfb426 100644 --- a/docs/src/examples/tables.md +++ b/docs/src/examples/tables.md @@ -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 ``` diff --git a/docs/src/man/save.md b/docs/src/man/save.md index bbf02824..cb404c47 100644 --- a/docs/src/man/save.md +++ b/docs/src/man/save.md @@ -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). diff --git a/src/PGFPlotsX.jl b/src/PGFPlotsX.jl index 836c43af..ca7dbffa 100644 --- a/src/PGFPlotsX.jl +++ b/src/PGFPlotsX.jl @@ -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") diff --git a/src/tikzdocument.jl b/src/tikzdocument.jl index 47bfc97b..d4f86a77 100644 --- a/src/tikzdocument.jl +++ b/src/tikzdocument.jl @@ -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(), @@ -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) diff --git a/test/test_build.jl b/test/test_build.jl index eb02f5b2..d1f955ef 100644 --- a/test/test_build.jl +++ b/test/test_build.jl @@ -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") @@ -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