From 639f2766eadcc508fa0be80eea442bd18267be0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Fri, 1 Oct 2021 16:26:33 +1000 Subject: [PATCH 1/3] Organise integrations --- src/Weave.jl | 4 ++-- src/{gadfly.jl => integrations/Gadfly.jl} | 0 src/{plots.jl => integrations/Plots.jl} | 0 3 files changed, 2 insertions(+), 2 deletions(-) rename src/{gadfly.jl => integrations/Gadfly.jl} (100%) rename src/{plots.jl => integrations/Plots.jl} (100%) diff --git a/src/Weave.jl b/src/Weave.jl index ce104b6d..bbf311a5 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -23,8 +23,8 @@ end weave_info() = WEAVE_VERSION, string(Date(now())) function __init__() - @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("plots.jl") - @require Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" include("gadfly.jl") + @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" include("integrations/Plots.jl") + @require Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004" include("integrations/Gadfly.jl") end # utilitity functions diff --git a/src/gadfly.jl b/src/integrations/Gadfly.jl similarity index 100% rename from src/gadfly.jl rename to src/integrations/Gadfly.jl diff --git a/src/plots.jl b/src/integrations/Plots.jl similarity index 100% rename from src/plots.jl rename to src/integrations/Plots.jl From 5b10a1b3b7b369ca9ffcf178767c75719cceb396 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 2/3] Add `PGFPlotsX.jl` integration --- Project.toml | 1 + src/Weave.jl | 1 + src/display_methods.jl | 1 + src/integrations/PGFPlotsX.jl | 42 +++++++++++++++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 src/integrations/PGFPlotsX.jl diff --git a/Project.toml b/Project.toml index d4d9dc06..d8134272 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 bbf311a5..24c94e97 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..19375173 --- /dev/null +++ b/src/integrations/PGFPlotsX.jl @@ -0,0 +1,42 @@ +module PGFPlotsXPlots + +using ..Weave, ..PGFPlotsX + +Base.showable(m::MIME"text/latex", plot::PGFPlotsX.AxisLike) = true +Base.showable(m::MIME"text/tikz", plot::PGFPlotsX.AxisLike) = true + +function Base.display(report::Weave.Report, m::MIME"text/latex", 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) + + pgfsave(full_name, figure; include_preamble = true, dpi = dpi) + + push!(report.figures, rel_name) + report.fignum += 1 + + return full_name +end + +function Base.display(report::Weave.Report, m::MIME"text/tikz", 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) + + pgfsave(full_name, figure; include_preamble = false, dpi = dpi) + + push!(report.figures, rel_name) + report.fignum += 1 + + return full_name +end + +end # PGFPlotsXPlots From 7f8b613e61f51c9a0e67b88ff884ce049928c52b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ciar=C3=A1n=20O=27Mara?= Date: Sun, 19 Feb 2023 23:53:18 +1100 Subject: [PATCH 3/3] Append LaTeX preambles --- src/integrations/PGFPlotsX.jl | 45 +++++++++++++++++++++++++++++++++++ src/rendering/texformats.jl | 2 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/src/integrations/PGFPlotsX.jl b/src/integrations/PGFPlotsX.jl index 19375173..19043f1c 100644 --- a/src/integrations/PGFPlotsX.jl +++ b/src/integrations/PGFPlotsX.jl @@ -5,8 +5,51 @@ using ..Weave, ..PGFPlotsX Base.showable(m::MIME"text/latex", plot::PGFPlotsX.AxisLike) = true Base.showable(m::MIME"text/tikz", plot::PGFPlotsX.AxisLike) = true +const str_warning = "Could not add LaTeX preamble to document." + +function add_standalone(format::Weave.LaTeXFormat) + str = print_tex(String, "\\usepackage{standalone}") # Adds newline character. + if !contains(format.tex_deps, str) + format.tex_deps *= str + end + return nothing +end + +function add_standalone(format::Weave.LaTeX2PDF) + return add_standalone(format.primaryformat) +end + +function add_standalone(format) + @warn str_warning + return nothing +end + +function add_preamble(format::Weave.LaTeXFormat) + for item in unique([PGFPlotsX.DEFAULT_PREAMBLE; PGFPlotsX.CUSTOM_PREAMBLE]) + str = print_tex(String, item) # Adds newline character. + if !contains(format.tex_deps, str) + format.tex_deps *= str + end + end + return nothing +end + +function add_preamble(format::Weave.LaTeX2PDF) + return add_preamble(format.primaryformat) +end + +function add_preamble(format) + @warn str_warning + return nothing +end + + function Base.display(report::Weave.Report, m::MIME"text/latex", figure::PGFPlotsX.AxisLike) + add_standalone(report.format) + + add_preamble(report.format) + chunk = report.cur_chunk ext = chunk.options[:fig_ext] @@ -24,6 +67,8 @@ end function Base.display(report::Weave.Report, m::MIME"text/tikz", figure::PGFPlotsX.AxisLike) + add_preamble(report.format) + chunk = report.cur_chunk ext = chunk.options[:fig_ext] diff --git a/src/rendering/texformats.jl b/src/rendering/texformats.jl index 3f059057..7be6f4cd 100644 --- a/src/rendering/texformats.jl +++ b/src/rendering/texformats.jl @@ -96,7 +96,7 @@ function render_figures(docformat::LaTeXFormat, chunk) end for fig in fignames - if splitext(fig)[2] == ".tex" # Tikz figures + if splitext(fig)[2] in [".tex", ".tikz"] # Tikz figures figstring *= "\\resizebox{$width}{!}{\\input{$fig}}\n" else if isempty(attribs)