用于各种语言代码语法高亮的 LaTeX 包 [英] LaTeX package for syntax highlighting of code in various languages
问题描述
我正在寻找一个对代码进行语法高亮的 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:
egin{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.
推荐答案
你可以使用 listings 包.它支持多种不同的语言,并且有很多用于自定义输出的选项.
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}
egin{document}
egin{lstlisting}[language=html]
<html>
<head>
<title>Hello</title>
</head>
<body>Hello</body>
</html>
end{lstlisting}
end{document}
这篇关于用于各种语言代码语法高亮的 LaTeX 包的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!