如果我这样做:
\lstdefinelanguage{VHDL}{
morekeywords={
library,use,all,entity,IN,is,port,in,out,end,architecture,of,
begin,and,END,THEN,ELSEIF,WHEN,IF,ELSE,EVENT,IS
},
morecomment=[l]--
}
\usepackage{xcolor}
\colorlet{keyword}{blue!100!black!80}
\colorlet{comment}{green!40!black!90}
\lstdefinestyle{vhdl}{
language = VHDL,
basicstyle = \ttfamily,
keywordstyle = \color{keyword}\bfseries,
commentstyle = \color{comment}
}
\begin{document}
\begin{lstlisting}[style=vhdl]
-- (this is a VHDL comment)
THEN
1
\end{lstlisting}
\end{document}
都好。
但我需要其他颜色。如果我这样做,我会遇到一个问题:
\lstdefinelanguage{VHDL}{
morekeywords={
library,use,all,entity,IN,is,port,in,out,end,architecture,of,
begin,and,END,THEN,ELSEIF,WHEN,IF,ELSE,EVENT,IS
},
morekeyword2s={
1
},
morecomment=[l]--
}
\usepackage{xcolor}
\colorlet{keyword}{blue!100!black!80}
\colorlet{keyword2}{red!100!black!80}
\colorlet{comment}{green!40!black!90}
\lstdefinestyle{vhdl}{
language = VHDL,
basicstyle = \ttfamily,
keywordstyle = \color{keyword}\bfseries,
commentstyle = \color{comment}
}
\begin{document}
\begin{lstlisting}[style=vhdl]
-- (this is a VHDL comment)
THEN
1
\end{lstlisting}
\end{document}
你能帮助我吗?谢谢。
答案1
你的第二个语法morekeywords
是错误的,你还必须定义第二个关键字样式。
\documentclass{article}
\usepackage{listings}
\lstdefinelanguage{VHDL}{
morekeywords={%
library,use,all,entity,IN,is,port,in,out,end,architecture,
of,begin,and,END,THEN,ELSEIF,WHEN,IF,ELSE,EVENT,IS
},
morekeywords=[2]{%
RED
},
morecomment=[l]--
}
\usepackage{xcolor}
\colorlet{keyword}{blue!100!black!80}
\colorlet{keyword2}{red!100!black!80}
\colorlet{comment}{green!40!black!90}
\lstdefinestyle{vhdl}{
language = VHDL,
basicstyle = \ttfamily,
keywordstyle = \color{keyword}\bfseries,
keywordstyle = [2]\color{keyword2},
commentstyle = \color{comment}
}
\begin{document}
\begin{lstlisting}[style=vhdl]
-- (this is a VHDL comment)
THEN
RED
\end{lstlisting}
\end{document}