# Own Section command working numbered and unnumbered

I use the following command to have section headings with subtitles

\newcommand{\Section}[2]{\section[#1]{#1\\\small »#2«}}


But now I only can have numbered sections because the * doesn't work for my own command. How can I have my command working both ways, with and without the asterisks?

-

This is the standard way to define *-variants:

\makeatletter
\newcommand{\xyz}{\@ifstar\@xyzstar\@xyz}
\newcommand{\@xyzstar}<what to do when there's a *>
\newcommand{\@xyz}<what to do when there's not a *>
\makeatother


In you case it's probably

\makeatletter
\newcommand{\Section}{\@ifstar\@Sectionstar\@Section}
\newcommand{\@Sectionstar}[2]{\section*{#1\\\small »#2«}}
\newcommand{\@Section}[2]{\section[#1]{#1\\\small »#2«}}
\makeatother

-

The xparse package provides an intuitive means for incorporating stars * in commands. Conditioning on whether you are using a starred/unstarred version is done using \IfBooleanTF:

\documentclass{article}
\usepackage[T1]{fontenc}% http://ctan.org/pkg/fontenc
\usepackage{xparse}% http://ctan.org/pkg/xparse
\NewDocumentCommand{\Section}{s m m}{
\IfBooleanTF{#1}%
{\section*{#2\\\small \guillemotright #3\guillemotleft}}% Unnumbered section
{\section[#2]{#2\\\small \guillemotright #3\guillemotleft}}% Numbered section
}
\begin{document}
\Section{First section}{first title}
\Section*{Second section}{second title}
\end{document}


-
 Should this solution be prefered to the one egreg presented? – Sebastian Sep 30 '11 at 19:10 @Sebastian: This might be a user preference. If you're comfortable with @egreg's solution and it is easy for you to modify, then that's that. Otherwise, for me, xparse is easy to read in terms of the code, rather than following a sequence of commands. In my answer, xparse is an additional package that has to be loaded (that comes with additional functionality). In @egreg's answer, manual definition of 2 commands is required (one for the starred * and one for the unstarred version). your choice. – Werner Sep 30 '11 at 19:17

It might be preferable to control section numbering globally. That is, you use non-asterisk sectioning commands everywhere in your document and then you use a command to say which section levels will be numbered.

Here's how to do it. If you place

\setcounter{secnumdepth}{1}


in your preamble, then only the highest level section will be numbered.

-
 I don't want to activate or deactivate it globally but individually with * or without – Sebastian Sep 30 '11 at 9:05