Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

I try to find out but I can't. Please help me!

Addendum:

  • parameter #1 is C or Matlab,
  • parameter #2 is true or false,
  • parameter #3 is same as #2
share|improve this question

migrated from stackoverflow.com Feb 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

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
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 at 17:12
add comment

1 Answer

\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.

share|improve this answer
add comment