andras-simonyi / citeproc-el

A CSL 1.0.2 Citation Processor for Emacs.
GNU General Public License v3.0
84 stars 9 forks source link

Problems rendering superscripts correctly for in-text citations when exporting to ODT #160

Closed matogoro closed 2 months ago

matogoro commented 2 months ago

Describe the bug

Hi,

I'm having trouble getting citar and citeproc-el to render certain superscripted citations properly when exporting to ODT (using org-cite). Basically, the generated ODT document shows the underlying org shorthand (^{1}) rather than a proper superscripted citation.

Unsurprisingly, only CSL styles that rely on superscript citations (e.g., nature.csl, american-medical-association.csl, etc.) are affected. This is not an issue with certain CSL styles that don't require superscript numbers (e.g., springer-vancouver.csl).

Some things I've noticed:

To Reproduce

A (stripped down) version of my configuration is below:

(use-package citeproc)

(use-package citar
  :custom
  (org-cite-global-bibliography '("~/Multimedia/Literature/SciLi/index.bib"))
  (org-cite-insert-processor 'citar)
  (org-cite-follow-processor 'citar)
  (org-cite-activate-processor 'citar)
  (citar-bibliography org-cite-global-bibliography)
  (citar-citeproc-csl-styles-dir "~/Documents/Zettelkasten/Templates/Text/CSL/styles")
  (citar-citeproc-csl-locales-dir "~/Documents/Zettelkasten/Templates/Text/CSL/locales")  ; cloned official CSL locales repository
  (citar-format-reference-function #'citar-citeproc-format-reference)
  :hook
  (LaTeX-mode . citar-capf-setup)
  (org-mode . citar-capf-setup))

In the manuscript buffer, I execute citar-citeproc-select-csl-style and select the appropriate CSL file (e.g., Nature). I also put in the following header to ensure the proper CSL file is loaded:

#+CITE_EXPORT: csl ~/Documents/Zettelkasten/Templates/Text/CSL/american-medical-association.csl

I export using org-export-dispatch to ODT, and the in-text citations of the resultant ODT file are displayed as ^{1} when viewed in LibreOffice.

Expected behavior Correct rendering of superscript citations in exported ODT files. Any help would be greatly appreciated!

Emacs version: GNU Emacs 29.3 Org 9.7-pre

andras-simonyi commented 2 months ago

Hello, thanks a lot for the detailed report and apologies for responding only now. I can confirm the problem, which is caused, I think, by the space present between the citation in superscript and the previous word or punctuation. The best solution would be to check during Org export whether a citation starts with text in superscript and eliminate any leading space if that is the case (actually, something similar is already done for note citations). I will try to fix the problem in the Org CSL export processor in the near future.

andras-simonyi commented 2 months ago

I've merged a pull request now (#161), which should solve the core rendering problem. I have also prepared a couple of citeproc and Org (oc-csl) patches that together delete the spaces before superscript citations -- I'll try to apply them shortly, although the Org patch might take a bit of time because of the mailing list discussions.

andras-simonyi commented 2 months ago

...the citeproc part (#162 ) has been merged, the Org patch is WIP.

andras-simonyi commented 2 months ago

I've also pushed the Org patch onto main so with the latest citeproc-el and Org development version these superscript citations should be properly exported to any supported format including odt.

matogoro commented 2 months ago

This is amazing. Thank you so much for your hard work!

For reference, the solution in the thread linked by @kjambunathan also works for my particular use-case, but it's great to having this in Org mainstream as well.

Hopefully this helps other folks with strict editing requirements.

andras-simonyi commented 2 months ago

Thanks, I've looked into @kjambunathan's solution and it seems to be using the dedicated org-odt citeproc-el formatter which is in certain respects still a work in progress -- eventually I intend to integrate it into oc-csl too.