Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PGFPlotsX #443

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
5 changes: 3 additions & 2 deletions src/Weave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/display_methods.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
File renamed without changes.
87 changes: 87 additions & 0 deletions src/integrations/PGFPlotsX.jl
Original file line number Diff line number Diff line change
@@ -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
File renamed without changes.
2 changes: 1 addition & 1 deletion src/rendering/texformats.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down