I'm using the listings package to document excerpts from my programs. I have been creating new environments for the various programming languages and wondering whether there was a way to hack the package so that it accepts a variable for the language definition in \lstset
.
For example,
\documentclass[11pt]{article}
\usepackage{listings}
\newcommand{\thelanguage}{Python}
\lstnewenvironment{\thelanguage}[1][]{
\lstset{
language = \thelanguage,
#1
}
}
{}
\begin{document}
\begin{Python}
This is a test.
\end{Python}
\end{document}
Using the above, latex throws the '!Improper alphabetic constant' error, which I presume is because the listings package is expecting a string rather than a variable. Is there a way round this? Should I be defining it as a macro and expanding it somehow? Still fairly new to latex, so any help would really help my understanding. Thanx.