According to LaTeX standards, the optional arguments of a command come before the mandatory ones. For example:
\command[optional]{mandatory}
Is it recommended to always follow this scheme? Is there any reason to avoid commands with inverted order of arguments? For example:
\command{mandatory}[optional]
A practical example: Supposing to create a class for articles, the author should be able to specify the title (TITLE); an optional short version of the title (SHORT) for page headings, and a note to the title (NOTE), similar a footnote. One could:
- define \title[SHORT]{TITLE} and \titlenote{NOTE},
or - define \title{TITLE}[NOTE] and \shorttitle{SHORT},
The first one is according to usual LaTeX commands, and the asmart and beamer classes; the second is more coherent in relating the note to the title, but seems a little cumbersome. My question is: which one of them should be preferred?
Thanks in advance for your answers!
Best Answer
Even standard latex commands have optional arguments before or after the mandatory arguments, for example
what is true is that the simple interface to defining optional arguments provided by
\newcommand
only lets you define one optional argument and it has to be first.There are disadvantages to having a mandatory argument last if there is any possibility of the following text having a
[
so for example
would take the parenthetic remark as the optional argument so would requrire
or similar constructs to hide the
[
from the argument scanner.Note that that is not an issue for the trailing optional argument of
\usepackage
as you can not have free text in the preamble.