1

So I'm writing a large document (almost a book) of notes, so to organize the document I have been using subfiles. Most of the time I am unable to compile the section that I am working on, and have to compile the entire document rather than the subsection that I am working on.

Below is how my file is organized: (I have put the name in quotes)

My folders are like so...

FOLDER: "Main"
    FILE: "ChapterA.tex"
    FILE: "ChapterB.tex"
    FILE: "ChapterC.tex"
FOLDER: "Sections"
    FOLDER: "TopicA"
        FILE: "SubsectionA1.tex"
        FILE: "SubsectionA2.tex"
        FILE: "SubsectionA3.tex"
    FOLDER: "TopicB"
        FILE: "SubsectionB1.tex"
        FILE: "SubsectionB2.tex"
        FILE: "SubsectionB3.tex"
    FOLDER: "TopicC"
        FILE: "SubsectionC1.tex"
        FILE: "SubsectionC2.tex"
        FILE: "SubsectionC3.tex"
FILE: "Main.tex"
FILE: "Preamble.sty"
FILE: "style.ist"

File "Preamble.sty" looks like...

\ProvidesPackage{Preamble}

\usepackage{--} %multiple packages for symbols and colors
\usepackage{morewrites}
\geometry{letterpaper,portrait, margin=1in}

[general formatting content for title and table of contents]

[creating some shortcuts and new commands that's used throughout the document using \DeclareMathOperator \newcommand and \catcode]

File "Main.tex" looks like this...

\documentclass{article}
\usepackage{Preamble}
\usepackage{subfiles}


\makeindex[name=aa, title={TITLE},columns=1, intoc, options= -s style.ist]

\begin{document}
\subfile{Main/ChapterA} \NewPage
\subfile{Main/ChapterB} \NewPage
\subfile{Main/ChapterC} \NewPage

\printindex[aa]

\end{document}

File ChapterA, ChapterB, ChapterC looks like this:

\documentclass[../Main.tex]{subfiles}

\begin{document}
\Section{Chapter A}
    \subfile{Sections/TopicA/SubsectionA1}
    \subfile{Sections/TopicA/SubsectionA2}
    \subfile{Sections/TopicA/SubsectionA3}
\end{document}

The Subsection files all are in some similar format like this...

\documentclass[../Main.tex]{subfiles}

\begin{document}
\subsubsection{topic}
\begin{itemize}
   \item TEXT...
\end{itemize}

\subsubsection{topic}
Some basic description
\begin{itemize}
    \item MORE INFO
\end{itemize}
\end{document}

When I am in "ChapterA.tex" and compile the file, the entire chapter compiles without the stuff from before or after. with only an a yellow error( "Package auxhook Warning: Cannot patch \document, using \AtBeginDocument instead.")

However when I am in "SubsectionA1.tex" and compile the subsection doesn't compile and I get a major error (' /usr/local/texlive/2017/texmf-dist/tex/latex/subfiles/subfiles.cls, line 40 LaTeX Error: File `../Main.tex' not found. ')

I have tried to edit the \documentclass[..] but am unable to get the subsections to compile like the way the chapters are able to. Why does one work and not the other?

2
  • From the project structure you show, the first line of the subsection files should read \documentclass[../../Main.tex]{subfiles} (note the second ../), since relative to the subsection files, the Main file with the preamble is two levels above.
    – gernot
    Dec 20, 2019 at 12:29
  • And the \subfile commands in Main files should use the path ../Sections/TopicA/SubsectionA1.tex etc (note the initial ../).
    – gernot
    Dec 20, 2019 at 13:12

1 Answer 1

1

I had to modify a few paths and to load additional packages to make your files compilable, but then your example works. As a basic rule,

Path information is relative to the directory that contains the file with the \subfile or \documentclass command.

% folder structure
% ----------------
% Main.tex
% Preamble.sty
% Main/ChapterA.tex
% Main/ChapterB.tex
% Sections/TopicA/SubsectionA1.tex
% Sections/TopicA/SubsectionA2.tex
% Sections/TopicB/SubsectionB1.tex
% Sections/TopicB/SubsectionB2.tex

% Main.tex
\documentclass{article}
\usepackage{Preamble}
\makeindex[name=aa, title={TITLE},columns=1, intoc, options= -s style.ist]
\usepackage{subfiles}
\begin{document}
\subfile{Main/ChapterA}
\subfile{Main/ChapterB}
\printindex[aa]
\end{document}

% Preamble.sty
\usepackage{imakeidx}
\usepackage{geometry}
\geometry{letterpaper,portrait, margin=1in}

% Main/ChapterA.tex
\documentclass[../Main.tex]{subfiles}
\begin{document}
\section{Chapter A}
    \subfile{../Sections/TopicA/SubsectionA1}
    \subfile{../Sections/TopicA/SubsectionA2}
\end{document}

% Main/ChapterB.tex
\documentclass[../Main.tex]{subfiles}
\begin{document}
\section{Chapter B}
    \subfile{../Sections/TopicB/SubsectionB1}
    \subfile{../Sections/TopicB/SubsectionB2}
\end{document}

% Sections/TopicA/SubsectionA1.tex
% Sections/TopicA/SubsectionA2.tex
% Sections/TopicB/SubsectionB1.tex
% Sections/TopicB/SubsectionB2.tex
\documentclass[../../Main.tex]{subfiles}
\begin{document}
\subsubsection{topic}
\begin{itemize}
   \item TEXT...
\end{itemize}
\end{document}

Then compiling the files separately works (except that makeindex misses style.ist).

You must log in to answer this question.

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