1

I'm looking for reproduce the color scheme of sublime text for my latex document. Here is my attempt:

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

enter image description here

As you can see my <> delimiters and so everything in between are supposed to be green but they're not and I don't know how to fix that. I have the same problem with = on line 17, I would like the = to be green but it is orange.

Also, I would like my function declaration to be a different color (a lighter blue) but I can't seem to change the color of the already colored text

1 Answer 1

0

Sublime text uses monokai as its default color scheme, which is a bit hard to emulate manually with listings. But the good news are, that minted (via pygmentize) already provides that color scheme:

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

enter image description here

Also, I'd suggest not to use dark mode.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .