Fixes to option parsing, gadfly pdf, stripping header, add tests

pull/202/head
Matti Pastell 2019-03-11 10:23:31 +02:00
parent c33309abf6
commit 35addd2b50
26 changed files with 250 additions and 673 deletions

View File

@ -25,6 +25,8 @@ Mustache = ">=0.4.1"
[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
[targets]
test = ["Test", "Plots"]
test = ["Test", "Plots", "Gadfly", "Cairo"]

View File

@ -100,15 +100,16 @@ function weave(source ; doctype = :auto,
doc = read_doc(source, informat)
doctype == :auto && (doctype = detect_doctype(doc.source))
doc.doctype = doctype
template != nothing && (doc.template = template)
highlight_theme != nothing && (doc.highlight_theme = highlight_theme)
css != nothing && (doc.css = css)
# Read args from document header, overrides command line args
if haskey(doc.header, "options")
(doctype, informat, out_path, args, mod, fig_path, fig_ext,
cache_path, cache, throw_errors, template, highlight_theme, css,
pandoc_options, latex_cmd) = header_args(doc)
pandoc_options, latex_cmd) = header_args(doc, out_path, mod,
fig_ext, fig_path,
cache_path, cache, throw_errors,
template, highlight_theme, css,
pandoc_options, latex_cmd)
end
template != nothing && (doc.template = template)

View File

@ -96,28 +96,31 @@ header_args(doc::WeaveDoc)`
Get weave arguments from document header
"""
function header_args(doc::WeaveDoc)
function header_args(doc::WeaveDoc, out_path, mod, fig_ext, fig_path,
cache_path, cache, throw_errors,template,
highlight_theme, css,
pandoc_options, latex_cmd)
args = getvalue(doc.header, "options", Dict())
doctype = getvalue(args, "doctype", doc.doctype)
args = combine_args(args, doctype)
informat = getvalue(args, "informat", :auto)
out_path = getvalue(args, "out_path", :doc)
out_path = getvalue(args, "out_path", out_path)
out_path == ":pwd" && (out_path = :pwd)
isa(out_path, Symbol) || (out_path = joinpath(dirname(doc.source), out_path))
mod = Symbol(getvalue(args, "mod", :sandbox))
fig_path = getvalue(args, "fig_path", "figures")
fig_ext = getvalue(args, "fig_ext", nothing)
cache_path = getvalue(args, "cache_path", "cache")
cache = Symbol(getvalue(args, "cache", :off))
throw_errors = getvalue(args, "throw_errors", false)
template = getvalue(args, "template", nothing)
mod = Symbol(getvalue(args, "mod", mod))
fig_path = getvalue(args, "fig_path", fig_path)
fig_ext = getvalue(args, "fig_ext", fig_ext)
cache_path = getvalue(args, "cache_path", cache_path)
cache = Symbol(getvalue(args, "cache", cache))
throw_errors = getvalue(args, "throw_errors", throw_errors)
template = getvalue(args, "template", template)
if template != nothing && !isempty(template)
template = joinpath(dirname(doc.source), template)
end
highlight_theme = getvalue(args, "highlight_theme", nothing)
css = getvalue(args, "css", nothing)
pandoc_options = getvalue(args, "pandoc_options", String[])
latex_cmd = getvalue(args, "latex_cmd", "xelatex")
highlight_theme = getvalue(args, "highlight_theme", highlight_theme)
css = getvalue(args, "css", css)
pandoc_options = getvalue(args, "pandoc_options", pandoc_options)
latex_cmd = getvalue(args, "latex_cmd", latex_cmd)
return (doctype, informat, out_path, args, mod, fig_path, fig_ext,
cache_path, cache, throw_errors, template, highlight_theme, css,

View File

@ -43,7 +43,7 @@ function Base.display(report::Report, data)
#Set preferred mimetypes for report based on format
fig_ext = report.cur_chunk.options[:fig_ext]
for m in unique([mimetype_ext[fig_ext] ; report.mimetypes])
if showable(m, data)
if Base.invokelatest(showable, m, data)
try
if !istextmime(m)
Compat.invokelatest(display, report, m, data)

View File

@ -24,7 +24,7 @@ function format(doc::WeaveDoc)
#strip header
if isa(doc.chunks[1], DocChunk)
if occursin("md2", doc.doctype)
if !occursin("pandoc", doc.doctype)
doc.chunks[1] = strip_header(doc.chunks[1])
end
end

View File

@ -10,6 +10,13 @@ end
Gadfly.set_default_plot_format(:svg)
Base.showable(m::MIME"application/pdf", p::Gadfly.Plot) = true
Base.showable(m::MIME"application/png", p::Gadfly.Plot) = true
function Base.display(report::Weave.Report, m::MIME"application/pdf", p::Gadfly.Plot)
display(report, MIME("image/svg+xml"), p)
end
function Base.display(report::Weave.Report, m::MIME"image/png", p::Gadfly.Plot)
display(report, MIME("image/svg+xml"), p)
end
@ -17,7 +24,6 @@ end
#Gadfly doesn't call the default display methods, this catches
#all Gadfly plots
function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Plot)
chunk = report.cur_chunk
w = chunk.options[:fig_width]Gadfly.inch
@ -46,4 +52,4 @@ function Base.display(report::Weave.Report, m::MIME"image/svg+xml", p::Gadfly.Pl
@warn("Can't save figure. Unsupported format, $format")
end
end
end
end

View File

@ -1,20 +0,0 @@
import PyPlot
function savefigs_pyplot(report::Report)
chunk = report.cur_chunk
fignames = AbstractString[]
ext = report.formatdict[:fig_ext]
figpath = joinpath(report.cwd, chunk.options[:fig_path])
isdir(figpath) || mkdir(figpath)
chunkid = (chunk.options[:label] == nothing) ? chunk.number : chunk.options[:label]
#Iterate over all open figures, save them and store names
for fig = PyPlot.plt[:get_fignums]()
full_name, rel_name = get_figname(report, chunk, fignum=fig)
PyPlot.savefig(full_name, dpi=chunk.options[:dpi])
push!(report.figures, rel_name)
report.fignum += 1
PyPlot.plt[:draw]()
PyPlot.plt[:close]()
end
end

View File

@ -0,0 +1,18 @@
````julia
using Gadfly
x = range(0, stop =2π, step=0.05)
plot(x=x, y = sin.(x), Geom.line)
````
![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.pdf)
![cos(x) function.](figures/gadfly_formats_test_2_1.pdf)
````julia
plot(x=x, y = cos.(2x), Geom.line)
````
![](figures/gadfly_formats_test_cos2_fun_1.pdf)

View File

@ -0,0 +1,18 @@
````julia
using Gadfly
x = range(0, stop =2π, step=0.05)
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)
````julia
plot(x=x, y = cos.(2x), Geom.line)
````
![](figures/gadfly_formats_test_cos2_fun_1.png)

View File

@ -0,0 +1,23 @@
---
options :
out_path : gadfly
---
~~~~{.julia}
using Gadfly
x = range(0, stop =2π, step=0.05)
plot(x=x, y = sin.(x), Geom.line)
~~~~~~~~~~~~~
![sin(x) function.](figures/gadfly_formats_test_sin_fun_1.png){#fig:sin_fun}
![cos(x) function.](figures/gadfly_formats_test_2_1.png)
~~~~{.julia}
plot(x=x, y = cos.(2x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_cos2_fun_1.png){width=15cm #fig:cos2_fun}\

View File

@ -0,0 +1,18 @@
````julia
using Gadfly
x = range(0, stop =2π, step=0.05)
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)
````julia
plot(x=x, y = cos.(2x), Geom.line)
````
![](figures/gadfly_formats_test_cos2_fun_1.svg)

View File

@ -0,0 +1,23 @@
\begin{juliacode}
using Gadfly
x = range(0, stop =2π, step=0.05)
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{juliacode}
plot(x=x, y = cos.(2x), Geom.line)
\end{juliacode}
\includegraphics[width=15cm]{figures/gadfly_formats_test_cos2_fun_1.pdf}

View File

@ -0,0 +1,23 @@
\begin{juliacode}
using Gadfly
x = range(0, stop =2π, step=0.05)
plot(x=x, y = sin.(x), Geom.line)
\end{juliacode}
\begin{figure}[ht]
\center
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_sin_fun_1.png}
\caption{sin(x) function.}
\label{fig:sin_fun}
\end{figure}
\begin{figure}[htpb]
\center
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_2_1.png}
\caption{cos(x) function.}
\end{figure}
\begin{juliacode}
plot(x=x, y = cos.(2x), Geom.line)
\end{juliacode}
\includegraphics[width=15cm]{figures/gadfly_formats_test_cos2_fun_1.png}

View File

@ -0,0 +1,19 @@
---
options :
out_path : gadfly
---
<<fig_cap="sin(x) function."; label="sin_fun"; fig_pos="ht">>=
using Gadfly
x = range(0, stop =2π, step=0.05)
plot(x=x, y = sin.(x), Geom.line)
@
<<echo=false; fig_cap="cos(x) function."; dpi=200>>=
plot(x=x, y = cos.(x), Geom.line)
@
<<label="cos2_fun"; out_width="15cm">>=
plot(x=x, y = cos.(2x), Geom.line)
@

View File

@ -1,29 +0,0 @@
<<fig_cap="sin(x) function."; label="sin_fun"; fig_pos="ht">>=
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
@
<<echo=false; fig_cap="cos(x) function."; dpi=200>>=
plot(x=x, y = cos(x), Geom.line)
@
<<echo=false; label="cos2_fun">>=
plot(x=x, y = cos(2x), Geom.line)
@
<<term=true;fig_width=5>>=
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
@
<<out_width="15cm">>=
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
y = 20
plot(x=x, y = cos(x), Geom.line)
@

View File

@ -1,53 +0,0 @@
````julia
using Gadfly
x = range(0, stop=2π, length=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 = range(0, stop=2π, length=200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
````
![](figures/gadfly_formats_test_4_1.js.svg)
````julia
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
````
![](figures/gadfly_formats_test_4_2.js.svg)
````julia
x = range(0, stop=2π, length=200)
plot(x=x, y = sin(x), Geom.line)
````
![](figures/gadfly_formats_test_5_1.js.svg)
````julia
y = 20
plot(x=x, y = cos(x), Geom.line)
````
![](figures/gadfly_formats_test_5_2.js.svg)

View File

@ -1,67 +0,0 @@
````julia
using Gadfly
x = range(0, stop=2π, length=200)
plot(x=x, y = sin(x), Geom.line)
````
![sin(x) function.][figures/gadfly_formats_test_sin_fun_1.png]
[figures/gadfly_formats_test_sin_fun_1.png]: figures/gadfly_formats_test_sin_fun_1.png
![cos(x) function.][figures/gadfly_formats_test_2_1.png]
[figures/gadfly_formats_test_2_1.png]: figures/gadfly_formats_test_2_1.png
![][figures/gadfly_formats_test_cos2_fun_1.png]
[figures/gadfly_formats_test_cos2_fun_1.png]: figures/gadfly_formats_test_cos2_fun_1.png
````julia
julia> x = range(0, stop=2π, length=200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
````
![][figures/gadfly_formats_test_4_1.png]
[figures/gadfly_formats_test_4_1.png]: figures/gadfly_formats_test_4_1.png
````julia
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
````
![][figures/gadfly_formats_test_4_2.png]
[figures/gadfly_formats_test_4_2.png]: figures/gadfly_formats_test_4_2.png
````julia
x = range(0, stop=2π, length=200)
plot(x=x, y = sin(x), Geom.line)
````
![][figures/gadfly_formats_test_5_1.png]
[figures/gadfly_formats_test_5_1.png]: figures/gadfly_formats_test_5_1.png width=15cm
````julia
y = 20
plot(x=x, y = cos(x), Geom.line)
````
![][figures/gadfly_formats_test_5_2.png]
[figures/gadfly_formats_test_5_2.png]: figures/gadfly_formats_test_5_2.png width=15cm

View File

@ -1,58 +0,0 @@
~~~~{.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 LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_1.png)\
~~~~{.julia}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_2.png)\
~~~~{.julia}
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_1.png){width=15cm}\
~~~~{.julia}
y = 20
plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_2.png){width=15cm}\

View File

@ -1,52 +0,0 @@
\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.ps}
\caption{sin(x) function.}
\label{fig:sin_fun}
\end{figure}
\begin{figure}[htpb]
\center
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_2_1.ps}
\caption{cos(x) function.}
\end{figure}
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.ps}
\begin{juliaterm}
julia> x = linspace(0, 2π, 200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
\end{juliaterm}
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_1.ps}
\begin{juliaterm}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
\end{juliaterm}
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_2.ps}
\begin{juliacode}
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
\end{juliacode}
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.ps}
\begin{juliacode}
y = 20
plot(x=x, y = cos(x), Geom.line)
\end{juliacode}
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.ps}

View File

@ -1,76 +0,0 @@
.. 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 LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
.. 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)
Plot(...)
.. 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)
.. image:: figures/gadfly_formats_test_5_1.png
:width: 15cm
.. code-block:: julia
y = 20
plot(x=x, y = cos(x), Geom.line)
.. image:: figures/gadfly_formats_test_5_2.png
:width: 15cm

View File

@ -1,52 +0,0 @@
\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}
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_cos2_fun_1.pdf}
\begin{juliaterm}
julia> x = linspace(0, 2π, 200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
\end{juliaterm}
\includegraphics[width=\linewidth]{figures/gadfly_formats_test_4_1.pdf}
\begin{juliaterm}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
\end{juliaterm}
\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)
\end{juliacode}
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_1.pdf}
\begin{juliacode}
y = 20
plot(x=x, y = cos(x), Geom.line)
\end{juliacode}
\includegraphics[width=15cm]{figures/gadfly_formats_test_5_2.pdf}

View File

@ -1,58 +0,0 @@
~~~~{.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 LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_1.svg)\
~~~~{.julia}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_2.svg)\
~~~~{.julia}
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_1.svg){width=15cm}\
~~~~{.julia}
y = 20
plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_2.svg){width=15cm}\

View File

@ -1,52 +0,0 @@
\begin{juliacode}
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
\end{juliacode}
\begin{figure}[ht]
\center
\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_sin_fun_1.tex}}
\caption{sin(x) function.}
\label{fig:sin_fun}
\end{figure}
\begin{figure}[htpb]
\center
\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_2_1.tex}}
\caption{cos(x) function.}
\end{figure}
\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_cos2_fun_1.tex}}
\begin{juliaterm}
julia> x = linspace(0, 2π, 200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
\end{juliaterm}
\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_4_1.tex}}
\begin{juliaterm}
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
\end{juliaterm}
\resizebox{\linewidth}{!}{\input{figures/gadfly_formats_test_4_2.tex}}
\begin{juliacode}
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
\end{juliacode}
\resizebox{15cm}{!}{\input{figures/gadfly_formats_test_5_1.tex}}
\begin{juliacode}
y = 20
plot(x=x, y = cos(x), Geom.line)
\end{juliacode}
\resizebox{15cm}{!}{\input{figures/gadfly_formats_test_5_2.tex}}

View File

@ -1,80 +0,0 @@
# Gadfly
````julia
julia> using Gadfly
julia> x = range(0, stop=2π, length=200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
````
![](figures/gadfly_markdown_test_1_1.png)
````julia
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
````
![](figures/gadfly_markdown_test_1_2.png)
````julia
x = range(0, stop=200, length=50)
println(x)
````
````
linspace(0.0,200.0,50)
````
````julia
julia> using Gadfly
julia> x = range(0, stop=2π, length=200)
200-element LinSpace{Float64}:
0.0,0.0315738,0.0631476,0.0947214,0.126295,…,6.18846,6.22004,6.25161,6.28319
julia> plot(x=x, y = sin(x), Geom.line)
Plot(...)
````
![](figures/gadfly_markdown_test_3_1.png)
````julia
julia> y = 20
20
julia> plot(x=x, y = cos(x), Geom.line)
Plot(...)
````
![](figures/gadfly_markdown_test_3_2.png)
````julia
x = range(0, stop=200, length=50)
println(x)
````
````
linspace(0.0,200.0,50)
````

View File

@ -2,59 +2,74 @@
using Weave
using Test
function test_gadfly(doctype, fig_ext)
out = weave(joinpath(@__DIR__ , "documents/gadfly_formats_test.jnw"),
out_path = joinpath(@__DIR__ , "documents/gadfly/"),
doctype = doctype, fig_ext = fig_ext)
result = read(out, String)
#cp(out, out*fig_ext*"."*doctype, force=true) # Used when adding new tests
ref = read(out*fig_ext*"."*doctype, String)
@test result == ref
rm(out)
end
weave("documents/gadfly_formats_test.txt", doctype = "tex", plotlib="gadfly")
result = read("documents/gadfly_formats_test.tex", String)
ref = read("documents/gadfly_formats_test_ref.tex", String)
@test result == ref
##
test_gadfly("github", ".png")
test_gadfly("github", ".pdf")
test_gadfly("github", ".svg")
test_gadfly("pandoc", ".png")
test_gadfly("tex", ".pdf")
test_gadfly("tex", ".png")
weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".tex", plotlib="gadfly")
result = read("documents/gadfly_formats_test.tex", String)
ref = read("documents/gadfly_formats_test_tikz_ref.tex", String)
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".ps", plotlib="gadfly")
result = read("documents/gadfly_formats_test.tex", String)
ref = read("documents/gadfly_formats_test_ps_ref.tex", String)
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly")
result = read("documents/gadfly_formats_test.md", String)
ref = read("documents/gadfly_formats_test_pandoc_ref.md", String)
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg")
result = read("documents/gadfly_formats_test.md", String)
ref = read("documents/gadfly_formats_test_svg_ref.md", String)
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg")
result = read("documents/gadfly_formats_test.md", String)
ref = read("documents/gadfly_formats_test_jssvg_ref.md", String)
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly")
result = read("documents/gadfly_formats_test.rst", String)
ref = read("documents/gadfly_formats_test_ref.rst", String)
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="multimarkdown", plotlib="gadfly")
result = read("documents/gadfly_formats_test.md", String)
ref = read("documents/gadfly_formats_test_mmd_ref.md", String)
@test result == ref
weave("documents/gadfly_formats_test.txt", doctype="asciidoc", plotlib="gadfly",
out_path="documents/output")
result = read("documents/output/gadfly_formats_test.txt", String)
ref = read("documents/output/gadfly_formats_test_ref.txt", String)
@test result == ref
weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown")
result = read("documents/gadfly_markdown_test.md", String)
ref = read("documents/gadfly_markdown_test_ref.md", String)
@test result == ref
weave("documents/FIR_design.jl", doctype="pandoc", plotlib="gadfly", informat="script")
result = read("documents/FIR_design.md", String)
ref = read("documents/FIR_design_ref.md", String)
@test result == ref
##
# weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".tex", plotlib="gadfly")
# result = read("documents/gadfly_formats_test.tex", String)
# ref = read("documents/gadfly_formats_test_tikz_ref.tex", String)
# @test result == ref
#
# weave("documents/gadfly_formats_test.txt", doctype="tex", fig_ext=".ps", plotlib="gadfly")
# result = read("documents/gadfly_formats_test.tex", String)
# ref = read("documents/gadfly_formats_test_ps_ref.tex", String)
# @test result == ref
#
# weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly")
# result = read("documents/gadfly_formats_test.md", String)
# ref = read("documents/gadfly_formats_test_pandoc_ref.md", String)
# @test result == ref
#
# weave("documents/gadfly_formats_test.txt", doctype="pandoc", plotlib="gadfly", fig_ext=".svg")
# result = read("documents/gadfly_formats_test.md", String)
# ref = read("documents/gadfly_formats_test_svg_ref.md", String)
# @test result == ref
#
# weave("documents/gadfly_formats_test.txt", doctype="github", plotlib="gadfly", fig_ext=".js.svg")
# result = read("documents/gadfly_formats_test.md", String)
# ref = read("documents/gadfly_formats_test_jssvg_ref.md", String)
# @test result == ref
#
# weave("documents/gadfly_formats_test.txt", doctype="rst", plotlib="gadfly")
# result = read("documents/gadfly_formats_test.rst", String)
# ref = read("documents/gadfly_formats_test_ref.rst", String)
# @test result == ref
#
# weave("documents/gadfly_formats_test.txt", doctype="multimarkdown", plotlib="gadfly")
# result = read("documents/gadfly_formats_test.md", String)
# ref = read("documents/gadfly_formats_test_mmd_ref.md", String)
# @test result == ref
#
# weave("documents/gadfly_formats_test.txt", doctype="asciidoc", plotlib="gadfly",
# out_path="documents/output")
# result = read("documents/output/gadfly_formats_test.txt", String)
# ref = read("documents/output/gadfly_formats_test_ref.txt", String)
# @test result == ref
#
# weave("documents/gadfly_markdown_test.jmd", doctype="github",plotlib="gadfly", informat="markdown")
# result = read("documents/gadfly_markdown_test.md", String)
# ref = read("documents/gadfly_markdown_test_ref.md", String)
# @test result == ref
#
# weave("documents/FIR_design.jl", doctype="pandoc", plotlib="gadfly", informat="script")
# result = read("documents/FIR_design.md", String)
# ref = read("documents/FIR_design_ref.md", String)
# @test result == ref

View File

@ -39,9 +39,14 @@ using Test
include("plotsjl_test.jl")
end
@testset "Cache" begin
@info("Testing cache")
include("cache_test.jl")
end
@testset "Gadfly" begin
@info("Test: Weaving with Gadfly.jl")
include("cache_test.jl")
include("gadfly_formats.jl")
end
@testset "Header options" begin