# Brackets in \subsection titles

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? • You're doing it wrong, since you're missing the braces \subsection{...}. – Werner Jul 15 '19 at 17:15 • \subsection{$\mathbb{Z}[\sqrt{2}]$} will work flawlessly. And \subsection{This is [rubbish]} raises no error at all. If you get errors from them, please add some information about the class you're using. Jul 15 '19 at 19:39 ## 2 Answers Welcome to TeX.SE! The following works: \documentclass{article} \usepackage{amsfonts} \begin{document} \section{$\mathbb{Z}[\sqrt{2}]$} \subsection{This is [rubbish]} \end{document}  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: \documentclass{article} \begin{document} \tableofcontents \section[{For TOC [with brackets]}]{Long title} \end{document}  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 as book), and Long title in the text. The following would be incorrect: \section[For TOC [with brackets]]{Long title}  Indeed, in that case: • the optional argument seen by \section would be For 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). • Thank you, I have copied and pasted this, but get the same result as before. Could this be because I am using a style file supplied by a publisher, and they may have put something in that messes things up? Jul 15 '19 at 17:18 • If you compile this exact code and nothing else, it should work. If it doesn't, I'm afraid it's an installation problem. But since you mention a style file we don't know, there appears to be a very important unknown that is not in your question, and I can't do anything about it, sorry. Jul 15 '19 at 17:20 • Don't you mean {[stuff with brackets]}? Jul 15 '19 at 17:29 • @barbarabeeton I really meant what I wrote: [{stuff with brackets}]. Try the \tableofcontents with \section[{For TOC [with brackets]}]{Long title}. Then remove the pair of braces inside the optional argument and enjoy. :-) (this breaks not only the TOC entry, but also the in-text title in an interesting way, BTW) Jul 15 '19 at 17:35 • That's a clearer example. The one you've given in the answer doesn't take into consideration the fact that the optional heading [in brackets] can cause problems, Newbies often aren't aware that such options exist. Jul 15 '19 at 17:41 I have now finally cured the problem, by putting a \mbox round each bracket: \subsection{$\mathbb{Z}\mbox{[}\sqrt{2}\mbox{]}\$}


But the problem does seem to be specific to the publisher's style file, since I don't need to go to such lengths with any LaTeX code not using this style file.