In a multi-file project organized as:
mainfile.tex
subfile1/subfile1.tex
subfile2/subfile2.tex
...
in order to make every subfile compilable on its own and make possible of referencing between subfiles, I'm currently using the package xr and write the following in the preamble of the subfiles:
\externaldocument{../subfile1/subfile1}
\externaldocument{../subfile2/subfile2}
...
but to avoid inputting the current file, I have to remove \externaldocument{../subfile1/subfile1} in subfile1.tex, remove \externaldocument{../subfile2/subfile2} in subfile2.tex, etc. This makes the preamble of the subfiles kind of hard to maintain when the number of files grows.
I wonder if this can be made automatic, that is to have a list of subfiles stored in list.tex, with each name of the subfile on a separate line:
subfile1
subfile2
...
and read this file line by line in the subfile, comparing if the current line is empty or equal to \jobname, and if not, add the line \externaldocument{../current-line/current-line}.
Is it possible to do this with expl3?
Below is a set of files to test. The files are organized as:
list.txt
main.tex
subfile-one/subfile-one.tex
subfile-two/subfile-two.tex
Below are the file contents.
- list.txt (the last empty line is on purpose)
subfile-one
subfile-two
- main.tex
\documentclass{article}
\usepackage{docmute}
\begin{document}
\input{subfile-one/subfile-one.tex}
\input{subfile-two/subfile-two.tex}
\end{document}
- subfile-one.tex
\documentclass{article}
\usepackage{xr}
% \externaldocument{../subfile-two/subfile-two}
\setcounter{section}{0}
\begin{document}
\section{one}
\label{one}
\ref{two}
\end{document}
- subfile-two.tex
\documentclass{article}
\usepackage{xr}
% \externaldocument{../subfile-one/subfile-one}
\setcounter{section}{1}
\begin{document}
\section{two}
\label{two}
\ref{one}
\end{document}
Expected behavior:
and each subfile should contain half of it.
