I have the following command definition (in the MWE)
\documentclass{article}
\usepackage{amsmath}
\def\hE_#1^#2#3{\hat {\textrm{E}}_{#1}^{#2}\,[#3]}
\begin{document}
\[
\hE_{1}^{2}{3},\qquad
% \hE^{2}{3},\qquad
% \hE_{1}{3},\qquad.
% \hE^{2}_{1}{3},\qquad
% \hE{3}
\]
\end{document}
Which outputs a particular expression with superscripts and subscripts. I want to define other usages of this command that allow for the commented variants. I thought I could do this
\def\hE^#1_#2#3{\hE_{#2}^{#1}{#3}}
\def\hE^#1#2{\hE_{}^{#1}{#2}}
\def\hE_#1#2{\hE_{#1}^{}{#2}}
But that gave me a TeX capacity exceeded
error. Is there a way to do this? I prefer to use internal tex definitions rather than external packages if possible.
xparse
than to try to do this via\def
– daleif Jul 7 '20 at 11:07\newcommand*{\hE}{\hat{\mathrm{E}}}
and fill the rest manually. Much more readable code than what you are trying to define (IMO). But if you really want that you might be interested in thee
argument ofxparse
. – campa Jul 7 '20 at 11:07\,[...]
for every usage of this command. Especially since I might decide to change the spacing later or change the delimiter. IMO, my usage is more readable from the point of view of content-focused writing. – Tohiko Jul 7 '20 at 11:10xparse
. While I prefer to use the standard TeX engine, I am not opposed to packages if they make life much simpler. I willxparse
manual and see what I can do. – Tohiko Jul 7 '20 at 11:12e
type inxparse
can handle^_
options in any order.xparse
will be worth your time. – daleif Jul 7 '20 at 11:17