Bug fix: environments with figures in latex

pull/21/head
Matti Pastell 2014-12-09 09:43:32 +02:00
parent d97c45c63d
commit 2d92fe44e5
3 changed files with 20 additions and 10 deletions

View File

@ -23,9 +23,16 @@ function format(executed, doctype)
else
#Fill undefined options with format specific defaults
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])
#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
result = format_codechunk(chunk, formatdict)
#Handle figures
@ -194,13 +201,13 @@ function formatfigures(chunk, docformat::Tex)
fignames = chunk[:figure]
caption = chunk[:fig_cap]
width = chunk[:out_width]
f_pos = chunk[:fig_pos]
f_env = chunk[:fig_env]
result = ""
figstring = ""
if f_env != nothing
result *= """\\begin{$f_env}[$f_pos]\n"""
end

View File

@ -12,7 +12,7 @@ function Base.display(report::Report, m::MIME"image/png", data)
chunk[:figure] = [rel_name]
if report.term_state == :text
report.cur_result *= "\n" * report.formatdict[:codeend]
report.cur_result *= "\n" * report.formatdict[:codeend] * "\n"
end
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)
end
#TODO get width and height from chunk options, after implementing Knitr compatible options
savefig(data, full_name, width=chunk[:fig_width]*chunk[:dpi], height=chunk[:fig_height]*chunk[:dpi])
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])
end
report.fignum += 1
end

View File

@ -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}
\label{fig:cos2_fun}
\end{figure}
@ -78,9 +76,7 @@ plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
\end{juliacode}
\begin{figure}[htpb]
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.pdf}
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.pdf}
\end{figure}