|
|
|
@ -1,8 +1,10 @@ |
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}} |
|
|
|
# # **8.** Example |
|
|
|
# # **8.** Example |
|
|
|
# |
|
|
|
# |
|
|
|
#md # [](@__BINDER_ROOT_URL__/generated/example.ipynb) |
|
|
|
#md # [](@__BINDER_ROOT_URL__/generated/example.ipynb) |
|
|
|
#md # [](@__NBVIEWER_ROOT_URL__/generated/example.ipynb) |
|
|
|
#md # [](@__NBVIEWER_ROOT_URL__/generated/example.ipynb) |
|
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}} |
|
|
|
# This is an example generated with Literate based on this |
|
|
|
# This is an example generated with Literate based on this |
|
|
|
# source file: [`example.jl`](@__REPO_ROOT_URL__/examples/example.jl). |
|
|
|
# source file: [`example.jl`](@__REPO_ROOT_URL__/examples/example.jl). |
|
|
|
# You are seeing the |
|
|
|
# You are seeing the |
|
|
|
@ -16,21 +18,30 @@ |
|
|
|
#nb # can be found here: [`example.html`](https://fredrikekre.github.io/Literate.jl/dev/generated/example.html), |
|
|
|
#nb # can be found here: [`example.html`](https://fredrikekre.github.io/Literate.jl/dev/generated/example.html), |
|
|
|
# and the plain script output can be found here: [`example.jl`](./example.jl). |
|
|
|
# and the plain script output can be found here: [`example.jl`](./example.jl). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
|
|
|
|
#nb # To view this notebook as a slideshow, install the [RISE plugin](https://rise.readthedocs.io/en/stable/installation.html) |
|
|
|
|
|
|
|
#nb # and press `alt-r` to start. Use spacebar to advance. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
# It is recommended to have the [source file](@__REPO_ROOT_URL__/examples/example.jl) |
|
|
|
# It is recommended to have the [source file](@__REPO_ROOT_URL__/examples/example.jl) |
|
|
|
# available when reading this, to better understand how the syntax in the source file |
|
|
|
# available when reading this, to better understand how the syntax in the source file |
|
|
|
# corresponds to the output you are seeing. |
|
|
|
# corresponds to the output you are seeing. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}} |
|
|
|
# ### Basic syntax |
|
|
|
# ### Basic syntax |
|
|
|
# The basic syntax for Literate is simple, lines starting with `# ` is interpreted |
|
|
|
# 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: |
|
|
|
# as markdown, and all the other lines are interpreted as code. Here is some code: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb %% A slide [code] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
x = 1//3 |
|
|
|
x = 1//3 |
|
|
|
y = 2//5 |
|
|
|
y = 2//5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}} |
|
|
|
# In markdown sections we can use markdown syntax. For example, we can |
|
|
|
# In markdown sections we can use markdown syntax. For example, we can |
|
|
|
# write *text in italic font*, **text in bold font** and use |
|
|
|
# write *text in italic font*, **text in bold font** and use |
|
|
|
# [links](https://www.youtube.com/watch?v=dQw4w9WgXcQ). |
|
|
|
# [links](https://www.youtube.com/watch?v=dQw4w9WgXcQ). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
# It is possible to filter out lines depending on the output using the |
|
|
|
# It is possible to filter out lines depending on the output using the |
|
|
|
# `#md`, `#nb`, `#jl` and `#src` tags (see [Filtering Lines](@ref)): |
|
|
|
# `#md`, `#nb`, `#jl` and `#src` tags (see [Filtering Lines](@ref)): |
|
|
|
#md # - This line starts with `#md` and is thus only visible in the markdown output. |
|
|
|
#md # - This line starts with `#md` and is thus only visible in the markdown output. |
|
|
|
@ -38,6 +49,7 @@ y = 2//5 |
|
|
|
#jl # - This line starts with `#jl` and is thus only visible in the notebook output. |
|
|
|
#jl # - This line starts with `#jl` and is thus only visible in the notebook output. |
|
|
|
#src # - This line starts with `#src` and is thus only visible in the source file. |
|
|
|
#src # - This line starts with `#src` and is thus only visible in the source file. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}} |
|
|
|
# The source file is parsed in chunks of markdown and code. Starting a line |
|
|
|
# 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 |
|
|
|
# with `#-` manually inserts a chunk break. For example, if we want to |
|
|
|
# display the output of the following operations we may insert `#-` in |
|
|
|
# display the output of the following operations we may insert `#-` in |
|
|
|
@ -45,12 +57,14 @@ y = 2//5 |
|
|
|
# `@example`-blocks in the markdown output, and two different notebook cells |
|
|
|
# `@example`-blocks in the markdown output, and two different notebook cells |
|
|
|
# in the notebook output. |
|
|
|
# in the notebook output. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb %% A slide [code] {"slideshow": {"slide_type": "subslide"}} |
|
|
|
x + y |
|
|
|
x + y |
|
|
|
|
|
|
|
|
|
|
|
#- |
|
|
|
#- |
|
|
|
|
|
|
|
#nb %% A slide [code] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
x * y |
|
|
|
x * y |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}} |
|
|
|
# ### Output Capturing |
|
|
|
# ### Output Capturing |
|
|
|
# Code chunks are by default placed in Documenter `@example` blocks in the generated |
|
|
|
# Code chunks are by default placed in Documenter `@example` blocks in the generated |
|
|
|
# markdown. This means that the output will be captured in a block when Documenter is |
|
|
|
# markdown. This means that the output will be captured in a block when Documenter is |
|
|
|
@ -64,6 +78,7 @@ x * y |
|
|
|
#md # returned from `foo`, the printing of `"This string is printed to stdout."` |
|
|
|
#md # returned from `foo`, the printing of `"This string is printed to stdout."` |
|
|
|
#md # is hidden. |
|
|
|
#md # is hidden. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb %% A slide [code] {"slideshow": {"slide_type": "subslide"}} |
|
|
|
function foo() |
|
|
|
function foo() |
|
|
|
println("This string is printed to stdout.") |
|
|
|
println("This string is printed to stdout.") |
|
|
|
return [1, 2, 3, 4] |
|
|
|
return [1, 2, 3, 4] |
|
|
|
@ -74,31 +89,38 @@ foo() |
|
|
|
# Just like in the REPL, outputs ending with a semicolon hides the output: |
|
|
|
# Just like in the REPL, outputs ending with a semicolon hides the output: |
|
|
|
1 + 1; |
|
|
|
1 + 1; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}} |
|
|
|
# Both Documenter's `@example` block and notebooks can display images. Here is an example |
|
|
|
# Both Documenter's `@example` block and notebooks can display images. Here is an example |
|
|
|
# where we generate a simple plot using the |
|
|
|
# where we generate a simple plot using the |
|
|
|
# [Plots.jl](https://github.com/JuliaPlots/Plots.jl) package |
|
|
|
# [Plots.jl](https://github.com/JuliaPlots/Plots.jl) package |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb %% A slide [code] {"slideshow": {"slide_type": "subslide"}} |
|
|
|
using Plots |
|
|
|
using Plots |
|
|
|
x = range(0, stop=6π, length=1000) |
|
|
|
x = range(0, stop=6π, length=1000) |
|
|
|
y1 = sin.(x) |
|
|
|
y1 = sin.(x) |
|
|
|
y2 = cos.(x) |
|
|
|
y2 = cos.(x) |
|
|
|
plot(x, [y1, y2]) |
|
|
|
plot(x, [y1, y2]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}} |
|
|
|
# ### Custom processing |
|
|
|
# ### Custom processing |
|
|
|
# |
|
|
|
# |
|
|
|
# It is possible to give Literate custom pre- and post-processing functions. |
|
|
|
# It is possible to give Literate custom pre- and post-processing functions. |
|
|
|
# For example, here we insert a placeholder value `x = 123` in the source, and use a |
|
|
|
# For example, here we insert a placeholder value `x = 123` in the source, and use a |
|
|
|
# preprocessing function that replaces it with `y = 321` in the rendered output. |
|
|
|
# preprocessing function that replaces it with `y = 321` in the rendered output. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb %% A slide [code] {"slideshow": {"slide_type": "subslide"}} |
|
|
|
x = 123 |
|
|
|
x = 123 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
# In this case the preprocessing function is defined by |
|
|
|
# In this case the preprocessing function is defined by |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb %% A slide [code] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
function pre(s::String) |
|
|
|
function pre(s::String) |
|
|
|
s = replace(s, "x = 123" => "y = 321") |
|
|
|
s = replace(s, "x = 123" => "y = 321") |
|
|
|
return s |
|
|
|
return s |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}} |
|
|
|
# ### [Documenter.jl interaction](@id documenter-interaction) |
|
|
|
# ### [Documenter.jl interaction](@id documenter-interaction) |
|
|
|
# |
|
|
|
# |
|
|
|
# In the source file it is possible to use Documenter.jl style references, |
|
|
|
# In the source file it is possible to use Documenter.jl style references, |
|
|
|
@ -106,10 +128,12 @@ end |
|
|
|
# For example, [here is a link](@ref documenter-interaction), but it is only |
|
|
|
# For example, [here is a link](@ref documenter-interaction), but it is only |
|
|
|
# visible as a link if you are reading the markdown output. We can also |
|
|
|
# visible as a link if you are reading the markdown output. We can also |
|
|
|
# use equations: |
|
|
|
# use equations: |
|
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
# ```math |
|
|
|
# ```math |
|
|
|
# \int_\Omega \nabla v \cdot \nabla u\ \mathrm{d}\Omega = \int_\Omega v f\ \mathrm{d}\Omega |
|
|
|
# \int_\Omega \nabla v \cdot \nabla u\ \mathrm{d}\Omega = \int_\Omega v f\ \mathrm{d}\Omega |
|
|
|
# ``` |
|
|
|
# ``` |
|
|
|
# |
|
|
|
|
|
|
|
|
|
|
|
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "fragment"}} |
|
|
|
# using Documenters math syntax. Documenters syntax is automatically changed to |
|
|
|
# using Documenters math syntax. Documenters syntax is automatically changed to |
|
|
|
# `\begin{equation} ... \end{equation}` in the notebook output to display correctly. |
|
|
|
# `\begin{equation} ... \end{equation}` in the notebook output to display correctly. |
|
|
|
|