rename `latex_keep_unicode` to `keep_unicode`, handle this in `format`

pull/334/head
Shuhei Kadowaki 2020-05-17 12:17:24 +09:00
parent 249c94a5c1
commit 4113402908
5 changed files with 19 additions and 18 deletions

View File

@ -80,6 +80,7 @@ options:
- `highlight_theme`
- `pandoc_options`
- `latex_cmd`
- `keep_unicode`
See also: [`weave`](@ref)

View File

@ -92,7 +92,7 @@ Weave an input document to output file.
- `highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing`: Theme used for syntax highlighting (defaults to `Highlights.Themes.DefaultTheme`)
- `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
- `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.
@ -114,7 +114,7 @@ function weave(
highlight_theme::Union{Nothing,Type{<:Highlights.AbstractTheme}} = nothing,
pandoc_options::Vector{<:AbstractString} = String[],
latex_cmd::AbstractString = "xelatex",
latex_keep_unicode::Bool = false,
keep_unicode::Bool = false,
)
doc = WeaveDoc(source, informat)
@ -144,7 +144,6 @@ function weave(
cache_path = get(weave_options, "cache_path", cache_path)
cache = Symbol(get(weave_options, "cache", cache))
throw_errors = get(weave_options, "throw_errors", throw_errors)
latex_keep_unicode = get(weave_options, "latex_keep_unicode", latex_keep_unicode)
end
doc = run_doc(
@ -158,7 +157,6 @@ function weave(
cache_path = cache_path,
cache = cache,
throw_errors = throw_errors,
latex_keep_unicode = latex_keep_unicode,
)
# format document
@ -180,12 +178,14 @@ function weave(
highlight_theme = get(weave_options, "highlight_theme", highlight_theme)
pandoc_options = get(weave_options, "pandoc_options", pandoc_options)
latex_cmd = get(weave_options, "latex_cmd", latex_cmd)
keep_unicode = get(weave_options, "keep_unicode", keep_unicode)
end
isnothing(template) || (doc.template = template)
isnothing(highlight_theme) || (doc.highlight_theme = highlight_theme)
# isnothing(theme) || (doc.theme = theme) # Reserved for themes
isnothing(css) || (doc.css = css)
get!(doc.format.formatdict, :keep_unicode, keep_unicode)
formatted = format(doc)
outname = get_outname(out_path, doc)

View File

@ -1,5 +1,8 @@
# so dirty, refactor
using Printf
struct Tex
description::AbstractString
formatdict::Dict{Symbol,Any}

View File

@ -26,7 +26,6 @@ Run code chunks and capture output from the parsed document.
* `: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.
@ -42,14 +41,10 @@ function run_doc(
cache_path::AbstractString = "cache",
cache::Symbol = :off,
throw_errors::Bool = false,
latex_keep_unicode::Bool = false,
)
# cache :all, :user, :off, :refresh
doc.doctype = isnothing(doctype) ? (doctype = detect_doctype(doc.source)) : doctype
if haskey(doc.format.formatdict, :keep_unicode)
doc.format.formatdict[:keep_unicode] = latex_keep_unicode
end
doc.format = deepcopy(formats[doctype])
doc.cwd = get_cwd(doc, out_path)

View File

@ -85,6 +85,8 @@ mdoc = run_doc(parsed, doctype = "github")
# Test disable escaping of unicode
@testset "escape/unescape unicode characters" begin
content = """
# Test chunk
α
@ -106,15 +108,15 @@ str = """
α = 10
```
"""
doc = mock_doc(str; doctype = "md2tex")
doc = Weave.format(doc)
@test occursin(Weave.uc2tex("α"), doc)
@test !occursin("α", doc)
let
doc = mock_doc(str; doctype = "md2tex")
@test occursin(Weave.uc2tex("α"), Weave.format(doc))
@test !occursin("α", Weave.format(doc))
end
doc = mock_doc(str; doctype = "md2tex")
doc.format.formatdict[:keep_unicode] = true
doc = Weave.format(doc)
@test occursin("α", doc)
@test !occursin(Weave.uc2tex("α"), doc)
let
doc = mock_doc(str; doctype = "md2tex", latex_keep_unicode = true)
@test occursin("α", Weave.format(doc))
@test !occursin(Weave.uc2tex("α"), Weave.format(doc))
end