Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Listings "cannot load requested language" after newly-defined dialect

191 views
Skip to first unread message

Peter Flynn

unread,
May 2, 2015, 5:42:19 PM5/2/15
to
I have defined a new XSLT2 dialect of XML for the listings package which
includes some extra keywords beyond XSLT, but I can't get it to
recognise this: I get the error message

> ! Package Listings Error: Couldn't load requested language.
>
> See the Listings package documentation for explanation.
> Type H <return> for immediate help.
> ...
>
> l.10 \begin{lstlisting}[language=XSLT2]
>
> ! Package Listings Error: language xslt2 undefined.

(also weird is that it quotes xslt2 in lowercase, but that's probably a
different matter).

Here is the MWE (extra keywords cut):

---------------------------------8<----------------------------
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage[XSLT2]{XML}% copied from lstlang1.sty
{morekeywords={xsl:for-each-group},%
alsodigit={-},%
}%
\lstloadlanguages{[XSLT2]XML}
\begin{document}
This is a test
\begin{lstlisting}[language=XSLT2]
<xsl:for-each-group select="db:biblioentry">
...
</xsl:for-each-group>
\end{lstlisting}
\end{document}
---------------------------------8<----------------------------

What am I doing wrong?

I am aware that I can use [language={[XSLT2]XML}], but if I use the
existing XSLT language I don't have to do {[XSLT]XML}...how do I
implement it so that it works in the same way? I have tried using
\lstset{defaultdialect=[XSLT2]XML} but it has no effect.

///Peter

Jean-Côme Charpentier

unread,
May 3, 2015, 9:09:48 AM5/3/15
to
Le 02/05/2015 23:42, Peter Flynn a écrit :
> I have defined a new XSLT2 dialect of XML for the listings package which
> includes some extra keywords beyond XSLT, but I can't get it to
> recognise this: I get the error message
>
>> ! Package Listings Error: Couldn't load requested language.
>> [...]
>
> Here is the MWE (extra keywords cut):
>
> ---------------------------------8<----------------------------
> [...]
> \begin{lstlisting}[language=XSLT2]
> ---------------------------------8<----------------------------
>
> What am I doing wrong?
>
> I am aware that I can use [language={[XSLT2]XML}],

Not only you can: you *must* use [language={[XSLT2]XML}]. XSLT2 isn't
a language and the error message is clear enough about that.

> but if I use the
> existing XSLT language I don't have to do {[XSLT]XML}

Because XSLT is a language, not a dialect of XML (from listings point
of vue of course). In lstlang1.sty, XSLT is defined like that:
\lst@definelanguage{XSLT}[]{XML}
You define the XSLT2 like that:
\lstdefinelanguage[XSLT2]{XML}
That's not the same! There is a '[]' very important in XSLT definition :-)

>...how do I
> implement it so that it works in the same way? I have tried using
> \lstset{defaultdialect=[XSLT2]XML} but it has no effect.

You have to insert the empty optional argument in order to specify a
base language for your new language:

\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{XSLT2}[]{XML}%
{morekeywords={xsl:for-each-group},%
alsodigit={-},%
}%
\lstloadlanguages{XSLT2}
\begin{document}
This is a test
\begin{lstlisting}[language=XSLT2]
<xsl:for-each-group select="db:biblioentry">
...
</xsl:for-each-group>
\end{lstlisting}
\end{document}

Jean-Côme Charpentier

Peter Flynn

unread,
May 3, 2015, 10:52:39 AM5/3/15
to
On 05/03/2015 02:09 PM, Jean-Côme Charpentier wrote:
[...]
> You have to insert the empty optional argument in order to specify a
> base language for your new language:

My misreading of the documentation...I thought to specify a base
language that you *omitted* the []

Many thanks
///Peter


0 new messages