views:

971

answers:

3

I want to add items in a LaTeX-document. Say for example, that I want add hints to the document. I create a command, so I can call something similar to this:

\hint{foocareful}{Be careful with foo!}{foo is a very precious item and can easily be broken. Be careful, especially don't throw foo.}

This will be formatted in special way, to make it easy for the reader to recognize it as a hint. It gets a label, that can be referenced in the example with 'foocareful'.

In the appendix I want to add a list of all hints with references to them. Something like:

\begin{enumerate}
   ...
   \item Be careful with foo! (\pageref{foocareful})
   ...
\end{enumerate}

But naturally I don't want to maintain this list by hand. How can I create automatically such a list?

+2  A: 

Have not done this in years, but I would look at the LaTeX source code for \tableofcontents and \listoffigures. I think the mechanism is generic and you can expand it to include your own lists.

coryan
+9  A: 

One way to do it is to use the float package. I think that, at least, the floatrow package can also do what you want, and may also be more flexible. See you go, though.

Here's an example of something like you're trying to do using float:

\documentclass{article}
\usepackage{float}

\floatstyle{boxed}
\newfloat{hintbox}{H}{hnt}
\floatname{hintbox}{Hint}

\newcommand\hint[2]{%
  \begin{hintbox}
    #2
    \caption{#1}
  \end{hintbox}}

\begin{document}
\section{Hello}

\hint{Be careful with foo!\label{foocareful}}{%
  foo is a very precious item and can easily be broken. 
  Be careful, especially don't throw foo.}

\hint{Don't worry about bar!\label{foocareful}}{%
  Unlike foo, bar is pretty easily to get along with.}

\section{End}

\listof{hintbox}{List of Hints}

\end{document}
Will Robertson
That works as wished. Thank you.
Mnementh
Wow, that's amazing!
Tobin Harris
Very useful package.
Ian Yang
A: 

See: http://www.latex-community.org/forum/viewtopic.php?f=45&t=3504

trivfloat is great!