Add citation output to md2tex format

citations
Matti Pastell 2019-03-02 19:20:14 +02:00
parent a6c7f1abb3
commit 3353856074
4 changed files with 23 additions and 3 deletions

View File

@ -103,6 +103,7 @@ function weave(source ; doctype = :auto,
css != nothing && (doc.css = css)
template != nothing && (doc.template = template)
WeaveMarkdown.reset_parser()
if haskey(doc.header, "bibliography")
WeaveMarkdown.init_parser(joinpath(dirname(source), doc.header["bibliography"]))
end

View File

@ -9,12 +9,20 @@ function latex(io::IO, tex::Markdown.LaTeX)
end
#Remove comments that can occur inside a line
function latexinline(io, comment::WeaveMarkdown.Comment)
function latexinline(io, comment::Comment)
write(io, "")
end
function latex(io::IO, comment::WeaveMarkdown.Comment)
function latex(io::IO, comment::Comment)
for line in split(comment.text, r"\r\n|\n")
write(io, "% $line\n")
end
end
function latexinline(io, citations::Citations)
cites = []
for c in citations.content
push!(cites, c.key)
end
write(io, string("\\cite{", join(cites, ", "), "}"))
end

View File

@ -97,6 +97,15 @@ function render_doc(formatted, doc::WeaveDoc, format::JMarkdown2tex)
wversion = ""
wtime = string(Date(now()))
references = ""
if !isempty(WeaveMarkdown.CITATIONS[:references])
bibfile = splitext(joinpath(dirname(doc.source), doc.header["bibliography"]))[1]
references = """
\\section*{References}
\\bibliographystyle{unsrt}
\\bibliography{$bibfile}
"""
end
if isempty(doc.template)
template = Mustache.template_from_file(joinpath(dirname(@__FILE__), "../templates/julia_tex.tpl"))
@ -105,7 +114,7 @@ function render_doc(formatted, doc::WeaveDoc, format::JMarkdown2tex)
end
return Mustache.render(template; body = formatted,
highlight = highlight,
highlight = highlight, references = references,
[Pair(Symbol(k), v) for (k,v) in doc.header]...)
end

View File

@ -39,4 +39,6 @@
{{{ :body }}}
{{{ :references }}}
\end{document}