I usually use the $$ sign to do in-line equations. But often I realize I want to number it, or turn it into a sequence of aligned equations. I then manually copy and paste the equation out of the $$ $$, type \begin{ equation} and then paste the equation in. Is there a way to do this faster?
Asked
Active
Viewed 98 times
0
1 Answers
4
You have not said what editor you are using. Any reasonable editor should be able to make that edit.
Or you could use a commandline tool such as perl.
For example if file.tex is
$$ 1=1$$
qqqq
$$
2=2
$$
qqqq
$$
2=2
+1
-1
$$
then
perl -0777 -pe 's/\$\$(.*?)\$\$/\\begin{equation}$1\\end{equation}/sg' file.tex >file2.tex
will create a file2.tex that looks like
\begin{equation} 1=1\end{equation}
qqqq
\begin{equation}
2=2
\end{equation}
qqqq
\begin{equation}
2=2
+1
-1
\end{equation}
Note I suggest writing new file rather than doing an in-place edit as it gives you a chance to check the output. (For example this one-liner is not checking mis-matched $$ that may appear in comments or macros or verbatim etc)
David Carlisle
- 757,742
$$in a LaTeX document to begin with. Please see the posting Why is\[ ... \]preferable to$$ ... $$? for more information on this subject. – Mico Jul 08 '22 at 22:26\[and\]. – John Kormylo Jul 08 '22 at 23:09