mirror of https://github.com/mpastell/Weave.jl
commit
46a0da597d
|
@ -26,11 +26,10 @@ YAML = "0.3, 0.4"
|
|||
julia = "1.2"
|
||||
|
||||
[extras]
|
||||
Cairo = "159f3aea-2a34-519c-b102-8c37f9878175"
|
||||
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
|
||||
Gadfly = "c91e804a-d5a3-530f-b6f0-dfbca275c004"
|
||||
Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80"
|
||||
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
|
||||
|
||||
[targets]
|
||||
test = ["Cairo", "DataFrames", "Gadfly", "Plots", "Test"]
|
||||
test = ["DataFrames", "Test"]
|
||||
|
|
|
@ -30,6 +30,7 @@ end
|
|||
|
||||
# utilitity functions
|
||||
take2string!(io) = String(take!(io))
|
||||
joinlines(lines) = join(lines, '\n')
|
||||
|
||||
"""
|
||||
list_out_formats()
|
||||
|
@ -217,7 +218,7 @@ function weave(
|
|||
rm(intermediate)
|
||||
elseif doctype == "md2pdf"
|
||||
run_latex(doc, out_path, latex_cmd)
|
||||
out_path = get_out_path(doc, out_path, ext = "pdf")
|
||||
out_path = get_out_path(doc, out_path, "pdf")
|
||||
end
|
||||
|
||||
@info "Weaved to $(out_path)"
|
||||
|
|
|
@ -15,7 +15,7 @@ const _DEFAULT_PARAMS = Dict{Symbol,Any}(
|
|||
:fig_path => DEFAULT_FIG_PATH,
|
||||
:dpi => 96,
|
||||
:term => false,
|
||||
:prompt => "\njulia> ",
|
||||
:prompt => "julia>",
|
||||
:label => nothing,
|
||||
:wrap => true,
|
||||
:line_width => 75,
|
||||
|
|
74
src/run.jl
74
src/run.jl
|
@ -192,55 +192,40 @@ function run_inline(inline::InlineCode, doc::WeaveDoc, report::Report, mod::Modu
|
|||
return inline
|
||||
end
|
||||
|
||||
reset_report(report::Report) = report.figures = String[]
|
||||
|
||||
function run_code(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module)
|
||||
ss = parse_input(chunk.content)
|
||||
n = length(ss)
|
||||
results = ChunkOutput[]
|
||||
for (i, s) in enumerate(ss)
|
||||
reset_report(report)
|
||||
obj, out = capture_output(
|
||||
mod,
|
||||
s,
|
||||
doc.path,
|
||||
chunk.options[:term],
|
||||
i == n,
|
||||
chunk.options[:error],
|
||||
)
|
||||
figures = report.figures # Captured figures
|
||||
result = ChunkOutput(s, out, report.rich_output, figures)
|
||||
report.rich_output = ""
|
||||
push!(results, result)
|
||||
end
|
||||
return results
|
||||
code = chunk.content
|
||||
path = doc.path
|
||||
error = chunk.options[:error]
|
||||
codes = chunk.options[:term] ? split_code(code) : [code]
|
||||
capture = code -> capture_output(code, mod, path, error, report)
|
||||
return capture.(codes)
|
||||
end
|
||||
|
||||
# Parse chunk input to array of expressions
|
||||
function parse_input(s)
|
||||
function split_code(code)
|
||||
res = String[]
|
||||
s = lstrip(s)
|
||||
n = sizeof(s)
|
||||
pos = 1
|
||||
while (oldpos = pos) ≤ n
|
||||
_, pos = Meta.parse(s, pos)
|
||||
push!(res, s[oldpos:pos-1])
|
||||
e = 1
|
||||
ex = :init
|
||||
while true
|
||||
s = e
|
||||
ex, e = Meta.parse(code, s)
|
||||
isnothing(ex) && break
|
||||
push!(res, strip(code[s:e-1]))
|
||||
end
|
||||
return res
|
||||
end
|
||||
|
||||
function capture_output(mod, s, path, term, lastline, error)
|
||||
local out = nothing
|
||||
local obj = nothing
|
||||
function capture_output(code, mod, path, error, report)
|
||||
reset_report!(report)
|
||||
|
||||
old = stdout
|
||||
rw, wr = redirect_stdout()
|
||||
reader = @async read(rw, String)
|
||||
|
||||
local out = nothing
|
||||
task_local_storage(:SOURCE_PATH, path) do
|
||||
try
|
||||
obj = include_string(mod, s, path) # TODO: fix line number
|
||||
!isnothing(obj) && (term || lastline) && display(obj)
|
||||
obj = include_string(mod, code, path) # TODO: fix line number
|
||||
!isnothing(obj) && display(obj)
|
||||
catch _err
|
||||
err = unwrap_load_err(_err)
|
||||
error || throw(err)
|
||||
|
@ -254,13 +239,19 @@ function capture_output(mod, s, path, term, lastline, error)
|
|||
end
|
||||
end
|
||||
|
||||
out = replace(out, r"\u001b\[.*?m" => "") # remove ANSI color codes
|
||||
return (obj, out)
|
||||
return ChunkOutput(code, remove_ansi_code(out), report.rich_output, report.figures)
|
||||
end
|
||||
|
||||
function reset_report!(report)
|
||||
report.rich_output = ""
|
||||
report.figures = String[]
|
||||
end
|
||||
|
||||
unwrap_load_err(err) = return err
|
||||
unwrap_load_err(err::LoadError) = return err.error
|
||||
|
||||
remove_ansi_code(s) = replace(s, r"\u001b\[.*?m" => "")
|
||||
|
||||
function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module)
|
||||
if !chunk.options[:eval]
|
||||
chunk.output = ""
|
||||
|
@ -399,7 +390,7 @@ function collect_term_results(chunk::CodeChunk)
|
|||
prompt = chunk.options[:prompt]
|
||||
result_chunks = CodeChunk[]
|
||||
for r in chunk.result
|
||||
output *= string(prompt, r.code, r.stdout)
|
||||
output *= string('\n', indent_term_code(prompt, r.code), '\n', r.stdout)
|
||||
if !isempty(r.figures)
|
||||
rchunk = CodeChunk(
|
||||
"",
|
||||
|
@ -429,6 +420,15 @@ function collect_term_results(chunk::CodeChunk)
|
|||
return result_chunks
|
||||
end
|
||||
|
||||
function indent_term_code(prompt, code)
|
||||
prompt_with_space = string(prompt, ' ')
|
||||
n = length(prompt_with_space)
|
||||
pads = ' ' ^ n
|
||||
return map(enumerate(split(code, '\n'))) do (i,line)
|
||||
isone(i) ? string(prompt_with_space, line) : string(pads, line)
|
||||
end |> joinlines
|
||||
end
|
||||
|
||||
function collect_hold_results(chunk::CodeChunk)
|
||||
for r in chunk.result
|
||||
chunk.output *= r.stdout
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
~~~~{.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.js.svg){#fig:sin_fun}
|
||||
|
||||
![cos(x) function.](figures/gadfly_formats_test_2_1.js.svg)
|
||||
|
||||
~~~~{.julia}
|
||||
plot(x=x, y = cos.(2x), Geom.line)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/gadfly_formats_test_cos2_fun_1.js.svg){width=15cm #fig:cos2_fun}\
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
````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)
|
|
@ -1,17 +0,0 @@
|
|||
````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)
|
|
@ -1,18 +0,0 @@
|
|||
~~~~{.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}\
|
||||
|
|
@ -1,17 +0,0 @@
|
|||
````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)
|
|
@ -1,22 +0,0 @@
|
|||
\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}
|
|
@ -1,22 +0,0 @@
|
|||
\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}
|
|
@ -1,22 +0,0 @@
|
|||
\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.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}
|
||||
|
||||
\begin{juliacode}
|
||||
plot(x=x, y = cos.(2x), Geom.line)
|
||||
\end{juliacode}
|
||||
\includegraphics[width=15cm]{figures/gadfly_formats_test_cos2_fun_1.ps}
|
|
@ -1,22 +0,0 @@
|
|||
\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
|
||||
\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}
|
||||
|
||||
\begin{juliacode}
|
||||
plot(x=x, y = cos.(2x), Geom.line)
|
||||
\end{juliacode}
|
||||
\resizebox{15cm}{!}{\input{figures/gadfly_formats_test_cos2_fun_1.tex}}
|
|
@ -1,19 +0,0 @@
|
|||
---
|
||||
weave_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)
|
||||
@
|
|
@ -1,12 +0,0 @@
|
|||
|
||||
# Gadfly
|
||||
|
||||
```{julia;fig_ext=".svg";dpi=300}
|
||||
using Gadfly
|
||||
x = collect(range(0, stop=2π, length=200))
|
||||
plot(
|
||||
layer(x=x, y = sin.(x), Geom.line),
|
||||
layer(x=x, y = cos.(x), Geom.line, Theme(default_color=colorant"red")),
|
||||
Guide.manual_color_key("Legend", ["sin", "cos"], ["deepskyblue", "red"])
|
||||
)
|
||||
```
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
|
||||
|
||||
<div class="Random plot">
|
||||
|
||||
<p>Some inline output</p>
|
||||
|
||||
|
||||
<pre class='hljl'>
|
||||
<span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-s'>"Testing output"</span><span class='hljl-p'>)</span>
|
||||
</pre>
|
||||
|
||||
|
||||
<pre class="output">
|
||||
Testing output
|
||||
</pre>
|
||||
|
||||
|
||||
|
||||
|
||||
</div>
|
||||
|
|
@ -1,22 +0,0 @@
|
|||
|
||||
|
||||
|
||||
\begin{frame}[fragile]
|
||||
\frametitle{Random plot}
|
||||
|
||||
Some inline output
|
||||
|
||||
|
||||
\begin{lstlisting}
|
||||
(*@\HLJLnf{println}@*)(*@\HLJLp{(}@*)(*@\HLJLs{"{}Testing}@*) (*@\HLJLs{output"{}}@*)(*@\HLJLp{)}@*)
|
||||
\end{lstlisting}
|
||||
|
||||
\begin{lstlisting}
|
||||
Testing output
|
||||
\end{lstlisting}
|
||||
|
||||
|
||||
|
||||
|
||||
\end{frame}
|
||||
|
|
@ -1,16 +0,0 @@
|
|||
|
||||
using Plots
|
||||
pyplot()
|
||||
x = range(0, stop=2*pi, length=50)
|
||||
println(x)
|
||||
p = plot(x = x, y = sin(x), size =(900,300))
|
||||
|
||||
plot(x = x, y = sin(x))
|
||||
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
|
||||
plot(y = cumsum(randn(1000, 1)))
|
|
@ -1,60 +0,0 @@
|
|||
~~~~{.julia}
|
||||
using Plots
|
||||
pyplot()
|
||||
x = linspace(0, 2*pi)
|
||||
println(x)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
~~~~
|
||||
linspace(0.0,6.283185307179586,50)
|
||||
~~~~
|
||||
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
p = plot(x, sin(x), size =(900,300))
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
julia> plot(x, sin(x))
|
||||
|
||||
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/plotsjl_test_2_1.png)\
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/plotsjl_test_3_1.png)\
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
julia> plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
|
||||
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/plotsjl_test_4_1.png)\
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
julia> scatter!(rand(100),markersize=6,c=:orange)
|
||||
|
||||
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/plotsjl_test_4_2.png)\
|
||||
|
||||
|
||||
![A random walk.](figures/plotsjl_test_random_1.png)
|
|
@ -1,47 +0,0 @@
|
|||
\begin{juliacode}
|
||||
using Plots
|
||||
pyplot()
|
||||
x = linspace(0, 2*pi)
|
||||
println(x)
|
||||
\end{juliacode}
|
||||
\begin{juliaout}
|
||||
linspace(0.0,6.283185307179586,50)
|
||||
\end{juliaout}
|
||||
|
||||
\begin{juliacode}
|
||||
p = plot(x, sin(x), size =(900,300))
|
||||
\end{juliacode}
|
||||
|
||||
\begin{juliaterm}
|
||||
julia> plot(x, sin(x))
|
||||
|
||||
|
||||
\end{juliaterm}
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_2_1.pdf}
|
||||
|
||||
\begin{juliacode}
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
\end{juliacode}
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_3_1.pdf}
|
||||
|
||||
\begin{juliaterm}
|
||||
julia> plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
|
||||
|
||||
\end{juliaterm}
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_4_1.pdf}
|
||||
|
||||
\begin{juliaterm}
|
||||
julia> scatter!(rand(100),markersize=6,c=:orange)
|
||||
|
||||
|
||||
\end{juliaterm}
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_4_2.pdf}
|
||||
|
||||
\begin{figure}[htpb]
|
||||
\center
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_random_1.pdf}
|
||||
\caption{A random walk.}
|
||||
\label{fig:random}
|
||||
\end{figure}
|
|
@ -1,41 +0,0 @@
|
|||
~~~~{.julia}
|
||||
using Plots
|
||||
gr()
|
||||
x = range(0, stop=2π, length=50)
|
||||
println(x)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
~~~~
|
||||
0.0:0.1282282715750936:6.283185307179586
|
||||
~~~~
|
||||
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
p = plot(x, sin.(x), size =(900,300))
|
||||
p
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/plotsjl_test_gr_1_1.png)\
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
plot(x, sin.(x))
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/plotsjl_test_gr_2_1.png)\
|
||||
|
||||
|
||||
~~~~{.julia}
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
~~~~~~~~~~~~~
|
||||
|
||||
|
||||
![](figures/plotsjl_test_gr_3_1.png)\
|
||||
|
||||
|
||||
![A random walk.](figures/plotsjl_test_gr_random_1.png){#fig:random}
|
|
@ -1,33 +0,0 @@
|
|||
\begin{juliacode}
|
||||
using Plots
|
||||
gr()
|
||||
x = range(0, stop=2π, length=50)
|
||||
println(x)
|
||||
\end{juliacode}
|
||||
\begin{juliaout}
|
||||
0.0:0.1282282715750936:6.283185307179586
|
||||
\end{juliaout}
|
||||
|
||||
\begin{juliacode}
|
||||
p = plot(x, sin.(x), size =(900,300))
|
||||
p
|
||||
\end{juliacode}
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_gr_1_1.pdf}
|
||||
|
||||
\begin{juliacode}
|
||||
plot(x, sin.(x))
|
||||
\end{juliacode}
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_gr_2_1.pdf}
|
||||
|
||||
\begin{juliacode}
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
\end{juliacode}
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_gr_3_1.pdf}
|
||||
|
||||
\begin{figure}[htpb]
|
||||
\center
|
||||
\includegraphics[width=\linewidth]{figures/plotsjl_test_gr_random_1.pdf}
|
||||
\caption{A random walk.}
|
||||
\label{fig:random}
|
||||
\end{figure}
|
|
@ -1,29 +0,0 @@
|
|||
|
||||
|
||||
```julia
|
||||
using Plots
|
||||
pyplot()
|
||||
x = linspace(0, 2*pi)
|
||||
println(x)
|
||||
p = plot(x, sin(x), size =(900,300))
|
||||
```
|
||||
|
||||
|
||||
```julia; term=true
|
||||
plot(x, sin(x))
|
||||
```
|
||||
|
||||
```julia
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
```
|
||||
|
||||
```julia; term=true
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
```
|
||||
|
||||
|
||||
```{julia;echo=false; fig_cap="A random walk."; label="random"}
|
||||
plot(cumsum(randn(1000, 1)))
|
||||
```
|
|
@ -1,25 +0,0 @@
|
|||
|
||||
|
||||
```julia
|
||||
using Plots
|
||||
gr()
|
||||
x = range(0, stop=2π, length=50)
|
||||
println(x)
|
||||
p = plot(x, sin.(x), size =(900,300))
|
||||
p
|
||||
```
|
||||
|
||||
|
||||
```julia
|
||||
plot(x, sin.(x))
|
||||
```
|
||||
|
||||
```julia
|
||||
plot(rand(100) / 3,reg=true,fill=(0,:green))
|
||||
scatter!(rand(100),markersize=6,c=:orange)
|
||||
```
|
||||
|
||||
|
||||
```{julia;echo=false; fig_cap="A random walk."; label="random"}
|
||||
plot(cumsum(randn(1000, 1), dims=1))
|
||||
```
|
|
@ -1,37 +0,0 @@
|
|||
|
||||
y= [2, 5, 12]
|
||||
|
||||
|
||||
x = 1:10
|
||||
d = Dict("Weave" => "testing")
|
||||
y = [2, 4 ,8]
|
||||
|
||||
|
||||
x = [12, 10]
|
||||
println(y)
|
||||
println(x)
|
||||
|
||||
|
||||
println("Results without code")
|
||||
println(x)
|
||||
|
||||
|
||||
y = 1:5
|
||||
println(y)
|
||||
|
||||
|
||||
a = "Don't print me"
|
||||
println(a)
|
||||
|
||||
|
||||
println("No markup for results.")
|
||||
|
||||
|
||||
println(collect(0:10:1000))
|
||||
|
||||
|
||||
println(collect(0:10:1000))
|
||||
|
||||
|
||||
println(collect(0:10:1000))
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
# Test for Gadfly with different chunk options and figure formatsusing Weave
|
||||
|
||||
using Gadfly, Cairo
|
||||
|
||||
|
||||
function test_gadfly(doctype, fig_ext)
|
||||
out = weave(
|
||||
joinpath(@__DIR__ , "documents/gadfly_formats_test.jnw"),
|
||||
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
|
||||
|
||||
test_gadfly("github", ".png")
|
||||
test_gadfly("github", ".pdf")
|
||||
test_gadfly("github", ".svg")
|
||||
test_gadfly("pandoc", ".png")
|
||||
test_gadfly("pandoc", ".js.svg")
|
||||
test_gadfly("tex", ".pdf")
|
||||
test_gadfly("tex", ".png")
|
||||
test_gadfly("tex", ".ps")
|
||||
test_gadfly("tex", ".tex")
|
||||
|
||||
p = Gadfly.plot(x=1:10, y=1:10)
|
||||
@test showable(MIME"application/pdf"(), p) == true
|
||||
@test showable(MIME"application/png"(), p) == true
|
|
@ -1,22 +0,0 @@
|
|||
using Plots
|
||||
|
||||
|
||||
function pljtest(source, resfile, doctype)
|
||||
weave("documents/$source", out_path = "documents/plotsjl/$resfile", doctype=doctype)
|
||||
result = read("documents/plotsjl/$resfile", String)
|
||||
ref = read("documents/plotsjl/$resfile.ref", String)
|
||||
@test result == ref
|
||||
rm("documents/plotsjl/$resfile")
|
||||
end
|
||||
|
||||
pljtest("plotsjl_test_gr.jmd", "plotsjl_test_gr.md", "pandoc")
|
||||
pljtest("plotsjl_test_gr.jmd", "plotsjl_test_gr.tex", "tex")
|
||||
|
||||
# test cache with plots
|
||||
isdir("documents/cache") && rm("documents/cache", recursive = true)
|
||||
weave("documents/plotsjl_test_gr.jmd", cache=:all)
|
||||
result = read("documents/plotsjl_test_gr.html", String)
|
||||
rm("documents/plotsjl_test_gr.html")
|
||||
weave("documents/plotsjl_test_gr.jmd", cache=:all)
|
||||
cached_result = read("documents/plotsjl_test_gr.html", String)
|
||||
@test result == cached_result
|
|
@ -3,6 +3,7 @@
|
|||
# - test for `include_weave`
|
||||
# - fire horrible tests
|
||||
# - test for ipynb integration
|
||||
# - test for integrations with other libraries, especially for Plots.jl and Gadfly.jl
|
||||
|
||||
# %%
|
||||
using Weave, Test
|
||||
|
@ -56,26 +57,10 @@ end
|
|||
include("test_display.jl")
|
||||
end
|
||||
|
||||
@testset "Formatters" begin
|
||||
@testset "legacy" begin
|
||||
include("formatter_test.jl")
|
||||
include("markdown_test.jl")
|
||||
include("figureformatter_test.jl")
|
||||
end
|
||||
|
||||
@testset "cache" begin
|
||||
include("cache_test.jl")
|
||||
end
|
||||
|
||||
# trigger only on CI
|
||||
if get(ENV, "CI", nothing) == "true"
|
||||
@testset "Plots" begin
|
||||
include("plotsjl_test.jl")
|
||||
end
|
||||
|
||||
@testset "Gadfly" begin
|
||||
include("gadfly_formats.jl")
|
||||
end
|
||||
else
|
||||
@info "skipped Plots.jl and Gadfly.jl integration test"
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue