General ⇒ Problems with newcommand and newenviornment
Problems with newcommand and newenviornment
I would like to save myself some typing by creating a macro for typesetting sourcecode examples. I would like to do something like this:
\newcommand{\pythonCode}[1] {\begin{lstlisting}[backgroundcolor=\color{pythonColor}]}#1\end{lstlisting}}
or this:
\newenvironment{pythonCode}[0]
{\begin{lstlisting}[backgroundcolor=\color{pythonColor}]}
{\end{pythonCode}
However, both of these approaches produce errors. Can somebody provide assistance on how solve such a problem? thank you
Learn LaTeX easily with newest books:
The LaTeX Beginner's Guide: 2nd edition and perfect for students writing a thesis
The LaTeX Cookbook: 2nd edition full of practical examples for mathematics, physics, chemistry, and more
LaTeX Graphics with TikZ: the first book about TikZ for perfect drawings in your LaTeX thesis
Problems with newcommand and newenviornment
try the \lstnewenvironment command, described in the section Environments of the package documentation (pp 40ff)