[Tex/LaTex] Remove extra curly braces

argumentsbraces

In this MWE, I demonstrate my problem:

\documentclass{article}
\usepackage{seqsplit}
\newcommand{\dosomething}[1]{\uppercase{#1}}
\newcommand{\dosomethingelse}[1]{\seqsplit{#1}}
\begin{document}
    \dosomething{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}

    % works with extra {...}
    \dosomething{{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}}

    \dosomethingelse{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}

    % does not work with extra {...}
    \dosomethingelse{{looooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong}}
\end{document}

Some commands work with extra curly braces, some don't. Why is that, and how can I make them work by preprocessing my arguments when they do have extra curly braces?

Best Answer

If the argument is not empty and starting spaces can be removed, then the following trick helps:

\makeatletter
\newcommand{\dosomethingelse}[1]{%
  \expandafter\seqsplit\expandafter{\@firstofone#1}%
}
\makeatother

\@firstofone is defined in the LaTeX kernel as:

\long\def\@firstofone#1{#1}

It grabs the first token as argument and outputs it again, thus it does "nothing". But if the argument is not a single token, but a token group in braces, then one level of braces are removed.

Related Question