清单着色问题

清单着色问题

我正在寻找为我的乳胶文档重现 sublime text 的配色方案。这是我的尝试:

\documentclass[10pt]{report}
\usepackage{listings}
\usepackage{xcolor}

\begin{document}

\definecolor{mGreen}{rgb}{0,0.6,0}
\definecolor{mGray}{rgb}{0.5,0.5,0.5}
\definecolor{mPurple}{rgb}{0.58,0,0.82}
\definecolor{backgroundColour}{rgb}{0.19,0.22,0.25}
\definecolor{pinkk}{rgb}{0.78,0.58,0.71}
\definecolor{greenn}{rgb}{0.6,0.78,0.58}
\definecolor{greennstring}{rgb}{0.6,0.78,0.49}
\definecolor{comments}{rgb}{0.65,0.67,0.72}
\definecolor{idd}{rgb}{0.38,0.70,0.70}
\definecolor{bluee}{rgb}{0.38,0.6,0.8}
\definecolor{orangee}{rgb}{0.98,0.48,0.34}
\definecolor{orangeee}{rgb}{0.98,0.68,0.34}
\definecolor{whitee}{rgb}{216,222,214}


\lstdefinestyle{CStyle}{
    commentstyle=\color{comments},
    backgroundcolor=\color{backgroundColour}, 
    keywordstyle=\color{pinkk},
    numberstyle=\tiny\color{mGray},
    basicstyle=\footnotesize\color{whitee},
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2,
    language=C,
    keywordstyle = {\color{pinkk}},
    keywordstyle = [2]{\color{orangeee}},
    keywordstyle = [3]{\color{orangee}},
    otherkeywords = {=,+,-,0,1,2,3,4,5,6,7,8,9,|,\%d , \\n,<,>},
    morekeywords = [2]{0,1,2,3,4,5,6,7,8,9},
    morekeywords = [3]{+,=,-,|,<,>},
    morecomment=[s][\color{greenn}]{<std}{>},
    stringstyle=\color{greennstring}
}

\lstset{emph={Fibonacci,main,printf},emphstyle=\color{bluee}}
\begin{lstlisting}[style=CStyle]
#include <stdio.h>
#include <stdlib.h> // EXIT_SUCCESS

int Fibonacci(int n){
    if(n == 0 || n == 1)    return n;
    int tab_fib[n];
    tab_fib[0]=0;
    tab_fib[1]=1;
    for(int i=2;i<n;i++){
        tab_fib[i] = tab_fib[i-1] +tab_fib[i-2];
    }
    n = tab_fib[n-1];
    return n;
}
int main(void){ 
    int n=5; 
    printf( "Fibonacci(%d)=%d\n" , n , Fibonacci(n) );
    return EXIT_SUCCESS;
}
\end{lstlisting}
\end{document}

在此处输入图片描述

如您所见,我的 <> 分隔符以及其间的所有内容都应该是绿色的,但它们不是,我不知道如何修复它。我在第 17 行的 = 也遇到了同样的问题,我希望 = 是绿色的,但它却是橙色的。

另外,我希望我的函数声明是不同的颜色(浅蓝色),但我似乎无法改变已经着色的文本的颜色

答案1

Sublime text 使用monokai为其默认配色方案,这有点难以手动模拟listings。但好消息是,minted(通过pygmentize) 已经提供了该配色方案:

\documentclass[10pt]{report}
\usepackage{minted}
\usepackage{xcolor}

\begin{document}

\definecolor{mGreen}{rgb}{0,0.6,0}
\definecolor{mGray}{rgb}{0.5,0.5,0.5}
\definecolor{mPurple}{rgb}{0.58,0,0.82}
\definecolor{backgroundColour}{rgb}{0.19,0.22,0.25}
\definecolor{pinkk}{rgb}{0.78,0.58,0.71}
\definecolor{greenn}{rgb}{0.6,0.78,0.58}
\definecolor{greennstring}{rgb}{0.6,0.78,0.49}
\definecolor{comments}{rgb}{0.65,0.67,0.72}
\definecolor{idd}{rgb}{0.38,0.70,0.70}
\definecolor{bluee}{rgb}{0.38,0.6,0.8}
\definecolor{orangee}{rgb}{0.98,0.48,0.34}
\definecolor{orangeee}{rgb}{0.98,0.68,0.34}
\definecolor{whitee}{rgb}{216,222,214}

\begin{minted}{c}
#include <stdio.h>
#include <stdlib.h> // EXIT_SUCCESS

int Fibonacci(int n){
    if(n == 0 || n == 1)    return n;
    int tab_fib[n];
    tab_fib[0]=0;
    tab_fib[1]=1;
    for(int i=2;i<n;i++){
        tab_fib[i] = tab_fib[i-1] +tab_fib[i-2];
    }
    n = tab_fib[n-1];
    return n;
}
int main(void){ 
    int n=5; 
    printf( "Fibonacci(%d)=%d\n" , n , Fibonacci(n) );
    return EXIT_SUCCESS;
}
\end{minted}
\end{document}

在此处输入图片描述

另外,我建议不要使用暗模式。

相关内容