gsalzer / subfiles

class and package for multi-file projects in LaTeX
LaTeX Project Public License v1.3c
25 stars 1 forks source link

Subfile in subfile [Question] #12

Closed N9199 closed 3 years ago

N9199 commented 3 years ago

Hello, I have a project with a structure similar to the follwing

.
├── part1
│   ├── part1.tex
│   └── part1section1.tex
└── main.tex

Where part1section1.tex is a subfile of part1.tex, which is a subfile of main.tex. Now, this doesn't compile and I think it's because the input paths are not correct when parsing everything. But I've had a similar problem before with graphics path, which I solved by redefining the subfile command the following way:

\let\org@subfile\subfile%
\renewcommand*{\subfile}[1]{%
  \filename@parse{#1}% LaTeX's file name parser
  \expandafter
  \graphicspath\expandafter{\expandafter{\filename@area}}
  \org@subfile{#1}
}

This made it so I could use relative paths and the graphic paths automatically corrected itself. So, is there a way to do something similar in this case? (I'm asking here, cause my Google-Fu failed me, and because I'm still trying to get how the programmatic part of LaTeX works)

gsalzer commented 3 years ago

Could you be a bit more specific about what's going wrong? The example below compiles. What are you doing differently? Make sure that you are using a recent version of subfiles; it should be v2.0.

% main.tex
\documentclass{article}
\usepackage{subfiles}
\begin{document}
This is main.
\subfile{part1/part1}
\end{document}

% part1/part1.tex
\documentclass[../main]{subfiles}
\begin{document}
This is part 1.
\subfile{part1section1}
\end{document}

% part1/part1section1.tex
\documentclass[../main]{subfiles}
\begin{document}
This is part 1, section 1.
\end{document}
gsalzer commented 3 years ago

Try subfiles without any hacks. graphicspath should be handled automatically and correctly (at least in v2.0, but probably also before).

N9199 commented 3 years ago

Ohh, I think I got what was wrong, I had \documentclass[part1]{subfiles} on part1section1.tex, I thought that because it's technically a subfile of part1.tex, then it had to reference part1.tex as its "parent", that clears a lot. Thanks