pandoc icon indicating copy to clipboard operation
pandoc copied to clipboard

Translate citation locator braces to \pnfmt when using --biblatex

Open seifferth opened this issue 4 years ago • 3 comments

BibLaTeX provides \pnfmt, which allows users to force treating special parts of a citation postnote as pages. This seems to be equivalent to pandoc-citeproc's locator braces, which provide the same functionality. Since locator braces are already handled by the LaTeX Writer anyway (they are stripped), it might be a good idea to simply translate them into LaTeX when possible.

seifferth avatar Apr 11 '21 14:04 seifferth

But not all locators are page numbers....

jgm avatar Apr 11 '21 16:04 jgm

I just saw that we already talked about this issue in https://github.com/jgm/pandoc/issues/5722. I completely forgot about that, to be honest.

But not all locators are page numbers....

Using \pnfmt should still work, I believe. Apparently, it is more of a suggestion to biblatex than a strong override (such as using \pno would be). To quote the manual (http://mirrors.ctan.org/macros/latex/contrib/biblatex/doc/biblatex.pdf, p. 117):

\pnfmt{<text>}

This command formats its argument <text> in the same format as postnote. The command can be used to format a page range while adding additional text in the postnote argument of a cite command.

\autocite[\pnfmt{378-381, 383} and more]{sigfridsson}

Preliminary testing with biblatex suggests that it might work:

\documentclass{article}
\begin{filecontents}{\jobname.bib}
@article{tenen-wythoff-2014,
    author = "Dennis Tenen and Grant Wythoff",
    title = "Sustainable Authorship in Plain Text using Pandoc and Markdown",
    year = "2014",
    journal = "The Programming Historian",
    volume = "3",
    doi = "https://doi.org/10.46430/phen0041",
}
\end{filecontents}
\usepackage[style=authoryear]{biblatex}
\addbibresource{\jobname.bib}
\begin{document}
  Arabic number as locator
    \autocite[\pnfmt{20}, additional note]{tenen-wythoff-2014}.
  Roman number as locator
    \autocite[\pnfmt{iv}, additional note]{tenen-wythoff-2014}.
  Part as locator
    \autocite[\pnfmt{pt. III}, additional note]{tenen-wythoff-2014}.
  Something else as locator
    \autocite[\pnfmt{(a)}, additional note]{tenen-wythoff-2014}.
\end{document}

The latex above produces the following citations:

Arabic number as locator (Tenen and Wythoff 2014, p. 20, additional note). Roman number as locator (Tenen and Wythoff 2014, p. iv, additional note). Part as locator (Tenen and Wythoff 2014, pt. III, additional note). Something else as locator (Tenen and Wythoff 2014, (a), additional note).

Adding pnfmt around an explicitly delimited citation locator with biblatex shouldn't hurt, at least.

The implementation is still lacking, of course, as it doesn't support whitespace in locators yet. It is also inconsistent with pandoc-citeproc, as my implementation allows multiple locators, while pandoc-citeproc only allows one. Maybe I could reuse (part of) the postfix parsing functionality from pandoc-citeproc directly? It has been integrated into pandoc if I understand correctly, hasn't it?

seifferth avatar Apr 11 '21 19:04 seifferth

Sorry I've let this languish. Yes, the code you're talking about is in Text.Pandoc.Citeproc.Locator - parseLocator.

jgm avatar Sep 19 '21 16:09 jgm