latex中使用minted宏包格式化编程语言代码和支持语法高亮:
\documentclass{beamer} \usepackage{minted} % -shell-escape \begin{document} \begin{frame}[fragile] %must using [fragile] \begin{minted}[mathescape, linenos, numbersep=5pt, gobble=2, frame=lines, framesep=2mm]{csharp} string title = "This is a Unicode π in the sky" /* Defined as $\pi=\lim_{n\to\infty}\frac{P_n}{d}$ where $P$ is the perimeter of an $n$-sided regular polygon circumscribing a circle of diameter $d$. */ const double pi = 3.1415926535 \end{minted} \end{frame} \end{document}可使用如下命令编译:
xelatex -shell-escape main
pdflatex -shell-escape main这个宏包比较强大,只是需要安装Pygments.如果你使用PythonXY,那么默认已安装.
效果如图所示: