2

I am trying to setup a LaTex Project for multiple users. Each user has their own sub-folder inside of each Project sub-folder. I would like each week to be able to also be generated as standalone document. The Problem that I run into is LaTeX does not seem to like relative paths in the sub-folders. What can I do to fix this?

├── example.tex
├── Project1
│   ├── name1
│   │   ├── name1.tex
│   ├── name2
│   │   ├── name2.tex
│   ├── name3
│   │   ├── name3.tex
│   └── week1.tex
├── Project2
│   ├── name1
│   │   ├── name1.tex
│   ├── name2
│   │   ├── name2.tex
│   ├── name3
│   │   ├── name3.tex
│   └── week2.tex
└── Project3
    ├── name1
    │   ├── name1
    ├── name2
    │   ├── name2.tex
    ├── name3
    │   ├── name3.tex
    └── week3.tex

Thanks, Wylie

  • 2
    What do you mean by "not like"? What did you use that "LaTeX did not like"? – Werner May 25 '15 at 19:07
  • I have tried a couple of different ways to use sub directories however it always seems to yield errors at me for ether what I generate a document from example.tex or from one of the Project files like week1.tex. – thewyliestcoyote May 25 '15 at 19:45
2

Inspired by the link that Timothy provided, I've come up with something slightly different:

main.tex:

\documentclass{article}

\usepackage{subfiles}
\usepackage{graphicx}

\begin{document}

% First subfile 
    \newcommand{\subdir}{Project1/name1}
    \subfile{\subdir/name1.tex}

% Second subfile 
    \renewcommand{\subdir}{{Project1/name2}}
    \subfile{\subdir/name2.tex}

% ... etc

\end{document}

name1.tex:

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

\providecommand{\subdir}{.}
    % When compiling main.tex, "\subdir" is already defined; no effect
    % When compiling this file, "\subdir" is defined as "."
    % Either way: paths relative to "\subdir" will be relative to this file's directory

\begin{document}
    \includegraphics{\subdir/Figures/A} 
        % Always includes "[project dir]/Project1/name1/Figures/A"
\end{document}

With this approach, the information about how the directories are laid out is only tracked in one file ("main.tex"). Both of the options suggested at Timothy's link instead require that each subfile record its own location, which leaves more files to update if directory structures change (and thus more opportunities for things to get out of sync).

1

I found this
http://www.latex-community.org/forum/viewtopic.php?f=5&t=13267
which explains the problems of using subfiles package with sub folders and a possible solution in detail.

Amendment
it basically says, that references made to resources (graphics in particular) must be declared as if the subfile was in the same directory as the main file and must be redirected in the preamble of the subfile.

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

%redirection for access from actual file location
\let \originalcmd \graphicspath
\renewcommand{\graphicspath}[1]{\originalcmd{{Figures/}}}

\begin{document}
% resource path from root folder
\graphicspath{{Chapters/Chapter_1/Figures/}}
...
\includegraphics{example.pdf}
...
\end{document}

bye
Timothy Truckle

  • Link only answers are not good. Please add specific details. otherwise, this is likely to be deleted. – luchonacho Oct 15 '16 at 11:04
  • I didn't want to copy that information to avoid issues with copyrights... – Timothy Truckle Oct 15 '16 at 11:22

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.