I'm quite lost. I can't figure out what I'm doing wrong below.
\documentclass{article}
\usepackage{amsmath,amssymb}
\makeatletter
\newcommand\aermb[1]{\def\ae@i@r{#1}\ae@rmb}
\def\ae@rmb{%%
\typeout{=======> \space\space ae@rmb}%%
\@ifnextchar[%]
{\@ae@rmb}{\@ae@rmb[\height]}}
\def\@ae@rmb[#1]{%%
\typeout{=======> \space @ae@rmb}%%
\def\ae@i@ht{#1}%%
\@@ae@rmb}
\def\@@ae@rmb{%%
\typeout{=======> @@ae@rmb}%%
\@ifnextchar[%]
{\typeout{\space\space\space optional arg}\@@@ae@rmb}
{\typeout{no optional arg}\@@@ae@rmb[\depth]}}
\def\@@@ae@rmb[#1]#2{$#2$}%%
%% \def\@@@ae@rmb[#1]#2{%%
%% \typeout{-->\detokenize\x{\ae@i@r}}%%
%% \typeout{-->\detokenize\x{\ae@i@ht}}%%
%% \typeout{==>\detokenize{#1}}}%%
%% \raisebox{\ae@i@r}[\ae@i@ht][#1]{\mbox{$#2$}}}
\makeatother
\begin{document}
\aermb{\frac{1}{2}}
\end{document}
I get the following error with the above code:
=======> ae@rmb
=======> @ae@rmb
=======> @@ae@rmb
no optional arg
Runaway argument?
! Paragraph ended before \@@@ae@rmb was complete.
<to be read again>
\par
l.30
?
Best Answer
Let's see what happens.
becomes
The macro
\ae@rmb
tests if the next token is[
, skipping spaces. The next token is\par
, due to the empty line. Thus the input stream, at this point, isand now it becomes
The macro
\@ae@rmb
does\def\ae@i@ht{\height}
and the input stream becomesSince the next token is not
[
, this becomesand now you have the problem, because argument
#2
to\@@@ae@rmb
is\par
; this is illegal because the macro is not long. But making it\long
is not the solution, because$\par$
is illegal either.Probably you should define
An easier implementation with
xparse
:Of course you'll have better ideas about what to do with the arguments.