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

17 篇文章 0 订阅
15 篇文章 4 订阅

先看看效果吧:

相关的测试代码如下,注意测试代码保存为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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值