biblatex 章ごとの参考文献と titlesec

biblatex 章ごとの参考文献と titlesec

これは前回の質問の続きですBiblatex を使用して章ごとの参考文献に番号なしの章を含める適切な方法

Audrey が提案した解決策は、titlesecパッケージを使用して章の見出しを変更すると機能しなくなります。MWE は次のとおりです。

\documentclass{book}


\usepackage{titlesec}           
\usepackage{titletoc}

\setcounter{tocdepth}{3}

\usepackage[style = phys,%
            sorting=none,%
            backend=biber,%
            style=numeric,%
            hyperref=auto,%
            backref = true,%
            refsection=chapter,%
%           citereset=chapter,%
            dateabbrev=false,%
            urldate=comp]{biblatex}

\usepackage{nameref}

\makeatletter
% Extend biblatex's \chapter patch to \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}}}}
% Save data for bibliography titles
\apptocmd\@makechapterhead
  {\csdef{subbib:\therefsection}{%
     Chapter~\ref{refsection:\therefsection} - \nameref{refsection:\therefsection}}}{}{}
\apptocmd\@makeschapterhead
  {\csdef{subbib:\therefsection}{%
     \nameref{refsection:\therefsection}}}{}{}

\makeatother

\defbibheading{subbibliography}{%
  \section*{References for \csuse{subbib:\therefsection}}}

\titleformat{\chapter}[hang]
{\bfseries \LARGE \bfseries }{ \thechapter}{0.75em}{}[\vspace{2ex}\titlerule]
\titlespacing*{\chapter}{0cm}{0cm}{0.6cm}

\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{refsegment}
\cite{A01}
\end{refsegment}
\chapter{Chapter 1}

\cite{A01,B02}

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

\backmatter

\printbibheading[heading=bibintoc]
\bibbysection[heading = subbibliography]

\end{document}

参考文献の結果は次のようになります。

ここに画像の説明を入力してください

ご覧のとおり、章への参照は消えています。疑問符さえありません。これは、の\csuse{subbib:\therefsection}}を使用した章形式の再定義を挿入した後、Audrey によるソリューションの部分が何も指さなくなることを意味していると思います。titlesec\titleformat

また、\titleformat{...}章見出しの再定義を biblatex パッチの前に置くと、次のエラーで終了しますargument of \csdef has an extra }

これを回避する方法はありますか?

答え1

章マクロの追加が問題である可能性があります。タイトルの制御シーケンス定義を の先頭biblatex追加パッチの直後に移動できます。

\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}}}}

関連情報