# Lstinline macro inside another environment

Why does the MWE below compile with errors only if I use ths \lstnewenvironment line? And how to define the verbatim macro inside an environment? I heard it's possible using plain TeX?

\documentclass{article}
\makeatletter
\IfFileExists{randompackageyoudonthave.sty}{
}{
\usepackage{listings}
\lstnewenvironment{Rcode}{\renewcommand\lstlistingname{Rcode}}% deleting this line makes this work
\newcommand{\code}[1]{\lstinline{##1}}
}
\makeatother
\begin{document}
\code{yeah! some code}
\end{document}


You were missing the end part of the environment; the syntax (without arguments) is

\lstnewenvironment{<name>}{<begin-env>}{<end-env>}


\documentclass{article}

\IfFileExists{randompackageyoudonthave.sty}{
}{
\usepackage{listings}
\lstnewenvironment{Rcode}{\renewcommand\lstlistingname{Rcode}}{}
\newcommand{\code}{\lstinline}
}

\begin{document}
\code{yeah! some code}

\code+yeah! some code+
\begin{Rcode}
yeah! some code
\end{Rcode}
\end{document}


Also, as egreg mentioned in his comment, it should be

\newcommand{\code}{\lstinline}


or

\newcommand{\code}{\lstinline[<options>]}


if some [<options>] should be used. This allows for the use of alternative delimiters, as in \code+text+ (see the example code above).

• Also there should be \newcommand{\code}{\lstinline[<options>]} without argument. May 21, 2014 at 19:22
• @egreg I've introduced your suggestion. Thanks. May 21, 2014 at 19:25
• In this way also the alternative syntax \code!<code>! (! any character like for \verb) is allowed, but it's not the only reason. May 21, 2014 at 19:28