使用 refsegment 为每章生成单独的参考书目不起作用

使用 refsegment 为每章生成单独的参考书目不起作用

我想打印每个章节的参考书目。阅读手册和这里的几个答案后,我得出结论,我应该使用这个refsegment功能。不幸的是,它没有像我预期的那样工作。

以下是我使用的代码:

\documentclass{scrbook}

\begin{filecontents}{refs.bib}
@article{wombat2016,
    author   = {Walther Wombat and Klaus Koala},
    title    = {The true meaning of 42},
    journal  = {Journal of modern skepticism},
}
@book{lion2010,
    author       = {Laura Lion and  Gabrielle Giraffe and Carl Capybara},
    title        = {The dangers of asking the wrong question},
    publisher    = {publishing house},
}
@online{wikibook,
    title        = {Generating Bibliographies with biblatex and biber},
    date         = {2016},
    url          = {https://en.wikibooks.org/wiki/LaTeX/Generating_Bibliographies_with_biblatex_and_biber},
}
\end{filecontents}

\usepackage[refsegment=chapter]{biblatex}
\bibliography{refs.bib}

\begin{document}

\chapter{Introduction}

Blabla~\cite{wombat2016}.
\printbibliography[segment=\therefsegment, heading=subbibliography]

\chapter{Further thoughts}

Blubbblubb~\cite{lion2010, wikibook}.
\printbibliography[segment=\therefsegment, heading=subbibliography]

\appendix
\printbibliography

\end{document}

这是运行 lualatex、biber、lualatex 后第一章的结果。我原本以为只会显示第三个条目。我在这里做错了什么? 在此处输入图片描述

答案1

正如评论中指出的那样,MWE 在当前版本biblatex(2019/12/01 的 v3.14)和scrbook(2020/01/24 的 v3.29)下运行良好。如果可能的话,您可能需要考虑更新 TeX 系统以获取当前版本。

如果这不可能,你可以尝试在https://github.com/plk/biblatex/issues/857

如果您更新到的较新版本,则应删除该解决方法,因此在 MWE 中我添加了一些代码,以便在的版本足够新时biblatex产生错误。biblatex

\documentclass{scrbook}

\usepackage[refsegment=chapter]{biblatex}

\makeatletter
\@ifpackagelater{biblatex}{2019/08/17}
  {\blx@error
     {Remove the redefinition of \string\blx@refpatch@chapter}
     {Your version of biblatex does not need the redefinition
      of \string\blx@refpatch@chapter}}
  {\def\blx@refpatch@chapter#1{%
     \ifundef\chapter
       {\blx@err@nodocdiv{chapter}}
       {\pretocmd\@makechapterhead{#1}
          {}
          {\blx@err@patch{\string\@makechapterhead}}
        \pretocmd\@makeschapterhead{#1}
          {}
          {\blx@err@patch{\string\@makeschapterhead}}}}}
\makeatother

\begin{filecontents}{\jobname.bib}
@article{wombat2016,
    author   = {Walther Wombat and Klaus Koala},
    title    = {The true meaning of 42},
    journal  = {Journal of modern skepticism},
}
@book{lion2010,
    author       = {Laura Lion and  Gabrielle Giraffe and Carl Capybara},
    title        = {The dangers of asking the wrong question},
    publisher    = {publishing house},
}
@online{wikibook,
    title        = {Generating Bibliographies with biblatex and biber},
    date         = {2016},
    url          = {https://en.wikibooks.org/wiki/LaTeX/Generating_Bibliographies_with_biblatex_and_biber},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}
\chapter{Introduction}

Blabla~\cite{wombat2016}.
\printbibliography[segment=\therefsegment, heading=subbibliography]

\chapter{Further thoughts}

Blubbblubb~\cite{lion2010, wikibook}.
\printbibliography[segment=\therefsegment, heading=subbibliography]

\appendix
\printbibliography
\end{document}

请注意,会采用不带文件扩展名\bibliography的文件名称,因此是不正确的,应该是。如今,通常首选使用而不是。采用名称.bib\bibliography{refs.bib}\bibliography{refs}\addbibresource\bibliographybiblatex\addbibresource文件扩展名,因此首选方法是

\addbibresource{refs.bib}

相关内容