From reading the code of the listings
package, it is apparently deliberate but undocumented behaviour that escapes cannot be used in lstinline
, with the exception of mathescape
. Presumably escapes are considered an 'unsafe feature' in TextStyle
contexts (of which lstinline
is one), but it is not clear why or when it might be unsafe.
It is possible to re-enable the feature, as done below, but beware in case it causes any problems:
\documentclass{article}
\usepackage{listings}% http://ctan.org/pkg/listings
% http://tex.stackexchange.com/q/43526
% fix the apparently deliberate but undocumented behaviour of disabling escapes other than mathescape in TextStyle (used by \lstinline)
% there may be a good reason why this is disabled by default, so beware in case it causes any problems
\usepackage{etoolbox}
\makeatletter
\patchcmd{\lsthk@TextStyle}{\let\lst@DefEsc\@empty}{}{}{\errmessage{failed to patch}}
\makeatother
% for the example:
\usepackage{textcomp}% for \textlangle, \textrangle
\begin{document}
Experimental brace syntax: \lstinline[escapechar=§]{§\textlangle§foo§\textrangle§}
Standard delimiter syntax: \lstinline[escapechar=§]!§\textlangle§foo§\textrangle§!
\end{document}