From 7e88052db3e9d458ab5f55f3540533cff496c289 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Sun, 9 Feb 2020 20:11:29 +0800 Subject: [PATCH 1/2] keep latex figures --- src/Weave.jl | 70 ++++++++++++++++++++++----------------------------- src/pandoc.jl | 2 +- 2 files changed, 31 insertions(+), 41 deletions(-) diff --git a/src/Weave.jl b/src/Weave.jl index 35eadec..aeb5de3 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -131,49 +131,39 @@ function weave( #theme != nothing && (doc.theme = theme) #Reserved for themes css != nothing && (doc.css = css) - try - doc = run(doc, doctype = doctype, - mod = mod, - out_path=out_path, args = args, - fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache, - throw_errors = throw_errors,latex_keep_unicode=latex_keep_unicode) - formatted = format(doc) + doc = run(doc, doctype = doctype, + mod = mod, + out_path=out_path, args = args, + fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache, + throw_errors = throw_errors,latex_keep_unicode=latex_keep_unicode) + formatted = format(doc) - outname = get_outname(out_path, doc) + outname = get_outname(out_path, doc) - open(outname, "w") do io - write(io, formatted) - end - - #Special for that need external programs - if doc.doctype == "pandoc2html" - mdname = outname - outname = get_outname(out_path, doc, ext = "html") - pandoc2html(formatted, doc, outname, pandoc_options) - rm(mdname) - elseif doc.doctype == "pandoc2pdf" - mdname = outname - outname = get_outname(out_path, doc, ext = "pdf") - pandoc2pdf(formatted, doc, outname, pandoc_options) - rm(mdname) - elseif doc.doctype == "md2pdf" - success = run_latex(doc, outname, latex_cmd) - success && rm(doc.fig_path, force = true, recursive = true) - success || return - outname = get_outname(out_path, doc, ext = "pdf") - end - - doc.cwd == pwd() && (outname = basename(outname)) - @info "Report weaved to $outname" - return abspath(outname) - # catch err - # @warn "Something went wrong during weaving" - # @error sprint(showerror, err) - # return nothing - finally - doctype == :auto && (doctype = detect_doctype(doc.source)) - occursin(r"2(pdf|html)", doctype) && rm(doc.fig_path, force = true, recursive = true) + open(outname, "w") do io + write(io, formatted) end + + #Special for that need external programs + if doc.doctype == "pandoc2html" + mdname = outname + outname = get_outname(out_path, doc, ext = "html") + pandoc2html(formatted, doc, outname, pandoc_options) + rm(mdname) + elseif doc.doctype == "pandoc2pdf" + mdname = outname + outname = get_outname(out_path, doc, ext = "pdf") + pandoc2pdf(formatted, doc, outname, pandoc_options) + rm(mdname) + elseif doc.doctype == "md2pdf" + success = run_latex(doc, outname, latex_cmd) + success || return + outname = get_outname(out_path, doc, ext = "pdf") + end + + doc.cwd == pwd() && (outname = basename(outname)) + @info("Report weaved to $outname") + return abspath(outname) end weave(doc::AbstractString, doctype::Union{Symbol,AbstractString}) = diff --git a/src/pandoc.jl b/src/pandoc.jl index f4b5fdb..c1870fb 100644 --- a/src/pandoc.jl +++ b/src/pandoc.jl @@ -108,7 +108,7 @@ function run_latex(doc::WeaveDoc, outname, latex_cmd = "xelatex") old_wd = pwd() cd(doc.cwd) xname = basename(outname) - @info("Weaved code to $outname. Running $latex_cmd") + @info("Weaved code to $outname . Running $latex_cmd") # space before '.' added for link to be clickable in Juno terminal textmp = mktempdir(".") try out = read(`$latex_cmd -shell-escape $xname -aux-directory $textmp -include-directory $(doc.cwd)`, String) From f126e1c7a9898b26db1313a378a07d3d37f6f175 Mon Sep 17 00:00:00 2001 From: Fredrik Bagge Carlson Date: Sun, 9 Feb 2020 20:13:37 +0800 Subject: [PATCH 2/2] fix formatting --- src/Weave.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Weave.jl b/src/Weave.jl index aeb5de3..d6a8846 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -132,10 +132,10 @@ function weave( css != nothing && (doc.css = css) doc = run(doc, doctype = doctype, - mod = mod, - out_path=out_path, args = args, - fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache, - throw_errors = throw_errors,latex_keep_unicode=latex_keep_unicode) + mod = mod, + out_path=out_path, args = args, + fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache, + throw_errors = throw_errors,latex_keep_unicode=latex_keep_unicode) formatted = format(doc) outname = get_outname(out_path, doc)