アルゴリズム環境に表示される関数名をどのようにタイプセットすればよいでしょうか?

アルゴリズム環境に表示される関数名をどのようにタイプセットすればよいでしょうか?

パッケージを使用していてalgorithmicx、一般的なテキストで関数について言及したいのですが、それを行う方法はありますか、それともアルゴリズムで使用される形式 (すべて大文字の等幅) を模倣した形式を作成する必要がありますか?

数学の場合と同じようなこと$ ... $をアルゴリズムに対して行います。

以下の例では、CalculateCovarianceテキスト内で を参照し、アルゴリズムと同じスタイルを使用してタイプセットしたいと考えています。

ここに画像の説明を入力してください

\documentclass{article}

\usepackage{algpseudocode}
\usepackage{algorithm}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{algorithm}[t]
\begin{algorithmic}[1]
\Function{IncrementalGN}{${\boldsymbol \theta}, {\bf v}, {\bf r}, {\bf z}_u, \Sigma_u, tol, it_{max}$}
\State $(\hat{\boldsymbol \theta}, \hat{\bf r}) = \Call{Update}{{\boldsymbol \theta}, {\bf v}, {\bf r}, {\bf z}_u, \Sigma_u}$
\State $(\hat\Lambda, \hat{\boldsymbol \eta}, A_u) = \Call{LinearSystem}{\hat{\boldsymbol \theta}\;, \hat{\bf r}}$

\State $changedLP = \textsc{false}$
\For{$it = 0$ \textbf{to} $it_{max}$}
    \State $ {\boldsymbol \delta} = \Call{Solve}{\hat\Lambda, \hat{\boldsymbol \eta}} $
    \If{$norm({\boldsymbol \delta}) < tol$}
        \State ${\bf break}$
    \EndIf
    \State $\hat{\boldsymbol \theta}\;\leftarrow \hat{\boldsymbol \theta} \oplus {\boldsymbol \delta}$
    \State $(\hat\Lambda, \hat{\boldsymbol \eta}) = \Call{LinearSystem}{\hat{\boldsymbol \theta}, \hat{\bf r}}$
    \State $changedLP = \textsc{true}$ % we have just optimized, L needs to be rebuilt    
\EndFor
\Statex \Comment a simple incremental Gauss-Newton solver

\State $ordering = \Call{AMD}{\hat\Lambda}$
\State $\hat R = \Call{Chol}{\hat\Lambda, ordering}$ %%legit\Comment the $\hat R$ factor may be reused, if available in the solver

\If{$changedLP$}
    \State $\hat\Sigma = \Call{CalculateCovariance}{\hat R, ordering}$
\Else
    \State $\hat\Sigma = \Call{UpdateCov}{\Sigma, \hat R, ordering, A_u, {\bf v}}$ % UpdateCovariance was too long
\EndIf
\EndFunction
\end{algorithmic}
\caption{\label{alg:seeifrelin} Covariance Recovery Algorithm Selection}
\end{algorithm}

\end{document}

答え1

ソースコードではalgpseudocodeパッケージでは、関数とプロシージャのタイプセットに使用されるマクロの定義を探します。

\algdef{SE}[PROCEDURE]{Procedure}{EndProcedure}%
   [2]{\algorithmicprocedure\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
   {\algorithmicend\ \algorithmicprocedure}%
\algdef{SE}[FUNCTION]{Function}{EndFunction}%
   [2]{\algorithmicfunction\ \textproc{#1}\ifthenelse{\equal{#2}{}}{}{(#2)}}%
   {\algorithmicend\ \algorithmicfunction}%

\textproc関数/プロシージャの名前をタイプセットするために何らかのマクロが使用されていることがわかります。参考までに、そのマクロはalgpseudocode次のように定義されています( )。

\algnewcommand\textproc{\textsc}

\algnewcommandちょっとした\newcommand工夫が凝らされています。

\textscただし、メインテキストで関数/プロシージャ名をタイプセットするために を使用するだけでは不十分です。\textproc意味的な観点からは、 を使用する方が望ましいです。

ここに画像の説明を入力してください

\documentclass{article}

\usepackage{algpseudocode}
\usepackage{algorithm}

\begin{document}
\begin{algorithm}
  \caption{AIP}\label{AIPal}
  \begin{algorithmic}[1]
    \Function{Bisection}{$f,a,b,\epsilon$}
    \State foo
    \State bar
    \EndFunction
  \end{algorithmic}
\end{algorithm}

The \textproc{Bisection} algorithm shows blah blah blah
\end{document}

関連情報