# What does \secdef do?

The definition of the chapter command in KOMA-class scrbook is:

\newcommand\chapter{\if@openright\cleardoublepage\else\clearpage\fi
\thispagestyle{\chapterpagestyle}%
\global\@topnum\z@
\@afterindentfalse
\secdef\@chapter\@schapter
}


I am wondering what \secdef does.

\secdef is a utility command; if a definition is in the form

\def\foo{<tokens>\secdef\fooA\fooB}


a call of \foo will do

 <tokens>\fooA


while calling \foo* will do

<tokens>\fooB


This is because the definition of \secdef is

\def\secdef#1#2{\@ifstar{#2}{\@dblarg{#1}}}


Therefore, leaving aside the <tokens> that may precede the execution of \secdef, we get

\@ifstar{\fooB}{\@dblarg{\fooA}}


If \foo* is called, \fooB is executed, otherwise TeX does

\@dblarg{\fooA}


and so \fooA must be defined in a special way:

\def\fooA[#1]#2{...}


like \@chapter is. The \@dblarg trick basically examines the next token; if it is [, then we are in a situation such as

\foo[X]{Y}


and LaTeX will do

\fooA[X]{Y}


Otherwise we have

\foo{Y}


and \@dblarg will arrange things in such a way that TeX will eventually see

\fooA[Y]{Y}


Change \foo into \chapter, \fooA into \@chapter and \fooB into \@schapter to better understand the idea.

Oh... I guess I got it on my own: \secdef seems to switch between \chapter and \chapter* call, so you can define in the example above for each case an own macro \@chapter (non-star case) or \@schapter (star-case).