From 21bc1cb5d25669ef9bee77d83aa574c31856fd6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Wed, 6 Oct 2021 10:31:49 +1100 Subject: [PATCH] Add `PGFPlotsX.jl` integration --- Project.toml | 1 + src/Weave.jl | 1 + src/display_methods.jl | 1 + src/integrations/PGFPlotsX.jl | 28 ++++++++++++++++++++++++++++ 4 files changed, 31 insertions(+) create mode 100644 src/integrations/PGFPlotsX.jl diff --git a/Project.toml b/Project.toml index e01b3285..62156473 100644 --- a/Project.toml +++ b/Project.toml @@ -30,6 +30,7 @@ julia = "1.2" [extras] DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" +PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/src/Weave.jl b/src/Weave.jl index 707211e0..6f2fda9f 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -25,6 +25,7 @@ weave_info() = WEAVE_VERSION, string(Date(now())) function __init__() @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("integrations/Plots.jl") @require Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" include("integrations/Gadfly.jl") + @require PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" include("integrations/PGFPlotsX.jl") end # utilitity functions diff --git a/src/display_methods.jl b/src/display_methods.jl index 779cb247..245145f6 100644 --- a/src/display_methods.jl +++ b/src/display_methods.jl @@ -32,6 +32,7 @@ const mimetype_ext = Dict( ".pdf" => "application/pdf", ".ps" => "application/postscript", ".tex" => "text/latex", + ".tikz" => "text/tikz", ) function Base.display(report::Report, data) diff --git a/src/integrations/PGFPlotsX.jl b/src/integrations/PGFPlotsX.jl new file mode 100644 index 00000000..5c3881ba --- /dev/null +++ b/src/integrations/PGFPlotsX.jl @@ -0,0 +1,28 @@ +module PGFPlotsXPlots + +using ..Weave, ..PGFPlotsX + +function Base.display(report::Weave.Report, m::MIME"application/pdf", figure::PGFPlotsX.AxisLike) + + chunk = report.cur_chunk + + ext = chunk.options[:fig_ext] + dpi = chunk.options[:dpi] + + full_name, rel_name = Weave.get_figname(report, chunk, ext = ext) + + # if ext in [".tikz", ".TIKZ", ".TikZ", ".pgf", ".PGF"] + if ext == ".tikz" + pgfsave(full_name, figure; include_preamble = false, dpi = dpi) + end + + if ext == ".tex" + pgfsave(full_name, figure; include_preamble = true, dpi = dpi) + end + + push!(report.figures, rel_name) + report.fignum += 1 + return full_name +end + +end # PGFPlotsXPlots