Merge pull request #295 from JunoLab/avi/moretypes

more type annotate APIs
pull/296/head
Shuhei Kadowaki 2020-03-27 19:12:51 +09:00 committed by GitHub
commit b6b4082977
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 207 additions and 175 deletions

View File

@ -1,9 +1,8 @@
language: julia
julia:
- 1.0
- 1.3
- 1.4
- 1 # current stable
- 1.0 # lts
- nightly
script:
@ -15,11 +14,10 @@ after_success:
jobs:
allow_failures:
- julia: 1.4
- julia: nightly
include:
- stage: "Documentation"
julia: 1.3
julia: 1
os: linux
script:
- julia --project=doc/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()));

View File

@ -10,34 +10,34 @@ Weave currently supports the following chunk options with the following defaults
## Options for code
* `echo = true`. Echo the code in the output document. If `false` the source code will be hidden.
* `results = "markup"`. The output format of the printed results. "markup" for literal block, "hidden" for hidden results or anything else for raw output (I tend to use tex for Latex and rst for rest. Raw output is useful if you want to e.g. create tables from code chunks.
* `eval = true`. Evaluate the code chunk. If false the chunk wont be executed.
* `term=false`. If true the output emulates a REPL session. Otherwise only stdout and figures will be included in output.
* `label`. Chunk label, will be used for figure labels in Latex as fig:label
* `wrap = true`. Wrap long lines from output.
* `line_width = 75`. Line width for wrapped lines.
* `cache = false`. Cache results, depends on `cache` parameter on `weave` function.
* `hold = false`. Hold all results until the end of the chunk.
* `tangle = true`. Set tangle to false to exclude chunk from tangled code.
- `echo = true`: Echo the code in the output document. If `false` the source code will be hidden.
- `results = "markup"`: The output format of the printed results. `"markup"` for literal block, `"hidden"` for hidden results, or anything else for raw output (I tend to use `"tex"` for Latex and `"rst"` for rest). Raw output is useful if you want to e.g. create tables from code chunks.
- `eval = true`: Evaluate the code chunk. If `false` the chunk wont be executed.
- `term = false`: If `true` the output emulates a REPL session. Otherwise only stdout and figures will be included in output.
- `label = nothing`: Chunk label, will be used for figure labels in Latex as `fig:label`.
- `wrap = true`: Wrap long lines from output.
- `line_width = 75`: Line width for wrapped lines.
- `cache = false`: Cache results, depending on `cache` parameter on `weave` function.
- `hold = false`: Hold all results until the end of the chunk.
- `tangle = true`: Set tangle to `false` to exclude chunk from tangled code.
## Options for figures
* `fig_width`. Figure width passed to plotting library e.g. `800`
* `fig_height` Figure height passed to plotting library
* `out_width`. Width of saved figure in output markup e.g. "50%", "12cm", `0.5\linewidth`
* `out_height`. Height of saved figure in output markup
* `dpi`=96. Resolution of saved figures.
* `fig_cap`. Figure caption.
* `label`. Chunk label, will be used for figure labels in Latex as fig:label
* `fig_ext`. File extension (format) of saved figures.
* `fig_pos="!h"`. Figure position in Latex.
* `fig_env="figure"`. Figure environment in Latex.
- `fig_width = 6`: Figure width passed to plotting library.
- `fig_height = 4`: Figure height passed to plotting library.
- `out_width`: Width of saved figure in output markup e.g. `"50%"`, `"12cm"`, `0.5\linewidth`
- `out_height`: Height of saved figure in output markup
- `dpi = 96`: Resolution of saved figures.
- `fig_cap`: Figure caption.
- `label`: Chunk label, will be used for figure labels in Latex as fig:label
- `fig_ext`: File extension (format) of saved figures.
- `fig_pos = "!h"`: Figure position in Latex, e.g.: `"ht"`.
- `fig_env = "figure"`: Figure environment in Latex.
## Set default chunk options
You can set the default chunk options (and `weave` arguments) for a document using the YAML header `options` field. e.g to set the default `out_width` of all figures you can use:
You can set the default chunk options (and `weave` arguments) for a document using the YAML header `options` field. E.g. to set the default `out_width` of all figures you can use:
```yaml
---

View File

@ -21,14 +21,13 @@ see [#116](https://github.com/mpastell/Weave.jl/issues/116).
notebook
```
You might want to use the `convert_doc` method below instead and run the code in Jupyter.
You might want to use the [`convert_doc`](@ref) method below instead and run the code in Jupyter.
You can select the `jupyter` used to execute the notebook with the `jupyter_path` argument (this defaults to the string "jupyter," i.e., whatever you have linked to that location.)
## Converting between formats
You can convert between all supported input formats using the `convert_doc`
function.
You can convert between all supported input formats using the [`convert_doc`](@ref) function.
To convert from script to notebook:
@ -43,5 +42,5 @@ convert_doc("FIR_design.ipynb", "FIR_design.jmd")
```
```@docs
convert_doc(infile::String, outfile::String)
convert_doc(infile::AbstractString, outfile::AbstractString)
```

View File

@ -1,22 +1,24 @@
# Using Weave
You can write your documentation and code in input document using Markdown, Noweb or script
syntax and use `weave` function to execute to document to capture results and figures.
syntax and use [`weave`](@ref) function to execute to document to capture results and figures.
## Weave
Weave document with markup and julia code using `Plots.jl` for plots,
`out_path = :pwd` makes the results appear in the current working directory.
> A prepared example
```julia
#First add depencies for the example
# First add depencies for the example
using Pkg; Pkg.add.(["Plots", "DSP"])
using Weave
weave(joinpath(dirname(pathof(Weave)), "../examples", "FIR_design.jmd"), out_path=:pwd)
```
```@docs
weave(source)
weave
```
## Tangle
@ -24,7 +26,7 @@ weave(source)
Tangling extracts the code from document:
```@docs
tangle(source)
tangle
```
## Supported output formats
@ -43,12 +45,12 @@ return "pandoc"
You can get a list of supported output formats:
```@example
using Weave # hide
list_out_formats()
```@docs
list_out_formats
```
```@docs
```@example
using Weave # hide
list_out_formats()
```
@ -96,7 +98,7 @@ or
! juliacode
```
syntax. Using the `j code` syntax you can insert code anywhere in a line and with
syntax. Using the `j code` syntax you can insert code anywhere in a line and with
the `!` syntax the whole line after `!` will be executed. The code will be replaced
with captured output in the weaved document.
@ -169,8 +171,8 @@ options:
## Passing arguments to documents
You can pass arguments as dictionary to the weaved document using the `args` argument
to `weave`. The dictionary will be available as `WEAVE_ARGS` variable in the document.
You can pass arguments as `Dict` to the weaved document using the `args` argument
to `weave`. The arguments will be available as `WEAVE_ARGS` variable in the document.
This makes it possible to create the same report easily for e.g. different
date ranges of input data from a database or from files with similar format giving the

View File

@ -1,5 +1,6 @@
module Weave
import Highlights
using Mustache
using Requires
function __init__()
@ -8,7 +9,7 @@ function __init__()
end
"""
`list_out_formats()`
list_out_formats()
List supported output formats
"""
@ -20,15 +21,23 @@ end
"""
`tangle(source ; out_path=:doc, informat="noweb")`
tangle(source::AbstractString; kwargs...)
Tangle source code from input document to .jl file.
* `informat`: `"noweb"` of `"markdown"`
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory, `"somepath"`, directory name as a string e.g `"/home/mpastell/weaveout"`
or filename as string e.g. ~/outpath/outfile.jl.
## Keyword options
- `informat::Union{Symbol,AbstractString} = :auto`: Input document format. `:auto` will set it automatically based on file extension. You can also specify either of `"script"`, `"markdown"`, `"notebook"`, or `"noweb"`
- `out_path::Union{Symbol,AbstractString} = :doc`: Path where the output is generated can be either of:
* `:doc`: Path of the source document (default)
* `:pwd`: Julia working directory
* `"somepath"`: `String` of output directory e.g. `"~/outdir"`, or of filename e.g. `"~/outdir/outfile.tex"`
"""
function tangle(source ; out_path=:doc, informat=:auto)
function tangle(
source::AbstractString;
out_path::Union{Symbol,AbstractString} = :doc,
informat::Union{Symbol,AbstractString} = :auto
)
doc = read_doc(source, informat)
doc.cwd = get_cwd(doc, out_path)
@ -50,60 +59,62 @@ end
"""
weave(source ; doctype = :auto,
informat=:auto, out_path=:doc, args = Dict(),
mod::Union{Module, Symbol} = Main,
fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache=:off,
template = nothing, highlight_theme = nothing, css = nothing,
pandoc_options = "",
latex_cmd = "xelatex")
weave(source::AbstractString; kwargs...)
Weave an input document to output file.
* `doctype`: :auto = set based on file extension or specify one of the supported formats.
See `list_out_formats()`
* `informat`: :auto = set based on file extension or set to `"noweb"`, `"markdown"` or `script`
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`:
Julia working directory, `"somepath"`: output directory as a String e.g `"/home/mpastell/weaveout"` or filename as
string e.g. ~/outpath/outfile.tex.
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS
* `mod`: Module where Weave `eval`s code. Defaults to `:sandbox`
to create new sandbox module, you can also pass a module e.g. `Main`.
* `fig_path`: where figures will be generated, relative to out_path
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
* `cache_path`: where of cached output will be saved.
* `cache`: controls caching of code: `:off` = no caching, `:all` = cache everything,
`:user` = cache based on chunk options, `:refresh`, run all code chunks and save new cache.
* `throw_errors`: if `false` errors are included in output document and the whole document is
executed. if `true` errors are thrown when they occur.
* `template`: Template (file path) or MustacheTokens for md2html or md2tex formats.
* `highlight_theme`: Theme (Highlights.AbstractTheme) for used syntax highlighting
* `css`: CSS (file path) used for md2html format
* `pandoc_options`: String array of options to pass to pandoc for `pandoc2html` and
`pandoc2pdf` formats e.g. ["--toc", "-N"]
* `latex_cmd`: the command used to make pdf from .tex
* `latex_keep_unicode`: if set to true (default is false), do not convert unicode characters to their
respective latex representation. This is especially useful if a font and tex-engine with support for unicode
characters are used.
## Keyword options
**Note:** Run Weave from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
- `doctype::Union{Symbol,AbstractString} = :auto`: Output document format. `:auto` will set it automatically based on file extension. You can also manually specify it; see [`list_out_formats()`](@ref) for the supported formats
- `informat::Union{Symbol,AbstractString} = :auto`: Input document format. `:auto` will set it automatically based on file extension. You can also specify either of `"script"`, `"markdown"`, `"notebook"`, or `"noweb"`
- `out_path::Union{Symbol,AbstractString} = :doc`: Path where the output is generated can be either of:
* `:doc`: Path of the source document (default)
* `:pwd`: Julia working directory
* `"somepath"`: `String` of output directory e.g. `"~/outdir"`, or of filename e.g. `"~/outdir/outfile.tex"`
- `args::Dict = Dict()`: Arguments to be passed to the weaved document; will be available as `WEAVE_ARGS` in the document
- `mod::Union{Module,Symbol} = :sandbox`: Module where Weave `eval`s code. Defaults to `:sandbox` to create new sandbox module. You also can also pass a `Module` e.g. `Main`
- `fig_path::AbstractString = "figures"`: Where figures will be generated, relative to `out_path`
- `fig_ext::Union{Nothing,AbstractString} = nothing`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`
- `cache_path::AbstractString = "cache"`: Where of cached output will be saved
- `cache::Symbol = :off`: Controls caching of code:
* `:off` means no caching (default)
* `:all` caches everything
* `:user` caches based on chunk options
* `:refresh` runs all code chunks and save new cache
- `throw_errors::Bool = false`: If `false` errors are included in output document and the whole document is executed. If `true` errors are thrown when they occur
- `template::Union{Nothing,AbstractString,Mustache.MustacheTokens} = nothing`: Template (file path) or `Mustache.MustacheTokens`s for `md2html` or `md2tex` formats
- `highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing`: Theme used for syntax highlighting (defaults to `Highlights.Themes.DefaultTheme`)
- `css::Union{Nothing,AbstractString} = nothing`: Path of a CSS file used for md2html format
- `pandoc_options::Vector{<:AbstractString} = String[]`: `String`s of options to pass to pandoc for `pandoc2html` and `pandoc2pdf` formats, e.g. `["--toc", "-N"]`
- `latex_cmd::AbstractString = "xelatex"`: The command used to make PDF file from .tex
- `latex_keep_unicode::Bool = false`: If `true`, do not convert unicode characters to their respective latex representation. This is especially useful if a font and tex-engine with support for unicode characters are used
!!! note
Run Weave from terminal and try to avoid weaving from IJulia or ESS; they tend to mess with capturing output.
"""
function weave(source ; doctype = :auto,
informat=:auto, out_path=:doc, args = Dict(),
mod::Union{Module, Symbol} = :sandbox,
fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache=:off,
throw_errors = false,
template = nothing, highlight_theme = nothing, css = nothing,
pandoc_options = String[]::Array{String},
latex_cmd = "xelatex",latex_keep_unicode=false)
function weave(
source::AbstractString;
doctype::Union{Symbol,AbstractString} = :auto,
informat::Union{Symbol,AbstractString} = :auto,
out_path::Union{Symbol,AbstractString} = :doc,
args::Dict = Dict(),
mod::Union{Module,Symbol} = :sandbox,
fig_path::AbstractString = "figures",
fig_ext::Union{Nothing,AbstractString} = nothing,
cache_path::AbstractString = "cache",
cache::Symbol = :off,
throw_errors::Bool = false,
template::Union{Nothing,AbstractString,Mustache.MustacheTokens} = nothing,
highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing,
css::Union{Nothing,AbstractString} = nothing,
pandoc_options::Vector{<:AbstractString} = String[],
latex_cmd::AbstractString = "xelatex",
latex_keep_unicode::Bool = false
)
doc = read_doc(source, informat)
doctype == :auto && (doctype = detect_doctype(doc.source))
doc.doctype = doctype
# Read args from document header, overrides command line args
if haskey(doc.header, "options")
(doctype, informat, out_path, args, mod, fig_path, fig_ext,
@ -153,68 +164,77 @@ function weave(source ; doctype = :auto,
end
doc.cwd == pwd() && (outname = basename(outname))
@info("Report weaved to $outname")
@info "Report weaved to $outname"
return abspath(outname)
#catch err
# @warn("Something went wrong during weaving")
# @error(sprint(showerror, err))
# catch err
# @warn "Something went wrong during weaving"
# @error sprint(showerror, err)
# return nothing
finally
doctype == :auto && (doctype = detect_doctype(doc.source))
if occursin("2pdf", doctype)
rm(doc.fig_path, force = true, recursive = true)
elseif occursin("2html", doctype)
rm(doc.fig_path, force = true, recursive = true)
end
occursin(r"2(pdf|html)", doctype) && rm(doc.fig_path, force = true, recursive = true)
end
end
function weave(doc::AbstractString, doctype::AbstractString)
weave(doc, doctype=doctype)
weave(doc::AbstractString, doctype::Union{Symbol,AbstractString}) =
weave(doc; doctype = doctype)
"""
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
"""
function notebook(
source::AbstractString;
out_path::Union{Symbol,AbstractString} = :pwd,
timeout = -1,
nbconvert_options::AbstractString = "",
jupyter_path::AbstractString = "jupyter",
)
doc = read_doc(source)
converted = convert_doc(doc, NotebookOutput())
doc.cwd = get_cwd(doc, out_path)
outfile = get_outname(out_path, doc, ext = "ipynb")
open(outfile, "w") do f
write(f, converted)
end
@info "Running nbconvert"
out = read(
`$jupyter_path nbconvert --ExecutePreprocessor.timeout=$timeout --to notebook --execute $outfile $nbconvert_options --output $outfile`,
String,
)
end
"""
notebook(source::String; out_path=:pwd, timeout=-1, nbconvert_options="", jupyter_path = "jupyter")
include_weave(source::AbstractString, informat::Union{Symbol,AbstractString} = :auto)
include_weave(m::Module, source::AbstractString, informat::Union{Symbol,AbstractString} = :auto)
Convert Weave document `source` to Jupyter notebook and execute the code
using nbconvert. **Ignores** all chunk options
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document,
`:pwd`: Julia working directory, `"somepath"`: Path as a
String e.g `"/home/mpastell/weaveout"`
* `timeout`: nbconvert cell timeout in seconds. Defaults to -1 (no timeout)
* `nbconvert_options`: string of additional options to pass to nbconvert, such as `--allow-errors`
* `jupyter_path`: Path/command for the Jupyter you want to use. Defaults to "jupyter," which runs whatever is linked/alias to that.
Include code from Weave document calling `include_string` on all code from doc.
Code is run in the path of the include document.
"""
function notebook(source::String; out_path=:pwd, timeout=-1, nbconvert_options=[], jupyter_path = "jupyter")
doc = read_doc(source)
converted = convert_doc(doc, NotebookOutput())
doc.cwd = get_cwd(doc, out_path)
outfile = get_outname(out_path, doc, ext="ipynb")
open(outfile, "w") do f
write(f, converted)
end
@info("Running nbconvert")
out = read(`$jupyter_path nbconvert --ExecutePreprocessor.timeout=$timeout --to notebook --execute $outfile $nbconvert_options --output $outfile`, String)
end
"""
include_weave(doc, informat=:auto)
include_weave(m::Module, doc, informat=:auto)
Include code from Weave document calling `include_string` on
all code from doc. Code is run in the path of the include document.
"""
function include_weave(m::Module, source, informat=:auto)
function include_weave(
m::Module,
source::AbstractString,
informat::Union{Symbol,AbstractString} = :auto,
)
old_path = pwd()
doc = read_doc(source, informat)
cd(doc.path)
try
code = join([x.content for x in
filter(x -> isa(x,Weave.CodeChunk), doc.chunks)], "\n")
code = join([x.content for x in filter(x -> isa(x, Weave.CodeChunk), doc.chunks)], "\n")
include_string(m, code)
catch e
throw(e)

View File

@ -15,7 +15,7 @@ mutable struct WeaveDoc
header::Dict
template::Union{AbstractString, Mustache.MustacheTokens}
css::AbstractString
highlight_theme
highlight_theme::Type{<:Highlights.AbstractTheme}
fig_path::AbstractString
chunk_defaults::Dict{Symbol,Any}
function WeaveDoc(source, chunks, header)

View File

@ -45,7 +45,7 @@ const rcParams = deepcopy(defaultParams)
Set default options for code chunks, use [`get_chunk_defaults`](@ref) to see the current values.
E.g.: set default `dpi` to 200 and `fig_width` to 8
E.g.: set default `dpi` to `200` and `fig_width` to `8`
```julia
julia> set_chunk_defaults(Dict{Symbol, Any}(:dpi => 200, fig_width => 8))
@ -57,7 +57,7 @@ function set_chunk_defaults(opts::Dict{Symbol, Any})
end
"""
`get_chunk_defaults()`
get_chunk_defaults()
Get default options used for code chunks.
"""
@ -66,9 +66,9 @@ function get_chunk_defaults()
end
"""
`restore_chunk_defaults()`
restore_chunk_defaults()
Restore Weave.jl default chunk options
Restore Weave.jl default chunk options.
"""
function restore_chunk_defaults()
rcParams[:chunk_defaults] = defaultParams[:chunk_defaults]
@ -93,9 +93,9 @@ end
getvalue(d::Dict, key , default) = haskey(d, key) ? d[key] : default
"""
header_args(doc::WeaveDoc)`
header_args(doc::WeaveDoc)
Get weave arguments from document header
Get weave arguments from document header.
"""
function header_args(doc::WeaveDoc, out_path, mod, fig_ext, fig_path,
cache_path, cache, throw_errors,template,
@ -129,9 +129,9 @@ function header_args(doc::WeaveDoc, out_path, mod, fig_ext, fig_path,
end
"""
`header_chunk_defaults!(doc::WeaveDoc)`
header_chunk_defaults!(doc::WeaveDoc)
Get chunk defaults from header and update
Get chunk defaults from header and update.
"""
function header_chunk_defaults!(doc::WeaveDoc)
for key in keys(doc.chunk_defaults)

View File

@ -1,32 +1,46 @@
using Base64
"""
run(doc::WeaveDoc; doctype = :auto,
mod::Union{Module, Symbol} = :sandbox, out_path=:doc,
args=Dict(), fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache = :off, throw_errors=false)
run(doc::WeaveDoc; kwargs...)
Run code chunks and capture output from parsed document.
Run code chunks and capture output from the parsed document.
* `doctype`: :auto = set based on file extension or specify one of the supported formats.
See `list_out_formats()`
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS.
* `mod`: Module where Weave `eval`s code. Defaults to `:sandbox`
to create new sandbox module, you can also pass a module e.g. `Main`.
* `fig_path`: where figures will be generated, relative to out_path
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
* `cache_path`: where of cached output will be saved.
* `cache`: controls caching of code: `:off` = no caching, `:all` = cache everything,
`:user` = cache based on chunk options, `:refresh`, run all code chunks and save new cache.
## Keyword options
**Note:** Run command from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
- `doctype::Union{Symbol,AbstractString} = :auto`: Output document format. `:auto` will set it automatically based on file extension. You can also manually specify it; see [`list_out_formats()`](@ref) for the supported formats
- `out_path::Union{Symbol,AbstractString} = :doc`: Path where the output is generated can be either of:
* `:doc`: Path of the source document (default)
* `:pwd`: Julia working directory
* `"somepath"`: `String` of output directory e.g. `"~/outdir"`, or of filename e.g. `"~/outdir/outfile.tex"`
- `args::Dict = Dict()`: Arguments to be passed to the weaved document; will be available as `WEAVE_ARGS` in the document
- `mod::Union{Module,Symbol} = :sandbox`: Module where Weave `eval`s code. Defaults to `:sandbox` to create new sandbox module. You also can also pass a `Module` e.g. `Main`
- `fig_path::AbstractString = "figures"`: Where figures will be generated, relative to `out_path`
- `fig_ext::Union{Nothing,AbstractString} = nothing`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`
- `cache_path::AbstractString = "cache"`: Where of cached output will be saved
- `cache::Symbol = :off`: Controls caching of code:
* `:off` means no caching (default)
* `:all` caches everything
* `:user` caches based on chunk options
* `:refresh` runs all code chunks and save new cache
- `throw_errors::Bool = false`: If `false` errors are included in output document and the whole document is executed. If `true` errors are thrown when they occur
- `latex_keep_unicode::Bool = false`: If `true`, do not convert unicode characters to their respective latex representation. This is especially useful if a font and tex-engine with support for unicode characters are used
!!! note
Run Weave from terminal and try to avoid weaving from IJulia or ESS; they tend to mess with capturing output.
"""
function Base.run(doc::WeaveDoc; doctype = :auto,
mod::Union{Module, Symbol} = :sandbox, out_path=:doc,
args=Dict(), fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache = :off, throw_errors=false, latex_keep_unicode=false)
function Base.run(
doc::WeaveDoc;
doctype::Union{Symbol,AbstractString} = :auto,
out_path::Union{Symbol,AbstractString} = :doc,
args::Dict = Dict(),
mod::Union{Module,Symbol} = :sandbox,
fig_path::AbstractString = "figures",
fig_ext::Union{Nothing,AbstractString} = nothing,
cache_path::AbstractString = "cache",
cache::Symbol = :off,
throw_errors::Bool = false,
latex_keep_unicode::Bool = false
)
#cache :all, :user, :off, :refresh
doc.cwd = get_cwd(doc, out_path)

View File

@ -31,16 +31,15 @@ function detect_outformat(outfile::String)
end
"""
`convert_doc(infile::AbstractString, outfile::AbstractString; format = nothing)`
convert_doc(infile::AbstractString, outfile::AbstractString; format::Union{Nothing,AbstractString} = nothing)
Convert Weave documents between different formats
* `infile` = Name of the input document
* `outfile` = Name of the output document
* `format` = Output format (optional). Detected from outfile extension, but can
be set to `"script"`, `"markdown"`, `"notebook"` or `"noweb"`.
- `infile`: Path of the input document
- `outfile`: Path of the output document
- `format = nothing`: Output document format (optional). It will be detected automatically from the `outfile` extension. You can also specify either of `"script"`, `"markdown"`, `"notebook"`, or `"noweb"`
"""
function convert_doc(infile::AbstractString, outfile::AbstractString; format = nothing)
function convert_doc(infile::AbstractString, outfile::AbstractString; format::Union{Nothing,AbstractString} = nothing)
doc = read_doc(infile)
if format == nothing