怎样写出下面这么漂亮的代码

怎样写出下面这么漂亮的代码

我想知道如何生成以下漂亮的代码,包括字体、颜色、线条和图形描述。我认为它不是由 编写的\lstset。此图片摘自一篇名为迈向优化安全系统:分析未定义行为的影响

在此处输入图片描述

答案1

该代码似乎使用包突出显示minted

pdflatex --shell-escape或排版arara

% arara: pdflatex: { shell: yes }
\documentclass{article}
\pagestyle{empty}% for cropping
\usepackage{minted,newtxtext,newtxmath,caption}
\newcommand\code{\texttt}
\newcommand\param{\textit}
\DeclareCaptionFont{bfmath}{\boldmath\bfseries}
\DeclareCaptionFormat{ruled}{\hrulefill\par#1#2#3}
\captionsetup{format=ruled,font=bfmath}
\begin{document}
\begin{figure}
  \centering
\begin{minted}{c}
const uint8_t *data     = /* buffer head */;
const uint8_t *data_end = /* buffer tail */;
int size = bytestream_get_be16(&data);
if (data + size >= data_end || data + size < data)
    return -1;
data += size;
...
int len = ff_amf_tag_size(data, data_end);
if (len < 0 || data + len >= data_end
            || data + len < data)
    return -1;
data += len;
/* continue to read data */
\end{minted}
  \caption{Unstable bounds checks in the form $\code{data} + x < \code{data}$ from FFmpeg/Libav, which gcc optimizes into $x < 0$.}
\end{figure}
\begin{figure}
  \centering
\begin{minted}{c}
void pdec(io *f, int k) {
    if (k < 0) {          /* print negative k */
        if (-k >= 0) {    /* not INT_MIN? */
            pchr(f, '-'); /* print minus */
            pdec(f, -k);  /* print -k */
            return;
        }
            ...           /* print INT_MIN */
            return;
        }
    ...                   /* print positive k */
}
\end{minted}
  \caption{An unstable integer check in plan9port. The function \code{pdec} prints a signed integer \code{k}; gcc optimizes the check \code{-k >= 0} into \param{true} when it learns that \code{k} is negative, leading to an infinite loop if the input \code{k} is \code{INT\_MIN}.}
\end{figure}
\end{document}

在此处输入图片描述

相关内容