Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I've the following project structure:

./main.tex
./ch1/ch1.tex
./ch1/tikz1/tikz1.tex

The main.tex looks like:

\documentclass{book}
\begin{document}
\subfile{./ch1/ch1.tex} 
\end{document}

The ch1.tex looks like:

\documentclass[../main.tex]{subfiles}
\begin{document}
\begin{figure}[H]
\centering
\subfile{./tikz1/tikz1.tex}
\end{figure}
\end{document}

When I run the ch1.tex everything is ok, it finds the tikz1.tex, but when I run the main.tex it can't find the tikz1.tex.

share|improve this question
2  
Why don't you use standalone package/class? –  Please don't touch Mar 16 '13 at 1:23
    
DO you need the special tikz?.tex files? Why do you not include them in the chapter file? –  Kurt Mar 16 '13 at 1:50
    
I need them because the tikz code is very big and I don't want to confuse it with ch1.tex code. –  Andyk Mar 16 '13 at 1:53
    
I tried standalone but I got the same problem. Could you please show how to do it correctly? –  Andyk Mar 16 '13 at 1:53
    
Welcome to TeX.sx!. Please include @Andyk like this so as to ping the other commenter –  texenthusiast Mar 16 '13 at 2:02
show 3 more comments

1 Answer 1

In addition to @MarcoDaniel's observation that \usepackage{subfiles} was missing from the main.tex file, there is a problem with how you compile the documents because of relative paths.

When you compile main.tex, latex looks in <maindir>/ch1/ for ch1.tex and in <maindir>/tikz1/ for tikz1.tex. When you compile ch1.tex (likely from its containing directory <maindir>/ch1/), latex looks in <maindir>/ch1/tikz/ for tikz1.tex. Clearly, both of these cannot be correct, unless you maintain two copies of tikz1.tex which sort of defeats the purpose.

There are a number of ways to solve this:

  1. Flatten the directory structure (might be OK depending on number of files)
  2. Use absolute paths (not recommended for portability reasons)
  3. Input ./ch1/ch1.tex to pdflatex run from <maindir> when compiling ch1.tex on its own. Depending on the editor you use, there may be ways to set this up for files other than the main file.
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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