이미 정의된 알고리즘 함수와 동일한 글꼴 스타일을 다른 알고리즘에서 사용

이미 정의된 알고리즘 함수와 동일한 글꼴 스타일을 다른 알고리즘에서 사용

이전에 정의한 함수를 다른 알고리즘 환경에서 호출할 때 알고리즘 환경에서도 동일한 글꼴 스타일을 사용하고 싶습니다.

다음은 최소한의 작업 예입니다. 동일한 글꼴 스타일을 표시하고 싶습니다. IntPlus두 번째 함수에서 호출할 때 함수멀티플러스.

\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용으로 설계되었지만 동일한 구문을 공유합니다. 이 사용법이 현명하지 못한 경우 @egreg가 나에게 알려줄 것이라고 확신합니다. :-)\Procedure\Function

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

여기에 이미지 설명을 입력하세요

관련 정보