[OS X TeX] Boldface

Peder Axensten peder at axensten.se
Sun Feb 13 18:48:31 EST 2005


On 13 feb 2005, at 22.28, Alain Schremmer wrote:

> It can matter—a bit: Say you were writing about three "occurrences" of 
> something and that you wanted to index "occurence".
> But this is really a shortcoming of NewTerm.
> I think that there are a couple of occurences of this in my book but I 
> will change the wording around it as I come across them (in one of my 
> many rereads).
>
> What I am curious about is what the difference is between (.+?) and 
> [^}]* (I assume that this is to allow the reference \1.)
>
> find
> \\textbf{(.+?)}\\index{\1}
> replace with
> \\NewTerm{\1}"
> and

I'll illustrate the difference by example, in the above case
"text \textbf{one {\Large two} three}\index{one {\Large two} three} 
text \textbf{one {\Large two} three}\index{one {\Large two} three} 
text"
becomes
"text \NewTerm{one {\Large two} three} text \NewTerm{one {\Large two} 
three} text"

> find
> \\textbf{[^}]*}\\index{
> replace with:
> \\NewTerm{

Here it stays the same since the inner {...} prevents a match.


To demonstrate the difference between greedy and non-greedu I give 
another example:

If you changed the first variant to "\\textbf{(.+)}\\index{\1}" -- to 
be greedy -- you'll get the same result in this case since the argument 
of index must be the same as the argument of textbf.

However, allowing different arguments results in different results:

find "\\textbf{(.+?)}\\index{(.+?)}" replace with "\\NewTerm{\1}{\2}"
results in "text \NewTerm{one {\Large two} three}{one {\Large two} 
three} text \NewTerm{one {\Large two} three}{one {\Large two} three} 
text"

whereas find "\\textbf{(.+)}\\index{(.+)}" replace with 
"\\NewTerm{\1}{\2}"
results in "text \NewTerm{one {\Large two} three}\index{one {\Large 
two} three} text \textbf{one {\Large two} three}{one {\Large two} 
three} text"

in this case the first "(.+)" mathes "one {\Large two} three}\index{one 
{\Large two} three} text \textbf{one {\Large two} three"
and not, as was intended, "one {\Large two} three".

Well, I don't know how illustrative this was.
IMHExperience, you want the expression to be non-greedy almost always.

> Regards
> --schremmer
>
>
> Peder Axensten wrote:
>
>> I guess that in practise it doesn't really matter, but using 
>> "\\textbf{(.+?)}\\index{.+?}" would incorrectly change "\textbf{one 
>> text}\index{different text}" to " \NewTerm{one text}".
>>
>> I suggest find "\\textbf{(.+?)}\\index{\1}", replace with 
>> "\\NewTerm{\1}".
>>
>> On 13 feb 2005, at 21.05, Maarten Sneep wrote:
>>
>>> On 13 feb 2005, at 19:28, Alain Schremmer wrote:
>>>
>>>> Of course, it works very nicely but good deeds are always punished: 
>>>> I need more help as now I have the problem to
>>>>
>>>> find
>>>> \textbf{text}\index{text}
>>>> and replace it with
>>>> \NewTerm{text}
>>>>
>>>> I tinkered a bit with the Find panel but there does not seem to be 
>>>> a wild card and I know nothing of regular expressions.
>>>>
>>>> Could someone
>>>> (a) give me the magic formula?
>>>> (b) direct me to an intro to regular expressions for dummies?
>>>
>>>
>>> Get a copy of TextWrangler and install it (it is no cost software). 
>>> TeXShop and iTeXMac also have regex available in their search 
>>> panels, but it may be a slightly different variant, and TextWrangler 
>>> uses the same syntax as BBEdit, and for that I'm sure how things 
>>> work. You may try TeXShop in 'pcre' mode, but be careful.
>>>
>>> Search for:
>>> \\textbf{(.+?)}\\index{.+?}
>>>
>>> Replace with:
>>> \\NewTerm{\01}
>>>
>>> The TextWrangler help contains an explanation of what you're doing 
>>> here, I suggest you read it.
>>
>>
>> /Peder
>>
>> --------------------- Info ---------------------
>> Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
>> & FAQ: http://latex.yauh.de/faq/
>> TeX FAQ: http://www.tex.ac.uk/faq
>> List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>
>>
>>
>>
> --------------------- Info ---------------------
> Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
>           & FAQ: http://latex.yauh.de/faq/
> TeX FAQ: http://www.tex.ac.uk/faq
> List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>
>
>
>
/Peder
+46-90-786.7719 (work)
+46-90-32344 (home)

--------------------- Info ---------------------
Mac-TeX Website: http://www.esm.psu.edu/mac-tex/
           & FAQ: http://latex.yauh.de/faq/
TeX FAQ: http://www.tex.ac.uk/faq
List Post: <mailto:MacOSX-TeX at email.esm.psu.edu>





More information about the MacOSX-TeX mailing list