使用多个关键字组定义列表语言

使用多个关键字组定义列表语言

我想使用语法高亮来显示 listings 包不支持的语言。目前,它几乎可以正常工作,但还不够完美。这是 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}

这给了我:这个结果

第二和第四个关键字样式不起作用,我不明白为什么。有人知道吗?

答案1

alsoletter={*}并且alsoletter={'}必须只有一个定义:alsoletter={*,'}

相关内容