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?

  • 2
    You're doing it wrong, since you're missing the braces \subsection{...}.
    – Werner
    Jul 15 '19 at 17:15
  • 2
    \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.
    – egreg
    Jul 15 '19 at 19:39

Welcome to TeX.SE!

The following works:




\subsection{This is [rubbish]}


enter image description here

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:



\section[{For TOC [with brackets]}]{Long title}


enter image description here

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}

enter image description here

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.
    – frougon
    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)
    – frougon
    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:


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.