1

Suppose I have a command like this: \command{<command>}{<content>}{<value>}. Is there any way to access to the other arguments by having one of them? e.g. something like this:

\getcontent{<value> or <command>}%----> output: <content>
\getcommand{<content> or <value>}%----> output: <command>
\getvalue{<content> or <command>}%----> output: <value>

I also have no Idea how to define \command{<command>}{<content>}{<value>}?

2

Perhaps the following is an option:

enter image description here

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

You'll note that, for convenience, I've left <command> as a string, rather than a control sequence. Since there's no context for the use of <command>, this might not be an issue.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.