diff --git a/.gitignore b/.gitignore index 99fdbe8..4b42e76 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,10 @@ test/documents/figures test/documents/*.tex test/documents/*.md test/documents/*.rst +test/documents/*.html +test/documents/*.pdf +!test/documents/*ref.* + tmp/ .idea diff --git a/src/Weave.jl b/src/Weave.jl index 7c9d409..b3aaf75 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -75,6 +75,7 @@ function weave(source ; doctype = "pandoc", plotlib="PyPlot", informat="noweb", rcParams[:chunk_defaults][:fig] = false else l_plotlib = lowercase(plotlib) + rcParams[:chunk_defaults][:fig] = true if l_plotlib == "winston" eval(parse("""include(Pkg.dir("Weave","src","winston.jl"))""")) rcParams[:plotlib] = "Winston" @@ -196,6 +197,7 @@ function run(parsed) else chunk[:result] = run_block(chunk[:content]) end + if rcParams[:plotlib] == "PyPlot" chunk[:fig] && (chunk[:figure] = savefigs(chunk)) else diff --git a/src/formatters.jl b/src/formatters.jl index db8e956..80a814a 100644 --- a/src/formatters.jl +++ b/src/formatters.jl @@ -26,7 +26,6 @@ function format(executed, doctype) chunk[:fig_env] == nothing && (chunk[:fig_env] = docformat.formatdict[:fig_env]) chunk[:fig_pos] == nothing && (chunk[:fig_pos] = docformat.formatdict[:fig_pos]) - #Format code result = format_codechunk(chunk, formatdict) #Handle figures diff --git a/src/gadfly.jl b/src/gadfly.jl index b824a2b..9dd2b9b 100644 --- a/src/gadfly.jl +++ b/src/gadfly.jl @@ -20,7 +20,7 @@ function Base.display(report::Report, m::MIME"image/png", p::Plot) 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 diff --git a/test/documents/chunk_options_ref.tex b/test/documents/chunk_options_ref.tex index 2f1b3ed..70d8288 100644 --- a/test/documents/chunk_options_ref.tex +++ b/test/documents/chunk_options_ref.tex @@ -1,13 +1,13 @@ -\begin{juliacode} +\begin{juliaterm} julia> y= [2, 5, 12] 3-element Array{Int64,1}: 2 5 12 -\end{juliacode} +\end{juliaterm} diff --git a/test/documents/gadfly_formats_test.txt b/test/documents/gadfly_formats_test.txt new file mode 100644 index 0000000..5e3db55 --- /dev/null +++ b/test/documents/gadfly_formats_test.txt @@ -0,0 +1,29 @@ + + +<>= +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +@ + +<>= +plot(x=x, y = cos(x), Geom.line) +@ + +<>= +plot(x=x, y = cos(2x), Geom.line) +@ + +<>= +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +y = 20 +plot(x=x, y = cos(x), Geom.line) +@ + +<>= +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +y = 20 +plot(x=x, y = cos(x), Geom.line) +@ diff --git a/test/documents/gadfly_formats_test_jssvg_ref.md b/test/documents/gadfly_formats_test_jssvg_ref.md new file mode 100644 index 0000000..61e459b --- /dev/null +++ b/test/documents/gadfly_formats_test_jssvg_ref.md @@ -0,0 +1,80 @@ + + + +````julia +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +```` + + +![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.js.svg) + + + +![cos(x) function.](figures/gadfly_formats_test_2_1.js.svg) + + + +![](figures/gadfly_formats_test_cos2_fun_1.js.svg) + + + +````julia +julia> x = linspace(0, 2π, 200) +200-element Array{Float64,1}: + 0.0 + 0.0315738 + 0.0631476 + 0.0947214 + 0.126295 + 0.157869 + 0.189443 + 0.221017 + 0.25259 + 0.284164 + ⋮ + 6.03059 + 6.06217 + 6.09374 + 6.12532 + 6.15689 + 6.18846 + 6.22004 + 6.25161 + 6.28319 + +julia> plot(x=x, y = sin(x), Geom.line) + +```` + + +![](figures/gadfly_formats_test_4_1.js.svg) + + +````julia +julia> y = 20 +20 + +julia> plot(x=x, y = cos(x), Geom.line) + +```` + + +![](figures/gadfly_formats_test_4_2.js.svg) + + + + +````julia +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +y = 20 +plot(x=x, y = cos(x), Geom.line) +```` + + +![](figures/gadfly_formats_test_5_1.js.svg) +![](figures/gadfly_formats_test_5_2.js.svg) + + diff --git a/test/documents/gadfly_formats_test_pandoc_ref.md b/test/documents/gadfly_formats_test_pandoc_ref.md new file mode 100644 index 0000000..866e1e4 --- /dev/null +++ b/test/documents/gadfly_formats_test_pandoc_ref.md @@ -0,0 +1,80 @@ + + + +~~~~{.julia} +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +~~~~~~~~~~~~~ + + +![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.png) + + + +![cos(x) function.](figures/gadfly_formats_test_2_1.png) + + + +![](figures/gadfly_formats_test_cos2_fun_1.png) + + + +~~~~{.julia} +julia> x = linspace(0, 2π, 200) +200-element Array{Float64,1}: + 0.0 + 0.0315738 + 0.0631476 + 0.0947214 + 0.126295 + 0.157869 + 0.189443 + 0.221017 + 0.25259 + 0.284164 + ⋮ + 6.03059 + 6.06217 + 6.09374 + 6.12532 + 6.15689 + 6.18846 + 6.22004 + 6.25161 + 6.28319 + +julia> plot(x=x, y = sin(x), Geom.line) + +~~~~~~~~~~~~~ + + +![](figures/gadfly_formats_test_4_1.png) + + +~~~~{.julia} +julia> y = 20 +20 + +julia> plot(x=x, y = cos(x), Geom.line) + +~~~~~~~~~~~~~ + + +![](figures/gadfly_formats_test_4_2.png) + + + + +~~~~{.julia} +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +y = 20 +plot(x=x, y = cos(x), Geom.line) +~~~~~~~~~~~~~ + + +![](figures/gadfly_formats_test_5_1.png) +![](figures/gadfly_formats_test_5_2.png) + + diff --git a/test/documents/gadfly_formats_test_ref.rst b/test/documents/gadfly_formats_test_ref.rst new file mode 100644 index 0000000..4b9a614 --- /dev/null +++ b/test/documents/gadfly_formats_test_ref.rst @@ -0,0 +1,102 @@ + + + +.. code-block:: julia + + using Gadfly + x = linspace(0, 2π, 200) + plot(x=x, y = sin(x), Geom.line) + + + +.. figure:: figures/gadfly_formats_test_sin_fun_1.png + :width: 15 cm + + sin(x) function. + + + + +.. figure:: figures/gadfly_formats_test_2_1.png + :width: 15 cm + + cos(x) function. + + + + +.. image:: figures/gadfly_formats_test_cos2_fun_1.png + :width: 15 cm + + + + +.. code-block:: julia + + julia> x = linspace(0, 2π, 200) + 200-element Array{Float64,1}: + 0.0 + 0.0315738 + 0.0631476 + 0.0947214 + 0.126295 + 0.157869 + 0.189443 + 0.221017 + 0.25259 + 0.284164 + ⋮ + 6.03059 + 6.06217 + 6.09374 + 6.12532 + 6.15689 + 6.18846 + 6.22004 + 6.25161 + 6.28319 + + julia> plot(x=x, y = sin(x), Geom.line) + + + + +.. image:: figures/gadfly_formats_test_4_1.png + :width: 15 cm + + + +.. code-block:: julia + + julia> y = 20 + 20 + + julia> plot(x=x, y = cos(x), Geom.line) + + + + +.. image:: figures/gadfly_formats_test_4_2.png + :width: 15 cm + + + + + +.. code-block:: julia + + x = linspace(0, 2π, 200) + plot(x=x, y = sin(x), Geom.line) + y = 20 + plot(x=x, y = cos(x), Geom.line) + + + +.. image:: figures/gadfly_formats_test_5_1.png + :width: 15cm + +.. image:: figures/gadfly_formats_test_5_2.png + :width: 15cm + + + diff --git a/test/documents/gadfly_formats_test_ref.tex b/test/documents/gadfly_formats_test_ref.tex new file mode 100644 index 0000000..59ee2f1 --- /dev/null +++ b/test/documents/gadfly_formats_test_ref.tex @@ -0,0 +1,86 @@ + + + +\begin{juliacode} +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +\end{juliacode} +\begin{figure}[ht] +\center +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_sin_fun_1.pdf} +\caption{sin(x) function.} +\label{fig:sin_fun} +\end{figure} + + + +\begin{figure}[htpb] +\center +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_2_1.pdf} +\caption{cos(x) function.} +\end{figure} + + + +\begin{figure}[htpb] +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.pdf} +\label{fig:cos2_fun} +\end{figure} + + + +\begin{juliaterm} +julia> x = linspace(0, 2π, 200) +200-element Array{Float64,1}: + 0.0 + 0.0315738 + 0.0631476 + 0.0947214 + 0.126295 + 0.157869 + 0.189443 + 0.221017 + 0.25259 + 0.284164 + ⋮ + 6.03059 + 6.06217 + 6.09374 + 6.12532 + 6.15689 + 6.18846 + 6.22004 + 6.25161 + 6.28319 + +julia> plot(x=x, y = sin(x), Geom.line) + +\end{juliacode} +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_1.pdf} + + +\begin{juliacode} +julia> y = 20 +20 + +julia> plot(x=x, y = cos(x), Geom.line) + +\end{juliacode} +\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_2.pdf} + + + + +\begin{juliacode} +x = linspace(0, 2π, 200) +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} + + diff --git a/test/documents/gadfly_formats_test_svg_ref.md b/test/documents/gadfly_formats_test_svg_ref.md new file mode 100644 index 0000000..af5c0f2 --- /dev/null +++ b/test/documents/gadfly_formats_test_svg_ref.md @@ -0,0 +1,80 @@ + + + +~~~~{.julia} +using Gadfly +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +~~~~~~~~~~~~~ + + +![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.svg) + + + +![cos(x) function.](figures/gadfly_formats_test_2_1.svg) + + + +![](figures/gadfly_formats_test_cos2_fun_1.svg) + + + +~~~~{.julia} +julia> x = linspace(0, 2π, 200) +200-element Array{Float64,1}: + 0.0 + 0.0315738 + 0.0631476 + 0.0947214 + 0.126295 + 0.157869 + 0.189443 + 0.221017 + 0.25259 + 0.284164 + ⋮ + 6.03059 + 6.06217 + 6.09374 + 6.12532 + 6.15689 + 6.18846 + 6.22004 + 6.25161 + 6.28319 + +julia> plot(x=x, y = sin(x), Geom.line) + +~~~~~~~~~~~~~ + + +![](figures/gadfly_formats_test_4_1.svg) + + +~~~~{.julia} +julia> y = 20 +20 + +julia> plot(x=x, y = cos(x), Geom.line) + +~~~~~~~~~~~~~ + + +![](figures/gadfly_formats_test_4_2.svg) + + + + +~~~~{.julia} +x = linspace(0, 2π, 200) +plot(x=x, y = sin(x), Geom.line) +y = 20 +plot(x=x, y = cos(x), Geom.line) +~~~~~~~~~~~~~ + + +![](figures/gadfly_formats_test_5_1.svg) +![](figures/gadfly_formats_test_5_2.svg) + + diff --git a/test/documents/gadfly_markdown_test_ref.md b/test/documents/gadfly_markdown_test_ref.md index 129a0c5..f65b9a4 100644 --- a/test/documents/gadfly_markdown_test_ref.md +++ b/test/documents/gadfly_markdown_test_ref.md @@ -32,6 +32,7 @@ julia> plot(x=x, y = sin(x), Geom.line) ```` + ![](figures/gadfly_markdown_test_1_1.png) @@ -43,6 +44,7 @@ julia> plot(x=x, y = cos(x), Geom.line) ```` + ![](figures/gadfly_markdown_test_1_2.png) @@ -119,6 +121,7 @@ julia> plot(x=x, y = sin(x), Geom.line) ```` + ![](figures/gadfly_markdown_test_3_1.png) @@ -130,6 +133,7 @@ julia> plot(x=x, y = cos(x), Geom.line) ```` + ![](figures/gadfly_markdown_test_3_2.png) diff --git a/test/gadfly_formats.jl b/test/gadfly_formats.jl new file mode 100644 index 0000000..00f76bc --- /dev/null +++ b/test/gadfly_formats.jl @@ -0,0 +1,30 @@ +#Test for Gadfly with different chunk options and figure formats +using Weave +using Base.Test + +weave("documents/gadfly_formats_test.txt", doctype="tex", plotlib="gadfly") +result = readall(open("documents/gadfly_formats_test.tex")) +ref = readall(open("documents/gadfly_formats_test_ref.tex")) +@test result == ref + +weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly") +result = readall(open("documents/gadfly_formats_test.md")) +ref = readall(open("documents/gadfly_formats_test_pandoc_ref.md")) +@test result == ref + + +weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg") +result = readall(open("documents/gadfly_formats_test.md")) +ref = readall(open("documents/gadfly_formats_test_svg_ref.md")) +@test result == ref + +weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg") +result = readall(open("documents/gadfly_formats_test.md")) +ref = readall(open("documents/gadfly_formats_test_jssvg_ref.md")) +@test result == ref + + +weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly") +result = readall(open("documents/gadfly_formats_test.rst")) +ref = readall(open("documents/gadfly_formats_test_ref.rst")) +@test result == ref diff --git a/test/runtests.jl b/test/runtests.jl index cfa3874..f074a4d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -7,32 +7,31 @@ using Base.Test weave("documents/chunk_options.noweb", plotlib=nothing) result = readall(open("documents/chunk_options.md")) ref = readall(open("documents/chunk_options_ref.md")) - @test result == ref weave("documents/chunk_options.noweb", doctype="tex", plotlib=nothing) result = readall(open("documents/chunk_options.tex")) ref = readall(open("documents/chunk_options_ref.tex")) - @test result == ref weave("documents/chunk_options.noweb", doctype="texminted", plotlib=nothing) result = readall(open("documents/chunk_options.tex")) ref = readall(open("documents/chunk_options_ref.texminted")) - @test result == ref weave("documents/chunk_options.noweb", doctype="rst", plotlib=nothing) result = readall(open("documents/chunk_options.rst")) ref = readall(open("documents/chunk_options_ref.rst")) - @test result == ref + #Test Gadfly and markdown reader, Gadfly only works with 0.3 if VERSION.minor == 3 weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown") result = readall(open("documents/gadfly_markdown_test.md")) ref = readall(open("documents/gadfly_markdown_test_ref.md")) @test result == ref + + include("gadfly_formats.jl") end