# Cross-referencing to the number of a customized environment with a counter

On the internet I found a possibility to create an example environment that is helpful for linguistic research papers, because it provides all examples with numbers:

\newcounter{exa}
\newenvironment{example}
{\stepcounter{exa}
{\end{enumerate}}


Does anyone know how to add the possibility to reference to this environment? I searched the web, but the suggestions I found didnt meet the problem or I didnt get them.

If there would be a possibility to add a reference the outcome could look like that:

text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text text

(53) EXAMPLE.

text text text text text text text text text text text text text text text text text text text text text text text text In (53) we provide ... text text text text text text text text text text text text text text text text text text text text text text text text

I hope that there is a way to label the example and cross-reference with the number back (or forth) to the EXAMPLE and that the number in the reference is able to adjusts the number as soon as the number of EXAMPLE changes (for example when you delete a preceding example or when you add an example in the preceding text). Is there a way?

-

What you are looking for is the \refstepcounter command. Use this instead of \stepcounter, and the next cross-reference you define with \label will refer to the new value of the counter you've just incremented. (More precisely, \refstepcounter{countername} saves the expanded value of the macro \thecountername.)
@Philip: Yep, that's about right. (You can also customize how the reference looks by redefining \theexa: for instance, for consistency with your list format, you might decide that you'd like to write \renewcommand\theexa{\arabic{exa}.} after definining the counter exa, in order to include the full-stop after the counter value.) –  Niel de Beaudrap Oct 15 '11 at 12:51
Do not be afraid to look at mathematically-oriented packages like amsthm or ntheorem which add to your (perfectly valid) solution a big chunk of customizability.