0

There are only really two kinds of citations I need to have in my paper

  1. (Lewis, 2001)
  2. (Lewis, 2001:54) where 54 is the page number

After a ton of googling I managed to find out that it's possible to create both these kinds of citations with org-ref in org-mode [1] [2]

For a minimal example:

#+LATEX_HEADER: \usepackage[round]{natbib}
#+LATEX_HEADER: \setcitestyle{notesep={:}}

* Test
1. This is an author year citation citep:lewis_plurality_2001
2. This has a page number [[cite:lewis_plurality_2001][100]]

bibliographystyle:apalike
bibliography:bibliography.bib

Will create:

  1. This is an author year citation (Lewis, 2001)
  2. This has a page number (Lewis, 2001:100)

But as noted in How to cite author-date including page number in org-mode? - to achieve the citation with page number you have to type [[cite:lewis_plurality_2001][100]]

The problem is that it will be virtually impossible to write a paper where you have to stop and square bracket every reference in that way. So I'm wondering if there isn't an easier way to do this with org-ref that I'm missing ?

1

If you know the bibtex key you want to cite then you can use org-insert-link to do this. Usually that is bound to C-c C-l, you will be prompted for what kind of link, you can choose cite (the capitalization is a little annoying and you might have to figure out how to not get Cite with this. I use ivy, and I have to toggle the case sensitivity, and search for ^cite: to get what I want.), then use completion to select the bibtex key, then you will be prompted for the description.

If you want the completion on the title/author etc, you need to make a new function like this

(defun harvard-cite (key page)
  (interactive (list (completing-read "Cite: " (orhc-bibtex-candidates))
             (read-string "Page: ")))


  (insert
   (org-make-link-string (format "cite:%s"
                 (cdr (assoc
                       "=key="
                       (cdr (assoc key (orhc-bibtex-candidates))))))
             page)))

Then, you can bind it to a convenient key and get on with your writing.

  • Thank you so much Professor Kitchin - didn't expect I'd be getting an answer directly from you! org-insert-link is exactly what I was looking for and works pretty much perfectly. But the harvard-cite function is the cherry on top and is just that much faster b/c you don't have to select the citation type first. For some reason though my orhc-bibtex-candidates was empty so I also had to evaluate (setq org-ref-bibtex-files '("references.bib")) – nmu Sep 4 at 20:31
0

Just wanted to mention another possible way of doing this, building on what Professor Kitchin said. I am also a complete lisp noob so this may violate lisp intergalactic laws I am not aware of, be that as it may - the function does seem to work for me.

The harvard-cite function works near perfectly fine just by itself. The only other thing I had to do to get it running was add (setq org-ref-bibtex-files '("bibliography.bib")) to my ~/.emacs otherwise my orhc-bibtex-candidates would be empty.

As it is the function will use only a single citation type with a page number, but if you also listen for an ivy prefix arg, then you can do a M-X harvard-cite and when hovering over an entry hit C-u to choose a different citation type. But if you just hit RET your default citation link will be used.

After reading https://kitchingroup.cheme.cmu.edu/blog/2016/06/14/Using-prefix-args-in-ivy-actions/ I somehow managed to modify the function to do just that. And with the code below you can select an alternate citation with C-u RET.

(setq org-ref-bibtex-files '("bibliography.bib")) ;; replace with your default bib file
(defun harvard-cite (entry page)
  (interactive (list (completing-read "Cite: "
                                      (orhc-bibtex-candidates))
                     (read-string "Page: ")))
  (setq key (cdr (assoc "=key=" (cdr (assoc entry (orhc-bibtex-candidates))))))
  (setq type (if ivy-current-prefix-arg
                 (ivy-read "type: " org-ref-cite-types)
                 org-ref-default-citation-link))
  (insert (org-make-link-string (format "%s:%s" type key) page)))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.