当我在不同的算法环境中调用该函数时,我想使用与算法环境中先前定义的函数相同的字体样式。
下面是一个最小的工作示例。我希望在 英特普当我在第二个函数中调用它时多重。
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\begin{document}
\begin{algorithm}
\caption{Adding two integers $a$ by $b$.}
\begin{algorithmic}[1]
\Require{$a, b$ are integers.}
\Ensure{$c$ an integer.}
\Statex
\Function{IntPlus}{$a, b$}
\State {$c \gets a + b$}
\State \Return {$c$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Distributive property.}
\begin{algorithmic}[1]
\Require{$a, b, c$ are integers.}
\Ensure{$d$ an integer.}
\Statex
\Function{MultPlus}{$a, b, c$}
\State {$g \gets (a \times b) $}
\State {$d \gets \text{IntPlus}(g, c)$ } % I want the font style of IntPlus to be the same when first defined.
\State \Return {$c$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}
答案1
使用\Call{<function name>}{<arguments>}
.\Call
是为\Procedure
调用而设计的,但\Function
s 共享相同的语法。我确信 @egreg 会让我知道这种用法是否不明智。:-)
\documentclass{article}
\usepackage{algorithm,algpseudocode}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\renewcommand{\algorithmicrequire}{\textbf{Input:}}
\renewcommand{\algorithmicensure}{\textbf{Output:}}
\begin{document}
\begin{algorithm}
\caption{Adding two integers $a$ by $b$.}
\begin{algorithmic}[1]
\Require{$a, b$ are integers.}
\Ensure{$c$ an integer.}
\Statex
\Function{IntPlus}{$a, b$}
\State {$c \gets a + b$}
\State \Return {$c$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\begin{algorithm}
\caption{Distritive property.}
\begin{algorithmic}[1]
\Require{$a, b, c$ are integers.}
\Ensure{$d$ an integer.}
\Statex
\Function{MultPlus}{$a, b, c$}
\State {$g \gets (a \times b) $}
\State {$d \gets \Call{IntPlus}{g, c}$ }
\State \Return {$c$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}