The mathematical text
${\mathbb Z}[\sqrt{2}]$
works perfectly well within the general text, but I want it as a subsection title. However,
\subsection${\mathbb Z}[\sqrt{2}]$
produces the error message "Missing $ inserted" when I try to typeset.
Further investigation shows that brackets within \subsection titles will typeset when not within math delimiters $ $, but not correctly. For example,
\subsection{This is [rubbish]}
will produce the subsection number, followed by just a close bracket ] (in the same bold font size as the subsection number), and then "This is [rubbish]" in the ordinary text font on the next line.
So is there any way to include brackets [ ] in a \subsection title, either within or outside math delimiters?
Best Answer
Welcome to TeX.SE!
The following works:
Please note that the mandatory argument of section must be given within braces (
{...}
) and that\mathbb
is not a declaration: it must be used as\mathbb{CORRECT}
, not as{\mathbb INCORRECT}
.As you can see, there is nothing special with brackets, as long as you've put the argument within braces, as usual.
Brackets in the optional argument
In case you need brackets inside an optional argument—which is not the case in the question—then there is a trick: you can wrap the whole within braces, like
[{stuff with brackets}]
. For instance:As shown in the screenshot, this uses the title
For TOC [with brackets]
in the table of contents (also in headers when using a class such asbook
), andLong title
in the text. The following would be incorrect:Indeed, in that case:
the optional argument seen by
\section
would beFor TOC [with brackets
(in the absence of braces, the first closing bracket found after the beginning of the optional argument marks the end of this argument);the mandatory argument would be
]
(first brace-balanced token list following the optional argument—only one token here), and{Long title}
would be interpreted as plain text following the section (simple text written inside a useless group).