I was doing search about my question (see here for more detail) and found a thread commath and \ifinner. In the thread, there is a macro named \spx , the definition and usage of which are extracted below. Since we can see {^{#1}} in the definition, it seems to be an improved ^. I understand that \if\relax\detokenize{#1} determines whether #1 is empty or not, but I cannot understand how the rest of this \if-clause functions. Additionally, there are some threads where similar \if-clause can be found (e.g. Writing musical pitches, Table without counting ampersands and so on).
What function does this kind of \if-clause have and what is the difference between \spx and plain ^?
% ----- definition of \spx and its usage -----
\newcommand{\spx}[1]{%
\if\relax\detokenize{#1}\relax
\expandafter\@gobble
\else
\expandafter\@firstofone
\fi
{^{#1}}%
}
\newcommand\pd[3][]{\frac{\partial\spx{#1}#2}{\partial#3\spx{#1}}}
\expandafter? Is it undesirable to replace\expandafter\@gobbleby\emptyand\expandafter\@firstofoneby^#1and then to delete{^{#1}}? – Merzong Jun 15 '15 at 09:13x\spx{}=xapparently seems to be the same as that ofx=xand also2\spx{2}=4as2^2=4. – Merzong Jun 15 '15 at 09:39^{#1}is executed inside the\ifwhich means that any code in that argument has to be slightly careful about how it exposes any\fitokens, and also any code inside#1if it looks ahead with\@ifnextcharor\futureletetc would see\firather than the next natural token. Rather than worry about whether that matters in each case most latex code just always uses the\expandafterform. – David Carlisle Jun 15 '15 at 10:58\expandafterform, but I cannot come up with the concrete case that may cause unintended behaviors. – Merzong Jun 15 '15 at 18:50