<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"><ahref="../../index.html"><imgclass="logo"src="../../assets/logo.png"alt="Literate.jl logo"/></a><h1>Literate.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="../../search/"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="../../"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="../../fileformat/"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="../../pipeline/"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="../../outputformats/"><strong>4.</strong> Output Formats</a></li><li><aclass="toctext"href="../../customprocessing/"><strong>5.</strong> Custom pre- and post-processing</a></li><li><aclass="toctext"href="../../documenter/"><strong>6.</strong> Interaction with Documenter.jl</a></li><liclass="current"><aclass="toctext"href><strong>7.</strong> Example</a><ulclass="internal"></ul></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref><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><ahref="https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/generated/example.inpynb"><imgsrc="https://mybinder.org/badge_logo.svg"alt/></a><ahref="https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/generated/example.ipynb"><imgsrc="https://img.shields.io/badge/show-nbviewer-579ACA.svg"alt/></a></p><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 viewed in <ahref="http://nbviewer.jupyter.org/">nbviewer</a> here: <ahref="https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/generated/example.ipynb"><code>example.ipynb</code></a>, and opened in <ahref="https://mybinder.org/">binder</a> here: <ahref="https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/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><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"><ahref="../../index.html"><imgclass="logo"src="../../assets/logo.png"alt="Literate.jl logo"/></a><h1>Literate.jl</h1><selectid="version-selector"onChange="window.location.href=this.value"style="visibility: hidden"></select><formclass="search"id="search-form"action="../../search/"><inputid="search-query"name="q"type="text"placeholder="Search docs"/></form><ul><li><aclass="toctext"href="../../"><strong>1.</strong> Introduction</a></li><li><aclass="toctext"href="../../fileformat/"><strong>2.</strong> File Format</a></li><li><aclass="toctext"href="../../pipeline/"><strong>3.</strong> Processing pipeline</a></li><li><aclass="toctext"href="../../outputformats/"><strong>4.</strong> Output Formats</a></li><li><aclass="toctext"href="../../customprocessing/"><strong>5.</strong> Custom pre- and post-processing</a></li><li><aclass="toctext"href="../../documenter/"><strong>6.</strong> Interaction with Documenter.jl</a></li><liclass="current"><aclass="toctext"href><strong>7.</strong> Example</a><ulclass="internal"></ul></li></ul></nav><articleid="docs"><header><nav><ul><li><ahref><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><ahref="https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/generated/example.ipynb"><imgsrc="https://mybinder.org/badge_logo.svg"alt/></a><ahref="https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/generated/example.ipynb"><imgsrc="https://img.shields.io/badge/show-nbviewer-579ACA.svg"alt/></a></p><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 viewed in <ahref="http://nbviewer.jupyter.org/">nbviewer</a> here: <ahref="https://nbviewer.jupyter.org/github/fredrikekre/Literate.jl/blob/gh-pages/dev/generated/example.ipynb"><code>example.ipynb</code></a>, and opened in <ahref="https://mybinder.org/">binder</a> here: <ahref="https://mybinder.org/v2/gh/fredrikekre/Literate.jl/gh-pages?filepath=dev/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><pre><codeclass="language-julia">x = 1//3
y = 2//5</code></pre><pre><codeclass="language-none">2//5</code></pre><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 out lines depending on the output using the <code>#md</code>, <code>#nb</code>, <code>#jl</code> and <code>#src</code> tags (see <ahref="../../fileformat/#Filtering-Lines-1">Filtering Lines</a>):</p><ul><li>This line starts with <code>#md</code> and is thus only visible in the markdown output.</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><pre><codeclass="language-julia">x + y</code></pre><pre><codeclass="language-none">11//15</code></pre><pre><codeclass="language-julia">x * y</code></pre><pre><codeclass="language-none">2//15</code></pre><h3><aclass="nav-anchor"id="Output-Capturing-1"href="#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><pre><codeclass="language-julia">function foo()
y = 2//5</code></pre><pre><codeclass="language-none">2//5</code></pre><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 out lines depending on the output using the <code>#md</code>, <code>#nb</code>, <code>#jl</code> and <code>#src</code> tags (see <ahref="../../fileformat/#Filtering-Lines-1">Filtering Lines</a>):</p><ul><li>This line starts with <code>#md</code> and is thus only visible in the markdown output.</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><pre><codeclass="language-julia">x + y</code></pre><pre><codeclass="language-none">11//15</code></pre><pre><codeclass="language-julia">x * y</code></pre><pre><codeclass="language-none">2//15</code></pre><h3><aclass="nav-anchor"id="Output-Capturing-1"href="#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><pre><codeclass="language-julia">function foo()
println("This string is printed to stdout.")
println("This string is printed to stdout.")