0

I use the subfiles package to divide the main document I'm working on into chapters, so that I don't have to compile the whole document everytime.

This means that I don't print the bibliography in any of the separate chapter files, I only print in the main file. When compiling the separate chapters, this results in a warning from hyperref, complaining about the lack of bibliography, as already discussed here.

The solution posted there is to use the package option hyperref=false when loading biblatex. This solves the problem in the chapter files, but now I don't have links in the main file.

So my question is: is there a way to differentiate the main file from the others, so that I can use some code like:

\ifmaindocument{\usepackage[backend=biber]{biblatex}}
\ifsubdocument{\usepackage[backend=biber, hyperref=false]{biblatex}}

in the preamble?

2 Answers 2

1

One thing which is different between the main file and the subfile is the name. Assuming your main file is called main.tex:

\usepackage{xstring}

\IfEq{\jobname}{\detokenize{main}}{%
    % stuff for main file
}{%
  % stuff for subfile
}
1

Your newest question gave me another idea that does not require additional packages:

\makeatletter
\ifdefined\preamble@file
    % stuff for the subfile
\else
    % stuff for the main file
\fi
\makeatother
2
  • Damn, you stalking me? Ahaha just joking. This is actually a very nice solution to both those problems, AND it doesn't require any additional packages. I'd accept both the answers if I could, thanks a lot.
    – noibe
    Apr 29, 2019 at 23:30
  • @noibe I was about to answer the other question, but was 3 seconds too slow, so I thought I could to put the \preamble@file to good use here :)
    – user187808
    Apr 29, 2019 at 23:31

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .