org-mode to write a paper, with RefTeX as minor-mode to insert quotations from a BibTeX (
RefTeX needs to be told which
.bib file to use. This is done by assigning a value to
I would like a
.bib file to be automatically assigned, depending on the name of the file I am editing. For example, if I edit a paper called
the-life-of-ants.org, RefTeX should automatically load
the-life-of-ants.bib, stored in the same folder as the
.bib file with the same name as the
.org file is stored in the local directory, my default bibliography file should be loaded instead.
This is in Emacs 25.3.1 on Windows 7.
I've tried a function that is called whenever
org-mode is loaded, using a hook in the last line of the code below. (The code also does some unrelated stuff, like changing the default keybinding for inserting citations to make it compatible with org-mode standard bindings.)
(defun org-mode-reftex-setup () (load-library "reftex") (and (buffer-file-name) (file-exists-p (buffer-file-name)) (reftex-parse-all)) (define-key org-mode-map (kbd "C-c (") 'reftex-citation) ; key-binding (if (file-exists-p (concat (file-name-sans-extension buffer-file-name) ".bib")) ; either use local .bib file (progn (setq reftex-default-bibliography (convert-standard-filename (concat (file-name-sans-extension buffer-file-name) ".bib"))) (message "Local bib-file loaded.")) ; or use default .bib file (progn (setq reftex-default-bibliography '"c:\\foo\\bar\\baz\\References.bib") (message "No bib-file found. Using default bibliography.")))) (add-hook 'org-mode-hook 'org-mode-reftex-setup)
Upon visiting an Org file, the function is executed as expected, and the correct value (it seems) is assigned to
reftex-default-bibliography -- or is it?
M-x eval-expression (message reftex-default-bibliography) tells me:
I don't understand why two lines are produced, one with quotes and double-backslashes (which are needed, I think, to correctly parse file-paths in MS Windows, and which are produced by
convert-standard-filename), and one without.
M-x eval-expression reftex-default-bibliography tells me only:
which seems to be correct.
And yet, when I try to insert a reference, I get an error:
reftex-locate-file: Wrong type argument: stringp, 99
What could be the problem here?