auctex-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [AUCTeX-devel] (old) TeX definitions and query-replace-regexp


From: Bernard Hurley
Subject: Re: [AUCTeX-devel] (old) TeX definitions and query-replace-regexp
Date: Sat, 9 Aug 2014 20:57:04 +0100
User-agent: Mutt/1.5.21 (2010-09-15)

On Sat, Aug 09, 2014 at 09:15:41PM +0200, Uwe Brauer wrote:
> Hi
> 
> I am in a state of advanced desperation. I have a couple of old latex
> files which contain a lot of definitions (with arguments) of the sort 
> 
> 
> \newcommand{\nv}[2]{\|#1\|_{H^{#2}}}
> 
> which are used in the document like this
> $\nv{G^a}{s} \leq C_2$ and
> 
> so I just wanted to have a simple elisp function which replaces the \nv
> calls by its definition.
> 
> I thought it should be something like this 
> (query-replace-regexp 
> "\\(\\\\nv{[a-z,A-Z,0-9]*\\^[a-z,A-Z,0-9]*}{[a-z,A-Z,0-9]*}\\)" 
> "\\\\|\\1\\\\|_{H^{\\2}}")

You have not selected the two subexpressions you want to replace correctlty.

re-builder gives the following for the first match:
"\\(?:\\\\nv{\\([[:alnum:]]*\\^[[:alnum:]]*\\)}{\\([[:alnum:]]*\\)}\\)"

But, of course, you could replace each [[:alnum:]] with [a-z,A-Z,0-9] if you 
like.
Note the \\( ... \\) around [[:alnum:]]*\\^[[:alnum:]]* and [[:alnum:]]*. These
select the subexpressions and label then \1 ans \2.  Note also the ?: that stops
the \\( at the beginning selecting a sub expression.

Incidentally if you use regular expression a lot in emacs it is worth getting 
the package rx and re-builder.

I hope this helps.

Bernard.

> 
> but it failed, I tried something simpler
> (query-replace-regexp "\\(\\\\nv{G\\^a}{s}\\)" "\\\\|\\1\\\\|_{H^{\\2}}")
> 
> no success neither. I admit regexps drive me crazy and would appreciate
> any help.
> 
> thanks
> 
> Uwe Brauer 



> _______________________________________________
> auctex-devel mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/auctex-devel




reply via email to

[Prev in Thread] Current Thread [Next in Thread]