Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maths in LaTex table of contents

Tags:

math

latex

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

like image 483
Yacoby Avatar asked Nov 15 '09 22:11

Yacoby


People also ask

How do you put maths in LaTeX mode?

There are a few ways to enter math mode, however the most common is $.... $, where the text within the dollar signs is in the math mode environment. You have already been using math mode unknowingly by using the \begin{equation} and \end{equation} commands.

How do you show math in overleaf?

Display math mode Use one of these constructions to typeset maths in display mode: \[...\] \begin{displaymath}...\end{displaymath} \begin{equation}...\end{equation}


1 Answers

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.

like image 181
Stephan202 Avatar answered Oct 30 '22 00:10

Stephan202