如何在beamer中添加其它语言的描述性源代码【方法一】

来源:互联网 发布:知乎账号 编辑:程序博客网 时间:2024/04/25 01:46

% 必须加下列两句

\documentclass[compress,red]{beamer}

\mode<presentation>


\usepackage{listings}                                 %使用listings包

\begin{document}

% -----------------定义你的代码部分[BEGIN]--------------------%

% \mycode指你的代码名,方便后面直接使用

% emph指定你要强调的关键字

% emphstyle指定强调使用什么颜色

\defverbatim[colored]\mycode{%

\begin{lstlisting}[frame=single, emph={cout,cin}, emphstyle={\color{blue}}]


cout << "Hello world!";

cin >> a;


\end{lstlisting}

}

%-----------------定义你的代码部分[END]--------------------%

\begin{frame}

% 直接调用

\mycode
\end{frame}
\end{document}