Skip to content

Commit

Permalink
Append LaTeX preambles
Browse files Browse the repository at this point in the history
  • Loading branch information
CiaranOMara committed Feb 19, 2023
1 parent 5b10a1b commit 7f8b613
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
45 changes: 45 additions & 0 deletions src/integrations/PGFPlotsX.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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]
Expand Down
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

0 comments on commit 7f8b613

Please sign in to comment.