(defun reftex-all-used-citation-keys ()
"Return a list of all citation keys used in document."
(reftex-access-scan-info)
- ;; FIXME: multicites macros provided by biblatex
- ;; are not covered in this function.
(let ((files (reftex-all-document-files))
(re (concat "\\\\"
"\\(?:"
"\\)"
;; Now match the key:
"{\\([^}]+\\)}"))
+ ;; Multicites: Match \MACRONAME(Global Pre)(Global Post)
+ (re2 (concat "\\\\"
+ (regexp-opt '("cites" "Cites"
+ "parencites" "Parencites"
+ "footcites" "footcitetexts"
+ "smartcites" "Smartcites"
+ "textcites" "Textcites"
+ "supercites"
+ "autocites" "Autocites"
+ "volcites" "Volcites"
+ "pvolcites" "Pvolcites"
+ "fvolcites" "Fvolcites"
+ "svolcites" "Svolcites"
+ "tvolcites" "Tvolcites"
+ "avolcites" "Avolcites"))
+ "\\(?:([^)]*)\\)\\{0,2\\}"))
+ ;; For each key in list [prenote][postnote]{key}
+ (re3 (concat "\\(?:\\[[^]]*\\]\\)\\{0,2\\}"
+ "{\\([^}]+\\)}"))
file keys kk k)
(save-current-buffer
(while (setq file (pop files))
(setq kk (split-string kk "[, \t\r\n]+"))
(while (setq k (pop kk))
(or (member k keys)
- (setq keys (cons k keys))))))))))
+ (setq keys (cons k keys))))))
+ ;; And now search for citation lists:
+ (goto-char (point-min))
+ (while (re-search-forward re2 nil t)
+ ;; Make sure we're not inside a comment:
+ (unless (save-match-data
+ (nth 4 (syntax-ppss)))
+ (while (progn
+ ;; Ignore the value of
+ ;; `reftex-allow-detached-macro-args' since we
+ ;; expect a bigger number of args and detaching
+ ;; them seems natural for line breaks:
+ (while (looking-at "[ \t\r\n]+\\|%.*\n")
+ (goto-char (match-end 0)))
+ (and (looking-at re3)
+ (goto-char (match-end 0))))
+ (setq kk (match-string-no-properties 1))
+ (while (string-match "%.*\n?" kk)
+ (setq kk (replace-match "" t t kk)))
+ (setq kk (split-string kk "[, \t\r\n]+"))
+ (while (setq k (pop kk))
+ (or (member k keys)
+ (setq keys (cons k keys)))))))))))
(reftex-kill-temporary-buffers)
keys))
\\Citep[pre][pos]{Citep:2022}
\\Citep*[pre][pos]{Citep*:2022}
+Qualified Citation Lists:
+\\cites(Global Prenote)(Global Postnote)[pre][post]{cites:1}[pre][post]{cites:2}
+\\Cites(Global Prenote)(Global Postnote)[pre][post]{Cites:1}[pre][post]{Cites:2}
+\\parencites(Global Prenote)(Global Postnote)[pre][post]{parencites:1}
+ [pre][post]{parencites:2}
+\\Parencites(Global Prenote)(Global Postnote)[pre][post]{Parencites:1}{Parencites:2}
+\\footcites[pre][post]{footcites:1}[pre][post]{footcites:2}
+\\footcitetexts{footcitetexts:1}{footcitetexts:2}
+\\smartcites{smartcites:1}
+% This is comment about \\smartcites{smartcites:2}
+[pre][post]{smartcites:2}
+% And this should be ignored \\smartcites{smartcites:3}{smartcites:4}
+
+
Test for bug#56655:
There was a few \\% of increase in budget \\Citep*{bug:56655}.
"citealp:2022" "citealp*:2022"
"Citet:2022" "Citet*:2022"
"Citep:2022" "Citep*:2022"
+ ;; Qualified Citation Lists
+ "cites:1" "cites:2"
+ "Cites:1" "Cites:2"
+ "parencites:1" "parencites:2"
+ "Parencites:1" "Parencites:2"
+ "footcites:1" "footcites:2"
+ "footcitetexts:1" "footcitetexts:2"
+ "smartcites:1" "smartcites:2"
"bug:56655")
#'string<)))
(kill-buffer (file-name-nondirectory tex-file)))))