Skip to content

Instantly share code, notes, and snippets.

@kleinschmidt
Last active March 15, 2022 09:19
Show Gist options
  • Save kleinschmidt/5ab0d3c423a7ee013a2c01b3919b009a to your computer and use it in GitHub Desktop.
Save kleinschmidt/5ab0d3c423a7ee013a2c01b3919b009a to your computer and use it in GitHub Desktop.
Insert markdown (pandoc-citeproc) formatted citations using RefTeX
;; reftex in markdown mode
;; if this isn't already set in your .emacs
(setq reftex-default-bibliography '("/path/to/library.bib"))
;; define markdown citation formats
(defvar markdown-cite-format)
(setq markdown-cite-format
'(
(?\C-m . "[@%l]")
(?p . "[@%l]")
(?t . "@%l")
)
)
;; wrap reftex-citation with local variables for markdown format
(defun markdown-reftex-citation ()
(interactive)
(let ((reftex-cite-format markdown-cite-format)
(reftex-cite-key-separator "; @"))
(reftex-citation)))
;; bind modified reftex-citation to C-c[, without enabling reftex-mode
;; https://www.gnu.org/software/auctex/manual/reftex/Citations-Outside-LaTeX.html#SEC31
(add-hook
'markdown-mode-hook
(lambda ()
(define-key markdown-mode-map "\C-c[" 'markdown-reftex-citation)))
@manueldeljesus
Copy link

Thanks for sharing. Would this solution be able to allow to insert several citations in one shot? I see the code referring to key-separator, but I am not being able to make it work. I am very new to Emacs, so it will probably be my fault, but I wanted to make sure nonetheless.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment