You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
201 lines
5.1 KiB
201 lines
5.1 KiB
{ |
|
"cells": [ |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"# **7.** Example\n", |
|
"\n", |
|
"This is an example generated with Literate based on this\n", |
|
"source file: [`example.jl`](https://github.com/fredrikekre/Literate.jl/blob/master/examples/example.jl).\n", |
|
"You are seeing the\n", |
|
"generated notebook output. The corresponding markdown (html) output The generated markdown can be found here: [`example.md`](./example.md), the\n", |
|
"can be found here: [`example.md`](./example.md),\n", |
|
"and the plain script output can be found here: [`example.jl`](./example.jl)." |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"It is recommended to have the [source file](https://github.com/fredrikekre/Literate.jl/blob/master/examples/example.jl)\n", |
|
"available when reading this, to better understand how the syntax in the source file\n", |
|
"corresponds to the output you are seeing." |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"### Basic syntax\n", |
|
"The basic syntax for Literate is simple, lines starting with `#'` is interpreted\n", |
|
"as markdown, and all the other lines are interpreted as code. Here is some code:" |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [ |
|
{ |
|
"output_type": "execute_result", |
|
"data": { |
|
"text/plain": "2//5" |
|
}, |
|
"metadata": {}, |
|
"execution_count": 1 |
|
} |
|
], |
|
"cell_type": "code", |
|
"source": [ |
|
"x = 1//3\n", |
|
"y = 2//5" |
|
], |
|
"metadata": {}, |
|
"execution_count": 1 |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"In markdown sections we can use markdown syntax. For example, we can\n", |
|
"write *text in italic font*, **text in bold font** and use\n", |
|
"[links](https://www.youtube.com/watch?v=dQw4w9WgXcQ)." |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"It is possible to filter lines by starting it with `#md`, `#nb` or `#jl`\n", |
|
"for markdown, notebook and script output only, respectively.\n", |
|
"This line is filtered out for markdown and script output." |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"The source file is parsed in chunks of markdown and code. Starting a line\n", |
|
"with `#-` manually inserts a chunk break. For example, if we want to\n", |
|
"display the output of the following operations we may insert `#-` in\n", |
|
"between. These two code blocks will now end up in different\n", |
|
"`@example`-blocks in the markdown output, and two different notebook cells\n", |
|
"in the notebook output." |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [ |
|
{ |
|
"output_type": "execute_result", |
|
"data": { |
|
"text/plain": "11//15" |
|
}, |
|
"metadata": {}, |
|
"execution_count": 2 |
|
} |
|
], |
|
"cell_type": "code", |
|
"source": [ |
|
"x + y" |
|
], |
|
"metadata": {}, |
|
"execution_count": 2 |
|
}, |
|
{ |
|
"outputs": [ |
|
{ |
|
"output_type": "execute_result", |
|
"data": { |
|
"text/plain": "2//15" |
|
}, |
|
"metadata": {}, |
|
"execution_count": 3 |
|
} |
|
], |
|
"cell_type": "code", |
|
"source": [ |
|
"x * y" |
|
], |
|
"metadata": {}, |
|
"execution_count": 3 |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"### Custom processing\n", |
|
"\n", |
|
"It is possible to give Literate custom pre- and post-processing functions.\n", |
|
"For example, here we insert two placeholders, which we will replace with\n", |
|
"something else at time of generation. We have here replaced our placeholders\n", |
|
"with `z` and `1.0 + 2.0im`:" |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [ |
|
{ |
|
"output_type": "execute_result", |
|
"data": { |
|
"text/plain": "1.0 + 2.0im" |
|
}, |
|
"metadata": {}, |
|
"execution_count": 4 |
|
} |
|
], |
|
"cell_type": "code", |
|
"source": [ |
|
"z = 1.0 + 2.0im" |
|
], |
|
"metadata": {}, |
|
"execution_count": 4 |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"### Documenter.jl interaction\n", |
|
"\n", |
|
"In the source file it is possible to use Documenter.jl style references,\n", |
|
"such as `@ref` and `@id`. These will be filtered out in the notebook output.\n", |
|
"For example, here is a link, but it is only\n", |
|
"visible as a link if you are reading the markdown output. We can also\n", |
|
"use equations:\n", |
|
"\\begin{equation}\n", |
|
"\\int f(x) dx\n", |
|
"\\end{equation}\n", |
|
"using Documenters math syntax. This is automatically changed to\n", |
|
"`\\begin{equation} ... \\end{equation}` in the notebook output to display\n", |
|
"correctly in the notebook too." |
|
], |
|
"metadata": {} |
|
}, |
|
{ |
|
"outputs": [], |
|
"cell_type": "markdown", |
|
"source": [ |
|
"*This notebook was generated using [Literate.jl](https://github.com/fredrikekre/Literate.jl).*" |
|
], |
|
"metadata": {} |
|
} |
|
], |
|
"nbformat_minor": 3, |
|
"metadata": { |
|
"language_info": { |
|
"file_extension": ".jl", |
|
"mimetype": "application/julia", |
|
"name": "julia", |
|
"version": "0.6.2" |
|
}, |
|
"kernelspec": { |
|
"name": "julia-0.6", |
|
"display_name": "Julia 0.6.2", |
|
"language": "julia" |
|
} |
|
}, |
|
"nbformat": 4 |
|
}
|
|
|