0

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?

7
  • 6
    This depends on the functionalities displayed by your editor.
    – Bernard
    Commented Jul 8, 2022 at 22:23
  • 1
    If your editor supports regex search, then it could be the way to go Commented Jul 8, 2022 at 22:24
  • 4
    You really shouldn't be using $$ in a LaTeX document to begin with. Please see the posting Why is \[ ... \] preferable to $$ ... $$? for more information on this subject.
    – Mico
    Commented Jul 8, 2022 at 22:26
  • @Mico didn't know that! I don't understand the answer in that post, but I'll believe it. So replacing $$ $$ in my question with [ ] , is there a shortcut?
    – 900edges
    Commented Jul 8, 2022 at 22:39
  • 6
    you are asking about editing a file but have not said what editor you are using. latex itself is not really involved here Commented Jul 8, 2022 at 23:50

1 Answer 1

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)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .