mirror of https://github.com/mpastell/Weave.jl
make `texminted` output valid texfile
parent
62d56846f4
commit
3eba5de7f4
|
@ -50,7 +50,7 @@ function format_chunk(chunk::CodeChunk, docformat)
|
|||
(chunk.options[:fig_env] = docformat.fig_env)
|
||||
end
|
||||
|
||||
hasfield(docformat, :indent) && (chunk.content = indent(chunk.content, docformat.indent))
|
||||
hasproperty(docformat, :indent) && (chunk.content = indent(chunk.content, docformat.indent))
|
||||
|
||||
chunk.content = format_code(chunk.content, docformat)
|
||||
|
||||
|
@ -87,7 +87,7 @@ function format_chunk(chunk::CodeChunk, docformat)
|
|||
chunk.output = format_output(chunk.output, docformat)
|
||||
end
|
||||
|
||||
if hasfield(docformat, :indent)
|
||||
if hasproperty(docformat, :indent)
|
||||
chunk.output = indent(chunk.output, docformat.indent)
|
||||
end
|
||||
strip(chunk.output) ≠ "" && (
|
||||
|
|
|
@ -18,7 +18,7 @@ using REPL.REPLCompletions: latex_symbols
|
|||
|
||||
function format(doc, template = nothing, highlight_theme = nothing; css = nothing)
|
||||
docformat = doc.format
|
||||
|
||||
# TODO : put docformat things earlier into docformat struct. that allows us to pass around fewer args
|
||||
docformat.highlight_theme = get_highlight_theme(highlight_theme)
|
||||
|
||||
restore_header!(doc)
|
||||
|
@ -28,7 +28,7 @@ function format(doc, template = nothing, highlight_theme = nothing; css = nothin
|
|||
end
|
||||
body = join(lines, '\n')
|
||||
|
||||
return render_doc(docformat, body, doc, template, css, highlight_theme)
|
||||
return render_doc(docformat, body, doc, template, css)
|
||||
end
|
||||
|
||||
render_doc(_, body, args...) = body
|
||||
|
|
|
@ -45,7 +45,7 @@ end
|
|||
register_format!("pandoc2html", Pandoc2HTML())
|
||||
|
||||
|
||||
function render_doc(::JMarkdown2HTML, body, doc, template, css, highlight_theme)
|
||||
function render_doc(docformat::JMarkdown2HTML, body, doc, template, css)
|
||||
_, weave_source = splitdir(abspath(doc.source))
|
||||
weave_version, weave_date = weave_info()
|
||||
|
||||
|
@ -53,7 +53,7 @@ function render_doc(::JMarkdown2HTML, body, doc, template, css, highlight_theme)
|
|||
get_html_template(template);
|
||||
body = body,
|
||||
stylesheet = get_stylesheet(css),
|
||||
highlight_stylesheet = get_highlight_stylesheet(MIME("text/html"), highlight_theme),
|
||||
highlight_stylesheet = get_highlight_stylesheet(MIME("text/html"), docformat.highlight_theme),
|
||||
header_script = doc.header_script,
|
||||
weave_source = weave_source,
|
||||
weave_version = weave_version,
|
||||
|
@ -62,7 +62,7 @@ function render_doc(::JMarkdown2HTML, body, doc, template, css, highlight_theme)
|
|||
)
|
||||
end
|
||||
|
||||
|
||||
# very similar to tex version of function
|
||||
function format_chunk(chunk::DocChunk, docformat::JMarkdown2HTML)
|
||||
out = IOBuffer()
|
||||
io = IOBuffer()
|
||||
|
|
|
@ -21,6 +21,8 @@ Base.@kwdef mutable struct JMarkdown2tex <: TexFormat
|
|||
fig_pos = nothing
|
||||
fig_env = nothing
|
||||
highlight_theme = nothing
|
||||
template = normpath(TEMPLATE_DIR, "md2pdf.tpl")
|
||||
tex_deps = ""
|
||||
end
|
||||
register_format!("md2tex", JMarkdown2tex())
|
||||
|
||||
|
@ -41,6 +43,8 @@ Base.@kwdef mutable struct Tex <: TexFormat
|
|||
out_width = "\\linewidth"
|
||||
out_height = nothing
|
||||
highlight_theme = nothing
|
||||
template = normpath(TEMPLATE_DIR, "md2pdf.tpl")
|
||||
tex_deps = ""
|
||||
end
|
||||
register_format!("tex", Tex())
|
||||
|
||||
|
@ -64,6 +68,8 @@ Base.@kwdef mutable struct TexMinted <: TexFormat
|
|||
fig_env = "figure"
|
||||
fig_pos = "htpb"
|
||||
highlight_theme = nothing
|
||||
template = normpath(TEMPLATE_DIR, "md2pdf.tpl")
|
||||
tex_deps = "\\usepackage{minted}"
|
||||
end
|
||||
register_format!("texminted", TexMinted())
|
||||
|
||||
|
@ -73,16 +79,25 @@ register_format!("texminted", TexMinted())
|
|||
isminted(::TexFormat) = false
|
||||
isminted(::TexMinted) = true
|
||||
|
||||
function render_doc(docformat::TexFormat, body, doc, template, _, highlight_theme)
|
||||
# TODO: template in docformat currently not used
|
||||
function render_doc(docformat::TexFormat, body, doc, template, _)
|
||||
return Mustache.render(
|
||||
get_tex_template(template);
|
||||
body = body,
|
||||
highlight = get_highlight_stylesheet(MIME("text/latex"), highlight_theme,
|
||||
minted = isminted(docformat)),
|
||||
highlight = "",
|
||||
tex_deps = docformat.tex_deps,
|
||||
[Pair(Symbol(k), v) for (k, v) in doc.header]...,
|
||||
)
|
||||
end
|
||||
function render_doc(docformat::JMarkdown2tex, body, doc, template, _)
|
||||
return Mustache.render(
|
||||
get_tex_template(template);
|
||||
body = body,
|
||||
highlight = get_highlight_stylesheet(MIME("text/latex"), docformat.highlight_theme),
|
||||
tex_deps = docformat.tex_deps,
|
||||
[Pair(Symbol(k), v) for (k, v) in doc.header]...,
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
# very similar to export to html
|
||||
function format_chunk(chunk::DocChunk, docformat::TexFormat)
|
||||
|
@ -118,6 +133,11 @@ end
|
|||
|
||||
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
|
||||
function format_code(code, docformat::TexFormat)
|
||||
#ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
|
||||
docformat.keep_unicode || return uc2tex(code)
|
||||
return code
|
||||
end
|
||||
function format_code(code, docformat::JMarkdown2tex)
|
||||
ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
|
||||
docformat.keep_unicode || return uc2tex(ret)
|
||||
return ret
|
||||
|
@ -139,6 +159,10 @@ end
|
|||
|
||||
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
|
||||
format_termchunk(chunk, docformat::TexFormat) =
|
||||
string(docformat.termstart, chunk.output, docformat.termend, '\n')
|
||||
|
||||
#should_render(chunk) ? highlight_term(MIME("text/latex"), , docformat.highlight_theme) : ""
|
||||
format_termchunk(chunk, docformat::JMarkdown2tex) =
|
||||
should_render(chunk) ? highlight_term(MIME("text/latex"), chunk.output, docformat.highlight_theme) : ""
|
||||
|
||||
|
||||
|
|
|
@ -283,7 +283,7 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
|
|||
report.fignum = 1
|
||||
report.cur_chunk = chunk
|
||||
|
||||
if hasfield(report.format, :out_width) && isnothing(chunk.options[:out_width])
|
||||
if hasproperty(report.format, :out_width) && isnothing(chunk.options[:out_width])
|
||||
chunk.options[:out_width] = report.format.out_width
|
||||
end
|
||||
|
||||
|
|
|
@ -7,7 +7,9 @@
|
|||
\usepackage{graphicx}
|
||||
\usepackage{microtype}
|
||||
\usepackage{hyperref}
|
||||
{{#:minted}}\usepacakge{minted}{{/:minted}}
|
||||
{{#:tex_deps}}
|
||||
{{{ :tex_deps }}}
|
||||
{{/:tex_deps}}
|
||||
|
||||
\setlength{\parindent}{0pt}
|
||||
\setlength{\parskip}{1.2ex}
|
||||
|
|
Loading…
Reference in New Issue