Preamble
I am writing a large document and I would like to keep it well structured not only in terms of source code (I am aware of commands like \input and include, as well as the standalone package), but also in terms of folder(s) containing the actual source files.
Following How to work with large projects, I have structured my project as follows:
/my_project
|-main.tex
|-... % other directories
|-/contents
|-chap01/ % more than one chapter
|-chap01.tex
|/img
|-img01.tex % more than one image
The key point is that each chapter folder has an inner folder containing the images to be typeset in that chapter. Now, the problem is that the images (usually TikZ figures and PGFplots to be compiled) placed in the lowest level of directories and included through standalone, throw an error and the document doesn't get compiled.
The actual question
So my question is: If the proposed structure is sensible, how can I make it work? And if you think it is not the best way to organize and manage a project, could you advise (or point to references about) another way?
How to reproduce the problem
main.tex
\documentclass{scrbook}
\usepackage{standalone}
\standaloneconfig{mode=buildnew}
\usepackage{graphicx}
\begin{document}
\include{./contents/chap01/chap01}
\end{document}
chap01.tex
\chapter{Test A}
\includestandalone{./img/img01}
img01.tex
\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}
\fill [red] (0,0) circle (2cm);
\end{tikzpicture}
\end{document}
And here is a small script to help reduce the hassle of the setup for GNU/Linux users. (Place the files main.tex, chap01.tex and img01.tex in a folder and run it.)
#!/bin/bash
# Build folders
mkdir ./contents ./contents/chap01 ./contents/chap01/img
# Place files in their respective directory
cp chap01.tex ./contents/chap01
cp img01.tex ./contents/chap01/img
# Remove files from root directory
rm ./chap01.tex ./img01.tex
# Compile main.tex
pdflatex -shell-escape main.tex
Related questions (with comments)
- How to work with large projects, not yet implemented in the example
- Best practice to include (standalone precompiled) graphics, doesn't take into account “nested” folders
- Including pictures in subdirectories with standalone package, about same structure but gives a different error (I have
standalonev. 1.1b) - Is it possible to place standalone graphics in subdirectories, never used
TEXINPUT



/my_project/img, but at the moment I feel that a tree structure is closer to my needs. Nonetheless, I have tried that andstandalonestill throws the same error. – Pier Paolo Feb 11 '15 at 17:43$pwdis still a level higher, so you should\input{someChapter/img/imagefile}– Johannes_B Feb 11 '15 at 17:45my_project/img(at the same level ofmy_project/contents) and have included the image ofchap01.texwith\includestandalone{../../img/img01}. – Pier Paolo Feb 11 '15 at 17:54s/\includestandalone{./img/img01}/\includestandalone{./contents/chap01/img/img01}/Your$pwdis./; to find the imagefile, you have tocdinto contents, thencdinto chap01, thencdinto theimgfolder. – Johannes_B Feb 11 '15 at 18:25pdflatex -shell-escape main.tex. I was mistaken about thepwd... If you post an answer I'll accept it, otherwise I think I might delete this question... If you have a suggestion, please share:)Thanks again. – Pier Paolo Feb 11 '15 at 18:45