패키지를 사용하고 있는데 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}