I recently learned how to make key=value commands with the pgfkeys package. I'm currently trying to define a command, let's call it \commander, with key=value options that can define new commands also with key=value functions. (Something like supercommand or metacommand.) The syntax of \commander is roughly the following:
\commander[color=red,pos=up,invert=false]{\thenewcommand}
Our \thenewcommand is expected to have some (but not all) of the same key=value options of \commander; furthermore, their default values have to be the values called by \commander (or the default values of \commander if they aren't explicitly called). For example, if \thenewcommand is defined as above, then calling:
\thenewcommand[color=blue]
is just the same as calling:
\thenewcommand[color=blue,pos=up,invert=false]
I have made some steps towards defining \commander. Here are its pgfkeys.
\newif\ifcommanderinvert
\pgfkeys{
/commander/.is family, /commander,
% "commander" options
color/.estore in = \commanderColor,
pos/.estore in = \commanderPos,
invert/.is if=commanderinvert,
% Ignore this: It is just for showing that I'm using the .unknown feature
.unknown/.code={\edef\commanderUnk{\commanderUnk,\pgfkeyscurrentname=#1}},%
}
And here is an incomplete definition of \commander:
% (Optional) argument #1 is for the options
% (Non-optional) argument #2 is the name of the new command
% (e.g.: \thenewcommand)
\newcommand{\commander}[2][]{%
% Loading \commander's pgfkeys
\pgfkeys{/commander,%
color=black,%
pos=up,%
invert=false,#1}%
%
% Here goes some code
Code...
%
% Here I define the pgfkeys for \thenewcommand.
% Every appearance of the string "thenewcommand" has to be replaced
% by the actual name of our new command or an abbreviation.
% Else, we risk making conflicting names each time we call \commander.
\newif\ifthenewcommandinvert
\pgfkeys{
/thenewcommand/.is family, /thenewcommand,
% "thenewcommand" options
% Notice I'm not using the "pos" option
color/.estore in = \thenewcommandColor,
invert/.is if=thenewcommandinvert,
}
% Defining \thenewcommand: it only has optional arguments
% Notice that the name of the new command is #2 of \commander
\newcommand{#2}[1][]{%
\pgfkeys{/thenewcommand,%
color=\commanderColor,%
%invert=?,
% How do I pass here the value of /commander invert/?
#1}%
% Here goes some code
\ifthenewcommandinvert%
Code...%
\else%
Code...\fi%
% (By the way, how can I distinctly refer to
% argument #1 of \commander and to argument #1 of \thenewcommand?)
}
With a definition along these lines, if we call \commander as follows:
\commander[color=blue]{\bluecommand}
then calling:
\bluecommand[invert=true]
must be the same as calling:
\bluecommand[color=blue,pos=up,invert=true]
In order to complete this function I have to overcome two challenges:
- What is the best strategy for recursively creating the
pgfkeysfor each new command created with\commander? - How do I the pass value of the
invertkey of\commanderas the default value of theinvertkey of the new command.
I hope someone can give me some hand here. Thanks in advance.
PS: For this command I'm using/requiring the packages graphicx, pgfkeys and tikz and, optionally, the class beamer.

\csname <command name>\endcsnamebut given that you are using pgf keys, why not just using<my new command>/.code={<code>}. This would also allow you to store the other keys on a directory of that name. (graphicxgets loaded bytikz.) – Sep 04 '19 at 14:46<my new command>/.code={<code>}". I suppose since I am new inpgfkeys, I don't have the proper background to understand what you say. (E.g. I don't know where to write that code.) Maybe you can point me to some part of the manual. Thanks in advance. – lfba Sep 06 '19 at 02:59posis for determinig the position,coloris for coloring the image, andinvertis for inverting the colors. I didn't post the whole code because it is somewhat big (specially considering it depends on some other commands previously defined.) – lfba Sep 06 '19 at 03:10\csname <command name>\endcsnameto convert keys to macros, which they internally use. You in a way seem to aim at "inverting" this procedure. Which is why I would suggest just to work with pgf keys, and/.code. – Sep 06 '19 at 03:20