Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}
\begin{enumerate}\item[\arabic{exa}.]\linespread{1}\em}
{\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?

share|improve this question
add comment

2 Answers

up vote 6 down vote accepted

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.)

share|improve this answer
    
Thanks! I got it. It should be looking like that: \documentclass{article} \newcounter{exa} %Beispiele mit durchgehender Nummerierung und in italics \newenvironment{example} {\refstepcounter{exa} \begin{enumerate}\item[\arabic{exa}.]\linespread{1}\em} {\end{enumerate}} \begin{document} \begin{example}asdfasdf\end{example} \begin{example}\label{a}asdfasdf\end{example} as \ref{a} \end{document} –  Philip Oct 15 '11 at 12:48
    
@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
    
Thats amazing, thanks again! –  Philip Oct 15 '11 at 13:16
add comment

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.

share|improve this answer
    
The problem is that I am not a great programmer and I guess that a big chunk of customizability requires a high degree of latex knowledge. Anyway, what kind of improvements offer these packeges? –  Philip Oct 17 '11 at 20:27
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.