Weave

This is the documentation of Weave.jl. Weave is a scientific report generator/literate programming tool for Julia. It resembles Pweave and, Knitr and Sweave.

You can write your documentation and code in input document using Nowed or Markdown syntax and use weave function to execute to document to capture results and figures.

Current features

Document syntax

Weave uses noweb or markdown syntax for defining the code chunks and documentation chunks.

Noweb

Code chunks

start with a line marked with <<>>= or <<options>>= and end with line marked with @. The code between the start and end markers is executed and the output is captured to the output document. See for options below.

Documentation chunks

Are the rest of the document (between @ and <<>>= lines and the first chunk be default) and can be written with several different markup languages.

Sample document

Markdown

Markdown code chunks are defined using fenced code blocks. See sample document:

Chunk options

I've tried to follow Knitr's naming for chunk options, but not all options are implemented.

Options are separated using ";" and need to be valid Julia expressions. Example: A code chunk that saves and displays a 12 cm wide image and hides the source code:

<<fig_width=5; echo=false >>=
using Gadfly
x = linspace(0, 2π, 200)
plot(x=x, y = sin(x), Geom.line)
@

Weave currently supports the following chunk options with the following defaults:

Options for code

Options for figures

Usage

Run from julia using Gadfly for plots:

using Weave
weave(Pkg.dir("Weave","examples","gadfly_sample.mdw"))

Using Winston for plots (Julia 0.3 only):

weave(Pkg.dir("Weave","examples","winston_sample.mdw"),
plotlib="Winston", doctype="pandoc")

Using PyPlot:

weave(Pkg.dir("Weave","examples","julia_sample.mdw"), plotlib="PyPlot")

File formats

You can get a list of supported output formats:

julia> list_out_formats()
pandoc: Pandoc markdown
rst: reStructuredText and Sphinx
texminted: Latex using minted for highlighting
github: Github markdown
tex: Latex with custom code environments

Reference

[method] —
list_out_formats()

List supported output formats

[method] —
tangle(source)

Tangle source code from input document to .jl file.

parameters:

tangle(source ; out_path=:doc, informat="noweb")
  • informat: "noweb" of "markdown"
  • out_path: Path where the output is generated. Can be: :doc: Path of the source document, :pwd: Julia working directory, "somepath": Path as a string e.g "/home/mpastell/weaveout"
[method] —
weave(source)

Weave an input document to output file.

parameters:

weave(source ; doctype = "pandoc", plotlib="Gadfly",
    informat="noweb", out_path=:doc, fig_path = "figures", fig_ext = nothing)
  • doctype: see list_out_formats()
  • plotlib: "PyPlot", "Gadfly", or "Winston"
  • informat: "noweb" of "markdown"
  • out_path: Path where the output is generated. Can be: :doc: Path of the source document, :pwd: Julia working directory, "somepath": Path as a string e.g "/home/mpastell/weaveout"
  • fig_path: where figures will be generated, relative to out_path
  • fig_ext: Extension for saved figures e.g. ".pdf", ".png". Default setting depends on doctype.

Note: Run Weave from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.