0

Firstly apologies if this is a silly mistake on my part.

I am writing my thesis and using subfiles for each chapter. I would like a reference section at the end of each chapter so I am therefore using chapterbib. I am also using the package achemso.

I'm having problems with compiling the subfiles in the main document. This could be the way that I am building the file, but it seems to work nicely for one subfile just not any more than that.

So I build each chapter (let's call it chapter1.tex) by:

Build (LuaLatex) Bibtex Build (LuaLatex) Build (LuaLatex)

Then the main document in the same way (let's call it thesis.tex)

Build (LuaLatex) Bibtex Build (LuaLatex) Build (LuaLatex)

The structure of my main document is something like:

\documentclass[11pt]{report}
\usepackage{achemso}
\usepackage[sectionbib]{chapterbib}
\usepackage[nottoc,numbib]{tocbibind}
\usepackage{subfiles}

\begin{document}
\subfile{../chapter1/chapter1.tex}
\subfile{../chapter2/chapter2.text}
\subfile{../chapter3/chapter3.text}
\subfile{../chapter4/chapter4.text}
\end{document}

And for my subfiles something like:

\documentclass[../Thesis/thesis.tex]{subfiles}

 \begin{document}

main text

\bibliography{../library}

\end{document}

Any help would be greatly appreciated.

Just to clarify, I can build the main document (thesis.tex) with the subfiles, but no references are included. Trying to then build the main document with bibtex pulls up an error something like:

The style file: achemso.bst Illegal, another \bibdata command---line 793 of file

This does not happen with only one subfile.

1

Perhaps a bit late for you, but I've been wrestling with a similar problem and this may help others.

I've not found a good way to use chapterbib with subfiles (according to the documentation, you could use \begin{cbunit}, although I had no joy with that, or \cbinput, but that looks like more effort than it's worth).

In most cases, however, it would be possible to use \include instead of \subfile (you will need to remove the preamble from your subfiles to do this). This works well with chapterbib.

There may also be a problem with \achemso when the root document has no citations (here, here), so avoid that if you can. You should be able to use the .bst files without using the rest of the package if, needed.

So your document would become something like:

\documentclass[11pt]{report}
\usepackage[sectionbib, super, sort]{natbib}
\usepackage{chapterbib}
\usepackage[nottoc,numbib]{tocbibind}

\begin{document}
\include{../chapter1/chapter1}
\include{../chapter2/chapter2}
\include{../chapter3/chapter3}
\include{../chapter4/chapter4}
\end{document}

And your chapters something like:

\chapter{Chapter 1}
main text

\bibliograpystyle{yourchosenstyle}
\bibliography{../library}

The other, critical, step is building everything correctly. This is more likely to be an issue if you're using a GUI such as TeX Studio. If that's the case, I'd suggest you manually delete all the auxiliary files generated when running Latex (ie. everything you didn't put there) and manually running pdflatex on the root doc, bibtex on each chapter and then pdflatex twice on the root doc from a terminal.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.