我曾经成功编译过一本书的手稿,首先是所有章节,然后只使用几个章节\includeonly
,同时保留.aux
完整编译的文件,但现在却出现错误:! LaTeX Error: No counter 'blx@maxsegment@6' defined.
为了复制错误,我设计了以下包含三个组件文件的 MWE,以便:
% test.tex
% MWE for `No counter 'blx@maxsegment@<number>` error with `includeonly`
%
\documentclass[a4paper,12pt]{book}
\usepackage{fontspec}
\usepackage[backend=biber,refsection=chapter,hyperref=auto]{biblatex}
\usepackage{hyperref}
\usepackage{cleveref}
%
% When the line below is commented out, error-free compilation results.
\includeonly{Two}
%
\begin{document}
%
\include{One}
\include{Two}
\include{Three}
%
\end{document}
%%%%%%%%%%%%%%
% One.tex
\chapter{One}\label{chap:one}
%%
% Two.tex
\chapter{Two}\label{chap:two}
%%
% Three.tex
\chapter{Three}\label{chap:three}
%%%%%%%%%%%%%%
当\includeonly
注释掉该行时,文件可以成功编译lualatex
。当\includeonly
取消注释该行时,我收到以下错误:
! LaTeX Error: No counter 'blx@maxsegment@1' defined.
See the LaTeX manual or LaTeX Companion for explanation.
Type H <return> for immediate help.
...
l.15 \include{One}
此问题之前已被确认,并已在此纠正Github 上的 2014 年问题和这个稍后在 Github 上发布。
我不确定它的再次出现是回归错误,还是因为我没有跟上 TeX 生态系统的变化,或者完全是其他原因。无论如何,如果能找到解决方法,我将不胜感激。
谢谢。
答案1
最新的 biblatex 尝试解决 includeonly 的一些问题(https://github.com/plk/biblatex/issues/1196),但仍遗漏了一些案例。
这里的问题是,biblatex 在包含的文件中动态创建计数器,如果您使用 \includeonly,则它们不会被定义。
你可以试试这个
\documentclass[a4paper,12pt]{book}
%\usepackage{fontspec}
\usepackage[backend=biber,refsection=chapter,hyperref=auto]{biblatex}
\makeatletter
\def\blx@refsection@i[#1]{%
\endgroup
\stepcounter{blx@maxsection}%
\setcounter{refsection}{\value{blx@maxsection}}%
\xifinlist{\the\c@refsection}\blx@allrefsections
{}
{\listxadd\blx@allrefsections{\the\c@refsection}}%
\ifcsdef{blx@defaultrefcontexts@\the\c@refsection}
{}
{\global\cslet{blx@defaultrefcontexts@\the\c@refsection}\@empty}%
\blx@providecounter{blx@maxsegment@\the\c@refsection}%
\blx@providecounter{blx@sectionciteorder@\the\c@refsection}%
%new provide counter in aux-file
\if@filesw
\immediate\write\@auxout{\noexpand\blx@providecounter{blx@maxsegment@\the\c@refsection}}%
\immediate\write\@auxout{\noexpand\blx@providecounter{blx@sectionciteorder@\the\c@refsection}}%
\fi
\blx@inf@refsec
\blx@secinit
\if@filesw
\blx@auxwrite\@mainaux{}{%
\string\abx@aux@refsection{\the\c@refsection}{\the\c@page}}%
\ifblank{#1}
{}
{\let\blx@bibfiles\@empty
% globals should be first as it might contain macros needed for others
\forlistloop{\listadd\blx@bibfiles}\blx@bibfiles@global}%
\blx@xsanitizeafter{\forcsvlist\blx@refsection@addfile}{#1}%
\blx@refsection@ii
\fi
\blx@info{Setting label 'refsection:\the\c@refsection'}%
\label{refsection:\the\c@refsection}%
\endgroup}
\usepackage{hyperref}
\usepackage{cleveref}
%
% When the line below is commented out, error-free compilation results.
%\includeonly{Two}
%
\begin{document}
%
\include{One}
\include{Two}
\include{Three}
%
\end{document}