3

I wanted to used syntax highlighting for a language unsupported by the listings package. Right now I have it almost working, but not completely. This is the MWE:

\documentclass{article}
\usepackage{listings,color}

% Define colors
\definecolor{codeBlue}{RGB}{0,0,255}
\definecolor{codeGreen}{RGB}{0,128,0}
\definecolor{codePurple}{RGB}{128,0,255}
\definecolor{codeOrange}{RGB}{255,128,128}
\definecolor{codePink}{RGB}{255,0,255}
\definecolor{codeGray}{rgb}{0.5,0.5,0.5}

% Define language style
\lstdefinestyle{apdl-modified}
    {       
        extendedchars=true,
        alsoletter={*},
        alsoletter={'},
        keywordstyle=\color{codeOrange},
        keywordstyle=[2]\color{codePurple},
        keywordstyle=[3]\color{codeBlue},
        keywordstyle=[4]\color{codePink},
        otherkeywords={
            /solve,
            /angle
        },
        keywords=[2]{
            *abbr,
            *dim
        },
        keywords=[3]{
            m,
            d
        },
        keywords=[4]{
            ',
            -,
            ",
            \%,
            (,
            ),
            ,,
            .,
            :,
            ;,
            ?,
            ^,
            ~,
            +,
            <,
            =,
            >
        },
        sensitive=false, % keywords are not case-sensitive
        morecomment=[l]{!}, % l is for line comment
        commentstyle=\color{codeGreen}, % style of comments
        numberstyle=\tiny\color{codeGray}
    }

% Define Language with previously defined style
\lstdefinelanguage{APDL}{style=apdl-modified}

\begin{document}
\begin{lstlisting}[language=APDL]
*dim,m,table,2,1, ,time
m(1,0,1) = 0.0001
m(1,1,1) = 0
m(2,0,1) = time
m(2,1,1) = time*speed

d,p51x, , %m% , , , ,ux,, , , ,

/solve
\end{lstlisting}
\end{document}

Which gives me: this result

The second and the fourth keywordstyle are not working, and I do not understand why. Anyone an idea?

1
  • You have to write alsoletter in a single definition _without_ using commas. If you use comma's, then they'll also be interpreted as "letters" (SO reference). This fixes the second keyword problem. So you should do alsoletter={*'}.
    – Breno
    Commented Aug 10, 2023 at 13:23

1 Answer 1

1

alsoletter={*} and alsoletter={'} must be in a single definition: alsoletter={*,'}

1
  • But does this influence the keywordstyle?
    – Benjamin
    Commented Sep 17, 2017 at 11:10

You must log in to answer this question.

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