To enforce labeling regulations in a document to be edited by ~50 users (imported subdocuments) i have to re-redine the existing document structuring commands part, chapter, etc to follow a predefined labeling scheme (prefixing with hierarchy level to avoid collisions).
As examples speak more than words, here my current definition for chapter (omitting details). Basically, both \chapter and \chapter* are extended with an optional parameter used to define a label which is automatically prefixed by "chap:", reusing the old \chapter command. Additionally, a command for creating references is defined where short vs. long reference text is chosen via the boolean variable \iflongrefs.
\RequirePackage{letltxmacro}
\RequirePackage{xargs}
\newcommand*\section@namelong{Section}%
\newcommand*\section@nameshort{Sect.}%
\newcommand*\section@prefix{sect}%
\LetLtxMacro{\section@old}{\section}%
\renewcommand\section{\@ifstar \section@star \section@nostar}%
\newcommandx*\section@nostar[3][1=,3=]{%
\ifx &%
\section@old{#2}%
\else%
\section@old[#1]{#2}%
\fi%
\ifx &%
\else%
\label{\section@prefix:#3}%
\fi%
}%
\newcommandx*\section@star[2][2=]{%
\section@old*{#1}%
\ifx &%
\else%
\label{\section@prefix:#2}%
\fi%
}%
\newcommand*\sectionref[1]{
\iflongrefs
\section@namelong~\ref{\section@prefix:#1}
\else
\section@nameshort\,\ref{\section@prefix:#1}
\fi
}
Now, I need similar definitions for part, subsection, etc... Of course I can copy & paste this, replacing \section@XXX with \part@XXX etc accordingly. However I'd prefer a more elegant solution, such as a "higher-order command" \extend encapsulating the (re)definitions. A call to \extend for chapters should look like the line given below, and produce all the code seen above.
\extend{section}{Section}{Sect.}{sect}
How can I make this work? Reading through various forum posts I feel \expandafter is the way to go, but I did not understand the examples enough to get it working for me. Any help?