Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

How to format all numbers in a code has been shown here. I have adapted it to include it in a language definition:

\documentclass[fleqn, a4paper]{article}
\usepackage{listings} 
\usepackage{color}

\lstdefinelanguage{mylang}{%
    basicstyle=\ttfamily,%
    literate={0}\textcolor{blue}{0}}{1}%
         {1}\textcolor{blue}{1}{1}%
         {2}\textcolor{blue}{2}{1}%
         {3}\textcolor{blue}{3}{1}%
         {4}\textcolor{blue}{4}{1}%
         {5}\textcolor{blue}{5}{1}%
         {6}\textcolor{blue}{6}{1}%
         {7}\textcolor{blue}{7}{1}%
         {8}\textcolor{blue}{8}{1}%
         {9}\textcolor{blue}{9}{1}%
         {.0}\textcolor{blue}{.0}{1}% Following is to ensure that only periods
         {.1}\textcolor{blue}{.1}{1}% followed by a digit are changed.
         {.2}\textcolor{blue}{.2}{1}%
         {.3}\textcolor{blue}{.3}{1}%
         {.4}\textcolor{blue}{.4}{1}%
         {.5}\textcolor{blue}{.5}{1}%
         {.6}\textcolor{blue}{.6}{1}%
         {.7}\textcolor{blue}{.7}{1}%
         {.8}\textcolor{blue}{.8}{1}%
         {.9}\textcolor{blue}{.9}{1}%
         {\ }{ }{1}% handle the space
         ,
    }
\begin{document}
\begin{lstlisting}[language=mylang]
    {
      _SetCalibTableName("lorem",100);
    }
\end{lstlisting}
\end{document}

The following error is produced:

! Argument of \lst@FillFixed@ has an extra }.

It looks as if it would not like my single { and }?

How to include it properly?

share|improve this question
    
Please complete your code snippet to a minimal working example (MWE). I tested the MWE in the linked question and it runs without any error message or warning ... –  Kurt Apr 18 '13 at 12:43

1 Answer 1

up vote 4 down vote accepted

Use an extra pair of braces in the second argument:

\documentclass[fleqn, a4paper]{article}
\usepackage{listings} 
\usepackage{color}

\lstdefinelanguage{mylang}{%
    basicstyle=\ttfamily,%
    literate={0}{{\textcolor{blue}{0}}}{1}%
         {1}{{\textcolor{blue}{1}}}{1}%
         {2}{{\textcolor{blue}{2}}}{1}%
         {3}{{\textcolor{blue}{3}}}{1}%
         {4}{{\textcolor{blue}{4}}}{1}%
         {5}{{\textcolor{blue}{5}}}{1}%
         {6}{{\textcolor{blue}{6}}}{1}%
         {7}{{\textcolor{blue}{7}}}{1}%
         {8}{{\textcolor{blue}{8}}}{1}%
         {9}{{\textcolor{blue}{9}}}{1}%
         {.0}{{\textcolor{blue}{.0}}}{1}% Following is to ensure that only periods
         {.1}{{\textcolor{blue}{.1}}}{1}% followed by a digit are changed.
         {.2}{{\textcolor{blue}{.2}}}{1}%
         {.3}{{\textcolor{blue}{.3}}}{1}%
         {.4}{{\textcolor{blue}{.4}}}{1}%
         {.5}{{\textcolor{blue}{.5}}}{1}%
         {.6}{{\textcolor{blue}{.6}}}{1}%
         {.7}{{\textcolor{blue}{.7}}}{1}%
         {.8}{{\textcolor{blue}{.8}}}{1}%
         {.9}{{\textcolor{blue}{.9}}}{1}%
         {\ }{{ }}{1}% handle the space
         ,%
    }
\begin{document}
\begin{lstlisting}[language=mylang]
    {
      _SetCalibTableName("lorem",100);
    }
\end{lstlisting}
\end{document}

enter image description here

share|improve this answer
    
Thank you Gonzalo, but it would still produce the same error. :-S. I have included a MWE in my original post. –  Jonas Apr 18 '13 at 13:22
    
@Jonas add the extra braces also in the final line (the one handling the space). –  Gonzalo Medina Apr 18 '13 at 13:38
    
@Jonas please see my updated answer. –  Gonzalo Medina Apr 18 '13 at 13:40
    
Sweet, it works, thank you! –  Jonas Apr 18 '13 at 15:53
    
A follow-up question has been posted here. –  Jonas Apr 18 '13 at 16:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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