我正在使用 Smalltalk 编程语言的 listings 包,但由于它不是现成的,所以我尝试手动完成。现在我遇到了数字问题。无论我是否更改:
numbersep=5pt,
numberstyle=\small\color{blue},
它没有被考虑在内,也就是说,它们没有改变。我知道我可以这样做:
\lstset{literate=%
{0}{{{\myNumberStyle{0}}}}1
{1}{{{\myNumberStyle{1}}}}1
{2}{{{\myNumberStyle{2}}}}1
{3}{{{\myNumberStyle{3}}}}1
{4}{{{\myNumberStyle{4}}}}1
{5}{{{\myNumberStyle{5}}}}1
{6}{{{\myNumberStyle{6}}}}1
{7}{{{\myNumberStyle{7}}}}1
{8}{{{\myNumberStyle{8}}}}1
{9}{{{\myNumberStyle{9}}}}1
}
但是,这会影响所有数字,即使它们在字符串或注释中。我只想在数字不在字符串或注释中时才应用样式……只在它们“单独”时才应用样式
为了记录,以下是我所有的设置:
\lstset{
language={},
% characters
tabsize=3,
escapechar={!},
keepspaces=true,
breaklines=true,
alsoletter={\#},
breakautoindent=true,
columns=fullflexible,
showstringspaces=false,
% background
frame=single,
aboveskip=1em, % automatic space before
framerule=0pt,
basicstyle=\small\ttfamily,
keywordstyle=\myKeywordStyle,% keyword style
commentstyle=\myCommentStyle,% comment style
frame=single,%
backgroundcolor=\color{source},
% numbering
numbersep=5pt,
numberstyle=\small\color{blue},
numberfirstline=true,
% caption
captionpos=b,
% formatting (html)
moredelim=[is][\textbf]{<b>}{</b>},
moredelim=[is][\textit]{<i>}{</i>},
moredelim=[is][\uline]{<u>}{</u>},
moredelim=[is][\color{red}\uwave]{<wave>}{</wave>},
moredelim=[is][\color{red}\sout]{<del>}{</del>},
moredelim=[is][\color{blue}\uline]{<ins>}{</ins>},
% smalltalk stuff
morecomment=[s][\myCommentStyle]{"}{"},%
morecomment=[s][\myvs]{|}{|},
morestring=[b][\myStringStyle]',
moredelim=[is][]{<sel>}{</sel>},
moredelim=[is][]{<rcv>}{</rcv>},
moredelim=[is][\itshape]{<symb>}{</symb>},
moredelim=[is][\scshape]{<class>}{</class>},
morekeywords={true,false,nil,self,super,thisContext},
identifierstyle=\idstyle,
}
\makeatletter
\newcommand*\idstyle[1]{%
\expandafter\id@style\the\lst@token{#1}\relax%
}
\def\id@style#1#2\relax{%
\ifnum\pdfstrcmp{#1}{\#}=0%
% this is a symbol
\mySymbolStyle{\the\lst@token}%
\else%
\edef\tempa{\uccode`#1}%
\edef\tempb{`#1}%
\ifnum\tempa=\tempb%
% this is a global
\myGlobalStyle{\the\lst@token}%
\else%
\the\lst@token%
\fi%
\fi%
}
\makeatother
有什么想法吗?提前谢谢您,
答案1
我找到了解决方案使用列表包时如何更改数字的颜色?
在开头加一个星号:
\lstset{literate=%
*{0}{{{\myNumberStyle{0}}}}1
{1}{{{\myNumberStyle{1}}}}1
{2}{{{\myNumberStyle{2}}}}1
{3}{{{\myNumberStyle{3}}}}1
{4}{{{\myNumberStyle{4}}}}1
{5}{{{\myNumberStyle{5}}}}1
{6}{{{\myNumberStyle{6}}}}1
{7}{{{\myNumberStyle{7}}}}1
{8}{{{\myNumberStyle{8}}}}1
{9}{{{\myNumberStyle{9}}}}1
}