bug-auctex
[Top][All Lists]
Advanced

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

bug#57720: 13.1.4; renumbering simple labels doesn't work with tcolorbox


From: Wierdl Máté
Subject: bug#57720: 13.1.4; renumbering simple labels doesn't work with tcolorbox
Date: Sun, 11 Sep 2022 13:08:49 -0500

It now seems to work perfectly.  I tried it not only on the test file but also on the book I have been working on which loads quite a few .tex files.  

Should I put this "defun" into my .emacs for the time being, till it gets incorporated into reftex?

Thx,

Máté

Arash Esbati <arash@gnu.org> ezt írta (időpont: 2022. szept. 11., V, 5:14):
Wierdl Máté <wierdlmate@gmail.com> writes:

> I do not know if this is a reftex or AUCTeX bug.

RefTeX.

> When using theoremlike environments from the tcolorbox, the function
> reftex-renumber-simple-labels messes up. It renumbers the labels in
> references but does nothing to the labels themselves.

The issue is more in the function `reftex-translate' which is called
inside `reftex-renumber-simple-labels': The former is not prepared to
deal with labels inside arguments of environments.  Can you try this
change by copying to scratch buffer, opening your .tex file, eval'ing
this function and then running `reftex-renumber-simple-labels' and see
if it works?

--8<---------------cut here---------------start------------->8---
(defun reftex-translate (files search-re translate-alist error-fmt test)
  ;; In FILES, look for SEARCH-RE and replace match 1 of it with
  ;; its association in TRANSLATE-ALIST.
  ;; If we do not find an association and TEST is non-nil, query
  ;; to ignore the problematic string.
  ;; If TEST is nil, it is ignored without query.
  ;; Return the number of replacements.
  (let ((n 0) file label match-data buf macro pos cell)
    (while (setq file (pop files))
      (setq buf (reftex-get-file-buffer-force file))
      (unless buf
        (error "No such file %s" file))
      (set-buffer buf)
      (save-excursion
        (save-restriction
          (widen)
          (goto-char (point-min))
          (while (re-search-forward search-re nil t)
            (backward-char)
            (save-excursion
              (setq label (reftex-match-string 1)
                    cell (assoc label translate-alist)
                    match-data (match-data)
                    macro (reftex-what-macro 1)
                    pos (cdr macro))
              (goto-char (or pos (point)))
              (when (and macro
                         (or (looking-at "\\\\ref")
                             (looking-at "\\\\[a-zA-Z]*ref\\(range\\)?[^a-zA-Z]")
                             (looking-at "\\\\ref[a-zA-Z]*[^a-zA-Z]")
                             (looking-at (format
                                          reftex-find-label-regexp-format
                                          (regexp-quote label)))
                             ;; In case the label-keyval is inside an
                             ;; optional argument to \begin{env}
                             (looking-at (concat
                                          "\\\\begin[[:space:]]*{[^}]+}"
                                          "[[:space:]]*"
                                          "\\[[^][]*"
                                          (format
                                           reftex-find-label-regexp-format
                                           (regexp-quote label))
                                          "[^][]*\\]"))
                             ;; In case the label-keyval is inside the
                             ;; first mandatory argument to \begin{env}
                             (looking-at (concat
                                          "\\\\begin[[:space:]]*{[^}]+}"
                                          "[[:space:]]*"
                                          "{[^}{]*"
                                          (format
                                           reftex-find-label-regexp-format
                                           (regexp-quote label))
                                          "[^}{]*}"))))
                ;; OK, we should replace it.
                (set-match-data match-data)
                (cond
                 ((and test (not cell))
                  ;; We've got a problem
                  (unwind-protect
                      (progn
                        (reftex-highlight 1 (match-beginning 0) (match-end 0))
                        (ding)
                        (or (y-or-n-p (format error-fmt label))
                            (error "Abort")))
                    (reftex-unhighlight 1)))
                 ((and test cell)
                  (cl-incf n))
                 ((and (not test) cell)
                  ;; Replace
                  (goto-char (match-beginning 1))
                  (delete-region (match-beginning 1) (match-end 1))
                  (insert (cdr cell)))
                 (t nil))))))))
    n))
--8<---------------cut here---------------end--------------->8---

TIA.  Best, Arash

reply via email to

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