Estoy usando el algorithmicx
paquete y me gustaría mencionar una función en texto común. ¿Hay alguna manera de hacerlo o tengo que crear un formato que imite el utilizado en el algoritmo (todo en mayúsculas, monoespacio)?
Algo parecido $ ... $
ocurre con las matemáticas, pero con los algoritmos.
En el siguiente ejemplo, quiero hacer referencia CalculateCovariance
en el texto y quiero que esté compuesto con el mismo estilo que en el algoritmo.
\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}
Respuesta1
En el código fuente delalgpseudocode
paquete, busque las definiciones de las macros utilizadas para componer funciones y procedimientos:
\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}%
Puede ver que \textproc
se utiliza alguna macro para escribir el nombre de la función/procedimiento. Para obtener información, esa macro se define (en algpseudocode
) de la siguiente manera,
\algnewcommand\textproc{\textsc}
donde \algnewcommand
es simplemente \newcommand
con un giro.
Sin embargo, no debería utilizarlo simplemente \textsc
para componer nombres de funciones/procedimientos en el texto principal; Es preferible usar \textproc
, desde un punto de vista semántico.
\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}