这个问题与我的另一个问题有关法语章节编号使用 bis、ter 等上一个问题给了我一种方法来用拉丁字母对不同的部分进行编号之二,之三,以及其他按顺序排列的内容。
现在我尝试交叉引用这些部分,但交叉引用编号不正确。请考虑下面的 MWE,它与上述问题的答案略有不同。
\documentclass{book}
\usepackage{xparse}
\usepackage{enumitem}
\usepackage[explicit]{titlesec}
\usepackage{lipsum}
\usepackage{calc}
\usepackage{totcount}
\usepackage{hyperref}
\ExplSyntaxOn
\seq_new:N \bislist
\seq_set_split:Nnn \bislist {;} {bis;ter;quater;quinquies;sexies;septies;octies;novies;decies}
\NewDocumentCommand {\bisprint} {m}
{
\seq_item:Nn \bislist {#1}
}
\ExplSyntaxOff
\newtotcounter{bismax}
\newcounter{bis}
\stepcounter{bis}
\setcounter{bismax}{1}
\newcommand{\bisadd}{\stepcounter{bis} \setcounter{bismax}{\minof{4}{\maxof{\thebismax}{\thebis-1}}}}
\AtBeginDocument{\newlength{\bislength}
\settowidth{\bislength}{\textit{\bisprint{\totvalue{bismax}}}}
\addtolength{\bislength}{1.5em}}
\titleformat{\section}[block]{\normalfont\large\normalfont\filcenter}{\thesection. --- #1}{0.5em}{}[\setcounter{bis}{1}]
\renewcommand\thesection{\arabic{section}}
\titleformat{name=\section,numberless}[block]{\normalfont\large\normalfont\filcenter}{\arabic{section} \textit{\bisprint{\arabic{bis}}}. --- #1}{0.5em}{}[ \addcontentsline{toc}{section}{\protect\numberline{\arabic{section} \textit{\bisprint{\arabic{bis}}}}#1} \bisadd{}]
\makeatletter
\renewcommand*\l@section{\@dottedtocline{1}{1.5em}{\bislength}}
\makeatother
\begin{document}
\tableofcontents
\section{First section header}\label{Sec1}
\lipsum[5]
\section*{Second section header}\label{Sec1bis}
\lipsum[6]
\section*{Third section header}\label{Sec1ter}
\lipsum[7]
Let's reference Section \ref{Sec1bis} and \ref{Sec1ter} here. This should have said "Section 1 \textit{bis} and Section 1 \textit{ter}." You will see that the cross-references do not work out correctly.
\end{document}
这将产生以下输出:
如你所见,最后一段试图交叉引用第 1 节之二和 1之三,但拉丁序数词没有正确显示。我认为这与命令有关\section*
,但我真的不确定。
答案1
这里有一个对常用命令影响最小的想法:\section+
引入一个“bis”部分。当\section
扫描不带后缀的 a 时,常规计数器会步进,计数器bis
会重置。
\documentclass{book}
\usepackage{xparse}
\usepackage{titlesec}
\usepackage{hyperref}
\usepackage{lipsum}
\titleformat{\section}[block]
{\normalfont\large\normalfont\filcenter}
{\thesection. --- }
{0em}
{}
\ExplSyntaxOn
\cs_set_eq:NN \origsection \section
\RenewDocumentCommand{\section}{s t+ o m }
{
\IfBooleanTF{#1}
{ \origsection* { #4 } }
{
\stepcounter{Hsection}
\IfBooleanTF{#2}
{
\addtocounter{section}{-1}
\stepcounter{bis}
}
{
\setcounter{bis}{1}
}
\IfNoValueTF{#3}
{ \origsection { #4 } }
{ \origsection [ #3 ] { #4 } }
}
}
\DeclareExpandableDocumentCommand {\bisprint} {}
{
\int_case:nnF { \value{bis} }
{
{0}{}
{1}{}
{2}{~bis}
{3}{~ter}
{4}{~quater}
{5}{~quinquies}
{6}{~sexies}
{7}{~septies}
{8}{~octies}
{9}{~novies}
{10}{~decies}
}
{ ~ HEY! }
}
\ExplSyntaxOff
\renewcommand{\thesection}{\arabic{section}\textit{\bisprint}}
\newcounter{bis}
\newcounter{Hsection}
\begin{document}
\tableofcontents
\section{First section header}\label{Sec1}
\lipsum[5]
\section+{Second section header}\label{Sec1bis}
\lipsum[6]
\section+{Third section header}\label{Sec1ter}
\lipsum[7]
Let's reference Section \ref{Sec1bis} and \ref{Sec1ter} here. This should have said "Section 1
\textit{bis} and Section 1 \textit{ter}." You will see that the cross-references do not work out
correctly.
\section{This should be 2}
\section+{This should be 2bis}
\end{document}
我把进一步的改进留给你。
答案2
您可以将您的更改numberless
\titleformat
为以下内容:
\makeatletter
\providecommand{\phantomsection}{}% To work with hyperref, if needed
\titleformat{name=\section,numberless}[block]
{\normalfont\large\normalfont\filcenter}
{\phantomsection% Set hyperref mark
\protected@xdef\@currentlabel{\thesection~\textit{\bisprint{\arabic{bis}}}}%
\arabic{section} \textit{\bisprint{\arabic{bis}}}. --- #1}
{0.5em}
{}
[ \addcontentsline{toc}{section}{\protect\numberline{\arabic{section} \textit{\bisprint{\arabic{bis}}}}#1} \bisadd{}]
\makeatother
这会更新\@currentlabel
- 系统所使用的 -\label
以\ref
包含您的\bisprint
-ed 号码。
上述情况也按预期工作hyperref
用来。