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
+chapterbib
approach: inspired by this answer (where however\include
is used instead of\subfile
). If theminted
package 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
+bibunits
approach: inspired by this answer, the output when compiling the subfile is the same whetherminted
is in use or not. However, ifminted
is used, no.bbl
file at all is generated, instead ifminted
is not used thechapter1.bbl
file is generated, but apparently abu1.bbl
file is missing.
chapter1.tex
output:
biblatex
approach: inspired by this answer (where however there is no use ofsubfiles
package). This attempt makes use of therefsection
feature ofbiblatex
. The output when compiling the subfile is the same whetherminted
is in use or not: the bibliography items are recognized but the bibliography itself is not printed. It is quite curious that ifminted
is used, no.bbl
file at all is generated, instead ifminted
is not used thechapter1.bbl
file 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}
}