[Top][All Lists]

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

Re: Select and insert multiple bibliography entries into one \cite comma

From: Arash Esbati
Subject: Re: Select and insert multiple bibliography entries into one \cite command with regexp search.
Date: Thu, 12 Aug 2021 21:59:22 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50

Vladimir Lomov <> writes:

> The advice is simple: don't use full path, try to put your bibtex files into
> $HOME/texmf/bibtex/bib/hongyi/

I agree.

Besides, we could teach RefTeX to ignore the \string macro in the
argument of \bibliography by patching the function
`reftex-locate-bibliography-files'.  Non-compilable .tex file:

--8<---------------cut here---------------start------------->8---



(defun reftex-locate-bibliography-files (master-dir &optional files)
  "Scan buffer for bibliography macros and return file list."
  (unless files
      (goto-char (point-min))
      ;; when biblatex is used, multiple \bibliography or
      ;; \addbibresource macros are allowed.  With plain bibtex, only
      ;; the first is used.
      (let ((using-biblatex (reftex-using-biblatex-p))
            (again t))
        (while (and again
                      ;; "\\(\\`\\|[\n\r]\\)[^%]*\\\\\\("
                      (mapconcat #'identity reftex-bibliography-commands "\\|")
                      ;; "\\)\\(\\[.+?\\]\\)?{[ \t]*\\([^}]+\\)")
                      ;; Patched regexp:
                      "\\)\\(\\[.+?\\]\\)?{[ \t]*\\(?:\\\\string\\|noexpand[ 
                     nil t))
          (setq files
                (append files
                        (split-string (reftex-match-string 4)
                                      "[ \t\n\r]*,[ \t\n\r]*")))
          (unless using-biblatex
            (setq again nil))))))
  (when files
    (setq files
           (lambda (x)
             (if (or (member x reftex-bibfile-ignore-list)
                     (delq nil (mapcar (lambda (re) (string-match re x))
                 ;; excluded file
               ;; find the file
               (reftex-locate-file x "bib" master-dir)))
    (delq nil files)))

(insert "\n"
        (format "%S" (symbol-value reftex-docstruct-symbol)))

% Put the name of your .bib file in the argument:


%%% Local Variables:
%%% mode: latex
%%% TeX-master: t
%%% End:
--8<---------------cut here---------------end--------------->8---

Open this file, adjust the argument of \bibliography to your .bib file,
let RefTeX parse the file and eval the (insert ...) form.  RefTeX will
fail to put the (bib "~/path/to/bib-file-sans-extension") into
`reftex-docstruct-symbol'.  Now eval the function, parse the file and
eval the (insert ...) form again.  It should work now.

I won't push this change to RefTeX/Emacs repo since I think it is a hack
and a clear solution is already there: The simple advice above and

Best, Arash

reply via email to

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