[Tex/LaTex] Undefined control sequence \likechapter

chapterstable of contents

I'm trying to make a ToC that would have numbered chapters and other items which would be numbered but would not be chapters.
To this end I'm trying to use a snippet I've found on the Web:

\makeatletter
     \renewcommand{\@dotsep}{2}
     \newcommand{\l@likechapter}[2]{{\bfseries\@dottedtocline{0}{0pt}{0pt}{#1}{#2}}}
 \makeatother 

\newcommand{\likechapter}[1]
{  
       \likechapterheading{#1}  
       \addcontentsline{toc}{likechapter}
{
\MakeUppercase{#1}
}
}

which upon rendering leads TeXLive to complain with:

! Undefined control sequence.
\likechapter #1-> \likechapterheading 
                                      {#1} \addcontentsline {toc}{likechapte...
l.331  \likechapter {Intro}

What am I doing wrong?

Best Answer

TeX/LaTeX complains about \likechapterheading as being undefined and used in \likechapter, i.e. it tries to expand \likechapter and stumbles over \likechapterheading, being unknown.

The example should be compilable if \providecommand{\likechapterheading}[1]{} is given, i.e. provide it if is not defined already, otherwise ignore the new definition.

Please note, that the ToC entry looks wrong from a typesetting point of view (indentation!)

\documentclass{book}

\providecommand{\likechapterheading}[1]{}


\makeatletter
\renewcommand{\@dotsep}{2}
\newcommand{\l@likechapter}[2]{{\bfseries\@dottedtocline{0}{0pt}{0pt}{#1}{#2}}}
\makeatother 

\newcommand{\likechapter}[1]{%  
  \likechapterheading{#1}  
  \addcontentsline{toc}{likechapter}{%
   \MakeUppercase{#1}%
  }%
}

\begin{document}
\tableofcontents

\chapter{Foo}
\likechapter{Foobar}

\end{document}