|
|
<!DOCTYPE html><HTML lang="en"><head><meta charset="UTF-8"/><meta content="width=device-width, initial-scale=1.0" name="viewport"/><title>7. Example · Literate.jl</title><link href="https://cdnjs.cloudflare.com/ajax/libs/normalize/4.2.0/normalize.min.css" rel="stylesheet" type="text/css"/><link href="https://fonts.googleapis.com/css?family=Lato|Roboto+Mono" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" type="text/css"/><link href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css" rel="stylesheet" type="text/css"/><script>documenterBaseURL=".."</script><script data-main="../assets/documenter.js" src="https://cdnjs.cloudflare.com/ajax/libs/require.js/2.2.0/require.min.js"></script><script src="../siteinfo.js"></script><script src="../../versions.js"></script><link href="../assets/documenter.css" rel="stylesheet" type="text/css"/><script data-outdated-warner="">function maybeAddWarning () { |
|
|
const head = document.getElementsByTagName('head')[0]; |
|
|
|
|
|
// Add a noindex meta tag (unless one exists) so that search engines don't index this version of the docs. |
|
|
if (document.body.querySelector('meta[name="robots"]') === null) { |
|
|
const meta = document.createElement('meta'); |
|
|
meta.name = 'robots'; |
|
|
meta.content = 'noindex'; |
|
|
|
|
|
head.appendChild(meta); |
|
|
}; |
|
|
|
|
|
// Add a stylesheet to avoid inline styling |
|
|
const style = document.createElement('style'); |
|
|
style.type = 'text/css'; |
|
|
style.appendChild(document.createTextNode('.outdated-warning-overlay { position: fixed; top: 0; left: 0; right: 0; box-shadow: 0 0 10px rgba(0, 0, 0, 0.3); z-index: 999; background-color: #ffaba7; color: rgba(0, 0, 0, 0.7); border-bottom: 3px solid #da0b00; padding: 10px 35px; text-align: center; font-size: 15px; } .outdated-warning-overlay .outdated-warning-closer { position: absolute; top: calc(50% - 10px); right: 18px; cursor: pointer; width: 12px; } .outdated-warning-overlay a { color: #2e63b8; } .outdated-warning-overlay a:hover { color: #363636; }')); |
|
|
head.appendChild(style); |
|
|
|
|
|
const div = document.createElement('div'); |
|
|
div.classList.add('outdated-warning-overlay'); |
|
|
const closer = document.createElement('div'); |
|
|
closer.classList.add('outdated-warning-closer'); |
|
|
|
|
|
// Icon by font-awesome (license: https://fontawesome.com/license, link: https://fontawesome.com/icons/times?style=solid) |
|
|
closer.innerHTML = '<svg aria-hidden="true" focusable="false" data-prefix="fas" data-icon="times" class="svg-inline--fa fa-times fa-w-11" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 352 512"><path fill="currentColor" d="M242.72 256l100.07-100.07c12.28-12.28 12.28-32.19 0-44.48l-22.24-22.24c-12.28-12.28-32.19-12.28-44.48 0L176 189.28 75.93 89.21c-12.28-12.28-32.19-12.28-44.48 0L9.21 111.45c-12.28 12.28-12.28 32.19 0 44.48L109.28 256 9.21 356.07c-12.28 12.28-12.28 32.19 0 44.48l22.24 22.24c12.28 12.28 32.2 12.28 44.48 0L176 322.72l100.07 100.07c12.28 12.28 32.2 12.28 44.48 0l22.24-22.24c12.28-12.28 12.28-32.19 0-44.48L242.72 256z"></path></svg>'; |
|
|
closer.addEventListener('click', function () { |
|
|
document.body.removeChild(div); |
|
|
}); |
|
|
let href = '/'; |
|
|
if (window.documenterBaseURL) { |
|
|
href = window.documenterBaseURL + '/../'; |
|
|
} |
|
|
div.innerHTML = 'This is an old version of the documentation. <br> <a href="' + href + '">Go to the newest version</a>.'; |
|
|
div.appendChild(closer); |
|
|
document.body.appendChild(div); |
|
|
}; |
|
|
|
|
|
if (document.readyState === 'loading') { |
|
|
document.addEventListener('DOMContentLoaded', maybeAddWarning); |
|
|
} else { |
|
|
maybeAddWarning(); |
|
|
}; |
|
|
</script></head><body><nav class="toc"><h1>Literate.jl</h1><select id="version-selector" onchange="window.location.href=this.value" style="visibility: hidden"></select><form action="../search.html" class="search" id="search-form"><input id="search-query" name="q" placeholder="Search docs" type="text"/></form><ul><li><a class="toctext" href="../index.html"><strong>1.</strong> Introduction</a></li><li><a class="toctext" href="../fileformat.html"><strong>2.</strong> File Format</a></li><li><a class="toctext" href="../pipeline.html"><strong>3.</strong> Processing pipeline</a></li><li><a class="toctext" href="../outputformats.html"><strong>4.</strong> Output Formats</a></li><li><a class="toctext" href="../customprocessing.html"><strong>5.</strong> Custom pre- and post-processing</a></li><li><a class="toctext" href="../documenter.html"><strong>6.</strong> Interaction with Documenter.jl</a></li><li class="current"><a class="toctext" href="example.html"><strong>7.</strong> Example</a><ul class="internal"></ul></li></ul></nav><article id="docs"><header><nav><ul><li><a href="example.html"><strong>7.</strong> Example</a></li></ul><a class="edit-page" href="https://github.com/fredrikekre/Literate.jl/blob/master/examples/example.jl"><span class="fa"></span> Edit on GitHub</a></nav><hr/><div id="topbar"><span>7. Example</span><a class="fa fa-bars" href="#"></a></div></header><h1><a class="nav-anchor" href="#**7.**-Example-1" id="**7.**-Example-1"><strong>7.</strong> Example</a></h1><p>This is an example generated with Literate based on this source file: <a href="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: <a href="https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/v0.2.1/generated/example.ipynb"><code>example.ipynb</code></a>, and the plain script output can be found here: <a href="example.jl"><code>example.jl</code></a>.</p><p>It is recommended to have the <a href="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><a class="nav-anchor" href="#Basic-syntax-1" id="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><code class="language-julia">x = 1//3 |
|
|
y = 2//5</code></pre><pre><code class="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 <a href="https://www.youtube.com/watch?v=dQw4w9WgXcQ">links</a>.</p><p>It is possible to filter out lines depending on the output using the <code>#md</code>, <code>#nb</code>, <code>#jl</code> and <code>#src</code> tags (see <a href="../fileformat.html#Filtering-Lines-1">Filtering Lines</a>):</p><ul><li><p>This line starts with <code>#md</code> and is thus only visible in the markdown output.</p></li></ul><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><code class="language-julia">x + y</code></pre><pre><code class="language-none">11//15</code></pre></div><div><pre><code class="language-julia">x * y</code></pre><pre><code class="language-none">2//15</code></pre></div><h3><a class="nav-anchor" href="#Output-Capturing-1" id="Output-Capturing-1">Output Capturing</a></h3><p>Code chunks are by default placed in Documenter <code>@example</code> blocks in the generated markdown. This means that the output will be captured in a block when Documenter is building the docs. In notebooks the output is captured in output cells, if the <code>execute</code> keyword argument is set to true. Output to <code>stdout</code>/<code>stderr</code> is also captured.</p><div><pre><code class="language-julia">function foo() |
|
|
println("This string is printed to stdout.") |
|
|
return [1, 2, 3, 4] |
|
|
end |
|
|
|
|
|
foo()</code></pre><pre><code class="language-none">This string is printed to stdout. |
|
|
4-element Array{Int64,1}: |
|
|
1 |
|
|
2 |
|
|
3 |
|
|
4</code></pre></div><h3><a class="nav-anchor" href="#Custom-processing-1" id="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><code class="language-julia">z = 1.0 + 2.0im</code></pre><pre><code class="language-none">1.0 + 2.0im</code></pre></div><h3><a class="nav-anchor" href="#documenter-interaction-1" id="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, <a href="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_\Omega \nabla v \cdot \nabla u\ \mathrm{d}\Omega = \int_\Omega v f\ \mathrm{d}\Omega\]</div><p>using Documenters math syntax. Documenters syntax is automatically changed to <code>\begin{equation} ... \end{equation}</code> in the notebook output to display correctly.</p><p><em>This page was generated using <a href="https://github.com/fredrikekre/Literate.jl">Literate.jl</a>.</em></p><footer><hr/><a class="previous" href="../documenter.html"><span class="direction">Previous</span><span class="title"><strong>6.</strong> Interaction with Documenter.jl</span></a></footer></article></body></HTML> |