# Extend a standard command

What I want to do is the following: whenever my code says \begin{lstlisting} I want it to be \begin{lstlisting}[language=GLSL] instead.

What I tried was inserting \renewcommand{\begin{lstlisting}}{\begin{lstlisting}[language=GLSL]} into the preamble of my document. But it seems to cause an infinite loop when compiling.

My question is: How could I get what I want without replacing every \begin{lstlisting} in the whole document?

-

## migrated from stackoverflow.comFeb 13 '12 at 14:09

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

In this particular instance, the usual redefinition tricks will likely not help you. (lstlisting needs to know when to stop the verbatim reading, so it needs to know what its environment is called.) The following is taken from the manual:

4.16 Environments

If you want to define your own pretty-printing environments, try the following command. The syntax comes from LATEX’s \newenvironment.

\lstnewenvironment {name}[number][opt. default arg.] {starting code} {ending code}


As a simple example we could just select a particular language.

lstnewenvironment{pascal}
{\lstset{language=pascal}} {}


Doing other things is as easy, for example, using more keys and adding an optional argument to adjust settings each listing:

\lstnewenvironment{pascalx}[1][]
{\lstset{language=pascal,numbers=left,numberstyle=\tiny,float,#1}} {}


ETA: And also, if I remember correctly, just saying \lstset{language=GLSL} will affect all further listings.

-
The \lstset{language=GLSL} worked. Thanks a lot. –  hans Feb 13 '12 at 17:25