I have the following code in a LaTeX file:
for \emph{service} in \emph{host}.resources:
for \emph{file} in \emph{host}.resources:
\underline{service}.requires.add(\underline{file})
for \emph{package} in \emph{host}.resources:
\underline{service}.requires.add(\underline{package})
Because this is inside a listing enviroment and I still want the emph and underline commands I escape the LaTeX commands, which results in something like this:
for %*\emph{file}*) in %*\emph{host}*).resources:
I tried to automate this process using the following sed command:
sed "s_\(\\emph{[a-z]*}\)_%\*\1\*)_"
But this results into the following output:
for \%*emph{dir}*) in \emph{host}.resources:
There are two problems with this:
- The '\' before emph is placed before the LaTeX escaping characters.
- sed only seems to replace the first match. I know about the greedy matching in sed, which is why I used [a-z]* instead of .* inside the curly braces. But this doesn't seem to work.
Any ideas on how to make sed do as I want?
\emph{anything}
with\%*emph{anything}*
?