为什么 \zifrefundefined 在 tcolorbox 引用上失败?

为什么 \zifrefundefined 在 tcolorbox 引用上失败?

鉴于此 MWE

\documentclass[
  a4paper,
  11pt,
  parskip=half
]{scrbook}

\usepackage[nospace]{varioref}
\usepackage[pdfencoding=unicode, psdextra]{hyperref}
\usepackage{cleveref}
\usepackage{zref}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\DeclareNewTOC[
  category=float,
  float,% declares floating environment eq
  floatpos=ht,
  nonfloat,% declares non-floating environment eq-
  listname={Some Items},
  name=TM,
  tocentrystyle=tocline,
  tocentrylevel:=table,
  tocentryindent:=table,
  tocentrynumwidth:=table,
  type=MySpecialEnvFloat,
]{ltm}

\newtcolorbox[
    auto counter,
    crefname={TM}{TMs}]{MyBox}[2][]{
    title={TM\,\thetcbcounter: #2},
    #1}

    
\begin{document}

\newcounter{MySpecialEnvCounter}
\makeatletter
\newcommand{\MySpecialEnv}[4]{%
    \refstepcounter{MySpecialEnvCounter}%

    \begin{MyBox}[label={#1}]{#2}
        \addcontentsline{ltm}{section}{TM\,\theMySpecialEnvCounter: #2}
        Some text
        \tcblower
        #4
    \end{MyBox}
}%  

\listofMySpecialEnvFloats

\MySpecialEnv{test-id}{Something that looks like a summary}{-}{
    sdjoajhsja sijaoihs siahskah
}

\MySpecialEnv{test-id-2}{Yet another summary}{-}{
    asjajsaj sakjskaj sjkajs
}

\subsection{varioref test}

Varioref test: Reference to \vref{test-id} and \vref{test-id-2}

Pageref test: \vpageref{test-id-2}

\subsection{Cref Test}

\cref{test-id}  \cpageref{test-id}

\subsection{zifrefundefined}

\zifrefundefined{test-id}{\nfss@text{\reset@font\bfseries??}}{GOOD}

\end{document}

我屈服了

错误的结果

如何修复此问题?

答案1

zref使用与标准系统不同的引用系统,因此您无法设置\label(这是label=您的选项tcolorbox所做的)并期望zref找到它。但是,由于系统是独立的,因此您可以使用模块提供的zref具有相同名称的标签来创建它。\zlabelzrefuser

\documentclass[
  a4paper,
  11pt,
  parskip=half
]{scrbook}

\usepackage[nospace]{varioref}
\usepackage[pdfencoding=unicode, psdextra]{hyperref}
\usepackage{cleveref}
\usepackage[user]{zref}
\usepackage{tcolorbox}
\tcbuselibrary{breakable}

\DeclareNewTOC[
  category=float,
  float,% declares floating environment eq
  floatpos=ht,
  nonfloat,% declares non-floating environment eq-
  listname={Some Items},
  name=TM,
  tocentrystyle=tocline,
  tocentrylevel:=table,
  tocentryindent:=table,
  tocentrynumwidth:=table,
  type=MySpecialEnvFloat,
]{ltm}

\newtcolorbox[
    auto counter,
    crefname={TM}{TMs}]{MyBox}[2][]{
    title={TM\,\thetcbcounter: #2},
    #1}


\begin{document}

\newcounter{MySpecialEnvCounter}
\makeatletter
\newcommand{\MySpecialEnv}[4]{%
    \refstepcounter{MySpecialEnvCounter}%
    \begin{MyBox}[label={#1}]{#2}
        \zlabel{#1}
        \addcontentsline{ltm}{section}{TM\,\theMySpecialEnvCounter: #2}
        Some text
        \tcblower
        #4
    \end{MyBox}
}%

\listofMySpecialEnvFloats

\MySpecialEnv{test-id}{Something that looks like a summary}{-}{
    sdjoajhsja sijaoihs siahskah
}

\MySpecialEnv{test-id-2}{Yet another summary}{-}{
    asjajsaj sakjskaj sjkajs
}

\subsection{varioref test}

Varioref test: Reference to \vref{test-id} and \vref{test-id-2}

Pageref test: \vpageref{test-id-2}

\subsection{Cref Test}

\cref{test-id}  \cpageref{test-id}

\subsection{zifrefundefined}

\zifrefundefined{test-id}{\nfss@text{\reset@font\bfseries??}}{GOOD}

\zref{test-id}

\end{document}

在此处输入图片描述

相关内容