Skip to content

Conversation

jgm
Copy link
Owner

@jgm jgm commented Aug 1, 2025

In transforming pandoc Cite to citeproc Citation,
extract a citationSuffix and citationPrefix from the last item's suffix and first item's prefix, respectively, if they contain a | character which separates the item's suffix or prefix from the whole Citation's.

for example:

[for example, see |@C1; @A3; @B4|, and others]

Here "for example, see" acts as a prefix for the whole group and will remain at the beginning even if the citation items are reordered by citeproc. Similarly, ", and others" will be a suffix for the whole group.

The terminology is confusing, because a pandoc Citation is a citeproc CitationItem, and a pandoc Cite (which can contain multiple Citations) is a citeproc Citation. A citeproc citationPrefix is a prefix on the whole group of items.

Closes #10894.

Notes:

  1. The org reader now adds global prefixes and suffixes the same way as the Markdown reader: as affixes to the first item's prefix or the last item's suffix, separated by a pipe (|).

  2. The org writer, however, has not been modified to convert the | to a ;, as required by org-cite syntax.

  3. This change doesn't currently do what one would expect, because of changes that were made to citeproc to prevent citation items with prefixes and suffixes from being sorted. Hence in test/command/10894.md, we have test output

    (Doe, 2020; Smith, 2021)
    

    without affixes, but

    (see Smith, 2021; Doe, 2020, and others)
    

    with affixes. To make this work well, we'd need to remove the citeproc code that prevented bad results before we had proper global prefixes and suffixes. However, removing this code would mean that existing documents would render differently, unless the new pipe syntax for citation affixes were used. That may be something we want to avoid.

  4. The use of pipes to separate out global affixes from item-level affixes is a kludge that could be avoided if we added additional fields to Cite in the pandoc AST. However, AST changes are disruptive, so perhaps it's not worth doing that.

In transforming pandoc Cite to citeproc Citation,
extract a `citationSuffix` and `citationPrefix` from the
last item's suffix and first item's prefix, respectively, if
they contain a `|` character which separates the item's suffix
or prefix from the whole Citation's.

for example:

    [for example, see |@c1; @A3; @b4|, and others]

Here "for example, see" acts as a prefix for the whole
group and will remain at the beginning even if the citation
items are reordered by citeproc. Similarly, ", and others"
will be a suffix for the whole group.

Closes #10894.

Notes:

1. The org reader now adds global prefixes and suffixes the
same way as the Markdown reader: as affixes to the first item's
prefix or the last item's suffix, separated by a pipe (`|`).

2. The org writer, however, has not been modified to convert the
`|` to a `;`, as required by org-cite syntax.

3. This change doesn't currently do what one would expect, because
of changes that were made to citeproc to prevent citation items
with prefixes and suffixes from being sorted.  Hence in
`test/command/10894.md`, we have test output
```
(Doe, 2020; Smith, 2021)
```
without affixes, but
```
(see Smith, 2021; Doe, 2020, and others)
```
with affixes.  To make this work well, we'd need to remove the citeproc
code that prevented bad results before we had proper global
prefixes and suffixes.  However, removing this code would mean that
existing documents would render differently, unless the new pipe
syntax for citation affixes were used.  That may be something we want
to avoid.

4. The use of pipes to separate out global affixes from item-level
affixes is a kludge that could be avoided if we added additional
fields to Cite in the pandoc AST. However, AST changes are disruptive,
so perhaps it's not worth doing that.
@jgm
Copy link
Owner Author

jgm commented Aug 1, 2025

I'm very unsure about whether to merge this one. As noted above, it doesn't really help much unless we make another change to citeproc, which might break current documents. And it's a bit hacked together without changes in the Pandoc Inline type. But, comments welcome. @adunning @tarleb

If we do end up making AST changes to Note (see #1603), that would be a good time to make changes to the Cite constructor too. (I'd even be tempted to make the terminology line up with citeproc: Citation -> CitationItem, Cite -> Citation -- or even to put the citeproc types in a separate package that can be used by both pandoc and citeproc.)

@tarleb
Copy link
Collaborator

tarleb commented Aug 1, 2025

I'm all for radical changes once in a while. Seems like both, a good investment and a good time to do it.

Aside: this might also be a good time to revisit endnotes, e.g. jgm/pandoc-types#34.

@jgm
Copy link
Owner Author

jgm commented Aug 3, 2025

Here's the code in citeproc that blocks sorting of citation items with prefixes/suffixes:
https://github.com/jgm/citeproc/blob/master/src/Citeproc/Eval.hs#L215-L239
We'd have to revert this for this PR to make much sense. This would mean that existing documents would render differently; users would have to add the special pipe syntax to keep global prefixes and suffixes in place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provide a way to add a prefix or suffix to a whole citation group
2 participants