tags:

views:

134

answers:

2

I am using ntheorem to typeset a set of conditions. In my preamble I have:

\theoremstyle{empty}
\newtheorem{Condtion}{Condtion}

When I want to typeset a condition, I write:

\begin{Condtion}[name]
\label{cnd:nm}
foo foo foo
\end{Condition}

The name appears boldface on the same line as the start of the text of the condition, with no number or anything. Perfect.

What I want to do now is refer to the condition by some variant of the \ref command, \ref calls the number [which is not displayed anywhere else] \thref writes "Condition n" for the nth condition \nameref writes the name of the SECTION of the label. a zref solution was suggested here, but seems unsatisfactory and unwieldly.

Any suggestions on a simple way to do this? (Even a simpler zref solution would be nice) At the moment I've just defined a \newcommand for each condition and use that rather than citing the condition itself. This is semantically opaque and just unsatisfying...

(edit: I emailed one author of ntheorem, Wolfgang May, and he explained that there isn't really a way to do this within ntheorem, since the [name] option isn't recorded.)

(edit: This isn't a dupe as suggested in the comment, since I'm interested in referencing an environment by its optional name command, not referencing the section/chapter it sits in.)

+2  A: 

you may want to check out the nameref package, which is distributed with hyperref. There is a section in the nameref documentation about referencing "stuff" : http://tug.ctan.org/cgi-bin/ctanPackageInformation.py?id=nameref

More on referencing: http://www.tex.ac.uk/cgi-bin/texfaq2html?label=nameref

Mica
nameref doesn't work: it references the title of the SECTION the theorem-like environment appears in. Am checking out other possibilities found in the possible dupes of the comment above.
Seamus
+2  A: 

I think the following may do what you want.

\makeatletter
\def\namedlabel#1#2{\begingroup
   \def\@currentlabel{#2}%
   \label{#1}\endgroup
}
\makeatother

Then you use it as

\begin{theorem}
  \namedlabel{thm:seamus}{Seamus' Theorem}
  Here is Seamus' Theorem.
\end{theorem}

Here I reference~\ref{thm:seamus}.

Unfortunately, it can then only be referenced by name, though I suppose you could use a normal \label as well (with a different key of course).

For the amsthm environments you can use

\makeatletter
\let\@old@begintheorem=\@begintheorem
\def\@begintheorem#1#2[#3]{%
  \gdef\@thm@name{#3}%
  \@old@begintheorem{#1}{#2}[#3]%
}
\def\namedthmlabel#1{\begingroup
   \edef\@currentlabel{\@thm@name}%
   \label{#1}\endgroup
}
\makeatother
Ivan Andrus
That kind of works. But it still isn't ideal. The point is, I want to use the content of the optional argument of the condition as the name I am calling. So I have `\begin{Condition}[Cnd Name]` and I want to have a label that will, when I `ref` it, say "Cnd Name", in bold as it is when the condition is first written out. This way, I have to add an extra argument to the label and make sure it matches "Cnd Name"...
Seamus
That's going to depend on the environment used. You'll probably have to create a wrapper for each such environment, since most of them probably don't save that information anywhere. If all you want is for the amsthm environments, I have added that to the answer.
Ivan Andrus
OK thanks. I'll try this out later. Will a similar thing work for ntheorem?
Seamus
`\newenvironment{condition}[2]{\begin{Condition}[#1] \namedlabel{#2}{#1} }{\end{Condition}}`This environment allows me to do what I want, when coupled with your namedlabel fix! Thanks
Seamus