Subject: Re: bug#31132: AUCTeX, RefTeX and biblatex's multicite commands

From: Arash Esbati <[email-masked]>
Date: Sat, 06 Apr 2024 23:00:39 +0200

Hi Gustavo,

Gustavo Barros <[email-masked]> writes:

> thank you very much for the patches. They are really appreciated.
> And sorry for the delay in reporting back. I didn't have the time
> these last couple of days to look at this with due care.

Sorry for my late response; it seems I didn't have time during the last
couple of years ;-)  Somehow this report went lost.

> I've performed some tests with the patches you sent on the full set of
> biblatex's citation commands, and can gladly report that both "C-c &"
> (reftex-view-crossref) and "C-c [" (reftex-citation) (when issued on
> the key of an existing citation command) work flawlessly on all of
> them.

I had a look again and I plan to install the following change in Emacs
master:

--8<---------------cut here---------------start------------->8---
diff --git a/lisp/textmodes/reftex-parse.el b/lisp/textmodes/reftex-parse.el
index 9694a1364d3..6e1c229561a 100644
--- a/lisp/textmodes/reftex-parse.el
+++ b/lisp/textmodes/reftex-parse.el
@@ -801,17 +801,17 @@ reftex-notice-new
   )

 (defsubst reftex-move-to-previous-arg (&optional bound)
-  "Assuming that we are in front of a macro argument,
-move backward to the closing parenthesis of the previous argument.
-This function understands the splitting of macros over several lines
-in TeX."
+  "Move backward to the closing parenthesis of the previous argument.
+This happens under the assumption that we are in front of a macro
+argument.  This function understands the splitting of macros over
+several lines in TeX."
   (cond
    ;; Just to be quick:
-   ((memq (preceding-char) '(?\] ?\})))
+   ((memq (preceding-char) '(?\] ?\) ?\})))
    ;; Do a search
    ((and reftex-allow-detached-macro-args
          (re-search-backward
-          "[]}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t))
+          "[])}][ \t]*[\n\r]?\\([ \t]*%[^\n\r]*[\n\r]\\)*[ \t]*\\=" bound t))
     (goto-char (1+ (match-beginning 0)))
     t)
    (t nil)))
@@ -860,13 +860,19 @@ reftex-what-macro
             (while (and (reftex-move-to-previous-arg bound)
                         (condition-case nil
                             (let ((forward-sexp-function nil))
-                              (backward-sexp) t)
+                              (if (eq (preceding-char) ?\))
+                                  (let ((temp-table (make-syntax-table)))
+                                    (modify-syntax-entry ?\( "()" temp-table)
+                                    (modify-syntax-entry ?\) ")(" temp-table)
+                                    (with-syntax-table temp-table
+                                      (backward-sexp)))
+                                (backward-sexp))
+                              t)
                           (error nil)))
-              (if (eq (following-char) ?\[) (cl-incf cnt-opt))
+              (if (memq (following-char) '(?\( ?\[)) (cl-incf cnt-opt))
               (cl-incf cnt))
             (setq pos (point))
-            (when (and (or (= (following-char) ?\[)
-                           (= (following-char) ?\{))
+            (when (and (memq (following-char) '(?\[ ?\( ?\{))
                        (re-search-backward "\\\\[*a-zA-Z]+\\=" nil t))
               (setq cmd (reftex-match-string 0))
               (when (looking-at "\\\\begin{[^}]*}")
--8<---------------cut here---------------end--------------->8---

Do you have the chance to install this locally and test it again?  I
will push it afterwards.  Thanks.

> But, in performing the tests, I observed some other things associated
> with biblatex's citation commands (some related to this issue, some
> not) that I might as well report too, in the hope they will be
> useful. As a regular biblatex user, I consider them minor.
>
> 1 - The multicite variants of 'volcite' are neither fontified nor call
> RefTeX when inserted (with "C-c RET"). They are inserted "plain" but,
> once inserted, "C-c [" will work on them. They are the following:
> -volcites
> -Volcites
> -pvolcites
> -Pvolcites
> -fvolcites
> -Fvolcites
> -svolcites
> -Svolcites
> -tvolcites
> -Tvolcites
> -avolcites
> -Avolcites

Fontification should work now for limited number of args:
https://git.savannah.gnu.org/cgit/auctex.git/tree/font-latex.el#n305

> 2 - A couple of 'volcite' variants are fontified, but don't call
> RefTeX when inserted:
> -pvolcite
> -ftvolcite

Fixed with commit 9ba0093b.

> 3 - One command is not fontified:
> -footfullcite

Is fixed.

> 4 - 'mcite'-like citation commands are neither fontified, nor call
> RefTeX when inserted:
> -mcite
> -Mcite
> -mparencite
> -Mparencite
> -mfootcite
> -mfootcitetext
> -mtextcite
> -Mtextcite

This is indeed nasty because of the notation (biblatex.pdf, page 120):

\mcite{key1,setA,*keyA1,*keyA2,*keyA3,key2,setB,*keyB1,*keyB2,*keyB3}

I have no idea what the best approach for this is.

Again, sorry the late response.

Best, Arash