You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
<!DOCTYPE html> |
|
|
<html lang="en"><head><meta charset="UTF-8"/><meta name="viewport" content="width=device-width, initial-scale=1.0"/><title>4. Output Formats · Literate.jl</title><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 href="../assets/custom.css" rel="stylesheet" type="text/css"/><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"><a class="docs-logo" href="../"><img src="../assets/logo.png" alt="Literate.jl logo"/></a><div class="docs-package-name"><span class="docs-autofit">Literate.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="../"><strong>1.</strong> Introduction</a></li><li><a class="tocitem" href="../fileformat/"><strong>2.</strong> File Format</a></li><li><a class="tocitem" href="../pipeline/"><strong>3.</strong> Processing pipeline</a></li><li class="is-active"><a class="tocitem" href><strong>4.</strong> Output Formats</a><ul class="internal"><li><a class="tocitem" href="#Markdown-Output-1"><span><strong>4.1.</strong> Markdown Output</span></a></li><li><a class="tocitem" href="#Notebook-Output-1"><span><strong>4.2.</strong> Notebook Output</span></a></li><li><a class="tocitem" href="#Script-Output-1"><span><strong>4.3.</strong> Script Output</span></a></li><li><a class="tocitem" href="#Configuration-1"><span><strong>4.4.</strong> Configuration</span></a></li></ul></li><li><a class="tocitem" href="../customprocessing/"><strong>5.</strong> Custom pre- and post-processing</a></li><li><a class="tocitem" href="../documenter/"><strong>6.</strong> Interaction with Documenter.jl</a></li><li><a class="tocitem" href="../generated/example/"><strong>7.</strong> Example</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><strong>4.</strong> Output Formats</a></li></ul><ul class="is-hidden-tablet"><li class="is-active"><a href><strong>4.</strong> Output Formats</a></li></ul></nav><div class="docs-right"><a class="docs-edit-link" href="https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/outputformats.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="Output-Formats-1"><a class="docs-heading-anchor" href="#Output-Formats-1"><strong>4.</strong> Output Formats</a><a class="docs-heading-anchor-permalink" href="#Output-Formats-1" title="Permalink"></a></h1><p>When the source is parsed, and have been processed it is time to render the output. We will consider the following source snippet:</p><pre><code class="language-julia"># # Rational numbers |
|
|
# |
|
|
# In julia rational numbers can be constructed with the `//` operator. |
|
|
# Lets define two rational numbers, `x` and `y`: |
|
|
|
|
|
x = 1//3 |
|
|
#- |
|
|
y = 2//5 |
|
|
|
|
|
# When adding `x` and `y` together we obtain a new rational number: |
|
|
|
|
|
z = x + y</code></pre><p>and see how this is rendered in each of the output formats.</p><h2 id="Markdown-Output-1"><a class="docs-heading-anchor" href="#Markdown-Output-1"><strong>4.1.</strong> Markdown Output</a><a class="docs-heading-anchor-permalink" href="#Markdown-Output-1" title="Permalink"></a></h2><p>Markdown output is generated by <a href="#Literate.markdown"><code>Literate.markdown</code></a>. The (default) markdown output of the source snippet above is as follows:</p><pre><code class="language-markdown">```@meta |
|
|
EditURL = "https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/outputformats.jl" |
|
|
``` |
|
|
|
|
|
# Rational numbers |
|
|
|
|
|
In julia rational numbers can be constructed with the `//` operator. |
|
|
Lets define two rational numbers, `x` and `y`: |
|
|
|
|
|
```@example name |
|
|
x = 1//3 |
|
|
``` |
|
|
|
|
|
```@example name |
|
|
y = 2//5 |
|
|
``` |
|
|
|
|
|
When adding `x` and `y` together we obtain a new rational number: |
|
|
|
|
|
```@example name |
|
|
z = x + y |
|
|
```</code></pre><p>We note that lines starting with <code>#</code> are printed as regular markdown, and the code lines have been wrapped in <code>@example</code> blocks. We also note that an <code>@meta</code> block have been added, that sets the <code>EditURL</code> variable. This is used by Documenter to redirect the "Edit on GitHub" link for the page, see <a href="../documenter/#Interaction-with-Documenter-1">Interaction with Documenter</a>.</p><p>See the section about <a href="#Configuration-1">Configuration</a> for how to configure the behavior and resulting output of <a href="#Literate.markdown"><code>Literate.markdown</code></a>.</p><article class="docstring"><header><a class="docstring-binding" id="Literate.markdown" href="#Literate.markdown"><code>Literate.markdown</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">Literate.markdown(inputfile, outputdir; config::Dict=Dict(), kwargs...)</code></pre><p>Generate a markdown file from <code>inputfile</code> and write the result to the directory <code>outputdir</code>.</p><p>See the manual section on <a href="#Configuration-1">Configuration</a> for documentation of possible configuration with <code>config</code> and other keyword arguments.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Literate.jl/blob/0f9e836d68f238becd3e193b22ebdad06e4d7ffa/src/Literate.jl#L350-L358">source</a></section></article><h2 id="Notebook-Output-1"><a class="docs-heading-anchor" href="#Notebook-Output-1"><strong>4.2.</strong> Notebook Output</a><a class="docs-heading-anchor-permalink" href="#Notebook-Output-1" title="Permalink"></a></h2><p>Notebook output is generated by <a href="#Literate.notebook"><code>Literate.notebook</code></a>. The (default) notebook output of the source snippet can be seen here: <a href="../generated/notebook.ipynb">notebook.ipynb</a>.</p><p>We note that lines starting with <code>#</code> are placed in markdown cells, and the code lines have been placed in code cells. By default the notebook is also executed and output cells populated. The current working directory is set to the specified output directory the notebook is executed.</p><p>See the section about <a href="#Configuration-1">Configuration</a> for how to configure the behavior and resulting output of <a href="#Literate.notebook"><code>Literate.notebook</code></a>.</p><article class="docstring"><header><a class="docstring-binding" id="Literate.notebook" href="#Literate.notebook"><code>Literate.notebook</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">Literate.notebook(inputfile, outputdir; config::Dict=Dict(), kwargs...)</code></pre><p>Generate a notebook from <code>inputfile</code> and write the result to <code>outputdir</code>.</p><p>See the manual section on <a href="#Configuration-1">Configuration</a> for documentation of possible configuration with <code>config</code> and other keyword arguments.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Literate.jl/blob/0f9e836d68f238becd3e193b22ebdad06e4d7ffa/src/Literate.jl#L463-L470">source</a></section></article><h3 id="Notebook-metadata-1"><a class="docs-heading-anchor" href="#Notebook-metadata-1">Notebook metadata</a><a class="docs-heading-anchor-permalink" href="#Notebook-metadata-1" title="Permalink"></a></h3><p>Jupyter notebook cells (both code cells and markdown cells) can contain metadata. This is enabled in Literate by the <code>%%</code> token, similar to <a href="https://jupytext.readthedocs.io/en/latest/formats.html#the-percent-format">Jupytext</a>. The format is as follows</p><pre><code class="language-none">%% optional ignored text [type] {optional metadata JSON}</code></pre><p>Cell metadata can, for example, be used for <a href="https://nbgrader.readthedocs.io/en/stable/contributor_guide/metadata.html">nbgrader</a> and the <a href="https://github.com/hakimel/reveal.js">reveal.js</a> notebook extension <a href="https://github.com/damianavila/RISE">RISE</a>.</p><h2 id="Script-Output-1"><a class="docs-heading-anchor" href="#Script-Output-1"><strong>4.3.</strong> Script Output</a><a class="docs-heading-anchor-permalink" href="#Script-Output-1" title="Permalink"></a></h2><p>Script output is generated by <a href="#Literate.script"><code>Literate.script</code></a>. The (default) script output of the source snippet above is as follows:</p><pre><code class="language-julia">x = 1//3 |
|
|
|
|
|
y = 2//5 |
|
|
|
|
|
z = x + y</code></pre><p>We note that lines starting with <code>#</code> are removed and only the code lines have been kept.</p><p>See the section about <a href="#Configuration-1">Configuration</a> for how to configure the behavior and resulting output of <a href="#Literate.script"><code>Literate.script</code></a>.</p><article class="docstring"><header><a class="docstring-binding" id="Literate.script" href="#Literate.script"><code>Literate.script</code></a> — <span class="docstring-category">Function</span></header><section><div><pre><code class="language-julia">Literate.script(inputfile, outputdir; config::Dict=Dict(), kwargs...)</code></pre><p>Generate a plain script file from <code>inputfile</code> and write the result to <code>outputdir</code>.</p><p>See the manual section on <a href="#Configuration-1">Configuration</a> for documentation of possible configuration with <code>config</code> and other keyword arguments.</p></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Literate.jl/blob/0f9e836d68f238becd3e193b22ebdad06e4d7ffa/src/Literate.jl#L291-L298">source</a></section></article><h2 id="Configuration-1"><a class="docs-heading-anchor" href="#Configuration-1"><strong>4.4.</strong> Configuration</a><a class="docs-heading-anchor-permalink" href="#Configuration-1" title="Permalink"></a></h2><p>The behavior of <a href="#Literate.markdown"><code>Literate.markdown</code></a>, <a href="#Literate.notebook"><code>Literate.notebook</code></a> and <a href="#Literate.script"><code>Literate.script</code></a> can be configured by keyword arguments. There are two ways to do this; pass <code>config::Dict</code> as a keyword argument, or pass individual keyword arguments.</p><div class="admonition is-info"><header class="admonition-header">Configuration precedence</header><div class="admonition-body"><p>Individual keyword arguments takes precedence over the <code>config</code> dictionary, so for e.g. <code>Literate.markdown(...; config = Dict("name" => "hello"), name = "world")</code> the resulting configuration for <code>name</code> will be <code>"world"</code>. Both individual keyword arguments and the <code>config</code> dictionary takes precedence over the default.</p></div></div><p>Available configurations with description and default values are given in the reference for <a href="#Literate.DEFAULT_CONFIGURATION"><code>Literate.DEFAULT_CONFIGURATION</code></a> just below.</p><article class="docstring"><header><a class="docstring-binding" id="Literate.DEFAULT_CONFIGURATION" href="#Literate.DEFAULT_CONFIGURATION"><code>Literate.DEFAULT_CONFIGURATION</code></a> — <span class="docstring-category">Constant</span></header><section><div><pre><code class="language-julia">DEFAULT_CONFIGURATION</code></pre><p>Default configuration for <a href="#Literate.markdown"><code>Literate.markdown</code></a>, <a href="#Literate.notebook"><code>Literate.notebook</code></a> and [<code>Literate.script</code>] which is used for everything not specified by the user. See the manual section about <a href="#Configuration-1">Configuration</a> for more information.</p><table><tr><th style="text-align: right">Configuration key</th><th style="text-align: left">Description</th><th style="text-align: left">Default value</th><th style="text-align: left">Comment</th></tr><tr><td style="text-align: right"><code>name</code></td><td style="text-align: left">Name of the output file (excluding file extension).</td><td style="text-align: left"><code>filename(inputfile)</code></td><td style="text-align: left"></td></tr><tr><td style="text-align: right"><code>preprocess</code></td><td style="text-align: left">Custom preprocessing function mapping <code>String</code> to <code>String</code>.</td><td style="text-align: left"><code>identity</code></td><td style="text-align: left">See <a href="../customprocessing/#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a>.</td></tr><tr><td style="text-align: right"><code>postprocess</code></td><td style="text-align: left">Custom preprocessing function mapping <code>String</code> to <code>String</code>.</td><td style="text-align: left"><code>identity</code></td><td style="text-align: left">See <a href="../customprocessing/#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a>.</td></tr><tr><td style="text-align: right"><code>documenter</code></td><td style="text-align: left">Boolean signaling that the source contains Documenter.jl elements.</td><td style="text-align: left"><code>true</code></td><td style="text-align: left">See <a href="../documenter/#Interaction-with-Documenter-1">Interaction with Documenter</a>.</td></tr><tr><td style="text-align: right"><code>credit</code></td><td style="text-align: left">Boolean for controlling the addition of <code>This file was generated with Literate.jl ...</code> to the bottom of the page. If you find Literate.jl useful then feel free to keep this.</td><td style="text-align: left"><code>true</code></td><td style="text-align: left"></td></tr><tr><td style="text-align: right"><code>keep_comments</code></td><td style="text-align: left">When <code>true</code>, keeps markdown lines as comments in the output script.</td><td style="text-align: left"><code>false</code></td><td style="text-align: left">Only applicable for <code>Literate.script</code>.</td></tr><tr><td style="text-align: right"><code>codefence</code></td><td style="text-align: left">Pair containing opening and closing fence for wrapping code blocks.</td><td style="text-align: left"><code>"```julia" => "```"</code></td><td style="text-align: left">If <code>documenter</code> is <code>true</code> the default is <code>"```@example"=>"```"</code>.</td></tr><tr><td style="text-align: right"><code>execute</code></td><td style="text-align: left">Whether to execute and capture the output.</td><td style="text-align: left"><code>true</code></td><td style="text-align: left">Only applicable for <code>Literate.notebook</code>.</td></tr></table></div><a class="docs-sourcelink" target="_blank" href="https://github.com/fredrikekre/Literate.jl/blob/0f9e836d68f238becd3e193b22ebdad06e4d7ffa/src/Literate.jl#L271-L288">source</a></section></article></article><nav class="docs-footer"><a class="docs-footer-prevpage" href="../pipeline/">« <strong>3.</strong> Processing pipeline</a><a class="docs-footer-nextpage" href="../customprocessing/"><strong>5.</strong> Custom pre- and post-processing »</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="Friday 22 November 2019 11:57">Friday 22 November 2019</span>. Using Julia version 1.2.0.</p></section><footer class="modal-card-foot"></footer></div></div></div></body></html>
|
|
|
|