I am using Windows as OS and TeXstudio as editor.

My project has the following structure:


I am using the subfiles package in order to compile independently the various chapters of my document. I would like the chapters to have their own references, both when compiling those independently and when compiling the entire document from main.tex. However, now I have to change the \bibliography argument according to whether I am compiling chapterN.tex or main.tex. More specifically, I have to type \bibliography{bibgraf} if I am compiling the former and \bibliography{chapterN/bibgraf} if I am compiling the latter.

How can I use \bibliography{something} so that both matin.tex and chapterN.tex compile successfully?



%%%%%%%%%%%%%%%%%%%%%%%% Identification %%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e} % sets the LATEX version for the class to work
\ProvidesClass{myclass} % identification of the class

%%%%%%%%%%%%%%%%%%%%%%%% Preliminary declarations %%%%%%%%%%%%%%%%%%%%%%%%
\LoadClass[a4paper,12pt]{report} % loads the class report

%----------------------- General use packages -----------------------
\RequirePackage[english]{babel} % management of culturally-determined typographical (and other) rules for the document language
\RequirePackage[utf8]{inputenc} % use of non-ASCII characters
\RequirePackage[T1]{fontenc} % use of even more non-ASCII characters (T1 font enconding)
\RequirePackage{float} % include [H] option for figures and tables
\RequirePackage{graphicx} % provides a key-value interface for optional arguments to the \includegraphics command

% Package for customising citations (especially author-year citation schemes) when using BibTeX
% numbers: allow numeric citations
% square: enable squared brackets
% sectionbib: to be used with the package chapterbib to add the bibliography to the table of contents as a unnumbered section instead of an unnumbered chapter

% Package that facilitates multiple bibliographies in a LATEX document

%%%%%%%%%%%%%%%%%%%%%%%% Options %%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%% More declarations %%%%%%%%%%%%%%%%%%%%%%%%

% The commands define \main as . (same folder)

% Set graphics path

% Set BibTeX style to apsrev4-1

% Change name of bibliography







Hallo main








%% my chapter 1 content
Hallo, this is a test:
\int dx =0

\onlyinsubfile{this only appears if chapter1.tex is compiled (not when main.tex is compiled)}
\notinsubfile{this only appears if main.tex is compiled (not when chapter1.tex is compiled)}

This is a reference test: \cite{anderson}

\onlyinsubfile{Call reference}



    title={Fundamental of Aerodynamics},
    author={Anderson, Jr., J. D.},
    series={McGraw-Hill Series in Aeronautical and Aerospace engineering},

Your Answer

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

Browse other questions tagged or ask your own question.