Latexdiff with subfiles

Note that the following is a work-around rather than a full solution:

latexdiff --append-safecmd=subfile d1/main.tex d2/main.tex --flatten > mydiff.tex

will take care of the cases where a \subfile command has been added or removed from the file, and the whole block is marked up (only tested on the MWE, would need to be confirmed for longer included material), or the filename of included file changes. You would still need to copy the included files into the directory where the difference file is generated (current directory in the MWE).

To highlight content changes to the subfiles, you can process each file separately

cat /dev/null > null latexdiff -pnull d1/includeme.tex d2/includeme.tex > includeme.tex

The -p option forces latexdiff to omit the preamble commands that it normally inserts automatically when it finds a \begin{document} (auxiliary file "null" is needed as -p/dev/null is not recognised due to a bug in latexdiff).

Now all that remains is to automate this. The following line is a hacky way to achieve some automation as proof-of-concept but would really need to be expanded into a more robust and flexible small shell script:

grep -v '^%' main.tex | grep subfile\{ | sed 's/^.*subfile{\(.*\)}.*$/\1/' \ | awk '{ print "latexdiff -pnull d1/" $1, "d2/" $1,">", $1 }' | sh


2 years after the question was asked, but I ended up writing a batch file for solving this in a windows environment:

@echo off
setlocal

set "old_path=..\..\tags\old_version\my_folder\"
set "new_path=..\..\..\trunk\my_folder\"
set "doc_name=my_file.tex"

latexdiff --flatten %doc_name% %doc_name% > flat.tex
cd %old_path%
latexdiff --flatten %doc_name% %doc_name% > flat.tex
cd %new_path%
latexdiff --flatten %old_path%flat.tex flat.tex > diff.tex

rm flat.tex
rm %old_path%flat.tex