[Tex/LaTex] Redefining the section command, keeping the starred definition

sectioningstarred-version

Currently, I'm working with a document based on the standard book.cls. I redefined the section command (unstarred) to get a more fancy heading. But while doing this, I ran into some walls.

\renewcommand{\section}{\secdef\@section\@ssection}
\newcommand{\@section}[2][?]{...}

Well obviously, I've redefined the unstarred version with \@section, and together with \secdef I fixed bugs in the ToC (strange doublings) and tried to keep the definition of the starred version. To make it short, it doesn't work… here is the output:

! Undefined control sequence.
\reserved@a *->\@ssection

Does anybody know how to handle it? Even \let doesn't help here…

Best Answer

\section is not defined via \secdef. So there is no \@ssection.

This may work:

\makeatletter
\let\latex@section\section
\def\section{\secdef\my@section{\latex@section*}}

\def\my@section[#1]#2{...}

\makeatother

So \section* will call \latex@section*, while \section{title} will call

\my@section[title]{title}

while \section[x]{title} will call

\my@section[x]{title}