[Top][All Lists]

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

[AUCTeX] Removing curly braces in RefTex custom citation format

From: Adrian Bradd
Subject: [AUCTeX] Removing curly braces in RefTex custom citation format
Date: Fri, 11 Dec 2015 18:45:48 -0500


I am running Emacs 24.5 (9.0) on Mac OS X 10.10.5. I am trying to use RefTex in Org mode for tracking research papers by using an altered RefTex citation format to paste in the title and a link to the paper. The code is:

(defun org-mode-reftex-setup ()
  (load-library "reftex")
  (and (buffer-file-name) (file-exists-p (buffer-file-name))
     ;enable auto-revert-mode to update reftex when bibtex file changes on disk
     (global-auto-revert-mode t)
     ;add a custom reftex cite format to insert links
     (reftex-set-cite-format "** [[papers:%1a/%y_%t][%l]]: %t \n")))
  (define-key org-mode-map (kbd "C-c )") 'reftex-citation))
(add-hook 'org-mode-hook 'org-mode-reftex-setup)
(setq org-link-abbrev-alist '(("papers" . "D:/Dropbox/Literature/Papers/%s.pdf")))

The issue occurs when there are curly braces in the title field of the BibTex document. It just so happens that Mendeley always surrounds the title in curly braces. So when this reference is placed in my file there are curly braces surrounding the title. It also breaks the link to the pdf by inserting the curly braces in the link. The blog post I stole this idea from cataloged their papers using the BibTex cite key. I don't really like that method and Mendeley isn't capable of it anyway, so I have convinced myself I need to figure out how to make this format work.

My elisp isn't great as I am new to it, but I tried to do some text replacement to solve the issue. I tested it with:

(?a . (concat "[[papers:%1a/%y_%t][%l]]:" (replace-regexp-in-string "\[\({|}\)\]" "" "%t")))

However, this does not seem to work. It reverts back to the \cite default format when I place the reference in my file. Probably because whatever I am doing isn't right.

A way to deal with this may be to alter the function of %t to remove curly braces (via text replacement?). In the Emacs wiki there is a section about changing the cite function to prepend a ~ in certain circumstances:

(setq reftex-format-cite-function 
          '(lambda (key fmt)
	     (let ((cite (replace-regexp-in-string "%l" key fmt)))
	       (if (or (= ?~ (string-to-char fmt))
		       (member (preceding-char) '(?\ ?\t ?\n ?~)))
	         (concat "~" cite)))))

It isn't entirely clear to me if this could work for my use case and how best to implement it. I was hoping someone could give me some advice on the best approach for this.



reply via email to

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