I'm working on a macro that when given Hello
will make a chapter named hello, and number it like this: 1 - Hello
, with the 1 -
inside the margins. I also want it to automatically label the chapter by lower-casing the argument and remove all the spaces, creating a \label{chap:hello}
.
So far, I've figured out that to remove the "Chapter" declaration, I must use \chapter*{}
, and I have to append other commands to make sure the chapter is properly numbered and displayed in the TOC.
- How to remove chapter numbering without removing it from tableofcontents
- Chapters without the “chapter” text in content [closed]
- chapter headings without the word "chapter"
What I have now is:
\renewcommand{\chapter}[1]
{%
\chapter*{#1}
\addcontentsline{toc}{chapter}{#1}
\stepcounter{chapter}
}
In a MWE (Minimum working example):
\documentclass{report}
\title{An Example} \author{Nobody}
\renewcommand{\chapter}[1]{%
\chapter*{#1}
\addcontentsline{toc}{chapter}{#1}
\stepcounter{chapter}
}
\begin{document}
\maketitle
\tableofcontents
\chapter{Hello}
\end{document}
(The title is needed for some formatting issues.)
When I test this though, I get the error:
line 10: TeX capacity exceeded, sorry [input stack size=5000] \tableofcontents
I can't seem to find an answer to this anywhere:
It seems to be a very non descriptive error.
Help?
One request: If you give me a macro that does the entire job, please explain how it works. (With documentation if it isn't too much trouble)
Best Answer
You have a little hidden infinite loop. You are redefinying
\chapter
, which calls\chapter*
. These are variants of the same command. Hence TeX builds a huge stack, ending with an overfull message.