Skip to content

Commit 7f8b613

Browse files
committed
Append LaTeX preambles
1 parent 5b10a1b commit 7f8b613

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

src/integrations/PGFPlotsX.jl

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,51 @@ using ..Weave, ..PGFPlotsX
55
Base.showable(m::MIME"text/latex", plot::PGFPlotsX.AxisLike) = true
66
Base.showable(m::MIME"text/tikz", plot::PGFPlotsX.AxisLike) = true
77

8+
const str_warning = "Could not add LaTeX preamble to document."
9+
10+
function add_standalone(format::Weave.LaTeXFormat)
11+
str = print_tex(String, "\\usepackage{standalone}") # Adds newline character.
12+
if !contains(format.tex_deps, str)
13+
format.tex_deps *= str
14+
end
15+
return nothing
16+
end
17+
18+
function add_standalone(format::Weave.LaTeX2PDF)
19+
return add_standalone(format.primaryformat)
20+
end
21+
22+
function add_standalone(format)
23+
@warn str_warning
24+
return nothing
25+
end
26+
27+
function add_preamble(format::Weave.LaTeXFormat)
28+
for item in unique([PGFPlotsX.DEFAULT_PREAMBLE; PGFPlotsX.CUSTOM_PREAMBLE])
29+
str = print_tex(String, item) # Adds newline character.
30+
if !contains(format.tex_deps, str)
31+
format.tex_deps *= str
32+
end
33+
end
34+
return nothing
35+
end
36+
37+
function add_preamble(format::Weave.LaTeX2PDF)
38+
return add_preamble(format.primaryformat)
39+
end
40+
41+
function add_preamble(format)
42+
@warn str_warning
43+
return nothing
44+
end
45+
46+
847
function Base.display(report::Weave.Report, m::MIME"text/latex", figure::PGFPlotsX.AxisLike)
948

49+
add_standalone(report.format)
50+
51+
add_preamble(report.format)
52+
1053
chunk = report.cur_chunk
1154

1255
ext = chunk.options[:fig_ext]
@@ -24,6 +67,8 @@ end
2467

2568
function Base.display(report::Weave.Report, m::MIME"text/tikz", figure::PGFPlotsX.AxisLike)
2669

70+
add_preamble(report.format)
71+
2772
chunk = report.cur_chunk
2873

2974
ext = chunk.options[:fig_ext]

src/rendering/texformats.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function render_figures(docformat::LaTeXFormat, chunk)
9696
end
9797

9898
for fig in fignames
99-
if splitext(fig)[2] == ".tex" # Tikz figures
99+
if splitext(fig)[2] in [".tex", ".tikz"] # Tikz figures
100100
figstring *= "\\resizebox{$width}{!}{\\input{$fig}}\n"
101101
else
102102
if isempty(attribs)

0 commit comments

Comments
 (0)