I was reading the following post Different command definitions with and without optional argument on how to implement Different command definitions with and without optional argument. The example mentioned in this link covers the case of one optional argument. Following the same guidelines, I have been trying to do the same with two optional arguments using the following code without any luck:
\makeatletter
\@ifundefined{myDummy}
{
\def\myDummy
{
\@ifnextchar[
{\@WithAtLeastParam}{\@WithoutParam}
}
\def\@WithoutParam#1{x_{#1}}
\def\@WithAtLeastParam[#1]
{
\@ifnextchar[
{\@WithTwoParam}{\@WithOneParam}
}
\def\@WithTwoParam#1[#2]#3{x_{#1\rightarrow #2,#3}}
\def\@WithOneParam#1#2{x_{#1\rightarrow #2}}
}
\makeatother
Could any one please tell me what I have been doing wrong?
xparsesolution, you may want to look into https://tex.stackexchange.com/a/2925/35864 – moewe May 18 '18 at 13:51%(see https://tex.stackexchange.com/q/7453/35864). If it is a math command, the spaces may not be problematic, but it is a good idea to keep this in mind in case one decides to write text mode macros. – moewe May 18 '18 at 13:55\def\@WithoutParam#1{x_{#1}}does not end in a control sequence name that would gobble the space. And it actually has a space after it, but that is irrelevant because it is used in the preamble. If used in the document that becomes apparent, have a look at https://gist.github.com/moewew/bf2c7bda7be3a0bc1c189bde61916b26 – moewe May 18 '18 at 16:22