Under Linux, you can use the facilities of bash
. First, you make an array—a list of .tex
files in the current folder (based on a wonderful StackOverflow answer):
arr=( $(find ./ -maxdepth 1 -iname "*.tex" | cut -c3- | sort | rev | cut -c5- | rev ) )
The cut
lery removes the ./
at the beginning of each file (but we still want to preserve the relative file path, so we can’t printf
or -exec basename
them). If you want recursive search, remove the -maxdepth 1
option. Apparently some people include .tex
files without extensions, so the code was modified: we cut off the extension and then search for it optionally. UPDATE. Besides that, we need the original list of files with extensions, so we need to run this (based on this solution):
arrtex=( $(find ./ -maxdepth 1 -iname "*.tex" | cut -c3- | sort ) )
arrtex=$(printf " %s" "${arrtex[@]}")
arrtex=${arrtex:1}
Assuming that you want to search whether they are included in your master file, just loop through every element of the list and check whether it exists in the master file:
for i in "${arr[@]}"
do
a="\\\\in(put|clude)\{${i}(\.tex)\}"
if grep -P -q -e "${a}" ${arrtex}
then msg="found"
else msg="NOT found"
fi
echo "Inclusion of ${i} in any TeX file: ${msg}"
done
Obviously you should disregard the fact that your master file is not included in your master file. I just wanted this code to be as simple as that.
If you want to search for inclusions in your master file only (say, main.tex
), then use this reduced version:
arr=( $(find ./ -maxdepth 1 -iname "*.tex" | cut -c3- | sort | rev | cut -c5- | rev ) )
for i in "${arr[@]}"
do
a="\\\\in(put|clude)\{${i}(\.tex)\}"
if grep -P -q -e "${a}" main.tex
then msg="found"
else msg="NOT found"
fi
echo "Inclusion of ${i} in main.tex: ${msg}"
done
There is much room for improvement, so any suggestions are welcome!
Sample output for my recent project (where chap02.tex
is an actual chapter, main.tex
is the master file and TODO.tex
is a garbage pile for notes):
Inclusion of chap02 in any TeX file: found
Inclusion of main in any TeX file: NOT found
Inclusion of TODO in any TeX file: NOT found
echo ${arr[@]}
chap02 main TODO
(/path/to/filename.tex
so it should be easy to extract a filelist using perl (or python or lua or ..) and compare with a recursive directory listing and report any .tex files that have not been input)\input
and\include
, writing out a file for each segment. i'd concatenate the files resulting from the grep and sort the combined result, ending with a list i could check against the directory listing. (yes, @DavidCarlisle, i should learn a scripting language, but that takes longer.)