다른 명령의 세 인수에 액세스할 수 있는 명령이 있습니까?

다른 명령의 세 인수에 액세스할 수 있는 명령이 있습니까?

다음과 같은 명령이 있다고 가정해 보겠습니다 \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>이는 문제가 되지 않을 수 있습니다.

관련 정보