Discussion:
How to use the syntax table?
Plamen Tanovski
2005-02-26 22:43:25 UTC
Permalink
Hi,

how can I match the argument of a LaTeX command in a
query-replace-regexp? Let us have

\gogo{asdfas \bobo{adfasd}a adsf} asdf \gogo{adfasd}

Neither \\gogo{.*\s) nor \\gogo{.*?\s) do the right match. And also
how can I find braces across the lines?

At least, why is ` punctuation (and ' not)?

Best regrads,
Ralf Angeli
2005-02-27 08:20:08 UTC
Permalink
Post by Plamen Tanovski
how can I match the argument of a LaTeX command in a
query-replace-regexp? Let us have
\gogo{asdfas \bobo{adfasd}a adsf} asdf \gogo{adfasd}
Neither \\gogo{.*\s) nor \\gogo{.*?\s) do the right match. And also
how can I find braces across the lines?
AFAICT this is not possible. That's why all the code in AUCTeX
dealing with macro arguments determines argument boundaries
differently.

In case you don't need the functionality of being asked for what to do
for every match, you could use something like the following function:

(defun my-TeX-replace-macro-arg (macro string)
"Search for MACRO and replace content of first argument with STRING."
(interactive "sMacro: \nsReplace content with: ")
(save-excursion
(let (start)
(while (re-search-forward (concat "\\\\" macro "{") nil t)
(setq start (point))
(goto-char (TeX-find-closing-brace))
(store-match-data (list start (1- (point))))
(replace-match string)))))

The function is very basic. It does not have any error handling and
matches only macros which have exactly a form of "\foo{bar}".
Post by Plamen Tanovski
At least, why is ` punctuation (and ' not)?
Hm, ' explicitely was given word syntax in AUCTeX as well as in the
default LaTeX mode of Emacs. Unfortunately I don't know why.
--
Ralf
Plamen Tanovski
2005-02-27 13:20:46 UTC
Permalink
Post by Ralf Angeli
In case you don't need the functionality of being asked for what to do
(defun my-TeX-replace-macro-arg (macro string)
"Search for MACRO and replace content of first argument with STRING."
(interactive "sMacro: \nsReplace content with: ")
(save-excursion
(let (start)
(while (re-search-forward (concat "\\\\" macro "{") nil t)
(setq start (point))
(goto-char (TeX-find-closing-brace))
(store-match-data (list start (1- (point))))
(replace-match string)))))
The function is very basic. It does not have any error handling and
matches only macros which have exactly a form of "\foo{bar}".
Thanks. This is a good point for me to start.

Best regards,

Loading...