12

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!

1

1 Answer 1

19

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.

1
  • 7
    It would make sense! Some formatting rules (e.g., font size) do apply to escaped latex code within listings. Splitting up into two inline listings with some normal text in between does not take that into account (I have a real-world example at hand currently :/)
    – stefanct
    Nov 8, 2015 at 1:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .