minted宏包实现在latex中MATLAB等语法高亮

先看看效果吧:

minted宏包实现在latex中MATLAB等语法高亮_第1张图片

相关的测试代码如下,注意测试代码保存为UTF-8格式:

\documentclass[mathserif]{beamer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{ctex}
\usepackage{color}
\usepackage{mdframed}%非常好用的frame框架宏包
\usepackage{tcolorbox}%非常好用的box框架宏包
%===========================================================
\usepackage{minted} %latex中编程语言格式化和语法高亮最好用的宏包之一
%编译器需要添加参数 xelatex -shell-escape
%必须先安装Python Pygments
%%测试如下:
%===========================================================
\begin{document}
\begin{frame}[fragile] %must using [fragile]
\frametitle{csharp代码高亮}
\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}
%===========================================================
\begin{frame}[fragile] %must using [fragile]
\frametitle{MATLAB 代码高亮}
\begin{minted}[mathescape,
	linenos,
	numbersep=5pt,
	gobble=2,
	frame=lines,
	framesep=2mm]{matlab}
    strtitle = 'This is a Unicode π in Matlab'
    s=0;
    for n=1:0.5:10
        s=s+n;
    end
    x=-pi:0.2:pi;
    y=sin(x);
    plot(x,y,'*b--')
\end{minted}
\end{frame}
%===========================================================
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 编译环境:MikTex2.9+Win7+XeLatex.Windows中强烈推荐MikTex,而不是TexLive.

你可能感兴趣的:(Latex,beamer,MATLAB)