Usar el mismo estilo de fuente de una función de algoritmo ya definida en otro algoritmo

Usar el mismo estilo de fuente de una función de algoritmo ya definida en otro algoritmo

Quiero usar el mismo estilo de fuente de una función previamente definida en un entorno de algoritmo cuando la llamo en un entorno de algoritmo diferente.

A continuación se muestra un ejemplo de trabajo mínimo. Quiero que se muestre el mismo estilo de fuente para el IntPlusfunción cuando la llamo en la segunda funciónMultiPlus.

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

Respuesta1

Usar \Call{<function name>}{<arguments>}. \Callestá diseñado para \Procedurellamadas, pero \Functioncomparten la misma sintaxis. Estoy seguro de que @egreg me avisará si este uso no es prudente. :-)

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

ingrese la descripción de la imagen aquí

información relacionada