6

In a larger latex project am using \include to include the chapter files and within those \input for sections and subsections.

I just discovered that due to some rearranging some of the \input commands got lost, so that several files did not get included and were no part of the generated PDF anymore.

I am not sure, if any other includes got missing as well. How can I check that efficiently?

My .tex files are scattered in a folder and one sub-folder of it, there are about 30 or 40 .tex files.

I am using ubuntu (if there are solutions outside of latex)

  • TeX itself has no knowledge of files in the current folder, it will always start searching on request. Having sai that, you either have to carefully check your document by hand, or have all filenames existent looked for in the tex files by any scripting language. – Johannes_B Jan 22 '16 at 15:16
  • 3
    all files input are recorded in the log as (/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) – David Carlisle Jan 22 '16 at 15:17
  • the approach i'd take (not being a competent perl or python programmer) is more manual. i would start with a directory listing of all .tex files in the affected directories. then i'd perform a grep on all these .tex files for \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.) – barbara beeton Jan 22 '16 at 15:37
  • @barbarabeeton grep for "\.tex$" on the log file (essentially David's solution, with no scripting) would be easier than grep on the TeX sources. – Ethan Bolker Jan 22 '16 at 15:48
  • @EthanBolker -- good thinking. thanks. – barbara beeton Jan 22 '16 at 16:56
4

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 cutlery 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
  • Thats a great Idea, and it works flawlessly in case all files are included directly in the main file. In my case however, several files are not included in the main, but in different files (don't ask me why, I see that this is not necessarily a good idea..). If I understand it correctly it does only show the files included in the main file then. I think it would require much work to adopt to that, therefore I am probably going to use @David Carlisle's suggestion and post it here once it is done. – kyra Jan 23 '16 at 15:50
  • 1
    @kyra Wait. I have extended this solution to many files in no time (see the newest edit). In order to check whether “this file is included in any of the files at least once”, we modified the line if grep..., replacing the name of the master file with the list of files to search in, that is, the original array without the .tex extension cut off. So the updated version checks whether each file is included at least once in any other file. It will return NOT found only for orphaned TeX files or the master files. This is exactly what you described, right? – Andreï Kostyrka Jan 23 '16 at 23:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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