编译子文件和主文件时获取每个子文件的参考书目

编译子文件和主文件时获取每个子文件的参考书目

我有一个包含多个文件的项目(见 overleaf)。我之所以使用 是subfiles因为我希望合作者能够在离线工作时编译他们的子文件。但同时能够编译整个项目。我们使用了类似的结构,但没有 ,subfiles但使用了includechapterbib。这样可以毫无问题地编译整个项目,但无法单独编译每个子文件。

我的目标是为每个子文件提供一个参考书目(而不是为整个项目提供一个参考书目)。

目前的情况是,我可以编译每个子文件,并根据引用生成其参考书目。但是,当我尝试编译主项目文件时,出现了问题,它似乎试图将第一个子文件的参考书目用于第二个子文件。

结构如下:

├── bibs # folder to save a bib file per subfile
│   ├── text1.bib
│   └── text2.bib
├── main.tex # main latex project file
├── misc
│   └── bibnosec.sty # a little patch
├── my-class.cls # my class
├── text1.tex # a subfile
└── text2.tex # another subfile

梅威瑟:

bibs/text1.bib

@inproceedings{Kermes2016,
    address = {Portoroz, Slovenia},
    author = {Kermes, Hannah and Knappen, J{\"{o}}rg and Degaetano-Ortlieb, Stefania and Teich, Elke},
    booktitle = {In Proceedings of the Ninth International Conference on Language Resources and Evaluation (LREC'16)},
    title = {{The Royal Society Corpus: From Uncharted Data to Corpus}},
    year = {2016}
}

@inproceedings{Khamis-etal2015,
    address = {Lancaster},
    author = {Khamis, Ashraf and Degaetano-Ortlieb, Stefania and Kermes, Hannah and Knappen, J{\"{o}}rg and Ordan, Noam and Teich, Elke},
    booktitle = {Corpus Linguistics 2015},
    month = jul,
    title = {{A resource for the diachronic study of scientific English: Introducing the Royal Society Corpus}},
    year = {2015}
}

bibs/text2.bib

@inproceedings{Khamis-etal2015,
    address = {Lancaster},
    author = {Khamis, Ashraf and Degaetano-Ortlieb, Stefania and Kermes, Hannah and Knappen, J{\"{o}}rg and Ordan, Noam and Teich, Elke},
    booktitle = {Corpus Linguistics 2015},
    month = jul,
    title = {{A resource for the diachronic study of scientific English: Introducing the Royal Society Corpus}},
    year = {2015}
}

@inproceedings{Degaetano-etal2015b,
    address = {RWTH Aachen University},
    author = {Degaetano-Ortlieb, Stefania and Kermes, Hannah and Khamis, Ashraf and Knappen, J{\"{o}}rg and Ordan, Noam and Teich, Elke},
    booktitle = {"Challenging Boundaries" - 42nd International Systemic Functional Congress (ISFCW2015)},
    month = jul,
    title = {{Information Density in Scientific Writing: A Diachronic Perspective}},
    year = {2015}
}

misc/bibnosec.sty

\ProvidesPackage{bibnosec}[2013/07/08 Bibliographies without sections (JKn)]
% This is the thebibliography environment from article.cls with
% two lines commented out
\renewenvironment{thebibliography}[1]
     {%\section*{\refname}%
      %\@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}}%
      \endlist}
\endinput

main.tex

\documentclass{my-class}
\begin{document}
\subfile{text1}
\subfile{text2}
\end{document}

my-class.cls

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{my-class}[2017/02/13 My MWE class]

% PAGE FORMAT
\LoadClass[a4paper,10pt,twoside]{article}

\RequirePackage{subfiles}

% BIBLIOGRAPHY
% bibliography management
\RequirePackage[sectionbib]{natbib}
% to enable multiple bibliographies in a document
\RequirePackage[sectionbib]{chapterbib}
% custom local package
\RequirePackage{misc/bibnosec}

text1.tex

\documentclass[main.tex]{subfiles}
\begin{document}
\section{This is section 1}
See \cite{Kermes2016} or \cite{Khamis-etal2015} for examples.
\subsection*{References}
\bibliographystyle{apalike}
\bibliography{bibs/text1}
\end{document}

text2.tex

\documentclass[main.tex]{subfiles}
\begin{document}
\section{This is section 2}
See \cite{Degaetano-etal2015b} or \cite{Khamis-etal2015} for examples.
\subsection*{References}
\bibliographystyle{apalike}
\bibliography{bibs/text2}
\end{document}

答案1

(您可以共享 Overleaf 项目的只读 URL;其他用户可以克隆文件并立即在副本中编辑它们;-)

这个包似乎比这个例子bibunits效果更好。以下是我做的:chapterbib

main.tex

\documentclass{my-class}
\usepackage{bibunits} % <-- the magical package!
%% Assuming all subfiles will use the same style
\defaultbibliographystyle{apalike}
\begin{document}
\subfile{text1}
\subfile{text2}
\end{document}

text1.tex

\documentclass[main.tex]{subfiles}
\begin{document}
\begin{bibunit}  % <-- add this line
\section{This is section 1}
See \cite{Kermes2016} or \cite{Khamis-etal2015} for examples.
\subsection*{References}
\putbib[bibs/text1]  % <-- your .bib file here!
\end{bibunit}    % <-- add this line
\end{document}

对于 也类似text2.tex

可以在以下位置找到一个工作示例https://www.overleaf.com/read/fscqhqtyhhpk。点击顶栏中的“PROJECT”切换文件列表面板;点击“Clone this project”获取可编辑的副本。

答案2

我尝试了一种解决方法。这实际上不是一个解决方案,但对于我的用例来说有效。

由于该项目位于 overleaf 中,因此默认情况下将编译主文件。为了避免任何问题,\subfile{text1.tex}我使用而不是 使用\include{text1.tex}

main.tex

\documentclass{my-class}
\begin{document}
\include{text1}
\include{text2}
\end{document}

然后我对前两行和最后一行都进行了text1.tex注释text2.tex

text1.tex

% \documentclass[main.tex]{subfiles}
% \begin{document}
\section{This is section 1}
See \cite{Kermes2016} or \cite{Khamis-etal2015} for examples.
\subsection*{References}
\bibliographystyle{apalike}
\bibliography{bibs/text1}
% \end{document}

它与之一起工作,chapterbib所以结果符合预期——每个书目都在其子文件的末尾进行编译。

如果只想编译子文件(本地工作),只需取消注释相同的三行即可仅编译带有参考书目的子文件。

理想情况下,我希望避免注释和取消注释行。因此,欢迎任何其他方法。

相关内容