auctex-devel
[Top][All Lists]
Advanced

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

Re: change $$ to equations with automatic labels


From: Uwe Brauer
Subject: Re: change $$ to equations with automatic labels
Date: Wed, 12 Jan 2022 15:32:11 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/29.0.50 (gnu/linux)

>>> "TH" == Tassilo Horn <tsdh@gnu.org> writes:

> Uwe Brauer <oub@mat.ucm.es> writes:
>> I am using the following code
>> 
>> (defun my-change-dollar-to-equation ()
>> (interactive)
>> (save-excursion
>> (replace-regexp "\\$\\$\\(\\(.\\|\n\\)*?\\)\\$\\$"
>> "\\\\begin{equation}\\1\\\\end{equation}")))

> I just want to mention that this command will shoot into your foot when
> you execute it when point is inside a $$...$$ block.

Oops, I never do that, but good to know.

>> But realized it would be nice to have for every changed equation, a
>> label. I tend to use reftex-label for that purpose. But to include the
>> automatic labeling in that simple function is beyond me, I am afraid.
>> 
>> Can any of the elips gurus help?

> The `replace-regexp' docstring says:

> This function is usually the wrong thing to use in a Lisp program.
> What you probably want is a loop like this:
>   (while (re-search-forward REGEXP nil t)
>     (replace-match TO-STRING nil nil))
> which will run faster and will not set the mark or print anything.

ok
> That will also give you the chance to compose a custom TO-STRING
> programmatically, e.g., something like

>   (concat "\\label{eqn:" my-num "}\n" (match-string 1))

> where you'd have to increment my-num in every iteration.

My hope was to use reftex-label which takes care of all that, but even
with that while loop it might not be possible, or maybe it is hm, I give
it a try later

> Getting the initial value of my-num based on the labels already in the
> document and ensuring that no duplicate labels are added is left as an
> exercise to the reader. ;-)

That is what I tell my students usually, if they have questions... 😉


> You could skip that complication by using labels of the form
> \label{eqn:dollar-converted:<NUM>} in the hope that "dollar-converted"
> is very unlikely to appear in the wild.

Well, I tend to fire up that function sometimes more than once, so I am
not sure whether this is a good idea.

Thanks for pointing out the while loop (should have occurred to me also
sigh 😕 

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


reply via email to

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