# Automatic subsection enumeration

For our math lectures I have been hard-coding paragraphs like

\paragraph*{Definition 1.1.1 (foo)}
\paragraph*{Example 1.1.2}
\paragraph*{Proposition 1.1.3}


and I want to create new commands like \definition, \lemma, \theorem, ... which create such paragraphs and handle the numbering. Every command is nested in a subsection, if you need to know.

Any specific idea what would be the best?

-

No no no.

\setcounter{secnumdepth}{5} should make your paragraphs automatically have numbers.

Wait, rereading the question, the ntheorem package allows you to create new environments (not commands) that are automatically numbered and so on. This might be better.

Here's a quick example of how these things would work:

\documentclass{article}
\usepackage{ntheorem}
\newtheorem{theorem}{Theorem}[subsection]
\newtheorem{example}{Example}[subsection]
\begin{document}
\section{Foo}

\subsection{First sub}

\begin{theorem}
Here is a theorem
\end{theorem}
\begin{theorem}
Another theorem
\end{theorem}

\subsection{Second sub}
\begin{example}
An example
\end{example}
\begin{theorem}
A third theorem
\end{theorem}
\end{document}


Declaring a new theorem involves giving the environment a name, then giving the theorem type a name that will display and finally (optinally) tell it where it gets its numbering from. In this case, I have told both theorem and example to get their numbering from the subsection they sit in, but you can change that if you'd like.

-
Does not work for me. Texlipse says No counter '' defined; undefined control sequence. My documentclass is \documentclass[twoside]{scrartcl} – Christian Ivicevic Aug 3 '11 at 16:18
@Christian yes sorry. I got the \setcounter syntax wrong. It should work now. But see the other edit: ntheorem might be a better bet. – Seamus Aug 3 '11 at 16:24
There is one more problem. Using theorem AND example in one sub gives them the same number! But i need incrementing number where it doesn't matter which typ of theorem we have! – Christian Ivicevic Aug 3 '11 at 16:39
@Christian Change \newtheorem{example}{Example}[subsection] to \newtheorem{example}[theorem]{Example}. This tells example to use the theorem counter. – Seamus Aug 3 '11 at 16:55
This means, that i must insert for every new type of paragraph a \newtheorem{paraType}[theorem]{Para Type}, doesn't it? I will adapt this solution because it suits the most! – Christian Ivicevic Aug 3 '11 at 17:00

You could use your own environment, something like the following:

\documentclass{article}

\newcounter{definition}[section] % counter will reset every section
\renewcommand{\thedefinition}{\thesubsection.\arabic{definition}}
\newenvironment{definition}{\refstepcounter{definition}{\bfseries Definition \thedefinition}}{}
\begin{document}

\section{foo}

\subsection{bar}

\begin{definition}\label{testmylabel}
Here is a definition.
\end{definition}

We see in \ref{testmylabel}.
\end{document}


Note that by using \refstepcounter you get the ability to use \label and \ref. If you plan to load any other theorem packages (such as ntheorem), you might like to use a different name for the definition, something like, 'mydefinition', to avoid potential clashes.

Below is a versatile environment you requested

\documentclass{article}
\usepackage{ifthen}

\newcounter{definition}[section]
\renewcommand{\thedefinition}{\thesubsection.\arabic{definition}}
\newenvironment{definition}{\refstepcounter{definition}{\bfseries Definition \thedefinition}}{}

\newenvironment{flexible}[1]{\refstepcounter{definition}%
\ifthenelse{\equal{#1}{def}}%
{%
{\bfseries Definition \thedefinition}%
}%
{%
\ifthenelse{\equal{#1}{prop}}%
{%
{\bfseries Proposition \thedefinition}%
}{}%
}%
}%
{}
\begin{document}

\section{foo}

\subsection{bar}

\begin{definition}\label{testmylabel}
Here is a definition.
\end{definition}

We see in \ref{testmylabel}.

\begin{flexible}{def}
some text
\end{flexible}

\begin{flexible}{prop}
some text
\end{flexible}

\end{document}

-
Due to the style of my script i want to use the paragraph instead of a whole environment (because the name of the definition, lemma, ... with its number is nicely written in bold text and not indented). Any short command for this one? – Christian Ivicevic Aug 3 '11 at 16:27
Furthermore, i've inserted \textsf. Any way to give "some" defs etc. an extended title like in my example in my first post? – Christian Ivicevic Aug 3 '11 at 16:37
I would create a new environment for each of your example, proposition, etc- or would you like just one environment that can change the name for you depending on an input argument? – cmhughes Aug 3 '11 at 16:40
The versatile environment sounds good - let me see what you can offer :D (Keep in mind that have something like "x 1.1.1 (y)" where this y in brackets is optional!) – Christian Ivicevic Aug 3 '11 at 16:41
I have decided to adapt @Seamus solution which is much easier. Still i have to check how to implement the optional title i mentioned! Thanks however! – Christian Ivicevic Aug 3 '11 at 17:04