4

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}}?


Details:

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

1 Answer 1

4
+50

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:

\documentclass{article}

\usepackage{listings}

\makeatletter
\newcommand{\getlang}{\lst@language}
\makeatother

\begin{document}

\lstset{language=tex}



\getlang

\lstset{language=Python,basicstyle=\color{blue},backgroundcolor=\color{lightgray}}


\getlang


\end{document}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .