>>> "PDN" == Paul D Nelson <ultr...@gmail.com> writes:
> Hi Uwe, > Uwe Brauer <o...@mat.ucm.es> writes: >> 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. >> >> (...) >> >> When the target environment is an *equation*, could a label not be >> inserted automatically? > When LaTeX-modify-math creates an equation environment, it does so via > LaTeX-insert-environment, which comes with the hook > LaTeX-after-insert-env-hook. I think you get what you want via > (LaTeX-modify-math "equation") and the following: > (defun my-after-insert-environment-hook (name beg end) > "Add label to newly inserted equation environments. > NAME is the environment just inserted, while BEG and END are the > positions just before \\begin and \\end." > (when (equal name "equation") > (unless (save-excursion (goto-char beg) > (search-forward "\\label{" end t)) > (save-excursion (goto-char beg) > (end-of-line) > (reftex-label))))) > (add-hook 'LaTeX-after-insert-env-hook #'my-after-insert-environment-hook) > What do you think? This seems to me as capable as introducing an > option, but a bit more flexible, because you can control exactly where > and how the label is inserted. Thanks very much, I just tried it out, very nice, however I made a small (most likely old fashioned change) --8<---------------cut here---------------start------------->8--- (defun my-after-insert-environment-hook (name beg end) "Add label to newly inserted equation environments. NAME is the environment just inserted, while BEG and END are the positions just before \\begin and \\end." (when (equal name "equation") (unless (save-excursion (goto-char beg) (search-forward "\\label{" end t)) (save-excursion (goto-char beg) (end-of-line) (insert "\n") ;are there more modern solutions? (reftex-label))))) --8<---------------cut here---------------end--------------->8--- Uwe -- 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.
smime.p7s
Description: S/MIME cryptographic signature