Usar o mesmo estilo de fonte de uma função de algoritmo já definida em outro algoritmo

Usar o mesmo estilo de fonte de uma função de algoritmo já definida em outro algoritmo

Quero usar o mesmo estilo de fonte de uma função definida anteriormente em um ambiente de algoritmo quando a chamar em um ambiente de algoritmo diferente.

Abaixo está um exemplo mínimo de trabalho. Quero que o mesmo estilo de fonte seja exibido para o IntPlusfunção quando eu a chamo na segunda funçãoMultiPlus.

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

Responder1

Usar \Call{<function name>}{<arguments>}. \Callfoi projetado para \Procedurechamadas, mas \Functioncompartilha a mesma sintaxe. Tenho certeza de que @egreg me informará se esse uso for imprudente. :-)

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

insira a descrição da imagem aqui

informação relacionada