Hi all,

I have recently had little time to follow the AUCTeX mailing list.
Yesterday, however, I received the announcement of version 14.0.1. Among
the new features was the function *LaTeX-modify-math*, which I very much
appreciate. I had previously written my own rather fragile kludges to
achieve similar results—this new implementation is far more robust.

There is, however, one enhancement I would like to propose—at least as
an optional feature—though I suspect the answer may be “no”.

When the target environment is an *equation*, could a label not be
inserted automatically? And by “automatically,” I mean integrated with
RefTeX’s label system. The *equation* environment typically produces
numbered equations (unless one is using =mathtools=, where the logic
becomes more intricate), and it is common to refer to them later in the
document.

That said, I am aware of the standard objection: RefTeX is a separate
package, and its integration with AUCTeX remains incomplete. Even so:

+ AUCTeX already permits interaction with RefTeX to some extent.

+ A new user option could be introduced, such as
  `use-reftex-labels-for-latex-modify-math`.

For reference, I have included below a function, courtesy of Arash,
which converts all =$$ ... $$= math environments into =equation=
environments complete with RefTeX labels.


Regards

Uwe Brauer  


(defun my-change-dollar-to-equation-label ()
  "Courtesy from Arash Esbati
[[https://groups.google.com/groups/search?as_umsgid=86fspsavpa....@gnu.org][Email
 from Arash Esbati: Re: change $$ to equations with automatic labels]]:
This function not only replaces displayed plain TeX equations with a `$$' 
equations with
the `\begin{{equation}' environment, but it also inserts an
appropriate label via `reftex-label'"
  (interactive)
  (let ((p (point-marker))
        (s (make-marker))
        (e (make-marker)))
    (goto-char (point-min))
    (while (re-search-forward (concat "^" (regexp-quote "$$")) nil t)
      ;; Start doing something if we are in a math evn:
      (when (texmathp)
        (set-marker s (point))
        ;; Search for the closing $$ pair:
        (re-search-forward (concat "^" (regexp-quote "$$")))
        (set-marker e (point))
        (delete-backward-char 2)
        (insert "\\end{equation}")
        (delete-horizontal-space)
        (goto-char s)
        (delete-backward-char 2)
        (insert "\\begin{equation}")
        (delete-horizontal-space)
        ;; Indent the environment:
        (goto-char e)
        (indent-according-to-mode)
        (goto-char s)
        (indent-according-to-mode)
        ;; Check if there is already a \label:
        (unless (re-search-forward "\\\\label{" e t)
          (goto-char s)
          (forward-line)
          (indent-according-to-mode)
          (reftex-label)
          (LaTeX-newline)
          (indent-according-to-mode))))
    (goto-char p)
    (set-marker p nil)
    (set-marker s nil)
    (set-marker e nil)))
-- 
I strongly condemn Hamas heinous despicable pogroms/atrocities on Israel
I strongly condemn Putin's war of aggression against Ukraine.
I support to deliver weapons to Ukraine's military. 
I support the EU and NATO membership of Ukraine. 

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to