以下代码给出了一个错误,但我不确定为什么:
\documentclass{beamer}
\usepackage{default}
% typesetting of algorithms
\usepackage[vlined,linesnumbered]{algorithm2e}
\SetArgSty{textnormal}
\SetCommentSty{textnormal}
\begin{document}
\begin{frame}%{ % Implementation of pin() (((
\frametitle{Implementation of \texttt{pin\,()}}
\begin{function}[H]
\Titleofalgo{ \texttt{pin($\mathit{pageno}$)}}
\eIf
{buffer pool already contains $\mathit{pageno}$}
{$\texttt{pinCount\,(\(\mathit{pageno}\))} \leftarrow
\texttt{pinCount\,(\(\mathit{pageno}\))} + 1$ \;
\Return{address of frame holding $\mathit{pageno}$ \;}}
{select a victim frame $v$ using the replacement policy \;
\If{$\texttt{dirty\,(\(v\))}$}
{write $v$ to disk \;}
read page $\mathit{pageno}$ from disk into frame $v$ \;
$\texttt{pinCount\,(\(\mathit{pageno}\))} \leftarrow 1$ \;
$\texttt{dirty\,(\(\mathit{pageno}\))} \leftarrow \text{false}$ \;
\Return{address of frame $v$} \;
}
\end{function}
\end{frame}
\end{document}
我收到的错误信息是
./test.tex:31: Undefined control sequence.
\beamer@doifinframe ...{function}[H] \Titleofalgo
{ \texttt {pin($\mathit {p...
l.31 \end{frame}
我不知道为什么。请问我遗漏了什么?
答案1
注意正确的拼写;它是\TitleOfAlgo
(T、O、A 大写)而不是\Titleofalgo
:
\documentclass{beamer}
\usepackage{default}
% typesetting of algorithms
\usepackage[vlined,linesnumbered]{algorithm2e}
\SetArgSty{textnormal}
\SetCommentSty{textnormal}
\begin{document}
\begin{frame}%{ % Implementation of pin() (((
\frametitle{Implementation of \texttt{pin\,()}}
\begin{function}[H]
\TitleOfAlgo{\texttt{pin($\mathit{pageno}$)}}
\eIf
{buffer pool already contains $\mathit{pageno}$}
{$\texttt{pinCount\,(\(\mathit{pageno}\))} \leftarrow
\texttt{pinCount\,(\(\mathit{pageno}\))} + 1$ \;
\Return{address of frame holding $\mathit{pageno}$ \;}}
{select a victim frame $v$ using the replacement policy \;
\If{$\texttt{dirty\,(\(v\))}$}
{write $v$ to disk \;}
read page $\mathit{pageno}$ from disk into frame $v$ \;
$\texttt{pinCount\,(\(\mathit{pageno}\))} \leftarrow 1$ \;
$\texttt{dirty\,(\(\mathit{pageno}\))} \leftarrow \text{false}$ \;
\Return{address of frame $v$} \;
}
\end{function}
\end{frame}
\end{document}
结果:
我还删除了标题中的虚假空白。
答案2
你忘了 TeX 区分大小写——命令是\TitleOfAlgo
,并且没有default
包——只有default theme
beamer 的:
\documentclass{beamer}
\usetheme{default}
% typesetting of algorithms
\usepackage[vlined,linesnumbered]{algorithm2e}
\SetArgSty{textnormal}
\SetCommentSty{textnormal}
\begin{document}
\begin{frame}%{ % Implementation of pin() (((
\frametitle{Implementation of \texttt{pin\,()}}
\begin{function}[H]
\TitleOfAlgo{ \texttt{pin($\mathit{pageno}$)}}
\eIf
{buffer pool already contains $\mathit{pageno}$}
{$\texttt{pinCount\,(\(\mathit{pageno}\))} \leftarrow
\texttt{pinCount\,(\(\mathit{pageno}\))} + 1$ \;
\Return{address of frame holding $\mathit{pageno}$ \;}}
{select a victim frame $v$ using the replacement policy \;
\If{$\texttt{dirty\,(\(v\))}$}
{write $v$ to disk \;}
read page $\mathit{pageno}$ from disk into frame $v$ \;
$\texttt{pinCount\,(\(\mathit{pageno}\))} \leftarrow 1$ \;
$\texttt{dirty\,(\(\mathit{pageno}\))} \leftarrow \text{false}$ \;
\Return{address of frame $v$} \;
}
\end{function}
\end{frame}
\end{document}