5

I am using the listings package for Smalltalk programming language but since it does not come out of the box, I am trying to do it by hand. Now I have a problem with numbers. No matter if I change:

    numbersep=5pt,
numberstyle=\small\color{blue},

it is not taken into account, that is, they do not change. I know I can do:

\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

}

However, that affects ALL numbers, even if they are inside strings or comments. I only want to applyt the style to numbers when they are NOT in strings or comments or whatever..just when they are "alone"

For the record, here is all my settings:

  \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

Any ideas? thanks a lot in advance,

3

I found the solution in How can I change the color of digits when using the listings package?

putting a star at the beginning:

    \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

}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.