![다른 명령의 세 인수에 액세스할 수 있는 명령이 있습니까?](https://rvso.com/image/405357/%EB%8B%A4%EB%A5%B8%20%EB%AA%85%EB%A0%B9%EC%9D%98%20%EC%84%B8%20%EC%9D%B8%EC%88%98%EC%97%90%20%EC%95%A1%EC%84%B8%EC%8A%A4%ED%95%A0%20%EC%88%98%20%EC%9E%88%EB%8A%94%20%EB%AA%85%EB%A0%B9%EC%9D%B4%20%EC%9E%88%EC%8A%B5%EB%8B%88%EA%B9%8C%3F.png)
다음과 같은 명령이 있다고 가정해 보겠습니다 \command{<command>}{<content>}{<value>}
. 그 중 하나를 사용하여 다른 인수에 액세스할 수 있는 방법이 있습니까? 예를 들어 다음과 같습니다.
\getcontent{<value> or <command>}%----> output: <content>
\getcommand{<content> or <value>}%----> output: <command>
\getvalue{<content> or <command>}%----> output: <value>
나는 또한 정의하는 방법을 전혀 모릅니다 \command{<command>}{<content>}{<value>}
.
답변1
아마도 다음이 옵션일 수 있습니다.
\documentclass{article}
% \command{<command>}{<content>}{<value>}
\newcommand{\command}[3]{%
\expandafter\def\csname #2@cmd\endcsname{#1}%
\expandafter\def\csname #3@cmd\endcsname{#1}%
\expandafter\def\csname #1@cnt\endcsname{#2}%
\expandafter\def\csname #3@cnt\endcsname{#2}%
\expandafter\def\csname #1@val\endcsname{#3}%
\expandafter\def\csname #2@val\endcsname{#3}%
}
\newcommand{\getcontent}[1]{%
\ifcsname #1@cnt\endcsname
\csname #1@cnt\endcsname
\else
No command/value associated with #1.
\fi
}
\newcommand{\getcommand}[1]{%
\ifcsname #1@cmd\endcsname
\csname #1@cmd\endcsname
\else
No content/value associated with #1.
\fi
}
\newcommand{\getvalue}[1]{%
\ifcsname #1@val\endcsname
\csname #1@val\endcsname
\else
No command/content associated with #1.
\fi
}
\begin{document}
\command{abc}{def}{ghi}
\getcommand{def} % abc
\getcommand{ghi} % abc
\getcontent{abc} % def
\getcontent{ghi} % def
\getvalue{abc} % ghi
\getvalue{def} % ghi
\getcommand{jkl}% No jkl found
\getcontent{jkl}% No jkl found
\getvalue{jkl}% No jkl found
\end{document}
편의상 <command>
제어 시퀀스가 아닌 문자열로 남겨두었습니다. 의 사용에 대한 컨텍스트가 없으므로 <command>
이는 문제가 되지 않을 수 있습니다.