This approach uses a very powerful command line and takes care of changes in the main latex document, including subdirectories/subfiles, that's even if the document is split into multiple .tex files. We will use latexdiff, a Perl script, and thus it requires we make installation of at least Perl 5.8 or higher. You can download and install Perl from here.
To get latexdiff, open your terminal, and issue the commands below to install it:
- sudo apt-get update
- sudo apt-get install latexdiff
To realize the usage of latexdiff, let's create two directories (LaTeX_dir_1 and LaTeX_dir_2) on the Desktop, each containing the main LaTeX document, respectively, named TeX_file_1.tex and TeX_file_2.tex, where there is the inclusion of sub-files via \input{file.tex} command to these main LaTeX documents, see attached. We will run latexdiff and see which changes were made to the TeX_file_2.tex in the LaTeX_dir_2 folder, and show the differences in diff.tex, as follows below.
Move to the first folder in the Desktop:
- cd Desktop/LaTeX_dir_1/
Compare LaTeX files and create the file diff.tex in the folder LaTeX_dir_1 with differences:
- latexdiff --append-safecmd=subfile TeX_file_1.tex /home/username/Desktop/LaTeX_dir_2/TeX_file_2.tex --flatten > diff.tex
The difference document produced looks like:
Remember to replace "username" above by the appropriate name of your machine. Two directories with test LaTeX files (taken from here) are attached.