Hi Tedd,
Welcome to the board!
I am not aware of an automatic way for this. The only way I can think of is a not very convenient one: declare the digits to be letters (as far as »listings« is concerned) and declare all digits that should be formatted as keywords with an own keywordstyle:
Code: Select all
\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage{beramono}% monospaced font with bold variant
\usepackage{xcolor}
\colorlet{comment}{black!30}
\colorlet{digit}{orange}
\colorlet{string}{green!80!black}
\usepackage{listings}
\lstdefinelanguage{mylanguage}{
morecomment = [l]{//} ,
commentstyle = \color{comment} ,
morestring = [b]" ,
stringstyle = \color{string} ,
morekeywords = [0]{var,string} ,
keywordstyle = [0]\bfseries ,
sensitive = true
}
\lstdefinestyle{mystyle}{
language = mylanguage ,
basicstyle = \ttfamily ,
flexiblecolumns ,
alsoletter = {0,1,2,3,4,5,6,7,8,9} ,
morekeywords = [1]{1,2,3,40} ,
keywordstyle = [1]\itshape\color{digit}
}
\begin{document}
\begin{lstlisting}[style=mystyle]
variable = 40
variable2 = variable1
string = "string123"
// This is a comment, not format nothing here 123
var = 1..2
\end{lstlisting}
\end{document}

- dgits.png (10.92 KiB) Viewed 7026 times
Maybe minted has better possibilities?
Regards