Reputation: 43
I received a 100 page Latex document with all equations between $$...$$
and I need to change them all to \begin{equation}...\end{equation}
Is there some clever way to do this in Latex (some built in functionality) or in Vim?
In Vim I am thinking
Either: a way to replace abc
with dbf
where all letters stand for patterns.
Or: replace all $$
with \begin{equation}
, then replace every second \begin{equation}
with \end{equation}
I'm not sure how to accomplish either though.
Upvotes: 4
Views: 732
Reputation: 4589
Using Vim:
Use a recording(:help q
), e.g. qe
:
$$
you want to change\begin{equation}
$$
\end{equation}
$$
Reapply recording with @
, @e
in my example.
@
takes a count, see :help @
Upvotes: 1
Reputation: 926
:%s/\$\$\(\_.\{-}\)\$\$/\\begin{equation}\1\\end{equation}/g
It searches $$
followed by everything (.
) including newline (\_
), non greedy (\{-}
), followed by another $$
. On the right part, \1
means "put the backreference" number 1, i.e. the first \(...\)
on the left.
This works with equations on single or multiple lines.
Upvotes: 4