4
\documentclass{article}
\usepackage{amsmath}
\ExplSyntaxOn
\clist_map_inline:nn { aaa, bbb, ccc }
  { \exp_args:Nco \DeclareMathOperator { #1 } { #1 } }
\ExplSyntaxOff
\begin{document}
$\aaa$
$\bbb$
$\ccc$
\end{document}

I can expand the arguments of \DeclareMathOperator but not \DeclareMathOperator*. How to expand the arguments of \DeclareMathOperator*?

1 Answer 1

5

Notwithstanding that it's common to say that \DeclareMathOperator* is a variant of \DeclareMathOperator (the same for all such commands), the command is just \DeclareMathOperator, which looks ahead to see whether * follows or not. Whether you write

\DeclareMathOperator*{\aaa}{aaa}

or

\DeclareMathOperator *{\aaa}{aaa}

is completely immaterial: there are two tokens before the {.

So in your case you have to jump over two tokens, not just one.

\documentclass{article}
\usepackage{amsmath}

\ExplSyntaxOn

\clist_map_inline:nn { aaa, bbb, ccc }
 {
  \exp_args:NNc \DeclareMathOperator * { #1 } { #1 }
 }

\ExplSyntaxOff

\begin{document}

\[
\aaa_{1\le i\le n} \bbb_{1\le j\le n} \ccc_{1\le k\le n}
\]

\end{document}

enter image description here

You just want \exp_args:Nc for the “no star” part. And o is useless, unless you want to use a macro expanding to a name, but that would be weird.

3
  • Thank you very much. Why are \DeclareMathOperator and * separate? Can you explain what * is? Or provide some links with existing answers. I tried searching but couldn't find any relevant explanation. I know that commands with and without * are logically separated internally. But I always thought there was a command for *, * was a part of the command, for example, \DeclareMathOperator* was a whole. But now it looks like a parameter of \DeclareMathOperator? It's just a relatively special parameter. Just like using s to mark in xparse.
    – Clara
    May 11, 2023 at 1:12
  • @Clara I added some preliminaries
    – egreg
    May 11, 2023 at 9:17
  • Thank you very much, I understand!
    – Clara
    May 11, 2023 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .