How to link citations with Hakyll?
I am using the newest Hakyll version 4.15. This version depends on the newest
citeproc
package. Previously,
pandoc-citeproc
was used to handle
citations and style.
I need to replace pandocCompilerWith
with my own bibtexCompilerWith
that
will link the citations. bibtexCompilerWith
could look something like this:
bibtexCompilerWith :: ReaderOptions
-> WriterOptions
-> FilePath
-> Identifier
-> Compiler (Item String)
= do
bibtexCompilerWith readerOpts writerOpts bibPath cslPath <- load cslPath
csl <- load (fromFilePath bibPath)
bib
getResourceBody>>= turnOnLinkCitations readerOpts -- insert Pandoc link-citations metadata
>>= processPandocBiblio csl bib -- existing Hakyll function that inserts more metadata
>>= return . writePandocWith writerOpts
Turning on link-citations
is straightforward:
turnOnLinkCitations :: ReaderOptions
-> Item String
-> Compiler (Item Pandoc)
= do
turnOnLinkCitations ropt item <- readPandocWith ropt item
pandoc return . addLinkCitations) pandoc
withItemBody (
addLinkCitations :: Pandoc -> Pandoc
Pandoc meta a) =
addLinkCitations (& unMeta
meta & M.insert "reference-section-title" (MetaString "Bibliography")
& M.insert "link-citations" (MetaBool True)
& \m -> Pandoc (Meta m) a
Hakyll provides the processPandocBiblio
function and uses the given bibtex
file to edit the meta map (that is also edited here for link-citations
). If I
would prefer to not use bibtex but list all of the citations in YAML
frontmatter of the article, then I would edit the pandoc meta directly.
For this post, I create a bib/citations.bib
file that includes a reference,
then I configure it in the YAML and cite an entry in the text like this
[@colbourn2006handbook]
, or like this [@colbourn2006handbook, pp.33-35]
and
leave it at the end of the paragraph. [2]
The bibliography below will include it. The citation style used is numeric but
I can use any style by providing a custom .csl
file that can be fetched from
Zotero Styles Repository.
Note: To include references in the bibliography that are not cited in the
article, I added a single hidden div
element below that lists them.
<div style="display: none;">
[@furedi1996lottery; @burger2007towards]
[@etzion1995bounds]
[@vazirani2013approximation, chapter 1, page 33]
</div>
Another note: It is a bit weird to use footnotes at the same time.
Tangential note: I am linking citations but there is still no real article linking them. Such is life.