I have been struggling with the following implementation for the last couple of days without being able to find a solution.
I have the following minimal working example:
\documentclass{article}
\usepackage{xkeyval}
\usepackage{amssymb, amsmath}
\usepackage{xparse}
\usepackage{etoolbox}
\makeatletter
\define@cmdkey [Notation] {nom} {A} {}
\define@cmdkey [Notation] {nom} {B} {}
\presetkeys [Notation] {nom} {A={},B={}}{}
\NewDocumentCommand{\nom}{ m O{} }{%
\setkeys[Notation]{nom}{#2}%
\ifdefempty{\cmdNotation@nom@A}{% Descriptor section
\ifdefempty{\cmdNotation@nom@B}{%
e-\def\subscript{}
}{%
f-\def\subscript{\mathtt{\cmdNotation@nom@B}}%
}%
}{%
\ifdefempty{\cmdNotation@nom@B}{%
g-\def\subscript{\mathtt{\cmdNotation@nom@A}}%
}{%
h-\def\subscript{\mathtt{\cmdNotation@nom@A,\cmdNotation@nom@B}}%
}%
}%
\mathcal{#1}_{\subscript}
}%
\makeatother
\makeatletter
\define@cmdkey [Notation] {test} {of} {}
\define@cmdkey [Notation] {test} {wrt} {}
\presetkeys [Notation] {test} {of={},wrt={}}{}
\NewDocumentCommand{\test}{ m O{} }{%
\setkeys[Notation]{test}{#2}%
\nom{#1}[A=\cmdNotation@test@of, B=\cmdNotation@test@wrt]
}%
\makeatother
\begin{document}
\begin{align}
\nom{K}[A=A, B=B]\
\nom{K}[A=A] \
\nom{K}[B=B] \
\nom{K} \
\test{K}[of=A, wrt=B] \
\test{K}[of=A] \
\test{K}[wrt=B] \
\test{K}
\end{align}
\end{document}
Basically when I call \nom inside \test and the optional inputs of test are empty, they are received in \nom as non-empty arguments.
So far, the only solution I have found is the following:
\makeatletter
\define@cmdkey [Notation] {test} {of} {}
\define@cmdkey [Notation] {test} {wrt} {}
\presetkeys [Notation] {test} {of={},wrt={}}{}
\NewDocumentCommand{\test}{ m O{} }{%
\setkeys[Notation]{test}{#2}%
\ifdefempty{\cmdNotation@test@wrt}{%
\ifdefempty{\cmdNotation@test@of}{%
\nom{#1}[]
}{%
\nom{#1}[B=\cmdNotation@test@of]
}%
}{%
\ifdefempty{\cmdNotation@test@of}{%
\nom{#1}[A=\cmdNotation@test@wrt]
}{%
\nom{#1}[A=\cmdNotation@test@wrt, B=\cmdNotation@test@of]
}%
}%
}%
\makeatother
But this is not feasible because in my real implementation \nom and \test have more than 10 inputs and I cannot create a check for each combination of inputs. Furthermore, I have 10 other fuctions similar to \test that internally call \nom.
I hope you can help me. Thanks in advance!
Edit:
As suggested by @Gaussler and @egreg, working with lists in principle works. But I stumbled accross some cases where the passed arguments are not part of a list, or another form of evaluation is needed instead of simple comma separation (see circled in blue). For instance \dot, \hat in the first case are two optional modifiers \mod and \modd, or K and L are part of a text descriptor where both/one/none of the inputs could exist.
In the case of each of the \test_i i = 1:n, I could use different combinations of inputs and pass them to \nom to produce different equations according to my needs.







semantexwhich was the package used in my answer (disclaimer: I am the author). For instance, you can define a key to be equivalent tocommand=\hatand another to be equivalent tocommand=\dot. Without knowing exactly what you want, it’s a bit hard to write an answer, but you can have a look at the manual (see the link above). – Gaussler Sep 13 '21 at 11:43;-)– Gaussler Sep 13 '21 at 12:13