Using loop in newcommand to build longer equal sign

for loopmacrossymbols

Following Is there a wider equal sign? and "For loop" in newcommand, I have come up with the naive command:

\newcount\tmp

\newcommand{\eqlong}[1][2]{% need this to prevent extra vertical space
    =
    \tmp=0
    \loop
        % increment dummy counter
        \advance\tmp by 1
        \joinrel=
        % repeat the loop provided the counter is within specified bound
        \ifnum\tmp<#1
    \repeat
}

Supposedly, \eqlong3 for instance should produce =\joinrel=\joinrel=, i.e. an equal sign about 3 times as long as a normal equal sign. The command as I've written doesn't work, but I'm wondering if someone could fix it.

I know a post I linked above (and also Extendible equals sign) mention the extarrows package, but here I just want a symbol whose length I can control with a parameter I pass.

Best Answer

Your command defines an optional argument that, if given, must be delimited by square brackets. If I understand your request correctly, you also want \eqlong[n] to produce a symbol n-times the length of =. As given, it produces a symbol (n+1)-times the length of =. This is fixed by simply changing \tmp=0 to \tmp=1.

\documentclass{article}

\newcount\tmp
\newcommand{\eqlong}[1][2]{% need this to prevent extra vertical space
    =
    \tmp=1
    \loop
        % increment dummy counter
        \advance\tmp by 1
        \joinrel=
        % repeat the loop provided the counter is within specified bound
        \ifnum\tmp<#1
    \repeat
}

\begin{document}
$a=b$

$a\eqlong b$ %default, twice as long

$a\eqlong[3] b$ %three times as long
\end{document}

enter image description here