emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [FR] Generalize org-reftex-citation
@ 2020-12-24 19:01 Gustavo Barros
  0 siblings, 0 replies; only message in thread
From: Gustavo Barros @ 2020-12-24 19:01 UTC (permalink / raw)
  To: emacs-orgmode

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.


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-12-24 19:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-24 19:01 [FR] Generalize org-reftex-citation Gustavo Barros

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).