Introduction
I am writing a report consisting of several assignments for one of my university courses. My OS is Windows and I use TeXstudio as editor. I am using the subfiles package as I want to have separate files for each assignment, being able to compile each file independently and finally assemble everything in one unique document that I have to deliver. I am using a custom class derived from the report class so that each assignment constitutes a chapter of the document and thus each subfile contains a single chapter.
Problem
I would like each chapter to have its own bibliography (and no global bibliography), included in the corresponding subfile. However this has become a nightmare, since I have tried different solutions with little success. A complication of my situation is given by the fact that I use the minted package to display some code. Of course I need to invoke the -shell-escape flag in TeXstudio, but this seems to interfere with the generation of .bbl file when compiling the subfile.
An explanation of my attempts follows and at the end of the question you can find a MWE including all attempted approaches.
Attempted solutions
natbib+chapterbibapproach: inspired by this answer (where however\includeis used instead of\subfile). If themintedpackage is not used, compiling subfile works (even if weird stuff appears in the bibliography, probably due to the style chosen) but when the main file is compiled the entire bibliography is repeated for each chapter, whereas only the chapter-related bibliography should appear.
chapter1.tex output:
main.tex output:
If the minted package is used, no .bbl file is generated when both chapter1.tex and main.tex are compiled.
chapter1.tex output:
natbib+bibunitsapproach: inspired by this answer, the output when compiling the subfile is the same whethermintedis in use or not. However, ifmintedis used, no.bblfile at all is generated, instead ifmintedis not used thechapter1.bblfile is generated, but apparently abu1.bblfile is missing.
chapter1.tex output:
biblatexapproach: inspired by this answer (where however there is no use ofsubfilespackage). This attempt makes use of therefsectionfeature ofbiblatex. The output when compiling the subfile is the same whethermintedis in use or not: the bibliography items are recognized but the bibliography itself is not printed. It is quite curious that ifmintedis used, no.bblfile at all is generated, instead ifmintedis not used thechapter1.bblfile appears in the folder.
chapter1.tex output:
Project structure and MWE
All approaches are reported in the codes listed, you can switch from one approach to the other by toggling the corresponding lines in both the main and the subfile. You will notice that I have both a bibgraf.bib file at the level of main.tex and bibgraf1.bib, bibgraf2.bib files at the level of the corresponding chapters. The former includes all bibliography items, while the latters only the chapter-related items. I do not have any preference regarding the approaches (packages to use, one main root .bib file or multiple .bib files for each chapter, etc.) I would just like to have each chapter with its corresponding bibliography within the subfile.
-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}
}





\bibliography{bib1}inchapter1/chapter1.tex– Andrew Jaffe Jan 28 '21 at 16:42bibfiles*.tex, and also that I think you need to runpdflatexon each of the chapter files (from their own directories) to create theauxfiles before you can run BibTeX. – Andrew Jaffe Jan 28 '21 at 22:46\includestatements (instead of\input), LaTeX generates separateauxfiles for the included files. I've actually tested all versions (with the correct extensions). – gernot Jan 28 '21 at 22:53pdflatexruns -- that was a holdover from my attempts to use plain\subfileinstead of\subfileinclude, which I could never get to work... – Andrew Jaffe Jan 28 '21 at 23:29subfiles(and of TeX alltogether), which should work as well (and indeed works in my test environment). I tried to copy it to Overleaf, but have difficulties to tell it to run latex/bibtex/... on the right files in the right order. Giving up ... – gernot Jan 29 '21 at 09:48\subfixin all (C) cases. I use\printbibliographyat the end of the main file. – Minh Nghĩa May 30 '21 at 00:02