Description
Given a LaTeX file with several mathematical formulas inside
where each of them is preceded and followed by tag lines
\[ and \], respectively.
For example,
we want to change the block
\[
y = x + 2
\]
to
\begin{equation}
\label{eqn:x}
y = x + 2
\end{equation}
where x is the formula number numbered from the head of the file.
|
| Raw Input
|
| Desired Output
| some texts
\[
y = x + 2
\]
some texts
\[
z = x^3 + 3*x^2 - 1
\]
some texts
\[
w = x^4 - 4*y^3
\]
some texts
\[
z = x^2 - y
\]
|
| some texts
\begin{equation}
\label{eqn:1}
y = x + 2
\end{equation}
some texts
\begin{equation}
\label{eqn:2}
z = x^3 + 3*x^2 - 1
\end{equation}
some texts
\begin{equation}
\label{eqn:3}
w = x^4 - 4*y^3
\end{equation}
some texts
\begin{equation}
\label{eqn:4}
z = x^2 - y
\end{equation}
|
|
Script and Comments
Script1 [ 1] /^\\[][]$/!b
[ 2] s/\\\]/\\end{equation}/
[ 3] t
[ 4] g
[ 5] s/[0-9]9*$/\n&/
[ 6] h
[ 7] y/0123456789/1234567890/
[ 8] G
[ 9] s/^.*\n(.*)\n(.*)\n.*/\2\1/
[10] s/^(0*)\n*$/1\1/
[11] h
[12] s/^.*/\\begin{equation}\n\\label{eqn:&}/
| |
|