2

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?

4

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

  • 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
  • A follow-up question has been posted here. – Jonas Apr 18 '13 at 16:02

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.