“Isodat”语言源代码语法高亮

“Isodat”语言源代码语法高亮

Isodat 语言用于 ThermoFisher Scientific® 的质谱仪,用于稳定同位素质谱分析。

该语言语法高亮的部分功能已在列表包:格式化语言定义中的所有数字?以及后续问题列出包:彩色数字,但变量名没有彩色

最后它应该看起来像下面的图片:

Isodat 源代码示例。

我得到以下信息:

.tex 中的 .pdf 的 .png。

你知道这里需要改什么吗?问题是:
1.注释中的数字,
2.字符串中的数字,

到目前为止,已修复以下内容:
3. 蓝色关键字(if、else、string、number),
4. 黑色关键字后的括号,
5. 块注释,
6. 浅蓝色关键字。7
. 蓝色字符串

\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
% https://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}

答案1

我在这里找到了它: 使用列表包时如何更改数字的颜色?

@Clément:在零前添加一个星号,即 {0}{{{\color{red}0}}}1 -> *{0}{{{\color{red}0}}}1 只为字符串和注释外部着色。您只需执行一次此操作,其余数字则无需执行。– Mark S. Everitt 2012 年 1 月 31 日 15:57

改变

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

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

看起来是这样的:

.tex 中的 .pdf 的 .png。

\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
% https://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}

答案2

我无法修复数字的颜色,您可以使用以下代码检查:

\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},
}

相关内容