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.

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
add comment

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

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

1 Answer

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.

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.

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

Your Answer

 
discard

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.