4. Output Formats
When the source is parsed, and have been processed it is time to render the output. We will consider the following source snippet:
#' # Rational numbers
+4. Output Formats · Literate.jl
4. Output Formats
When the source is parsed, and have 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,11 @@ 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.
4.1. Markdown Output
The (default) markdown output of the source snippet above is as follows
# Rational numbers
+z = x + y
and see how this is rendered in each of the output formats.
4.1. Markdown Output
The (default) markdown output of the source snippet above is as follows
```@meta
+EditURL = "https://github.com/fredrikekre/Literate.jl/blob/master/docs/src/outputformats.jl"
+```
+
+# Rational numbers
In julia rational numbers can be constructed with the `//` operator.
Lets define two rational numbers, `x` and `y`:
@@ -27,22 +31,8 @@ When adding `x` and `y` together we obtain a new rational number:
```@example name
z = x + y
-```
We note that lines starting with #' is printed as regular markdown, and the code lines have been wrapped in @example blocks.
Some of the output rendering can be controlled with keyword arguments to Literate.markdown:
Literate.markdown — Function.Literate.markdown(inputfile, outputdir; kwargs...)
Generate a markdown file from inputfile and write the result to the directoryoutputdir.
Keyword arguments:
name: name of the output file, excluding .md. name is also used to name all the @example blocks, and to replace @__NAME__. Defaults to the filename of inputfile.
preprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.
documenter: boolean that tells if the output is intended to use with Documenter.jl. Defaults to true. See the the manual section on Interaction with Documenter.
codefence: A Pair of opening and closing code fence. Defaults to
"```@example $(name)" => "```"
if documenter = true and
"```julia" => "```"
if documenter = false.
source4.2. Notebook Output
The (default) notebook output of the source snippet above is as follows
│ # Rational numbers
- │
- │ In julia rational numbers can be constructed with the `//` operator.
- │ Lets define two rational numbers, `x` and `y`:
-
-In[1]: │ x = 1//3
-Out[1]: │ 1//3
-
-In[2]: │ y = 2//5
-Out[2]: │ 2//5
-
- │ When adding `x` and `y` together we obtain a new rational number:
-
-In[3]: │ z = x + y
-Out[3]: │ 11/15
We note that lines starting with #' is put in markdown cells, and the code lines have been put 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. Some of the output rendering can be controlled with keyword arguments to Literate.notebook:
Literate.notebook — Function.Literate.notebook(inputfile, outputdir; kwargs...)
Generate a notebook from inputfile and write the result to outputdir.
Keyword arguments:
name: name of the output file, excluding .ipynb. name is also used to replace @__NAME__. Defaults to the filename of inputfile.
preprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.
execute: a boolean deciding if the generated notebook should also be executed or not. Defaults to true. The current working directory is set to outputdir when executing the notebook.
documenter: boolean that says if the source contains Documenter.jl specific things to filter out during notebook generation. Defaults to true. See the the manual section on Interaction with Documenter.
source4.3. Script Output
The (default) script output of the source snippet above is as follows
x = 1//3
+```
We note that lines starting with #' is printed as regular markdown, and the code lines have been wrapped in @example blocks. We also note that an @meta block have been added, that sets the EditURL variable. This is used by Documenter to redirect the "Edit on GitHub" link for the page, see Interaction with Documenter.
Some of the output rendering can be controlled with keyword arguments to Literate.markdown:
Literate.markdown — Function.Literate.markdown(inputfile, outputdir; kwargs...)
Generate a markdown file from inputfile and write the result to the directoryoutputdir.
Keyword arguments:
name: name of the output file, excluding .md. name is also used to name all the @example blocks, and to replace @__NAME__. Defaults to the filename of inputfile.
preprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.
documenter: boolean that tells if the output is intended to use with Documenter.jl. Defaults to true. See the the manual section on Interaction with Documenter.
codefence: A Pair of opening and closing code fence. Defaults to
"```@example $(name)" => "```"
if documenter = true and
"```julia" => "```"
if documenter = false.
source4.2. Notebook Output
The (default) notebook output of the source snippet can be seen here: notebook.ipynb.
We note that lines starting with #' is put in markdown cells, and the code lines have been put 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. Some of the output rendering can be controlled with keyword arguments to Literate.notebook:
Literate.notebook — Function.Literate.notebook(inputfile, outputdir; kwargs...)
Generate a notebook from inputfile and write the result to outputdir.
Keyword arguments:
name: name of the output file, excluding .ipynb. name is also used to replace @__NAME__. Defaults to the filename of inputfile.
preprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.
execute: a boolean deciding if the generated notebook should also be executed or not. Defaults to true. The current working directory is set to outputdir when executing the notebook.
documenter: boolean that says if the source contains Documenter.jl specific things to filter out during notebook generation. Defaults to true. See the the manual section on Interaction with Documenter.
source4.3. Script Output
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. Some of the output rendering can be controlled with keyword arguments to Literate.script:
Literate.script — Function.Literate.script(inputfile, outputdir; kwargs...)
Generate a plain script file from inputfile and write the result to outputdir.
Keyword arguments:
name: name of the output file, excluding .jl. name is also used to replace @__NAME__. Defaults to the filename of inputfile.
preprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.
documenter: boolean that says if the source contains Documenter.jl specific things to filter out during script generation. Defaults to true. See the the manual section on Interaction with Documenter.
keep_comments: boolean that, if set to true, keeps markdown lines (#') as comments in the output script. Defaults to false.
source
+z = x + yWe note that lines starting with #' are removed and only the code lines have been kept. Some of the output rendering can be controlled with keyword arguments to Literate.script:
Literate.script — Function.Literate.script(inputfile, outputdir; kwargs...)
Generate a plain script file from inputfile and write the result to outputdir.
Keyword arguments:
name: name of the output file, excluding .jl. name is also used to replace @__NAME__. Defaults to the filename of inputfile.
preprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.
documenter: boolean that says if the source contains Documenter.jl specific things to filter out during script generation. Defaults to true. See the the manual section on Interaction with Documenter.
keep_comments: boolean that, if set to true, keeps markdown lines (#') as comments in the output script. Defaults to false.
source
diff --git a/latest/outputformats.jl b/latest/outputformats.jl
new file mode 100644
index 0000000..4fbfd71
--- /dev/null
+++ b/latest/outputformats.jl
@@ -0,0 +1,12 @@
+#' # Rational numbers
+#'
+#' In julia rational numbers can be constructed with the `//` operator.
+#' Lets define two rational numbers, `x` and `y`:
+
+x = 1//3
+#-
+y = 2//5
+
+#' When adding `x` and `y` together we obtain a new rational number:
+
+z = x + y
diff --git a/latest/search_index.js b/latest/search_index.js
index 5a4b6a5..be397e6 100644
--- a/latest/search_index.js
+++ b/latest/search_index.js
@@ -149,7 +149,7 @@ var documenterSearchIndex = {"docs": [
"page": "4. Output Formats",
"title": "4. Output Formats",
"category": "section",
- "text": "When the source is parsed, and have been processed it is time to render the output. We will consider the following source snippet:#\' # Rational numbers\n#\'\n#\' In julia rational numbers can be constructed with the `//` operator.\n#\' Lets define two rational numbers, `x` and `y`:\n\nx = 1//3\n#-\ny = 2//5\n\n#\' When adding `x` and `y` together we obtain a new rational number:\n\nz = x + yand see how this is rendered in each of the output formats."
+ "text": "When the source is parsed, and have been processed it is time to render the output. We will consider the following source snippet:Markdown.parse(\"```julia\\n\" * rstrip(read(\"outputformats.jl\", String)) * \"\\n```\")and see how this is rendered in each of the output formats."
},
{
@@ -165,7 +165,7 @@ var documenterSearchIndex = {"docs": [
"page": "4. Output Formats",
"title": "4.1. Markdown Output",
"category": "section",
- "text": "The (default) markdown output of the source snippet above is as follows# Rational numbers\n\nIn julia rational numbers can be constructed with the `//` operator.\nLets define two rational numbers, `x` and `y`:\n\n```@example name\nx = 1//3\n```\n\n```@example name\ny = 2//5\n```\n\nWhen adding `x` and `y` together we obtain a new rational number:\n\n```@example name\nz = x + y\n```We note that lines starting with #\' is printed as regular markdown, and the code lines have been wrapped in @example blocks.Some of the output rendering can be controlled with keyword arguments to Literate.markdown:Literate.markdown"
+ "text": "The (default) markdown output of the source snippet above is as followsfile = joinpath(@__DIR__, \"src/generated/name.md\")\nstr = \"````markdown\\n\" * rstrip(read(file, String)) * \"\\n````\"\nrm(file)\nMarkdown.parse(str)We note that lines starting with #\' is printed as regular markdown, and the code lines have been wrapped in @example blocks. We also note that an @meta block have been added, that sets the EditURL variable. This is used by Documenter to redirect the \"Edit on GitHub\" link for the page, see Interaction with Documenter.Some of the output rendering can be controlled with keyword arguments to Literate.markdown:Literate.markdown"
},
{
@@ -181,7 +181,7 @@ var documenterSearchIndex = {"docs": [
"page": "4. Output Formats",
"title": "4.2. Notebook Output",
"category": "section",
- "text": "The (default) notebook output of the source snippet above is as follows │ # Rational numbers\n │\n │ In julia rational numbers can be constructed with the `//` operator.\n │ Lets define two rational numbers, `x` and `y`:\n\nIn[1]: │ x = 1//3\nOut[1]: │ 1//3\n\nIn[2]: │ y = 2//5\nOut[2]: │ 2//5\n\n │ When adding `x` and `y` together we obtain a new rational number:\n\nIn[3]: │ z = x + y\nOut[3]: │ 11/15We note that lines starting with #\' is put in markdown cells, and the code lines have been put 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. Some of the output rendering can be controlled with keyword arguments to Literate.notebook:Literate.notebook"
+ "text": "The (default) notebook output of the source snippet can be seen here: notebook.ipynb.We note that lines starting with #\' is put in markdown cells, and the code lines have been put 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. Some of the output rendering can be controlled with keyword arguments to Literate.notebook:Literate.notebook"
},
{
@@ -197,7 +197,7 @@ var documenterSearchIndex = {"docs": [
"page": "4. Output Formats",
"title": "4.3. Script Output",
"category": "section",
- "text": "The (default) script output of the source snippet above is as followsx = 1//3\n\ny = 2//5\n\nz = x + yWe note that lines starting with #\' are removed and only the code lines have been kept. Some of the output rendering can be controlled with keyword arguments to Literate.script:Literate.script"
+ "text": "The (default) script output of the source snippet above is as followsfile = joinpath(@__DIR__, \"src/generated/outputformats.jl\")\nstr = \"```julia\\n\" * rstrip(read(file, String)) * \"\\n```\"\nrm(file)\nMarkdown.parse(str)We note that lines starting with #\' are removed and only the code lines have been kept. Some of the output rendering can be controlled with keyword arguments to Literate.script:Literate.script"
},
{