本文介绍了通过其[名称]引用类似定理的环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用ntheorem排版一组条件.在我的序言中,我有:

  \ theoremstyle {empty}\ newtheorem {条件} {条件} 

当我要排版一个条件时,我写:

  \ begin {条件} [名称]\ label {cnd:nm}foo foo foo\ end {条件} 

名称与条件文本的开头在同一行上以粗体显示,没有数字或任何其他内容.完美.

我现在想做的是通过 \ ref 命令的某些变体来引用条件,\ ref拨打该号码[在其他任何地方都没有显示]\ thref为第n个条件写条件n"\ nameref写入标签的SECTION的名称.建议在此处使用zref解决方案,但似乎并不令人满意毫无用处

有什么简单的方法可以做到这一点吗?(甚至更简单的zref解决方案也将是不错的选择)目前,我刚刚为每个条件定义了 \ newcommand ,并使用它而不是引用条件本身.这在语义上是不透明的,只是令人不满意...

(我给ntheorem的一位作者沃尔夫冈·梅(Wolfgang May)发了电子邮件,他解释说ntheorem内实际上没有办法做到这一点,因为没有记录[name]选项.

(这不是注释中建议的重复,因为我有兴趣通过其可选名称命令引用环境,而不是引用其所在的节/章.)

解决方案

我认为以下内容可能会满足您的要求.

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

然后将其用作

  \ begin {theorem}\ namedlabel {thm:seamus} {Seamus定理}这是西莫斯定理.\ end {th​​eorem}在这里,我参考〜\ ref {thm:seamus}. 

不幸的是,尽管我想您也可以使用普通的 \ label (当然还有不同的键),但是只能按名称引用.

对于 amsthm 环境,您可以使用

  \ 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 

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

解决方案

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

这篇关于通过其[名称]引用类似定理的环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-03 14:47