Sometimes I see [] before {}, such as:
\documentclass[letter,12pt]{article}
Sometimes I see {} before [], such as:
\newcommand{name}[num]{definition}
Which should go first, [] or {} ? Does it matter?
Sometimes I see [] before {}, such as:
\documentclass[letter,12pt]{article}
Sometimes I see {} before [], such as:
\newcommand{name}[num]{definition}
Which should go first, [] or {} ? Does it matter?
The number and position of arguments is part of the command definition, so the order definitely matters.
\documentclass for example has two optional arguments, one before, and one after, the mandatory argument.
\documentclass[letter,12pt]{article}[2020/01/01]
for example would specify that you need a version of the class file no older than next year (this will generate an error that the version is not available, just so you see the effect).
so if you use
\documentclass{article}[letter,12pt]
then you get an error not because the optional argument is last, but because letter,12pt is not a valid date.
\documentclass{article}[2000/01/01]
would work without error.
The basic \newcommand definition form only allows the definition of commands with a single optional argument, which appears first, however that restriction was just to keep the syntax of \newcommand simple, very few standard latex commands that have optional arguments are defined via \newcommand.
For a documented user interface that allows the specification of commands with multiple optional arguments in arbitrary position with respect to the mandatory arguments, see the xparse package.
[]) first followed by all the mandatory parameters (using the{}). But this can be changed (see for example thexparsepacakge). So, for your own macros stick to defining the optional paramters first followed by the mandatory ones, unless there is a very good reason to do otherwise. For exisitng macros, you would need to consult the documentation as to the required order. – Peter Grill Nov 18 '18 at 00:19\@ifnextchar[{\@withoptionalarg}{\@without}but with xparse you won't have to do that. – John Kormylo Nov 18 '18 at 00:36\newcommanddoesn't follow that advice? – cfr Nov 18 '18 at 00:52\newcommandcouldn't be defined so that users of\newcommandused it with standard LaTeX syntax, rather than having to put the optional arguments in the middle of the mandatory ones. – cfr Nov 18 '18 at 22:15