<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>5. Custom pre- and post-processing · Examples.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL="."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="assets/documenter.js"></script><scriptsrc="siteinfo.js"></script><scriptsrc="../versions.js"></script><linkhref="assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Examples.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="index.html"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="fileformat.html"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="outputformats.html"><strong>4.</strong> Output formats</a></li><liclass="current"><aclass="toctext"href="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a><ulclass="internal"></ul></li><li><aclass="toctext"href="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><li><aclass="toctext"href="generated/example.html"><strong>7.</strong> Example</a></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Examples.jl/blob/master/docs/src/customprocessing.md"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>5. Custom pre- and post-processing</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="Custom-pre-and-post-processing-1"href="#Custom-pre-and-post-processing-1"><strong>5.</strong> Custom pre- and post-processing</a></h1><p>Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing <ahref="fileformat.html#Filtering-lines-1">line filtering</a> there might be situations where you need to manually hook into the generation and change things. In <code>Examples.jl</code> this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.</p><p>All of the generators (<ahref="outputformats.html#Examples.markdown"><code>Examples.markdown</code></a>, <ahref="outputformats.html#Examples.notebook"><code>Examples.notebook</code></a> and <ahref="outputformats.html#Examples.script"><code>Examples.script</code></a>) accepts <code>preprocess</code> and <code>postprocess</code> keyword arguments. The default "transformation" is the <code>identity</code> function. The input to the transformation functions is a <code>String</code>, and the output should be the transformed <code>String</code>.</p><p><code>preprocess</code> is sent the raw input that is read from the source file (<ahref="pipeline.html#Pre-processing-1">modulo the default line ending transformation</a>). <code>postprocess</code> is given different things depending on the output: For markdown and script output <code>postprocess</code> is given the content <code>String</code> just before writing it to the output file, but for notebook output <code>postprocess</code> is given the dictionary representing the notebook, since, in general, this is more useful.</p><p>As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a <code>preprocess</code> function that splices the date into the source for us. Consider the following source file:</p><pre><codeclass="language-julia">#' # Example
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>5. Custom pre- and post-processing · Literate.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL="."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="assets/documenter.js"></script><scriptsrc="siteinfo.js"></script><scriptsrc="../versions.js"></script><linkhref="assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Literate.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="index.html"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="fileformat.html"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="outputformats.html"><strong>4.</strong> Output Formats</a></li><liclass="current"><aclass="toctext"href="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a><ulclass="internal"></ul></li><li><aclass="toctext"href="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><li><aclass="toctext"href="generated/example.html"><strong>7.</strong> Example</a></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/customprocessing.md"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>5. Custom pre- and post-processing</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="Custom-pre-and-post-processing-1"href="#Custom-pre-and-post-processing-1"><strong>5.</strong> Custom pre- and post-processing</a></h1><p>Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing <ahref="fileformat.html#Filtering-Lines-1">line filtering</a> there might be situations where you need to manually hook into the generation and change things. In Literate this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.</p><p>All of the generators (<ahref="outputformats.html#Literate.markdown"><code>Literate.markdown</code></a>, <ahref="outputformats.html#Literate.notebook"><code>Literate.notebook</code></a> and <ahref="outputformats.html#Literate.script"><code>Literate.script</code></a>) accepts <code>preprocess</code> and <code>postprocess</code> keyword arguments. The default "transformation" is the <code>identity</code> function. The input to the transformation functions is a <code>String</code>, and the output should be the transformed <code>String</code>.</p><p><code>preprocess</code> is sent the raw input that is read from the source file (<ahref="pipeline.html#Pre-processing-1">modulo the default line ending transformation</a>). <code>postprocess</code> is given different things depending on the output: For markdown and script output <code>postprocess</code> is given the content <code>String</code> just before writing it to the output file, but for notebook output <code>postprocess</code> is given the dictionary representing the notebook, since, in general, this is more useful.</p><p>As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a <code>preprocess</code> function that splices the date into the source for us. Consider the following source file:</p><pre><codeclass="language-julia">#' # Example
#' This example was generated DATEOFTODAY
#' This example was generated DATEOFTODAY
x = 1 // 3</code></pre><p>where <code>DATEOFTODAY</code> is a placeholder, to make it easier for our <code>preprocess</code> function to find the location. Now, lets define the <code>preprocess</code> function, for example</p><pre><codeclass="language-julia">function update_date(content)
x = 1 // 3</code></pre><p>where <code>DATEOFTODAY</code> is a placeholder, to make it easier for our <code>preprocess</code> function to find the location. Now, lets define the <code>preprocess</code> function, for example</p><pre><codeclass="language-julia">function update_date(content)
end</code></pre><p>which would replace every occurrence of <code>"DATEOFTODAY"</code> with the current date. We would now simply give this function to the generator, for example:</p><pre><codeclass="language-julia">Examples.markdown("input.jl", "outputdir"; preprocess = update_date)</code></pre><footer><hr/><aclass="previous"href="outputformats.html"><spanclass="direction">Previous</span><spanclass="title"><strong>4.</strong> Output formats</span></a><aclass="next"href="documenter.html"><spanclass="direction">Next</span><spanclass="title"><strong>6.</strong> Interaction with Documenter.jl</span></a></footer></article></body></html>
end</code></pre><p>which would replace every occurrence of <code>"DATEOFTODAY"</code> with the current date. We would now simply give this function to the generator, for example:</p><pre><codeclass="language-julia">Literate.markdown("input.jl", "outputdir"; preprocess = update_date)</code></pre><footer><hr/><aclass="previous"href="outputformats.html"><spanclass="direction">Previous</span><spanclass="title"><strong>4.</strong> Output Formats</span></a><aclass="next"href="documenter.html"><spanclass="direction">Next</span><spanclass="title"><strong>6.</strong> Interaction with Documenter.jl</span></a></footer></article></body></html>
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>6. Interaction with Documenter.jl · Examples.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL="."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="assets/documenter.js"></script><scriptsrc="siteinfo.js"></script><scriptsrc="../versions.js"></script><linkhref="assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Examples.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="index.html"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="fileformat.html"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="outputformats.html"><strong>4.</strong> Output formats</a></li><li><aclass="toctext"href="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><liclass="current"><aclass="toctext"href="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a><ulclass="internal"></ul></li><li><aclass="toctext"href="generated/example.html"><strong>7.</strong> Example</a></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Examples.jl/blob/master/docs/src/documenter.md"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>6. Interaction with Documenter.jl</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="Interaction-with-Documenter-1"href="#Interaction-with-Documenter-1"><strong>6.</strong> Interaction with Documenter.jl</a></h1><p><code>Examples.jl</code> can be used for any purpose, it spits out regular markdown files, and notebooks. Typically, though, these files will be used to render documentation for your package. The generators (<ahref="outputformats.html#Examples.markdown"><code>Examples.markdown</code></a>, <ahref="outputformats.html#Examples.notebook"><code>Examples.notebook</code></a> and <ahref="outputformats.html#Examples.script"><code>Examples.script</code></a>) supports a keyword argument <code>documenter</code> that lets the generator perform some extra things, keeping in mind that the generated files will, eventually, be used with Documenter.jl. So lets take a look at what will happen if we set <code>documenter = true</code>:</p><p><ahref="outputformats.html#Examples.markdown"><code>Examples.markdown</code></a>:</p><ul><li>The default code fence will change from<pre><codeclass="language-none">```julia
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>6. Interaction with Documenter.jl · Literate.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL="."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="assets/documenter.js"></script><scriptsrc="siteinfo.js"></script><scriptsrc="../versions.js"></script><linkhref="assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Literate.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="index.html"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="fileformat.html"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="outputformats.html"><strong>4.</strong> Output Formats</a></li><li><aclass="toctext"href="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><liclass="current"><aclass="toctext"href="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a><ulclass="internal"></ul></li><li><aclass="toctext"href="generated/example.html"><strong>7.</strong> Example</a></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/documenter.md"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>6. Interaction with Documenter.jl</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="Interaction-with-Documenter-1"href="#Interaction-with-Documenter-1"><strong>6.</strong> Interaction with Documenter.jl</a></h1><p>Literate can be used for any purpose, it spits out regular markdown files, and notebooks. Typically, though, these files will be used to render documentation for your package. The generators (<ahref="outputformats.html#Literate.markdown"><code>Literate.markdown</code></a>, <ahref="outputformats.html#Literate.notebook"><code>Literate.notebook</code></a> and <ahref="outputformats.html#Literate.script"><code>Literate.script</code></a>) supports a keyword argument <code>documenter</code> that lets the generator perform some extra things, keeping in mind that the source code have been written with Documenter.jl in mind. So lets take a look at what will happen if we set <code>documenter = true</code>:</p><h3><aclass="nav-anchor"id="[Literate.markdown](@ref):-1"href="#[Literate.markdown](@ref):-1"><ahref="outputformats.html#Literate.markdown"><code>Literate.markdown</code></a>:</a></h3><ul><li><p>The default code fence will change from</p><pre><codeclass="language-none">```julia
```</code></pre></li><li>The following <code>@meta</code> block will be added to the top of the markdown page, which redirects the "Edit on GitHub" link on the top of the page to the <em>source file</em> rather than the generated <code>.md</code> file:<pre><codeclass="language-none">```@meta
```</code></pre></li><li><p>The following <code>@meta</code> block will be added to the top of the markdown page, which redirects the "Edit on GitHub" link on the top of the page to the <em>source file</em> rather than the generated <code>.md</code> file:</p><pre><codeclass="language-none">```@meta
```</code></pre></li></ul><p><ahref="outputformats.html#Examples.notebook"><code>Examples.notebook</code></a>:</p><ul><li>Documenter style <code>@ref</code>s and <code>@id</code> will be removed. This means that you can use <code>@ref</code> and <code>@id</code> in the source file without them leaking to the notebook.</li><li>Documenter style markdown math<pre><codeclass="language-none">```math
```</code></pre></li></ul><h3><aclass="nav-anchor"id="[Literate.notebook](@ref):-1"href="#[Literate.notebook](@ref):-1"><ahref="outputformats.html#Literate.notebook"><code>Literate.notebook</code></a>:</a></h3><ul><li><p>Documenter style <code>@ref</code>s and <code>@id</code> will be removed. This means that you can use <code>@ref</code> and <code>@id</code> in the source file without them leaking to the notebook.</p></li><li><p>Documenter style markdown math</p><pre><codeclass="language-none">```math
\int f dx
\int f dx
```</code></pre>is replaced with notebook compatible<pre><codeclass="language-none">\begin{equation}
```</code></pre><p>is replaced with notebook compatible</p><pre><codeclass="language-none">\begin{equation}
\int f dx
\int f dx
\end{equation}</code></pre></li></ul><footer><hr/><aclass="previous"href="customprocessing.html"><spanclass="direction">Previous</span><spanclass="title"><strong>5.</strong> Custom pre- and post-processing</span></a><aclass="next"href="generated/example.html"><spanclass="direction">Next</span><spanclass="title"><strong>7.</strong> Example</span></a></footer></article></body></html>
\end{equation}</code></pre></li></ul><h3><aclass="nav-anchor"id="[Literate.script](@ref):-1"href="#[Literate.script](@ref):-1"><ahref="outputformats.html#Literate.script"><code>Literate.script</code></a>:</a></h3><ul><li><p>Documenter style <code>@ref</code>s and <code>@id</code> will be removed. This means that you can use <code>@ref</code> and <code>@id</code> in the source file without them leaking to the script.</p></li></ul><footer><hr/><aclass="previous"href="customprocessing.html"><spanclass="direction">Previous</span><spanclass="title"><strong>5.</strong> Custom pre- and post-processing</span></a><aclass="next"href="generated/example.html"><spanclass="direction">Next</span><spanclass="title"><strong>7.</strong> Example</span></a></footer></article></body></html>
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>2. File Format · Examples.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL="."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="assets/documenter.js"></script><scriptsrc="siteinfo.js"></script><scriptsrc="../versions.js"></script><linkhref="assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Examples.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="index.html"><strong>1.</strong> Introduction</a></li><liclass="current"><aclass="toctext"href="fileformat.html"><strong>2.</strong> File Format</a><ulclass="internal"><li><aclass="toctext"href="#Syntax-1"><strong>2.1.</strong> Syntax</a></li><li><aclass="toctext"href="#Filtering-lines-1"><strong>2.2.</strong> Filtering Lines</a></li></ul></li><li><aclass="toctext"href="pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="outputformats.html"><strong>4.</strong> Output formats</a></li><li><aclass="toctext"href="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><li><aclass="toctext"href="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><li><aclass="toctext"href="generated/example.html"><strong>7.</strong> Example</a></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="fileformat.html"><strong>2.</strong> File Format</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Examples.jl/blob/master/docs/src/fileformat.md"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>2. File Format</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="**2.**-File-Format-1"href="#**2.**-File-Format-1"><strong>2.</strong> File Format</a></h1><p>The source file format for <code>Examples.jl</code> is a regular, commented, julia (<code>.jl</code>) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. <code>include</code>, to make sure the examples stay up do date with other changes in your package.</p><h2><aclass="nav-anchor"id="Syntax-1"href="#Syntax-1"><strong>2.1.</strong> Syntax</a></h2><p>The basic syntax is simple:</p><ul><li>lines starting with <code>#'</code> is treated as markdown,</li><li>all other lines are treated as julia code.</li></ul><p>The reason for using <code>#'</code> instead of <code>#</code> is that we want to be able to use <code>#</code> as comments, just as in a regular script. Lets look at a simple example:</p><pre><codeclass="language-julia">#' # Rational numbers
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>2. File Format · Literate.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL="."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="assets/documenter.js"></script><scriptsrc="siteinfo.js"></script><scriptsrc="../versions.js"></script><linkhref="assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Literate.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="index.html"><strong>1.</strong> Introduction</a></li><liclass="current"><aclass="toctext"href="fileformat.html"><strong>2.</strong> File Format</a><ulclass="internal"><li><aclass="toctext"href="#Syntax-1"><strong>2.1.</strong> Syntax</a></li><li><aclass="toctext"href="#Filtering-Lines-1"><strong>2.2.</strong> Filtering Lines</a></li><li><aclass="toctext"href="#Default-Replacements-1"><strong>2.3.</strong> Default Replacements</a></li></ul></li><li><aclass="toctext"href="pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="outputformats.html"><strong>4.</strong> Output Formats</a></li><li><aclass="toctext"href="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><li><aclass="toctext"href="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><li><aclass="toctext"href="generated/example.html"><strong>7.</strong> Example</a></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="fileformat.html"><strong>2.</strong> File Format</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/fileformat.md"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>2. File Format</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="**2.**-File-Format-1"href="#**2.**-File-Format-1"><strong>2.</strong> File Format</a></h1><p>The source file format for Literate is a regular, commented, julia (<code>.jl</code>) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. <code>include</code>, to make sure the examples stay up do date with other changes in your package.</p><h2><aclass="nav-anchor"id="Syntax-1"href="#Syntax-1"><strong>2.1.</strong> Syntax</a></h2><p>The basic syntax is simple:</p><ul><li><p>lines starting with <code>#'</code> is treated as markdown,</p></li><li><p>all other lines are treated as julia code.</p></li></ul><p>The reason for using <code>#'</code> instead of <code>#</code> is that we want to be able to use <code>#</code> as comments, just as in a regular script. Lets look at a simple example:</p><pre><codeclass="language-julia">#' # Rational numbers
#'
#'
#' In julia rational numbers can be constructed with the `//` operator.
#' In julia rational numbers can be constructed with the `//` operator.
#' Lets define two rational numbers, `x` and `y`:
#' Lets define two rational numbers, `x` and `y`:
@ -9,39 +9,8 @@ y = 2//5
#' When adding `x` and `y` together we obtain a new rational number:
#' When adding `x` and `y` together we obtain a new rational number:
z = x + y</code></pre><p>In the lines <code>#'</code> we can use regular markdown syntax, for example the <code>#</code> used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:</p><ul><li>The script is valid julia, which means that we can <code>include</code> it and the example will run</li><li>The script is "self-explanatory", i.e. the markdown lines works as comments and thus serve as good documentation on its own.</li></ul><p>For simple use this is all you need to know, the script above is valid. Let's take a look at what the above snippet would generate, with default settings:</p><ul><li><p><ahref="outputformats.html#Examples.markdown"><code>Examples.markdown</code></a>: leading <code>#'</code> are removed, and code lines are wrapped in <code>@example</code>-blocks:</p><pre><codeclass="language-markdown"># Rational numbers
z = x + y</code></pre><p>In the lines <code>#'</code> we can use regular markdown syntax, for example the <code>#</code> used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:</p><ul><li><p>The script is valid julia, which means that we can <code>include</code> it and the example will run (for example in the <code>test/runtests.jl</code> script, to include the example in the test suite).</p></li><li><p>The script is "self-explanatory", i.e. the markdown lines works as comments and thus serve as good documentation on its own.</p></li></ul><p>For simple use this is all you need to know. The following additional special syntax can also be used:</p><ul><li><p><code>#md</code>, <code>#nb</code>, <code>#jl</code>: tags for filtering of lines, see <ahref="fileformat.html#Filtering-Lines-1">Filtering Lines</a>.</p></li><li><p><code>#-</code>: tag for manually controlling chunk-splits, see <ahref="pipeline.html#Custom-control-over-chunk-splits-1">Custom control over chunk splits</a>.</p></li></ul><p>There is also some default convenience replacements that will always be performed, see <ahref="fileformat.html#Default-Replacements-1">Default Replacements</a>.</p><h2><aclass="nav-anchor"id="Filtering-Lines-1"href="#Filtering-Lines-1"><strong>2.2.</strong> Filtering Lines</a></h2><p>It is possible to filter out lines depending on the output format. For this purpose, there are three different "tokens" that can be placed on the start of the line:</p><ul><li><p><code>#md</code>: markdown output only,</p></li><li><p><code>#nb</code>: notebook output only,</p></li><li><p><code>#jl</code>: script output only.</p></li></ul><p>Lines starting with one of these tokens are filtered out in the <ahref="pipeline.html#Pre-processing-1">preprocessing step</a>.</p><p>Suppose, for example, that we want to include a docstring within a <code>@docs</code> block using Documenter. Obviously we don't want to include this in the notebook, since <code>@docs</code> is Documenter syntax that the notebook will not understand. This is a case where we can prepend <code>#md</code> to those lines:</p><pre><codeclass="language-julia">#md #' ```@docs
#md #' Literate.markdown
In julia rational numbers can be constructed with the `//` operator.
#md #' Literate.notebook
Lets define two rational numbers, `x` and `y`:
#md #' Literate.markdown
#md #' ```</code></pre><p>The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading <code>#md</code> from the lines. Beware that the space after the tag is also removed.</p><h2><aclass="nav-anchor"id="Default-Replacements-1"href="#Default-Replacements-1"><strong>2.3.</strong> Default Replacements</a></h2><p>The following convenience "macros" are always expanded:</p><ul><li><p><code>@__NAME__</code></p><p>expands to the <code>name</code> keyword argument to <ahref="outputformats.html#Literate.markdown"><code>Literate.markdown</code></a>, <ahref="outputformats.html#Literate.notebook"><code>Literate.notebook</code></a> and <ahref="outputformats.html#Literate.script"><code>Literate.script</code></a> (defaults to the filename of the input file).</p></li><li><p><code>@__REPO__ROOT_URL__</code></p><p>expands to <code>https://github.com/$(ENV["TRAVIS_REPO_SLUG"])/blob/master/</code> and is a convenient way to use when you want to link to files outside the doc-build directory. For example <code>@__REPO__ROOT_URL__src/Literate.jl</code> would link to the source of the Literate module.</p></li><li><p><code>@__NBVIEWER_ROOT_URL__</code></p><p>expands to <code>https://nbviewer.jupyter.org/github/$(ENV["TRAVIS_REPO_SLUG"])/blob/gh-pages/$(folder)/</code> where <code>folder</code> is the folder that <code>Documenter.deploydocs</code> deploys too. This can be used if you want a link that opens the generated notebook in <ahref="http://nbviewer.jupyter.org/">http://nbviewer.jupyter.org/</a>.</p></li></ul><footer><hr/><aclass="previous"href="index.html"><spanclass="direction">Previous</span><spanclass="title"><strong>1.</strong> Introduction</span></a><aclass="next"href="pipeline.html"><spanclass="direction">Next</span><spanclass="title"><strong>3.</strong> Processing pipeline</span></a></footer></article></body></html>
```@example filename
x = 1//3
y = 2//5
```
When adding `x` and `y` together we obtain a new rational number:
```@example filename
z = x + y
```</code></pre></li><li><p><ahref="outputformats.html#Examples.notebook"><code>Examples.notebook</code></a>: leading <code>#'</code> are removed, markdown lines are placed in <code>"markdown"</code> cells, and code lines in <code>"code"</code> cells:</p><pre><codeclass="language-none"> │ # Rational numbers
│
│ In julia rational numbers can be constructed with the `//` operator.
│ Lets define two rational numbers, `x` and `y`:
In [1]: │ x = 1//3
│ y = 2//5
Out [1]: │ 2//5
│ When adding `x` and `y` together we obtain a new rational number:
In [2]: │ z = x + y
Out [2]: │ 11//15</code></pre></li><li><p><ahref="outputformats.html#Examples.script"><code>Examples.script</code></a>: all lines starting with <code>#'</code> are removed:</p><pre><codeclass="language-julia">x = 1//3
y = 2//5
z = x + y</code></pre></li></ul><h2><aclass="nav-anchor"id="Filtering-lines-1"href="#Filtering-lines-1"><strong>2.2.</strong> Filtering Lines</a></h2><p>It is possible to filter out lines depending on the output format. For this purpose, there are three different "tokens" that can be placed on the start of the line:</p><ul><li><code>#md</code>: markdown output only,</li><li><code>#nb</code>: notebook output only,</li><li><code>#jl</code>: script output only.</li></ul><p>Lines starting with one of these tokens are filtered out in the <ahref="pipeline.html#Pre-processing-1">preprocessing step</a>.</p><p>Suppose, for example, that we want to include a docstring within a <code>@docs</code> block using Documenter. Obviously we don't want to include this in the notebook, since <code>@docs</code> is Documenter syntax that the notebook will not understand. This is a case where we can prepend <code>#md</code> to those lines:</p><pre><codeclass="language-julia">#md #' ```@docs
#md #' Examples.markdown
#md #' Examples.notebook
#md #' Examples.markdown
#md #' ```</code></pre><p>The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading <code>#md</code> from the lines. Beware that the space after the tag is also removed.</p><footer><hr/><aclass="previous"href="index.html"><spanclass="direction">Previous</span><spanclass="title"><strong>1.</strong> Introduction</span></a><aclass="next"href="pipeline.html"><spanclass="direction">Next</span><spanclass="title"><strong>3.</strong> Processing pipeline</span></a></footer></article></body></html>
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>7. Example · Examples.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL=".."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="../assets/documenter.js"></script><scriptsrc="../siteinfo.js"></script><scriptsrc="../../versions.js"></script><linkhref="../assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Examples.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="../search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="../index.html"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="../fileformat.html"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="../pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="../outputformats.html"><strong>4.</strong> Output formats</a></li><li><aclass="toctext"href="../customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><li><aclass="toctext"href="../documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><liclass="current"><aclass="toctext"href="example.html"><strong>7.</strong> Example</a><ulclass="internal"></ul></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="example.html"><strong>7.</strong> Example</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Examples.jl/blob/master/examples/example.jl"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>7. Example</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="**7.**-Example-1"href="#**7.**-Example-1"><strong>7.</strong> Example</a></h1><p>This is an example for Examples.jl. The source file can be found<ahref="https://github.com/fredrikekre/Examples.jl/blob/master/examples/example.jl">here</a>. The generated markdown can be found here: <ahref="example.html"><code>example.md</code></a>, the generated notebook can be found here: <ahref="https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/latest/generated/example.ipynb"><code>example.ipynb</code></a>, and the plain script output can be found here: <ahref="example.jl"><code>example.jl</code></a>.</p><h3><aclass="nav-anchor"id="Rational-numbers-in-Julia-1"href="#Rational-numbers-in-Julia-1">Rational numbers in Julia</a></h3><p>Rational number in julia can be constructed with the<code>//</code>operator:</p><div><pre><codeclass="language-julia">x = 1//3
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>7. Example · Literate.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL=".."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="../assets/documenter.js"></script><scriptsrc="../siteinfo.js"></script><scriptsrc="../../versions.js"></script><linkhref="../assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Literate.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="../search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="../index.html"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="../fileformat.html"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="../pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="../outputformats.html"><strong>4.</strong> Output Formats</a></li><li><aclass="toctext"href="../customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><li><aclass="toctext"href="../documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><liclass="current"><aclass="toctext"href="example.html"><strong>7.</strong> Example</a><ulclass="internal"></ul></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="example.html"><strong>7.</strong> Example</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Literate.jl/blob/master/examples/example.jl"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>7. Example</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="**7.**-Example-1"href="#**7.**-Example-1"><strong>7.</strong> Example</a></h1><p>This is an example generated with Literate based on this source file:<ahref="https://github.com/fredrikekre/Literate.jl/blob/master/examples/example.jl"><code>example.jl</code></a>. You are seeing the html-output which Documenter have generated based on a markdown file generated with Literate. The corresponding notebook can be found here: <ahref="https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/latest/generated/example.ipynb"><code>example.ipynb</code></a>, and the plain script output can be found here: <ahref="example.jl"><code>example.jl</code></a>.</p><p>It is recommended to have the <ahref="https://github.com/fredrikekre/Literate.jl/blob/master/examples/example.jl">source file</a> available when reading this, to better understand how the syntax in the source file corresponds to the output you are seeing.</p><h3><aclass="nav-anchor"id="Basic-syntax-1"href="#Basic-syntax-1">Basic syntax</a></h3><p>The basic syntax for Literate is simple, lines starting with<code>#'</code>is interpreted as markdown, and all the other lines are interpreted as code. Here is some code:</p><div><pre><codeclass="language-julia">x = 1//3
y = 2//5</code></pre><pre><codeclass="language-none">2//5</code></pre></div><p>Operations with rational number returns a new rational number</p><div><pre><codeclass="language-julia">x + y</code></pre><pre><codeclass="language-none">11//15</code></pre></div><div><pre><codeclass="language-julia">x * y</code></pre><pre><codeclass="language-none">2//15</code></pre></div><p>Everytime a rational number is constructed, it will be simplified using the <code>gcd</code> function, for example<code>2//4</code>simplifies to<code>1//2</code>:</p><div><pre><codeclass="language-julia">2//4</code></pre><pre><codeclass="language-none">1//2</code></pre></div><p>and <code>2//4 + 2//4</code> simplifies to <code>1//1</code>:</p><div><pre><codeclass="language-julia">2//4 + 2//4</code></pre><pre><codeclass="language-none">1//1</code></pre></div><footer><hr/><aclass="previous"href="../documenter.html"><spanclass="direction">Previous</span><spanclass="title"><strong>6.</strong> Interaction with Documenter.jl</span></a></footer></article></body></html>
y = 2//5</code></pre><pre><codeclass="language-none">2//5</code></pre></div><p>In markdown sections we can use markdown syntax. For example, we can write <em>text in italic font</em>, <strong>text in bold font</strong> and use <ahref="https://www.youtube.com/watch?v=dQw4w9WgXcQ">links</a>.</p><p>It is possible to filter lines by starting it with <code>#md</code>, <code>#nb</code> or <code>#jl</code> for markdown, notebook and script output only, respectively. This line is filtered out for notebook and script output.</p><p>The source file is parsed in chunks of markdown and code. Starting a line with <code>#-</code> manually inserts a chunk break. For example, if we want to display the output of the following operations we may insert <code>#-</code> in between. These two code blocks will now end up in different <code>@example</code>-blocks in the markdown output, and two different notebook cells in the notebook output.</p><div><pre><codeclass="language-julia">x + y</code></pre><pre><codeclass="language-none">11//15</code></pre></div><div><pre><codeclass="language-julia">x * y</code></pre><pre><codeclass="language-none">2//15</code></pre></div><h3><aclass="nav-anchor"id="Custom-processing-1"href="#Custom-processing-1">Custom processing</a></h3><p>It is possible to give Literate custom pre- and post-processing functions. For example, here we insert two placeholders, which we will replace with something else at time of generation. We have here replaced our placeholders with<code>z</code>and<code>1.0 + 2.0im</code>:</p><div><pre><codeclass="language-julia">z = 1.0 + 2.0im</code></pre><pre><codeclass="language-none">1.0 + 2.0im</code></pre></div><h3><aclass="nav-anchor"id="documenter-interaction-1"href="#documenter-interaction-1">Documenter.jl interaction</a></h3><p>In the source file it is possible to use Documenter.jl style references, such as <code>@ref</code> and <code>@id</code>. These will be filtered out in the notebook output. For example, <ahref="example.html#documenter-interaction-1">here is a link</a>, but it is only visible as a link if you are reading the markdown output. We can also use equations:</p><div>\[\int f(x) dx\]</div><p>using Documenters math syntax. This is automatically changed to <code>\begin{equation} ... \end{equation}</code> in the notebook output to display correctly in the notebook too.</p><footer><hr/><aclass="previous"href="../documenter.html"><spanclass="direction">Previous</span><spanclass="title"><strong>6.</strong> Interaction with Documenter.jl</span></a></footer></article></body></html>
<htmllang="en"><head><metacharset="UTF-8"/><metaname="viewport"content="width=device-width, initial-scale=1.0"/><title>4. Output Formats · Literate.jl</title><linkhref="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css"rel="stylesheet"type="text/css"/><linkhref="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css"rel="stylesheet"type="text/css"/><linkhref="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css"rel="stylesheet"type="text/css"/><script>documenterBaseURL="."</script><scriptsrc="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"data-main="assets/documenter.js"></script><scriptsrc="siteinfo.js"></script><scriptsrc="../versions.js"></script><linkhref="assets/documenter.css"rel="stylesheet"type="text/css"/></head><body><navclass="toc"><h1>Literate.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="search.html"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="index.html"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="fileformat.html"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="pipeline.html"><strong>3.</strong> Processing pipeline</a></li><liclass="current"><aclass="toctext"href="outputformats.html"><strong>4.</strong> Output Formats</a><ulclass="internal"><li><aclass="toctext"href="#Markdown-Output-1"><strong>4.1.</strong> Markdown Output</a></li><li><aclass="toctext"href="#Notebook-Output-1"><strong>4.2.</strong> Notebook Output</a></li><li><aclass="toctext"href="#Script-Output-1"><strong>4.3.</strong> Script Output</a></li></ul></li><li><aclass="toctext"href="customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><li><aclass="toctext"href="documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><li><aclass="toctext"href="generated/example.html"><strong>7.</strong> Example</a></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref="outputformats.html"><strong>4.</strong> Output Formats</a></li></ul><aclass="edit-page"href="https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/outputformats.md"><spanclass="fa"></span> Edit on GitHub</a></nav><hr/><divid="topbar"><span>4. Output Formats</span><aclass="fa fa-bars"href="#"></a></div></header><h1><aclass="nav-anchor"id="Output-Formats-1"href="#Output-Formats-1"><strong>4.</strong> Output Formats</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><codeclass="language-julia">#' # Rational numbers
#' │
#'
#'This line is treated as markdown, since it starts with #' │
#'In julia rational numbers can be constructed with the `//` operator.
#'The leading #' (including the space) is removed ┘
#'Lets define two rational numbers, `x` and `y`:
#' Here is an example with some code ]
x = 1//3
#-
y = 2//5
x = sin.(cos.([1, 2, 3])) ┐
#' When adding `x` and `y` together we obtain a new rational number:
y = x.^2 - x ┘</code></pre><p>By default, <code>CodeChunks</code> written to Documenter <code>@example</code> blocks. For example, the code above would result in the following markdown:</p><pre><codeclass="language-markdown"># Markdown
This line is treated as markdown, since it starts with #'
z = x + y</code></pre><p>and see how this is rendered in each of the output formats.</p><h2><aclass="nav-anchor"id="Markdown-Output-1"href="#Markdown-Output-1"><strong>4.1.</strong> Markdown Output</a></h2><p>The (default) markdown output of the source snippet above is as follows</p><pre><codeclass="language-markdown"># Rational numbers
The leading #' (including the space) is removed
Here is an example with some code
In julia rational numbers can be constructed with the `//` operator.
Lets define two rational numbers, `x` and `y`:
```@example
```@example name
x = sin.(cos.([1, 2, 3]))
x = 1//3
y = x.^2 - x
```
```</code></pre><sectionclass="docstring"><divclass="docstring-header"><aclass="docstring-binding"id="Examples.markdown"href="#Examples.markdown"><code>Examples.markdown</code></a> — <spanclass="docstring-category">Function</span>.</div><div><div><pre><codeclass="language-none">Examples.markdown(inputfile, outputdir; kwargs...)</code></pre><p>Generate a markdown file from <code>inputfile</code> and write the result to the directory<code>outputdir</code>.</p><p>Keyword arguments:</p><ul><li><code>name</code>: name of the output file, excluding <code>.md</code>. <code>name</code> is also used to name all the <code>@example</code> blocks. Defaults to the filename of <code>inputfile</code>.</li><li><code>preprocess</code>, <code>postprocess</code>: custom pre- and post-processing functions, see the <ahref="customprocessing.html#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a> section of the manual. Defaults to <code>identity</code>.</li><li><code>documenter</code>: boolean that tells if the output is intended to use with Documenter.jl. Defaults to <code>true</code>. See the the manual section on <ahref="documenter.html#Interaction-with-Documenter-1">Interaction with Documenter</a>.</li><li><code>codefence</code>: A <code>Pair</code> of opening and closing code fence. Defaults to<pre><codeclass="language-none">"```@example $(name)" =>"```"</code></pre>if <code>documenter = true</code> and<pre><codeclass="language-none">"```julia" =>"```"</code></pre>if <code>documenter = false</code>.</li></ul></div></div><aclass="source-link"target="_blank"href="https://github.com/fredrikekre/Examples.jl/blob/f68b0f8ffaf19d6fa7fdb29b9d4ac5ca2c49b8de/src/Examples.jl#L162-L186">source</a></section><h2><aclass="nav-anchor"id="Notebook-output-1"href="#Notebook-output-1"><strong>4.2.</strong> Notebook output</a></h2><sectionclass="docstring"><divclass="docstring-header"><aclass="docstring-binding"id="Examples.notebook"href="#Examples.notebook"><code>Examples.notebook</code></a> — <spanclass="docstring-category">Function</span>.</div><div><div><pre><codeclass="language-none">Examples.notebook(inputfile, outputdir; kwargs...)</code></pre><p>Generate a notebook from <code>inputfile</code> and write the result to <code>outputdir</code>.</p><p>Keyword arguments:</p><ul><li><code>name</code>: name of the output file, excluding <code>.ipynb</code>. Defaults to the filename of <code>inputfile</code>.</li><li><code>preprocess</code>, <code>postprocess</code>: custom pre- and post-processing functions, see the <ahref="customprocessing.html#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a> section of the manual. Defaults to <code>identity</code>.</li><li><code>execute</code>: a boolean deciding if the generated notebook should also be executed or not. Defaults to <code>true</code>.</li><li><code>documenter</code>: boolean that says if the source contains Documenter.jl specific things to filter out during notebook generation. Defaults to <code>true</code>. See the the manual section on <ahref="documenter.html#Interaction-with-Documenter-1">Interaction with Documenter</a>.</li></ul></div></div><aclass="source-link"target="_blank"href="https://github.com/fredrikekre/Examples.jl/blob/f68b0f8ffaf19d6fa7fdb29b9d4ac5ca2c49b8de/src/Examples.jl#L272-L288">source</a></section><h2><aclass="nav-anchor"id="Script-output-1"href="#Script-output-1"><strong>4.3.</strong> Script output</a></h2><sectionclass="docstring"><divclass="docstring-header"><aclass="docstring-binding"id="Examples.script"href="#Examples.script"><code>Examples.script</code></a> — <spanclass="docstring-category">Function</span>.</div><div><div><pre><codeclass="language-none">Examples.script(inputfile, outputdir; kwargs...)</code></pre><p>Generate a plain script file from <code>inputfile</code> and write the result to <code>outputdir</code>.</p><p>Keyword arguments:</p><ul><li><code>name</code>: name of the output file, excluding <code>.jl</code>. Defaults to the filename of <code>inputfile</code>.</li><li><code>preprocess</code>, <code>postprocess</code>: custom pre- and post-processing functions, see the <ahref="customprocessing.html#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a> section of the manual. Defaults to <code>identity</code>.</li></ul></div></div><aclass="source-link"target="_blank"href="https://github.com/fredrikekre/Examples.jl/blob/f68b0f8ffaf19d6fa7fdb29b9d4ac5ca2c49b8de/src/Examples.jl#L94-L105">source</a></section><footer><hr/><aclass="previous"href="pipeline.html"><spanclass="direction">Previous</span><spanclass="title"><strong>3.</strong> Processing pipeline</span></a><aclass="next"href="customprocessing.html"><spanclass="direction">Next</span><spanclass="title"><strong>5.</strong> Custom pre- and post-processing</span></a></footer></article></body></html>
```@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> is printed as regular markdown, and the code lines have been wrapped in <code>@example</code> blocks.</p><p>Some of the output rendering can be controlled with keyword arguments to <ahref="outputformats.html#Literate.markdown"><code>Literate.markdown</code></a>:</p><sectionclass="docstring"><divclass="docstring-header"><aclass="docstring-binding"id="Literate.markdown"href="#Literate.markdown"><code>Literate.markdown</code></a> — <spanclass="docstring-category">Function</span>.</div><div><pre><codeclass="language-none">Literate.markdown(inputfile, outputdir; kwargs...)</code></pre><p>Generate a markdown file from <code>inputfile</code> and write the result to the directory<code>outputdir</code>.</p><p>Keyword arguments:</p><ul><li><p><code>name</code>: name of the output file, excluding <code>.md</code>. <code>name</code> is also used to name all the <code>@example</code> blocks, and to replace <code>@__NAME__</code>. Defaults to the filename of <code>inputfile</code>.</p></li><li><p><code>preprocess</code>, <code>postprocess</code>: custom pre- and post-processing functions, see the <ahref="customprocessing.html#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a> section of the manual. Defaults to <code>identity</code>.</p></li><li><p><code>documenter</code>: boolean that tells if the output is intended to use with Documenter.jl. Defaults to <code>true</code>. See the the manual section on <ahref="documenter.html#Interaction-with-Documenter-1">Interaction with Documenter</a>.</p></li><li><p><code>codefence</code>: A <code>Pair</code> of opening and closing code fence. Defaults to</p><pre><codeclass="language-none">"```@example $(name)" =>"```"</code></pre><p>if <code>documenter = true</code> and</p><pre><codeclass="language-none">"```julia" =>"```"</code></pre><p>if <code>documenter = false</code>.</p></li></ul></div><aclass="source-link"target="_blank"href="https://github.com/fredrikekre/Literate.jl/blob/dedf3afa64480da84a1cebad823970205882c525/src/Literate.jl#L221-L246">source</a></section><h2><aclass="nav-anchor"id="Notebook-Output-1"href="#Notebook-Output-1"><strong>4.2.</strong> Notebook Output</a></h2><p>The (default) notebook output of the source snippet above is as follows</p><pre><codeclass="language-none"> │ # Rational numbers
│
│ In julia rational numbers can be constructed with the `//` operator.
│ Lets define two rational numbers, `x` and `y`:
In[1]: │ x = 1//3
Out[1]: │ 1//3
In[2]: │ y = 2//5
Out[2]: │ 2//5
│ When adding `x` and `y` together we obtain a new rational number:
In[3]: │ z = x + y
Out[3]: │ 11/15</code></pre><p>We note that lines starting with <code>#'</code> is put in markdown cells, and the code lines have been put in code cells. By default the notebook is also executed and output cells populated. Some of the output rendering can be controlled with keyword arguments to <ahref="outputformats.html#Literate.notebook"><code>Literate.notebook</code></a>:</p><sectionclass="docstring"><divclass="docstring-header"><aclass="docstring-binding"id="Literate.notebook"href="#Literate.notebook"><code>Literate.notebook</code></a> — <spanclass="docstring-category">Function</span>.</div><div><pre><codeclass="language-none">Literate.notebook(inputfile, outputdir; kwargs...)</code></pre><p>Generate a notebook from <code>inputfile</code> and write the result to <code>outputdir</code>.</p><p>Keyword arguments:</p><ul><li><p><code>name</code>: name of the output file, excluding <code>.ipynb</code>. <code>name</code> is also used to replace <code>@__NAME__</code>. Defaults to the filename of <code>inputfile</code>.</p></li><li><p><code>preprocess</code>, <code>postprocess</code>: custom pre- and post-processing functions, see the <ahref="customprocessing.html#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a> section of the manual. Defaults to <code>identity</code>.</p></li><li><p><code>execute</code>: a boolean deciding if the generated notebook should also be executed or not. Defaults to <code>true</code>.</p></li><li><p><code>documenter</code>: boolean that says if the source contains Documenter.jl specific things to filter out during notebook generation. Defaults to <code>true</code>. See the the manual section on <ahref="documenter.html#Interaction-with-Documenter-1">Interaction with Documenter</a>.</p></li></ul></div><aclass="source-link"target="_blank"href="https://github.com/fredrikekre/Literate.jl/blob/dedf3afa64480da84a1cebad823970205882c525/src/Literate.jl#L317-L333">source</a></section><h2><aclass="nav-anchor"id="Script-Output-1"href="#Script-Output-1"><strong>4.3.</strong> Script Output</a></h2><p>The (default) script output of the source snippet above is as follows</p><pre><codeclass="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. Some of the output rendering can be controlled with keyword arguments to <ahref="outputformats.html#Literate.script"><code>Literate.script</code></a>:</p><sectionclass="docstring"><divclass="docstring-header"><aclass="docstring-binding"id="Literate.script"href="#Literate.script"><code>Literate.script</code></a> — <spanclass="docstring-category">Function</span>.</div><div><pre><codeclass="language-none">Literate.script(inputfile, outputdir; kwargs...)</code></pre><p>Generate a plain script file from <code>inputfile</code> and write the result to <code>outputdir</code>.</p><p>Keyword arguments:</p><ul><li><p><code>name</code>: name of the output file, excluding <code>.jl</code>. <code>name</code> is also used to replace <code>@__NAME__</code>. Defaults to the filename of <code>inputfile</code>.</p></li><li><p><code>preprocess</code>, <code>postprocess</code>: custom pre- and post-processing functions, see the <ahref="customprocessing.html#Custom-pre-and-post-processing-1">Custom pre- and post-processing</a> section of the manual. Defaults to <code>identity</code>.</p></li><li><p><code>documenter</code>: boolean that says if the source contains Documenter.jl specific things to filter out during script generation. Defaults to <code>true</code>. See the the manual section on <ahref="documenter.html#Interaction-with-Documenter-1">Interaction with Documenter</a>.</p></li></ul></div><aclass="source-link"target="_blank"href="https://github.com/fredrikekre/Literate.jl/blob/dedf3afa64480da84a1cebad823970205882c525/src/Literate.jl#L165-L179">source</a></section><footer><hr/><aclass="previous"href="pipeline.html"><spanclass="direction">Previous</span><spanclass="title"><strong>3.</strong> Processing pipeline</span></a><aclass="next"href="customprocessing.html"><spanclass="direction">Next</span><spanclass="title"><strong>5.</strong> Custom pre- and post-processing</span></a></footer></article></body></html>
@ -13,7 +13,7 @@ var documenterSearchIndex = {"docs": [
"page":"1. Introduction",
"page":"1. Introduction",
"title":"1. Introduction",
"title":"1. Introduction",
"category":"section",
"category":"section",
"text":"Welcome to the documentation for Examples.jl. A simplistic package to help you organize examples for you package documentation."
"text":"Welcome to the documentation for Literate – a simplistic package for Literate Programming."
},
},
{
{
@ -21,7 +21,7 @@ var documenterSearchIndex = {"docs": [
"page":"1. Introduction",
"page":"1. Introduction",
"title":"What?",
"title":"What?",
"category":"section",
"category":"section",
"text":"Examples.jl is a package that, based on a single source file, generates markdown, for e.g. Documenter.jl, Jupyter notebooks and uncommented scripts for documentation of your package.The main design goal is simplicity. It should be simple to use, and the syntax should be simple. In short all you have to do is to write a commented julia script!The package consists mainly of three functions, which all takes the same script file as input, but generates different output:Examples.markdown: generates a markdown file\nExamples.notebook: generates an (optionally executed) notebook\nExamples.script: generates a plain script file, removing everything that is not code"
"text":"Literate is a package that generate markdown pages (for e.g. Documenter.jl), and Jupyter notebooks, from the same source file. There is also an option to \"clean\" the source from all metadata, and produce a pure Julia script.The main design goal is simplicity. It should be simple to use, and the syntax should be simple. In short, all you have to do is to write a commented julia script!The public interface consists mainly of three functions, which all takes the same script file as input, but generates different output:Literate.markdown: generates a markdown file\nLiterate.notebook: generates an (optionally executed) notebook\nLiterate.script: generates a plain script file, removing all metadata and special syntax."
},
},
{
{
@ -29,15 +29,7 @@ var documenterSearchIndex = {"docs": [
"page":"1. Introduction",
"page":"1. Introduction",
"title":"Why?",
"title":"Why?",
"category":"section",
"category":"section",
"text":"Examples are (probably) the best way to showcase your awesome package, and examples are often the best way for a new user to learn how to use it. It is therefore important that the documentation of your package contains examples for users to read and study. However, people are different, and we all prefer different ways of trying out a new package. Some people wants to RTFM, others want to explore the package interactively in, for example, a notebook, and some people wants to study the source code. The aim of Examples.jl is to make it easy to give the user all of these options, while still keeping maintenance to a minimum.It is quite common that packages have \"example notebooks\" to showcase the package. Notebooks are great for this, but they are not so great with version control, like git. The reason is that a notebook is a very \"rich\" format since it contains output and other metadata. Changes to the notebook thus result in large diffs, which makes it harder to review the actual changes.It is also common that packages include examples in the documentation, for example by using Documenter.jl @example-blocks. This is also great, but it is not quite as interactive as a notebook, for the users who prefer that.Examples.jl tries to solve the problems above by creating the output as a part of the doc build. Examples.jl generates the output from a single source file which makes it easier to maintain, test, and keep the manual and your example notebooks in sync."
"text":"Examples are (probably) the best way to showcase your awesome package, and examples are often the best way for a new user to learn how to use it. It is therefore important that the documentation of your package contains examples for users to read and study. However, people are different, and we all prefer different ways of trying out a new package. Some people wants to RTFM, others want to explore the package interactively in, for example, a notebook, and some people wants to study the source code. The aim of Literate is to make it easy to give the user all of these options, while still keeping maintenance to a minimum.It is quite common that packages have \"example notebooks\" to showcase the package. Notebooks are great for showcasing a package, but they are not so great with version control, like git. The reason being that a notebook is a very \"rich\" format since it contains output and other metadata. Changes to the notebook thus result in large diffs, which makes it harder to review the actual changes.It is also common that packages include examples in the documentation, for example by using Documenter.jl @example-blocks. This is also great, but it is not quite as interactive as a notebook, for the users who prefer that.Literate tries to solve the problems above by creating the output as a part of the doc build. Literate generates the output based on a single source file which makes it easier to maintain, test, and keep the manual and your example notebooks in sync."
},
{
"location":"index.html#How?-1",
"page":"1. Introduction",
"title":"How?",
"category":"section",
"text":"TBD"
},
},
{
{
@ -53,7 +45,7 @@ var documenterSearchIndex = {"docs": [
"page":"2. File Format",
"page":"2. File Format",
"title":"2. File Format",
"title":"2. File Format",
"category":"section",
"category":"section",
"text":"The source file format for Examples.jl is a regular, commented, julia (.jl) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. include, to make sure the examples stay up do date with other changes in your package."
"text":"The source file format for Literate is a regular, commented, julia (.jl) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. include, to make sure the examples stay up do date with other changes in your package."
},
},
{
{
@ -61,15 +53,23 @@ var documenterSearchIndex = {"docs": [
"page":"2. File Format",
"page":"2. File Format",
"title":"2.1. Syntax",
"title":"2.1. Syntax",
"category":"section",
"category":"section",
"text":"The basic syntax is simple:lines starting with #\' is treated as markdown,\nall other lines are treated as julia code.The reason for using #\' instead of # is that we want to be able to use # as comments, just as in a regular script. Lets look at a simple example:#\' # Rational numbers\n#\'\n#\' In julia rational numbers can be constructed with the `//` operator.\n#\' Lets define two rational numbers, `x` and `y`:\n\nx = 1//3\ny = 2//5\n\n#\' When adding `x` and `y` together we obtain a new rational number:\n\nz = x + yIn the lines #\' we can use regular markdown syntax, for example the # used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:The script is valid julia, which means that we can include it and the example will run\nThe script is \"self-explanatory\", i.e. the markdown lines works as comments and thus serve as good documentation on its own.For simple use this is all you need to know, the script above is valid. Let\'s take a look at what the above snippet would generate, with default settings:Examples.markdown: leading #\' are removed, and code lines are wrapped in @example-blocks:\n# Rational numbers\n\nIn julia rational numbers can be constructed with the `//` operator.\nLets define two rational numbers, `x` and `y`:\n\n```@example filename\nx = 1//3\ny = 2//5\n```\n\nWhen adding `x` and `y` together we obtain a new rational number:\n\n```@example filename\nz = x + y\n```\nExamples.notebook: leading #\' are removed, markdown lines are placed in \"markdown\" cells, and code lines in \"code\" cells:\n │ # Rational numbers\n │\n │ In julia rational numbers can be constructed with the `//` operator.\n │ Lets define two rational numbers, `x` and `y`:\n\nIn [1]: │ x = 1//3\n │ y = 2//5\n\nOut [1]: │ 2//5\n\n │ When adding `x` and `y` together we obtain a new rational number:\n\nIn [2]: │ z = x + y\n\nOut [2]: │ 11//15\nExamples.script: all lines starting with #\' are removed:\nx = 1//3\ny = 2//5\n\nz = x + y"
"text":"The basic syntax is simple:lines starting with #\' is treated as markdown,\nall other lines are treated as julia code.The reason for using #\' instead of # is that we want to be able to use # as comments, just as in a regular script. Lets look at a simple example:#\' # Rational numbers\n#\'\n#\' In julia rational numbers can be constructed with the `//` operator.\n#\' Lets define two rational numbers, `x` and `y`:\n\nx = 1//3\ny = 2//5\n\n#\' When adding `x` and `y` together we obtain a new rational number:\n\nz = x + yIn the lines #\' we can use regular markdown syntax, for example the # used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:The script is valid julia, which means that we can include it and the example will run (for example in the test/runtests.jl script, to include the example in the test suite).\nThe script is \"self-explanatory\", i.e. the markdown lines works as comments and thus serve as good documentation on its own.For simple use this is all you need to know. The following additional special syntax can also be used:#md, #nb, #jl: tags for filtering of lines, see Filtering Lines.\n#-: tag for manually controlling chunk-splits, see Custom control over chunk splits.There is also some default convenience replacements that will always be performed, see Default Replacements."
},
},
{
{
"location":"fileformat.html#Filtering-lines-1",
"location":"fileformat.html#Filtering-Lines-1",
"page":"2. File Format",
"page":"2. File Format",
"title":"2.2. Filtering Lines",
"title":"2.2. Filtering Lines",
"category":"section",
"category":"section",
"text":"It is possible to filter out lines depending on the output format. For this purpose, there are three different \"tokens\" that can be placed on the start of the line:#md: markdown output only,\n#nb: notebook output only,\n#jl: script output only.Lines starting with one of these tokens are filtered out in the preprocessing step.Suppose, for example, that we want to include a docstring within a @docs block using Documenter. Obviously we don\'t want to include this in the notebook, since @docs is Documenter syntax that the notebook will not understand. This is a case where we can prepend #md to those lines:#md #\' ```@docs\n#md #\' Examples.markdown\n#md #\' Examples.notebook\n#md #\' Examples.markdown\n#md #\' ```The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading #md from the lines. Beware that the space after the tag is also removed."
"text":"It is possible to filter out lines depending on the output format. For this purpose, there are three different \"tokens\" that can be placed on the start of the line:#md: markdown output only,\n#nb: notebook output only,\n#jl: script output only.Lines starting with one of these tokens are filtered out in the preprocessing step.Suppose, for example, that we want to include a docstring within a @docs block using Documenter. Obviously we don\'t want to include this in the notebook, since @docs is Documenter syntax that the notebook will not understand. This is a case where we can prepend #md to those lines:#md #\' ```@docs\n#md #\' Literate.markdown\n#md #\' Literate.notebook\n#md #\' Literate.markdown\n#md #\' ```The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading #md from the lines. Beware that the space after the tag is also removed."
"text":"The following convenience \"macros\" are always expanded:@__NAME__\nexpands to the name keyword argument to Literate.markdown, Literate.notebook and Literate.script (defaults to the filename of the input file).\n@__REPO__ROOT_URL__\nexpands to https://github.com/$(ENV[\"TRAVIS_REPO_SLUG\"])/blob/master/ and is a convenient way to use when you want to link to files outside the doc-build directory. For example @__REPO__ROOT_URL__src/Literate.jl would link to the source of the Literate module.\n@__NBVIEWER_ROOT_URL__\nexpands to https://nbviewer.jupyter.org/github/$(ENV[\"TRAVIS_REPO_SLUG\"])/blob/gh-pages/$(folder)/ where folder is the folder that Documenter.deploydocs deploys too. This can be used if you want a link that opens the generated notebook in http://nbviewer.jupyter.org/."
},
},
{
{
@ -93,7 +93,7 @@ var documenterSearchIndex = {"docs": [
"page":"3. Processing pipeline",
"page":"3. Processing pipeline",
"title":"3.1. Pre-processing",
"title":"3.1. Pre-processing",
"category":"section",
"category":"section",
"text":"The first step is pre-processing of the input file. The file is read to a String and CRLF style line endings (\"\\r\\n\") are replaced with LF line endings (\"\\n\") to simplify internal processing. The next step is to apply the user specified pre-processing function. See Custom pre- and post-processing.Next the line filtering is performed, see Filtering lines, meaning that lines starting with #md, #nb or #jl are handled (either just the token itself is removed, or the full line, depending on the output target)."
"text":"The first step is pre-processing of the input file. The file is read to a String. The first processing step is to apply the user specified pre-processing function, see Custom pre- and post-processing.The next step is to perform all of the built-in default replacements. CRLF style line endings (\"\\r\\n\") are replaced with LF line endings (\"\\n\") to simplify internal processing. Next, line filtering is performed, see Filtering Lines, meaning that lines starting with #md, #nb or #jl are handled (either just the token itself is removed, or the full line, depending on the output target). The last pre-processing step is to expand the convenience \"macros\" described in Default Replacements is expanded."
},
},
{
{
@ -117,7 +117,7 @@ var documenterSearchIndex = {"docs": [
"page":"3. Processing pipeline",
"page":"3. Processing pipeline",
"title":"3.3. Document generation",
"title":"3.3. Document generation",
"category":"section",
"category":"section",
"text":"After the parsing it is time to generate the output. What is done in this step is very different depending on the output target, and it is describe in more detail in the Output format sections: Markdown output, Notebook output and Script output. In short, the following is happening:Markdown output: markdown chunks are printed as-is, code chunks are put inside a code fence (defaults to @example-blocks),\nNotebook output: markdown chunks are printed in markdown cells, code chunks are put in code cells,\nScript output: markdown chunks are discarded, code chunks are printed as-is."
"text":"After the parsing it is time to generate the output. What is done in this step is very different depending on the output target, and it is describe in more detail in the Output format sections: Markdown Output, Notebook Output and Script Output. In short, the following is happening:Markdown output: markdown chunks are printed as-is, code chunks are put inside a code fence (defaults to @example-blocks),\nNotebook output: markdown chunks are printed in markdown cells, code chunks are put in code cells,\nScript output: markdown chunks are discarded, code chunks are printed as-is."
},
},
{
{
@ -138,66 +138,66 @@ var documenterSearchIndex = {"docs": [
{
{
"location":"outputformats.html#",
"location":"outputformats.html#",
"page":"4. Output formats",
"page":"4. Output Formats",
"title":"4. Output formats",
"title":"4. Output Formats",
"category":"page",
"category":"page",
"text":""
"text":""
},
},
{
{
"location":"outputformats.html#Output-formats-1",
"location":"outputformats.html#Output-Formats-1",
"page":"4. Output formats",
"page":"4. Output Formats",
"title":"4. Output formats",
"title":"4. Output Formats",
"category":"section",
"category":"section",
"text":""
"text":"When the source is parsed, and have been processed it is time to render the output. We will consider the following source snippet:#\' # Rational numbers\n#\'\n#\' In julia rational numbers can be constructed with the `//` operator.\n#\' Lets define two rational numbers, `x` and `y`:\n\nx = 1//3\n#-\ny = 2//5\n\n#\' When adding `x` and `y` together we obtain a new rational number:\n\nz = x + yand see how this is rendered in each of the output formats."
"text":"Examples.markdown(inputfile, outputdir; kwargs...)\n\nGenerate a markdown file from inputfile and write the result to the directoryoutputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .md. name is also used to name all the @example blocks. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\ndocumenter: boolean that tells if the output is intended to use with Documenter.jl. Defaults to true. See the the manual section on Interaction with Documenter.\ncodefence: A Pair of opening and closing code fence. Defaults to\n\"```@example $(name)\" => \"```\"\nif documenter = true and\n\"```julia\" => \"```\"\nif documenter = false.\n\n\n\n\n\n"
"text":"Literate.markdown(inputfile, outputdir; kwargs...)\n\nGenerate a markdown file from inputfile and write the result to the directoryoutputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .md. name is also used to name all the @example blocks, and to replace @__NAME__. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\ndocumenter: boolean that tells if the output is intended to use with Documenter.jl. Defaults to true. See the the manual section on Interaction with Documenter.\ncodefence: A Pair of opening and closing code fence. Defaults to\n\"```@example $(name)\" => \"```\"\nif documenter = true and\n\"```julia\" => \"```\"\nif documenter = false.\n\n\n\n"
"text":"#\' # Markdown ┐\n#\' │\n#\' This line is treated as markdown, since it starts with #\' │\n#\' The leading #\' (including the space) is removed ┘\n\n#\' Here is an example with some code ]\n\nx = sin.(cos.([1, 2, 3])) ┐\ny = x.^2 - x ┘By default, CodeChunks written to Documenter @example blocks. For example, the code above would result in the following markdown:# Markdown\n\nThis line is treated as markdown, since it starts with #\'\nThe leading #\' (including the space) is removed\n\nHere is an example with some code\n\n```@example\nx = sin.(cos.([1, 2, 3]))\ny = x.^2 - x\n```Examples.markdown"
"text":"The (default) markdown output of the source snippet above is as follows# Rational numbers\n\nIn julia rational numbers can be constructed with the `//` operator.\nLets define two rational numbers, `x` and `y`:\n\n```@example name\nx = 1//3\n```\n\n```@example name\ny = 2//5\n```\n\nWhen adding `x` and `y` together we obtain a new rational number:\n\n```@example name\nz = x + y\n```We note that lines starting with #\' is printed as regular markdown, and the code lines have been wrapped in @example blocks.Some of the output rendering can be controlled with keyword arguments to Literate.markdown:Literate.markdown"
"text":"Examples.notebook(inputfile, outputdir; kwargs...)\n\nGenerate a notebook from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .ipynb. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\nexecute: a boolean deciding if the generated notebook should also be executed or not. Defaults to true.\ndocumenter: boolean that says if the source contains Documenter.jl specific things to filter out during notebook generation. Defaults to true. See the the manual section on Interaction with Documenter.\n\n\n\n\n\n"
"text":"Literate.notebook(inputfile, outputdir; kwargs...)\n\nGenerate a notebook from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .ipynb. name is also used to replace @__NAME__. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\nexecute: a boolean deciding if the generated notebook should also be executed or not. Defaults to true.\ndocumenter: boolean that says if the source contains Documenter.jl specific things to filter out during notebook generation. Defaults to true. See the the manual section on Interaction with Documenter.\n\n\n\n"
"text":"The (default) notebook output of the source snippet above is as follows │ # Rational numbers\n │\n │ In julia rational numbers can be constructed with the `//` operator.\n │ Lets define two rational numbers, `x` and `y`:\n\nIn[1]: │ x = 1//3\nOut[1]: │ 1//3\n\nIn[2]: │ y = 2//5\nOut[2]: │ 2//5\n\n │ When adding `x` and `y` together we obtain a new rational number:\n\nIn[3]: │ z = x + y\nOut[3]: │ 11/15We note that lines starting with #\' is put in markdown cells, and the code lines have been put in code cells. By default the notebook is also executed and output cells populated. Some of the output rendering can be controlled with keyword arguments to Literate.notebook:Literate.notebook"
},
},
{
{
"location":"outputformats.html#Examples.script",
"location":"outputformats.html#Literate.script",
"page":"4. Output formats",
"page":"4. Output Formats",
"title":"Examples.script",
"title":"Literate.script",
"category":"function",
"category":"function",
"text":"Examples.script(inputfile, outputdir; kwargs...)\n\nGenerate a plain script file from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .jl. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\n\n\n\n\n\n"
"text":"Literate.script(inputfile, outputdir; kwargs...)\n\nGenerate a plain script file from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .jl. name is also used to replace @__NAME__. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\ndocumenter: boolean that says if the source contains Documenter.jl specific things to filter out during script generation. Defaults to true. See the the manual section on Interaction with Documenter.\n\n\n\n"
},
},
{
{
"location":"outputformats.html#Script-output-1",
"location":"outputformats.html#Script-Output-1",
"page":"4. Output formats",
"page":"4. Output Formats",
"title":"4.3. Script output",
"title":"4.3. Script Output",
"category":"section",
"category":"section",
"text":"Examples.script"
"text":"The (default) script output of the source snippet above is as followsx = 1//3\n\ny = 2//5\n\nz = x + yWe note that lines starting with #\' are removed and only the code lines have been kept. Some of the output rendering can be controlled with keyword arguments to Literate.script:Literate.script"
},
},
{
{
@ -213,7 +213,7 @@ var documenterSearchIndex = {"docs": [
"page":"5. Custom pre- and post-processing",
"page":"5. Custom pre- and post-processing",
"title":"5. Custom pre- and post-processing",
"title":"5. Custom pre- and post-processing",
"category":"section",
"category":"section",
"text":"Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing line filtering there might be situations where you need to manually hook into the generation and change things. In Examples.jl this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.All of the generators (Examples.markdown, Examples.notebook and Examples.script) accepts preprocess and postprocess keyword arguments. The default \"transformation\" is the identity function. The input to the transformation functions is a String, and the output should be the transformed String.preprocess is sent the raw input that is read from the source file (modulo the default line ending transformation). postprocess is given different things depending on the output: For markdown and script output postprocess is given the content String just before writing it to the output file, but for notebook output postprocess is given the dictionary representing the notebook, since, in general, this is more useful.As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a preprocess function that splices the date into the source for us. Consider the following source file:#\' # Example\n#\' This example was generated DATEOFTODAY\n\nx = 1 // 3where DATEOFTODAY is a placeholder, to make it easier for our preprocess function to find the location. Now, lets define the preprocess function, for examplefunction update_date(content)\n content = replace(content, \"DATEOFTODAY\" => Date(now()))\n return content\nendwhich would replace every occurrence of \"DATEOFTODAY\" with the current date. We would now simply give this function to the generator, for example:Examples.markdown(\"input.jl\", \"outputdir\"; preprocess = update_date)"
"text":"Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing line filtering there might be situations where you need to manually hook into the generation and change things. In Literate this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.All of the generators (Literate.markdown, Literate.notebook and Literate.script) accepts preprocess and postprocess keyword arguments. The default \"transformation\" is the identity function. The input to the transformation functions is a String, and the output should be the transformed String.preprocess is sent the raw input that is read from the source file (modulo the default line ending transformation). postprocess is given different things depending on the output: For markdown and script output postprocess is given the content String just before writing it to the output file, but for notebook output postprocess is given the dictionary representing the notebook, since, in general, this is more useful.As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a preprocess function that splices the date into the source for us. Consider the following source file:#\' # Example\n#\' This example was generated DATEOFTODAY\n\nx = 1 // 3where DATEOFTODAY is a placeholder, to make it easier for our preprocess function to find the location. Now, lets define the preprocess function, for examplefunction update_date(content)\n content = replace(content, \"DATEOFTODAY\" => Date(now()))\n return content\nendwhich would replace every occurrence of \"DATEOFTODAY\" with the current date. We would now simply give this function to the generator, for example:Literate.markdown(\"input.jl\", \"outputdir\"; preprocess = update_date)"
},
},
{
{
@ -229,7 +229,31 @@ var documenterSearchIndex = {"docs": [
"page":"6. Interaction with Documenter.jl",
"page":"6. Interaction with Documenter.jl",
"title":"6. Interaction with Documenter.jl",
"title":"6. Interaction with Documenter.jl",
"category":"section",
"category":"section",
"text":"Examples.jl can be used for any purpose, it spits out regular markdown files, and notebooks. Typically, though, these files will be used to render documentation for your package. The generators (Examples.markdown, Examples.notebook and Examples.script) supports a keyword argument documenter that lets the generator perform some extra things, keeping in mind that the generated files will, eventually, be used with Documenter.jl. So lets take a look at what will happen if we set documenter = true:Examples.markdown:The default code fence will change from\n```julia\n# code\n```\nto Documenters @example blocks:\n```@examples $(name)\n# code\n```\nThe following @meta block will be added to the top of the markdown page, which redirects the \"Edit on GitHub\" link on the top of the page to the source file rather than the generated .md file:\n```@meta\nEditURL = \"$(relpath(inputfile, outputdir))\"\n```Examples.notebook:Documenter style @refs and @id will be removed. This means that you can use @ref and @id in the source file without them leaking to the notebook.\nDocumenter style markdown math\n```math\n\\int f dx\n```\nis replaced with notebook compatible\n\\begin{equation}\n\\int f dx\n\\end{equation}"
"text":"Literate can be used for any purpose, it spits out regular markdown files, and notebooks. Typically, though, these files will be used to render documentation for your package. The generators (Literate.markdown, Literate.notebook and Literate.script) supports a keyword argument documenter that lets the generator perform some extra things, keeping in mind that the source code have been written with Documenter.jl in mind. So lets take a look at what will happen if we set documenter = true:"
"text":"The default code fence will change from\n```julia\n# code\n```\nto Documenters @example blocks:\n```@examples $(name)\n# code\n```\nThe following @meta block will be added to the top of the markdown page, which redirects the \"Edit on GitHub\" link on the top of the page to the source file rather than the generated .md file:\n```@meta\nEditURL = \"$(relpath(inputfile, outputdir))\"\n```"
"text":"Documenter style @refs and @id will be removed. This means that you can use @ref and @id in the source file without them leaking to the notebook.\nDocumenter style markdown math\n```math\n\\int f dx\n```\nis replaced with notebook compatible\n\\begin{equation}\n\\int f dx\n\\end{equation}"
"text":"Documenter style @refs and @id will be removed. This means that you can use @ref and @id in the source file without them leaking to the script."
},
},
{
{
@ -237,7 +261,7 @@ var documenterSearchIndex = {"docs": [
@ -245,15 +269,31 @@ var documenterSearchIndex = {"docs": [
"page":"7. Example",
"page":"7. Example",
"title":"7. Example",
"title":"7. Example",
"category":"section",
"category":"section",
"text":"This is an example for Examples.jl. The source file can be found here. The generated markdown can be found here: example.md, the generated notebook can be found here: example.ipynb, and the plain script output can be found here: example.jl."
"text":"This is an example generated with Literate based on this source file: example.jl. You are seeing the html-output which Documenter have generated based on a markdown file generated with Literate. The corresponding notebook can be found here: example.ipynb, and the plain script output can be found here: example.jl.It is recommended to have the source file available when reading this, to better understand how the syntax in the source file corresponds to the output you are seeing."
"text":"The basic syntax for Literate is simple, lines starting with #\' is interpreted as markdown, and all the other lines are interpreted as code. Here is some code:x = 1//3\ny = 2//5In markdown sections we can use markdown syntax. For example, we can write text in italic font, text in bold font and use links.It is possible to filter lines by starting it with #md, #nb or #jl for markdown, notebook and script output only, respectively. This line is filtered out for notebook and script output.The source file is parsed in chunks of markdown and code. Starting a line with #- manually inserts a chunk break. For example, if we want to display the output of the following operations we may insert #- in between. These two code blocks will now end up in different @example-blocks in the markdown output, and two different notebook cells in the notebook output.x + yx * y"
"text":"It is possible to give Literate custom pre- and post-processing functions. For example, here we insert two placeholders, which we will replace with something else at time of generation. We have here replaced our placeholders with z and 1.0 + 2.0im:z = 1.0 + 2.0im"
"text":"Rational number in julia can be constructed with the // operator:x = 1//3\ny = 2//5Operations with rational number returns a new rational numberx + yx * yEverytime a rational number is constructed, it will be simplified using the gcd function, for example 2//4 simplifies to 1//2:2//4and 2//4 + 2//4 simplifies to 1//1:2//4 + 2//4"
"text":"In the source file it is possible to use Documenter.jl style references, such as @ref and @id. These will be filtered out in the notebook output. For example, here is a link, but it is only visible as a link if you are reading the markdown output. We can also use equations:int f(x) dxusing Documenters math syntax. This is automatically changed to \\begin{equation} ... \\end{equation} in the notebook output to display correctly in the notebook too."