reddit / emacs

converting from org-ref to org-cite

badkey212 · 2022-09-22 16:15
Having used orf-ref for a time, I am currently investigating the possibilities of org-cite. Is there any smart way to convert citations in the org-ref style to the org-cite syntax? E.g. I am looking for something doing the replacement `[[cite:key]] > [cite:@key]` if possible also `[[parencite:key]] > [cite:p,@key]` and so on. Any ideas?
rberaldo · 2022-09-22 18:20
I'll be looking forward to the answers to this. Also, does org-cite have support for cross-referencing?
bdarcus · 2022-09-22 18:24
No; org-cite focuses exclusively on ... citations. Org itself does have lightweight support for cross-references, however.
bdarcus · 2022-09-22 18:29
There is no parencite style in org; that's the default output. See table 1 in [this article](https://blog.tecosaur.com/tmio/2021-07-31-citations.html) for the style-output mappings. You can also take a look at the function he uses for the conversion [here](https://tecosaur.github.io/emacs-config/config.html#citation,code--4).
attento_redaz · 2022-09-22 18:37
Looks like a task solvable by regular expression-based find and replace -- unfortunately, I'm not aware of any ready-made solution. Incidentally, `[cite:p,@key]` should be `[cite/p:@key]` to be syntactically correct if you meant `p` to be the citation style , but AFAIK the main processors do not support a `p` style, as brackets are typically created automatically by the default `[cite:@key]` form, at least for author-date citations.
badkey212 · 2022-09-22 21:10
Sorry for being unclear - I was looking for the conversion function org-ref-to-org-cite. Thanks for the hint!
feedhardordietryin · 2022-09-23 09:16
I have made slight adaptions to tecosaurs function to additionally handle page references. Maybe thats of some help if you use those (Does not work with citations of the type `[[cite:key-2020]]`, only `cite:key-2020`): (defun org-ref-to-org-cite () "Attempt to convert org-ref citations to org-cite syntax." (interactive) (let* ((cite-conversions '(("cite" . "//b") ("Cite" . "//bc") ("nocite" . "/n") ("citep" . "") ("citep*" . "//f") ("parencite" . "") ("Parencite" . "//c") ("citeauthor" . "/a/f") ("citeauthor*" . "/a") ("citeyear" . "/na/b") ("Citep" . "//c") ("Citealp" . "//bc") ("Citeauthor" . "/a/cf") ("Citeauthor*" . "/a/c") ("autocite" . "") ("Autocite" . "//c") ("textcite" . "/text") ("Textcite" . "/text") ("notecite" . "/l/b") ("Notecite" . "/l/bc") ("pnotecite" . "/l") ("Pnotecite" . "/l/bc"))) (cite-regexp (rx (? "[[") (regexp (regexp-opt (mapcar #'car cite-conversions) t)) ":" (group (or (+ (not (any "\n ,.)]}"))))) (opt "]") (opt (seq "[" (group (+ (any alnum ","))(opt (seq "\\" (+ alpha))))"]]"))))) (save-excursion (goto-char (point-min)) (while (re-search-forward cite-regexp nil t) (message (format "[cite%s:@%s%s]" (cdr (assoc (match-string 1) cite-conversions)) (match-string 2) (if (match-string 3) (concat " " (s-replace "\\" "\\\\" (match-string 3))) (concat "")))) (replace-match (format "[cite%s:@%s%s]" (cdr (assoc (match-string 1) cite-conversions)) (match-string 2) (if (match-string 3) (concat " " (s-replace "\\" "\\\\" (match-string 3))) (concat ""))))))))
bdarcus · 2022-09-23 13:25
I end up with an extra bracket at the end: `[cite:@key]]` PS - there's also [this function](https://github.com/jkitchin/org-ref-cite/blob/393ffc56fca2f171981832fbc9e98301ca7abdde/org-ref-cite-compat.el#L31) from John Kitchin.
feedhardordietryin · 2022-09-23 17:48
> I end up with an extra bracket at the end Can you post an example org-ref citation where this is happening? > there's also this function from John Kitchin I opted to not keep the dependency on org-ref but it's likely more robust than the hacked together regex above.
bdarcus · 2022-09-23 18:37
>Can you post an example org-ref citation where this is happening? I never really used org-ref, but I was using this simple example from the OP: `[[cite:key]]` ​ >I opted to not keep the dependency on org-ref but it's likely more robust than the hacked together regex above. I played with it a bit, and it seems to have it's own issues, aside from the dependencies.
feedhardordietryin · 2022-09-24 08:24
> `[[cite:key]]` Oh, I see. I've always used either the short form `cite:key` (without the brackets) or the longer version `[[cite:key][p8]]` that's why I did not come up.