Add tags
Information and discussion about LaTeX's general text formatting features (e.g. bold, italic, enumerations, ...)
by Tedd on Wed Dec 19th, 2012
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: - Code: Select all • Open in writeLaTeX
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.
-
Tedd
-
- Posts: 6
- Joined: Wed Dec 19th, 2012
by cgnieder on Thu Dec 20th, 2012
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 • Open in writeLaTeX
\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 431 times
Maybe minted has better possibilities? Regards
-

cgnieder
- Site Moderator
-
- Posts: 1314
- Joined: Sat Apr 16th, 2011
- Location: Germany
-
by Tedd on Thu Dec 20th, 2012
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.
-
Tedd
-
- Posts: 6
- Joined: Wed Dec 19th, 2012
by cgnieder on Thu Dec 20th, 2012
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
-

cgnieder
- Site Moderator
-
- Posts: 1314
- Joined: Sat Apr 16th, 2011
- Location: Germany
-
by Tedd on Thu Dec 20th, 2012
Oh, really, i started studying it now! It seems to be very good, thank you cgnieder!
-
Tedd
-
- Posts: 6
- Joined: Wed Dec 19th, 2012
Return to Text Formatting
Users browsing this forum: No registered users and 11 guests
|