# addtotoc without a number and without a header on the inserted page

I want to add the bibliography of an external pdf, which I inlcluded by the pdfpages package, to my TOC without giving it a number. I found this solution. My problem is that the <header> option of addtotoc is appearing also on the top of the inserted page!. So, I want to get rid of it.

MWE:(don't forget to change "pages=34-37" and "1512.pdf")

    \documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{fourier}
\usepackage{lipsum}

\usepackage{pdfpages}

\makeatletter
\let\l@chapternonum\l@section %chapter
\newcounter{chapternonum}{}
\renewcommand{\thechapternonum}{} %[1]{\chapter{#1}}
\makeatother
\begin{document}
\setcounter{secnumdepth}{3} %level 3 for \subsubsection

\tableofcontents

\chapter{Supersymmetry bla bla}
\lipsum[1-5]
\section{1st Section}
\lipsum[1-3]
\subsection{1st Subsection}
\lipsum[3-5]
\subsubsection{1st Subsubsection}
\lipsum[3-5]
\section{2nd Section}
\lipsum[1-3]
\subsection{2nd Subsection}
\lipsum[3-5]

\end{document}

• \l@chapternonum is to blame for this. – user31729 Aug 6 '17 at 15:13
• you can try \includepdf[pages=34-37,addtotoc={34,section,10,Bibliographie,lab:refcont1}]{1512.pdf} here 10 can by any number >3=secnumdepth. – touhami Aug 7 '17 at 7:13

The addtotoc option does rely that there is a command \l@chapternonum if the section type is named chapternonum (as in the linked solution by Werner) as well as it tries to add a 'section' title with a macro named \@chapternum, which is not present of course. If this macro is not defined, it adds the header with

\expandafter\@sect\AM@temp
\hskip\z@\par\vskip-\parskip\vskip-\baselineskip\hskip\z@


leaving the heading hanging around in the margin.

The easiest way to solve this is

\newcommand{\@chapternonum}[2][]{\addcontentsline{toc}{section}{#1}},

since the definition within \AM@addtotoc seems to be a little weird.

Here's the relevant code from pdfpages.sty

\newcommand{\AM@addtotoc}{}

\begingroup
\def\@endpart{}\def\partname{}%
\def\autodot{}% KOMA classes
\def\ch@pt@c{\the\AM@toc@title}% memoir classes
\def\thepart{}}%
\edef\AM@temp{{\AM@toc@section}{\AM@toc@level}%
{\z@}{\z@}{\z@}{}[\the\AM@toc@title]{}}%
\edef\AM@tempi{\noexpand\csname @\AM@toc@section\noexpand\endcsname%
[\the\AM@toc@title]{}}%
\@ifundefined{@\AM@toc@section}
{\expandafter\@sect\AM@temp%%%%%% This is the culprit!!!!!
\hskip\z@\par\vskip-\parskip\vskip-\baselineskip\hskip\z@}
{\AM@tempi}%
\xdef\@currentlabel{\@currentlabel}%
\label{\AM@toc@label}%
\endgroup
}


Solution:

 \documentclass[10pt,a4paper]{book}
\usepackage[utf8]{inputenc}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amssymb}
\usepackage{fourier}
\usepackage{lipsum}

\usepackage{pdfpages}

\usepackage{hyperref}

\providecommand{\phantomsection}{}

\makeatletter

\let\l@chapternonum\l@section %chapter
\newcounter{chapternonum}
\renewcommand{\thechapternonum}{} %[1]{\chapter{#1}}
\makeatother

\begin{document}
\setcounter{secnumdepth}{3} %level 3 for \subsubsection

See \ref{lab:refcont1}

\tableofcontents

\chapter{Supersymmetry bla bla}
\lipsum[1-5]
\section{1st Section}
\lipsum[1-3]
\subsection{1st Subsection}
\lipsum[3-5]
\subsubsection{1st Subsubsection}
\lipsum[3-5]
\section{2nd Section}
\lipsum[1-3]
\subsection{2nd Subsection}
\lipsum[3-5]


The code to generate 7.pdf can be found in my answer here
• Thanks a lot for the answer. When I compile your solution, I obtain a number 1.3 before Foo as a section which I don't want – Mohamed Vall Aug 6 '17 at 16:01
• Thanks again, it works as I wanted. As a side remark, hyperref does not go to the right "Foo"'s page, is this relevant to your code? – Mohamed Vall Aug 6 '17 at 16:21
• @LlavDem: It is since \addcontentsline is different when hyperref is included -- see the update in \@chapternonum with \phantomsection and a proper `\@currentlabel – user31729 Aug 6 '17 at 19:18