\begin{frame}[fragile]
% verbatim-like environment.
\end{frame}

## 抄录环境是怎么实现的？

\begingroup
\catcode |=0 \catcode [= 1 \catcode]=2
\catcode \{=12 \catcode \}=12 \catcode\\=12
|gdef|@xverbatim#1\end{verbatim}[#1|end[verbatim]]
|gdef|@sxverbatim#1\end{verbatim*}[#1|end[verbatim*]]
|endgroup

## 脆弱命令是怎么回事？

1. 编号自增 1

2. 输出章节标题

3. 处理目录（和 PDF 书签）

4. 做页眉的章节标记

1. TeX 在写文件时，会将宏——此处特别注意 \section{} 参数中可能包含的宏——完全展开；

2. 但完全展开写入文件之后，又要重新为 TeX 所读入，这时可能造成奇怪的错误。

## 这和 frame 有什么关系？

If you wish to use a {verbatim} environment in a frame, you have to add the option [fragile] to the {frame} environment. In this case, [...] and the \end{frame} must be alone on a single line. Using this option will cause the frame contents to be written to an external file and the read back.

If a frame contains fragile text, different internal mechanisms are used to typeset the frame to ensure that inside the frame the character codes can be reset. The price of switching to another internal mechanism is that either you cannot use overlays or an external file needs to be written and read back (which is not always desirable).

In detail, the following happens when this option is given for normal (pdf)LaTeX: The contents of the frame is scanned and then written to a special file named ⟨jobname⟩.vrb or, if a label has been assigned to the frame, ⟨jobname⟩.⟨current frame number⟩.vrb. Then, the frame is started anew and the content of this file is read back. Since, upon reading of a file, the character codes can be modified, this allows you to use both verbatim text and overlays.

To determine the end of the frame, the following rule is used: The first occurence of a single line containing exactly \end{⟨frame environment name⟩} ends the frame. The ⟨environment name⟩ is normally frame, but it can be changed using the environmentoption. This special rule is needed since the frame contents is, after all, not interpreted when it is gathered.