mirror of https://github.com/mpastell/Weave.jl
Bug fix: environments with figures in latex
parent
d97c45c63d
commit
2d92fe44e5
|
@ -23,9 +23,16 @@ function format(executed, doctype)
|
||||||
else
|
else
|
||||||
#Fill undefined options with format specific defaults
|
#Fill undefined options with format specific defaults
|
||||||
chunk[:out_width] == nothing && (chunk[:out_width] = docformat.formatdict[:out_width])
|
chunk[:out_width] == nothing && (chunk[:out_width] = docformat.formatdict[:out_width])
|
||||||
chunk[:fig_env] == nothing && (chunk[:fig_env] = docformat.formatdict[:fig_env])
|
|
||||||
chunk[:fig_pos] == nothing && (chunk[:fig_pos] = docformat.formatdict[:fig_pos])
|
chunk[:fig_pos] == nothing && (chunk[:fig_pos] = docformat.formatdict[:fig_pos])
|
||||||
|
|
||||||
|
#Only use floats if chunk has caption or sets fig_env
|
||||||
|
if chunk[:fig_cap] != nothing && chunk[:fig_env] == nothing
|
||||||
|
(chunk[:fig_env] = docformat.formatdict[:fig_env])
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#Format code
|
#Format code
|
||||||
result = format_codechunk(chunk, formatdict)
|
result = format_codechunk(chunk, formatdict)
|
||||||
#Handle figures
|
#Handle figures
|
||||||
|
@ -194,13 +201,13 @@ function formatfigures(chunk, docformat::Tex)
|
||||||
fignames = chunk[:figure]
|
fignames = chunk[:figure]
|
||||||
caption = chunk[:fig_cap]
|
caption = chunk[:fig_cap]
|
||||||
width = chunk[:out_width]
|
width = chunk[:out_width]
|
||||||
|
|
||||||
|
|
||||||
f_pos = chunk[:fig_pos]
|
f_pos = chunk[:fig_pos]
|
||||||
f_env = chunk[:fig_env]
|
f_env = chunk[:fig_env]
|
||||||
result = ""
|
result = ""
|
||||||
figstring = ""
|
figstring = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if f_env != nothing
|
if f_env != nothing
|
||||||
result *= """\\begin{$f_env}[$f_pos]\n"""
|
result *= """\\begin{$f_env}[$f_pos]\n"""
|
||||||
end
|
end
|
||||||
|
|
|
@ -12,7 +12,7 @@ function Base.display(report::Report, m::MIME"image/png", data)
|
||||||
chunk[:figure] = [rel_name]
|
chunk[:figure] = [rel_name]
|
||||||
|
|
||||||
if report.term_state == :text
|
if report.term_state == :text
|
||||||
report.cur_result *= "\n" * report.formatdict[:codeend]
|
report.cur_result *= "\n" * report.formatdict[:codeend] * "\n"
|
||||||
end
|
end
|
||||||
|
|
||||||
report.cur_result *= formatfigures(chunk, docformat)
|
report.cur_result *= formatfigures(chunk, docformat)
|
||||||
|
@ -22,7 +22,14 @@ function Base.display(report::Report, m::MIME"image/png", data)
|
||||||
push!(report.figures, rel_name)
|
push!(report.figures, rel_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
#TODO get width and height from chunk options, after implementing Knitr compatible options
|
vector_fmts = [".pdf", ".svg"]
|
||||||
|
|
||||||
|
#Don't use dpi for vector formats
|
||||||
|
if chunk[:fig_ext] in vector_fmts
|
||||||
|
savefig(data, full_name, width=chunk[:fig_width]*100, height=chunk[:fig_height]*100)
|
||||||
|
else
|
||||||
savefig(data, full_name, width=chunk[:fig_width]*chunk[:dpi], height=chunk[:fig_height]*chunk[:dpi])
|
savefig(data, full_name, width=chunk[:fig_width]*chunk[:dpi], height=chunk[:fig_height]*chunk[:dpi])
|
||||||
|
end
|
||||||
|
|
||||||
report.fignum += 1
|
report.fignum += 1
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,10 +23,8 @@ plot(x=x, y = sin(x), Geom.line)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\begin{figure}[htpb]
|
|
||||||
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.pdf}
|
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.pdf}
|
||||||
\label{fig:cos2_fun}
|
\label{fig:cos2_fun}
|
||||||
\end{figure}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -78,9 +76,7 @@ plot(x=x, y = sin(x), Geom.line)
|
||||||
y = 20
|
y = 20
|
||||||
plot(x=x, y = cos(x), Geom.line)
|
plot(x=x, y = cos(x), Geom.line)
|
||||||
\end{juliacode}
|
\end{juliacode}
|
||||||
\begin{figure}[htpb]
|
|
||||||
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.pdf}
|
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.pdf}
|
||||||
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.pdf}
|
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.pdf}
|
||||||
\end{figure}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue