在算法中使用 \vv

在算法中使用 \vv

对于下面的文档,我在环境\vv中使用时出现如下所示的错误algorithmic。如果我更改为\vec,则不会出现错误。我该怎么做才能继续使用\vv

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}  
\usepackage{esvect}
\begin{document}
    $\vv{p}$
        \begin{algorithmic}
            \Procedure{$Eval$}{$rm$,$\vv{p}$}

            \EndProcedure
        \end{algorithmic}
\end{document}

错误如下:

Undefined control sequence. \Procedure{$Eval$}{$rm$,$\vv{p}$}
Argument of \@firstoftwo has an extra }. \Procedure{$Eval$}{$rm$,$\vv{p}$}
Paragraph ended before \@firstoftwo was complete. \Procedure{$Eval$}{$rm$,$\vv{p}$}
Argument of \mathpalette has an extra }. \Procedure{$Eval$}{$rm$,$\vv{p}$}
Paragraph ended before \mathpalette was complete. \Procedure{$Eval$}{$rm$,$\vv{p}$}
Incomplete \iffalse; all text was ignored after line 9.

答案1

真正的错误信息是

! Undefined control sequence.
\reserved@a ->\@nil 

l.8             \Procedure{$Eval$}{$rm$,$\vv{p}$}

问题是\Procedure有“移动参数”,所以\vv必须保护诸如这样的脆弱命令。要么使用

\Procedure{$Eval$}{$rm$,$\protect\vv{p}$}

或者一开始就让命令变得强大:

\documentclass{article}
\usepackage{algorithm}
\usepackage{algpseudocode}
\usepackage{esvect}

\MakeRobust{\vv}

\begin{document}

$\vv{p}$

\begin{algorithmic}
  \Procedure{$Eval$}{$rm$,$\vv{p}$}

  \EndProcedure
\end{algorithmic}

\end{document}

在此处输入图片描述

我认为你应该使用

\Procedure{$\mathit{Eval}$}{$\mathit{rm},\vv{p}$}

以获得均匀的间距。

相关内容