I am writing a long report that needs the help of the subfiles package to break it into individual sections. It works like a charm until I further split one of the subfiles into two. Previously, the \ifSubfilesClassLoaded command helps distinguish whether a given file is compiled from main or subfiles shown in this thread. But when I get two levels of subfiles, it can no longer tell which level of subfiles it is working on.
Consider a hierarchy of files like this:
main.tex
myBib.bib
sections/section1.tex
materials/a_complex_table.tex
Here is a MWE:
%%%%%% main.tex
\documentclass[10pt]{article}
\usepackage[numbers,sort&compress]{natbib}
\usepackage{subfiles}
\begin{document}
\section{Section One}
\subfile{sections/section1.tex}
\bibliographystyle{ieeetr}
\bibliography{myBib}
\end{document}
%%%%%% section1.tex
% !TeX root = section1.tex
\documentclass[../main.tex]{subfiles}
\begin{document}
I like to cite \cite{A}
\subfile{../materials/a_complex_table.tex}
\ifSubfilesClassLoaded{
\bibliographystyle{ieeetr}
\bibliography{../myBib}
}{}
\end{document}
%%%%%% a_complex_table.tex
% !TeX root = a_complex_table.tex
\documentclass[../main.tex]{subfiles}
\begin{document}
\begin{table}[!htb]
\begin{tabular}{ l r }
Name & Reference \
A & \cite{A} \
B & \cite{B} \
G & \cite{G}
\end{tabular}
\end{table}
\ifSubfilesClassLoaded{
\bibliographystyle{ieeetr}
\bibliography{../myBib}
}{}
\end{document}
and my bibfile:
@book{A,
title={The meaning of A},
author={A. Alpha},
year=2020,
publisher={Apublisher}
}
@book{B,
title={The meaning of B},
author={B. Beta},
year=2021,
publisher={Bpublisher}
}
@book{G,
title={The meaning of G},
author={G. Gamma},
year=2022,
publisher={Gpublisher}
}
Typesetting main.tex and a_complex_table.tex both are fine, but compiling my section1.tex executes \bibliography{../myBib} twice since \ifSubfilesClassLoaded doesn't distinguish between subfiles. How can I fix this duplication?
