ConTeXt 中的类似 Cleveref 的命令

ConTeXt 中的类似 Cleveref 的命令

下列的康特克斯花园,我设置了定理环境,就像下面的 MWE 一样。我想知道 ConTeXt 是否有类似于\crefLaTeX 包的命令cleveref,它会自动在所有参考文献前面添加“推论”、“定理”、“备注”等。最好是这样工作的:如果我后来决定将推论改为备注,参考文献应该自动更新。

附带问题:我如何阻止 ConTeXt 在定理数字后插入这些换行符?

% mode=mkiv

\defineenumeration[remark]
[text=Remark,
location=serried,
width=fit,
right={.~}]
\setupenumerations[remark]
[prefix=yes,
% or prefixsegments=chapter:section
prefixsegments=section] 
\setupnumber[remark][way=bysection]

\defineenumeration[theorem]
[text=Theorem,
location=serried,
width=fit,
counter=remark, % only use counter of remark
style=italic,
right={.~}]
\setupenumerations[theorem]
[prefix=yes,
prefixsegments=section]

\defineenumeration[corollary]
[text=Corollary,
location=serried,
width=fit,
counter=remark, % only use counter of remark
style=italic,
right={.~}]
\setupenumerations[corollary]
[prefix=yes,
prefixsegments=section]

\starttext


\startremark
This is a silly remark.
\stopremark

\starttheorem
This is a deep theorem.
\stoptheorem

\startcorollary[easyresult]
This is an easy corollary.
\stopcorollary

I want \cref[easyresult] to work like \in{Corollary}[easyresult].

\stoptext

显然,它目前无法编译(\cref不是命令),但我想要的是

在此处输入图片描述

答案1

您可以定义\cref如下:

\definereferenceformat[cref][label=*]

然后,对于所有枚举,定义:

\setuplabeltext[corollary={Corollary }, theorem={Theorem }, ]

这是一个简单的例子:

\definereferenceformat[cref][label=*]
\setuplabeltext[corollary={Corollary }]


\defineenumeration
  [remark]
  [
    text=Remark,
    location=serried,
    width=fit,
    right={.~},
    prefix=yes,
    % or prefixsegments=chapter:section
    prefixsegments=section,
  ]

\setupnumber[remark][way=bysection]

\defineenumeration
  [theorem]
  [
    text=Theorem,
    location=serried,
    width=fit,
    counter=remark, % only use counter of remark
    style=italic,
    right={.~},
    prefix=yes,
    prefixsegments=section,
  ]

\defineenumeration
  [corollary]
  [
    text=Corollary,
    location=serried,
    width=fit,
    counter=remark, % only use counter of remark
    style=italic,
    right={.~},
    prefix=yes,
    prefixsegments=section,
  ]

\starttext

\startsection
    [title={First section},
     reference={sec:one}]

In \cref[sec:one], we discuss \unknown

\stopsection

\startremark
This is a silly remark.
\stopremark

\starttheorem
This is a deep theorem.
\stoptheorem

\startcorollary[easyresult]
This is an easy corollary.
\stopcorollary

I want \cref[easyresult] to work like \in{Corollary}[easyresult].

\stoptext

这使

在此处输入图片描述

相关内容