[OS X TeX] Re: Find and replace with regular expressions

Markus S youcontrol at hispeed.ch
Mon Nov 19 11:37:36 EST 2007

> 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)$.

My poor man's way of doing is do a find all on '$'. Scan the list if 
all equations have at least a space before the $ at the beginning. If 
yes, do a find all for ' $', check again to see if only equations in 
this list and then do replace all. Continue for the end of the 

Or, categorise all occurances of '$'. If they are only of the type \$ 
and $ equation $ then first replace \$ with something else that is 
unique and use your regex. Finally, replace that unique string with \$ 

More information about the MacOSX-TeX mailing list