<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>Using Weave · Weave.jl</title><linkrel="canonical"href="http://weavejl.mpastell.com/stable/usage/"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/fontawesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/solid.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/brands.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL=".."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js"data-main="../assets/documenter.js"></script><scriptsrc="../siteinfo.js"></script><scriptsrc="../../versions.js"></script><linkclass="docs-theme-link"rel="stylesheet"type="text/css"href="../assets/themes/documenter-dark.css"data-theme-name="documenter-dark"/><linkclass="docs-theme-link"rel="stylesheet"type="text/css"href="../assets/themes/documenter-light.css"data-theme-name="documenter-light"data-theme-primary/><scriptsrc="../assets/themeswap.js"></script></head><body><divid="documenter"><navclass="docs-sidebar"><divclass="docs-package-name"><spanclass="docs-autofit">Weave.jl</span></div><formclass="docs-search"action="../search/"><inputclass="docs-search-query"id="documenter-search-query"name="q"type="text"placeholder="Search docs"/></form><ulclass="docs-menu"><li><aclass="tocitem"href="../">Weave.jl - Scientific Reports Using Julia</a></li><li><aclass="tocitem"href="../getting_started/">Getting started</a></li><liclass="is-active"><aclass="tocitem"href>Using Weave</a><ulclass="internal"><li><aclass="tocitem"href="#weave-1"><span><code>weave</code></span></a></li><li><aclass="tocitem"href="#tangle-1"><span><code>tangle</code></span></a></li><li><aclass="tocitem"href="#Supported-Output-Formats-1"><span>Supported Output Formats</span></a></li><li><aclass="tocitem"href="#document-syntax-1"><span>Document Syntax</span></a></li><li><aclass="tocitem"href="#Configuration-via-YAML-Header-1"><span>Configuration via YAML Header</span></a></li><li><aclass="tocitem"href="#Passing-Runtime-Arguments-to-Documents-1"><span>Passing Runtime Arguments to Documents</span></a></li><li><aclass="tocitem"href="#include_weave-1"><span><code>include_weave</code></span></a></li></ul></li><li><aclass="tocitem"href="../publish/">Publishing to HTML and PDF</a></li><li><aclass="tocitem"href="../chunk_options/">Chunk Options</a></li><li><aclass="tocitem"href="../header/">Header Configuration</a></li><li><aclass="tocitem"href="../notebooks/">Working with Jupyter notebooks</a></li><li><aclass="tocitem"href="../function_index/">Function index</a></li></ul><divclass="docs-version-selector field has-addons"><divclass="control"><spanclass="docs-label button is-static is-size-7">Version</span></div><divclass="docs-selector control is-expanded"><divclass="select is-fullwidth is-size-7"><selectid="documenter-version-selector"></select></div></div></div></nav><divclass="docs-main"><headerclass="docs-navbar"><navclass="breadcrumb"><ulclass="is-hidden-mobile"><liclass="is-active"><ahref>Using Weave</a></li></ul><ulclass="is-hidden-tablet"><liclass="is-active"><ahref>Using Weave</a></li></ul></nav><divclass="docs-right"><aclass="docs-edit-link"href="https://github.com/JunoLab/Weave.jl/blob/master/doc/src/usage.md"title="Edit on GitHub"><spanclass="docs-icon fab"></span><spanclass="docs-label is-hidden-touch">Edit on GitHub</span></a><aclass="docs-settings-button fas fa-cog"id="documenter-settings-button"href="#"title="Settings"></a><aclass="docs-sidebar-button fa fa-bars is-hidden-desktop"id="documenter-sidebar-button"href="#"></a></div></header><
using Pkg; Pkg.add.(["Plots", "DSP"])
weave(Weave.SAMPLE_JL_DOC; out_path=:pwd)</code></pre><articleclass="docstring"><header><aclass="docstring-binding"id="Weave.weave"href="#Weave.weave"><code>Weave.weave</code></a> — <spanclass="docstring-category">Function</span></header><section><div><pre><codeclass="language-julia">weave(source::AbstractString; kwargs...)</code></pre><p>Weave an input document to output file.</p><p><strong>Keyword options</strong></p><ul><li><code>doctype::Union{Nothing,AbstractString} = nothing</code>: Output document format. By default (i.e. given <code>nothing</code>), Weave will set it automatically based on file extension. You can also manually specify it; see <ahref="#Weave.list_out_formats"><code>list_out_formats()</code></a> for the supported formats</li><li><code>informat::Union{Nothing,AbstractString} = nothing</code>: Input document format. By default (i.e. given <code>nothing</code>), Weave will set it automatically based on file extension. You can also specify either of <code>"script"</code>, <code>"markdown"</code>, <code>"notebook"</code>, or <code>"noweb"</code></li><li><code>out_path::Union{Symbol,AbstractString} = :doc</code>: Path where the output is generated can be either of:<ul><li><code>:doc</code>: Path of the source document (default)</li><li><code>:pwd</code>: Julia working directory</li><li><code>"somepath"</code>: <code>String</code> of output directory e.g. <code>"~/outdir"</code>, or of filename e.g. <code>"~/outdir/outfile.tex"</code></li></ul></li><li><code>args::Dict = Dict()</code>: Arguments to be passed to the weaved document; will be available as <code>WEAVE_ARGS</code> in the document</li><li><code>mod::Union{Module,Nothing} = nothing</code>: Module where Weave <code>eval</code>s code. You can pass a <code>Module</code> object, otherwise create an new sandbox module.</li><li><code>fig_path::AbstractString = "figures"</code>: Where figures will be generated, relative to <code>out_path</code></li><li><code>fig_ext::Union{Nothing,AbstractString} = nothing</code>: Extension for saved figures e.g. <code>".pdf"</code>, <code>".png"</code>. Default setting depends on <code>doctype</code></li><li><code>cache_path::AbstractString = "cache"</code>: Where of cached output will be saved</li><li><code>cache::Symbol = :off</code>: Controls caching of code:<ul><li><code>:off</code> means no caching (default)</li><li><code>:all</code> caches everything</li><li><code>:user</code> caches based on chunk options</li><li><code>:refresh</code> runs all code chunks and save new cache</li></ul></li><li><code>throw_errors::Bool = false</code>: If <code>false</code> errors are included in output document and the whole document is executed. If <code>true</code> errors are thrown when they occur</li><li><code>template::Union{Nothing,AbstractString,Mustache.MustacheTokens} = nothing</code>: Template (file path) or <code>Mustache.MustacheTokens</code>s for <code>md2html</code> or <code>md2tex</code> formats</li><li><code>css::Union{Nothing,AbstractString} = nothing</code>: Path of a CSS file used for md2html format</li><li><code>highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing</code>: Theme used for syntax highlighting (defaults to <code>Highlights.Themes.DefaultTheme</code>)</li><li><code>pandoc_options::Vector{<:AbstractString} = String[]</code>: <code>String</code>s of options to pass to pandoc for <code>pandoc2html</code> and <code>pandoc2pdf</code> formats, e.g. <code>["--toc", "-N"]</code></li><li><code>latex_cmd::AbstractString = "xelatex"</code>: The command used to make PDF file from .tex</li><li><code>keep_unicode::Bool = false</code>: If <code>true</code>, do not convert unicode characters to their respective latex representation. This is especially useful if a font and tex-engine with support for unicode characters are used</li></ul><divclass="admonition is-info"><headerclass="admonition-header">Note</header><divclass="admonition-body
end</code></pre><p>You can also manually specify it using the <code>doctype</code> keyword option. You can get a list of supported output formats:</p><articleclass="docstring"><header><aclass="docstring-binding"id="Weave.list_out_formats"href="#Weave.list_out_formats"><code>Weave.list_out_formats</code></a> — <spanclass="docstring-category">Function</span></header><section><div><pre><codeclass="language-julia">list_out_formats(io = stdout)</code></pre><p>List supported output formats</p></div><aclass="docs-sourcelink"target="_blank"href="https://github.com/JunoLab/Weave.jl/blob/1972d03d1991b8535df0fbd26af674c9599b8ea5/src/Weave.jl#L29-L33">source</a></section></article><pre><codeclass="language-julia">list_out_formats()</code></pre><pre><codeclass="language-none">github: GitHub markdown
hugo: Hugo markdown (using shortcodes)</code></pre><h2id="document-syntax-1"><aclass="docs-heading-anchor"href="#document-syntax-1">Document Syntax</a><aclass="docs-heading-anchor-permalink"href="#document-syntax-1"title="Permalink"></a></h2><p>Weave uses markdown, Noweb or script syntax for defining the code chunks and documentation chunks. You can also weave Jupyter notebooks. The format is detected based on the file extension, but you can also set it manually using the <code>informat</code> parameter.</p><p>The rules for autodetection are:</p><pre><codeclass="language-julia">ext == ".jl"&& return "script"
return "noweb"</code></pre><h3id="Documentation-Chunks-1"><aclass="docs-heading-anchor"href="#Documentation-Chunks-1">Documentation Chunks</a><aclass="docs-heading-anchor-permalink"href="#Documentation-Chunks-1"title="Permalink"></a></h3><p>In markdown and Noweb input formats documentation chunks are the parts that aren't inside code delimiters. Documentation chunks can be written with several different markup languages.</p><h3id="code-chunks-1"><aclass="docs-heading-anchor"href="#code-chunks-1">Code Chunks</a><aclass="docs-heading-anchor-permalink"href="#code-chunks-1"title="Permalink"></a></h3><p>Code chunks are written in different ways in different formats.</p><h4id="Markdown-Format-1"><aclass="docs-heading-anchor"href="#Markdown-Format-1">Markdown Format</a><aclass="docs-heading-anchor-permalink"href="#Markdown-Format-1"title="Permalink"></a></h4><p>Weave code chunks are defined using fenced code blocks, same as with <ahref="https://spec.commonmark.org/0.29/#fenced-code-blocks">common markdown</a>:</p><pre><codeclass="language-markdown"> ```julia
code
...
```</code></pre><p>Weave code chunks can optionally be followed by <ahref="../chunk_options/#chunk-options-1">chunk options</a> on the same line. E.g. the chunk below will hide code itself from generated output:</p><pre><codeclass="language-markdown"> ```julia, echo = false
code
...
```</code></pre><h4id="Noweb-Format-1"><aclass="docs-heading-anchor"href="#Noweb-Format-1">Noweb Format</a><aclass="docs-heading-anchor-permalink"href="#Noweb-Format-1"title="Permalink"></a></h4><p>Code chunks start with a line marked with <code><<>>=</code> or <code><<options>>=</code> and end with line marked with <code>@</code>. The code between the start and end markers is executed and the output is captured to the output document.</p><h3id="inline-code-1"><aclass="docs-heading-anchor"href="#inline-code-1">Inline Code</a><aclass="docs-heading-anchor-permalink"href="#inline-code-1"title="Permalink"></a></h3><p>You can also add inline code to your documents using</p><pre><codeclass="language-none">`j juliacode`</code></pre><p>or</p><pre><codeclass="language-none">! juliacode</code></pre><p>syntax.</p><p>The former syntax allows you to insert code <em>anywhere</em> in a line while the <code>!</code> syntax treats the whole line as code, and the code will be replaced with captured output in the weaved document.</p><p>If the code produces figures, the filename or base64 encoded string will be added to output, e.g. to include a Plots figure in markdown you can use:</p><pre><codeclass="language-none">![A plot](`j plot(1:10)`)</code></pre><p>or to produce any HTML output:</p><pre><codeclass="language-none">! display("text/html", "Header from julia");</code></pre><h3id="Script-Format-1"><aclass="docs-heading-anchor"href="#Script-Format-1">Script Format</a><aclass="docs-heading-anchor-permalink"href="#Script-Format-1"title="Permalink"></a></h3><p>Weave also supports script input format with a markup in comments. These scripts can be executed normally using Julia or published with Weave.</p><p>Lines starting with <code>#'</code>, <code>#%%</code> or <code># %%</code> are treated as document.</p><p>All non-document lines are treated as code. You can set chunk options using lines starting with <code>#+</code> just before code e.g:</p><pre><codeclass="language-julia">#+ term=true
hoge # some code comes here</code></pre><p>The format is identical to <ahref="http://mpastell.com/pweave/pypublish.html">Pweave</a> and the concept is similar to publishing documents with MATLAB or using Knitr's <ahref="http://yihui.name/knitr/demo/stitch/">spin</a>. Weave will remove the first empty space from each line of documentation.</p><divclass="admonition is-success"><headerclass="admonition-header">Tip</header><divclass="admonition-body"><ul><li>Here are sample documents:<ul><li><ahref="https://github.com/mpastell/Weave.jl/blob/master/examples/FIR_design.jmd">markdown format</a></li><li><ahref="https://github.com/mpastell/Weave.jl/blob/master/examples/FIR_design.jl">script format</a></li></ul></li><li><ahref="../chunk_options/#chunk-options-1">Details about chunk options</a></li></ul></div></div><h2id="Configuration-via-YAML-Header-1"><aclass="docs-heading-anchor"href="#Configuration-via-YAML-Header-1">Configuration via YAML Header</a><aclass="docs-heading-anchor-permalink"href="#Configuration-via-YAML-Header-1"title="Permalink"></a></h2><p>When <code>weave</code>ing markdown files, you can use YAML header to provide additional metadata and configuration options. See <ahref="../header/#Header-Configuration-1">Header Configuration</a> section for more details.</p><h2id="Passing-Runtime-Arguments-to-Documents-1"><aclass="docs-heading-anchor"href="#Passing-Runtime-Arguments-to-Documents-1">Passing Runtime Arguments to Documents</a><aclass="docs-heading-anchor-permalink"href="#Passing-Runtime-Arguments-to-Documents-1"title="Permalink"></a></h2><p>You can pass arguments as <code>Dict</code> to the weaved document using the <code>args</code> argument to <code>weave</code>. The arguments will be available as <code>WEAVE_ARGS</code> variable in the document.</p><p>This makes it possible to create the same report easily for e.g. different date ranges of input data from a database or from files with similar format giving the filename as input.</p><p>In order to pass a filename to a document you need call <code>weave</code> using:</p><pre><codeclass="language-julia">weave("mydoc.jmd", args = Dict("filename" =>"somedata.h5"))</code></pre><p>and you can access the filename from document as follows:</p><pre><codeclass="language-none"> ```julia
print(WEAVE_ARGS["filename"])
```</code></pre><p>You can use the <code>out_path</code> argument to control the name of the output document.</p><h2id="include_weave-1"><aclass="docs-heading-anchor"href="#include_weave-1"><code>include_weave</code></a><aclass="docs-heading-anchor-permalink"href="#include_weave-1"title="Permalink"></a></h2><p>You can call <code>include_weave</code> on a Weave document and run all code chunks within in the current session.</p><articleclass="docstring"><header><aclass="docstring-binding"id="Weave.include_weave"href="#Weave.include_weave"><code>Weave.include_weave</code></a> — <spanclass="docstring-category">Function</span></header><section><div><pre><codeclass="language-julia">include_weave(source::AbstractString, informat::Union{Nothing,AbstractString} = nothing)
include_weave(m::Module, source::AbstractString, informat::Union{Nothing,AbstractString} = nothing)</code></pre><p>Include code from Weave document calling <code>include_string</code> on all code from doc. Code is run in the path of the include document.</p></div><aclass="docs-sourcelink"target="_blank"href="https://github.com/JunoLab/Weave.jl/blob/1972d03d1991b8535df0fbd26af674c9599b8ea5/src/Weave.jl#L284-L290">source</a></section></article></article><navclass="docs-footer"><aclass="docs-footer-prevpage"href="../getting_started/">« Getting started</a><aclass="docs-footer-nextpage"href="../publish/">Publishing to HTML and PDF »</a></nav></div><divclass="modal"id="documenter-settings"><divclass="modal-background"></div><divclass="modal-card"><headerclass="modal-card-head"><pclass="modal-card-title">Settings</p><buttonclass="delete"></button></header><sectionclass="modal-card-body"><p><labelclass="label">Theme</label><divclass="select"><selectid="documenter-themepicker"><optionvalue="documenter-light">documenter-light</option><optionvalue="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <ahref="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> on <spanclass="colophon-date"title="Saturday 30 May 2020 12:37">Saturday 30 May 2020</span>. Using Julia version 1.4.2.</p></section><footerclass="modal-card-foot"></footer></div></div></div></body></html>