# Enumerated examples

I'm trying to create an example environment, so I've done the very simple

\newtheorem{example}{Example}[section]


which I can then use as

\begin{example}
Example 1
\end{example}


What I would really like to do is (sometimes) have example 12.1(a), 12.1(b), 12.1(c) and then also 12.2,12.3 etc.

Is there a nice simple way to do this?

-

Using your theorem definition for examples as a basis, the following MWE provides a subexample theorem with a counter of its own that links up with the example theorem:

\documentclass{article}
\usepackage{etoolbox}% http://ctan.org/pkg/etoolbox
\newbool{insubexample}
\newtheorem{example}{Example}[section]% Example
\newtheorem{subexample}{Example}[example]% Sub-example
\renewcommand{\thesubexample}{\theexample(\alph{subexample})}%
\AtBeginEnvironment{example}{\global\boolfalse{insubexample}}%
\AtBeginEnvironment{subexample}{%
\ifbool{insubexample}{}{\global\booltrue{insubexample}%
\refstepcounter{example}}%
}%
\begin{document}

\setcounter{section}{11}% Just because...
\section{A section}
\begin{example}Here's an example.\end{example}
\begin{subexample}Here's a sub-example.\end{subexample}
\begin{subexample}Here's a sub-example.\end{subexample}
\begin{subexample}Here's a sub-example.\end{subexample}
\begin{subexample}Here's a sub-example.\end{subexample}
\begin{example}Here's an example.\end{example}
\begin{example}Here's an example.\end{example}
\begin{subexample}Here's a sub-example.\end{subexample}
\begin{subexample}Here's a sub-example.\end{subexample}
\begin{example}Here's an example.\end{example}

\end{document}


The etoolbox package provides support for boolean variables (insubexample in this case) that is used to condition on whether or not you are using the regular example theorem, or the newly defined subexample theorem. Based on this, the regular example theorem counter is either incremented or not.

-
Thank you - that is perfect! –  Qwirk Oct 7 '11 at 8:09