emacs-orgmode
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[FR] Generalize org-reftex-citation


From: Gustavo Barros
Subject: [FR] Generalize org-reftex-citation
Date: Thu, 24 Dec 2020 16:01:44 -0300
User-agent: mu4e 1.4.13; emacs 27.1

Hi All,

It's been some time since included in my todos to cook something to insert citations in Org using RefTeX's infrastructure. As I set this morning to do so, I found out it already existed: `org-reftex-citation'. Alas, it is not enough for me (and certainly also others), because it uses a simple regexp search for "#+BIBLIOGRAPHY:", thus only being able to find the .bib file with that specific form of declaration. In particular, it does not support biblatex (as far as I can tell).

Before I found out the function existed, I had a general idea of letting RefTeX work in the exported .tex file. It turns out it is easy to adapt `org-reftex-citation' to do precisely that. And in so doing, being thus able to do anything RefTeX is able to support in its native environment, on top of anything Org is able to export. The only disadvantage I see, and which I consider minor, is that the .tex file has to exist.

My take on this neat little idea so far is:

#+begin_src emacs-lisp
(defvar gb/org--rds nil)
(defun gb/org-reftex-citation ()
 "Use `reftex-citation' to insert a citation into the buffer.
The bibliography sources for the base Org file are found by RefTeX itself parsing the corresponding exported \".tex\" file, which is required to exist. Those are passed to `reftex-citation' to insert a citation into the base Org
buffer."
 (interactive)
 (unless (derived-mode-p 'org-mode)
   (user-error "Not an Org buffer"))
 (let ((tex-file (org-export-output-file-name ".tex")))
   (if (file-readable-p tex-file)
       (find-file-noselect tex-file)
(user-error "TeX file not available, export first to %S" tex-file))
   (let ((reftex-docstruct-symbol 'gb/org--rds)
         gb/org--rds)
     (with-current-buffer (get-file-buffer tex-file)
       (reftex-access-scan-info nil)
       (setq gb/org--rds (symbol-value reftex-docstruct-symbol)))
     (call-interactively 'reftex-citation))))
#+end_src

Still lightly tested, but looks good with what I tried out.

So, I thought it was a good idea to send this to the list as suggestion / feature request.

Best regards,
Gustavo.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]