Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

What I want to do is having two or more possibilities when escaping from normal code formatting. For instance, if I give the option escapechar=\⠶ I would like to avoid saying something like this:

\begin{lstlistings}[language=C,escapechar=\⠶]
double a;
int i; ⠶\color{red}$\longleftarrow$ this is counter $i$⠶
\end{lstlistings}

I just want to escape with the given (unusual) character being sure that the color command is automatically given. In other words, the escaped text in the following code:

\begin{lstlistings}[language=C,escapechar=\⠶]
double a;
int i; ⠶$\longleftarrow$ this is counter $i$⠶
\end{lstlistings}

should be in red.

Similarly, instead of this:

\begin{lstlistings}[language=C,escapechar=\£]
double a; £\color{green}$\longleftarrow$ this is the variable $a$£
int i;
\end{lstlistings}

I want to escape with the character £ being sure that a green text is typeset.

share|improve this question
    
Please consider accepting your own answer, so that your question be removed from the "unanswered" pile. –  Jubobs Mar 10 at 12:27

1 Answer 1

up vote 2 down vote accepted

The answer is given by the options escapebegin and escapeend:

\begin{lstlistings}[language=C,escapechar=\⠶,escapebegin=\color{red},escapeend={}]
double a;
int i; ⠶$\longleftarrow$ this is counter $i$⠶
\end{lstlistings}

give a red comment.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.