# Why won't my subsection appear correctly in the contents?

I need to show one subsubsection title in the main body of the text and another in the contents page. I have been using:

\subsubsection[contents title]{text title}


This had worked really well. Now one of the titles that I need in the contents has square brackets in and so gives me loads of error messages (I assume because the brackets are getting confused).

This is my minimum working example (\subsubsection[$[\text{PtL}^5\text{(ppy)Cl}]^+$]{Title in text} is the line causing the problem):

\documentclass[12pt,a4paper,oneside]{memoir}

\begin{document}
\tableofcontents

\chapter{1}
\subsubsection{Title in text}
\subsubsection[$[\text{PtL}^5\text{(ppy)Cl}]^+$]{Title in text}

\end{document}


Thanks for your help, sorry, I'm still relatively new to LaTeX!!

-
The first ] is mistaken for the end of the optional argument. Use \subsubsection[{$[\text{PtL}^5\text{(ppy)Cl}]^+$}]{Title in text} –  egreg Jun 20 '14 at 14:59
Brilliant, thank you. I'd tried a couple of things but not thought of brackets! –  Gemma Jun 20 '14 at 15:03

You have to set the attribute of your toc-text in curley brackets in order to escape the [] command. I also inserted two commands which allow to show the subsubsection in your toc.

Please note that the command \text{} requires the package mathtools or alike.

% arara: pdflatex
% arara: pdflatex

\documentclass[12pt,a4paper,oneside]{memoir}
\setcounter{tocdepth}{3} % show also subsections in toc
\setcounter{secnumdepth}{3} % show also subsections number in toc
\usepackage{mathtools}

\begin{document}
\tableofcontents

\chapter{chapter}
\section[test]{section}
\subsection{subsection}
\subsubsection{Title in text}
\subsubsection[{$[\text{PtL}^5\text{(ppy)Cl}]^+$}]{Title in text}
\end{document}


-