すでに定義されているアルゴリズム関数と同じフォントスタイルを別のアルゴリズムで使用する

すでに定義されているアルゴリズム関数と同じフォントスタイルを別のアルゴリズムで使用する

アルゴリズム環境で以前に定義された関数を別のアルゴリズム環境で呼び出すときに、その関数と同じフォント スタイルを使用したいと思います。

以下は最小限の動作例です。同じフォントスタイルを表示したいのですが、 インプラス2番目の関数で呼び出す関数マルチプラス

\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が、\Functions は同じ構文を共有します。この使用法が賢明でない場合は、@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}

ここに画像の説明を入力してください

関連情報