## LaTeX forum ⇒ Text Formatting ⇒ listings | Format only Digits Topic is solved

Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
Tedd
Posts: 6
Joined: Wed Dec 19, 2012 3:33 am

### listings | Format only Digits

Hello guys.

With the listings package I want only digits in orange. No strings or comments. I've looked at many topics about it on the internet but are not very satisfactory. I'll explain below:

variable = 40  % Format "40" variable2 = variable1  % There is nothing formats // This is a comment, not format nothing here 123  % There is nothing formats var = 1..2 % Only "1" and "2"

Note: This is for RGSS, of RPG Maker.

Is this really possible? Thank you for your attention.

cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
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:

\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 1568 times

Maybe minted has better possibilities?

Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

Tedd
Posts: 6
Joined: Wed Dec 19, 2012 3:33 am
Oh, really thanks cgnieder!

So you think the minted package is best for this case?

I'm new in LaTeX, I am studying just a month ago. I started with listings beacause i found more material, but i will find out about this package. As would be done in minted this example? Could you exemplify?

Thankful. Tedd.

cgnieder
Site Moderator
Posts: 1948
Joined: Sat Apr 16, 2011 7:27 pm
Location: Germany
Contact:
Tedd wrote:So you think the minted package is best for this case?

Actually I don't know. I fairly familiar with »listings« but I have never used »minted« before. I just heard that it is quite powerful, too. So I think you should at least take a look.

Regards
Clemens
------------------------------
New German Q&A site about TeX: http://texwelt.de/wissen

Tedd
Posts: 6
Joined: Wed Dec 19, 2012 3:33 am
Oh, really, i started studying it now! It seems to be very good, thank you cgnieder!