How can I get the language currently set for the listings (aka lstlistings) package, e.g. via \lstset{language=Python,basicstyle=\color{blue},backgroundcolor=\color{lightgray}}?


I want to use the value in my own command that also puts some lstinline text into the index, under the right language.

I tried variables like \language, \lst.language, ... But they do not contain the value.

Hence I introduced a new variable via e.g. \newcommand{\lstLanguage}{Python} in each chapter, and used \lstset{language=\lstLanguage,basicstyle=\color{blue},backgroundcolor=\color{lightgray}} instead. But that causes the error

​ ! Package Listings Error: language Python undefined


It is stored in \lst@language. The following minimal example shows how to get the currently set listings language from LaTeX and yields tex python:










Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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