You are correct that it is not always easy to remember which is which1. There is no real reason behind it - except that an optional argument is by convention and is -- by now become
an unwritten rule -- made up of square brackets. So if you know the argument is optional, in
99% of the cases you will be safe to use a square bracket. It is also the first argument, as it makes sense to look ahead to see, if there is an optional argument first.
Sometimes confusion arises with environment type of commands such as:
\begin{figure}[htbp]
The mnemonic to use here is that the command is really
\figure[htbp]
which again follows the rule that the []
represent an optional argument.
Patience and texdoc package name
are required for some complicated patterns such as
the wrapfig
package commands and the like, where you end with commands such as:
\begin{wrapfigure}[6]{r}[..]{12cm}
but even again, here the pattern is [optional]{argument}
.
The curly bracket convention, has its roots in early computer languages where they were used to denote begin and end. In Pascal, which was the language that Knuth used to program TeX, curlies denoted the arguments of function definitions and it probably made sense to use the same for TeX.
The original TeX did not have any build-in mechanisms for optional arguments, as we know them today. A macro was and is still defined as:
\def\name#1#2{#1 #2}
It also makes sense to use curlies for denoting argument calls, as you really telling the parser, begin reading this argument until you encounter the end. One could argue that using normal brackets would be better and a macro like the one above would follow more modern paradigms if written as:
\name(...)(...)
As a matter of fact it is very easy to write TeX macros to accept input in such a way. However, if you consider that we are dealing mostly with textual input, normal brackets are common in such text, which would start imposing on us the need to delineate strings with inverted commas or some other convention.
The LaTeX Team build up more complicated top functions to make life easier and especially since, the key-value concept was introduced a more standardized syntax styling became possible.
But overall I agree with you that overall (all)TeX does not use a lot of computer memory, but it does tax our own.
- I have the same problem with markdown's links.
\somefunction{aaa}[bbb]
are very rare : usually optional come first, mandatory after. Note that you can format sourcecode by enclosing it in ` (backticks).\begin{figure}[float-specifiers]
. Maybe that's why I think my intuition's off -- the pattern I see most often is not representative?\begin
can be technically seen as a macro, but it is definitely a particular case. In that case, thefloat-specifiers
are optional arguments to thefigure
environment, rather than to the\begin
"macro". And by the way, this specific placement of the optional after the mandatory leads to erratic behavior, such as the bugs ofarray
for example if the first cell starts with a[
.