gsalzer / subfiles

class and package for multi-file projects in LaTeX
LaTeX Project Public License v1.3c
25 stars 1 forks source link

Citations in subfiles #24

Closed atlewf closed 3 years ago

atlewf commented 3 years ago

Similar issue to #7. I am using the natbib package as citation tool. I have included

\ifSubfilesClassLoaded{
    \bibliography{references}
    }{}

at the end of each subfile (before \enddocument). This works perfectly fine for compiling just the subfiles, but when compiling main.tex the bibliography is included at the end of each chapter. Also, the error "undefined control sequence" appear next to the line where "ifSubfilesClassLoaded" begins. Do you have a solution to this?

gsalzer commented 3 years ago

The error messages says that \ifSubfilesClassLoaded does not exist. This indicates that you use the subfiles package in a version prior to 2.0. The command is available in 2.0, 2.1, 2.2 (latest version). To find out which version you use, search in the log file for subfiles; when loading it, the version number should appear.

If you work with your own latex distribution, then update the subfiles package. On Overleaf, the globally installed version is 1.6; maybe it works if you install your own updated subfiles.sty and subflies.cls.

A work-around is to include the following lines into your preamble:

\usepackage{subfiles}
\makeatletter
\providecommand\ifSubfilesClassLoaded{%
  \expandafter\ifx\csname ver@subfiles.cls\endcsname\relax
    \expandafter\@secondoftwo
  \else
    \expandafter\@firstoftwo
  \fi
}
\makeatother

As soon as the subfiles package is upgraded, this extra definition will become obsolete, but will not do any harm. If you use \newcommand instead of \providecommand, you will notice the upgrade since you will get the error command already defined, and then can remove the patch.

atlewf commented 3 years ago

I am working on Overleaf, and the \newcommand trick worked perfectly. Thank you!