GeneralProblems with newcommand and newenviornment

LaTeX specific issues not fitting into one of the other forums of this category.
Post Reply
minofifa
Posts: 2
Joined: Thu Aug 13, 2009 1:43 am

Problems with newcommand and newenviornment

Post by minofifa »

Hi everyone

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

Recommended reading 2024:

LaTeXguide.org • LaTeX-Cookbook.net • TikZ.org

NEW: TikZ book now 40% off at Amazon.com for a short time.

gmedina
Posts: 2313
Joined: Wed Jul 11, 2007 11:45 pm

Problems with newcommand and newenviornment

Post by gmedina »

Hi,

try the \lstnewenvironment command, described in the section Environments of the package documentation (pp 40ff)
1,1,2,3,5,8,13,21,34,55,89,144,233,...
minofifa
Posts: 2
Joined: Thu Aug 13, 2009 1:43 am

Re: Problems with newcommand and newenviornment

Post by minofifa »

awesome, this worked great. thank you
Post Reply