From eeb723981d0202ecadb555ac771d235b52ccf7eb Mon Sep 17 00:00:00 2001 From: Sebastian Pech Date: Sun, 25 Aug 2019 10:25:57 +0200 Subject: [PATCH] Fix printing [] if fig_env is empty string --- src/formatters.jl | 13 +++++-------- test/figureformatter_test.jl | 7 ++++++- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/formatters.jl b/src/formatters.jl index 4f6d87a..7aeb3dc 100644 --- a/src/formatters.jl +++ b/src/formatters.jl @@ -257,23 +257,20 @@ function formatfigures(chunk, docformat::Union{Tex,JMarkdown2tex}) f_env = "figure" end - f_pos == nothing && (f_pos = "!h") - + (f_pos == nothing) && (f_pos = "!h") #Set size attribs = "" width == nothing || (attribs = "width=$width") (attribs != "" && height != nothing ) && (attribs *= ",") height == nothing || (attribs *= "height=$height") - - if f_env != nothing - result *= """\\begin{$f_env}[$f_pos]\n""" + if f_env != nothing + result *= "\\begin{$f_env}" + (f_pos != "") && (result *= "[$f_pos]") + result *= "\n" end - for fig = fignames - - if splitext(fig)[2] == ".tex" #Tikz figures figstring *= "\\resizebox{$width}{!}{\\input{$fig}}\n" else diff --git a/test/figureformatter_test.jl b/test/figureformatter_test.jl index 10b68e8..6ee63cf 100644 --- a/test/figureformatter_test.jl +++ b/test/figureformatter_test.jl @@ -7,7 +7,6 @@ options = merge(Weave.rcParams[:chunk_defaults], chunk.options) merge!(chunk.options, options) chunk.figures = ["figs/figures_plot1.png"] - @test Weave.formatfigures(chunk, Weave.md2tex) == "\\includegraphics{figs/figures_plot1.png}\n" @test Weave.formatfigures(chunk, Weave.tex) == "\\includegraphics{figs/figures_plot1.png}\n" @test Weave.formatfigures(chunk, Weave.texminted) == "\\includegraphics{figs/figures_plot1.png}\n" @@ -34,3 +33,9 @@ chunk.options[:label] = "somefig" @test Weave.formatfigures(chunk, Weave.pandoc) == "![Nice plot](figs/figures_plot1.png){width=100% #fig:somefig}\n" @test Weave.formatfigures(chunk, Weave.tex) == "\\begin{figure}[!h]\n\\center\n\\includegraphics[width=100%]{figs/figures_plot1.png}\n\\caption{Nice plot}\n\\label{fig:somefig}\n\\end{figure}\n" @test Weave.formatfigures(chunk, Weave.tex) == Weave.formatfigures(chunk, Weave.md2tex) + +chunk.options[:label] = nothing +chunk.options[:fig_cap] = nothing +chunk.options[:fig_env] = "center" +chunk.options[:fig_pos] = "" +@test Weave.formatfigures(chunk, Weave.tex) == "\\begin{center}\n\\includegraphics[width=100%]{figs/figures_plot1.png}\n\\end{center}\n"