[OS X TeX] Find and replace with regular expressions
Art Werschulz
agw at comcast.net
Mon Nov 19 12:19:28 EST 2007
Hi.
On Nov 19, 2007, at 11:24 AM, Matthew Leingang wrote:
>>> 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.
>
> Indeed, my original response pointed out that very flaw, and
> others. But I wanted to give an answer which would probably work
> for a lot of the document, and if he wanted to (learn enough to)
> tweak the regex he could, or just find the rest manually, he'd
> still save a lot of work.
>
> Is there any regex that's going to work 100% of the time?. How
> would you fix the text
>
> Acme sells widgets for \$5.00 a unit. The cost to produce $x$
> widgets is $\$(2x-0.03 x^2)$.
You'd need to make sure that the dollar signs aren't preceded by
backslashes. So if you replace "$" by "[^\\]$" in the original
regexp, you should be okay. Please note that I have not tested this
out, and so it may need tweaking. Don't try this on your only copy
of the file!!!
Art Werschulz (8-{)} "Metaphors be with you." -- bumper sticker
GCS/M (GAT): d? -p+ c++ l u+(-) e--- m* s n+ h f g+ w+ t++ r- y?
Internet: agw STRUDEL comcast.net
More information about the MacOSX-TeX
mailing list