Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

referencing the NAME of an environment

118 views
Skip to first unread message

seamus bradley

unread,
May 5, 2010, 11:19:00 AM5/5/10
to
I'm using ntheorem package and I have a custom environment that is set
up as follows:

\theoremstyle{plain}
\newtheorem{Condition}{Condition}

Say I call it like this:

\begin{Condtion}[Symmetry]
\label{cnd:sym}
foo foo foo
\end{Condition}

Now I want to be able to call some variant of the \ref command, and
have the NAME of the environment (eg "Symmetry").
\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.

zref seems like an awfully complex way of doing something pretty darn
simple. Any answers?

GL

unread,
May 5, 2010, 11:26:17 AM5/5/10
to
Le 05/05/2010 17:19, seamus bradley a �crit :

zref is not "complex", but requires initialization (definition of
properties).

To force \nameref to come with the "correct" name, you have to
update \@currentlabelname at the beginning of your environment:
set
\def\@currentlabelname{Symmetry} for example
before \label.

Regards.

seamus bradley

unread,
May 6, 2010, 8:49:47 AM5/6/10
to
On May 5, 4:26 pm, GL <gouail...@gmail.com> wrote:

I could do that, but then I might as well just do \newcommand{\refsym}
{\textbf{Symmetry}} and use that instead of referencing. The point is
that I want to try and call the optional argument of the environment...

GL

unread,
May 6, 2010, 9:10:07 AM5/6/10
to
Le 06/05/2010 14:49, seamus bradley a �crit :

> On May 5, 4:26 pm, GL<gouail...@gmail.com> wrote:
>> Le 05/05/2010 17:19, seamus bradley a �crit :

>>
>>
>>
>>> I'm using ntheorem package and I have a custom environment that is set
>>> up as follows:
>>
>>> \theoremstyle{plain}
>>> \newtheorem{Condition}{Condition}
>>
>>> Say I call it like this:
>>
>>> \begin{Condtion}[Symmetry]
>>> \label{cnd:sym}
>>> foo foo foo
>>> \end{Condition}
>>
>> \def\@currentlabelname{Symmetry} for example
>> before \label.
>>
>> Regards.
>
> I could do that, but then I might as well just do \newcommand{\refsym}
> {\textbf{Symmetry}} and use that instead of referencing. The point is
> that I want to try and call the optional argument of the environment...

I know, just embed your environment :

\newtheorem{CONDITION}{Condition}
\newenvironment{Condition}[1][]{%
\begin{CONDITION}%
\def\@currentlabelname{#1}%
}{%
\end{CONDITION}%
}

%%%
\begin{Condition}[Symmetry]


\label{cnd:sym}
foo foo foo
\end{Condition}

Not tested, but I think it should work...

seamus bradley

unread,
May 6, 2010, 11:06:03 AM5/6/10
to
On May 6, 2:10 pm, GL <gouail...@gmail.com> wrote:

> Le 06/05/2010 14:49, seamus bradley a écrit :
>
>
>
> > On May 5, 4:26 pm, GL<gouail...@gmail.com>  wrote:

That breaks the naming. The condition itself then becomes named
"Condition 1". But i see what you are trying to do...

Ulrich M. Schwarz

unread,
May 6, 2010, 1:37:23 PM5/6/10
to
On Wed, 05 May 2010 17:19:00 +0200, seamus bradley
<seamusth...@gmail.com> wrote:

> I'm using ntheorem package and I have a custom environment that is set
> up as follows:
>
> \theoremstyle{plain}
> \newtheorem{Condition}{Condition}
>
> Say I call it like this:
>
> \begin{Condtion}[Symmetry]
> \label{cnd:sym}
> foo foo foo
> \end{Condition}
>
> Now I want to be able to call some variant of the \ref command, and
> have the NAME of the environment (eg "Symmetry").

This appears to work and is likely to show up in the next release of
thmtools:

\documentclass{article}

\usepackage{ntheorem,thmtools,nameref,hyperref}

\newtheorem{Condition}{Condition}
\makeatletter
\addtotheorempostheadhook[Condition]{%
\ifcsname NR@gettitle\endcsname% guard in case it's not defined
\expandafter\NR@gettitle\expandafter{\thmt@optarg}%
\fi
}
\makeatother

\begin{document}
\begin{Condition}[Symmetry]


\label{cnd:sym}
foo foo foo
\end{Condition}

See \autoref{cnd:sym} `\nameref{cnd:sym}' on \autopageref{cnd:sym}.

\end{document}


HTH
Ulrich

0 new messages