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.

Isodat language is used for Mass-spectrometers from ThermoFisher Scientific®, which is used for Stable Isotope Mass-spectrometry.

Parts of the language's syntax highlighting has been explored in listings package: formating all numbers in language definition? and the follow-up question listing package: colored numbers, but not colored in variable names.

In the end it should look like the image below:

Example of Isodat source code.

I get the following:

.png of .pdf from .tex.

Do you know what needs to be changed here? The problems are:
1. numbers within comment,
2. numbers within string,

So far the following have been fixed:
3. keywords in blue (if, else, string, number),
4. parenthesis following keywords in black,
5. block comments,
6. keywords in lightblue.
7. strings in blue

\documentclass[fleqn, a4paper, landscape]{article}
\usepackage{xcolor}

\definecolor{isored}{rgb}{0.6,0,0} % for strings
\definecolor{isogreen}{rgb}{0.25,0.6,0.2} % comments
\definecolor{isoblue}{rgb}{0.0,0.0,1} % keyword
\definecolor{isolightblue}{rgb}{0.5,0.5,1.0} % keywords
\definecolor{isocomgreen}{rgb}{0.25,0.35,0.75} % javadoc

\usepackage{etoolbox}

\newtoggle{InString}{}% Keep track of if we are within a string
\togglefalse{InString}% Assume not initally in string
% http://tex.stackexchange.com/questions/34896/coloring-digits-with-the-listings-package?rq=1
\newcommand*{\ColorIfNotInString}[1]{\iftoggle{InString}{#1}{\textcolor{isored}#1}}%
\newcommand*{\ProcessQuote}[1]{#1\iftoggle{InString}{\global\togglefalse{InString}}{\global\toggletrue{InString}}}%

\usepackage{listings} 

\lstdefinelanguage{isodat}
{%
  basicstyle=\ttfamily,%
  literate=%
     %{"}{{{\ProcessQuote{"}}}}1% Disable coloring within double quotes
     {0}{{\ColorIfNotInString{0}}}{1}%
     {1}{{\ColorIfNotInString{1}}}{1}%
     {2}{{\ColorIfNotInString{2}}}{1}%
     {3}{{\ColorIfNotInString{3}}}{1}%
     {4}{{\ColorIfNotInString{4}}}{1}%
     {5}{{\ColorIfNotInString{5}}}{1}%
     {6}{{\ColorIfNotInString{6}}}{1}%
     {7}{{\ColorIfNotInString{7}}}{1}%
     {8}{{\ColorIfNotInString{8}}}{1}%
     {9}{{\ColorIfNotInString{9}}}{1}%
     {.0}{{\ColorIfNotInString{.0}}}{1}% Following is to ensure that only periods
     {.1}{{\ColorIfNotInString{.1}}}{1}% followed by a digit are changed.
     {.2}{{\ColorIfNotInString{.2}}}{1}%
     {.3}{{\ColorIfNotInString{.3}}}{1}%
     {.4}{{\ColorIfNotInString{.4}}}{1}%
     {.5}{{\ColorIfNotInString{.5}}}{1}%
     {.6}{{\ColorIfNotInString{.6}}}{1}%
     {.7}{{\ColorIfNotInString{.7}}}{1}%
     {.8}{{\ColorIfNotInString{.8}}}{1}%
     {.9}{{\ColorIfNotInString{.9}}}{1}%
     {\ }{{ }}{1}% handle the space
     ,
     %string=[s]{_}{=},
     %string=[s]{_}{(}, 
  mathescape=true, 
  emphstyle={[2]\color{isoblue}},
  tabsize=4,
  captionpos=b,
  showstringspaces=false,
  keywordstyle=\color{isoblue},
  keywordstyle=[2]\color{isoblue},
  commentstyle=\color{isogreen},%
  stringstyle=\color{isolightblue},%
  morestring=[s][\color{isoblue}]{"}{"},%
  morecomment = [l]{//},
  morecomment = [l]{///},
  morecomment = [s]{/*}{*/},
  sensitive = true,
  morekeywords = {if, else, string, number},%You need to add here
  emph={_Set, _Delay, _strstr, _strtod, _strmid},% You need to add here
  emphstyle=\color{isolightblue},
}

\begin{document}
    \begin{lstlisting}[caption=Isodat language sample..,language=isodat]

        _Set("Precon/Trap 3",0);
        _Delay(1000,1,"Evacuating Carbon trap")
        //_Set("ExtValveBlock/Valve 4",1); commented because interferes with extraction

        string SeqPrepText="";
        number AnzFull=1;

        SeqPrepText =_GetSequenceText("Preparation","1,0");
        //_MessageBox(SeqPrepText,MB_OK,MB_ICONEXCLAMATION);        

        Midpoint    = _strstr (SeqPrepText,",");
        if (Midpoint==-1) 
        {
        /* Format stimmt nicht falsches oder kein Trennzeichen
           no error haldling so far
           cut to 1 and zero by default */
        }
        else
        {
          AnzHalf = _strtod(_strmid(SeqPrepText,(Midpoint+1),(StrLaenge-Midpoint-1)));
        }
    \end{lstlisting}
\end{document}
share|improve this question
    
Listings can only scan for tokens. You need more. So I think you need a more powerful tool to highlight such code. Maybe pygments. However therefor you have to write a new Lexer. –  Marco Daniel Jun 7 '13 at 11:12
    
You say, it is not possible to highlight numbers within coments in comment color, while they are otherwise in red? i.e. is there no hierarchy in the colour scheme? –  Jonas Jun 8 '13 at 6:43
    
This looks like C with different keywords to me, so modifying the Pygments C lexer to create one for this language shouldn't be too hard. –  You Jun 8 '13 at 8:59
    
@You: I thought the same but was not able to find any rules for the required language. Jonas: Sorry for this bad news. What do you mean with hierarchy? –  Marco Daniel Jun 8 '13 at 10:23
    
I meant, that numbers within comments and strings should not get colored: 1. color all the numbers, 2. color all the comments and strings. -> the numbers in string/comments will not be red. –  Jonas Jun 16 '13 at 11:14
show 2 more comments

2 Answers 2

I found it here: How can I change the color of digits when using the listings package?

@Clément: Add a star before the zero, i.e. {0}{{{\color{red}0}}}1 -> *{0}{{{\color{red}0}}}1 to only colour outside of strings and comments. You only need to do this once, so not for the rest of the numerals. – Mark S. Everitt Jan 31 '12 at 15:57

Change

 {"}{{{\ProcessQuote{"}}}}1% Disable coloring within double quotes
 {0}{{\ColorIfNotInString{0}}}{1}%

to

 *{0}{{\ColorIfNotInString{0}}}{1}%

So it looks like:

.png of .pdf from .tex.

\documentclass[fleqn, a4paper, landscape]{article}
\usepackage{xcolor}

\definecolor{isored}{rgb}{0.6,0,0} % for strings
\definecolor{isogreen}{rgb}{0.25,0.6,0.2} % comments
\definecolor{isoblue}{rgb}{0.0,0.0,1} % keyword
\definecolor{isolightblue}{rgb}{0.5,0.5,1.0} % keywords
\definecolor{isocomgreen}{rgb}{0.25,0.35,0.75} % javadoc

\usepackage{etoolbox}

\newtoggle{InString}{}% Keep track of if we are within a string
\togglefalse{InString}% Assume not initally in string
% http://tex.stackexchange.com/questions/34896/coloring-digits-with-the-listings-package?rq=1
\newcommand*{\ColorIfNotInString}[1]{\iftoggle{InString}{#1}{\textcolor{isored}#1}}%
\newcommand*{\ProcessQuote}[1]{#1\iftoggle{InString}{\global\togglefalse{InString}}{\global\toggletrue{InString}}}%

\usepackage{listings} 

\lstdefinelanguage{isodat}
{%
  basicstyle=\ttfamily,%
  literate=%
     *{0}{{\ColorIfNotInString{0}}}{1}%
     {1}{{\ColorIfNotInString{1}}}{1}%
     {2}{{\ColorIfNotInString{2}}}{1}%
     {3}{{\ColorIfNotInString{3}}}{1}%
     {4}{{\ColorIfNotInString{4}}}{1}%
     {5}{{\ColorIfNotInString{5}}}{1}%
     {6}{{\ColorIfNotInString{6}}}{1}%
     {7}{{\ColorIfNotInString{7}}}{1}%
     {8}{{\ColorIfNotInString{8}}}{1}%
     {9}{{\ColorIfNotInString{9}}}{1}%
     {.0}{{\ColorIfNotInString{.0}}}{1}% Following is to ensure that only periods
     {.1}{{\ColorIfNotInString{.1}}}{1}% followed by a digit are changed.
     {.2}{{\ColorIfNotInString{.2}}}{1}%
     {.3}{{\ColorIfNotInString{.3}}}{1}%
     {.4}{{\ColorIfNotInString{.4}}}{1}%
     {.5}{{\ColorIfNotInString{.5}}}{1}%
     {.6}{{\ColorIfNotInString{.6}}}{1}%
     {.7}{{\ColorIfNotInString{.7}}}{1}%
     {.8}{{\ColorIfNotInString{.8}}}{1}%
     {.9}{{\ColorIfNotInString{.9}}}{1}%
     {\ }{{ }}{1}% handle the space
     ,
     %string=[s]{_}{=},
     %string=[s]{_}{(}, 
  mathescape=true, 
  emphstyle={[2]\color{isoblue}},
  tabsize=4,
  captionpos=b,
  showstringspaces=false,
  keywordstyle=\color{isoblue},
  keywordstyle=[2]\color{isoblue},
  commentstyle=\color{isogreen},%
  stringstyle=\color{isolightblue},%
  morestring=[s][\color{isoblue}]{"}{"},%
  morecomment = [l]{//},
  morecomment = [l]{///},
  morecomment = [s]{/*}{*/},
  sensitive = true,
  morekeywords = {if, else, string, number},%You need to add here
  emph={_Set, _Delay, _strstr, _strtod, _strmid},% You need to add here
  emphstyle=\color{isolightblue},
}

\begin{document}
    \begin{lstlisting}[caption=Isodat language sample..,language=isodat]

        _Set("Precon/Trap 3",0);
        _Delay(1000,1,"Evacuating Carbon trap")
        //_Set("ExtValveBlock/Valve 4",1); commented because interferes with extraction

        string SeqPrepText="";
        number AnzFull=1;

        SeqPrepText =_GetSequenceText("Preparation","1,0");
        //_MessageBox(SeqPrepText,MB_OK,MB_ICONEXCLAMATION);        

        Midpoint    = _strstr (SeqPrepText,",");
        if (Midpoint==-1) 
        {
        /* Format stimmt nicht falsches oder kein Trennzeichen
           no error haldling so far
           cut to 1 and zero by default */
        }
        else
        {
          AnzHalf = _strtod(_strmid(SeqPrepText,(Midpoint+1),(StrLaenge-Midpoint-1)));
        }
    \end{lstlisting}
\end{document}
share|improve this answer
add comment

I am not able to fix the color of the number, can you check with the following code:

\lstdefinelanguage{isodat}
{
  basicstyle=\ttfamily,%
  literate=%
  %         {"}{{{\ProcessQuote{"}}}}1% Disable coloring within double quotes
     {0}{{\ColorIfNotInString{0}}}{1}%
     {1}{{\ColorIfNotInString{1}}}{1}%
     {2}{{\ColorIfNotInString{2}}}{1}%
     {3}{{\ColorIfNotInString{3}}}{1}%
     {4}{{\ColorIfNotInString{4}}}{1}%
     {5}{{\ColorIfNotInString{5}}}{1}%
     {6}{{\ColorIfNotInString{6}}}{1}%
     {7}{{\ColorIfNotInString{7}}}{1}%
     {8}{{\ColorIfNotInString{8}}}{1}%
     {9}{{\ColorIfNotInString{9}}}{1}%
     {.0}{{\ColorIfNotInString{.0}}}{1}% Following is to ensure that only periods
     {.1}{{\ColorIfNotInString{.1}}}{1}% followed by a digit are changed.
     {.2}{{\ColorIfNotInString{.2}}}{1}%
     {.3}{{\ColorIfNotInString{.3}}}{1}%
     {.4}{{\ColorIfNotInString{.4}}}{1}%
     {.5}{{\ColorIfNotInString{.5}}}{1}%
     {.6}{{\ColorIfNotInString{.6}}}{1}%
     {.7}{{\ColorIfNotInString{.7}}}{1}%
     {.8}{{\ColorIfNotInString{.8}}}{1}%
     {.9}{{\ColorIfNotInString{.9}}}{1}%
     {\ }{{ }}{1}% handle the space
     ,
  mathescape=true, 
  emphstyle={[2]\color{isoblue}},
  tabsize=4,
  captionpos=b,
  showstringspaces=false,
  keywordstyle=\color{isoblue},
  keywordstyle=[2]\color{isoblue},
  commentstyle=\color{isogreen},%
  stringstyle=\color{isolightblue},%
  morestring=[s][\color{isoblue}]{"}{"},%
  morecomment = [l]{//}, 
  morecomment = [l]{///},
  morecomment = [s]{/*}{*/},
  sensitive = true,
  morekeywords = {if, else, string, number},%You need to add here
  emph={_Set, _Delay, _strstr, _strtod, _strmid},% You need to add here
  emphstyle=\color{isolightblue},
}
share|improve this answer
    
Nice one! I included your solution into the question, so that it gets easier to follow. But too bad you had to remove string=[s]{_}{=}, and string=[s]{_}{(},. - Is there no way of setting like from (inclusive) to (exclusive)? –  Jonas Jun 19 '13 at 18:49
add comment

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.