tags:

views:

210

answers:

3

I am trying to add a table of contents for my LaTex document. The issue I am having is that this line:

 \subsubsection{The expectation of \(X^2\)}

Causes an error in the file that contains the table of contents

\contentsline {subsubsection}{\numberline {1.2.3}
The expectation of \relax $X^2\relax \GenericError { }{
LaTeX Error: Bad math environment delimiter}{
    See the LaTeX manual or LaTeX Companion for explanation.}
{Your command was ignored.\MessageBreak Type I <command> <return> 
to replace it with another command,\MessageBreak or <return> to 
continue without it.}}{5}

Which causes the document not to be generated.

Does anyone have a solution to having maths in sections while still having the table of contents

+6  A: 

You should use the Amsmath inline math delimiter $ instead of \( and \). Thus:

\subsubsection{The expectation of $X^2$}

Note: be sure to remove the currently generated .toc file first, otherwise the error will not go away.

Stephan202
Is there any downside to using $ and $$ as opposed to \( and \[?
Yacoby
`$` is fine, but `\[`...`\]` should always be used over `$$`...`$$`.
Will Robertson
@Will: agreed, of course.
Stephan202
+1  A: 

Could you try again with putting the $ signs around the expression? What error do you get?

bandi
+3  A: 

If you wish to continue using \(...\) as your math delimiters, you can load the (officially supported) fixltx2e package. This is where fixes to LaTeX go that cannot be integrated into the main sources because of the possibility of backwards compatibility problems.

(In short, your problem is that \( and \) by default aren't "robust" and hence can't be used in places like section headings and captions; the fixltx2e package fixes this.)

Will Robertson