如何使超链接目标名称唯一,以使 TOC 链接起作用?

如何使超链接目标名称唯一,以使 TOC 链接起作用?

这个问题的情况和我自己搜索错误信息得到的结果有些不同。

[20]LuaTeX warning (ext4): destin
ation with the same identifier (name{subsection.1.2.1}) has been already used,
duplicate ignored

基本上,我重复的部分名称,并且错误是......不是错误的,我只需要一种方法来使目标名称唯一,以便 TOC 点击链接可以工作。

这是 MWE,它可以解释发生了什么。

% main.tex

\documentclass[12pt]{article}

\usepackage{tocloft}
\usepackage{regexpatch}
\usepackage{etoolbox}
\usepackage[newparttoc]{titlesec}

\usepackage[pdfencoding=auto,plainpages=false,pdfpagelabels,psdextra]{hyperref}
\usepackage{bookmark}
\usepackage{fontspec, xunicode, microtype}

\makeatletter
    \def\@seccntformat#1{\protect\makebox[0pt][r]{\csname
    the#1\endcsname\quad}}
\makeatother

\makeatletter
\patchcmd{\@part}% <cmd>
  {\markboth{}{}}% <search>
  {\partmark{#1}}% <replace>
  {}{}% <success><failure>
\makeatother


\makeatletter
    \@addtoreset{section}{part}
\makeatother

\cftpagenumbersoff{part}

\title{Test}

\begin{document}
\pagenumbering{gobble}

% titlepage

\begin{center}

A Title

\end{center}

% end title page


\pagebreak
\tableofcontents
\pagebreak

\hypersetup{pageanchor=true}
\pagenumbering{arabic}


% would be \input{"test1"}, but it doesn't matter

\pagebreak
\part{Part One}
\section{To Slice a Hotdog}
    \subsection{Operating a Knife}
        Foo Bar.


\renewcommand{\thepart}{\Alph{part}}

\pagebreak
\begin{center}Addendums\end{center}
\pagebreak

\setcounter{part}{0}
% would be \input{"addendums"}, but again, doesn't change things

\pagebreak
\part{Addendum One}
\section{To Blend a Hotdog}
    \subsection{Operating a Blender}
        Something something.

\end{document}

我是意识到的我收到这些错误的原因是我重置了部件号计数器。我拥有的文档的第一部分按数字编号,即 1-9 等。下一部分,有点像附录,但更像附录,按 AZ 排序。因此我重置了计数器并将编号设置为\Alph

当然,如果有更好的方法来实现我想要实现的目标,而不需要重置计数器并避免所有这些问题,那么这也是可行的。

目录中的显示效果很好,但单击该项目只会将我带到第一部分,这当然是可以理解的。这就是我要解决的问题。

从我所收集的信息来看,我需要攻击这个宏:\HyperDestNameFilter。我丢失了推荐这个的原始 StackOverflow 答案,但我首先尝试了\renewcommand*{\HyperDestNameFilter}[1]{\jobname-#1},才意识到由于我的文件被\input编辑到主文件中,所以作业名称将是相同的。

然后,我尝试使用\renewcommand*{\HyperDestNameFilter}[1]{\thepage-#1}。乍一看,这似乎有效,因为我不再收到错误。

然而,在编译所有页面后,我得到了一大堆,我的意思是一大堆, 这些:

LuaTeX warning (dest): name{-subsubsection.1.3.3.3} has been referenced but does
 not exist, replaced by a fixed one

LuaTeX warning (dest): name{-subsubsection.1.3.3.2} has been referenced but does
 not exist, replaced by a fixed one

LuaTeX warning (dest): name{-subsubsection.1.3.3.1} has been referenced but does
 not exist, replaced by a fixed one

LuaTeX warning (dest): name{-subsection.1.3.3} has been referenced but does not 
exist, replaced by a fixed one

LuaTeX warning (dest): name{-subsection.1.3.2} has been referenced but does not 
exist, replaced by a fixed one

它一直都在,我想它适用于每个部分、小节、小小节,所有内容。现在,单击目录中的所有标题都会将我带到最后一页。全部链接已损坏。帮忙?

那么,TL;DR:我该如何做才能获得唯一的目的地名称,以便即使我有具有相同编号的相同部分标题,我的 TOC 链接也能正常工作?

非常感谢。

答案1

手动重置切片结构的计数器必须造成混淆hyperref,因为它会根据计数器值生成锚点。

例如,锚点名称可以是part.1

Addendum但是,即使\thepart重新定义为\Alph{part}——锚点名称是由名为等的特殊命令生成的,这将再次出现。\theHpart如果这得到一个新的前缀,那么addendum一切都应该会好起来。

因此

\renewcommand{\theHpart}{addendum.\thepart}

应提供唯一的名称。

\documentclass[12pt]{article}

\usepackage{tocloft}

\usepackage{etoolbox}
\usepackage[newparttoc]{titlesec}
\usepackage{fontspec, microtype}
\usepackage[pdfencoding=auto,plainpages=false,pdfpagelabels,psdextra]{hyperref}
\usepackage{bookmark}


\makeatletter
    \def\@seccntformat#1{\protect\makebox[0pt][r]{\csname
    the#1\endcsname\quad}}
\makeatother

\makeatletter
\patchcmd{\@part}% <cmd>
  {\markboth{}{}}% <search>
  {\partmark{#1}}% <replace>
  {}{}% <success><failure>
\makeatother


\makeatletter
    \@addtoreset{section}{part}
\makeatother

\cftpagenumbersoff{part}

\title{Test}

\begin{document}
\pagenumbering{gobble}

% titlepage

\begin{center}

A Title

\end{center}

% end title page


\pagebreak
\tableofcontents
\pagebreak

\hypersetup{pageanchor=true}
\pagenumbering{arabic}


% would be \input{"test1"}, but it doesn't matter

\pagebreak
\part{Part One}
\section{To Slice a Hotdog}
    \subsection{Operating a Knife}
        Foo Bar.


\renewcommand{\thepart}{\Alph{part}}

\pagebreak
\begin{center}Addendums\end{center}
\pagebreak

\setcounter{part}{0}
\renewcommand{\theHpart}{addendum.\thepart}
% would be \input{"addendums"}, but again, doesn't change things

\pagebreak
\part{Addendum One}
\section{To Blend a Hotdog}
    \subsection{Operating a Blender}
        Something something.

\end{document}

相关内容