With the package listing
I can use emph=
to emphasize specific identifiers in the whole listing.
\begin{lstlisting}[style=towi, title=Functions,emph={add}]
void print(int arg) { /* ... */ }
int add(int a, int b) { return a + b; }
...
print(12); // call function print
int sum = add(8, 4); // call function add
\end{lstlisting}
This will emphasize all instances of add
in the listing.
But I want to emphasize only one specific instance, and not only the identifier, but want to choose freely, which part to emphasize, say add(8, 4);
.
Best Answer
To achieve what you want, instead of adding
emph=
, define anescapechar
and use the formatting of youremphstyle
to emphasize that part of the line.For example, let's suppose that you have
Then, defining
you can write
to emphasize
add(8, 4);
and not the other occurrences ofadd
.MWE:
Output: