mirror of https://github.com/mpastell/Weave.jl
Add bibtex support to md2pdf
parent
3353856074
commit
41dd6a9e37
|
@ -122,8 +122,6 @@ function weave(source ; doctype = :auto,
|
||||||
write(io, formatted)
|
write(io, formatted)
|
||||||
end
|
end
|
||||||
|
|
||||||
WeaveMarkdown.reset_parser()
|
|
||||||
|
|
||||||
#Special for that need external programs
|
#Special for that need external programs
|
||||||
if doc.doctype == "pandoc2html"
|
if doc.doctype == "pandoc2html"
|
||||||
mdname = outname
|
mdname = outname
|
||||||
|
@ -148,6 +146,7 @@ function weave(source ; doctype = :auto,
|
||||||
# @warn("Something went wrong during weaving")
|
# @warn("Something went wrong during weaving")
|
||||||
# println(e)
|
# println(e)
|
||||||
finally
|
finally
|
||||||
|
WeaveMarkdown.reset_parser()
|
||||||
doctype == :auto && (doctype = detect_doctype(doc.source))
|
doctype == :auto && (doctype = detect_doctype(doc.source))
|
||||||
if occursin("pandoc2pdf", doctype) && cache == :off
|
if occursin("pandoc2pdf", doctype) && cache == :off
|
||||||
rm(doc.fig_path, force = true, recursive = true)
|
rm(doc.fig_path, force = true, recursive = true)
|
||||||
|
|
|
@ -7,7 +7,6 @@ function list_references(m::MIME"text/html")
|
||||||
refs[CITATIONS[:refnumbers][key]] = key
|
refs[CITATIONS[:refnumbers][key]] = key
|
||||||
end
|
end
|
||||||
io = IOBuffer()
|
io = IOBuffer()
|
||||||
write(io, "<h3>References</h3>")
|
|
||||||
write(io, "<ol>")
|
write(io, "<ol>")
|
||||||
for i in 1:length(refs)
|
for i in 1:length(refs)
|
||||||
ref = CITATIONS[:references][refs[i]]
|
ref = CITATIONS[:references][refs[i]]
|
||||||
|
|
|
@ -24,5 +24,5 @@ function latexinline(io, citations::Citations)
|
||||||
for c in citations.content
|
for c in citations.content
|
||||||
push!(cites, c.key)
|
push!(cites, c.key)
|
||||||
end
|
end
|
||||||
write(io, string("\\cite{", join(cites, ", "), "}"))
|
write(io, string("\\citep{", join(cites, ", "), "}"))
|
||||||
end
|
end
|
||||||
|
|
|
@ -99,9 +99,9 @@ function render_doc(formatted, doc::WeaveDoc, format::JMarkdown2tex)
|
||||||
|
|
||||||
references = ""
|
references = ""
|
||||||
if !isempty(WeaveMarkdown.CITATIONS[:references])
|
if !isempty(WeaveMarkdown.CITATIONS[:references])
|
||||||
bibfile = splitext(joinpath(dirname(doc.source), doc.header["bibliography"]))[1]
|
bibfile = splitext(abspath(joinpath(dirname(doc.source), doc.header["bibliography"])))[1]
|
||||||
|
bibfile = replace(bibfile, "\\" => "/")
|
||||||
references = """
|
references = """
|
||||||
\\section*{References}
|
|
||||||
\\bibliographystyle{unsrt}
|
\\bibliographystyle{unsrt}
|
||||||
\\bibliography{$bibfile}
|
\\bibliography{$bibfile}
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
|
import .WeaveMarkdown
|
||||||
|
|
||||||
"""
|
"""
|
||||||
`pandoc2html(formatted::AbstractString, doc::WeaveDoc)`
|
`pandoc2html(formatted::AbstractString, doc::WeaveDoc)`
|
||||||
|
@ -108,9 +108,17 @@ 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)
|
||||||
|
bibname = splitext(xname)[1]
|
||||||
@info("Weaved code to $outname. Running $latex_cmd")
|
@info("Weaved code to $outname. Running $latex_cmd")
|
||||||
textmp = mktempdir(".")
|
textmp = mktempdir(".")
|
||||||
try
|
try
|
||||||
|
out = read(`$latex_cmd -shell-escape $xname -aux-directory $textmp -include-directory $(doc.cwd)`, String)
|
||||||
|
if !isempty(WeaveMarkdown.CITATIONS[:references])
|
||||||
|
cd(textmp)
|
||||||
|
out = read(`bibtex $bibname`, String)
|
||||||
|
cd("..")
|
||||||
|
out = read(`$latex_cmd -shell-escape $xname -aux-directory $textmp -include-directory $(doc.cwd)`, String)
|
||||||
|
end
|
||||||
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)
|
||||||
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)
|
||||||
rm(xname)
|
rm(xname)
|
||||||
|
@ -118,9 +126,11 @@ function run_latex(doc::WeaveDoc, outname, latex_cmd = "xelatex")
|
||||||
cd(old_wd)
|
cd(old_wd)
|
||||||
return true
|
return true
|
||||||
catch e
|
catch e
|
||||||
@warn("Error converting document to pdf. Try running latex manually")
|
@info(e)
|
||||||
|
@warn("Error converting document to pdf. Try running with md2tex format and using latex manually")
|
||||||
cd(old_wd)
|
cd(old_wd)
|
||||||
rm(textmp)
|
rm(xname)
|
||||||
|
rm(textmp, recursive=true)
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
\usepackage{amssymb,amsmath}
|
\usepackage{amssymb,amsmath}
|
||||||
\usepackage{bm}
|
\usepackage{bm}
|
||||||
\usepackage{graphicx}
|
\usepackage{graphicx}
|
||||||
|
\usepackage{natbib}
|
||||||
\usepackage{microtype}
|
\usepackage{microtype}
|
||||||
\usepackage{hyperref}
|
\usepackage{hyperref}
|
||||||
\setlength{\parindent}{0pt}
|
\setlength{\parindent}{0pt}
|
||||||
|
|
Loading…
Reference in New Issue