# addcontentsline works for section but not for chapter

I'm trying to add a new chapter to both the bookmarks in the PDF as well as the table of contents, without having the chapter appear on the page outside of the TOC. When I try this using \addcontentsline{toc}{chapter}{Chapter Title Here}, it gets an error and won't compile. Here's the code that errors:

\documentclass{article}
\usepackage{hyperref}
\usepackage{titlesec}

\begin{document}

\tableofcontents

\newpage

\phantomsection

\section{First Section}

\end{document}


Interestingly, when I change chapter to section and section to subsection, everything works as I want, except that I want these to be at the chapter and section levels instead:

\documentclass{article}
\usepackage{hyperref}
\usepackage{titlesec}

\begin{document}

\tableofcontents

\newpage

\phantomsection

\subsection{First Section}

\end{document}


Is there a way to fix the top example so that it works like the second example but with the desired levels?

• You are aware there is no chapter support in article? there's no \chatpter command and thus of course no support for formatting chapters in the toc. Please use a document class that supports chapters. – daleif Jul 8 '15 at 5:51
• ... for example, report or book classes. – Sigur Jul 8 '15 at 6:18
• Or, as you load titlesec, you can create \chapter as a new sectional level for the article class, between part and \section. – Bernard Jul 8 '15 at 8:51

The standard article class does not support the use of \chapters. Separation of \sections is typically achieved by using \parts:

\documentclass{article}
\usepackage{titlesec,hyperref}

\begin{document}

\tableofcontents

\newpage

\phantomsection

\section{First Section}

\end{document}


Here is a solution

\documentclass{article}
\usepackage{hyperref}
\usepackage{titlesec}
\makeatletter
\let\l@chapter\l@section
\let\l@section\l@subsection
\let\l@subsection\l@subsubsection
\makeatother
\begin{document}

\tableofcontents

\newpage

\phantomsection