# Combine listings package with my own enviroment [duplicate]

Possible Duplicate:
How to use different lstset settings for listings?

I have defined my own enviroment as:

\newenvironment{codegui}[3]{%
\def\tmplanguage{#1}\relax
\def\tmpshowspaces{#2}\relax
\def\tmpshowtabs{#3}\relax
\lstset{language={\tmplanguage},%
showspaces={\tmpshowspaces},
showtabs={\tmpshowtabs}, tab=\rightarrowfill,
stepnumber=1,
numbersep=5pt,
keywordstyle=\bfseries,
stringstyle=\ttfamily,
numbers=left,
numberstyle=\tiny
}
\relax
\begin{lstlisting}
}{%
\end{lstlisting}
}


and when I run it in document such as:

\begin{codegui}{C}{true}{true}
#include <stdio.h>
int main(){
printf("hello world");
return 0;
}
\end{codegui}


I have erros:

! Package Listings Error: language C undefined.
! Emergency stop.


• parameter #1 is C or Matlab,
• parameter #2 is true or false,
• parameter #3 is same as #2
-

## migrated from stackoverflow.comFeb 13 '12 at 16:22

This question came from our site for professional and enthusiast programmers.

## marked as duplicate by Werner, Marco Daniel, lockstep, Joseph Wright♦Feb 14 '12 at 8:25

Welcome to TeX.sx! Your question was migrated here from Stack Overflow. Please register on this site, too, and make sure that both accounts are associated with each other, otherwise you won't be able to comment on or accept answers or edit your question. –  Werner Feb 13 '12 at 16:27
You might be interested in the matlab-prettifier package; see this answer. –  Jubobs Apr 28 '14 at 17:12

\lstnewenvironment{codegui}[3]{%
\lstset{language={#1},%
showspaces={#2},
showtabs={#3}, tab=\rightarrowfill,
stepnumber=1,
numbersep=5pt,
keywordstyle=\bfseries,
stringstyle=\ttfamily,
numbers=left,
numberstyle=\tiny
}\relax
}{%
}


I use \lstnewenvironment for the definition, and it works well.

-