emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Richard Lawrence <richard.lawrence@berkeley.edu>
To: emacs-orgmode@gnu.org
Cc: Vikas Rawal <vikaslists@agrarianresearch.org>
Subject: Re: Managing bibtex database using org-mode?
Date: Thu, 08 May 2014 09:30:09 -0700	[thread overview]
Message-ID: <871tw4xmge.fsf@berkeley.edu> (raw)
In-Reply-To: 587A9279-A389-4A3F-808D-1E090741DD98@agrarianresearch.org

[-- Attachment #1: Type: text/plain, Size: 3371 bytes --]

Hi Vikas and all,

Vikas Rawal <vikaslists@agrarianresearch.org> writes:

>> I manage my whole bibtex database on org. It makes my workflow more
>> integrated. It allows me to keep bib info, todo states and notes all
>> in the same place, and it allows me to access it all through the
>> agenda. I just periodically run org-bibtex to make sure that I have a
>> updated bib file.
>
> This is exactly what I have in mind. Would you mind sharing an example
> file, and may be an outline of your work flow?

I also manage my whole bibtex database in Org.  Here is my setup:

1) I store new readings as I come across them using a capture template.
(See the attached "reading.txt".)  This template is pretty basic, but I
think it could easily be adapted to store more data, such as links to
PDFs, or automatically import Bibtex entries (over org-protocol?) using
a function from org-bibtex.

The relevant stanza from my org-capture-templates is:
#+BEGIN_SRC elisp
	("dr" "Reading" entry
	 (file+olp ,dissertation-agenda-file "Reading list")
	 (file ,(concat org-template-directory "/reading.txt"))
	 :prepend t)
#+END_SRC

2) I use a post-capture hook to detect whether a captured entry is a
reading (it looks for the AUTHOR property) and optionally add
bibliographic data using org-bibtex-create-in-current-entry:

#+BEGIN_SRC elisp
(defun add-bibliographic-data ()
  ; this is a bit hacky: we detect the AUTHOR property, and create bibtex entries if
  ; it is present
  (message "optionally adding bibliographic data")
  (if (and (org-entry-get (point) "AUTHOR")
	   (y-or-n-p "Add bibliographic data? "))
      ; with prefix arg to get all fields:
      (org-bibtex-create-in-current-entry 1)
    nil))

(add-hook 'org-capture-before-finalize-hook (lambda () (add-bibliographic-data)))
#+END_SRC

This completes the `front-end' portion of my setup, which gets data on
new readings into Org.

The `back-end' setup, which exports the captured entries to a .bib file,
involves a Makefile that calls wrappers around org-bibtex functions.

3) All the wrapper functions do is walk over the Org tree containing my
reading list, using org-map-entries, and export each entry with a
defined CUSTOM_ID value using org-bibtex-headline to a new buffer.  (It
skips those with no CUSTOM_ID, since these won't produce valid bibtex
entries.)  This buffer then gets saved as the new .bib file.  The code
is in bib-export.el, attached.

Note that this code makes some assumptions about my setup (mostly that
all reading entries are stored under a top-level "Reading list" heading
in a certain Org file); it is not suitable for general use without some
adaptation.

You can call the wrapper functions from within Emacs using
M-x reading-list-to-bibtex.

4) I also call the wrapper functions from a Makefile.  This allows me to
get a fresh copy of my .bib file whenever it's needed, just by typing
`make bib'.  Here's the relevant stanza from the Makefile, which lives
in the same directory as the file containing my reading list
(tasks.org):

#+BEGIN_SRC make
EMACS=emacs
BATCH_EMACS=$(EMACS) --batch -Q --load lib/el/org-dissertation.el

build/dissertation.bib: tasks.org lib/el/bib-export.el
	$(BATCH_EMACS) --load lib/el/bib-export.el --file tasks.org \
		       --funcall reading-list-to-bibtex

bib: build/dissertation.bib
#+END_SRC

That's it!  Hope you find that useful.

Best,
Richard


[-- Attachment #2: reading.txt --]
[-- Type: text/plain, Size: 170 bytes --]

** %^{Todo state|FIND|PRINT|READ|NOTES} [#%^{Priority|A|B|C}] %^{Description|Reading} %^g
   %^{TITLE}p %^{AUTHOR}p %^{AREA}p %?
   :PROPERTIES:
   :Entered: %U
   :END:

[-- Attachment #3: bib-export.el --]
[-- Type: application/emacs-lisp, Size: 1293 bytes --]

  parent reply	other threads:[~2014-05-08 16:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-07  5:20 Managing bibtex database using org-mode? Vikas Rawal
2014-05-07  7:51 ` Eric S Fraga
2014-05-07  8:55 ` Leonard Avery Randall
2014-05-07 10:29   ` Vikas Rawal
2014-05-08 10:27     ` Leonard Avery Randall
2014-05-08 16:30     ` Richard Lawrence [this message]
2014-06-02 11:29     ` Leonard Avery Randall
2014-06-02 17:31       ` John Kitchin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.orgmode.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=871tw4xmge.fsf@berkeley.edu \
    --to=richard.lawrence@berkeley.edu \
    --cc=emacs-orgmode@gnu.org \
    --cc=vikaslists@agrarianresearch.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public 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).