[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
replace regexp question
From: |
Seweryn Kokot |
Subject: |
replace regexp question |
Date: |
Mon, 14 May 2007 12:33:41 +0200 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.0.95 (gnu/linux) |
Hello,
Assume in a latex file I have a lot of occurences like these:
\begin{figure}[htbp]
\centering
\includegraphics{filename}
\caption{Text}
\label{fig:label}
\end{figure}
and
\begin{table}[htbp]
\centering
\caption{Text}
\label{tab:label}
\captab{tab:label}{text}{}
\begin{tabular}{ccc}
...
\end{tabular}
\end{table}
I want to change all occurences \caption and \label to get something
like these:
\begin{figure}[htbp]
\centering
\includegraphics{filename}
\capfig{fig:label}{Text}{}
\end{figure}
and
\begin{table}[htbp]
\centering
\captab{tab:label}{text}{}
\begin{tabular}{ccc}
...
\end{tabular}
\end{table}
So I wrote a function if .emacs
(defun my-caption-to-capfig ()
"bar"
(interactive)
(while (re-search-forward
"\\\\caption\{\\(.*\\)\}\s*\n\s*\\\\label\{\\(.*\\)\}\s*\n\s*\\\\end\{figure\}"
nil t)
(replace-match
"\\\\capfig{\\2}{\\1}{}\n\\\\end{figure}")))
(defun my-caption-to-captab ()
"foo"
(interactive)
(while (re-search-forward
"\\\\caption\{\\(.*\\)\}\s*\n\s*\\\\label\{\\(.*\\)\}\s*\n\s*\\\\begin\{tabular\}"
nil t)
(replace-match "\\\\captab{\\2}{\\1}{}\n\\\\begin{tabular}")))
but sometimes \end{figure} and \begin{tabular} are indented and then after
replacing I get it
without indent. How to take it into account in (replace-match "...") function?
regards,
Seweryn Kokot
- replace regexp question,
Seweryn Kokot <=