# To typeset LaTeX code using listings package: [AlLaTeX] dialect instead of [LaTeX] dialect for additional identifiers?

To typeset LaTeX code using the listings package, the typical advice is to specify the LaTeX dialect via the language = [LaTeX]{TeX} key-value pair in a \lstset command. (E.g., Joseph Wright's answer to "Typesetting LaTeX Source Code with the listings package.")

When I do so, some standard-LaTeX control sequences are properly highlighted, e.g., \def and \newcommand. However, others aren't, e.g., \AtBeginDocument and \RequirePackage. And no non–control sequence keywords, such as environment names (e.g, equation, document, or array) are highlighted. (See the upper half of the below output of the below MWE.)

If I change the dialect from LaTeX to AlLaTeX, all of the following are properly highlighted: \def, \newcommand, \AtBeginDocument, \RequirePackage, equation, document, array. (See the lower half of the below output of the below MWE.)

This behavior is consistent with the language definitions in the "Language 'drivers' details" document at "§2.79 TeX."

The LaTeX dialect is defined via \lst@definelanguage[LaTeX]{TeX}[common]{TeX} (line 6788 at page 158), where (a) the moretexcs key-value pair has many control sequences (such as \def and newcommand) but not others (such as \AtBeginDocument and \RequirePackage).

There is also a definition for a AlLaTeX dialect which is defined by \lst@definelanguage[AlLaTeX]{TeX}[LaTeX]{TeX} (line 6761 at page 158), which appears to me to mean that the AlLaTeX dialect is based on the definition of the LaTeX dialect. (See "§4.7 Language definitions" of the listings package documentation: "If the language definition is based on another definition, you must specify the whole [⟨base dialect⟩]{and base language⟩}.")

The moretexcs key-value pair for the AlLaTeX dialect has many control sequences that are missing from the definition of the LaTeX dialect. In addition, it has a morekeywords key-value pair that identifies many non–control sequence standard-LaTeX keywords such as array, center, displaymath, etc. that are also absent from the LaTeX dialect. (See line 6784.)

Two questions:

1: To what does the AlLaTeX dialect refer? I've never heard of such a LaTeX variant. Does this have a meaning outside the context of the listings package?

2: Is perhaps the AlLaTeX dialect simply a dialect defined to add previously missing control sequences and keywords to the LaTeX dialect? If so, why didn't they just add these to the LaTeX dialect? (Concerns about backward compatibility?)

3: If you want to typeset LaTeX code using the listings package, should one use the AlLaTeX dialect rather than the LaTeX dialect, in order to take advantage of the additional definitions? Is there any downside to this?

MWE:

\documentclass{article}
\usepackage{xcolor}
\usepackage{listings}
\parindent=0pt
\lstset{%
language=[LaTeX]Tex,%
sensitive=true,%
texcsstyle=*\color{green},%
keywordstyle=\color{blue},%
}
\begin{document}
With the \texttt{LaTeX} dialect:
\begin{itemize}
\item \lstinline|\def|
\item \lstinline|\newcommand|
\item \lstinline|\AtBeginDocument|
\item \lstinline|\RequirePackage|
\item \lstinline|equation|
\item \lstinline|document|
\item \lstinline|array|
\end{itemize}

With the \texttt{AlLaTeX} dialect:
\lstset{language=[AlLaTeX]Tex}
\begin{itemize}
\item \lstinline|\def|
\item \lstinline|\newcommand|
\item \lstinline|\AtBeginDocument|
\item \lstinline|\RequirePackage|
\item \lstinline|equation|
\item \lstinline|document|
\item \lstinline|array|
\end{itemize}
\end{document}


• The source code doesn't say what AlLaTeX means, so one only guess, perhaps "alternative latex". But it is not a special latex version, simply a different set of keywords. If you like it better use it. – Ulrike Fischer Mar 2 at 23:09