Edit: About bounty I am happy with the question below and this bounty is for that question. I don't think I can take a better
I searched a little bit about the usage of optional arguments in LaTeX but some things are not yet very clear for me.
When
My question is not specific for commands or for packages but for both.
Sometimes we need to specify one or more optional arguments for a package or for a command. We can find commands like:
\Foo[OptArg1,OptArg2]{Arg1}{Arg2}
and like:
\Foo[OptArg1][OptArg2]{Arg1}{Arg2}
For the first I see one family with two optional arguments separated with comma. For the second I have two families with one optional argument for each one.
I suppose something is different in these two ways, but haven't exactly understand when my command has to use the first and when has to use the second way.
For example let's say we need a command that will use our first optional argument to split the first non-optional argument in parts. Then I prefer the second way because in the first my comma as a separator will not be understood (it is already a separator). But I still could use a command like:
\Foo[separator={,},OptArg2]{Arg1}{Arg2}
to do the same thing.
Of course if I would like to separate the optional arguments of second family my way with \Foo[separator={//}][OptArg2//OptArg3] would be the only (or at least a better) choice because I have tt define the separator before reading the second family arguments.
How
Also, sometimes the command has to behave different if two families are given and deferent if one is given. For example in my above example if the first argument is not given, comma will be used to separate the second families optional arguments. But if is given, then it will be used as a separator and the command will behave different on reading the arguments.
In such situations I think \def is a more general option for writing the command than newcommand because we have more choices while reading the arguments. (\newcommand will break the second arguments before read the first or something like that. Consider also a ']' including in second families arguments...)
My questions are:
- When (standard LaTeX) do I have to use the first way and when the second?
- Is \def the only only or the better way to define our commands in general situations like in situations we don't already know the amount of arguments or in situations like the above with the separator or the ']' I already described?
PS: In the second question consider that I want my command to allow me by reading the next character handle much situations. (For example I want to read characters after the command one by one and stop only if i have found two ordinary arguments or the command \stop etc. Not asking for code of this, just asking if \newcommand can do it -and it is a good choice- or if \def is the only choice)