pandoc
pandoc copied to clipboard
Processing citations with some CSL styles results in key/citation overlap
Explain the problem.
Some citation styles (eg din-1505-2-alphanumeric render with the citation key overlapping with the citation title -- eg the following markdown:
---
linkReferences: true
reference-section-title: References
nocite: |
@*
references:
- id: AtiMacCA
author:
- family: Atiyah
given: M. F.
- family: Macdonald
given: I. G.
collection-number: '361'
collection-title: Addison-wesley series in mathematics
issued:
- year: 1969
page: ix+128
publisher: Addison-Wesley
publisher-place: Reading, MA
title: Introduction to commutative algebra
type: book
...
compiled with pandoc test.md --citeproc --csl ~/.local/share/pandoc/citation-styles/ieee-trigraph.csl -so test.pdf yields the following output:
This does not occur with pandoc's builtin CSL style:
Checking the difference in the rendered latex, it appears the DIN style causes Pandoc to wrap the key in
\CSLLeftMargin and the citation in \CSLRightInline
Pandoc version?
$ pacman -Q pandoc-static-git
pandoc-static-git 3.1.11.1.r8.gd8ff4ff87-1
$ pandoc --version
pandoc 3.1.11.1
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /home/gesh/.local/share/pandoc
CSL style was downloaded today from the link given above
Our default template contains:
\newlength{\csllabelwidth}
\setlength{\csllabelwidth}{3em}
If you need a wider label width, you should be able to \setlength{\csllabelwidth}{6em} in your document or header-includes.
Hrm, OK. Any reason this isn't implemented as a tabular environment with the label getting the maximum width of all labels, and the citation itself getting whatever remains?
Also, weird that the default style doesn't wrap the label and citation in environments the way setting a csl style does.
Unsure of the design goals of the citation rendering. If it's meant to integrate with LaTeX's native bibliography system, then I would expect CSLReferences to wrap thebibliography at least. In that case, citeproc could work out the maximum label length, then pass 10^length as the obligatory argument to thebibliography.
Otherwise, we could style the references as a table, eg:
\usepackage{tabularray}
\NewTblrTheme{CSLReferences}{
\DefTblrTemplate{head}{CSLReferences}{}
\DefTblrTemplate{foot}{CSLReferences}{}
\SetTblrTemplate{head}{CSLReferences}
\SetTblrTemplate{foot}{CSLReferences}
}
\begin{document}
\begin{longtblr}[theme=CSLReferences]{colspec = lX, width = \textwidth}
... & ... \\
\end{longtblr}
\end{document}
It's designed to conform to CSL specs as far as possible. There are many CSL display options and we have to accommodate them all (so, we can't assume a tabular format unless that works in every case...and in any case we wouldn't use longtblr or any exotic table package).
Wrapping thebibliography and using bibitem for the label is something I hadn't thought of, but it might be worth exploring.
Suggestions welcome on latex code to calculate the max width of labels used? [EDIT: well I guess we could calculate this in pandoc itself, not as accurately but probably accurately enough, by comparing length of stringified content]
One issue with wrapping thebibliography is that (I believe) this environment generates its own label, which will interfere with our existing way of handling bibliography titles with citeproc.
Maybe this can be disabled?
On Sun, Jan 14, 2024 at 01:45:15PM -0800, John MacFarlane wrote:
rapping
thebibliographyand usingbibitemfor the label is something I hadn't thought of, but it might be worth exploring.Suggestions welcome on latex code to calculate the max width of labels used?
Would it be possible to have citeproc emit that max width somewhere? Don't know
what its calling convention is.
Otherwise, a combination of calc and xstring? Don't know how much overhead
that'd be, and if you're generating that calculation, you might as well just
compute it before inserting it into the LaTeX code.
BTW, in searching, I landed on https://ctan.org/pkg/citation-style-language -- I don't know how they're doing things, but it seems they integrate more deeply with standard BibTeX. Perhaps that's an approach worth taking?
On Sun, Jan 14, 2024 at 01:49:04PM -0800, John MacFarlane wrote:
One issue with wrapping
thebibliographyis that (I believe) this environment generates its own label, which will interfere with our existing way of handling bibliography titles with citeproc. Maybe this can be disabled?
Checking, apparently it can, by locally resetting \section and \chapter to
no-ops: https://tex.stackexchange.com/q/22645