Removing the application of a macro from an expression

\documentclass{article}

\def\firstArgument#1{\zza#1}
\def\macroName#1{\zzb#1}
\def\zza#1#2{#2}
\def\zzb#1#2{\expandafter\zzc\string#1}
\def\zzc#1{}
\begin{document}

\firstArgument{\bf{a}}

\macroName{\bf{a}}
   
\end{document}

enter image description here

note that a is not an argument of \bf here.


As in TeX they are closely tied to the concepts of defining and expanding macros let's avoid the terms "argument" and "parameter" completely and instead use the modified form of Backus/Naur-notation introduced for defining TeX's "parts of speech" in Chapter 24: Summary of Vertical Mode of the TeXbook:

If this is to be applied to the token-pattern

⟨control sequence⟩⟨left brace⟩⟨balanced text⟩⟨right brace⟩

  • ⟨control sequence⟩ neither being an \outer token nor being an active character nor being the "nameless control sequence token" constructable via \csname\endcsname or via a single character of category code 0(escape), i.e., a backslash, at the not-commented end of a line of input while \endlinechar's value is not positive
  • ⟨balanced text⟩ not containing tokens defined in terms of \outer

only, while the \escapechar-parameter has its usual value 92(decimal):

\documentclass{article}

\makeatletter
\newcommand\firstArgument[1]{\@secondoftwo#1}%
\newcommand\macroName[1]{\expandafter\expandafter\expandafter\@gobble\expandafter\string\@firstoftwo#1}%
\makeatother

\begin{document}

\ttfamily\selectfont

\firstArgument{\textbf{a}}
 
\macroName{\textbf{a}}

\end{document}

Tags:

Macros