BibLaTeX 和导航器包之间可能存在冲突

BibLaTeX 和导航器包之间可能存在冲突

biblatex我在使用包(管理参考书目)和navigator包(将文件嵌入 PDF)时遇到了麻烦。以下是一个最小示例:

\documentclass[11pt,letterpaper,titlepage]{article}

\usepackage{biblatex}
\usepackage{navigator}

\addbibresource{latextest.bib}

% Just need some file here
\embeddedfile{Test}[Test.txt]{latextest.bib}

\begin{document}

Test

Test \cite{ctan}

Test

\printbibliography

\finishpdffile

\end{document}

以下是 latextest.bib 的内容:

@online{ctan,
    title = "The Comprehensive TeX Archive Network",
    url = "https://ctan.org/"
}

日志文件显示了几个错误:

! Undefined control sequence.
<argument> \bibname 

l.11 \begin{document}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.


! LaTeX Error: Missing \begin{document}.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...                                              

l.11 \begin{document}

You're in trouble here.  Try typing  <return>  to proceed.
If that doesn't work, type  X <return>  to quit.

! Too many }'s.
<argument> ...cs \bibname {\abx@str @bibliography}

l.11 \begin{document}

You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.

! Too many }'s.
<argument> \letcs \refname {\abx@str @references}

l.11 \begin{document}

You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.

! Undefined control sequence.
<argument> \biblistname 

l.11 \begin{document}

The control sequence at the end of the top line
of your error message was never \def'ed. If you have
misspelled it (e.g., `\hobx'), type `I' and the correct
spelling (e.g., `I\hbox'). Otherwise just continue,
and I'll forget about whatever was undefined.

! Too many }'s.
<argument> ... \biblistname {\abx@str @shorthands}

l.11 \begin{document}

You've closed more groups than you opened.
Such booboos are generally harmless, so keep going.

如果注释掉与参考书目相关的命令(\usepackage{biblatex}\addbibresource\cite和),则编译成功。同样,如果注释掉\printbibliography与嵌入文件相关的命令(\usepackage{navigator}\embeddedfile和),则编译也会成功。\finishpdffile

在 Ubuntu 上运行 MiKTeX 2.9.7216-x64(昨天重新安装,所有软件包都是最新的)和 TeX Live 2017.20180305-1 时都会发生这种情况。我正在使用 XeTeX 和 Biber 进行编译。

我将非常感激任何关于如何解决该问题的修复或建议。

答案1

navigator和之间确实存在根本不兼容biblatex(或者更准确地说,两者使用的 TeX 编程工具箱texapi和之间存在根本不兼容etoolbox)。

如果你将最小示例中两个包的加载顺序交换为

\usepackage{navigator}
\usepackage{biblatex}

你会得到以下错误

("C:\Program Files\MiKTeX 2.9\tex/latex/etoolbox\etoolbox.sty"

! LaTeX Error: Command \letcs already defined.
               Or name \end... illegal, see p.192 of the manual.

这表明,navigator或者由 加载的包定义了也由 定义的navigator命令(需要)。\letcsetoolboxbiblatex

经过一番挖掘,我们发现texapi,由 加载的navigator已经

\long\pdef\letcs#1{\expandafter\let  \csname#1\endcsname}

etoolbox

\newrobustcmd{\letcs}[2]{%
  \ifcsdef{#2}
    {\expandafter\let\expandafter#1\csname#2\endcsname}
    {\undef#1}}

不幸的是,这两个定义具有完全相反的“语法”。texapi的版本用作

\letcs{foo}\bar

whileetoolbox使用它的版本作为

\letcs\foo{bar}

由于该命令在两者中无处不在,navigator并且biblatex这种名称冲突使软件包几乎不兼容。如果您想让这两个软件包一起工作,您必须\letcs根据所使用的命令保存和恢复正确的版本。

在下面的 MWE 中,设置了一些东西,以便\letcs整个文档中的 的工作定义是 来自 的定义etoolbox。这意味着对于每个navigator命令,我们都需要本地重置\letcs为其texapi定义。

\documentclass[11pt,letterpaper,titlepage]{article}

\usepackage{navigator}
\let\navletcs\letcs
\let\letcs\relax
\usepackage{biblatex}

\begin{filecontents}{latextest.bib}
@online{ctan,
    title = "The Comprehensive TeX Archive Network",
    url = "https://ctan.org/"
}
\end{filecontents}
\addbibresource{latextest.bib}

\begingroup
\let\letcs\navletcs
\embeddedfile{Test}[Test.txt]{latextest.bib}
\endgroup

\begin{document}
Test

Test \cite{ctan}

Test

\printbibliography

\begingroup
\let\letcs\navletcs
\finishpdffile
\endgroup
\end{document}

相关内容