Working with Jupyter notebooks

Weaving from Jupyter notebooks

Weave supports using Jupyter Notebooks as input format. This means you can weave notebooks to any supported formats; by default, it will be weaved to HTML.

weave("notebook.ipynb") # will be weaved to HTML
Warning

You can't use chunk options with notebooks.

Output to Jupyter notebooks

As of Weave 0.5.1. there is new notebook method to convert Weave documents to Jupyter notebooks using nbconvert.

Weave.notebookFunction
notebook(source::AbstractString; kwargs...)

Convert Weave document source to Jupyter Notebook and execute the code using nbconvert. Ignores all chunk options.

Keyword options

  • out_path::Union{Symbol,AbstractString} = :pwd: Path where the output is generated can be either of:
    • :doc: Path of the source document
    • :pwd: Julia working directory (default)
    • "somepath": String of output directory e.g. "~/outdir", or of filename e.g. "~/outdir/outfile.tex"
  • timeout = -1: nbconvert cell timeout in seconds. Defaults to -1 (no timeout)
  • nbconvert_options::AbstractString = "": String of additional options to pass to nbconvert, such as "--allow-errors"
  • jupyter_path::AbstractString = "jupyter": Path/command for the Jupyter you want to use. Defaults to "jupyter", which runs whatever is linked/alias to that
Warning

The code is not executed by Weave, but by nbconvert. This means that the output doesn't necessarily always work properly; see #116.

Note

In order to just convert Weave document to Jupyter Notebook, use convert_doc instead.

source

You can specify jupyter used to execute the notebook with the jupyter_path keyword argument (this defaults to the "jupyter", i.e. whatever you have linked to that location).

Instead, you might want to use the convert_doc method below and run the code in Jupyter.

Converting between formats

You can convert between all supported input formats using the convert_doc function.

To convert from script to notebook:

convert_doc("examples/FIR_design.jl", "FIR_design.ipynb")

and from notebook to Markdown use:

convert_doc("FIR_design.ipynb", "FIR_design.jmd")
Weave.convert_docFunction
convert_doc(infile::AbstractString, outfile::AbstractString; outformat::Union{Nothing,AbstractString} = nothing)

Convert Weave documents between different formats

  • infile: Path of the input document
  • outfile: Path of the output document
  • outformat = nothing: Output document format (optional). By default (i.e. given nothing) Weave will try to automatically detect it from the outfile's extension. You can also specify either of "script", "markdown", "notebook", or "noweb"
source