When the source is parsed, and has been processed it is time to render the output. We will consider the following source snippet:
# # Rational numbers
#
# In julia rational numbers can be constructed with the `//` operator.
# Lets define two rational numbers, `x` and `y`:
@@ -10,7 +10,7 @@ y = 2//5
# When adding `x` and `y` together we obtain a new rational number:
-z = x + y
and see how this is rendered in each of the output formats.
Markdown output is generated by Literate.markdown. The (default) markdown output of the source snippet above is as follows:
```@meta
+z = x + y
and see how this is rendered in each of the output formats.
Markdown output is generated by Literate.markdown. There exist various "flavors" of markdown and Literate supports some different flavors, see Markdown flavors. The default flavor is Literate.DocumenterFlavor() and, as the name suggest, it generates markdown files meant to be used together with Documenter.jl. The output of the source snippet above is as follows:
```@meta
EditURL = "https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/outputformats.jl"
```
@@ -42,7 +42,7 @@ x = 1//3
````
````
1//3
-````
In this example the output is just plain text. However, if the resulting value of the code block can be displayed as an image (png or jpeg) Literate will include the image representation of the output.
Since Documenter executes and captures results of @example block it is not necessary to use execute=true for markdown output that is meant to be used as input to Documenter.
Code execution of markdown output requires at least Literate version 2.4.
See the section about Configuration for more information about how to configure the behavior and resulting output of Literate.markdown.
Literate.markdown(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a markdown file from inputfile and write the result to the directory outputdir.
Default output directory pwd requires at least Literate version 2.5.
See the manual section on Configuration for documentation of possible configuration with config and other keyword arguments.
sourceLiterate supports different "flavors" to the markdown output. To specify a flavor pass the flavor keyword argument to Literate.markdown. The default flavor (Literate.DefaultFlavor) is the Documenter compatible output used throughout most examples. Another supported flavor is Literate.FranklinFlavor for output compatible with the Franklin.jl static site generator. Currently the only difference is that the Franklin flavor supports text/html MIME output when executing the markdown file, e.g. with
Literate.markdown(input, output; execute=true, flavor=Literate.FranklinFlavor())
The Franklin flavor requires at least Literate version 2.9.
Notebook output is generated by Literate.notebook. The (default) notebook output of the source snippet can be seen here: notebook.ipynb.
We note that lines starting with # are placed in markdown cells, and the code lines have been placed in code cells. By default the notebook is also executed and output cells populated. The current working directory is set to the specified output directory the notebook is executed.
See the section about Configuration for how to configure the behavior and resulting output of Literate.notebook.
Literate.notebook(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a notebook from inputfile and write the result to outputdir.
Default output directory pwd requires at least Literate version 2.5.
See the manual section on Configuration for documentation of possible configuration with config and other keyword arguments.
sourceJupyter notebook cells (both code cells and markdown cells) can contain metadata. This is enabled in Literate by the %% token, similar to Jupytext. The format is as follows
%% optional ignored text [type] {optional metadata JSON}
Cell metadata can, for example, be used for nbgrader and the reveal.js notebook extension RISE.
The following would create a 3 slide deck with RISE:
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}}
+````
In this example the output is just plain text. However, if the resulting value of the code block can be displayed as an image (image/png or image/jpeg), HTML (text/html) or markdown (text/markdown) Literate will include the richest representation of the output.
Since Documenter executes and captures results of @example block it is not necessary to use execute=true for markdown output that is meant to be used as input to Documenter.
See the section about Configuration for more information about how to configure the behavior and resulting output of Literate.markdown.
Literate.markdown(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a markdown file from inputfile and write the result to the directory outputdir.
See the manual section on Configuration for documentation of possible configuration with config and other keyword arguments.
sourceLiterate can output markdown in different flavors. The flavor is specified using the flavor keyword argument. The following flavors are currently supported:
flavor = Literate.DocumenterFlavor() this is the default flavor and the output is meant to be used as input to Documenter.jl.flavor = Literate.FranklinFlavor() this outputs markdown meant to be used as input to Franklin.jl.
Notebook output is generated by Literate.notebook. The (default) notebook output of the source snippet can be seen here: notebook.ipynb.
We note that lines starting with # are placed in markdown cells, and the code lines have been placed in code cells. By default the notebook is also executed and output cells populated. The current working directory is set to the specified output directory the notebook is executed.
See the section about Configuration for how to configure the behavior and resulting output of Literate.notebook.
Literate.notebook(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a notebook from inputfile and write the result to outputdir.
See the manual section on Configuration for documentation of possible configuration with config and other keyword arguments.
sourceJupyter notebook cells (both code cells and markdown cells) can contain metadata. This is enabled in Literate by the %% token, similar to Jupytext. The format is as follows
%% optional ignored text [type] {optional metadata JSON}
Cell metadata can, for example, be used for nbgrader and the reveal.js notebook extension RISE.
The following would create a 3 slide deck with RISE:
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "slide"}}
# # Some title
#
# We're using `#nb` so the metadata is only included in notebook output
@@ -52,8 +52,8 @@ x = 1//3
y = 2//5
#nb # %% A slide [markdown] {"slideshow": {"slide_type": "subslide"}}
-# For more information about RISE, see [the docs](https://rise.readthedocs.io/en/stable/usage.html)
Script output is generated by Literate.script. The (default) script output of the source snippet above is as follows:
x = 1//3
+# For more information about RISE, see [the docs](https://rise.readthedocs.io/en/stable/usage.html)
Script output is generated by Literate.script. The (default) script output of the source snippet above is as follows:
x = 1//3
y = 2//5
-z = x + y
We note that lines starting with # are removed and only the code lines have been kept.
See the section about Configuration for how to configure the behavior and resulting output of Literate.script.
Literate.script(inputfile, outputdir=pwd(); config::Dict=Dict(), kwargs...)
Generate a plain script file from inputfile and write the result to outputdir.
Default output directory pwd requires at least Literate version 2.5.
See the manual section on Configuration for documentation of possible configuration with config and other keyword arguments.
sourceThe behavior of Literate.markdown, Literate.notebook and Literate.script can be configured by keyword arguments. There are two ways to do this; pass config::Dict as a keyword argument, or pass individual keyword arguments.
Passing configuration as a dictionary requires at least Literate version 2.2.
Individual keyword arguments take precedence over the config dictionary, so for e.g. Literate.markdown(...; config = Dict("name" => "hello"), name = "world") the resulting configuration for name will be "world". Both individual keyword arguments and the config dictionary take precedence over the default.
Available configurations with description and default values are given in the reference for Literate.DEFAULT_CONFIGURATION just below.
DEFAULT_CONFIGURATION
Default configuration for Literate.markdown, Literate.notebook and Literate.script which is used for everything not specified by the user. See the manual section about Configuration for more information.
| Configuration key | Description | Default value | Comment |
|---|
name | Name of the output file (excluding file extension). | filename(inputfile) | |
preprocess | Custom preprocessing function mapping String to String. | identity | See Custom pre- and post-processing. |
postprocess | Custom preprocessing function mapping String to String. | identity | See Custom pre- and post-processing. |
documenter | Boolean signaling that the source contains Documenter.jl elements. | true | See Interaction with Documenter. |
credit | Boolean for controlling the addition of This file was generated with Literate.jl ... to the bottom of the page. If you find Literate.jl useful then feel free to keep this. | true | |
keep_comments | When true, keeps markdown lines as comments in the output script. | false | Only applicable for Literate.script. |
execute | Whether to execute and capture the output. | true (notebook), false (markdown) | Only applicable for Literate.notebook and Literate.markdown. For markdown this requires at least Literate 2.4. |
codefence | Pair containing opening and closing fence for wrapping code blocks. | "````julia" => "````" | If documenter is true the default is "````@example"=>"````". |
flavor | Output flavor for markdown. | Literate.DefaultFlavor() | See Markdown flavors. |
devurl | URL for "in-development" docs. | "dev" | See Documenter docs. Unused if repo_root_url/nbviewer_root_url/binder_root_url are set. |
repo_root_url | URL to the root of the repository. | - | Determined automatically on Travis CI, GitHub Actions and GitLab CI. Used for @__REPO_ROOT_URL__. |
nbviewer_root_url | URL to the root of the repository as seen on nbviewer. | - | Determined automatically on Travis CI, GitHub Actions and GitLab CI. Used for @__NBVIEWER_ROOT_URL__. |
binder_root_url | URL to the root of the repository as seen on mybinder. | - | Determined automatically on Travis CI, GitHub Actions and GitLab CI. Used for @__BINDER_ROOT_URL__. |
repo_root_path | Filepath to the root of the repository. | - | Determined automatically on Travis CI, GitHub Actions and GitLab CI. Used for computing Documenters EditURL. |
source