Weave.jl/dev/chunk_options/index.html

14 lines
12 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<!DOCTYPE html>
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>Chunk Options · Weave.jl</title><link rel="canonical" href="http://weavejl.mpastell.com/stable/chunk_options/"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/fontawesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/solid.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/css/brands.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/KaTeX/0.11.1/katex.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.3.6/require.min.js" data-main="../assets/documenter.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-dark.css" data-theme-name="documenter-dark"/><link class="docs-theme-link" rel="stylesheet" type="text/css" href="../assets/themes/documenter-light.css" data-theme-name="documenter-light" data-theme-primary/><script src="../assets/themeswap.js"></script></head><body><div id="documenter"><nav class="docs-sidebar"><div class="docs-package-name"><span class="docs-autofit">Weave.jl</span></div><form class="docs-search" action="../search/"><input class="docs-search-query" id="documenter-search-query" name="q" type="text" placeholder="Search docs"/></form><ul class="docs-menu"><li><a class="tocitem" href="../">Weave.jl - Scientific Reports Using Julia</a></li><li><a class="tocitem" href="../getting_started/">Getting started</a></li><li><a class="tocitem" href="../usage/">Using Weave</a></li><li><a class="tocitem" href="../publish/">Publishing to HTML and PDF</a></li><li class="is-active"><a class="tocitem" href>Chunk Options</a><ul class="internal"><li><a class="tocitem" href="#Syntax-1"><span>Syntax</span></a></li><li><a class="tocitem" href="#Weave-Chunk-Options-1"><span>Weave Chunk Options</span></a></li><li><a class="tocitem" href="#Default-Chunk-Options-1"><span>Default Chunk Options</span></a></li></ul></li><li><a class="tocitem" href="../header/">Header Configuration</a></li><li><a class="tocitem" href="../notebooks/">Working with Jupyter notebooks</a></li><li><a class="tocitem" href="../function_index/">Function index</a></li></ul><div class="docs-version-selector field has-addons"><div class="control"><span class="docs-label button is-static is-size-7">Version</span></div><div class="docs-selector control is-expanded"><div class="select is-fullwidth is-size-7"><select id="documenter-version-selector"></select></div></div></div></nav><div class="docs-main"><header class="docs-navbar"><nav class="breadcrumb"><ul class="is-hidden-mobile"><li class="is-active"><a href>Chunk Options</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href>Chunk Options</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/JunoLab/Weave.jl/blob/master/doc/src/chunk_options.md" title="Edit on GitHub"><span class="docs-icon fab"></span><span class="docs-label is-hidden-touch">Edit on GitHub</span></a><a class="docs-settings-button fas fa-cog" id="documenter-settings-button" href="#" title="Settings"></a><a class="docs-sidebar-button fa fa-bars is-hidden-desktop" id="documenter-sidebar-button" href="#"></a></div></header><article class="content" id="documenter-page"><h1 id="chunk-options-1"><a class="docs-heading-anchor" href="#chunk-options-1">Chunk Options</a><a class="docs-heading-anchor-permalink" href="#chunk-options-1" title="Permalink"></a></h1><p>You can use chunk options to configure how each chunk is evaluated, rendered, etc. Most of the ideas came from <a href="http://yihui.name/knitr/options">chunk options in RMarkdown</a>.</p><h2 id="Syntax-1"><a class="docs-heading-anchor" href="#Syntax-1">Syntax</a><a class="docs-heading-anchor-permalink" href="#Syntax-1" title="Permalink"></a></h2><p>Chunk options come after <a href="../usage/#code-chunks-1">code chunk</a> header. There are two (slightly) different syntax to write them:</p><ul><li>(Julia&#39;s toplevel expression) options are separated by semicolon (<code>;</code>)</li><li>(RMarkdown style) options are separated by comma (<code>,</code>)</li></ul><p>Let&#39;s take a look at examples. All the following code chunk header are valid, and so configured to hide the source code from generated output (<code>echo = false</code>) and displays figures with 12cm width (<code>out_width = &quot;12cm&quot;</code>):</p><pre><code class="language-md"> ```julia; echo = false; out_width = &quot;12cm&quot;
```{julia; echo = false; out_width = &quot;12cm&quot;}
```julia, echo = false, out_width = &quot;12cm&quot;
```{julia, echo = false, out_width = &quot;12cm&quot;}</code></pre><h2 id="Weave-Chunk-Options-1"><a class="docs-heading-anchor" href="#Weave-Chunk-Options-1">Weave Chunk Options</a><a class="docs-heading-anchor-permalink" href="#Weave-Chunk-Options-1" title="Permalink"></a></h2><p>Weave currently supports the following chunk options: we&#39;ve mostly followed <a href="http://yihui.name/knitr/options">RMarkdown&#39;s namings</a>, but not all options are implemented.</p><h3 id="Evaluation-1"><a class="docs-heading-anchor" href="#Evaluation-1">Evaluation</a><a class="docs-heading-anchor-permalink" href="#Evaluation-1" title="Permalink"></a></h3><ul><li><code>eval = true</code>: Evaluate the code chunk. If <code>false</code> the chunk wont be executed.</li><li><code>error = true</code>: If <code>true</code> <a href="../usage/#Weave.weave"><code>weave</code></a> won&#39;t stop on errors and rather they will be included in output document. If <code>false</code>, <a href="../usage/#Weave.weave"><code>weave</code></a> will halt on any of un-caught errors.</li><li><code>cache = false</code>: Cache results, depending on <code>cache</code> parameter on <a href="../usage/#Weave.weave"><code>weave</code></a> function.</li><li><code>tangle = true</code>: Set tangle to <code>false</code> to exclude chunk from tangled code.</li></ul><h3 id="Rendering-1"><a class="docs-heading-anchor" href="#Rendering-1">Rendering</a><a class="docs-heading-anchor-permalink" href="#Rendering-1" title="Permalink"></a></h3><ul><li><code>echo = true</code>: Echo the code in the output document. If <code>false</code> the source code will be hidden.</li><li><code>results = &quot;markup&quot;</code>: The output format of the printed results. <code>&quot;markup&quot;</code> for literal block, <code>&quot;hidden&quot;</code> for hidden results, or anything else for raw output (I tend to use <code>&quot;tex&quot;</code> for Latex and <code>&quot;rst&quot;</code> for rest). Raw output is useful if you want to e.g. create tables from code chunks.</li><li><code>term = false</code>: If <code>true</code> the output emulates a REPL session. Otherwise only stdout and figures will be included in output.</li><li><code>wrap = true</code>: Wrap long lines from output.</li><li><code>line_width = 75</code>: Line width for wrapped lines.</li><li><code>hold = false</code>: Hold all results until the end of the chunk.</li></ul><h3 id="Figures-1"><a class="docs-heading-anchor" href="#Figures-1">Figures</a><a class="docs-heading-anchor-permalink" href="#Figures-1" title="Permalink"></a></h3><ul><li><code>label = nothing</code>: Chunk label, will be used for figure labels in Latex as <code>fig:label</code>.</li><li><code>fig_width = 6</code>: Figure width passed to plotting library.</li><li><code>fig_height = 4</code>: Figure height passed to plotting library.</li><li><code>out_width</code>: Width of saved figure in output markup e.g. <code>&quot;50%&quot;</code>, <code>&quot;12cm&quot;</code>, <code>0.5\linewidth</code></li><li><code>out_height</code>: Height of saved figure in output markup</li><li><code>dpi = 96</code>: Resolution of saved figures.</li><li><code>fig_cap</code>: Figure caption.</li><li><code>fig_ext</code>: File extension (format) of saved figures.</li><li><code>fig_pos = &quot;!h&quot;</code>: Figure position in Latex, e.g.: <code>&quot;ht&quot;</code>.</li><li><code>fig_env = &quot;figure&quot;</code>: Figure environment in Latex.</li></ul><h2 id="Default-Chunk-Options-1"><a class="docs-heading-anchor" href="#Default-Chunk-Options-1">Default Chunk Options</a><a class="docs-heading-anchor-permalink" href="#Default-Chunk-Options-1" title="Permalink"></a></h2><p>You can set the default chunk options (and <code>weave</code> arguments) for a document using <code>weave_options</code> key in YAML <a href="../header/#Header-Configuration-1">Header Configuration</a>. E.g. to set the default <code>out_width</code> of all figures you can use:</p><pre><code class="language-yaml">---
weave_options:
out_width : 50%
---</code></pre><p>You can also set or change the default chunk options for a document either before weave using the <code>set_chunk_defaults</code> function.</p><article class="docstring"><header><a class="docstring-binding" id="Weave.set_chunk_defaults!" href="#Weave.set_chunk_defaults!"><code>Weave.set_chunk_defaults!</code></a><span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">set_chunk_defaults!(k::Symbol, v::Any) = DEFAULT_PARAMS[k]= v
set_chunk_defaults!(kv::Pair{Symbol,Any}...) = for (k,v) in kv; set_chunk_defaults!(k, v); end
set_chunk_defaults!(opts::AbstractDict{Symbol,Any}) = merge!(DEFAULT_PARAMS, opts)</code></pre><p>Set default options for code chunks, use <a href="#Weave.get_chunk_defaults"><code>get_chunk_defaults</code></a> to see the current values.</p><p>E.g.: all the three examples below will set default <code>dpi</code> to <code>200</code> and <code>fig_width</code> to <code>8</code>:</p><ul><li><code>set_chunk_defaults!(:dpi, 200); set_chunk_defaults!(:fig_width, 8)</code></li><li><code>set_chunk_defaults!(:dpi =&gt; 200, :fig_width =&gt; 8)</code></li><li><code>set_chunk_defaults!(Dict(:dpi =&gt; 200, :fig_width =&gt; 8))</code></li></ul></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JunoLab/Weave.jl/blob/dadce5110c72f29066c251425db008ef88feba18/src/config.jl#L30-L41">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Weave.get_chunk_defaults" href="#Weave.get_chunk_defaults"><code>Weave.get_chunk_defaults</code></a><span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">get_chunk_defaults()</code></pre><p>Get default options used for code chunks.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JunoLab/Weave.jl/blob/dadce5110c72f29066c251425db008ef88feba18/src/config.jl#L46-L50">source</a></section></article><article class="docstring"><header><a class="docstring-binding" id="Weave.restore_chunk_defaults!" href="#Weave.restore_chunk_defaults!"><code>Weave.restore_chunk_defaults!</code></a><span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">restore_chunk_defaults!()</code></pre><p>Restore Weave.jl default chunk options.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/JunoLab/Weave.jl/blob/dadce5110c72f29066c251425db008ef88feba18/src/config.jl#L53-L57">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../publish/">« Publishing to HTML and PDF</a><a class="docs-footer-nextpage" href="../header/">Header Configuration »</a></nav></div><div class="modal" id="documenter-settings"><div class="modal-background"></div><div class="modal-card"><header class="modal-card-head"><p class="modal-card-title">Settings</p><button class="delete"></button></header><section class="modal-card-body"><p><label class="label">Theme</label><div class="select"><select id="documenter-themepicker"><option value="documenter-light">documenter-light</option><option value="documenter-dark">documenter-dark</option></select></div></p><hr/><p>This document was generated with <a href="https://github.com/JuliaDocs/Documenter.jl">Documenter.jl</a> on <span class="colophon-date" title="Saturday 13 June 2020 17:06">Saturday 13 June 2020</span>. Using Julia version 1.4.2.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>