TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

migrated from stackoverflow.com Feb 13 '12 at 14:09

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

up vote 4 down vote accepted

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.

{\lstset{language=pascal}} {} 

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

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

share|improve this answer
The \lstset{language=GLSL} worked. Thanks a lot. – hans Feb 13 '12 at 17:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.