使用子文件的章节参考书目

使用子文件的章节参考书目

介绍

我正在为我的一门大学课程撰写一份包含多项作业的报告。我的操作系统是 Windows,我使用 TeXstudio 作为编辑器。我使用该subfiles软件包是因为我希望每项作业都有单独的文件,能够独立编译每个文件,并最终将所有内容汇编成一个我必须交付的独特文档。我使用从该类report派生的自定义类,以便每项作业都构成chapter文档的一部分,因此每个子文件都包含一个chapter.

问题

我希望每一个chapter都有自己的参考书目(并且我将一个包含全局参考书目的文件(即全局参考书目)包含在相应的子文件中。然而,这已成为一场噩梦,因为我尝试了不同的解决方案但收效甚微。我的情况变得复杂,因为我使用该minted包来显示一些代码。当然,我需要-shell-escape在 TeXstudio 中调用该标志,但这似乎会干扰编译子文件时文件的生成.bbl

以下是对我的尝试的解释,在问题的最后,你可以找到包含所有尝试方法的 MWE。

尝试的解决方案

  • natbib+chapterbib方法:灵感来自这个答案(但是,其中\include代替\subfile)。如果minted包是不是使用时,编译子文件有效(即使参考书目中出现奇怪的东西,可能是由于选择的风格)但是当编译主文件时,整个参考书目会为每个章节重复,而只有与章节相关的参考书目应该出现。

chapter1.tex输出:

在此处输入图片描述

main.tex输出:

在此处输入图片描述

如果minted使用该包,则编译和.bbl时不会生成任何文件。chapter1.texmain.tex

chapter1.tex输出:

在此处输入图片描述

  • natbib+bibunits方法:灵感来自这个答案minted,无论是否使用 ,编译子文件时的输出都是相同的。但是,如果minted使用 ,则.bbl根本不会生成任何文件,相反,如果minted没有使用 ,chapter1.bbl则会生成文件,但显然bu1.bbl缺少一个文件。

chapter1.tex输出:

在此处输入图片描述

  • biblatex方法:灵感来自这个答案(但是没有使用subfiles包)。此尝试利用了refsection的功能。无论是否使用 ,biblatex编译子文件时的输出都是相同的:参考书目项目被识别,但参考书目本身不会被打印。非常奇怪的是,如果使用 ,则根本不会生成任何文件,而如果没有使用 ,则文件会出现在文件夹中。mintedminted.bblmintedchapter1.bbl

chapter1.tex输出:

在此处输入图片描述

项目结构和 MWE

所有方法均在列出的代码中报告,您可以通过在主文件和子文件中切换相应的行来从一种方法切换到另一种方法。您会注意到,我有一个bibgraf.bib级别为的文件和相应章节级别的文件。前者包括所有参考书目main.tex项目,而后者仅包括与章节相关的项目。我对方法没有任何偏好(要使用的包、一个主根文件或每个章节的多个文件等)。我只想让每个章节及其相应的参考书目都在子文件中。bibgraf1.bibbibgraf2.bib.bib.bib

-project
    -main.tex
    -bibgraf.bib
    -chapter1
        -chapter1.tex
        -bibgraf1.bib
    -chapter2
        -chapter2.tex
        -bibgraf2.bib

main.tex

% Definition of main command to access subfiles input both from master and slave files
\providecommand{\main}{.}

% Document class
\documentclass{report}

\usepackage[english]{babel} % management of culturally-determined typographical (and other) rules for the document language

% Package to generate code listing
\usepackage[newfloat]{minted}
% newfloat: the float package is used to create the listing environment

% Subfiles package
\usepackage{subfiles}

% Bibliography packages
%---- Natbib + chapterbib approach -----
%\usepackage[sectionbib,super,sort]{natbib}
%\usepackage{chapterbib}
%---------------------------------------
%---- Natbib + bibunit approach -----
%\usepackage[sectionbib]{natbib}
%\usepackage{bibunits}
%\defaultbibliographystyle{apsrev4-1}
%------------------------------------
%---- Biblatex approach -----
\usepackage{biblatex}
\addbibresource{bibgraf.bib}
%----------------------------

% Change chapter name
\addto\captionsenglish{\renewcommand{\chaptername}{Assignment}}

\begin{document}

    This is something from the main

    % First chapter
    \subfile{chapter1/chapter1}

    % Second chapter
    \subfile{chapter2/chapter2}

\end{document}

bibgraf.bib

@CONTROL{REVTEX41Control}
@CONTROL{apsrev41Control,author="00",editor="1",pages="1",title="0",year="0"}

@article{Kulfan2008,
    author = {Kulfan, B. M.},
    title = {Universal Parametric Geometry Representation Method},
    journal = {Journal of Aircraft},
    volume = {45},
    number = {1},
    pages = {142-158},
    year = {2008},
    doi = {10.2514/1.29958},
    URL = { 
    https://doi.org/10.2514/1.29958
    },
    eprint = { 
    https://doi.org/10.2514/1.29958
    }
}

@book{anderson,
    title={Fundamental of Aerodynamics},
    author={Anderson, Jr., J. D.},
    isbn={9781259010286},
    series={McGraw-Hill Series in Aeronautical and Aerospace engineering},
    url={https://books.google.nl/books?id=xVsiAwAAQBAJ},
    year={2011},
    edition={5},
    publisher={McGraw-Hill}
}

@book{abbott,
    title={Theory of Wing Sections},
    subtitle={Including a Symmary of Airfoil Data},
    author={Abbott, I. H. and von Doenhoff, A. E.},
    isbn={9780486605869},
    series={Dover Books on Aeronautical Engineering Series},
    year={1959},
    publisher={Dover Pubblications}
}

chapter1.tex

%!TeX root = chapter1

\providecommand{\main}{..}

\makeatletter
\def\input@path{{\main/}}
\makeatother

\documentclass[\main/main.tex]{subfiles}

\begin{document}

    %---- Natbib + bibunit approach -----
%   \begin{bibunit}
%       \chapter{First chapter}
%       This is chapter 1 reference test: \cite{Kulfan2008}, \cite{anderson}.
%       \subsection*{References}
%       \putbib[\main/chapter1/bibgraf1]
%   \end{bibunit}
    %------------------------------------

    %---- Natbib + chapterbib approach -----
%   \chapter{First chapter}
%   This is chapter 1 reference test: \cite{Kulfan2008}, \cite{anderson}.
%   \nocite{apsrev41Control}
%   \bibliographystyle{apsrev4-1}
%   \bibliography{\main/bibgraf}
    %---------------------------------------

    %--------- Biblatex approach ----------
    \newrefsection
    \chapter{First chapter}
    This is chapter 1 reference test: \autocite{Kulfan2008}, \autocite{anderson}.
    \printbibliography
    %--------------------------------------

\end{document}

bibgraf1.bib

@CONTROL{REVTEX41Control}
@CONTROL{apsrev41Control,author="00",editor="1",pages="1",title="0",year="0"}

@article{Kulfan2008,
    author = {Kulfan, B. M.},
    title = {Universal Parametric Geometry Representation Method},
    journal = {Journal of Aircraft},
    volume = {45},
    number = {1},
    pages = {142-158},
    year = {2008},
    doi = {10.2514/1.29958},
    URL = { 
    https://doi.org/10.2514/1.29958
    },
    eprint = { 
    https://doi.org/10.2514/1.29958
    }
}

@book{anderson,
    title={Fundamental of Aerodynamics},
    author={Anderson, Jr., J. D.},
    isbn={9781259010286},
    series={McGraw-Hill Series in Aeronautical and Aerospace engineering},
    url={https://books.google.nl/books?id=xVsiAwAAQBAJ},
    year={2011},
    edition={5},
    publisher={McGraw-Hill}
}

chapter2.tex

%!TeX root = chapter2

\providecommand{\main}{..}

\makeatletter
\def\input@path{{\main/}}
\makeatother

\documentclass[\main/main.tex]{subfiles}

\begin{document}

    %---- Natbib + bibunit approach -----
%   \begin{bibunit}
%       \chapter{Second chapter}
%       This is chapter 2 reference test: \cite{Kulfan2008}, \cite{abbott}.
%       \subsection*{References}
%       \putbib[\main/chapter2/bibgraf2]
%   \end{bibunit}
    %------------------------------------

    %---- Natbib + chapterbib approach -----
%   \chapter{Second chapter}
%   This is chapter 2 reference test: \cite{Kulfan2008}, \cite{abbott}.
%   \nocite{apsrev41Control}
%   \bibliographystyle{apsrev4-1}
%   \bibliography{\main/bibgraf}
    %---------------------------------------

    %--------- Biblatex approach ----------
    \newrefsection
    \chapter{Second chapter}
    This is chapter 2 reference test: \autocite{Kulfan2008}, \autocite{abbott}.
    \printbibliography
    %--------------------------------------

\end{document}

bibgraf2.bib

@CONTROL{REVTEX41Control}
@CONTROL{apsrev41Control,author="00",editor="1",pages="1",title="0",year="0"}

@article{Kulfan2008,
    author = {Kulfan, B. M.},
    title = {Universal Parametric Geometry Representation Method},
    journal = {Journal of Aircraft},
    volume = {45},
    number = {1},
    pages = {142-158},
    year = {2008},
    doi = {10.2514/1.29958},
    URL = { 
    https://doi.org/10.2514/1.29958
    },
    eprint = { 
    https://doi.org/10.2514/1.29958
    }
}

@book{abbott,
    title={Theory of Wing Sections},
    subtitle={Including a Symmary of Airfoil Data},
    author={Abbott, I. H. and von Doenhoff, A. E.},
    isbn={9780486605869},
    series={Dover Books on Aeronautical Engineering Series},
    year={1959},
    publisher={Dover Pubblications}
}

答案1

子书目适用于subfiles从 1.5 版开始,Github或来自加拿大运输安全局. 参见其文档注意,不再需要自己操作文件路径。下面我展示如何使用包排版子书目

(A) chapterbib

(二) bibunits

(C) biblatex

对于每一种情况,我们都考虑两种文件结构。

(1)顶级目录中的 bib 文件

main.tex
bib1.bib
bib2.bib
chapter1/chapter1.tex
chapter2/chapter2.tex

(2)子目录中的 bib 文件

main.tex
chapter1/bib1.bib
chapter1/chapter1.tex
chapter2/bib2.bib
chapter2/chapter2.tex

bib 文件包含以下条目。

% bib1.bib
@book{A,
    title={The meaning of A},
    author={A. Alpha},
    year=2019,
    publisher={Apublisher}
}

% bib2.bib
@book{B,
    title={The meaning of B},
    author={B. Beta},
    year=2019,
    publisher={Bpublisher}
}

(A1)chapterbib主目录中的包、bib 文件

% main.tex
\documentclass{report}
\usepackage{chapterbib}
\usepackage{subfiles}
\begin{document}
\subfileinclude{chapter1/chapter1}
\subfileinclude{chapter2/chapter2}
\end{document}    

% chapter1/chapter1.tex
\documentclass[../main]{subfiles}
\begin{document}
\chapter{First chapter}
My references: \cite{A}
\bibliographystyle{alpha}
\bibliography{../bib1,../bib2}
\end{document}

% chapter2/chapter2.tex
\documentclass[../main]{subfiles}
\begin{document}
\chapter{Second chapter}
My references: \cite{B}
\bibliographystyle{alpha}
\bibliography{../bib1,../bib2}
\end{document}

要排版main.tex,请运行

pdflatex main
bibtex chapter1/chapter1
bibtex chapter2/chapter2
pdflatex main
pdflatex main

要单独排版其中一章,请运行

cd chapter1
pdflatex chapter1
bibtex chapter1
pdflatex chapter1
pdflatex chapter1

(A2)chapterbib子目录中的包、bib 文件

与 (A1) 类似,但将\bibliography命令改为\bibliography{bib1}inchapter1.tex\bibliography{bib2}in chapter2.tex

(B1)bibunits主目录中的包、bib 文件

% main.tex
\documentclass{report}
\usepackage{bibunits}
\defaultbibliographystyle{apalike}
\usepackage{subfiles}
\begin{document}
\subfile{chapter1/chapter1}
\subfile{chapter2/chapter2}
\end{document}

% chapter1/chapter1.tex
\documentclass[../main]{subfiles}
\begin{document}
\begin{bibunit}
\chapter{First chapter}
My references: \cite{A}
\putbib[\subfix{../bib1},\subfix{../bib2}]
\end{bibunit}
\end{document}

% chapter2/chapter2.tex
\documentclass[../main]{subfiles}
\begin{document}
\begin{bibunit}
\chapter{Second chapter}
My references: \cite{B}
\putbib[\subfix{../bib1},\subfix{../bib2}]
\end{bibunit}
\end{document}

要排版主文档,请运行

pdflatex main
bibtex bu1
bibtex bu2
pdflatex main
pdflatex main

要单独排版章节,请运行

cd chapter1
pdflatex chapter1
bibtex bu1
pdflatex chapter1
pdflatex chapter1

(B2)bibunits子目录中的包、bib 文件

与 (B1) 类似,但将\putbib命令改为\putbib[\subfix{bib1}]inchapter1.tex\putbib[\subfix{bib2}]in chapter2.tex

(C1)包biblatex,主目录中的 bib 文件

% main.tex
\documentclass{report}
\usepackage{biblatex}
\usepackage{subfiles}
\bibliography{bib1,bib2}
\begin{document}
\subfileinclude{chapter1/chapter1}
\subfileinclude{chapter2/chapter2}
\end{document}

% chapter1/chapter1.tex
\documentclass[../main]{subfiles}
\begin{document}
\newrefsection
\chapter{First chapter}
My references: \cite{A}
\printbibliography
\end{document}

% chapter2/chapter2.tex
\documentclass[../main]{subfiles}
\begin{document}
\newrefsection
\chapter{Second chapter}
My references: \cite{B}
\printbibliography
\end{document}

要排版主文档,请运行

pdflatex main
biber main
pdflatex main
pdflatex main

要单独排版章节,请运行

cd chapter1
pdflatex chapter1
biber chapter1
pdflatex chapter1
pdflatex chapter1

(C2)包biblatex,子目录中的 bib 文件

与 (C1) 类似,但将\bibliography中的命令替换main.tex\bibliography{chapter1/bib1,chapter2/bib2}

注意文件名及其路径

一般情况下,文件名(带有可选路径)必须用 包围\subfix{...},如 (B1) 和 (B2) 中所示。该\bibliography命令已\subfix内置此魔法,因此\subfix在 (A1)、(A2)、(C1) 和 (C2) 中不需要 (事实上,它反而会把事情搞乱)。

相关内容