问题描述
我正在寻找一个LaTeX软件包,该软件包对代码进行语法高亮显示.例如,现在我使用逐字记录块编写代码:
I am looking for a LaTeX package that does syntax highlighting on code. For example, right now I use the verbatim block to write code:
\begin{verbatim}
<html>
<head>
<title>Hello</title>
</head>
<body>Hello</body>
</html>
\end{verbatim}
这可以很好地在我的文档上显示代码.但是,假设我想像IDE在输出文档中那样突出显示HTML标记? 是否有可以帮助您的软件包?
And this works fine to display the code on my document. But, suppose I wanted to highlight the HTML markup the way an IDE would in the output document? Is there a package that could help?
我想对各种语言(例如Java,C#,HTML,CSS等)执行相同的操作.
I would like to do the same for various languages such as Java, C#, HTML, CSS and so on.
推荐答案
您可以使用列表包.它支持许多不同的语言,并且有很多用于自定义输出的选项.
You can use the listings package. It supports many different languages and there are lots of options for customising the output.
\documentclass{article}
\usepackage{listings}
\begin{document}
\begin{lstlisting}[language=html]
<html>
<head>
<title>Hello</title>
</head>
<body>Hello</body>
</html>
\end{lstlisting}
\end{document}
这篇关于LaTeX软件包,用于以多种语言突出显示代码的语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!