Weave.jl/examples/gadfly_md_sample.jmd

77 lines
2.3 KiB
Plaintext
Raw Normal View History

2016-12-15 21:14:18 +01:00
---
title : Intro to Weave.jl with Gadfly
author : Matti Pastell
date : 13th December 2016
---
2016-04-20 21:19:01 +02:00
2017-03-14 20:27:26 +01:00
# Intro
2016-12-15 21:14:18 +01:00
This a sample [Julia](http://julialang.org/) markdown document that can
2020-06-13 21:05:28 +02:00
be executed using [Weave.jl](https://github.com/JunoLab/Weave.jl).
2016-04-20 21:19:01 +02:00
The code is delimited from docs using markdown fenced code blocks
2016-12-15 21:14:18 +01:00
markup which can be seen looking at the source document
[gadfly_md_sample.jmd](gadfly_md_sample.jmd)
2016-04-20 21:19:01 +02:00
in the examples directory of the package. The source document can be executed
2016-12-15 21:14:18 +01:00
and the results with Gadfly plots are captured in the resulting file.
2016-04-20 21:19:01 +02:00
2016-12-15 21:14:18 +01:00
You can create markdown output or pdf (with xelatex) and HTML directly using
2016-04-20 21:19:01 +02:00
the weave command as follows:
```{julia; eval=false}
using Weave
#Markdown
weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown",
out_path = :pwd, doctype = "pandoc")
#HTML
weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown",
out_path = :pwd, doctype = "md2html")
#pdf
weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown",
out_path = :pwd, doctype = "md2pdf")
```
2016-12-15 21:14:18 +01:00
*The markdown variant used for html and pdf output is Julia markdown.*
The documents will be written to the Julia working directory when you
use the `out_path = :pwd`.
2016-04-20 21:19:01 +02:00
2017-03-14 20:27:26 +01:00
# Capturing code
2016-04-20 21:19:01 +02:00
The basic code chunk will be run with default options and the code and
output will be captured.
```julia
using Gadfly
x = linspace(0, 2*pi)
println(x)
2018-01-07 11:31:06 +01:00
plot(x = x, y = sin.(x))
2016-04-20 21:19:01 +02:00
```
You can also control the way the results are captured, plot size etc.
using chunk options. Here is an example of a chunk that behaves like a repl.
```{julia;term=true}
x = 1:10
d = Dict("Weave" => "testing")
y = [2, 4 ,8]
```
You can also for instance hide the code and show only the figure, add a
caption to the figure and make it wider as follows (you can only see the
syntax from the source document):
2016-12-16 23:16:40 +01:00
```{julia;echo=false; fig_cap="A random walk."; label="random"; fig_width=7; fig_height=4}
2016-04-20 21:19:01 +02:00
plot(y = cumsum(randn(1000, 1)), Geom.line)
```
2017-03-14 20:27:26 +01:00
# Whats next
2016-04-20 21:19:01 +02:00
Read the documentation:
2016-12-13 14:30:23 +01:00
- stable: [http://mpastell.github.io/Weave.jl/stable/](http://mpastell.github.io/Weave.jl/stable/)
2020-06-14 06:34:43 +02:00
- latest: [http://weavejl.mpastell.com/dev/](http://weavejl.mpastell.com/dev/)
2016-04-20 21:19:01 +02:00
2020-06-13 21:05:28 +02:00
See other examples in the [GitHub repo](https://github.com/JunoLab/Weave.jl/tree/master/examples)