3

I am considering whether to to try to use subfiles with memoir, biber, and xelatex. Before I try, I wanted to ask: does this kind of setup work with subfiles?

Usually I would just try it myself and see, but this question on SE has made me hesitate because it suggests that similar setup does not work, then a self-answer, which is marked as accepted, has an "EDIT" that says that it only works to compile the mainfile but not the individual subfiles. But compiling the subfiles is of course the whole point of using subfiles.

In other words, what I want to know is whether subfiles a robust package that should work with all these different complex packages and software -- or is it really just designed for simple LaTeX documents without automated bibliography, Unicode, or other complications?

2 Answers 2

5

Answer to the main question: Yes, the subfiles package will most likely work. I edited the almost correct answer of B Hos to make his example work. The crucial point when using subfiles is to ensure that the paths are correct; here it meant to wrap the command \subfix around the bibliography file. See the docs for details.

The problem in the old thread is actually not a subfiles problem but related to the specific TeX editor used: How to tell it what the current main file is, for typesetting and displaying? Otherwise, posts older than two years are probably not useful anymore, as both, LaTeX and the subfiles package, changed considerably in October 2020.

General remark: Do you have a good reason for using the subfiles package? To structure the source of a large document, the most robust way is still to use \input (and to a lesser extent \include), and to comment/uncomment these \input statements as needed. The main document may look like

\documentclass{memoir}
\input{mypreamble}
\begin{document}
\input{sections/introduction}
%\input{sections/problem}
%\input{sections/solution}
%\input{sections/conclusion}
\end{document}

to typeset the introduction only. With a really large document, the included files may consist of \inputs themselves. Since \input is built in to (La)TeX, it works seamlessly with all packages and all TeX tools (including editors).

1
  • In my setup, I have a sections/ directory where I put an ever-changing collection of files, each one added or renamed as I draft and move around sections or chapters of a book. I then have a simple script to generate a file with the necessary \input commands for everything that is in sections/. So it is trickier to just comment things out -- or rather that commenting is overwritten each time I write the script. But you're probably right that it may nevertheless be the simplest way to do it. Oct 10, 2022 at 16:23
4

I used TeX Studio, default compiler and XeLaTeX both worked. In addition to the example below I tried the article class.

Main.tex:

\documentclass{memoir}
\usepackage{blindtext}
\usepackage{lipsum}
\usepackage[
    backend=biber, 
    style=authoryear-icomp, 
    sorting=nyt]{biblatex}

\usepackage{subfiles} 
\addbibresource{\subfix{bibliography.bib}}

\title{Subfiles package example}
\author{}
\date{ }

\begin{document}
    \maketitle
    \section{Introduction}
    \subfile{sections/introduction}
    \section{Second section}
    \cite{Potter2017}
    \printbibliography
\end{document}

Introduction.tex

\documentclass[../main.tex]{subfiles}
\begin{document}
    \lipsum
    \cite{Anderson2018}
    \printbibliography
\end{document}

Edit

bibliography.bib:

@article{Potter2017,
    author={Potter, Joe},
    title={Marmots},
    journaltitle={Alpine Journal},
    volume={3},
    number={2},
    year={2017},
    pages={40--43}
}

@article{Anderson2018,
    author={Anderson, Joan},
    title={Waterwheels},
    journaltitle={Engineering},
    volume={9},
    number={1},
    year={2018},
    pages={92--101}
}
2
  • Were you able to get the bibliography to work when compiling the subfile? You didn't include bibliography.bib, so I added it in the same directory as main.tex. But then running biber (after running xelatex) on introduction.tex, I get "ERROR - Cannot find 'bibliography.bib'!" Oct 10, 2022 at 4:03
  • 1
    @AlexRoberts I corrected the example, it should work now.
    – gernot
    Oct 10, 2022 at 11:18

You must log in to answer this question.

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