I use the listings package to render code in LaTeX documents. I am trying to define a new command or a new environment that uses \lstinline inside. I have read numerous questions about this on StackExchange, but have not found a solution to my problem.
I want a macro \code such that this code:
\code{a $\leq$ b}
expands to this:
\begin{definition}
\lstinline[mathescape=true]{a $\leq$ b}
\end{definition}
The NewDocumentCommand from the xparse package seemed promising but this doesn't compile.
\NewDocumentCommand\code{v}{\lstinline[mathescape=true]{#1}}
\code{a $\leq$ b}
The error:
ERROR: Undefined control sequence.
--- TeX said ---
\lst@arg ->a $\
leq$ b
l.6 \code{a $\leq$ b}
So, my question is: is it possible to warn LaTeX that the argument of \code should not be expanded until it is passed to \lstinline?
Thank you,
Pierre

\newcommand\code{\lstinline[mathescape=true]}so that the argument was not scanned before listinline starts. – David Carlisle Mar 09 '16 at 14:01