サブファイル使用時の参考文献

サブファイル使用時の参考文献

私は、Biblatex を使用して XeLaTeX で博士論文を書いています。個々の章をコンパイルする必要がある場合と、ドキュメント全体をコンパイルする必要がある場合があり、サブファイルを使用しています。これは非常に便利です。ただし、これらの各章にはコマンドがあり\printbibliography、最終ドキュメントをコンパイルするときには、メインファイルでコマンドのみが実行されるように、そのコマンドをオフにしたいと考えています\printbibliography

ファイル構造は次のようになります。

Main.tex:

\usepackage{subfiles, biblatex}
\begin{document}

\subfile{Chapter1.tex}

\printbibliography
\end{document}

Chapter1.tex:

\documentclass[Main.tex]{subfiles}
\begin{document}
\cite{Someguy1981}
\printbibliography
\end{document}

答え1

subfiles.styコマンドは\subfile次のように定義されます:

\newcommand\subfile[1]{\begingroup\skip@preamble\input{#1}\endgroup}

したがって、ローカルで何もしないように再定義するコードをフックするのは簡単です\printbibliography。例として、メイン ファイルのプリアンブルに次のコードを追加します。

\makeatletter

\newrobustcmd*{\nobibliography}{%
  \@ifnextchar[%]
    {\blx@nobibliography}
    {\blx@nobibliography[]}}

\def\blx@nobibliography[#1]{}

\appto{\skip@preamble}{\let\printbibliography\nobibliography}

\makeatother

では、引用コマンドを介して書誌データを利用できるようになることに注意してくださいbiblatex。したがって、メイン ファイルの外部で書誌エントリを表示する場合を除き、サブファイルで を呼び出す必要はありません\printbibliography

答え2

私はオードリーのアプローチも利用しました(https://tex.stackexchange.com/a/107111/85983) をしばらく使っていましたが、\printbibliography各サブファイルの最後に記述しなければならないのが面倒になりました。現在は、メイン ファイルのプリアンブルで次の Latex フックを使用しています。

%%% Default start and end for each subfile
\AtBeginDocument{%
}

\AtEndDocument{%
    \printbibliography
    \listoffigures
    \listoftables
    \newpage
    \printacronyms[include-classes=abbrev,name=Acronyms]
}

答え3

サブファイルのバージョン2.0以降では、条件マクロを使用して、\ifSubfilesClassLoaded{}{}Audreyのアプローチと同様のことを行うこともできます(https://tex.stackexchange.com/a/107111/85983)。

私の設定では、MWE は次のようになります。

メイン.tex

\documentclass{book}
\usepackage{biblatex}
\usepackage{subfiles} % must be last usepackage

\providecommand{\topdir}{.}
\addglobalbib{\topdir/references.bib} % topdir is needed here so that
                                      % we can resolve the path in the subfile
                                      % correctly. There we re-define the
                                      % topdir macro to the location of the
                                      % bib file.

\begin{document}
\subfile{dir/sub}
\printbibliography[heading=bibintoc]{}
\end{document}

サブ.tex

\providecommand{\topdir}{..} % reset all paths to location of main.tex
\documentclass[../main.tex]{subfiles}

\begin{document}
% some content with citations

\ifSubfilesClassLoaded{%
    \printbibliography{}
}{} % we have no 'else' action
\end{document}

答え4

別の方法としては、サブファイルとメインファイルをジョブ名で区別する方法があります。メインファイルが と呼ばれThesis.tex、ジョブ名は通常 であるとするThesisと、次のようにテストできます。

\IfEq{\jobname}{\detokenize{Thesis}}{}{%
    \AtEndDocument{%
        \printbibliography%
    }
}

これにより、サブファイルの最後に参考文献が挿入され、メイン ファイルでは何も行われません。

(可能であればこれを の前に使用してください\usepackage{biblatex}。そうしないと警告が表示される場合があります。\AtEndDocument{\printbibliography} の未定義参照の警告

関連情報