Como posso digitar nomes de funções conforme aparecem em ambientes algorítmicos?

Como posso digitar nomes de funções conforme aparecem em ambientes algorítmicos?

Estou usando o algorithmicxpacote e gostaria de mencionar uma função em texto comum. Existe uma maneira de fazer isso ou preciso criar um formato que imite aquele usado no algoritmo (todas em maiúsculas monoespaçadas)?

Algo parecido $ ... $com matemática, mas com algoritmos.

No exemplo abaixo, quero fazer referência CalculateCovarianceno texto e quero que ele seja digitado usando o mesmo estilo do algoritmo.

insira a descrição da imagem aqui

\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}

Responder1

No código-fonte doalgpseudocodepacote, procure as definições das macros usadas para funções e procedimentos de composição tipográfica:

\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}%

Você pode ver que alguma \textprocmacro é usada para compor o nome da função/procedimento. Para informação, essa macro é definida (em algpseudocode) como segue,

\algnewcommand\textproc{\textsc}

onde \algnewcommandé simplesmente \newcommandcom um toque diferente.

No entanto, você não deve usar apenas \textscpara digitar nomes de funções/procedimentos no texto principal; usar \textprocé preferível, do ponto de vista semântico.

insira a descrição da imagem aqui

\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}

informação relacionada