mirror of https://github.com/mpastell/Weave.jl
keep latex figures
parent
67126a515a
commit
7e88052db3
70
src/Weave.jl
70
src/Weave.jl
|
@ -131,49 +131,39 @@ function weave(
|
||||||
#theme != nothing && (doc.theme = theme) #Reserved for themes
|
#theme != nothing && (doc.theme = theme) #Reserved for themes
|
||||||
css != nothing && (doc.css = css)
|
css != nothing && (doc.css = css)
|
||||||
|
|
||||||
try
|
doc = run(doc, doctype = doctype,
|
||||||
doc = run(doc, doctype = doctype,
|
mod = mod,
|
||||||
mod = mod,
|
out_path=out_path, args = args,
|
||||||
out_path=out_path, args = args,
|
fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache,
|
||||||
fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache,
|
throw_errors = throw_errors,latex_keep_unicode=latex_keep_unicode)
|
||||||
throw_errors = throw_errors,latex_keep_unicode=latex_keep_unicode)
|
formatted = format(doc)
|
||||||
formatted = format(doc)
|
|
||||||
|
|
||||||
outname = get_outname(out_path, doc)
|
outname = get_outname(out_path, doc)
|
||||||
|
|
||||||
open(outname, "w") do io
|
open(outname, "w") do io
|
||||||
write(io, formatted)
|
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)
|
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
weave(doc::AbstractString, doctype::Union{Symbol,AbstractString}) =
|
weave(doc::AbstractString, doctype::Union{Symbol,AbstractString}) =
|
||||||
|
|
|
@ -108,7 +108,7 @@ function run_latex(doc::WeaveDoc, outname, latex_cmd = "xelatex")
|
||||||
old_wd = pwd()
|
old_wd = pwd()
|
||||||
cd(doc.cwd)
|
cd(doc.cwd)
|
||||||
xname = basename(outname)
|
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(".")
|
textmp = mktempdir(".")
|
||||||
try
|
try
|
||||||
out = read(`$latex_cmd -shell-escape $xname -aux-directory $textmp -include-directory $(doc.cwd)`, String)
|
out = read(`$latex_cmd -shell-escape $xname -aux-directory $textmp -include-directory $(doc.cwd)`, String)
|
||||||
|
|
Loading…
Reference in New Issue