KOMA 脚本:附录 TOC 中 etoc 包的标签名称错误

KOMA 脚本:附录 TOC 中 etoc 包的标签名称错误

我使用 etoc-package 和 KOMA-script 类 scrreprt 来创建附录子目录。此子目录列出了从章节级别到子章节的所有附录。附录标题不会添加到主目录中(但会添加到书签中),并且标题不会打印出来,而是添加到页眉中。为此,我创建了\appendixsection, ... 命令。Hyperref 还会创建指向附录位置的链接,但不知何故\def\@currentlabelname{#1}无法生成正确的标签名称。

在此处输入图片描述

正确的标签名称应为:A.1 附录、A.1.1 子附录、A.1.1.1 子子附录。有谁知道如何解决此问题吗?

这是我的 MWE。

\documentclass[
a4paper,
11pt,
parskip=half,
numbers=noenddot,
openright,
]{scrreprt}

\usepackage{scrlayer-scrpage}
\usepackage[no-math]{fontspec}
\PassOptionsToPackage{no-math}{fontspec}
\usepackage{calc}
\usepackage{etoolbox}
\usepackage{etoc}
\usepackage{setspace}
\usepackage{pdfpages}
\usepackage{footnotebackref} % Loads hyperref
\usepackage[showframe]{geometry}

\setkomafont{chapterentry}{\normalfont\bfseries}
\spacing{1.3}

\hypersetup{
    hypertexnames=false,
    colorlinks=true,
    citecolor=black,
    linkcolor=black,
    urlcolor=black,
    bookmarksnumbered,
    bookmarksdepth=2,
    bookmarksopenlevel=1,
    bookmarksopen=true,
}

% Header
\pagestyle{scrheadings}
\clearpairofpagestyles
\KOMAoption{headsepline}{true}
\ohead{\pagemark}
\renewcommand{\headfont}{\normalfont}
\automark[chapter]{chapter}
\ihead{\headmark}

% Typearea
\newlength{\pageleftmargin}
\newlength{\pagerightmargin}
\newlength{\pagetopmargin}
\newlength{\pagebottommargin}
\setlength{\pageleftmargin}{35mm}
\setlength{\pagerightmargin}{15mm}
\setlength{\pagetopmargin}{30mm}
\setlength{\pagebottommargin}{25mm}

\geometry{
    landscape=false,
    twoside=true,
    showframe=true,
    left=\pageleftmargin,
    right=\pagerightmargin,
    top=\pagetopmargin,
    bottom=\pagebottommargin,   
}

% PDF inclue settings
\newlength{\pdfoffsetX}
\setlength{\pdfoffsetX}{(\pageleftmargin-\pagerightmargin)/2}
\newlength{\pdfoffsetY}
\setlength{\pdfoffsetY}{(\pagetopmargin-\pagebottommargin)/2}
\includepdfset{pagecommand={},width=\textwidth,offset=\pdfoffsetX mm -\pdfoffsetY mm}

% Appendix
\appto\appendix{\setcounter{secnumdepth}{3}}
\appto\appendix{\addtocontents{toc}{\protect\setcounter{tocdepth}{3}}}
\appto\appendix{\hypersetup{bookmarksdepth=3}}
\appto\appendix{\automark[section]{section}
                \automark*[subsection]{subsection}
                \automark*[subsubsection]{subsubsection}}

% Appendix TOC
\newcommand{\appendixtoc}{
    \etocsettocdepth.toc{chapter}\etocignoretoctocdepth
    \etocsetnexttocdepth{subsubsubsection}
    \etocsettocstyle{}{}
    \KOMAoptions{parskip=never}
    \localtableofcontents
    \KOMAoptions{parskip=half}
    \clearpage
}

% Phantom titles for appendices
\newcommand{\appendixsection}[1]{
    \stepcounter{section}%
    \makeatletter\def\@currentlabelname{#1}\makeatother%
    \phantomsection%
    \addxcontentsline{toc}{section}{\protect\numberline{\thesection}#1}%
    \sectionmark{#1}%
}
\newcommand{\appendixsubsection}[1]{
    \stepcounter{subsection}%
    \makeatletter\def\@currentlabelname{#1}\makeatother%
    \phantomsection%
    \addxcontentsline{toc}{subsection}{\protect\numberline{\thesubsection}#1}%
    \subsectionmark{#1}%
}
\newcommand{\appendixsubsubsection}[1]{
    \stepcounter{subsubsection}%
    \makeatletter\def\@currentlabelname{#1}\makeatother%
    \phantomsection%
    \addxcontentsline{toc}{subsubsection}{\protect\numberline{\thesubsubsection}#1}%
    \subsubsectionmark{#1}%
}

\begin{document}

\tableofcontents

\chapter{Chapter 1}

Reference to appendix \ref{app: Appendix Section} \nameref{app: Appendix Section}.\\
Reference to sub-appendix \ref{app: Appendix Subsection} \nameref{app: Appendix Subsection}.\\
Reference to subsub-appendix \ref{app: Appendix Subsubsection} \nameref{app: Appendix Subsubsection}.

\section{Section 1}
\section{Section 2}

\appendix
\chapter{Appendices}

\appendixtoc

%\includepdf[pages=1,pagecommand={\appendixsection{First Appendix} \label{app: Appendix Section}}]{TestA4.pdf}
\appendixsection{Appendix} \label{app: Appendix Section}
Appendix Section \dots
\clearpage
\appendixsubsection{Sub-Appendix} \label{app: Appendix Subsection}
Sub-appendix \dots
\clearpage
\appendixsubsubsection{Subsub-Appendix} \label{app: Appendix Subsubsection}
Subsub-appendix \dots

\end{document}

相关内容