From ab39c1a84907815f6878baa4576971ef8e0ddc86 Mon Sep 17 00:00:00 2001 From: autodocs Date: Fri, 20 Apr 2018 09:28:49 +0000 Subject: [PATCH] build based on dedf3af --- latest/customprocessing.html | 4 +- latest/documenter.html | 12 +-- latest/fileformat.html | 43 ++-------- latest/generated/example.html | 4 +- latest/generated/example.ipynb | 104 +++++++++++++++-------- latest/generated/example.jl | 4 +- latest/index.html | 2 +- latest/outputformats.html | 56 +++++++++---- latest/pipeline.html | 4 +- latest/search.html | 2 +- latest/search_index.js | 148 +++++++++++++++++++++------------ 11 files changed, 226 insertions(+), 157 deletions(-) diff --git a/latest/customprocessing.html b/latest/customprocessing.html index 9e5a3c5..ec847b0 100644 --- a/latest/customprocessing.html +++ b/latest/customprocessing.html @@ -1,8 +1,8 @@ -5. Custom pre- and post-processing · Examples.jl

5. Custom pre- and post-processing

5. Custom pre- and post-processing

Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing line filtering there might be situations where you need to manually hook into the generation and change things. In Examples.jl this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.

All of the generators (Examples.markdown, Examples.notebook and Examples.script) accepts preprocess and postprocess keyword arguments. The default "transformation" is the identity function. The input to the transformation functions is a String, and the output should be the transformed String.

preprocess is sent the raw input that is read from the source file (modulo the default line ending transformation). postprocess is given different things depending on the output: For markdown and script output postprocess is given the content String just before writing it to the output file, but for notebook output postprocess is given the dictionary representing the notebook, since, in general, this is more useful.

As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a preprocess function that splices the date into the source for us. Consider the following source file:

#' # Example
+5. Custom pre- and post-processing · Literate.jl

5. Custom pre- and post-processing

5. Custom pre- and post-processing

Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing line filtering there might be situations where you need to manually hook into the generation and change things. In Literate this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.

All of the generators (Literate.markdown, Literate.notebook and Literate.script) accepts preprocess and postprocess keyword arguments. The default "transformation" is the identity function. The input to the transformation functions is a String, and the output should be the transformed String.

preprocess is sent the raw input that is read from the source file (modulo the default line ending transformation). postprocess is given different things depending on the output: For markdown and script output postprocess is given the content String just before writing it to the output file, but for notebook output postprocess is given the dictionary representing the notebook, since, in general, this is more useful.

As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a preprocess function that splices the date into the source for us. Consider the following source file:

#' # Example
 #' This example was generated DATEOFTODAY
 
 x = 1 // 3

where DATEOFTODAY is a placeholder, to make it easier for our preprocess function to find the location. Now, lets define the preprocess function, for example

function update_date(content)
     content = replace(content, "DATEOFTODAY" => Date(now()))
     return content
-end

which would replace every occurrence of "DATEOFTODAY" with the current date. We would now simply give this function to the generator, for example:

Examples.markdown("input.jl", "outputdir"; preprocess = update_date)
+end

which would replace every occurrence of "DATEOFTODAY" with the current date. We would now simply give this function to the generator, for example:

Literate.markdown("input.jl", "outputdir"; preprocess = update_date)
diff --git a/latest/documenter.html b/latest/documenter.html index 9920140..c7167fc 100644 --- a/latest/documenter.html +++ b/latest/documenter.html @@ -1,12 +1,12 @@ -6. Interaction with Documenter.jl · Examples.jl

6. Interaction with Documenter.jl

6. Interaction with Documenter.jl

Examples.jl can be used for any purpose, it spits out regular markdown files, and notebooks. Typically, though, these files will be used to render documentation for your package. The generators (Examples.markdown, Examples.notebook and Examples.script) supports a keyword argument documenter that lets the generator perform some extra things, keeping in mind that the generated files will, eventually, be used with Documenter.jl. So lets take a look at what will happen if we set documenter = true:

Examples.markdown:

Literate.script:

diff --git a/latest/fileformat.html b/latest/fileformat.html index 3a38412..d2bc139 100644 --- a/latest/fileformat.html +++ b/latest/fileformat.html @@ -1,5 +1,5 @@ -2. File Format · Examples.jl

2. File Format

2. File Format

The source file format for Examples.jl is a regular, commented, julia (.jl) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. include, to make sure the examples stay up do date with other changes in your package.

2.1. Syntax

The basic syntax is simple:

The reason for using #' instead of # is that we want to be able to use # as comments, just as in a regular script. Lets look at a simple example:

#' # Rational numbers
+2. File Format · Literate.jl

2. File Format

2. File Format

The source file format for Literate is a regular, commented, julia (.jl) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. include, to make sure the examples stay up do date with other changes in your package.

2.1. Syntax

The basic syntax is simple:

  • lines starting with #' is treated as markdown,

  • all other lines are treated as julia code.

The reason for using #' instead of # is that we want to be able to use # as comments, just as in a regular script. Lets look at a simple example:

#' # Rational numbers
 #'
 #' In julia rational numbers can be constructed with the `//` operator.
 #' Lets define two rational numbers, `x` and `y`:
@@ -9,39 +9,8 @@ y = 2//5
 
 #' When adding `x` and `y` together we obtain a new rational number:
 
-z = x + y

In the lines #' we can use regular markdown syntax, for example the # used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:

  • The script is valid julia, which means that we can include it and the example will run
  • The script is "self-explanatory", i.e. the markdown lines works as comments and thus serve as good documentation on its own.

For simple use this is all you need to know, the script above is valid. Let's take a look at what the above snippet would generate, with default settings:

  • Examples.markdown: leading #' are removed, and code lines are wrapped in @example-blocks:

    # Rational numbers
    -
    -In julia rational numbers can be constructed with the `//` operator.
    -Lets define two rational numbers, `x` and `y`:
    -
    -```@example filename
    -x = 1//3
    -y = 2//5
    -```
    -
    -When adding `x` and `y` together we obtain a new rational number:
    -
    -```@example filename
    -z = x + y
    -```
  • Examples.notebook: leading #' are removed, markdown lines are placed in "markdown" cells, and code lines in "code" cells:

             │ # 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
    -         │ y = 2//5
    -
    -Out [1]: │ 2//5
    -
    -         │ When adding `x` and `y` together we obtain a new rational number:
    -
    -In [2]:  │ z = x + y
    -
    -Out [2]: │ 11//15
  • Examples.script: all lines starting with #' are removed:

    x = 1//3
    -y = 2//5
    -
    -z = x + y

2.2. Filtering Lines

It is possible to filter out lines depending on the output format. For this purpose, there are three different "tokens" that can be placed on the start of the line:

  • #md: markdown output only,
  • #nb: notebook output only,
  • #jl: script output only.

Lines starting with one of these tokens are filtered out in the preprocessing step.

Suppose, for example, that we want to include a docstring within a @docs block using Documenter. Obviously we don't want to include this in the notebook, since @docs is Documenter syntax that the notebook will not understand. This is a case where we can prepend #md to those lines:

#md #' ```@docs
-#md #' Examples.markdown
-#md #' Examples.notebook
-#md #' Examples.markdown
-#md #' ```

The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading #md from the lines. Beware that the space after the tag is also removed.

+z = x + y

In the lines #' we can use regular markdown syntax, for example the # used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:

For simple use this is all you need to know. The following additional special syntax can also be used:

There is also some default convenience replacements that will always be performed, see Default Replacements.

2.2. Filtering Lines

It is possible to filter out lines depending on the output format. For this purpose, there are three different "tokens" that can be placed on the start of the line:

Lines starting with one of these tokens are filtered out in the preprocessing step.

Suppose, for example, that we want to include a docstring within a @docs block using Documenter. Obviously we don't want to include this in the notebook, since @docs is Documenter syntax that the notebook will not understand. This is a case where we can prepend #md to those lines:

#md #' ```@docs
+#md #' Literate.markdown
+#md #' Literate.notebook
+#md #' Literate.markdown
+#md #' ```

The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading #md from the lines. Beware that the space after the tag is also removed.

2.3. Default Replacements

The following convenience "macros" are always expanded:

diff --git a/latest/generated/example.html b/latest/generated/example.html index feb14cf..70b1bc4 100644 --- a/latest/generated/example.html +++ b/latest/generated/example.html @@ -1,3 +1,3 @@ -7. Example · Examples.jl

7. Example

7. Example

This is an example for Examples.jl. The source file can be found here. The generated markdown can be found here: example.md, the generated notebook can be found here: example.ipynb, and the plain script output can be found here: example.jl.

Rational numbers in Julia

Rational number in julia can be constructed with the // operator:

x = 1//3
-y = 2//5
2//5

Operations with rational number returns a new rational number

x + y
11//15
x * y
2//15

Everytime a rational number is constructed, it will be simplified using the gcd function, for example 2//4 simplifies to 1//2:

2//4
1//2

and 2//4 + 2//4 simplifies to 1//1:

2//4 + 2//4
1//1
+7. Example · Literate.jl

7. Example

7. Example

This is an example generated with Literate based on this source file: example.jl. You are seeing the html-output which Documenter have generated based on a markdown file generated with Literate. The corresponding notebook can be found here: example.ipynb, and the plain script output can be found here: example.jl.

It is recommended to have the source file available when reading this, to better understand how the syntax in the source file corresponds to the output you are seeing.

Basic syntax

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:

x = 1//3
+y = 2//5
2//5

In markdown sections we can use markdown syntax. For example, we can write text in italic font, text in bold font and use links.

It is possible to filter lines by starting it with #md, #nb or #jl for markdown, notebook and script output only, respectively. This line is filtered out for notebook and script output.

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 display the output of the following operations we may insert #- in between. These two code blocks will now end up in different @example-blocks in the markdown output, and two different notebook cells in the notebook output.

x + y
11//15
x * y
2//15

Custom processing

It is possible to give Literate custom pre- and post-processing functions. For example, here we insert two placeholders, which we will replace with something else at time of generation. We have here replaced our placeholders with z and 1.0 + 2.0im:

z = 1.0 + 2.0im
1.0 + 2.0im

Documenter.jl interaction

In the source file it is possible to use Documenter.jl style references, such as @ref and @id. These will be filtered out in the notebook output. For example, here is a link, but it is only visible as a link if you are reading the markdown output. We can also use equations:

\[\int f(x) dx\]

using Documenters math syntax. This is automatically changed to \begin{equation} ... \end{equation} in the notebook output to display correctly in the notebook too.

diff --git a/latest/generated/example.ipynb b/latest/generated/example.ipynb index 9bd5ea2..4f919a8 100644 --- a/latest/generated/example.ipynb +++ b/latest/generated/example.ipynb @@ -6,12 +6,12 @@ "source": [ "# **7.** Example\n", "\n", - "This is an example for Examples.jl.\n", - "The source file can be found [here](https://github.com/fredrikekre/Examples.jl/blob/master/examples/example.jl).\n", - "The generated markdown can be found here: [`example.md`](./example.md), the\n", - "generated notebook can be found here:\n", - "[`example.ipynb`](https://nbviewer.jupyter.org/github/fredrikekre/Examples.jl/blob/gh-pages/latest/generated/example.ipynb), and the\n", - "plain script output can be found here: [`example.jl`](./example.jl)." + "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": {} }, @@ -19,8 +19,19 @@ "outputs": [], "cell_type": "markdown", "source": [ - "### Rational numbers in Julia\n", - "Rational number in julia can be constructed with the `//` operator:" + "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": {} }, @@ -47,7 +58,32 @@ "outputs": [], "cell_type": "markdown", "source": [ - "Operations with rational number returns a new rational number" + "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": {} }, @@ -91,8 +127,12 @@ "outputs": [], "cell_type": "markdown", "source": [ - "Everytime a rational number is constructed, it will be simplified\n", - "using the `gcd` function, for example `2//4` simplifies to `1//2`:" + "### 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": {} }, @@ -101,7 +141,7 @@ { "output_type": "execute_result", "data": { - "text/plain": "1//2" + "text/plain": "1.0 + 2.0im" }, "metadata": {}, "execution_count": 4 @@ -109,7 +149,7 @@ ], "cell_type": "code", "source": [ - "2//4" + "z = 1.0 + 2.0im" ], "metadata": {}, "execution_count": 4 @@ -118,27 +158,21 @@ "outputs": [], "cell_type": "markdown", "source": [ - "and `2//4 + 2//4` simplifies to `1//1`:" + "### 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": [ - { - "output_type": "execute_result", - "data": { - "text/plain": "1//1" - }, - "metadata": {}, - "execution_count": 5 - } - ], - "cell_type": "code", - "source": [ - "2//4 + 2//4" - ], - "metadata": {}, - "execution_count": 5 } ], "nbformat_minor": 3, @@ -147,11 +181,11 @@ "file_extension": ".jl", "mimetype": "application/julia", "name": "julia", - "version": "0.7.0" + "version": "0.6.2" }, "kernelspec": { - "name": "julia-0.7", - "display_name": "Julia 0.7.0", + "name": "julia-0.6", + "display_name": "Julia 0.6.2", "language": "julia" } }, diff --git a/latest/generated/example.jl b/latest/generated/example.jl index c63a265..025e604 100644 --- a/latest/generated/example.jl +++ b/latest/generated/example.jl @@ -5,7 +5,5 @@ x + y x * y -2//4 - -2//4 + 2//4 +z = 1.0 + 2.0im diff --git a/latest/index.html b/latest/index.html index e346dce..1d14697 100644 --- a/latest/index.html +++ b/latest/index.html @@ -1,2 +1,2 @@ -1. Introduction · Examples.jl

1. Introduction

1. Introduction

Welcome to the documentation for Examples.jl. A simplistic package to help you organize examples for you package documentation.

What?

Examples.jl is a package that, based on a single source file, generates markdown, for e.g. Documenter.jl, Jupyter notebooks and uncommented scripts for documentation of your package.

The main design goal is simplicity. It should be simple to use, and the syntax should be simple. In short all you have to do is to write a commented julia script!

The package consists mainly of three functions, which all takes the same script file as input, but generates different output:

Why?

Examples are (probably) the best way to showcase your awesome package, and examples are often the best way for a new user to learn how to use it. It is therefore important that the documentation of your package contains examples for users to read and study. However, people are different, and we all prefer different ways of trying out a new package. Some people wants to RTFM, others want to explore the package interactively in, for example, a notebook, and some people wants to study the source code. The aim of Examples.jl is to make it easy to give the user all of these options, while still keeping maintenance to a minimum.

It is quite common that packages have "example notebooks" to showcase the package. Notebooks are great for this, but they are not so great with version control, like git. The reason is that a notebook is a very "rich" format since it contains output and other metadata. Changes to the notebook thus result in large diffs, which makes it harder to review the actual changes.

It is also common that packages include examples in the documentation, for example by using Documenter.jl @example-blocks. This is also great, but it is not quite as interactive as a notebook, for the users who prefer that.

Examples.jl tries to solve the problems above by creating the output as a part of the doc build. Examples.jl generates the output from a single source file which makes it easier to maintain, test, and keep the manual and your example notebooks in sync.

How?

TBD

+1. Introduction · Literate.jl

1. Introduction

1. Introduction

Welcome to the documentation for Literate – a simplistic package for Literate Programming.

What?

Literate is a package that generate markdown pages (for e.g. Documenter.jl), and Jupyter notebooks, from the same source file. There is also an option to "clean" the source from all metadata, and produce a pure Julia script.

The main design goal is simplicity. It should be simple to use, and the syntax should be simple. In short, all you have to do is to write a commented julia script!

The public interface consists mainly of three functions, which all takes the same script file as input, but generates different output:

Why?

Examples are (probably) the best way to showcase your awesome package, and examples are often the best way for a new user to learn how to use it. It is therefore important that the documentation of your package contains examples for users to read and study. However, people are different, and we all prefer different ways of trying out a new package. Some people wants to RTFM, others want to explore the package interactively in, for example, a notebook, and some people wants to study the source code. The aim of Literate is to make it easy to give the user all of these options, while still keeping maintenance to a minimum.

It is quite common that packages have "example notebooks" to showcase the package. Notebooks are great for showcasing a package, but they are not so great with version control, like git. The reason being that a notebook is a very "rich" format since it contains output and other metadata. Changes to the notebook thus result in large diffs, which makes it harder to review the actual changes.

It is also common that packages include examples in the documentation, for example by using Documenter.jl @example-blocks. This is also great, but it is not quite as interactive as a notebook, for the users who prefer that.

Literate tries to solve the problems above by creating the output as a part of the doc build. Literate generates the output based on a single source file which makes it easier to maintain, test, and keep the manual and your example notebooks in sync.

diff --git a/latest/outputformats.html b/latest/outputformats.html index d0fd869..cb6d5bc 100644 --- a/latest/outputformats.html +++ b/latest/outputformats.html @@ -1,20 +1,48 @@ -4. Output formats · Examples.jl

4. Output formats

4. Output formats

4.1. Markdown output

#' # Markdown                                                  ┐
-#'                                                             │
-#' This line is treated as markdown, since it starts with #'   │
-#' The leading #' (including the space) is removed             ┘
+4. Output Formats · Literate.jl

4. Output Formats

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`:
 
-#' Here is an example with some code                           ]
+x = 1//3
+#-
+y = 2//5
 
-x = sin.(cos.([1, 2, 3]))                                      ┐
-y = x.^2 - x                                                   ┘

By default, CodeChunks written to Documenter @example blocks. For example, the code above would result in the following markdown:

# Markdown
+#' When adding `x` and `y` together we obtain a new rational number:
 
-This line is treated as markdown, since it starts with #'
-The leading #' (including the space) is removed
+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
 
-Here is an example with some code
+In julia rational numbers can be constructed with the `//` operator.
+Lets define two rational numbers, `x` and `y`:
 
-```@example
-x = sin.(cos.([1, 2, 3]))
-y = x.^2 - x
-```
Examples.markdownFunction.
Examples.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. 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.
source

4.2. Notebook output

Examples.notebookFunction.
Examples.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. 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.
  • 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.
source

4.3. Script output

Examples.scriptFunction.
Examples.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. 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.
source
+```@example name +x = 1//3 +``` + +```@example name +y = 2//5 +``` + +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.markdownFunction.
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.

source

4.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. Some of the output rendering can be controlled with keyword arguments to Literate.notebook:

Literate.notebookFunction.
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.

  • 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.

source

4.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.scriptFunction.
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.

source
diff --git a/latest/pipeline.html b/latest/pipeline.html index c0f807e..6d11149 100644 --- a/latest/pipeline.html +++ b/latest/pipeline.html @@ -1,5 +1,5 @@ -3. Processing pipeline · Examples.jl

3. Processing pipeline

3. Processing pipeline

The generation of output follows the same pipeline for all output formats:

  1. Pre-processing
  2. Parsing
  3. Document generation
  4. Post-processing
  5. Writing to file

3.1. Pre-processing

The first step is pre-processing of the input file. The file is read to a String and CRLF style line endings ("\r\n") are replaced with LF line endings ("\n") to simplify internal processing. The next step is to apply the user specified pre-processing function. See Custom pre- and post-processing.

Next the line filtering is performed, see Filtering lines, meaning that lines starting with #md, #nb or #jl are handled (either just the token itself is removed, or the full line, depending on the output target).

3.2. Parsing

After the preprocessing the file is parsed. The first step is to categorize each line and mark them as either markdown or code according to the rules described in the Syntax section. Lets consider the example from the previous section with each line categorized:

#' # Rational numbers                                                     <- markdown
+3. Processing pipeline · Literate.jl

3. Processing pipeline

3. Processing pipeline

The generation of output follows the same pipeline for all output formats:

  1. Pre-processing

  2. Parsing

  3. Document generation

  4. Post-processing

  5. Writing to file

3.1. Pre-processing

The first step is pre-processing of the input file. The file is read to a String. The first processing step is to apply the user specified pre-processing function, see Custom pre- and post-processing.

The next step is to perform all of the built-in default replacements. CRLF style line endings ("\r\n") are replaced with LF line endings ("\n") to simplify internal processing. Next, line filtering is performed, see Filtering Lines, meaning that lines starting with #md, #nb or #jl are handled (either just the token itself is removed, or the full line, depending on the output target). The last pre-processing step is to expand the convenience "macros" described in Default Replacements is expanded.

3.2. Parsing

After the preprocessing the file is parsed. The first step is to categorize each line and mark them as either markdown or code according to the rules described in the Syntax section. Lets consider the example from the previous section with each line categorized:

#' # Rational numbers                                                     <- markdown
 #'                                                                        <- markdown
 #' In julia rational numbers can be constructed with the `//` operator.   <- markdown
 #' Lets define two rational numbers, `x` and `y`:                         <- markdown
@@ -26,4 +26,4 @@ Lets define two rational numbers, `x` and `y`:

Chunk #2:

 y = 2 // 5

Chunk #3:

When adding `x` and `y` together we obtain a new rational number:

Chunk #4:

z = x + y

It is then up to the Document generation step to decide how these chunks should be treated.

Custom control over chunk splits

Sometimes it is convenient to be able to manually control how the chunks are split. For example, if you want to split a block of code into two, such that they end up in two different @example blocks or notebook cells. The #- token can be used for this purpose. All lines starting with #- are used as "chunk-splitters":

x = 1 // 3
 y = 2 // 5
 #-
-z = x + y

The example above would result in two consecutive code-chunks.

Tip

The rest of the line, after #-, is discarded, so it is possible to use e.g. #------------- as a chunk splitter, which may make the source code more readable.

3.3. Document generation

After the parsing it is time to generate the output. What is done in this step is very different depending on the output target, and it is describe in more detail in the Output format sections: Markdown output, Notebook output and Script output. In short, the following is happening:

  • Markdown output: markdown chunks are printed as-is, code chunks are put inside a code fence (defaults to @example-blocks),
  • Notebook output: markdown chunks are printed in markdown cells, code chunks are put in code cells,
  • Script output: markdown chunks are discarded, code chunks are printed as-is.

3.4. Post-processing

When the document is generated the user, again, has the option to hook-into the generation with a custom post-processing function. The reason is that one might want to change things that are only visible in the rendered document. See Custom pre- and post-processing.

3.5. Writing to file

The last step of the generation is writing to file. The result is written to $(outputdir)/$(name)(.md|.ipynb|.jl) where outputdir is the output directory supplied by the user (for example docs/generated), and name is a user supplied filename. It is recommended to add the output directory to .gitignore since the idea is that the generated documents will be generated as part of the build process rather than beeing files in the repo.

+z = x + y

The example above would result in two consecutive code-chunks.

Tip

The rest of the line, after #-, is discarded, so it is possible to use e.g. #------------- as a chunk splitter, which may make the source code more readable.

3.3. Document generation

After the parsing it is time to generate the output. What is done in this step is very different depending on the output target, and it is describe in more detail in the Output format sections: Markdown Output, Notebook Output and Script Output. In short, the following is happening:

3.4. Post-processing

When the document is generated the user, again, has the option to hook-into the generation with a custom post-processing function. The reason is that one might want to change things that are only visible in the rendered document. See Custom pre- and post-processing.

3.5. Writing to file

The last step of the generation is writing to file. The result is written to $(outputdir)/$(name)(.md|.ipynb|.jl) where outputdir is the output directory supplied by the user (for example docs/generated), and name is a user supplied filename. It is recommended to add the output directory to .gitignore since the idea is that the generated documents will be generated as part of the build process rather than beeing files in the repo.

diff --git a/latest/search.html b/latest/search.html index c0081e4..674f80b 100644 --- a/latest/search.html +++ b/latest/search.html @@ -1,2 +1,2 @@ -Search · Examples.jl

Search

Search

Number of results: loading...

+Search · Literate.jl

Search

Search

Number of results: loading...

diff --git a/latest/search_index.js b/latest/search_index.js index e44fe2f..ed0a449 100644 --- a/latest/search_index.js +++ b/latest/search_index.js @@ -13,7 +13,7 @@ var documenterSearchIndex = {"docs": [ "page": "1. Introduction", "title": "1. Introduction", "category": "section", - "text": "Welcome to the documentation for Examples.jl. A simplistic package to help you organize examples for you package documentation." + "text": "Welcome to the documentation for Literate – a simplistic package for Literate Programming." }, { @@ -21,7 +21,7 @@ var documenterSearchIndex = {"docs": [ "page": "1. Introduction", "title": "What?", "category": "section", - "text": "Examples.jl is a package that, based on a single source file, generates markdown, for e.g. Documenter.jl, Jupyter notebooks and uncommented scripts for documentation of your package.The main design goal is simplicity. It should be simple to use, and the syntax should be simple. In short all you have to do is to write a commented julia script!The package consists mainly of three functions, which all takes the same script file as input, but generates different output:Examples.markdown: generates a markdown file\nExamples.notebook: generates an (optionally executed) notebook\nExamples.script: generates a plain script file, removing everything that is not code" + "text": "Literate is a package that generate markdown pages (for e.g. Documenter.jl), and Jupyter notebooks, from the same source file. There is also an option to \"clean\" the source from all metadata, and produce a pure Julia script.The main design goal is simplicity. It should be simple to use, and the syntax should be simple. In short, all you have to do is to write a commented julia script!The public interface consists mainly of three functions, which all takes the same script file as input, but generates different output:Literate.markdown: generates a markdown file\nLiterate.notebook: generates an (optionally executed) notebook\nLiterate.script: generates a plain script file, removing all metadata and special syntax." }, { @@ -29,15 +29,7 @@ var documenterSearchIndex = {"docs": [ "page": "1. Introduction", "title": "Why?", "category": "section", - "text": "Examples are (probably) the best way to showcase your awesome package, and examples are often the best way for a new user to learn how to use it. It is therefore important that the documentation of your package contains examples for users to read and study. However, people are different, and we all prefer different ways of trying out a new package. Some people wants to RTFM, others want to explore the package interactively in, for example, a notebook, and some people wants to study the source code. The aim of Examples.jl is to make it easy to give the user all of these options, while still keeping maintenance to a minimum.It is quite common that packages have \"example notebooks\" to showcase the package. Notebooks are great for this, but they are not so great with version control, like git. The reason is that a notebook is a very \"rich\" format since it contains output and other metadata. Changes to the notebook thus result in large diffs, which makes it harder to review the actual changes.It is also common that packages include examples in the documentation, for example by using Documenter.jl @example-blocks. This is also great, but it is not quite as interactive as a notebook, for the users who prefer that.Examples.jl tries to solve the problems above by creating the output as a part of the doc build. Examples.jl generates the output from a single source file which makes it easier to maintain, test, and keep the manual and your example notebooks in sync." -}, - -{ - "location": "index.html#How?-1", - "page": "1. Introduction", - "title": "How?", - "category": "section", - "text": "TBD" + "text": "Examples are (probably) the best way to showcase your awesome package, and examples are often the best way for a new user to learn how to use it. It is therefore important that the documentation of your package contains examples for users to read and study. However, people are different, and we all prefer different ways of trying out a new package. Some people wants to RTFM, others want to explore the package interactively in, for example, a notebook, and some people wants to study the source code. The aim of Literate is to make it easy to give the user all of these options, while still keeping maintenance to a minimum.It is quite common that packages have \"example notebooks\" to showcase the package. Notebooks are great for showcasing a package, but they are not so great with version control, like git. The reason being that a notebook is a very \"rich\" format since it contains output and other metadata. Changes to the notebook thus result in large diffs, which makes it harder to review the actual changes.It is also common that packages include examples in the documentation, for example by using Documenter.jl @example-blocks. This is also great, but it is not quite as interactive as a notebook, for the users who prefer that.Literate tries to solve the problems above by creating the output as a part of the doc build. Literate generates the output based on a single source file which makes it easier to maintain, test, and keep the manual and your example notebooks in sync." }, { @@ -53,7 +45,7 @@ var documenterSearchIndex = {"docs": [ "page": "2. File Format", "title": "2. File Format", "category": "section", - "text": "The source file format for Examples.jl is a regular, commented, julia (.jl) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. include, to make sure the examples stay up do date with other changes in your package." + "text": "The source file format for Literate is a regular, commented, julia (.jl) scripts. The idea is that the scripts also serve as documentation on their own and it is also simple to include them in the test-suite, with e.g. include, to make sure the examples stay up do date with other changes in your package." }, { @@ -61,15 +53,23 @@ var documenterSearchIndex = {"docs": [ "page": "2. File Format", "title": "2.1. Syntax", "category": "section", - "text": "The basic syntax is simple:lines starting with #\' is treated as markdown,\nall other lines are treated as julia code.The reason for using #\' instead of # is that we want to be able to use # as comments, just as in a regular script. Lets look at a simple example:#\' # 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\ny = 2//5\n\n#\' When adding `x` and `y` together we obtain a new rational number:\n\nz = x + yIn the lines #\' we can use regular markdown syntax, for example the # used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:The script is valid julia, which means that we can include it and the example will run\nThe script is \"self-explanatory\", i.e. the markdown lines works as comments and thus serve as good documentation on its own.For simple use this is all you need to know, the script above is valid. Let\'s take a look at what the above snippet would generate, with default settings:Examples.markdown: leading #\' are removed, and code lines are wrapped in @example-blocks:\n# Rational numbers\n\nIn julia rational numbers can be constructed with the `//` operator.\nLets define two rational numbers, `x` and `y`:\n\n```@example filename\nx = 1//3\ny = 2//5\n```\n\nWhen adding `x` and `y` together we obtain a new rational number:\n\n```@example filename\nz = x + y\n```\nExamples.notebook: leading #\' are removed, markdown lines are placed in \"markdown\" cells, and code lines in \"code\" cells:\n │ # 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\n │ y = 2//5\n\nOut [1]: │ 2//5\n\n │ When adding `x` and `y` together we obtain a new rational number:\n\nIn [2]: │ z = x + y\n\nOut [2]: │ 11//15\nExamples.script: all lines starting with #\' are removed:\nx = 1//3\ny = 2//5\n\nz = x + y" + "text": "The basic syntax is simple:lines starting with #\' is treated as markdown,\nall other lines are treated as julia code.The reason for using #\' instead of # is that we want to be able to use # as comments, just as in a regular script. Lets look at a simple example:#\' # 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\ny = 2//5\n\n#\' When adding `x` and `y` together we obtain a new rational number:\n\nz = x + yIn the lines #\' we can use regular markdown syntax, for example the # used for the heading and the backticks for formatting code. The other lines are regular julia code. We note a couple of things:The script is valid julia, which means that we can include it and the example will run (for example in the test/runtests.jl script, to include the example in the test suite).\nThe script is \"self-explanatory\", i.e. the markdown lines works as comments and thus serve as good documentation on its own.For simple use this is all you need to know. The following additional special syntax can also be used:#md, #nb, #jl: tags for filtering of lines, see Filtering Lines.\n#-: tag for manually controlling chunk-splits, see Custom control over chunk splits.There is also some default convenience replacements that will always be performed, see Default Replacements." }, { - "location": "fileformat.html#Filtering-lines-1", + "location": "fileformat.html#Filtering-Lines-1", "page": "2. File Format", "title": "2.2. Filtering Lines", "category": "section", - "text": "It is possible to filter out lines depending on the output format. For this purpose, there are three different \"tokens\" that can be placed on the start of the line:#md: markdown output only,\n#nb: notebook output only,\n#jl: script output only.Lines starting with one of these tokens are filtered out in the preprocessing step.Suppose, for example, that we want to include a docstring within a @docs block using Documenter. Obviously we don\'t want to include this in the notebook, since @docs is Documenter syntax that the notebook will not understand. This is a case where we can prepend #md to those lines:#md #\' ```@docs\n#md #\' Examples.markdown\n#md #\' Examples.notebook\n#md #\' Examples.markdown\n#md #\' ```The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading #md from the lines. Beware that the space after the tag is also removed." + "text": "It is possible to filter out lines depending on the output format. For this purpose, there are three different \"tokens\" that can be placed on the start of the line:#md: markdown output only,\n#nb: notebook output only,\n#jl: script output only.Lines starting with one of these tokens are filtered out in the preprocessing step.Suppose, for example, that we want to include a docstring within a @docs block using Documenter. Obviously we don\'t want to include this in the notebook, since @docs is Documenter syntax that the notebook will not understand. This is a case where we can prepend #md to those lines:#md #\' ```@docs\n#md #\' Literate.markdown\n#md #\' Literate.notebook\n#md #\' Literate.markdown\n#md #\' ```The lines in the example above would be filtered out in the preprocessing step, unless we are generating a markdown file. When generating a markdown file we would simple remove the leading #md from the lines. Beware that the space after the tag is also removed." +}, + +{ + "location": "fileformat.html#Default-Replacements-1", + "page": "2. File Format", + "title": "2.3. Default Replacements", + "category": "section", + "text": "The following convenience \"macros\" are always expanded:@__NAME__\nexpands to the name keyword argument to Literate.markdown, Literate.notebook and Literate.script (defaults to the filename of the input file).\n@__REPO__ROOT_URL__\nexpands to https://github.com/$(ENV[\"TRAVIS_REPO_SLUG\"])/blob/master/ and is a convenient way to use when you want to link to files outside the doc-build directory. For example @__REPO__ROOT_URL__src/Literate.jl would link to the source of the Literate module.\n@__NBVIEWER_ROOT_URL__\nexpands to https://nbviewer.jupyter.org/github/$(ENV[\"TRAVIS_REPO_SLUG\"])/blob/gh-pages/$(folder)/ where folder is the folder that Documenter.deploydocs deploys too. This can be used if you want a link that opens the generated notebook in http://nbviewer.jupyter.org/." }, { @@ -93,7 +93,7 @@ var documenterSearchIndex = {"docs": [ "page": "3. Processing pipeline", "title": "3.1. Pre-processing", "category": "section", - "text": "The first step is pre-processing of the input file. The file is read to a String and CRLF style line endings (\"\\r\\n\") are replaced with LF line endings (\"\\n\") to simplify internal processing. The next step is to apply the user specified pre-processing function. See Custom pre- and post-processing.Next the line filtering is performed, see Filtering lines, meaning that lines starting with #md, #nb or #jl are handled (either just the token itself is removed, or the full line, depending on the output target)." + "text": "The first step is pre-processing of the input file. The file is read to a String. The first processing step is to apply the user specified pre-processing function, see Custom pre- and post-processing.The next step is to perform all of the built-in default replacements. CRLF style line endings (\"\\r\\n\") are replaced with LF line endings (\"\\n\") to simplify internal processing. Next, line filtering is performed, see Filtering Lines, meaning that lines starting with #md, #nb or #jl are handled (either just the token itself is removed, or the full line, depending on the output target). The last pre-processing step is to expand the convenience \"macros\" described in Default Replacements is expanded." }, { @@ -117,7 +117,7 @@ var documenterSearchIndex = {"docs": [ "page": "3. Processing pipeline", "title": "3.3. Document generation", "category": "section", - "text": "After the parsing it is time to generate the output. What is done in this step is very different depending on the output target, and it is describe in more detail in the Output format sections: Markdown output, Notebook output and Script output. In short, the following is happening:Markdown output: markdown chunks are printed as-is, code chunks are put inside a code fence (defaults to @example-blocks),\nNotebook output: markdown chunks are printed in markdown cells, code chunks are put in code cells,\nScript output: markdown chunks are discarded, code chunks are printed as-is." + "text": "After the parsing it is time to generate the output. What is done in this step is very different depending on the output target, and it is describe in more detail in the Output format sections: Markdown Output, Notebook Output and Script Output. In short, the following is happening:Markdown output: markdown chunks are printed as-is, code chunks are put inside a code fence (defaults to @example-blocks),\nNotebook output: markdown chunks are printed in markdown cells, code chunks are put in code cells,\nScript output: markdown chunks are discarded, code chunks are printed as-is." }, { @@ -138,66 +138,66 @@ var documenterSearchIndex = {"docs": [ { "location": "outputformats.html#", - "page": "4. Output formats", - "title": "4. Output formats", + "page": "4. Output Formats", + "title": "4. Output Formats", "category": "page", "text": "" }, { - "location": "outputformats.html#Output-formats-1", - "page": "4. Output formats", - "title": "4. Output formats", + "location": "outputformats.html#Output-Formats-1", + "page": "4. Output Formats", + "title": "4. Output Formats", "category": "section", - "text": "" + "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." }, { - "location": "outputformats.html#Examples.markdown", - "page": "4. Output formats", - "title": "Examples.markdown", + "location": "outputformats.html#Literate.markdown", + "page": "4. Output Formats", + "title": "Literate.markdown", "category": "function", - "text": "Examples.markdown(inputfile, outputdir; kwargs...)\n\nGenerate a markdown file from inputfile and write the result to the directoryoutputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .md. name is also used to name all the @example blocks. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\ndocumenter: 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.\ncodefence: A Pair of opening and closing code fence. Defaults to\n\"```@example $(name)\" => \"```\"\nif documenter = true and\n\"```julia\" => \"```\"\nif documenter = false.\n\n\n\n\n\n" + "text": "Literate.markdown(inputfile, outputdir; kwargs...)\n\nGenerate a markdown file from inputfile and write the result to the directoryoutputdir.\n\nKeyword arguments:\n\nname: 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.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\ndocumenter: 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.\ncodefence: A Pair of opening and closing code fence. Defaults to\n\"```@example $(name)\" => \"```\"\nif documenter = true and\n\"```julia\" => \"```\"\nif documenter = false.\n\n\n\n" }, { - "location": "outputformats.html#Markdown-output-1", - "page": "4. Output formats", - "title": "4.1. Markdown output", + "location": "outputformats.html#Markdown-Output-1", + "page": "4. Output Formats", + "title": "4.1. Markdown Output", "category": "section", - "text": "#\' # Markdown ┐\n#\' │\n#\' This line is treated as markdown, since it starts with #\' │\n#\' The leading #\' (including the space) is removed ┘\n\n#\' Here is an example with some code ]\n\nx = sin.(cos.([1, 2, 3])) ┐\ny = x.^2 - x ┘By default, CodeChunks written to Documenter @example blocks. For example, the code above would result in the following markdown:# Markdown\n\nThis line is treated as markdown, since it starts with #\'\nThe leading #\' (including the space) is removed\n\nHere is an example with some code\n\n```@example\nx = sin.(cos.([1, 2, 3]))\ny = x.^2 - x\n```Examples.markdown" + "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" }, { - "location": "outputformats.html#Examples.notebook", - "page": "4. Output formats", - "title": "Examples.notebook", + "location": "outputformats.html#Literate.notebook", + "page": "4. Output Formats", + "title": "Literate.notebook", "category": "function", - "text": "Examples.notebook(inputfile, outputdir; kwargs...)\n\nGenerate a notebook from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .ipynb. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\nexecute: a boolean deciding if the generated notebook should also be executed or not. Defaults to true.\ndocumenter: 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.\n\n\n\n\n\n" + "text": "Literate.notebook(inputfile, outputdir; kwargs...)\n\nGenerate a notebook from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .ipynb. name is also used to replace @__NAME__. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\nexecute: a boolean deciding if the generated notebook should also be executed or not. Defaults to true.\ndocumenter: 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.\n\n\n\n" }, { - "location": "outputformats.html#Notebook-output-1", - "page": "4. Output formats", - "title": "4.2. Notebook output", + "location": "outputformats.html#Notebook-Output-1", + "page": "4. Output Formats", + "title": "4.2. Notebook Output", "category": "section", - "text": "Examples.notebook" + "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. Some of the output rendering can be controlled with keyword arguments to Literate.notebook:Literate.notebook" }, { - "location": "outputformats.html#Examples.script", - "page": "4. Output formats", - "title": "Examples.script", + "location": "outputformats.html#Literate.script", + "page": "4. Output Formats", + "title": "Literate.script", "category": "function", - "text": "Examples.script(inputfile, outputdir; kwargs...)\n\nGenerate a plain script file from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .jl. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\n\n\n\n\n\n" + "text": "Literate.script(inputfile, outputdir; kwargs...)\n\nGenerate a plain script file from inputfile and write the result to outputdir.\n\nKeyword arguments:\n\nname: name of the output file, excluding .jl. name is also used to replace @__NAME__. Defaults to the filename of inputfile.\npreprocess, postprocess: custom pre- and post-processing functions, see the Custom pre- and post-processing section of the manual. Defaults to identity.\ndocumenter: 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.\n\n\n\n" }, { - "location": "outputformats.html#Script-output-1", - "page": "4. Output formats", - "title": "4.3. Script output", + "location": "outputformats.html#Script-Output-1", + "page": "4. Output Formats", + "title": "4.3. Script Output", "category": "section", - "text": "Examples.script" + "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" }, { @@ -213,7 +213,7 @@ var documenterSearchIndex = {"docs": [ "page": "5. Custom pre- and post-processing", "title": "5. Custom pre- and post-processing", "category": "section", - "text": "Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing line filtering there might be situations where you need to manually hook into the generation and change things. In Examples.jl this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.All of the generators (Examples.markdown, Examples.notebook and Examples.script) accepts preprocess and postprocess keyword arguments. The default \"transformation\" is the identity function. The input to the transformation functions is a String, and the output should be the transformed String.preprocess is sent the raw input that is read from the source file (modulo the default line ending transformation). postprocess is given different things depending on the output: For markdown and script output postprocess is given the content String just before writing it to the output file, but for notebook output postprocess is given the dictionary representing the notebook, since, in general, this is more useful.As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a preprocess function that splices the date into the source for us. Consider the following source file:#\' # Example\n#\' This example was generated DATEOFTODAY\n\nx = 1 // 3where DATEOFTODAY is a placeholder, to make it easier for our preprocess function to find the location. Now, lets define the preprocess function, for examplefunction update_date(content)\n content = replace(content, \"DATEOFTODAY\" => Date(now()))\n return content\nendwhich would replace every occurrence of \"DATEOFTODAY\" with the current date. We would now simply give this function to the generator, for example:Examples.markdown(\"input.jl\", \"outputdir\"; preprocess = update_date)" + "text": "Since all packages are different, and may have different demands on how to create a nice example for the documentation it is important that the package maintainer does not feel limited by the by default provided syntax that this package offers. While you can generally come a long way by utilizing line filtering there might be situations where you need to manually hook into the generation and change things. In Literate this is done by letting the user supply custom pre- and post-processing functions that may do transformation of the content.All of the generators (Literate.markdown, Literate.notebook and Literate.script) accepts preprocess and postprocess keyword arguments. The default \"transformation\" is the identity function. The input to the transformation functions is a String, and the output should be the transformed String.preprocess is sent the raw input that is read from the source file (modulo the default line ending transformation). postprocess is given different things depending on the output: For markdown and script output postprocess is given the content String just before writing it to the output file, but for notebook output postprocess is given the dictionary representing the notebook, since, in general, this is more useful.As an example, lets say we want to splice the date of generation into the output. We could of course update our source file before generating the docs, but we could instead use a preprocess function that splices the date into the source for us. Consider the following source file:#\' # Example\n#\' This example was generated DATEOFTODAY\n\nx = 1 // 3where DATEOFTODAY is a placeholder, to make it easier for our preprocess function to find the location. Now, lets define the preprocess function, for examplefunction update_date(content)\n content = replace(content, \"DATEOFTODAY\" => Date(now()))\n return content\nendwhich would replace every occurrence of \"DATEOFTODAY\" with the current date. We would now simply give this function to the generator, for example:Literate.markdown(\"input.jl\", \"outputdir\"; preprocess = update_date)" }, { @@ -229,7 +229,31 @@ var documenterSearchIndex = {"docs": [ "page": "6. Interaction with Documenter.jl", "title": "6. Interaction with Documenter.jl", "category": "section", - "text": "Examples.jl can be used for any purpose, it spits out regular markdown files, and notebooks. Typically, though, these files will be used to render documentation for your package. The generators (Examples.markdown, Examples.notebook and Examples.script) supports a keyword argument documenter that lets the generator perform some extra things, keeping in mind that the generated files will, eventually, be used with Documenter.jl. So lets take a look at what will happen if we set documenter = true:Examples.markdown:The default code fence will change from\n```julia\n# code\n```\nto Documenters @example blocks:\n```@examples $(name)\n# code\n```\nThe following @meta block will be added to the top of the markdown page, which redirects the \"Edit on GitHub\" link on the top of the page to the source file rather than the generated .md file:\n```@meta\nEditURL = \"$(relpath(inputfile, outputdir))\"\n```Examples.notebook:Documenter style @refs and @id will be removed. This means that you can use @ref and @id in the source file without them leaking to the notebook.\nDocumenter style markdown math\n```math\n\\int f dx\n```\nis replaced with notebook compatible\n\\begin{equation}\n\\int f dx\n\\end{equation}" + "text": "Literate can be used for any purpose, it spits out regular markdown files, and notebooks. Typically, though, these files will be used to render documentation for your package. The generators (Literate.markdown, Literate.notebook and Literate.script) supports a keyword argument documenter that lets the generator perform some extra things, keeping in mind that the source code have been written with Documenter.jl in mind. So lets take a look at what will happen if we set documenter = true:" +}, + +{ + "location": "documenter.html#[Literate.markdown](@ref):-1", + "page": "6. Interaction with Documenter.jl", + "title": "Literate.markdown:", + "category": "section", + "text": "The default code fence will change from\n```julia\n# code\n```\nto Documenters @example blocks:\n```@examples $(name)\n# code\n```\nThe following @meta block will be added to the top of the markdown page, which redirects the \"Edit on GitHub\" link on the top of the page to the source file rather than the generated .md file:\n```@meta\nEditURL = \"$(relpath(inputfile, outputdir))\"\n```" +}, + +{ + "location": "documenter.html#[Literate.notebook](@ref):-1", + "page": "6. Interaction with Documenter.jl", + "title": "Literate.notebook:", + "category": "section", + "text": "Documenter style @refs and @id will be removed. This means that you can use @ref and @id in the source file without them leaking to the notebook.\nDocumenter style markdown math\n```math\n\\int f dx\n```\nis replaced with notebook compatible\n\\begin{equation}\n\\int f dx\n\\end{equation}" +}, + +{ + "location": "documenter.html#[Literate.script](@ref):-1", + "page": "6. Interaction with Documenter.jl", + "title": "Literate.script:", + "category": "section", + "text": "Documenter style @refs and @id will be removed. This means that you can use @ref and @id in the source file without them leaking to the script." }, { @@ -237,7 +261,7 @@ var documenterSearchIndex = {"docs": [ "page": "7. Example", "title": "7. Example", "category": "page", - "text": "EditURL = \"https://github.com/fredrikekre/Examples.jl/blob/master/examples/example.jl\"" + "text": "EditURL = \"https://github.com/fredrikekre/Literate.jl/blob/master/examples/example.jl\"" }, { @@ -245,15 +269,31 @@ var documenterSearchIndex = {"docs": [ "page": "7. Example", "title": "7. Example", "category": "section", - "text": "This is an example for Examples.jl. The source file can be found here. The generated markdown can be found here: example.md, the generated notebook can be found here: example.ipynb, and the plain script output can be found here: example.jl." + "text": "This is an example generated with Literate based on this source file: example.jl. You are seeing the html-output which Documenter have generated based on a markdown file generated with Literate. The corresponding notebook can be found here: example.ipynb, and the plain script output can be found here: example.jl.It is recommended to have the source file available when reading this, to better understand how the syntax in the source file corresponds to the output you are seeing." +}, + +{ + "location": "generated/example.html#Basic-syntax-1", + "page": "7. Example", + "title": "Basic syntax", + "category": "section", + "text": "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:x = 1//3\ny = 2//5In markdown sections we can use markdown syntax. For example, we can write text in italic font, text in bold font and use links.It is possible to filter lines by starting it with #md, #nb or #jl for markdown, notebook and script output only, respectively. This line is filtered out for notebook and script output.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 display the output of the following operations we may insert #- in between. These two code blocks will now end up in different @example-blocks in the markdown output, and two different notebook cells in the notebook output.x + yx * y" +}, + +{ + "location": "generated/example.html#Custom-processing-1", + "page": "7. Example", + "title": "Custom processing", + "category": "section", + "text": "It is possible to give Literate custom pre- and post-processing functions. For example, here we insert two placeholders, which we will replace with something else at time of generation. We have here replaced our placeholders with z and 1.0 + 2.0im:z = 1.0 + 2.0im" }, { - "location": "generated/example.html#Rational-numbers-in-Julia-1", + "location": "generated/example.html#documenter-interaction-1", "page": "7. Example", - "title": "Rational numbers in Julia", + "title": "Documenter.jl interaction", "category": "section", - "text": "Rational number in julia can be constructed with the // operator:x = 1//3\ny = 2//5Operations with rational number returns a new rational numberx + yx * yEverytime a rational number is constructed, it will be simplified using the gcd function, for example 2//4 simplifies to 1//2:2//4and 2//4 + 2//4 simplifies to 1//1:2//4 + 2//4" + "text": "In the source file it is possible to use Documenter.jl style references, such as @ref and @id. These will be filtered out in the notebook output. For example, here is a link, but it is only visible as a link if you are reading the markdown output. We can also use equations:int f(x) dxusing Documenters math syntax. This is automatically changed to \\begin{equation} ... \\end{equation} in the notebook output to display correctly in the notebook too." }, ]}