Most commands use {} to receive parameters. For example $\binom{6}{2}$ typesets the binomial coefficient 6 choose 2. However \sqrt receives a [] parameter as its first parameter. For example $\sqrt[3]{2}$ typesets the cubic root of 2. How are the two parameter delimiters different?
- 31
-
1Welcome to TeX SE! – LaTeXereXeTaL Nov 08 '22 at 05:10
-
3Optional arguments are in square brackets and mandatory arguments are in curley brackets. – Dr. Manuel Kuehner Nov 08 '22 at 05:10
-
This is normally explained in every Latex introduction. – Dr. Manuel Kuehner Nov 08 '22 at 05:11
-
See https://tex.stackexchange.com/questions/11/what-are-good-learning-resources-for-a-latex-beginner for example – Dr. Manuel Kuehner Nov 08 '22 at 05:12
2 Answers
LaTeX commands can have mandatory and optional arguments. Not all commands have both kinds, though. Mandatory arguments are delimited by braces {}, while optional ones by brackets [].
Let's make an example:
\newtheorem{theorem}{Theorem}
defines a new environment called theorem, that will automatically receive a numbering and typeset the text in a special way. You can optionally decide that the numbering of theorems be subordinate to another counter, typically section; in this case you would define the environment by
\newtheorem{theorem}{Theorem}[section]
The brackets [] delimit the optional argument.
In this case the first theorem in section 3 will be numbered 3.1 and the first in section 4 will be numbered 4.1, while in the previous case the numbering will have just one number increasing independently of sections.
Now you want to define also a lemma environment for lemmas. You might do
\newtheorem{lemma}{Lemma}
so lemmas will receive their independent numbering (maybe subordinate to section as before), but a common style is to define lemma so it shares the numbering with theorem (which makes it easier for the reader to find the statement, because Lemma 2 will be found just before Theorem 3, for instance). You can therefore optionally decide to define
\newtheorem{lemma}[theorem]{Theorem}
Note the different positioning of the optional arguments.
The case of \sqrt is a bit unfortunate. In plain TeX, the cube root of 42 is typeset with \root 3 \of {42}, which has no place in LaTeX style syntax. Leslie Lamport, instead of defining a generic command \root with two mandatory arguments, decided to overload \sqrt by adding an optional argument, so the above is realized by \sqrt[3]{42}.
Is there a rule to know how many arguments, mandatory or optional, a command has? No. Manuals describe them.
The \newtheorem command has two mandatory arguments and two optional ones; specifying one excludes specifying the other, for obvious semantic reasons, but this is not at all typical. Consider, for instance,
\makebox{abc def}
\makebox[3cm]{abc def}
\makebox[3cm][s]{abc def}
All three print an indivisible unit containing the text “abc def”, but
the first will occupy the “natural width” of the text and is equivalent to
\mbox{abc def}the second will occupy the stated width, with “abc def” in the middle
the third will occupy the stated width, with “abc” at the left side and ”def” at the right side.
Try
X\makebox{abc def}X\par
X\makebox[3cm]{abc def}X\par
X\makebox[3cm][s]{abc def}\par
to compare. Note that it's not possible, in this case, to leave the optional argument blank: something like
\makebox[][]{abc def}
will flood the terminal with error messages. Only in some cases, [] is the same as not specifying the optional argument:
\usepackage[]{amsmath}
is the same as without []; also \sqrt[]{42} typesets the same as \sqrt{42} (but is not the same, strictly speaking). To the contrary, \makebox[]{abc def} is an error.
Sometimes, not specifying an optional argument will use a default. This is the case of \parbox: stating \parbox{3cm}{...} is the same as \parbox[c]{3cm}{...}. Again, the documentation of the command explains its syntax and the possible default values for optional arguments.
Your example command \binom has two mandatory arguments: you have to tell LaTeX how many elements you choose from and how many elements you want to choose, so the wanted binomial symbol can be typeset. This command has no optional argument.
- 1,121,712
Curly braces {} indicate required arguments. Square brackets [] indicate optional arguments. LaTeX macros can have up to 1 optional argument, and several required arguments. It is necessary to specify the optional argument before the required argument(s). E.g., \sqrt[3]{2} for "the cube root of 2".
The word "optional" in "optional argument" means that the default value is to be used if no optional argument is specified. The default may be empty. E.g., \sqrt{2} signifies that the default value -- which happens to be "blank" -- applies, so that we read the result as "square root of 2". (It's actually perfectly legal to write \sqrt[2]{2}; however, I know of no math text that insists on writing the "ordinary" square root that way...)
- 506,678
- 3,594
-
1
\parboxhas three initial optional argument,\makeboxtwo. There”s also\newtheorem{thm}{Theorem}[section], where the optional argument is trailing.However, strictly speaking, no TeX macro can have optional argument, so your answer might need some different choice of terminology. – egreg Nov 08 '22 at 08:53 -
also the default behaviour is not necessarily the same as the no optional argument case.
\sqrt{x}is not the same as\sqrt[]{x}although they may look similar, just asxis not the same asx^{}– David Carlisle Nov 08 '22 at 09:17