[Top][All Lists]

[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: Arash Esbati
Subject: bug#57720: 13.1.4; renumbering simple labels doesn't work with tcolorbox
Date: Sun, 11 Sep 2022 22:40:17 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50

Wierdl Máté <wierdlmate@gmail.com> writes:

> 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.

Thanks for testing, also on a bigger project, that gives me a better feeling.

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

I think I will install this version which seems a little more robust to

--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)
        (opt-re (concat "\\(?:{[^}{]*"
        (man-re (concat "\\(?:{[^}{]*"
        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)
          (goto-char (point-min))
          (while (re-search-forward search-re nil t)
              (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 "\\\\ref[a-zA-Z]*[^a-zA-Z]")
                             (looking-at (format
                                          (regexp-quote label)))
                             ;; In case the label-keyval is inside an
                             ;; optional argument to \begin{env}
                             (looking-at (concat
                                           (regexp-quote label))
                             ;; In case the label-keyval is inside the
                             ;; first mandatory argument to \begin{env}
                             (looking-at (concat
                                           (regexp-quote label))
                ;; OK, we should replace it.
                (set-match-data match-data)
                 ((and test (not cell))
                  ;; We've got a problem
                        (reftex-highlight 1 (match-beginning 0) (match-end 0))
                        (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))))))))
--8<---------------cut here---------------end--------------->8---

And yes, you will have to put in your .emacs wrapped in

    (with-eval-after-load 'reftex-global
      (defun ...)

until Emacs 29 is out and you're using it (unless you want to built the
version out of Emacs repo and use it)

Best, Arash

reply via email to

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