[OS X TeX] Find and replace with regular expressions
Alessandro Andretta
alessandroandretta at mac.com
Tue Nov 20 12:41:40 CET 2007
Hi Ross.
First of all, thanks everyone for the help.
Actually Mathew Leingang's suggetion worked almost flawlessly
for my file --- there were only a couple of wrong replacements that
I had to fix by hand, not a big deal.
On 19 Nov 2007, at 21:22, Ross Moore wrote:
> Hello Alessandro,
>
> On 19/11/2007, at 11:20 PM, 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.
>
> That is because this is a very difficult thing to do automatically
> and reliably.
>
>> Is there a simple way to archive this with any of the editors above?
>
> Probably not.
> There have been many replies and hints at the difficulty.
>
> As yet none has mentioned patterns like:
>
> $...math... \mbox{...text...$...$...} ...more math... $
>
> or setting a table inside mathematics, or a table that uses
> math-delimiters in the column-spec part.
> Then there is the case of $ occurring within verbatim environments,
> or \verb+....+ constructions; e.g. for coding examples.
>
> There is also the problem of unmatched $s due to %-comments on
> lines within your LaTeX source.
>
>
> Also, if you have $...$ delimiters, then you probably also
> have $$....$$ displays. So you must cope with these first,
> before handling the single-dollar delimiters.
> Alternatively, cope with the resulting $\(.....\)$ afterwards.
After posting my first message I started mulling why there was
no such feature in the 'search-n-replace' panels of any editors,
and some of the issues you mentioned came to mind...
>
>
>
> devoted to correctly recognising math environments, whether
> the delimiters be $...$ or \(....\) or $$....$$ or \[....\] .
One should get rid of $$...$$ right away.
In fact one should only use \[ ... \] IMHO.
>
> But this coding is not stand-alone, needing a detailed knowledge
> of nesting levels of {....}s, and all the %-comments having been
> replaced already.
I guess one could handle first the commented text.
> If you are serious about doing this, then IMHO it is best to
> use 'Find' and 'Replace & Find Next', looking at each instance
> to verify that you are indeed making the correct delimiter
> replacements for the specific math-environment.
>
Probably so, but if the file is long, well it is a pain.
Thanks again to everyone for the great feedback.
--aa
-------------------------- Helpful Info --------------------------
TeX FAQ: http://www.tex.ac.uk/faq
List Reminders and Etiquette: http://www.esm.psu.edu/mac-tex/list/
List Info: http://email.esm.psu.edu/mailman/listinfo/macosx-tex
List Archive: http://tug.org/pipermail/macostex-archives/
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
More information about the macostex-archives
mailing list