I would like to be able to decide how long a resulting character sequence is, in order to properly type set an expression.
Consider an argument like \varepsilon or \mathscr{A} which both result in a single character.
I understand that we could compile a list of feasible macro names and look up the argument in the list.
Is there, however, a more canonical way to learn that the width of the argument is that of exactly one character (in which case I, among other actions, would omit parentheses)?
Consider a macro
\NewDocumentCommand{\fn}{m m}{
{#1} \left( {#2} \right)
}
where #1 represents the name of the function (which is expected to be one or more characters long) and #2 represents the arguments to the function.
The macro is intended to properly typeset expressions like
\fn{f}{\frac{a}{b}}
\fn{\varepsilon}{\frac{a}{b}}
\fn{\mathscr{A}}{\frac{a}{b}}
\fn{Velocity}{vwx}
where the first argument may be of varying width and should remain unmodified if it is exactly one character long (or wide), and have \mathrm applied to if it is longer (or wider).
I intend to properly parse the input for particular tokens like \circle and see thus whether the first argument to \fn is a complex expression. I do understand that we use shorthand notation for function composition, in particular---this should be a corner case.
So to summarize,
I am looking for an approach to count the number of characters (and, likely, dimensional width) of a character sequence as it would be type-set.

\settowidthcommand? (which is usually more meaningful) – David Carlisle Feb 05 '15 at 10:59\nequses two characters, should it count for one or two? Similarly,\notinis composed with two characters, but it's produced in a four pronged array. I'm afraid the problem is not even meaningful (not your fault, of course). – egreg Feb 05 '15 at 11:57unicode-mathrely on the same typesetting rule? – user71833 Feb 05 '15 at 12:08\documentclass{article} \newcounter{numchars} \newcommand\countchars[1]{\setcounter{numchars}{0}\counthelp#1\relax\relax\relax\thenumchars} \def\counthelp#1#2\relax{\ifx#1\relax\else\stepcounter{numchars}\counthelp#2\relax\fi} \begin{document} \countchars{abc} \countchars{a} \countchars{ab} \countchars{} \countchars{ab\ne c} \countchars{abc} \end{document}– Steven B. Segletes Feb 05 '15 at 13:532for\mathscr{A}(maybe because ofunicode-math). I can't explain what a sequence of\relaxor a macro definition with\relaxin the parameter list evaluates to. I'll read up on latex2e and TeX primitives to see whether I can suitably adjust your kindly provided suggestion. I read the implementation ofunicode-math(latex3) and, as a quick fix, will do for now the same thing---an associated list of values. – user71833 Feb 06 '15 at 08:43\relaxis a "do nothing" macro that is unexpandable. In this case, I'm using it as a flag. In this case,\counthelprecursively digests and counts each token of the input until it hits a\relax, which it takes as the end. It finds the\relaxthere in the first place because\countcharsplaced it there at the end of the argument when invoking\counthelp. Indeed, unicode chars are "double-length". FYI, I place 3\relaxes at the end of the input when calling to\counthelp, in case you pass a blank argument, since\counthelpwants to see 3 tokens at a time. – Steven B. Segletes Feb 06 '15 at 10:47\mathbin{\dot\cup}should count as a single character; and what about\newcommand{\foo}{\mathcal{F}(I)}. How can you hope to be able to count the items? – egreg Jun 02 '15 at 22:15