[OS X TeX] Find and replace with regular expressions
Eric Jablow
ejablow at cox.net
Mon Nov 19 14:39:33 CET 2007
On Nov 19, 2007, at 8:18 AM, Matthew Leingang wrote:
> On Nov 19, 2007, at 7:20 AM, Alessandro Andretta wrote:
>
>> I would like to replace the $ signs in a LaTeX file with \( and \)
>> thus I would have to search for $...$ and replace it with \( ... \)
>> where ... is any string of symbols (letters, numbers, \ , {} &,etc)
>> EXCEPT $. I tried the help menu of TeXShop, TextMate, Textwrangler,
>> but their general treatment seems be a bit too technical for my
>> taste.
>> Is there a simple way to archive this with any of the editors above?
>
> Dear Alessandro,
>
> Good question. You need a more advanced search-and-replace
> capability that looks at the context, not just the string itself.
> This is what regular expressions [1] are for.
>
> TeXShop has regular expression support built in. So you can open up
> a find window,
> put this in the search box
>
> \$([^$]+)\$
>
> and this in the replace box
>
> \\(\1\\)
>
> make sure you click "Regular Expressions," and go.
This has some flaws. You need negative look-behind assertions in the
search, because you don't want to pick up the \$ of
Acme sells widgets for \$5.00 a unit. The cost to produce $x$
widgets is $2x-0.03 x^2$ dollars.
Different regex engines have different ways of handling such assertions.
Respectfully,
Eric Jablow
More information about the macostex-archives
mailing list