如何使用 minted 以等宽字体呈现全黑文本的代码块?

如何使用 minted 以等宽字体呈现全黑文本的代码块?

如何使用 minted 以电传字体(等宽固定宽度字体)呈现代码块,并且所有文本都是相同的颜色(可能是黑色)?

如果您希望代码块内的所有文本都变成黑色(没有语法高亮),您会写什么?

我们的确是不是想:

\usemintedstyle{perldoc}      
\usemintedstyle{colorful}

\documentclass{article}
\usepackage{minted}
\usepackage{xcolor}
\colorlet{myblack}{black!50!white}

\begin{document}

\section*{Minted styles with non-italic comments}

\subsection*{Light theme}

\subsubsection*{\texttt{perldoc}}

\usemintedstyle{perldoc}

\begin{minted}[linenos]{r}


    int main():
        // Generate data
        const unsigned arraySize = 32768;
        
       // arraySize = 32768
       // arraySize = const(unsigned(arraySize))
        
        Array<int> data = Array<int>(arraySize);

        for (unsigned k = 0; k < arraySize; ++k)
            data[k] = k;
            // semi-colon ; and new line \n is redundant
            // \n\r;  ... three consecutive infix operators 
            // \r\n;  ... three consecutive infix operators
            // \n;    ... two consecutive infix operator
            // ;      ... one consecutive infix operator 
            // \n     ... one consecutive infix operator

        //TO DO: randomize order

        // TO DO: TEST TIME FOR LINEAR Searchinf for
        // arraySize/2 

        data.sort();
        // Equivalent to:
        //      sort(data);
        //      sort<<Array<int>>>(data);  
        //      sort<type(data)>(data); 

    // TO DO: Binary Search 
    Uni<float> start   = Unitized<float>(clock(), "seconds");
    Uni<float> current = Unitized<float>(clock(), "seconds");

    // `Uni` is sub_sequence alias of `Unitized`
    // all sequence are allowed provided that
    // not exist two labels in current scope
    // such that alias is subsequence of both labels

    Uni<unsigned> = Uni<unsigned>duration(5, "min");  

    // most case-insensitive sub-sequences of "min" are allowed
    // as string inputs to the Unitized template constructor

    while (current - start < ideal_duration):
        // TO DO: 
        //     run binary search
        //     count number of binary searches were done

        // ENGLISH:
        //    promote integer to Unitized<insigned>("seconds")
        current = clock();
    
    actual_duration = finish - start
    
    average_time = count/actual_duration 
    

       
       // colon `:` at end of loop preamble 
       //           is redundant
       //
       // the following two things are the same
       //     for():for()
       //     for()for()
       //
       // the following two things are the same
       //     pow:(10, 99)
       //     pow(10, 99)
       //
       // colon is an infix delimieter (and comma, space, etc...)
       //
       // transition from alphanumeric chars to non-alphanumeric
       // is implicit infix delimeter
       //
       // `for` is a functor
       // ---------------
       // for(x)(y)
       // ---------------
       // f = for(x)
       // f(y)
       // ---------------

    std::cout << average_time << '\n';

        //std::cout similar to
        //   disp()
        //   display()
        //   print()
        //   printf()
        //   fprintf()

\end{minted}

\end{document}

答案1

您可以使用bw黑白效果的样式(运行pygmentize -L styles以获取所有可用默认样式的列表):

% !TeX program = txs:///arara
% arara: pdflatex: {synctex: on, interaction: nonstopmode, shell: yes}
\documentclass{article}
\usepackage{minted}
\usepackage{xcolor}
\colorlet{myblack}{black!50!white}

%\selectcolormodel{gray}

\begin{document}

\section*{Minted styles with non-italic comments}

\subsection*{Light theme}

\subsubsection*{\texttt{perldoc}}

\usemintedstyle{bw}

\begin{minted}[linenos]{r}


    int main():
        // Generate data
        const unsigned arraySize = 32768;
        
       // arraySize = 32768
       // arraySize = const(unsigned(arraySize))
        
        Array<int> data = Array<int>(arraySize);

        for (unsigned k = 0; k < arraySize; ++k)
            data[k] = k;
            // semi-colon ; and new line \n is redundant
            // \n\r;  ... three consecutive infix operators 
            // \r\n;  ... three consecutive infix operators
            // \n;    ... two consecutive infix operator
            // ;      ... one consecutive infix operator 
            // \n     ... one consecutive infix operator

        //TO DO: randomize order

        // TO DO: TEST TIME FOR LINEAR Searchinf for
        // arraySize/2 

        data.sort();
        // Equivalent to:
        //      sort(data);
        //      sort<<Array<int>>>(data);  
        //      sort<type(data)>(data); 

    // TO DO: Binary Search 
    Uni<float> start   = Unitized<float>(clock(), "seconds");
    Uni<float> current = Unitized<float>(clock(), "seconds");

    // `Uni` is sub_sequence alias of `Unitized`
    // all sequence are allowed provided that
    // not exist two labels in current scope
    // such that alias is subsequence of both labels

    Uni<unsigned> = Uni<unsigned>duration(5, "min");  

    // most case-insensitive sub-sequences of "min" are allowed
    // as string inputs to the Unitized template constructor

    while (current - start < ideal_duration):
        // TO DO: 
        //     run binary search
        //     count number of binary searches were done

        // ENGLISH:
        //    promote integer to Unitized<insigned>("seconds")
        current = clock();
    
    actual_duration = finish - start
    
    average_time = count/actual_duration 
    

       
       // colon `:` at end of loop preamble 
       //           is redundant
       //
       // the following two things are the same
       //     for():for()
       //     for()for()
       //
       // the following two things are the same
       //     pow:(10, 99)
       //     pow(10, 99)
       //
       // colon is an infix delimieter (and comma, space, etc...)
       //
       // transition from alphanumeric chars to non-alphanumeric
       // is implicit infix delimeter
       //
       // `for` is a functor
       // ---------------
       // for(x)(y)
       // ---------------
       // f = for(x)
       // f(y)
       // ---------------

    std::cout << average_time << '\n';

        //std::cout similar to
        //   disp()
        //   display()
        //   print()
        //   printf()
        //   fprintf()

\end{minted}

\end{document}

答案2

首先,缩进逐字环境,因为缩进将保留在输出中。

其次,如果您不想要特殊格式,请使用Verbatim

\documentclass{article}
\usepackage{minted}
\usepackage{fancyvrb}
\usepackage{xcolor}

\begin{document}

\section*{Minted styles with non-italic comments}

\begin{minted}[style=bw,linenos]{r}
int main():
    // Generate data
    const unsigned arraySize = 32768;

    // arraySize = 32768
    // arraySize = const(unsigned(arraySize))
    Array<int> data = Array<int>(arraySize);

    for (unsigned k = 0; k < arraySize; ++k)
        data[k] = k;
        // semi-colon ; and new line \n is redundant
        // \n\r;  ... three consecutive infix operators 
        // \r\n;  ... three consecutive infix operators
        // \n;    ... two consecutive infix operator
        // ;      ... one consecutive infix operator 
        // \n     ... one consecutive infix operator
\end{minted}

\section*{Simple verbatim}

\begin{Verbatim}[linenos]
int main():
    // Generate data
    const unsigned arraySize = 32768;

    // arraySize = 32768
    // arraySize = const(unsigned(arraySize))
    Array<int> data = Array<int>(arraySize);

    for (unsigned k = 0; k < arraySize; ++k)
        data[k] = k;
        // semi-colon ; and new line \n is redundant
        // \n\r;  ... three consecutive infix operators 
        // \r\n;  ... three consecutive infix operators
        // \n;    ... two consecutive infix operator
        // ;      ... one consecutive infix operator 
        // \n     ... one consecutive infix operator
\end{Verbatim}

\end{document}

如果你坚持minted并且想要全部清单使用方法bw,只需\usemintedstyle{bw}在序言中发出即可。

在此处输入图片描述

相关内容