This is a second question on this macro definition: Defining a macro with three optional arguments in the form \newmacro{a}{b}[c]{d}[e][f] and \newmacro{a}{b}[c]{d}*[f]
To sum up: I had define a macro \funcdef for writing function declarations inside math-mode. This macro takes three compulsory arguments and three optional arguments, one of them is the notation the function takes. v.g.
\funcdef{f}{a}[A]{B}
means that f is the name of the function whose declaration I am making. a is the sample variable, and A and B are respectively domain and codomain.
It renders as

However if I want to define a multiple-variable domain, I will use it as:
\funcdef{f}{(a,b)}[A\times B]{C}[f(a,b)]
So I get the correct form

I have to use the optional argument to avoid the undesirables

\funcdef{f}{a,b}[A\times B]{C}
\funcdef{f}{(a,b)}[A\times B]{C}
The original idea of this optional parameter was to provide an alternative notation to the standard functional notation, compare, for example:

\funcdef{\times}{(a,b)}[A\times A]{A}[a\times b]
\funcdef{\times}{(a,b)}[A\times A]{A}
The question:
When using standard functional notation on a multiple variable domain, I would like to either add or remove the parenthesis, so that the code is either
\funcdef{f}{a,b}[A\times B]{C}
or
\funcdef{f}{(a,b)}[A\times B]{C}
An I would get the result as

For a minimal functional code of these examples:
\documentclass{article}
\makeatletter
\newcommand\funcdef[2]{\def\func@name{#1}\def\func@var{#2}\begin{array}{r@{\ }c@{\,}c@{\,}l}#1:\func@dom}
\newcommand\func@dom[2][\@empty]{&\ifx#1\@empty#2\else#1\fi&\to\\&\func@var&\mapsto&\func@use}
\newcommand\func@use{\@ifstar\func@use@\func@usei}
\newcommand\func@use@{\func@name(\func@var)\func@def}
\newcommand\func@usei[1][\@empty]{\ifx#1\@empty\func@name(\func@var)\else#1\fi\func@def}
\newcommand\func@def[1][\@empty]{\ifx#1\@empty\relax\else\mathrel{:=}#1\fi\end{array}}
\makeatother
\begin{document}
$$\funcdef{f}{a}[A]{B}$$
$$\funcdef{f}{(a,b)}[A\times B]{C}[f(a,b)]$$
$$\funcdef{f}{a,b}[A\times B]{C}$$
$$\funcdef{f}{(a,b)}[A\times B]{C}$$
$$\funcdef{\times}{(a,b)}[A\times A]{A}[a\times b]$$
$$\funcdef{\times}{(a,b)}[A\times A]{A}$$
\end{document}

pgfkeys: Modify\funcdefmacro to usepgfkeysinstead ofkeyval– Peter Grill Dec 10 '16 at 01:37