How to keep track of “Examples” in a math document

I'm not sure if this has already been asked, but I have been curious if amsthm also contains support for "examples".

For example, I would like to have something like

\begin{example}
...
\end{example}

that gets auto numbered in the same way as theorems, lemmas, remarks, etc.

Is there any LaTeX package that supports this?

• \newtheorem{example}{Example}, out of the box with LaTeX or with amsthm then. It will define a counter example, is numbered and can be referred to – user31729 Jan 1 '17 at 9:52
• If you prefer some eye-candy, look for mdframed and tcolorbox, both provide theorem environments with colour etc. There are certainly more packages that define theorem - like environments. – user31729 Jan 1 '17 at 10:03

Three short example definitions from amsthm, tcolorbox and mdframed. See the different options and the similarities.

\documentclass{article}

\usepackage{amsthm}
\usepackage[most]{tcolorbox}

\usepackage{mdframed}

\newtheorem{amsexample}{Example from amsthm package}[section] % Defines a counter named amsexample which resets with section

\newtcbtheorem[auto counter,number within=section]{tcbexample}{Example from tcolorbox}{%
colback=white!90!yellow,
colbacktitle={yellow},
coltitle={black}
}{exa}

\newmdtheoremenv[backgroundcolor=cyan]{mdfexample}{Example from mdframed package}[section]

\begin{document}

\section{A section}

\begin{amsexample}
Some example.
\end{amsexample}

\begin{tcbexample}{This is my example title}{first}
Some example.
\end{tcbexample}

\begin{mdfexample}[MDF example title]
Some example.
\end{mdfexample}

See \ref{exa:first} for more eye-candy.

\end{document}