[Tex/LaTex] Hide part and chapter headings

sectioningtitlesec

Is there a way to completely hide the \part and \chapter headings when they are called (but still show them in the toc)? Maybe using titlesec?

Note:

I'm using something like this to capture the chapter headings and reuse them:

\documentclass{book}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}

% Define \chaphead to be used in section headings
\let\oldchapter\chapter
\newcommand\temphead{}
\newcommand\chaphead{}
\renewcommand\chapter[2][\temphead]{%
    \renewcommand\temphead{#2}%
    \renewcommand\chaphead{#2}%
    \oldchapter[#1]{#2}}

\newcommand*\Hide{%

\titleformat{\chapter}[display]
  {}{}{0pt}{}
%\titleclass{\chapter}{straight}

\titleformat{\section}[display]
  {\large} % format
  {\chaphead, section \thesection} % label
  {10pt} %sep
  {} %before
}

\begin{document}

{
\Hide
\chapter{A first chapter}
\section{A first section}
\lipsum
}

\chapter{A second chapter}
\section{A second section}
\lipsum

\end{document}

When activating \titleclass{\chapter}{straight}, it seems \chaphead is not capture anymore.

Best Answer

Indeed, you can use the titlesec package; its explicit option allows you to remove the titles:

\documentclass{book}
\usepackage[explicit]{titlesec}

\newcommand*\Hide{%
\titleformat{\chapter}[display]
  {}{}{0pt}{\Huge}
\titleformat{\part}
  {}{}{0pt}{}
}

\begin{document}
\tableofcontents

{
\Hide
\part{A test part}
\chapter{A test chapter}
\section{Test section}
}

\part{A test part}
\chapter{A test chapter}
\section{Test section}

\end{document}