![Existe algum comando que permita acessar os três argumentos de outro comando?](https://rvso.com/image/405357/Existe%20algum%20comando%20que%20permita%20acessar%20os%20tr%C3%AAs%20argumentos%20de%20outro%20comando%3F.png)
Suponha que eu tenha um comando como este: \command{<command>}{<content>}{<value>}
. Existe alguma maneira de acessar os outros argumentos tendo um deles? por exemplo, algo assim:
\getcontent{<value> or <command>}%----> output: <content>
\getcommand{<content> or <value>}%----> output: <command>
\getvalue{<content> or <command>}%----> output: <value>
Também não tenho ideia de como definir \command{<command>}{<content>}{<value>}
?
Responder1
Talvez o seguinte seja uma opção:
\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}
Você notará que, por conveniência, deixei <command>
como uma string, em vez de uma sequência de controle. Como não há contexto para o uso de <command>
, isso pode não ser um problema.