[texhax] Undesired blank space

Rodolfo Medina rodolfo.medina at gmail.com
Fri May 4 22:17:08 CEST 2018


Hi all.

In plain TeX: I wanted to define a command featuring two mandatory arguments
and two optional:

 \mandoptmandopt#1[#2]#3[#4]

, so I fetched from internet the following stuff:

\long\def\@ifnextchar#1#2#3{%
  \let\reserved at d=#1%
  \def\reserved at a{#2}%
  \def\reserved at b{#3}%
  \futurelet\@let at token\@ifnch}
\def\@ifnch{%
  \ifx\@let at token\@sptoken
    \let\reserved at c\@xifnch
  \else
    \ifx\@let at token\reserved at d
      \let\reserved at c\reserved at a
    \else
      \let\reserved at c\reserved at b
    \fi
  \fi
  \reserved at c}
\def\:{\let\@sptoken= } \:  % this makes \@sptoken a space token
\def\:{\@xifnch} \expandafter\def\: {\futurelet\@let at token\@ifnch}

, then did:

\def\mandoptmandopt@@@#1[#2]#3[#4]{#1 #2 #3 #4}

\def\mandoptmandopt@#1#2{%
  \@ifnextchar[%]
    {\mandoptmandopt@@@{#1}[]{#2}}
    {\mandoptmandopt@@@{#1}[]{#2}[]}
}

\def\mandoptmandopt@@#1[#2]#3{%
  \@ifnextchar[%]
    {\mandoptmandopt@@@{#1}[#2]{#3}}
    {\mandoptmandopt@@@{#1}[#2]{#3}[]}
}

then finally:

\def\mandoptmandopt#1{%
  \@ifnextchar[%]
  {\mandoptmandopt@@{#1}}
  {\mandoptmandopt@{#1}}
}

Everything seems all right except that...

\mandoptmandopt{John}[Mary]{Alfred}.

I get an undesired blank space before the period.  Why does this happen, and
how to eliminate it?

Thanks for any help...

Rodolfo



More information about the texhax mailing list