Использование того же стиля шрифта уже определенной функции алгоритма в другом алгоритме

Использование того же стиля шрифта уже определенной функции алгоритма в другом алгоритме

Я хочу использовать тот же стиль шрифта ранее определенной функции в среде алгоритма при ее вызове в другой среде алгоритма.

Ниже приведен минимальный рабочий пример. Я хочу, чтобы тот же стиль шрифта отображался для ИнтПлюсфункция, когда я вызываю ее во второй функцииМультПлюс.

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

введите описание изображения здесь

Связанный контент