> For the complete documentation index, see [llms.txt](https://ayakaleaf-pro.ayaka.space/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ayakaleaf-pro.ayaka.space/latex/zh-cn/ge-shi-hua/12-code-highlighting-with-minted.md).

# 使用 minted 进行代码高亮

## 引言

本文展示如何使用 [`minted` 宏包](https://ctan.org/pkg/minted?lang=en) 在 LaTeX 文档中格式化并高亮编程语言源代码，先从一个示例开始：

```latex
\documentclass{article}
\usepackage{minted}
\begin{document}
\begin{minted}{python}
import numpy as np

def incmatrix(genl1,genl2):
    m = len(genl1)
    n = len(genl2)
    M = None #to become the incidence matrix
    VT = np.zeros((n*m,1), int)  #dummy variable

    #compute the bitwise xor matrix
    M1 = bitxormatrix(genl1)
    M2 = np.triu(bitxormatrix(genl2),1)

    for i in range(m-1):
        for j in range(i+1, m):
            [r,c] = np.where(M2 == M1[i,j])
            for k in range(len(r)):
                VT[(i)*n + r[k]] = 1;
                VT[(i)*n + c[k]] = 1;
                VT[(j)*n + r[k]] = 1;
                VT[(j)*n + c[k]] = 1;

                if M is None:
                    M = np.copy(VT)
                else:
                    M = np.concatenate((M, VT), 1)

                VT = np.zeros((n*m,1), int)

    return M
\end{minted}
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Example+of+the+minted+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bminted%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bminted%7D%7Bpython%7D%0Aimport+numpy+as+np%0A++++%0Adef+incmatrix%28genl1%2Cgenl2%29%3A%0A++++m+%3D+len%28genl1%29%0A++++n+%3D+len%28genl2%29%0A++++M+%3D+None+%23to+become+the+incidence+matrix%0A++++VT+%3D+np.zeros%28%28n%2Am%2C1%29%2C+int%29++%23dummy+variable%0A++++%0A++++%23compute+the+bitwise+xor+matrix%0A++++M1+%3D+bitxormatrix%28genl1%29%0A++++M2+%3D+np.triu%28bitxormatrix%28genl2%29%2C1%29+%0A%0A++++for+i+in+range%28m-1%29%3A%0A++++++++for+j+in+range%28i%2B1%2C+m%29%3A%0A++++++++++++%5Br%2Cc%5D+%3D+np.where%28M2+%3D%3D+M1%5Bi%2Cj%5D%29%0A++++++++++++for+k+in+range%28len%28r%29%29%3A%0A++++++++++++++++VT%5B%28i%29%2An+%2B+r%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28i%29%2An+%2B+c%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28j%29%2An+%2B+r%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28j%29%2An+%2B+c%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++%0A++++++++++++++++if+M+is+None%3A%0A++++++++++++++++++++M+%3D+np.copy%28VT%29%0A++++++++++++++++else%3A%0A++++++++++++++++++++M+%3D+np.concatenate%28%28M%2C+VT%29%2C+1%29%0A++++++++++++++++%0A++++++++++++++++VT+%3D+np.zeros%28%28n%2Am%2C1%29%2C+int%29%0A++++%0A++++return+M%0A%5Cend%7Bminted%7D%0A%5Cend%7Bdocument%7D)

此示例生成如下输出：

![展示 minted 宏包输出的示例](/files/ad13533b8c19da7ca1b2dc7a02035bb919f774d8)

这里有两个重要命令。在导言区中通过编写以下内容导入该宏包

```latex
\usepackage{minted}
```

然后这些标签 `\begin{minted}{python}` 和 `\end{minted}` 界定了一个环境，它会以等宽字体逐字打印文本，并对注释、关键字和函数应用颜色。参数 `python` 是源代码所使用的编程语言。 `minted` 支持 150 多种编程和标记语言以及配置文件，参见 [参考指南](#reference-guide) 以查看受支持语言列表。

**注意**：对于 `minted` 要与你的 *本地* LaTeX 发行版配合使用，还必须安装一个名为 [Pygments](https://pygments.org/) 的附加程序。 [Overleaf](https://www.overleaf.com/) 可以帮你省去安装它以及为编译文档而运行特殊命令的麻烦——在 Overleaf 上，使用 `minted` 的文档将“开箱即用”。

## 基本用法

如下示例所示， `minted` 环境可以通过配置来修改排版后代码的视觉呈现。这里， `minted` 环境使用若干以逗号分隔的参数，形式为 `key=value`:

```latex
\documentclass{article}
\usepackage{minted}
\usepackage{xcolor} % to access the named colour LightGray
\definecolor{LightGray}{gray}{0.9}
\begin{document}
\begin{minted}
[
frame=lines,
framesep=2mm,
baselinestretch=1.2,
bgcolor=LightGray,
fontsize=\footnotesize,
linenos
]
{python}
import numpy as np

def incmatrix(genl1,genl2):
    m = len(genl1)
    n = len(genl2)
    M = None #to become the incidence matrix
    VT = np.zeros((n*m,1), int)  #dummy variable

    #compute the bitwise xor matrix
    M1 = bitxormatrix(genl1)
    M2 = np.triu(bitxormatrix(genl2),1)

    for i in range(m-1):
        for j in range(i+1, m):
            [r,c] = np.where(M2 == M1[i,j])
            for k in range(len(r)):
                VT[(i)*n + r[k]] = 1;
                VT[(i)*n + c[k]] = 1;
                VT[(j)*n + r[k]] = 1;
                VT[(j)*n + c[k]] = 1;

                if M is None:
                    M = np.copy(VT)
                else:
                    M = np.concatenate((M, VT), 1)

                VT = np.zeros((n*m,1), int)

    return M
\end{minted}
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Another+example+of+the+minted+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bminted%7D%0A%5Cusepackage%7Bxcolor%7D+%25+to+access+the+named+colour+LightGray%0A%5Cdefinecolor%7BLightGray%7D%7Bgray%7D%7B0.9%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bminted%7D%0A%5B%0Aframe%3Dlines%2C%0Aframesep%3D2mm%2C%0Abaselinestretch%3D1.2%2C%0Abgcolor%3DLightGray%2C%0Afontsize%3D%5Cfootnotesize%2C%0Alinenos%0A%5D%0A%7Bpython%7D%0Aimport+numpy+as+np%0A++++%0Adef+incmatrix%28genl1%2Cgenl2%29%3A%0A++++m+%3D+len%28genl1%29%0A++++n+%3D+len%28genl2%29%0A++++M+%3D+None+%23to+become+the+incidence+matrix%0A++++VT+%3D+np.zeros%28%28n%2Am%2C1%29%2C+int%29++%23dummy+variable%0A++++%0A++++%23compute+the+bitwise+xor+matrix%0A++++M1+%3D+bitxormatrix%28genl1%29%0A++++M2+%3D+np.triu%28bitxormatrix%28genl2%29%2C1%29+%0A%0A++++for+i+in+range%28m-1%29%3A%0A++++++++for+j+in+range%28i%2B1%2C+m%29%3A%0A++++++++++++%5Br%2Cc%5D+%3D+np.where%28M2+%3D%3D+M1%5Bi%2Cj%5D%29%0A++++++++++++for+k+in+range%28len%28r%29%29%3A%0A++++++++++++++++VT%5B%28i%29%2An+%2B+r%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28i%29%2An+%2B+c%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28j%29%2An+%2B+r%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28j%29%2An+%2B+c%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++%0A++++++++++++++++if+M+is+None%3A%0A++++++++++++++++++++M+%3D+np.copy%28VT%29%0A++++++++++++++++else%3A%0A++++++++++++++++++++M+%3D+np.concatenate%28%28M%2C+VT%29%2C+1%29%0A++++++++++++++++%0A++++++++++++++++VT+%3D+np.zeros%28%28n%2Am%2C1%29%2C+int%29%0A++++%0A++++return+M%0A%5Cend%7Bminted%7D%0A%5Cend%7Bdocument%7D)

此示例生成如下输出：

![使用 minted 宏包格式化排版代码的示例](/files/dc19c61b2e8505f96c2d07a2cab533b28c6e4200)

本示例中使用的参数是：

* `frame=lines`：绘制两条线，一条在代码上方，一条在下方，用于框住代码。其他可能的值有 `leftline`, `topline`, `bottomline` 和 `single`.
* `framesep=2mm`：框与代码之间的间距设为 2mm。其他 [长度单位](/latex/zh-cn/ge-shi-hua/01-lengths-in-latex.md) 也可以使用。
* `baselinestretch=1.2`：代码的行距设为 1.2。
* `bgcolor=LightGray`：背景颜色设为 `LightGray`。要使其生效，你需要导入 `xcolor` 宏包。参见 [在 LaTeX 中使用颜色](/latex/zh-cn/ge-shi-hua/13-using-colors-in-latex.md) 以了解更多有关颜色操作的内容。
* `fontsize=\footnotesize`：字体大小设为 `footnotesize`。还可以设置其他 [字体大小](/latex/zh-cn/zi-ti/01-font-sizes-families-and-styles.md#reference-guide) 。
* `linenos`：启用行号。

其他可能有用的选项包括：

* `mathescape`：在代码注释中启用数学模式。
* `rulecolor`：更改框线的颜色。
* `showspaces`：启用一个特殊字符来显示空格。

## 从文件中包含代码

代码通常存储在源文件中，因此一个能自动从文件导入代码的命令非常方便，如以下示例所示：

```latex
\documentclass{article}
\usepackage{minted}
\title{Importing files using minted}
\begin{document}
接下来的代码将直接从文件中导入：

\inputminted{octave}{BitXorMatrix.m}
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=\&snip_name\[]=main.tex\&snip\[]=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bminted%7D%0A%5Ctitle%7BImporting+files+using+minted%7D%0A%5Cbegin%7Bdocument%7D%0AThe+next+code+will+be+directly+imported+from+a+file%3A%0A%0A%5Cinputminted%7Boctave%7D%7BBitXorMatrix.m%7D%0A%5Cend%7Bdocument%7D\&snip_name\[]=BitXorMatrix.m\&snip\[]=function+X+%3D+BitXorMatrix%28A%2CB%29%0A%25function+to+compute+the+sum+without+charge+of+two+vectors%0A%09%0A%09%25convert+elements+into+usigned+integers%0A%09A+%3D+uint8%28A%29%3B%0A%09B+%3D+uint8%28B%29%3B%0A%0A%09m1+%3D+length%28A%29%3B%0A%09m2+%3D+length%28B%29%3B%0A%09X+%3D+uint8%28zeros%28m1%2C+m2%29%29%3B%0A%09for+n1%3D1%3Am1%0A%09%09for+n2%3D1%3Am2%0A%09%09%09X%28n1%2C+n2%29+%3D+bitxor%28A%28n1%29%2C+B%28n2%29%29%3B%0A%09%09end%0A%09end\&main_document=main.tex)

此示例生成如下输出：

![使用 minted 导入代码文件](/files/2d46a41a00416c2d2585162766a3c0d79d09dba5)

命令 `\inputminted{octave}{BitXorMatrix.m}` 从文件 `BitXorMatrix.m`中导入代码，参数 `octave` 会告诉 LaTeX 代码所使用的编程语言。该命令还可以接受两个额外参数，只导入文件的一部分；例如，要导入第 2 行到第 12 行的代码，命令变为：

```latex
\inputminted[firstline=2, lastline=12]{octave}{BitXorMatrix.m}
```

## 单行代码

如果你只需要输入一行代码，命令 `\mint`及其语法如下一个示例所示，就可以办到。

```latex
单行代码格式化同样适用于 \texttt{minted}。例如，像这样的一个小段 HTML：
\mint{html}|<h2>Something <b>here</b></h2>|
\noindent 也可以正确格式化。
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=One+line+code+example+with+minted\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bminted%7D%0A%5Cbegin%7Bdocument%7D%0AOne-line+code+formatting+also+works+with+%5Ctexttt%7Bminted%7D.+For+example%2C+a+small+fragment+of+HTML+like+this%3A%0A%5Cmint%7Bhtml%7D%7C%3Ch2%3ESomething+%3Cb%3Ehere%3C%2Fb%3E%3C%2Fh2%3E%7C%0A%5Cnoindent+can+be+formatted+correctly.%0A%5Cend%7Bdocument%7D)

此示例生成如下输出：

![使用 minted 的单行代码示例](/files/c334c5d2d9e975382ccdb5cfd9b3618570d10fd2)

花括号中的参数设置编程语言（`html` 在此处为标记语言），待格式化的实际文本由字符 '|' 分隔。

## 自定义词法分析器

**（请注意，由于 `minted` 自 2023 年以来的变化，以下方法仅适用于** [**TeX Live 2022 或更早版本**](/latex/zh-cn/zhi-shi-ku/148-using-the-overleaf-project-menu.md#tex-live-version)**.)**

默认情况下， `minted` 仅支持那些词法分析器已经安装或已在 `pygmentize`中注册的语言。如果你编写了自定义词法分析器，或者想使用一个尚未在 Overleaf 上安装的语言词法分析器，你仍然可以使用下述方法在自己的 Overleaf 项目中使用它 [此处](https://tex.stackexchange.com/questions/18083/how-to-add-custom-c-keywords-to-be-recognized-by-minted#comment930474_42392).

假设你在文件 `nl-lexer.py`中定义了一个包含类 `NetLogoLexer` 的 NetLogo 语言词法分析器。上传 `nl-lexer.py` 到你的 Overleaf 项目，然后在使用 `nl-lexer.py:NetLogoLexer` 时将其指定为“语言名称”。 `minted`。例如：

```latex
\begin{minted}{nl-lexer.py:NetLogoLexer -x}
   ... your code here ...
\end{minted}
```

[这里是](http://quantixed.org/2018/10/23/new-lexicon-how-to-add-a-custom-minted-lexer-in-overleaf/) 另一个 ImageJ Macro 语言的示例。

## 颜色和样式表

用于代码高亮的配色方案保存在样式表中。你可以创建自己的样式表，或者使用 LaTeX 发行版中已有的样式表。请参见 [参考指南](#reference-guide) 以查看 [Overleaf](https://www.overleaf.com).

```latex
\documentclass{article}
\usepackage{minted}
\usemintedstyle{borland}
\begin{document}
\begin{minted}{python}
import numpy as np

def incmatrix(genl1,genl2):
    m = len(genl1)
    n = len(genl2)
    M = None #to become the incidence matrix
    VT = np.zeros((n*m,1), int)  #dummy variable

    #compute the bitwise xor matrix
    M1 = bitxormatrix(genl1)
    M2 = np.triu(bitxormatrix(genl2),1)

    for i in range(m-1):
        for j in range(i+1, m):
            [r,c] = np.where(M2 == M1[i,j])
            for k in range(len(r)):
                VT[(i)*n + r[k]] = 1;
                VT[(i)*n + c[k]] = 1;
                VT[(j)*n + r[k]] = 1;
                VT[(j)*n + c[k]] = 1;

                if M is None:
                    M = np.copy(VT)
                else:
                    M = np.concatenate((M, VT), 1)

                VT = np.zeros((n*m,1), int)

    return M
\end{minted}
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=pdflatex\&snip_name=Using+stylesheets+with+minted+package\&snip=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bminted%7D%0A%5Cusemintedstyle%7Bborland%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Bminted%7D%7Bpython%7D%0Aimport+numpy+as+np%0A++++%0Adef+incmatrix%28genl1%2Cgenl2%29%3A%0A++++m+%3D+len%28genl1%29%0A++++n+%3D+len%28genl2%29%0A++++M+%3D+None+%23to+become+the+incidence+matrix%0A++++VT+%3D+np.zeros%28%28n%2Am%2C1%29%2C+int%29++%23dummy+variable%0A++++%0A++++%23compute+the+bitwise+xor+matrix%0A++++M1+%3D+bitxormatrix%28genl1%29%0A++++M2+%3D+np.triu%28bitxormatrix%28genl2%29%2C1%29+%0A%0A++++for+i+in+range%28m-1%29%3A%0A++++++++for+j+in+range%28i%2B1%2C+m%29%3A%0A++++++++++++%5Br%2Cc%5D+%3D+np.where%28M2+%3D%3D+M1%5Bi%2Cj%5D%29%0A++++++++++++for+k+in+range%28len%28r%29%29%3A%0A++++++++++++++++VT%5B%28i%29%2An+%2B+r%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28i%29%2An+%2B+c%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28j%29%2An+%2B+r%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++VT%5B%28j%29%2An+%2B+c%5Bk%5D%5D+%3D+1%3B%0A++++++++++++++++%0A++++++++++++++++if+M+is+None%3A%0A++++++++++++++++++++M+%3D+np.copy%28VT%29%0A++++++++++++++++else%3A%0A++++++++++++++++++++M+%3D+np.concatenate%28%28M%2C+VT%29%2C+1%29%0A++++++++++++++++%0A++++++++++++++++VT+%3D+np.zeros%28%28n%2Am%2C1%29%2C+int%29%0A++++%0A++++return+M%0A%5Cend%7Bminted%7D%0A%5Cend%7Bdocument%7D)

使用 `borland` 样式表会产生如下输出：

![使用 borland 样式表时 minted 宏包的输出](/files/b6ecc28a75e4fc7f43b77af474ec767910eabef8)

设置着色样式的语法很简单，命令 `\usemintedstyle{borland}` 使用颜色主题 `borland` 来格式化源代码。你可以在 [参考指南](#reference-guide).

## 标题、标签和代码列表

使用 **minted** 格式化的代码列表可以包含在浮动元素中，就像 [图](/latex/zh-cn/geng-duo-zhu-ti/27-inserting-images.md#positioning) 和 [表](/latex/zh-cn/tu-xing-he-biao-ge/01-tables.md#positioning-tables)一样。代码列表可以指定标题和标签，然后稍后可被引用并包含在“代码列表”中。

```latex
\documentclass{article}
\usepackage{minted}
\title{代码示例列表}
\begin{document}
\begin{listing}[!ht]
\inputminted{octave}{BitXorMatrix.m}
\caption{来自外部文件的示例}
\label{listing:1}
\end{listing}

\begin{listing}[!ht]
\begin{minted}{c}
#include <stdio.h>
int main() {
   printf("Hello, World!"); /*printf() outputs the quoted string*/
   return 0;
}
\end{minted}
\caption{C 语言中的 Hello World}
\label{listing:2}
\end{listing}

\begin{listing}[!ht]
\begin{minted}{lua}
function fact (n)--defines a factorial function
  if n == 0 then
    return 1
  else
    return n * fact(n-1)
  end
end

print("enter a number:")
a = io.read("*number") -- read a number
print(fact(a))
\end{minted}
\caption{Example from the Lua manual}
\label{listing:3}
\end{listing}
\noindent\texttt{minted} makes a nice job of typesetting listings \ref{listing:1}, \ref{listing:2} and \ref{listing:3}.
\renewcommand\listoflistingscaption{List of source codes}
\listoflistings
\end{document}
```

[在 Overleaf 中打开此示例](https://www.overleaf.com/docs?engine=\&snip_name\[]=main.tex\&snip\[]=%5Cdocumentclass%7Barticle%7D%0A%5Cusepackage%7Bminted%7D%0A%5Ctitle%7BListing+code+examples%7D%0A%5Cbegin%7Bdocument%7D%0A%5Cbegin%7Blisting%7D%5B%21ht%5D%0A%5Cinputminted%7Boctave%7D%7BBitXorMatrix.m%7D%0A%5Ccaption%7BExample+from+external+file%7D%0A%5Clabel%7Blisting%3A1%7D%0A%5Cend%7Blisting%7D%0A%0A%5Cbegin%7Blisting%7D%5B%21ht%5D%0A%5Cbegin%7Bminted%7D%7Bc%7D%0A%23include+%3Cstdio.h%3E%0Aint+main%28%29+%7B%0A+++printf%28%22Hello%2C+World%21%22%29%3B+%2F%2Aprintf%28%29+outputs+the+quoted+string%2A%2F%0A+++return+0%3B%0A%7D%0A%5Cend%7Bminted%7D%0A%5Ccaption%7BHello+World+in+C%7D%0A%5Clabel%7Blisting%3A2%7D%0A%5Cend%7Blisting%7D%0A%0A%5Cbegin%7Blisting%7D%5B%21ht%5D%0A%5Cbegin%7Bminted%7D%7Blua%7D%0Afunction+fact+%28n%29--defines+a+factorial+function%0A++if+n+%3D%3D+0+then%0A++++return+1%0A++else%0A++++return+n+%2A+fact%28n-1%29%0A++end%0Aend%0A%0Aprint%28%22enter+a+number%3A%22%29%0Aa+%3D+io.read%28%22%2Anumber%22%29+--+read+a+number%0Aprint%28fact%28a%29%29%0A%5Cend%7Bminted%7D%0A%5Ccaption%7BExample+from+the+Lua+manual%7D%0A%5Clabel%7Blisting%3A3%7D%0A%5Cend%7Blisting%7D%0A%5Cnoindent%5Ctexttt%7Bminted%7D+makes+a+nice+job+of+typesetting+listings+%5Cref%7Blisting%3A1%7D%2C+%5Cref%7Blisting%3A2%7D+and+%5Cref%7Blisting%3A3%7D.%0A%5Crenewcommand%5Clistoflistingscaption%7BList+of+source+codes%7D%0A%5Clistoflistings%0A%5Cend%7Bdocument%7D\&snip_name\[]=BitXorMatrix.m\&snip\[]=%25This+code+is+directly+imported+from+a+file%0A%25A+function+to+compute+the+sum+without+charge+of+two+vectors%0Afunction+X+%3D+BitXorMatrix%28A%2CB%29%0A%25convert+elements+into+unsigned+integers%0AA+%3D+uint8%28A%29%3B%0AB+%3D+uint8%28B%29%3B%0A%0Am1+%3D+length%28A%29%3B%0Am2+%3D+length%28B%29%3B%0AX+%3D+uint8%28zeros%28m1%2C+m2%29%29%3B%0A+for+n1%3D1%3Am1%0A++for+n2%3D1%3Am2%0A+++X%28n1%2C+n2%29+%3D+bitxor%28A%28n1%29%2C+B%28n2%29%29%3B%0A++end%0Aend\&main_document=main.tex)

本示例的第一页包含以下输出：

![示例代码片段列表](/files/50ee9916b7b124e6b0baaff8530720970b618c69)

要打印包含所有“listing”元素的列表，请使用 `\listoflistings`。在上面的示例中，默认标题 `代码列表` 被更改为 `源代码列表` ，方法是编写

```latex
\renewcommand\listoflistingscaption{List of source codes}
\listoflistings % 现在排版列表
```

上面示例生成的第二页包含以下列表：

![源代码列表示例](/files/d42266578f0cf65ecd66c511c8ac62c2f5b4e437)

## 参考指南

**minted 的颜色样式**

| 名称       | 输出                                                                    | 名称       | 输出                                                                     |
| -------- | --------------------------------------------------------------------- | -------- | ---------------------------------------------------------------------- |
| manni    | ![MintedStyles1.png](/files/3b8643c75f740dbaa12c2807ec0ba85782464933) | fruity   | ![MintedStyles10.png](/files/0cd4bd6b906139eeeee1c79ff0b829f290875ad7) |
| rrt      | ![MintedStyles2.png](/files/2e499e49d8f9bdd75e36f3566dd6bd9dff56eaee) | autumn   | ![MintedStyles11.png](/files/624e6e7ad1bcfb776c9189ff240143df734b1b29) |
| perldoc  | ![MintedStyles3.png](/files/68ade7d6177d05fc3cfad905f50a5e5b7ff1f796) | bw       | ![MintedStyles12.png](/files/ae04e68c522bcd3c0f30d783215e89b1727c1e47) |
| borland  | ![MintedStyles4.png](/files/27e363c7863f068f9a59cb76deca72976d3c6223) | emacs    | ![MintedStyles13.png](/files/e06a26d0dd3ba242ca67a2f6b0c28d858bd842fa) |
| colorful | ![MintedStyles5.png](/files/fee8a2781125ac2fa77778d0cd0b1e29ede27d27) | vim      | ![MintedStyles14.png](/files/97f627903acabf079bedfe8bfa9a655329cfa48b) |
| murphy   | ![MintedStyles6.png](/files/b658b00f28df9105e9c4dca8142c9f870b4891d6) | pastie   | ![MintedStyles15.png](/files/58495e52d0d6be057e81dcf1d6e0c189f06d6a1d) |
| vs       | ![MintedStyles7.png](/files/ba15e23a2da8c87a388d2b302f02f790572e7cba) | friendly | ![MintedStyles16.png](/files/f7cf04c27e4bcb6f1038bfbda8b04c3d0c104326) |
| trac     | ![MintedStyles8.png](/files/f3a88953f4b06da0b8a6aeb5fbd239cfbc33c654) | native   | ![MintedStyles17.png](/files/cf6c74d222b6d67d656c26487d4edaab7bccf8b3) |
| tango    | ![MintedStyles9.png](/files/d5fac10176ecd50f204b4f93072b52a27779f812) | monokai  | ![MintedStyles18.png](/files/d28155542c4b7f47acdc6abbfcf1f6a2b39d2b26) |

某些配色方案需要深色背景才能清晰可读。

**主要支持的编程语言和配置文件**

|          |            |             |           |
| -------- | ---------- | ----------- | --------- |
| cucumber | abap       | ada         | ahk       |
| antlr    | apacheconf | applescript | as        |
| aspectj  | autoit     | asy         | awk       |
| basemake | bash       | bat         | bbcode    |
| befunge  | bmax       | boo         | brainfuck |
| bro      | bugs       | c           | ceylon    |
| cfm      | cfs        | cheetah     | clj       |
| cmake    | cobol      | cl          | console   |
| control  | coq        | cpp         | croc      |
| csharp   | css        | cuda        | cyx       |
| d        | dg         | diff        | django    |
| dpatch   | duel       | dylan       | ec        |
| erb      | evoque     | fan         | fancy     |
| fortran  | gas        | genshi      | glsl      |
| gnuplot  | go         | gosu        | groovy    |
| gst      | haml       | haskell     | hxml      |
| html     | http       | hx          | idl       |
| irc      | ini        | java        | jade      |
| js       | json       | jsp         | kconfig   |
| koka     | lasso      | livescrit   | llvm      |
| logos    | lua        | mako        | mason     |
| matlab   | minid      | monkey      | moon      |
| mxml     | myghty     | mysql       | nasm      |
| newlisp  | newspeak   | numpy       | ocaml     |
| octave   | ooc        | perl        | php       |
| plpgsql  | postgresql | postscript  | pot       |
| prolog   | psql       | puppet      | python    |
| qml      | ragel      | 原始          | ruby      |
| rhtml    | sass       | scheme      | smalltalk |
| sql      | ssp        | tcl         | tea       |
| tex      | 文本         | vala        | vgl       |
| vim      | xml        | xquery      | yaml      |

## 进一步阅读

更多信息请参见：

* [LaTeX 中的长度](/latex/zh-cn/ge-shi-hua/01-lengths-in-latex.md)
* [代码清单](/latex/zh-cn/ge-shi-hua/11-code-listing.md)
* [计数器](/latex/zh-cn/ge-shi-hua/10-counters.md)
* [在 LaTeX 中使用颜色](/latex/zh-cn/ge-shi-hua/13-using-colors-in-latex.md)
* [字体大小、字体族和样式](/latex/zh-cn/zi-ti/01-font-sizes-families-and-styles.md)
* [字体类型](/latex/zh-cn/zi-ti/02-font-typefaces.md)
* [大型项目中的管理](/latex/zh-cn/wen-dang-jie-gou/07-management-in-a-large-project.md)
* [多文件 LaTeX 项目](/latex/zh-cn/wen-dang-jie-gou/08-multi-file-latex-projects.md)
* [目录](/latex/zh-cn/wen-dang-jie-gou/02-table-of-contents.md)
* [单面和双面文档](/latex/zh-cn/ge-shi-hua/08-single-sided-and-double-sided-documents.md)
* [该 **minted** 包文档](https://texdoc.org/serve/minted/0)


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://ayakaleaf-pro.ayaka.space/latex/zh-cn/ge-shi-hua/12-code-highlighting-with-minted.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
