[texhax] trying to modify book.cls to automatically add TOC entry for \chapter* gives errors

Susan Dittmar SDittmar at eureca.de
Thu May 8 09:16:34 CEST 2008


Quoting Niall Mansfield (texhax at uit.co.uk):
> - Using book.cls
> - Want to change \chapter*{} in order to:
> 	* add a TOC entry
> 	* set the running heads
>    so that we can use \chapter*{} for Preface, Foreword,
>    Glossary, etc.

I personally do not like such redefinitions. I think it would be better to
define a new command for the new job -- after all, are you sure you will
never need the original starred version? And will you still be able to read
your own code in some years? Especially the second part will be much easier
if you use a new name for the new command.

So what I would do is something like this (untested!):

\usepackage{ifthen}
\newcommand{\chapterNoNumber}[2][]{%
	\chapter*{#2}%
	% allow for the optional argument of chapter*:
	\ifthenelse{\equal{#1}{}}%
		{\addcontentsline{toc}{chapter}{#2}\markboth{#2}{#2}}%
		{\addcontentsline{toc}{chapter}{#1}\markboth{#1}{#1}}%
}

Hope that helps,

	Susan


More information about the texhax mailing list