[Tex/LaTex] listings ‘escapeinside’-option is not working for me

listings

this is my first question here. I'm not exaclty new to LaTeX, but to be honest I've never really gotten too much into it.

So here's my problem:

I have this minimal example:

\documentclass{scrreprt}

% Quellcode
\usepackage{listings} % für Formatierung in Quelltexten
\lstset{
    escapeinside={(*@}{@*)},          % if you want to add LaTeX within your code
}

\begin{document}

\chapter{some chapter}

\section{some section}
some text \lstinline|some code (*@ \textbf{TRYING TO ESCAPE HERE} @*) some more code|

\end{document}

What I get in my pdf-file is this:

enter image description here

I guess you can see I'm trying to escape the \lstinline command to insert a basic LaTeX one but it's not working for me. I'm referring to the escapeinside-option from the listings-manual section 4.14.

I hope I've stuck to all the standards with my post.
Please let me know if any further information about package versions and what not is required.
Any help will be very much appreciated!

Best Answer

Although not explicitly stated in the documentation I have found that the escaping only works in listings using the lstlisting environment, not within lstinline. See this:

\documentclass{scrreprt}

% Quellcode
\usepackage{listings} % für Formatierung in Quelltexten
\lstset{
    escapeinside={(*@}{@*)},          % if you want to add LaTeX within your code
}

\begin{document}

\chapter{some chapter}

\section{some section}
some text \lstinline|some code (*@ \textbf{TRYING TO ESCAPE HERE} @*) some more code|

A new paragraph and a listing:
\begin{lstlisting}
some code (*@ \textbf{TRYING TO ESCAPE HERE} @*) some more code
\end{lstlisting}
\end{document}

output

And actually thinking about it, within a lstinline escaping seems to make little sense - you could just use \lstinline|some code| \textbf{TRYING TO ESCAPE HERE} \lstinline|some more code| in your example.

Related Question