交叉引用显示零件编号

交叉引用显示零件编号

有没有办法让交叉引用写出\part这样的数字?

参见上文第1部分,第 3 页。

我目前正在使用:\here{}\label{}\footnote{Cf. \where{}. Page \pageref{}.}

所以我需要一些东西来检查标签在哪个部分,然后在脚注中写下该部分的编号。

编辑:我认为这并不重要\where\here但我根据要求添加了代码。

\makeatletter
\newcount\here@undef
\newcommand{\here}[1]{%
  \@ifundefined{here@#1@undef}{}{\global\advance\here@undef by -1}%
  \global\@namedef{here@#1}{}%
}
\newcommand{\where}[1]{%
  \@ifundefined{here@#1}{%
    below%
    \@ifundefined{here@#1@undef}{%
      \global\@namedef{here@#1@undef}{}%
      \global\advance\here@undef by 1
    }{}%
  }{%
    above%
  }%
}
\AtEndDocument{%
  \ifnum\here@undef>0
    \GenericWarning{}{There were undefined above/below labels}%
  \fi}
\makeatother%

答案1

该包zref用于执行此类任务:提取标签数据(如果\zlabel使用相关命令等)。

为了提供正确的信息,必须存储“属性”,在这种情况下,属性是应连接到标签的零件编号。

该命令\here使用给定名称存储标签\zlabel@byprops\there然后提取信息。

更新带有可用超链接的版本:

 \documentclass{scrbook}

\usepackage[counter,user,hyperref]{zref}




\makeatletter
\AtBeginDocument{%
\@ifpackageloaded{hyperref}{%
}{
  \providecommand{\phantomsection}{}
  \providecommand{\hyperlink}[2]{#2}
}

\zref@newlist{partpage}
\zref@newprop*{partprop}[-1]{\number\value{part}}
\zref@addprops{partpage}{partprop,page,anchor} % page is defined by default!

\newcounter{herecntr}

\newcommand{\here}[1]{%
  \phantomsection% Needed for correct hyper links
  \zref@labelbyprops{#1}{partprop,page,anchor}%
}

\newcommand{\there}[1]{%
  Part \zref[partprop]{#1}, page \hyperlink{\zref@extract{#1}{anchor}}{\zpageref{#1}}
}
}
\makeatother


\usepackage{hyperref}


\usepackage{blindtext}

\begin{document}
Now, let us see\footnote{You will find in \there{firstref} some important information, but in \there{secondref} the information is much more important. Give it a try, but do not forget the stuff in \there{somethingdifferent}}


\part{My wonderful first part} 

\blindtext[6] firstref\here{firstref}

\part{My second and yet better part}

\blindtext[7] secondref\here{secondref}


\part{My third and yet even better part}

\blindtext[3] thirdref\here{thirdref}

\chapter{Foo}\here{somethingdifferent}

\blindtext[2]

\end{document}

enter image description here

更新对于压缩引用,即,\there如果引用在同一部分,则命令不会打印零件编号!

\documentclass{scrbook}

\usepackage[counter,user,hyperref]{zref}




\makeatletter
\AtBeginDocument{%
\@ifpackageloaded{hyperref}{%
}{
  \providecommand{\phantomsection}{}
  \providecommand{\hyperlink}[2]{#2}
}

\zref@newlist{partpage}
\zref@newprop*{partprop}[-1]{\number\value{part}}
\zref@addprops{partpage}{partprop,page,anchor} % page is defined by default!

%\newcounter{herecntr}

\newcommand{\here}[1]{%
  \phantomsection% Needed for correct hyper links
  \zref@labelbyprops{#1}{partprop,page,anchor}%
}

\newcommand{\there}[1]{%
  \ifnum\value{part}=\zref@extract{#1}{partprop}\relax% Check whether the current part counter value is the same as the extracted part property from the label
  page \hyperlink{\zref@extract{#1}{anchor}}{\zpageref{#1}}
  \else% No, it is not the same!
  Part \zref[partprop]{#1}, page \hyperlink{\zref@extract{#1}{anchor}}{\zpageref{#1}}%
  \fi
}
}
\makeatother


\usepackage{hyperref}

\usepackage{blindtext}

\begin{document}

\part{My wonderful first part} 

Now, let us see\footnote{You will find in \there{firstref} some important information, but in \there{secondref} the information is much more important. Give it a try, but do not forget the stuff in \there{somethingdifferent}}



\blindtext[6] firstref\here{firstref}

\part{My second and yet better part}

\blindtext[7] secondref\here{secondref}


\part{My third and yet even better part}

\blindtext[3] thirdref\here{thirdref}

\chapter{Foo}\here{somethingdifferent}

\blindtext[2]

\end{document}

相关内容