Ich verwende das algorithmicx
Paket und möchte eine Funktion in normalem Text erwähnen. Gibt es eine Möglichkeit, das zu tun, oder muss ich ein Format erstellen, das dem im Algorithmus verwendeten Format ähnelt (alles in Großbuchstaben, Monospace)?
Ähnliches $ ... $
gilt für Mathematik, jedoch für Algorithmen.
Im folgenden Beispiel möchte ich CalculateCovariance
im Text auf verweisen und es im gleichen Stil wie im Algorithmus setzen.
\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}
Antwort1
Im Quellcode deralgpseudocode
Suchen Sie im Paket nach den Definitionen der Makros, die für den Satz von Funktionen und Prozeduren verwendet werden:
\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}%
Sie können sehen, dass ein \textproc
Makro verwendet wird, um den Namen der Funktion/Prozedur zu setzen. Zur Information: Dieses Makro ist (in algpseudocode
) wie folgt definiert:
\algnewcommand\textproc{\textsc}
wo es \algnewcommand
einfach ist \newcommand
mit einem Twist.
Sie sollten jedoch nicht nur \textsc
Funktions-/Prozedurnamen im Haupttext verwenden; \textproc
aus semantischer Sicht ist die Verwendung vorzuziehen.
\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}