Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Referencing a theorem-like environment by its [name]

Tags:

latex

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

like image 750
Seamus Avatar asked May 04 '10 17:05

Seamus


2 Answers

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
like image 96
Ivan Andrus Avatar answered Sep 21 '22 12:09

Ivan Andrus


nameref doesn't work: it references the title of the SECTION the theorem-like environment appears in.

This is a nameref bug that was already fixed a while ago: http://web.archiveorange.com/archive/v/9uUx5EuqoCGynIvx3om7#lY2MJxvge2oMgOi

Unfortunately some Linux distros like Debian/Ubuntu ship with horribly old versions of the packages (Ubuntu 11.04 still ships TeX Live 2009 although the latest version is TeX Live 2011). If you're using such a Linux distro stop using the Tex Live package in the distro, and install TeX Live directly from here: http://www.tug.org/texlive/ You can then update packages using tlmgr (a really cool tool that doesn't ship with Debian/Ubuntu).

like image 22
Catalin Hritcu Avatar answered Sep 20 '22 12:09

Catalin Hritcu