pull/443/merge
Ciarán O'Mara 2023-02-19 13:02:01 +00:00 committed by GitHub
commit 31b8940965
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 93 additions and 3 deletions

View File

@ -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"

View File

@ -23,8 +23,9 @@ 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")
@require PGFPlotsX = "8314cec4-20b6-5062-9cdb-752b83310925" include("integrations/PGFPlotsX.jl")
end
# utilitity functions

View File

@ -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)

View File

@ -0,0 +1,87 @@
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
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]
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)
add_preamble(report.format)
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

View File

@ -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)