Am i able to do something like this: (without defining new environment)
\newcommand{\code}[2] {
\begin{lstlisting}[language=#1]
#2
\end{lstlisting}
}
I don't want to write:
\begin{code}{python}
>>> print "Hello World!"
\end{code}
I want to be able to write:
\code{python}{>>> print "Hello World!"}
listingsprovides\lstinline. – egreg Jul 29 '14 at 19:45\lstinlinewithout reading the argument:\newcommand*\code[1]{\lstinline[language=#1]}. As @egreg says this only works for short inline code – cgnieder Jul 29 '14 at 19:58lstlistingis like a verbatim environment; it's fragile and can't really be included in the arguments of other commands. This post might help: http://tex.stackexchange.com/questions/59715/package-listings-warning-text-dropped-after-begin-of-listing-when-calling-funct It contains some more egreg wisdom, too. As an aside, try searching the archive before asking a question; you're probably not the first to run into a given problem. – dgoodmaniii Jul 29 '14 at 19:59