• Syntax for loading listings languages

    From Peter Flynn@21:1/5 to All on Wed Feb 28 00:58:44 2024
    Using the listings package. I am curious as to why the LaTeX language
    has to be loaded and used as [LaTeX]TeX, but a language or dialect I
    define myself can be both loaded and used by simple name alone.

    =================================================================== \documentclass{article}

    \usepackage{listings} \lstdefinelanguage{DocBook}[]{XML}{morekeywords={chapter,para}} \lstdefinelanguage{LaTeXe}[LaTeX]{TeX}{morekeywords={DeclareLanguageMapping}} \lstloadlanguages{DocBook,[LaTeX]TeX,LaTeXe}

    \begin{document}

    \begin{lstlisting}[language={[LaTeX]TeX}]
    \tableofcontents
    \end{lstlisting}

    \begin{lstlisting}[language=DocBook]
    <chapter><para>
    \end{lstlisting}

    \begin{lstlisting}[language=LaTeXe]
    \DeclareLanguageMapping
    \end{lstlisting}

    \end{document} ===================================================================

    Peter

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Holger Schieferdecker@21:1/5 to All on Wed Feb 28 12:45:57 2024
    Am 28.02.2024 um 01:58 schrieb Peter Flynn:
    Using the listings package. I am curious as to why the LaTeX language
    has to be loaded and used as [LaTeX]TeX, but a language or dialect I
    define myself can be both loaded and used by simple name alone.

    Maybe I don't get your point, but I want to share my thoughts on that
    issue. Let me add that I'm not an expert with listings.

    As far as I understand the manual there are single languages and
    languages with one or more dialects. In the former case you can load the language by using its name. For languages with dialects you need to
    specify which dialect you want to use. But it is possible to define a
    default dialect for a language. In that case you can load the language
    with that dialect by simply using the language name. According to the
    manual for TeX the default dialect is plain. So just loading TeX as
    language would invoke plain TeX.

    In your example below you define a new language called LaTeXe based on [LaTeX]{TeX}. Now LaTeXe is a language without dialects and can be
    loaded without specifying one.

    If I understand you correctly you would like to load [LaTeX]{TeX} by
    just specifying LaTeX. Which doesn't work.

    Now I tried something which presumably doesn't make sense, but it works.

    \lstdefinelanguage[Peter]{MyHTML}[]{HTML}{...} \lstdefinelanguage[Peter]{MyXML}[]{XML}{...}

    You can define several languages with the same dialect name. So
    specifying just the dialect is not distinct.

    %%%%%
    \documentclass{article}
    \usepackage{listings}
    \usepackage{xcolor} \lstdefinelanguage[Peter]{MyHTML}[]{HTML}{morekeywords={Peter}} \lstdefinelanguage[Peter]{MyXML}[]{XML}{morekeywords={Peter}}

    \begin{document}

    \begin{lstlisting}[language={[Peter]{MyHTML}}]
    Hallo Peter
    \end{lstlisting}

    \begin{lstlisting}[language={[Peter]{MyXML}}]
    Hallo Peter
    \end{lstlisting}

    \end{document}
    %%%%%

    I hope this helps a bit.

    Holger

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Peter Flynn@21:1/5 to Holger Schieferdecker on Wed Feb 28 16:31:11 2024
    On 28/02/2024 11:45, Holger Schieferdecker wrote:
    Am 28.02.2024 um 01:58 schrieb Peter Flynn:
    Using the listings package. I am curious as to why the LaTeX
    language has to be loaded and used as [LaTeX]TeX, but a language or
    dialect I define myself can be both loaded and used by simple name
    alone.

    Maybe I don't get your point,

    I explained it badly. I should have written "a language or dialect I
    define myself, either completely new or based on an existing dialect of
    an existing language".

    As far as I understand the manual there are single languages and
    languages with one or more dialects. In the former case you can load
    the language by using its name. For languages with dialects you need
    to specify which dialect you want to use. But it is possible to
    define a default dialect for a language. In that case you can load
    the language with that dialect by simply using the language name.

    As I understand it, you can invoke the default dialect by loading
    []{lang} (ie empty square brackets).

    According to the manual for TeX the default dialect is plain. So just
    loading TeX as language would invoke plain TeX.

    Right.

    In your example below you define a new language called LaTeXe based
    on [LaTeX]{TeX}. Now LaTeXe is a language without dialects and can be
    loaded without specifying one.

    OK. That's what I hoped. I need to define some extra commands not in the [LaTeX] dialect.

    If I understand you correctly you would like to load [LaTeX]{TeX} by
    just specifying LaTeX. Which doesn't work.

    No, I just wanted to make sure of the rules.

    Now I tried something which presumably doesn't make sense, but it
    works.
    \lstdefinelanguage[Peter]{MyHTML}[]{HTML}{...} \lstdefinelanguage[Peter]{MyXML}[]{XML}{...}
    You can define several languages with the same dialect name. So
    specifying just the dialect is not distinct.

    Right, because they are dialects of a different base language.

    I hope this helps a bit.

    Yes, thank you. In effect, for my purposes the *only* language to load
    that requires a dialect is [LaTeX]{TeX}, as far as I can see.

    Peter

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)