Short question

Seems like --flatten doesn't work properly with latexdiff-vc. How can I get this working, without reverting to my elaborated workflow described below?


I track the history of my Latex documents using SVN. I've recently started using latexdiff to generate PDFs highlighting the changes between certain revisions.

My initial workflow of svn+latexdiff was (1) to copy over the whole svn folder to a temporary lcoation, (2) update this to the relevant revision, (3) go back to the original svn folder and (4) start latexdiff specifying the relevant folders and files. As I split up my latex document in multiple files using \input{} statements, I have to use the latexdiff --flatten option to get this working. So, at the Windows command prompot I type something like:

latexdiff --flatten ..\..\copy_at_r48\main.tex main.tex > diff.tex

I figured there must be an easier way and bumped into latexdiff-vc which supports specifying svn revisions directly. However, the following doesn't seem to work, as the old versions of linked files doesn't seem to get retrieved/flatten; there are only DIFF markings in the main content:

latexdiff-vc --flatten -r 48 main.tex
  • I never got latexdiff-vc to work either. My workflow is: 1) flatten the document (using a perl script) 2) checkin that document 3) checkout previously flattened document 4) run latexdiff on working copy of flattened document and checkout version. Not perfect by any means, but relatively simple and quick if you combine all those steps in a batch file
    – Jörg
    Jun 27, 2012 at 15:03

3 Answers 3


I've written a very simple Windows batch script (latexdiff-svn.bat) that automated my described workflow. It exports a given revision of the the svn working copy to a temporary folder (typically under C:\Users\username\AppData\Local\Temp), performs latexdiff --flatten, and deletes the temporary folder.

The actual barebones script is only 5 lines

:: Usage: 
::      latexdiff-svn <svn revision number> <filename>
set tempfolder=%TEMP%\latexdiffsvn
rmdir /s /q %tempfolder%
svn export -r %1 . %tempfolder%
latexdiff --flatten %tempfolder%/%2 %2 > diff-%2-r%1.tex
rmdir /s /q %tempfolder%

And below a slightly more elaborated version that does some basic checking on the parameters, and provides some friendly clues to the user. You can copy-paste the code in a file named for example 'latexdiff-svn.bat'

:: Usage: 
::      latexdiff-svn <svn revision number> <filename>
:: e.g.
::      latexdiff-svn.bat 23 main.tex

::Some basic checks on the arguments
@if "%1"=="" goto not_enough_parameters
@if "%2"=="" goto not_enough_parameters
@if not exist %2 goto file_does_not_exist
@svn info -r %1 > NUL
@if errorlevel 1 goto revision_does_not_exist
@goto all_seems_ok

@echo I need exactly two arguments, the first one specifying 
@echo the svn revision number, the second one the file name.
@echo Example syntax:
@echo    latexdiff-svn 23 main.tex
@goto :EOF

@echo I couldn't find the file you specified: %2
@goto :EOF

@echo The current folder does not contain an svn working copy, 
@echo or the revision number specified (%1) does not exist
@goto :EOF

@set tempfolder=%TEMP%\latexdiffsvn
@set difffile=diff-%2-r%1.tex
@if exist %tempfolder% rmdir /s /q %tempfolder%
@echo Creating temporary folder at revision %1
@svn export -r %1 . %tempfolder% > NUL
@echo Running latexdiff
latexdiff --flatten %tempfolder%/%2 %2 > %difffile%

@if exist %tempfolder% rmdir /s /q %tempfolder%

@echo Written to: %difffile%
@echo Done !

Note: the latexdiff script used with the --flatten option outputs a few DEBUG lines. If you want to suppress these (without fixing the perl script itself), see the solution to this stackoverflow question: https://stackoverflow.com/questions/11362041/how-to-suppress-specific-lines-in-windows-cmd-output

  • That's a nice workaround, thank you. Unfortunately, latexdiff's "flatten" option is very limited. For instance, it includes commented "input{x}" commands and only includes top-level inputs (see here). Hence, for my rather complicated documents, I require more advanced "flatten" scripts.
    – Jörg
    Jun 28, 2012 at 15:48

From version 1.1.0 latexdiff-vc actually supports use of the --flatten option for SVN by temporarily checking out the old version in a separate directory. The limitations of the --flatten option alluded to by Jörg's comment to another answer also are no longer there in newer versions of latexdiff.


Usually, I will use latexpand to flatten the separate files into one single tex file at first, then I will use latexdiff. This can be easily done by batch scripts.

  • For some reason the --flatten flag to latexdiff was not actually flattening my \includes, but manually using latexpand did the trick, thanks!
    – nedned
    Jul 8, 2018 at 6:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .