Add bibtex support to md2pdf

citations
Matti Pastell 2019-03-03 10:44:16 +02:00
parent 3353856074
commit 41dd6a9e37
6 changed files with 18 additions and 9 deletions

View File

@ -122,8 +122,6 @@ function weave(source ; doctype = :auto,
write(io, formatted)
end
WeaveMarkdown.reset_parser()
#Special for that need external programs
if doc.doctype == "pandoc2html"
mdname = outname
@ -148,6 +146,7 @@ function weave(source ; doctype = :auto,
# @warn("Something went wrong during weaving")
# println(e)
finally
WeaveMarkdown.reset_parser()
doctype == :auto && (doctype = detect_doctype(doc.source))
if occursin("pandoc2pdf", doctype) && cache == :off
rm(doc.fig_path, force = true, recursive = true)

View File

@ -7,7 +7,6 @@ function list_references(m::MIME"text/html")
refs[CITATIONS[:refnumbers][key]] = key
end
io = IOBuffer()
write(io, "<h3>References</h3>")
write(io, "<ol>")
for i in 1:length(refs)
ref = CITATIONS[:references][refs[i]]

View File

@ -24,5 +24,5 @@ function latexinline(io, citations::Citations)
for c in citations.content
push!(cites, c.key)
end
write(io, string("\\cite{", join(cites, ", "), "}"))
write(io, string("\\citep{", join(cites, ", "), "}"))
end

View File

@ -99,9 +99,9 @@ function render_doc(formatted, doc::WeaveDoc, format::JMarkdown2tex)
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 = """
\\section*{References}
\\bibliographystyle{unsrt}
\\bibliography{$bibfile}
"""

View File

@ -1,4 +1,4 @@
import .WeaveMarkdown
"""
`pandoc2html(formatted::AbstractString, doc::WeaveDoc)`
@ -108,9 +108,17 @@ function run_latex(doc::WeaveDoc, outname, latex_cmd = "xelatex")
old_wd = pwd()
cd(doc.cwd)
xname = basename(outname)
bibname = splitext(xname)[1]
@info("Weaved code to $outname. Running $latex_cmd")
textmp = mktempdir(".")
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)
rm(xname)
@ -118,9 +126,11 @@ function run_latex(doc::WeaveDoc, outname, latex_cmd = "xelatex")
cd(old_wd)
return true
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)
rm(textmp)
rm(xname)
rm(textmp, recursive=true)
return false
end
end

View File

@ -5,6 +5,7 @@
\usepackage{amssymb,amsmath}
\usepackage{bm}
\usepackage{graphicx}
\usepackage{natbib}
\usepackage{microtype}
\usepackage{hyperref}
\setlength{\parindent}{0pt}