1

I am working on overleaf, and I am trying to set up a large project. When I compile main.tex the citation appears, but when I do the local compile of content/mini.tex they do not.

Any suggestions?

My main.tex

\documentclass[9pt]{book}
\usepackage{subfiles}

\begin{document}

A citation\cite{someone1981}

\subfile{content/mini}

\bibliography{bib} \bibliographystyle{apalike} \end{document}

And then the subfile: content/mini

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

\begin{document}

\section{In Subfile} This cite is in the subfile \cite{10.1007/978-3-031-20738-9_128}

\end{document}

JamesT
  • 3,169
  • 2
    Welcome to TeX.SE, how are you loading biblatex, is that the citation package you are using? Overleaf compiles the entire document without user input whereas local compilations require that you run biber (or bibtex), are you just running pdflatex on your document to compile it on your local system? You should run pdflatex then biber then pdflatex then pdflatex to compile it on your local system. Let us know how that goes and if it worked or not, if you don't know how to do that on your TeX local system let us know that too please :) – JamesT Jul 18 '23 at 18:10
  • 1
    As I understand it, the subfile package uses the preamble from the main file, i.e. nothing which comes later in the document. // Suggestion: move the bib-statements to a separate file and use \input{} in main and other files at the end. // And yes, you need to use the process JamesT describes. – MS-SPO Jul 18 '23 at 18:10
  • I am not using biblatex, just add \bibliography{} at the end. The document is compiled on overleaf with pdflatex – Carlos Mougan Jul 18 '23 at 18:17
  • 3
    why are you tagging your question with biblatex if you are not using it?? – Ulrike Fischer Jul 18 '23 at 18:23
  • 1
    For handling bibliography with subfiles, see ch. 3.3 in https://mirror.dogado.de/tex-archive/macros/latex/contrib/subfiles/subfiles.pdf , which describes conditional handling. – MS-SPO Jul 18 '23 at 18:27
  • content/mini.tex has no contents that tell LaTeX to generate a bibliography, so the citations will not be resolved. Even if the preamble of main.tex is brought in, there is no bibliography, since the main bit of the bibliography commands must be placed in the document body, which is not inherited. The easiest way to get a bibliography when compiling content/mini.tex is probably with \ifSubfilesClassLoaded as suggested by @MS-SPO in their comment above. ... – moewe Jul 18 '23 at 19:06
  • 1
    ... Note that the citation labels generated by compiling only a part of the document may deviate from the labels generated when compiling a larger document with more contents. But I guess you'll have to live with that. Personally, I think subfiles only makes sense if you actually expect to have to compile one of the parts of your large project as a stand-alone file. If that is not the case, it might be easier to work with \include and \includeonly. That also allows you to selectively compile just a part of your large project. – moewe Jul 18 '23 at 19:08

1 Answers1

1

As mentioned in the comments, you need a \bibliography command to generate the bibliography. In the subfile, use the command \ifSubfilesClassLoaded to make the generation conditional. The code below works when run locally.

With Overleaf, there is the problem that it cannot access the files in the parent folder when processing mini.tex, so bibtex fails with the error that ../bib.bib cannot be found. (I think this is because Overleaf copies the folder containing mini.tex and all subfolders, but not the parent folder, to some other place before running latex+bibtex.)

Here is the code that works locally:

% main.tex
\documentclass{book}
\bibliographystyle{apalike}
\usepackage{subfiles}
\begin{document}
A citation\cite{someone1981}
\subfile{content/mini}
\bibliography{bib}
\end{document}

% content/mini.tex \documentclass[../main]{subfiles} \begin{document} \section{In Subfile} This cite is in the subfile \cite{10.1007/978-3-031-20738-9_128} \ifSubfilesClassLoaded{% <<<<<<<<<<<<<<<<<<<<< \bibliography{../bib}% <<<<<<<<<<<<<<<<<<<<< }{}% <<<<<<<<<<<<<<<<<<<<< \end{document}

% bib.bib @Book{someone1981, author = {S.O.Meone}, title = {The title}, publisher = {Publisher}, year = {1981}, }

@InProceedings{10.1007/978-3-031-20738-9_128, author="Zhang, Zhe and Wang, Shenhang and Meng, Gong", editor="Xiong, Ning and Li, Maozhen and Li, Kenli and Xiao, Zheng and Liao, Longlong and Wang, Lipo", title="A Review on Pre-processing Methods for Fairness in Machine Learning", booktitle="Advances in Natural Computation, Fuzzy Systems and Knowledge Discovery", year="2023", publisher="Springer International Publishing", pages="1185--1191", isbn="978-3-031-20738-9" }

gernot
  • 49,614
  • Thanks!! This works for me, I have ended up doing something similar, and I have added some of the lines from this answer to have the bibliography at the end of the local and at the end of the global documetn https://tex.stackexchange.com/questions/478460/main-bibliography-at-the-end-of-the-main-document-and-at-the-end-of-the-subfiles?rq=1 – Carlos Mougan Jul 19 '23 at 18:38