tags:

views:

61

answers:

4

I am using TeXnicCenter to edit a LaTeX document.

I now want to remove a certain tag (say, emph{blabla}} which occurs multiple times in my document , but not tag's content (so in this example, I want to remove all emphasization). What is the easiest way to do so?

May also be using another program easily available on Windows 7.

Edit: In response to regex suggestions, it is important that it can deal with nested tags.

Edit 2: I really want to remove the tag from the text file, not just disable it.

A: 

any reasonably advanced editor should let you do a search/replace using regular expressions, replacing emph{bla} by bla etc.

second
Wouldn't be better to say: "replace `\emph{` with `{`"?
Crowley
+2  A: 

Using a regular expression do something like s/\\emph\{([^\}]*)\}/\1/g. If you are not familiar with regular expressions this says:

s -- replace
/ -- begin match section
\\emph\{ -- match \emph{
( -- begin capture
[^\}]* -- match any characters except (meaning up until) a close brace because:
  [] a group of characters
  ^ means not or "everything except"
  \} -- the close brace
  and * means 0 or more times
) -- end capture, because this is the first (in this case only) capture, it is number 1
\} -- match end brace
/ -- begin replace section
\1 -- replace with captured section number 1
/ -- end regular expression, begin extra flags
g -- global flag, meaning do this every time the match is found not just the first time

This is with Perl syntax, as that is what I am familiar with. The following perl "one-liners" will accomplish two tasks

perl -pe 's/\\emph\{([^\}]*)\}/\1/g' filename will "test" printing the file to the command line

perl -pi -e 's/\\emph\{([^\}]*)\}/\1/g' filename will change the file in place.

Similar commands may be available in your editor, but if not this will (should) work.

Joel
+1, very nice documentation.
Heinzi
Thanks, if one is going to answer one may as well do it with gusto
Joel
Will it function correctly if there is another tag inside the tag to remove (i.e, meaning there will be a closing brace before encoutering the correct closing brace)?
Rabarberski
@Raberberski: No. Matching parenthesis with regexps is known to be quite a hard problem.
Heinzi
As Heinzi said, it is more difficult in that case. Here is a link with some discussion http://www.perlmonks.org/?node_id=660316 . They are considering angle brackets but replacing with curly should be no problem. They recursively parse out each nested text.
Joel
Perhaps something better for you is the Perl module (as suggested in that link) is the Text::Balanced module http://search.cpan.org/~adamk/Text-Balanced-2.02/lib/Text/Balanced.pm .
Joel