Does he want automatically to have the label created every time he
creates the environment? Or does he just want to put a label in it
manually, after he creates it, so he can cross-reference to it? If the
latter, it's trivial: Just put the label there. You can do this, for
example, with the lemma environment, and LaTeX doesn't care whether it's
user created or what have you. But you have to be sure to use
\refstepcounter not just \stepcounter when incrementing the counter. See
below.

If what he wants is the former, then it can be done, but we need to
consider where we'll get the name of the label. One might have the idea
to do it with a counter, but then if you were to add a new such
environment between the ones you'd already created, you'd break the
cross-references. Another way to do it would be to have the environment
accept an argument (possibly optional) which will then appear as the
name of the label. For example,

\newcounter{formula}
\newenvironment{Formula}[1][xxx]%
    {\refstepcounter{formula}%
        \begin{list}{\theformula}
            {
                \renewcommand{\makelabel}[1]{(##1)\hfil}
                \setlength{\labelwidth}{\leftmargin - \labelsep}
            }
        \item%
        \ifthenelse{\equal{#1}{xxx}}{}{\label{Formula:#1}}%
    }
    {
    \end{list}
    }
%End Formula environment

You can then use the formula environment like this:

/begin{Formula}[sillyformula]
        This is a silly formula.
\end{Formula}

and refer to it via \ref{sillyformula} (or
\prettyref{Formula:sillyformula}, if you wish).

I'm working on getting this to work in LyX.

Richard

Bruce Pourciau wrote:
> Thinking I knew much more LaTeX than I do, a colleague asked me how to
> introduce a label command in a user-defined environment so he could
> cross-reference. I said I'd check with the LaTeX experts on the LyX
> list. What say you?
>
> Bruce

Reply via email to