# Customized 'list of…'

I am using the covington package to manage my examples. I would now like to create my list of examples, right after my list of figures and tables. Is there any way to do it?

example of an example:

\begin{examples}
\item blabla
\end{examples}

-
Have a look at the answers here and see if they work for you. I don't know whether using covington would change anything. –  Scott H. Nov 29 '12 at 7:40
Welcome to TeX.sx! The examples in the covington package are numbered using the equation counter, so this Table of Equations question may help you. –  Andrew Swann Nov 29 '12 at 7:47
What should be typeset in the list of examples in the case you mention? –  egreg Nov 29 '12 at 7:49

The example environment provided by the covington package is a list environment with the individual items labelled via the equation counter. This does not fit too well with standard solutions to this type of problem: e.g. thmtools works for theorem like environments instead.

The code below uses the tocloft package. However, the standard set-up involves using a new counter. I have chosen to change the counter used by the example environment, so these are now numbered differently from equations.

\documentclass{article}

\usepackage{covington,tocloft}

\newcommand{\listofexamples}{List of Examples}
\newlistof{example}{lex}{\listofexamples}
\theexample}}}

\newcounter{examplesave}

\renewenvironment{examples}%
{%
\begin{list}{(\theexample\lentry)}%
{%
\setcounter{examplesave}{\arabic{example}}%
\usecounter{example}%
\setcounter{example}{\arabic{examplesave}}%
\setlength{\listparindent}{0pt}%
\def\makelabel##1{##1\hfil}%
}%
\raggedright}%
{\end{list}}

\renewcommand{\exampleno}{\refstepcounter{example}\theexample}

\begin{document}

\listofexample

\begin{examples}
\item An example
\item Another example
\end{examples}

\clearpage

\begin{example}
Last example
\end{example}

\end{document}


The above code sets up the list of examples mechanism in the standard tocloft way and then provides a new version of the example environment with the equation counter replaced by an example counter at each instance. The labelling command is extended to add an appropriate line to the table of examples via the \lentry command. I have also included a redfinition of the only other command in the covington package that uses the equation counter for examples.

Finally, remember to run latex on such a file twice to get the correct numbering in the list of examples.

-

Here's a solution that uses the \@starttoc to start a new file \jobname.exs which stores contentsline information about the example and examples environment. I've borrowed some ideas from Creating list of for \newtheoremstyle

I've used the etoolbox to append \item with the crucial part about \addcontentsline, but only if it is inside an example or examples environment (we wouldn't want it to happen inside of another list such as enumerate, itemize, etc) as both are set up in terms of a list environment; I've set up a bool to check if we're inside example or examples.

\documentclass{article}
\usepackage{covington}
\usepackage{etoolbox}
\usepackage{lipsum}% just to generate text

% this sets up \jobname.exs which will store the
% contentslines added on each example or examples
\makeatletter
\newcommand\listexamplename{List of Examples}
\newcommand\listofexamples{%
\section*{\listexamplename}\@starttoc{exs}}
\makeatother

% Note that the example and examples environment are defined
% in terms of a list; we test if we're inside either environment
% by setting up a boolean; note that this boolean will only
% be local to the environment, and will be false outside of it
% so there's no need to make it false again
\newbool{inexamples}
\appto\examples{\setbool{inexamples}{true}}

% This adds a contents line to \jobname.exs
%
% this does it for each \item inside of an examples environment
\appto\item{%
\ifbool{inexamples}{%
% if the \item is inside \begin{examples}, then
% update the example list
}%
{%
% otherwise do nothing
}%
}

\begin{document}

\listofexamples

$$y=mx+c$$

\begin{examples}
\item first
\item second
\end{examples}

\begin{example}
\lipsum[2]
\end{example}

\begin{example}
\lipsum[2]
\end{example}

\begin{example}
\lipsum[2]
\end{example}

\end{document}

-