Replacing "x" with "x \index{x}" for multiple x Problem

General discussions about Advanced Find and Replace
Post Reply
Posts: 1
Joined: Tue Jan 05, 2010 5:41 pm

Replacing "x" with "x \index{x}" for multiple x Problem

Post by rendsvig » Tue Jan 05, 2010 6:07 pm


I'm setting up books in .tex, and doint that I often have to generate indexes, meaning that for some string of letters, "x", I have to replace them with "x\index{x}". Here "x" is a word, and of course I need to replace words starting with capitol letters with words starting with capitol letters, and that is no problem -- unfortunately, the words may also be followed by a space, a full stop, a comma etc., and this is where my problems begin. To give an example, say x is the word "test" in the text


and I would like to replace "test" with "test\index{test}" and "Test" with "Test\index{test}", but if I add these as entries in the batch replace option, I get


which is no wonder, but not what I wanted.

I can fix this by taking my strings to be "Test " and "test " (that is, I add a space to the end of the string), but then I wont get "test" replaced in "So the program passed the test." Hence, I'll have to add for every word I wish to change both version with capitol letters, but also versions for every possible sign after, i.e., comma, full stop, space etc.

Is there any way to get around this?

Post Reply