I have a question that is very similar to the one described here: How to create individual chapter PDFs from included TeXs?
I want to create individual PDF-files (chap01.pdf, chap02.pdf, ...) from multiple TeX-Files (chap01.tex, chap02.tex, ...), which are included in my maintex.tex file. However, the main difference is that my main.tex file is located in my main project directory (e.g. /project), whereas the article-files are located in a subdirectory (e.g. /project/heft1-2019).
\documentclass[a4paper]{report}
\usepackage[utf8]{inputenc} % Required for including letters with accents
\usepackage[T1]{fontenc} % Use 8-bit encoding that has 256 glyphs
\usepackage[ngerman]{babel}
\begin{document}
\include{heft1-2019/chap01}
\include{heft1-2019/chap02}
\include{heft1-2019/chap03}
\end{document}
I tried different solutions, but for me the most elegant seems to be the bash command from egreg: https://tex.stackexchange.com/a/31366/192099
for i in chap*.tex; do j=${i%.tex}; pdflatex -jobname=the$j "\includeonly{$j}\input{maintex}"; done
If all tex files are in the same directory this bash command works wonderfully.
Since the tex files of the articles are in a subdirectory, compiling obviously does not work.
How do I rewrite the bash command so that I can run it from the main project directory and create the PDFs in the subdirectory (heft1-2019), where the article files (chap01.tex, chap02.tex, ...) are located?