使用 biblatex 在每章參考書目中包含未編號章節的正確方法

使用 biblatex 在每章參考書目中包含未編號章節的正確方法

我一直在使用文件範例3.11.4biblatex論文末尾生成每章的參考書目。它的效果很好,直到我嘗試將我的介紹寫成一個未編號的章節。那麼,引言就不會出現在參考書目中。這是一個 MWE:

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\defbibheading{bibintoc}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

\chapter*{Introduction}

\cite{A01}

\chapter{Chapter 1}

\cite{A01,B02}

\backmatter

\printbibheading
\bibbysegment[heading = bibintoc]

\end{document}

我找到了一個解決方法,對未編號的簡介使用refsection。以下是解決方法的 MWE:

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\defbibheading{bibintoc}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\defbibheading{bibintoc2}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for the \nameref{refsection:\therefsection}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

\chapter*{Introduction}
\begin{refsection}
\cite{A01}
\end{refsection}
\chapter{Chapter 1}

\cite{A01,B02}

\backmatter

\printbibheading
\printbibliography[section=1,heading=bibintoc2]
\bibbysegment[heading = bibintoc]

\end{document}

我對此感到滿意,直到我添加了一個帶有引文的未編號結論。然後代碼崩潰並biblatex返回nested refsections錯誤。這是 MWE:

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\defbibheading{bibintoc}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\defbibheading{bibintoc2}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for the \nameref{refsection:\therefsection}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

\chapter*{Introduction}
\begin{refsection}
\cite{A01}
\end{refsection}
\chapter{Chapter 1}

\cite{A01,B02}

\chapter*{Conclusion}
\begin{refsection}
\cite{C03}
\end{refsection}

\backmatter

\printbibheading
\printbibliography[section=1,heading=bibintoc2]
\bibbysegment[heading = bibintoc]

\end{document}

有什麼想法如何解決這個問題嗎?或者,更好的是,如何正確實施文件\chapter*範例?3.11.4biblatex

先謝謝您的幫忙!

答案1

您可以在未編號的章節中手動呼叫\newrefsegment和:\citereset

\chapter*{Introduction}
\newrefsegment
\citereset

但參考書目部分的標題無法保持一致的格式。有多種方法可以解決這個問題。在這裡,我們使用\chapter和 的補丁來處理所有事情\chapter*

\documentclass{book}
\usepackage[sorting=none,refsegment=chapter,citereset=chapter]{biblatex}
\usepackage{nameref}

\makeatletter
% Extend biblatex's \chapter patch to \chapter* and save data for titles
\def\blx@refpatch@chapter#1{%
  \ifundef\chapter
    {\blx@err@nodocdiv{chapter}}
    {\pretocmd\@makechapterhead
       {#1%
        \csdef{subbib:\therefsection\therefsegment}{%
          Chapter~\ref{refsegment:\therefsection\therefsegment}}}
       {}{\blx@err@patch{\string\@makechapterhead}}%
     \pretocmd\@makeschapterhead
       {#1%
        \csdef{subbib:\therefsection\therefsegment}{%
          \nameref{refsegment:\therefsection\therefsegment}}}
       {}{\blx@err@patch{\string\@makeschapterhead}}}}
\makeatother
\defbibheading{subbibliography}{%
  \section*{References for \csuse{subbib:\therefsection\therefsegment}}}

\addbibresource{biblatex-examples.bib}
\begin{document}
\tableofcontents
\chapter*{Introduction}
\cite{reese}
\chapter{First chapter}
\cite{companion}
\chapter*{Unnumbered chapter}
\cite{glashow,weinberg}
\chapter{Second chapter}
\cite{glashow}
\chapter*{Conclusion}
\cite{reese}
\printbibheading[heading=bibintoc]
\bibbysegment[heading=subbibliography]
\end{document}

在此輸入影像描述

這種方法也適用於逐章參考章節。

\documentclass{book}
\usepackage[sorting=none,refsection=chapter]{biblatex}
\usepackage{nameref}

\makeatletter
% Extend biblatex's \chapter patch to \chapter*, save data for titles
\def\blx@refpatch@chapter#1{%
  \ifundef\chapter
    {\blx@err@nodocdiv{chapter}}
    {\pretocmd\@makechapterhead
       {#1\csdef{subbib:\therefsection}{Chapter~\ref{refsection:\therefsection}}}
       {}{\blx@err@patch{\string\@makechapterhead}}%
     \pretocmd\@makeschapterhead
       {#1\csdef{subbib:\therefsection}{\nameref{refsection:\therefsection}}}
       {}{\blx@err@patch{\string\@makeschapterhead}}}}
\makeatother
\defbibheading{subbibliography}{\section*{References for \csuse{subbib:\therefsection}}}

\addbibresource{biblatex-examples.bib}
\begin{document}
...
\printbibheading[heading=bibintoc]
\bibbysection[heading=subbibliography]
\end{document}

答案2

您必須\endrefsegment在未編號的「結論」章節之前手動終止最後一段。

\documentclass{book}

\usepackage[sorting = none, style = numeric, refsegment = chapter, cite reset = chapter]{bib latex}
\usepackage{nameref}

\defbibheading{bibintoc}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for Chapter \ref{refsegment:\therefsection\therefsegment} - \nameref{refsegment:\therefsection\therefsegment}}}

\defbibheading{bibintoc2}{%
  \addcontentsline{toc}{chapter}{\bibname}%
  \section*{References for the \nameref{refsection:\therefsection}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents}
\addbibresource{\jobname.bib}

\begin{document}

\chapter*{Introduction}
\begin{refsection}
\cite{A01}
\end{refsection}
\chapter{Chapter 1}

\cite{A01,B02}

\endrefsegment

\chapter*{Conclusion}
\begin{refsection}
\cite{C03}
\end{refsection}

\backmatter

\printbibheading
\printbibliography[section=1,heading=bibintoc2]
\bibbysegment[heading = bibintoc]
\printbibliography[section=2,heading=bibintoc2]

\end{document}

在此輸入影像描述

雖然這解決了您眼前的問題,但使用 s 作為引言和結論的解決方法refsection會導致這些章節完全獨立的參考書目標簽(請注意 C. Cuthor 的作品如何在結論中分配標籤“1”)。以下解決方案僅適用於refsegments (並由此實現整個文件唯一的標籤):

  • 不要使用有星號的版本\chapter*,但是\chapter 介紹和結論。這樣,refsegment將為這些章節分配一個(正)編號,並且可以使用 列印它們各自的參考文獻\bibbysegment

  • 使用\frontmatter\mainmatter\backmatter使引言和結論成為非編號章節。 (實際上,使用\boolfalse{@mainmatter}而不是\frontmatter避免切換到羅馬頁碼。)

  • \therefsegment宣告新的計數器來儲存front-resp 之後的值。 mainmatter,並在標題的新定義中使用這些計數器bibintoc2來實作 front-/main-/backmatter 引用的不同格式。


\documentclass{book}

\usepackage[sorting=none,style =numeric,refsegment=chapter,citereset=chapter]{biblatex}
\usepackage{nameref}

\newcounter{segmentendfront}
\newcounter{segmentendmain}

\defbibheading{bibintoc2}{%
  \addcontentsline{toc}{chapter}{\refname}%
  \section*{\refname\ for
    \ifnumgreater{\therefsegment}{\value{segmentendfront}}{%
      \ifnumgreater{\therefsegment}{\value{segmentendmain}}{%
        the
      }{%
        Chapter~\ref{refsegment:\therefsection\therefsegment} --
      }%
    }{%
      the
    }%
    \nameref{refsegment:\therefsection\therefsegment}%
  }%
}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
@misc{A01,
  author = {Author, A.},
  year = {2001},
  title = {Alpha},
}
@misc{B02,
  author = {Buthor, B.},
  year = {2002},
  title = {Bravo},
}
@misc{C03,
  author = {Cuthor, C.},
  year = {2003},
  title = {Charlie},
}
\end{filecontents}

\addbibresource{\jobname.bib}

\begin{document}

\boolfalse{@mainmatter}% instead of \frontmatter, which would also switch
    %to Roman page numbering

\chapter{Introduction}

\cite{A01}

\mainmatter
\setcounter{segmentendfront}{\therefsection\therefsegment}

\chapter{First chapter}

\cite{A01,B02}

\chapter{Second chapter}

\cite{B02}

\backmatter
\setcounter{segmentendmain}{\therefsection\therefsegment}

\chapter{Conclusion}

\cite{C03}

\printbibheading
\bibbysegment[heading=bibintoc2]

\end{document}

在此輸入影像描述

答案3

我認為你可以這樣做:

\chapter*{Introduction}
\begin{refsegment}
\cite{A01}
\end{refsegment}

編輯:結論的 refsegment 的問題不在於存在第二個 refsegment,而是使用選項refsegment=chapter命令\chapter插入 a \begin{refsegment}(或類似的東西),並且這不是由 `\chapter* 關閉的。

您可以在結論之前停止此部分:

\endrefsegment

\chapter*{Conclusion}

(更好的解決方案是\chapter*也打補丁)。

相關內容