mirror of https://github.com/mpastell/Weave.jl
Updates to gadfly sample
parent
54a9a79e98
commit
92a5a372c4
|
@ -2,23 +2,52 @@
|
|||
% Matti Pastell
|
||||
% 20th April 2016
|
||||
|
||||
# Introduction
|
||||
|
||||
This a sample [Julia](http://julialang.org/) noweb document that can
|
||||
be executed using [Weave.jl](https://github.com/mpastell/Weave.jl).
|
||||
|
||||
The code is delimited from docs using `<<>>=` and `@` markup which can be seen
|
||||
looking at the source document [gadfly_sample.mdw] in the examples directory
|
||||
of the package. The source document can be executed and the results with Gadfly
|
||||
plots are captured in the resulting file.
|
||||
|
||||
You can create markdown output or pdf and HTML directly (with Pandoc) using
|
||||
the weave command as follows:
|
||||
|
||||
```julia
|
||||
using Weave
|
||||
weave(Pkg.dir("Weave","examples","gadfly_sample.mdw"), out_path = :pwd)
|
||||
#Markdown
|
||||
weave(Pkg.dir("Weave","examples","gadfly_sample.mdw"),
|
||||
out_path = :pwd, doctype = "pandoc")
|
||||
#HTML
|
||||
weave(Pkg.dir("Weave","examples","gadfly_sample.mdw"),
|
||||
out_path = :pwd, doctype = "md2html")
|
||||
#pdf
|
||||
weave(Pkg.dir("Weave","examples","gadfly_sample.mdw"),
|
||||
out_path = :pwd, doctype = "md2pdf")
|
||||
```
|
||||
|
||||
*The documents will be written to the Julia working directory when you
|
||||
use the `out_path = :pwd`.*
|
||||
|
||||
# Capturing code
|
||||
|
||||
The basic code chunk will be run with default options and the code and
|
||||
output will be captured.
|
||||
|
||||
<<>>=
|
||||
Using Gadfly
|
||||
x = linspace(0, 2*pi)
|
||||
println(x)
|
||||
plot(x = x, y = sin(x))
|
||||
@
|
||||
|
||||
|
||||
|
||||
<<term=true>>=
|
||||
using Gadfly
|
||||
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, 200)
|
||||
println(x)
|
||||
@
|
||||
|
|
|
@ -34,21 +34,21 @@ function parse_doc(document::AbstractString, format="noweb"::AbstractString)
|
|||
start_line = 0
|
||||
|
||||
options = Dict()
|
||||
optionAbstractString = ""
|
||||
optionString = ""
|
||||
parsed = Any[]
|
||||
for lineno in 1:length(lines)
|
||||
line = lines[lineno]
|
||||
if (m = match(codestart, line)) != nothing && state=="doc"
|
||||
state = "code"
|
||||
if m.captures[1] == nothing
|
||||
optionAbstractString = ""
|
||||
optionString = ""
|
||||
else
|
||||
optionAbstractString=strip(m.captures[1])
|
||||
optionString=strip(m.captures[1])
|
||||
end
|
||||
#@show optionAbstractString
|
||||
options = Dict{Symbol,Any}()
|
||||
if length(optionAbstractString) > 0
|
||||
expr = parse(optionAbstractString)
|
||||
if length(optionString) > 0
|
||||
expr = parse(optionString)
|
||||
Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2])
|
||||
Base.Meta.isexpr(expr,:toplevel) && map(pushopt,fill(options,length(expr.args)),expr.args)
|
||||
end
|
||||
|
@ -67,7 +67,7 @@ function parse_doc(document::AbstractString, format="noweb"::AbstractString)
|
|||
end
|
||||
if ismatch(codeend, line) && state=="code"
|
||||
|
||||
chunk = CodeChunk(content, codeno, start_line, optionAbstractString, options)
|
||||
chunk = CodeChunk(content, codeno, start_line, optionString, options)
|
||||
#chunk = @compat Dict{Symbol,Any}(:type => "code", :content => content,
|
||||
# :number => codeno, :options => options,
|
||||
# :optionAbstractString => optionAbstractString,
|
||||
|
|
Loading…
Reference in New Issue