1

I am writing a long document with two other people using Dropbox as the file storage mechanism. I want to have each person be able to work on their piece individually. Therefore I want to be able to compile each document seperately, as well as compile the main document. The subfiles package seemed perfect for this.

I tried following the example for modular documents on Wikibooks, but it is not working for me. The top level document will build, but the lower level ones will have file not found errors.

Here is my setup:

  • Images folder
  • tex folder
  • main.tex
  • styles.sty

Inside main.tex:

\documentclass[11pt,letterpaper]{article}
\usepackage{styling} %includes \usepackage{subfiles}
\begin{document}
\maketitle
\tableofcontents
\subfile{./tex/subpiece1}
\end{document}

Inside subpiece1 in tex folder:

\documentclass[../main.tex]{subfiles}
\graphicspath{ {Images/subpiece1/} }

\begin{document}
\section{sectiontitle}
%Images and text
\end{document}

The error when building the subfile seperately: ../main.tex:4: LaTeX Error: File `styling.sty' not found. [^^M]

  • 1
    possible duplicate of How to organize large documents in small nested folders – Fran Feb 20 '15 at 8:36
  • @Fran It is not a duplicate. This one deals specifically with subfiles package, with which I also get an error if I place sub-files in separate directories. – drozzy Dec 24 '15 at 0:19
  • @drozzy I understood the question, and the linked question have a working solution to have compilable sub-files in separate directories (although without the subfiles packacke or class). Besides this, I suspect that your error will be different of the above. That was due to a non standard package in the local ../ but the subfile will search for packages it in the path (=error) and the local directory, that now will be ../tex (=error). This is solved in the MWE f the question simply using the original \usepackage{subfiles} instead of \usepackage{styling}. – Fran Dec 24 '15 at 11:56
  • @Fran I'm not sure I follow, but seems like "styling" includes subfiles package, which in turn fails on sub-directory paths. – drozzy Dec 24 '15 at 16:26
  • @drozzy No "wich in turn fails". No matter if subfiles.sty is included in styling.sty or not. Compiling subpiece1.tex, it is the document class subfiles class which work first and take the preamble of the main file. Here \usepackage{styling} search for styling.sty at the local directory (that now is the subfolder), but is not here, then in the path, but is not here = error. However, using \usepackage{subfiles.sty} directly in the main file will work because it should be accessible to any document in any folder (in a distribution well installed). – Fran Dec 24 '15 at 19:03
2

I came accross the same problem you did when i compiled my first multi-file document using the subfiles package.

Since I am not a long term latex user i do not fully understand the mechanics of the problem but I suspect the problem is that when you compile the "slave" file (in your case 'subpiece1.tex') your compiler searches for the custom package in the same directory as 'subpiece1.tex' and the other default tex directories.

I managed to solve the problem by changing the \usepackage{} command to also include a relative path that will be common for both the "master" and the "slave" .tex files.

What you need to do:

  1. Add a folder in your home directory for the master document. i.e. your home directory should have folders: master folder (containing main.tex), tex folder, images folder.
  2. Edit your main.tex folder so that the \usepackage{} command includes the relative path to 'styling.sty' (it should read \usepackage{../styling} with no file extension)
  3. If you did step one correctly 'styling.sty' will have the same relative path from 'main.tex' and 'subpiece1.tex' (the relative path for both is one folder up. This is achieved by '../' in the \usepackage{} command)
  4. Update all the other relative file paths so they read as required.

main.tex now reads

\documentclass[11pt,letterpaper]{article}
\usepackage{../styling} %includes \usepackage{subfiles}
\begin{document}
%\maketitle (I just removed these because for the demonstartion i didnt actually need them)
%\tableofcontents
\subfile{../tex/subpiece1}
\end{document}

subpiece1 now reads

\documentclass[../master/main.tex]{subfiles}
% again I just removed the graphics path because I have no need for it
\begin{document}
\section{sectiontitle}
%Images and text
\end{document}

I personally prefer to group my preamble.sty into the same folder as my main.tex but the basic idea is the same. I believe any path would be fine as long as the relative paths are the same for both the 'main.tex' and 'subpiece1.tex' files.

I also suspect there are better/more elegant ways of getting around this problem but this worked for me so far.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.