# define moretexcs (listings)

I want to define moretexcs lists outside of a lstdefinestyle macro because I want to load these definitions from a separate tex file. However inside lstset moretexcs is ignored:

\documentclass{article}

\usepackage{xcolor}
\usepackage{listings}

\lstdefinestyle{lstStyleLaTeX}{%
,language = [LaTeX]TeX%
% ,moretexcs={abc},
,keywordstyle=\color{red}
}
\lstset{%
language=[LaTeX]TeX,
moretexcs={abc},
}%

\begin{document}
\begin{lstlisting}[style=lstStyleLaTeX]
\abc{content}
\end{lstlisting}

\end{document}

-
According to the listings documentation (section 4.18 Language definitions, p 42), "If used ‘standalone’ outside a language deﬁnition, the key might work only after selecting a nonempty language (and switching back to the empty language if necessary)." So, perhaps you need language=[LaTeX]TeX as part of \lstset, and lanuage={} afterwards... –  Werner Nov 25 '12 at 18:38
With your changes it does not give an error, but it simply has no effect. –  Matthias Pospiech Nov 26 '12 at 21:55
Why not say \lstset{style=lstStyleLaTeX, moretexcs={abc}} and omit the [style=lstStyleLaTeX] argument later? –  cgnieder Dec 15 '12 at 13:51
I changes styles in my document quite often because I use not only LaTeX as a language. –  Matthias Pospiech Dec 16 '12 at 14:19

The following example defines macro \addmoretexcs. The optional argument specifies the dialect (default is common). The language is loaded if it is not yet available. Then the language definition, internally stored in \lstlang@<language>$<dialect>, is extended by setting the additional moretexcs list: \documentclass{article} \usepackage{xcolor} \usepackage{listings} \lstdefinestyle{lstStyleLaTeX}{% ,language = [LaTeX]TeX% % ,moretexcs={abc}, ,keywordstyle=\color{red} } \makeatletter \newcommand*{\addmoretexcs}[2][common]{% \lowercase{\@ifundefined{lstlang@tex$#1}}{%
}{}%
\lstset{moretexcs={#2}}%
}%
}
\makeatother