I have been going from thread to thread for a while and I still cannot wrap my head around my problem.
I want to do something that I thought would be basic; declare an "inner product" command that takes two mandatory arguments and print them between brackets. Something like
Now, a simple way to do so is
\NewDocumentCommand\innerproduct{mm}{\left\langle{#1}\,,{#2}\right\rangle}
so I can get the example by doing \innerproduct{a}{b}. But \innerproduct{a,b} would be much nicer, and that is where I am not sure how to proceed. I read about argument processors and I tried
\NewDocumentCommand\privateip{mm}{\left\langle{#1}\,,{#2}\right\rangle}
\NewDocumentCommand\innerproduct{>{\SplitArgument{1}{,}}m}{\privateip#1}
which does the job but seems a bit shaky for me, in the sense that I would rather not have to define two commands each time that I want to accomplish this. Can the two be bundled together?
There are examples around doing all sorts of cool stuff by iterating over lists in a (to me) obscure manner, but I think what I want is much simpler: making sure the two arguments are present, and being able to access them to print them.
EDIT: Thanks for the many answers!
To clarify a little bit, my concern was not about having to define a chain of commands to achieve my results, but the cluttered namespace. And my example was simple, but I hoped I could generalise the answer to other cases.
I did not know about mathtools and I liked that approach, which indeed fills perfectly this use case. I'll also check out semantex in the future. That is where I am at now:
\makeatletter
\DeclarePairedDelimiterXPP\p@ip[3]{}\langle\rangle{\ifblank{#3}{}{_#3}}{#1\,,#2}
\NewDocumentCommand\innerproduct{so>{\SplitArgument{1}{,}}mO{}}{%
\IfBooleanTF{#1}{%
\p@ip*#3{#4}%
}{%
\IfNoValueTF{#2}{\p@ip#3{#4}}{\p@ip[#2]#3{#4}}%
}%
}
\makeatother
I do not how I missed it, but I used some @ magic to get on with my clutter problem.
The optional star or size argument can be used normally, I get the target behaviour \innerproduct{a,b}, and I added an optional suffix that I need to distinguish operators (that will demand some spacing tuning, but that is another problem). Hooray!
$\innerproduct[\Big]{\frac12,y}$
$\innerproduct[\Bigg]{\frac12,y}$
$\innerproduct*{\frac12,y}$
$\innerproduct*{\frac12,y}[A]$
$\innerproduct{\frac12,y}[A]$
$\innerproduct[\big]{\frac12,y}[A]$
Still keen on any comments.






