从 AtEndPreamble 钩子中加载 BibLaTeX

从 AtEndPreamble 钩子中加载 BibLaTeX

以下MWE编译:

\documentclass{article}
\usepackage{biblatex}
\begin{document}
\end{document}

而以下情况则不然:

\documentclass{article}
\usepackage{etoolbox}
\AtEndPreamble{\usepackage{biblatex}}
\begin{document}
\end{document}

产生以下输出:

This is pdfTeX, Version 3.14159265-2.6-1.40.16 (TeX Live 2015/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./tex.tex
LaTeX2e <2016/02/01>
Babel <3.9q> and hyphenation patterns for 81 language(s) loaded.
(/usr/share/texlive/texmf-dist/tex/latex/base/article.cls
Document Class: article 2014/09/29 v1.4h Standard LaTeX document class
(/usr/share/texlive/texmf-dist/tex/latex/base/size10.clo))
(/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
(/usr/share/texlive/texmf-dist/tex/latex/biblatex/biblatex.sty

Package biblatex Warning: No "backend" specified, using Biber backend.
(biblatex)                To use BibTeX, load biblatex with 
(biblatex)                the "backend=bibtex" option.

(/usr/share/texlive/texmf-dist/tex/latex/biblatex/biblatex_.sty
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)
(/usr/share/texlive/texmf-dist/tex/latex/oberdiek/kvoptions.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ltxcmds.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/kvsetkeys.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/infwarerr.sty)
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/etexcmds.sty
(/usr/share/texlive/texmf-dist/tex/generic/oberdiek/ifluatex.sty))))
(/usr/share/texlive/texmf-dist/tex/latex/logreq/logreq.sty
(/usr/share/texlive/texmf-dist/tex/latex/logreq/logreq.def))
(/usr/share/texlive/texmf-dist/tex/latex/base/ifthen.sty)
(/usr/share/texlive/texmf-dist/tex/latex/url/url.sty)
! Undefined control sequence.
<argument> \blx@mknoautolang 

l.310   \let\do\noexpand}

我想知道如何避免此错误,同时保留使用\AtEndPreamble或类似的挂钩机制。

答案1

我认为根本没有必要将加载推迟biblatex到序言的末尾。

\AtEndPreamble在这里不起作用,因为\usepackage{biblatex}尝试写入.aux当时未打开的设置。

\begin{document}打开的.aux,而不是\documentclass

以下是代码的摘录latex.ltx\def\document这里删除了一些不相关的行

\def\document{\endgroup
  % Some lines deleted
  \begingroup\@floatplacement\@dblfloatplacement
    \makeatletter\let\@writefile\@gobbletwo
    \global \let \@multiplelabels \relax
    \@input{\jobname.aux}%   --> reading the existing .aux - file
  \endgroup
  \if@filesw
    \immediate\openout\@mainaux\jobname.aux     % Open the .aux file for reading again (if \nofiles wasn't used). 
    \immediate\write\@mainaux{\relax}%
  \fi

这是一个解决方法,但是我不建议它,因为也\addbibresource必须在代码中使用它\BeforeBeginEnvironment,因为\addbibresource不能再使用前导码(biblatex当时使用该命令时没有可用!)

\documentclass{article}
\usepackage{etoolbox}
\BeforeBeginEnvironment{document}{%
  \usepackage{biblatex}
  \addbibresource{biblio.bib}
}

\begin{document}
\cite{Lam94}
\printbibliography
\end{document}

相关内容