mirror of https://github.com/mpastell/Weave.jl
move unicode2tex escape characters to struct
parent
b569740915
commit
12e148af18
|
@ -98,6 +98,9 @@ Base.@kwdef mutable struct TexMinted <: TexFormat
|
||||||
keep_unicode = false
|
keep_unicode = false
|
||||||
template = nothing
|
template = nothing
|
||||||
tex_deps = "\\usepackage{minted}"
|
tex_deps = "\\usepackage{minted}"
|
||||||
|
# how to escape latex in verbatim/code environment
|
||||||
|
start_escape = "|\$"
|
||||||
|
close_escape = "\$|"
|
||||||
end
|
end
|
||||||
register_format!("texminted", TexMinted())
|
register_format!("texminted", TexMinted())
|
||||||
|
|
||||||
|
@ -125,6 +128,9 @@ Base.@kwdef mutable struct JMarkdown2tex <: TexFormat
|
||||||
template = nothing
|
template = nothing
|
||||||
keep_unicode = false
|
keep_unicode = false
|
||||||
tex_deps = ""
|
tex_deps = ""
|
||||||
|
# how to escape latex in verbatim/code environment
|
||||||
|
start_escape = "(*@"
|
||||||
|
close_escape = "@*)"
|
||||||
end
|
end
|
||||||
register_format!("md2tex", JMarkdown2tex())
|
register_format!("md2tex", JMarkdown2tex())
|
||||||
register_format!("md2pdf", JMarkdown2tex())
|
register_format!("md2pdf", JMarkdown2tex())
|
||||||
|
@ -176,12 +182,11 @@ function format_chunk(chunk::DocChunk, docformat::TexFormat)
|
||||||
end
|
end
|
||||||
clear_buffer_and_format!(io, out, WeaveMarkdown.latex)
|
clear_buffer_and_format!(io, out, WeaveMarkdown.latex)
|
||||||
out = take2string!(out)
|
out = take2string!(out)
|
||||||
return docformat.keep_unicode ? out : uc2tex(docformat, out)
|
return unicode2tex(docformat, out)
|
||||||
end
|
end
|
||||||
|
|
||||||
function format_output(result, docformat::TexFormat)
|
function format_output(result, docformat::TexFormat)
|
||||||
docformat.keep_unicode || return uc2tex(docformat, result, true)
|
return unicode2tex(docformat, result, true)
|
||||||
return result
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function format_output(result, docformat::JMarkdown2tex)
|
function format_output(result, docformat::JMarkdown2tex)
|
||||||
|
@ -191,39 +196,26 @@ function format_output(result, docformat::JMarkdown2tex)
|
||||||
Highlights.Format.escape(io, MIME("text/latex"), x, charescape = true),
|
Highlights.Format.escape(io, MIME("text/latex"), x, charescape = true),
|
||||||
result,
|
result,
|
||||||
)
|
)
|
||||||
docformat.keep_unicode || return uc2tex(docformat, result_escaped, true)
|
return unicode2tex(docformat, result_escaped, true)
|
||||||
return result_escaped
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function format_code(code, docformat::TexFormat)
|
function format_code(code, docformat::TexFormat)
|
||||||
docformat.keep_unicode || return uc2tex(docformat, code, true)
|
return unicode2tex(docformat, code, true)
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
function format_code(code, docformat::JMarkdown2tex)
|
function format_code(code, docformat::JMarkdown2tex)
|
||||||
ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
|
ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
|
||||||
docformat.keep_unicode || return uc2tex(docformat, ret, false)
|
unicode2tex(docformat, ret, false)
|
||||||
return ret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Convert unicode to tex, escape listings if needed
|
function unicode2tex(docformat::TexFormat, s, escape = false)
|
||||||
function uc2tex(::JMarkdown2tex, s, escape = false)
|
# Check whether to convert at all and return input if not4
|
||||||
|
docformat.keep_unicode && return s
|
||||||
|
starter = docformat.escape_starter
|
||||||
|
closer = docformat.escape_closer
|
||||||
for key in keys(latex_symbols)
|
for key in keys(latex_symbols)
|
||||||
if escape
|
body = "\\ensuremath{$(texify(key))}"
|
||||||
s = replace(s, latex_symbols[key] => "(*@\\ensuremath{$(texify(key))}@*)")
|
target = escape ? string(starter, body, closer) : body
|
||||||
else
|
s = replace(s, latex_symbols[key] => body)
|
||||||
s = replace(s, latex_symbols[key] => "\\ensuremath{$(texify(key))}")
|
|
||||||
end
|
|
||||||
end
|
|
||||||
return s
|
|
||||||
end
|
|
||||||
|
|
||||||
function uc2tex(::TexFormat, s, escape = false)
|
|
||||||
for key in keys(latex_symbols)
|
|
||||||
if escape
|
|
||||||
s = replace(s, latex_symbols[key] => "|\$\\ensuremath{$(texify(key))}\$|")
|
|
||||||
else
|
|
||||||
s = replace(s, latex_symbols[key] => "\\ensuremath{$(texify(key))}")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
return s
|
return s
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue