別のコマンドの 3 つの引数にアクセスできるコマンドはありますか?

別のコマンドの 3 つの引数にアクセスできるコマンドはありますか?

次のようなコマンドがあるとします。\command{<command>}{<content>}{<value>}引数の 1 つを指定して他の引数にアクセスする方法はありますか? たとえば、次のようになります。

\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>、これは問題にならない可能性があります。

関連情報