Is there any tool that compares two dvi files. I would like to check if they are identical after I make some changes with source tex file.

  • Any special reason you want to work on the dvi file directly and not convert them to ps and then to pdf so that you can employ tools like diffpdf or pdftotext, depending on whether you're interested in the text content or the layout? – Christian Feb 15 '13 at 11:05
  • Not quite an answer to the question, but might be useful to anyone with this question: to avoid the timestamp annoyance, you can make TeX think its run started at some fixed time, using a program like faketime. For example, run faketime '2008-12-24 08:15:42' tex foo.tex or faketime '2008-12-24 08:15:42' pdftex --output-format=dvi foo.tex – ShreevatsaR Nov 21 '19 at 21:03

TeX adds a comment into the DVI file, e.g.:

 TeX output 2013.02.15:1010

It contains the date and time that complicates the comparison of the DVI files:

  • The time stamp can be set explicitly by setting \year, \month, and \time. If the two files for comparison have the same values, then the time stamp in the DVI files are the same and you can compare the files using the usual programs (diff, comp, …).

  • The comment has a fixed location in the DVI file format in the preamble. The fifteenth byte contains the length of the comment that follows. With the usual standard case, just ignore the first 42 bytes of the file. The missing values for numerator, denominator and magnification are repeated in the postamble anyway. In Linux the stripping could be done with tail by setting option -c to the file length minus 42.

  • Another possibility is dvitype that outputs the DVI contents in a more human readable manner, here the eigths line with the DVI comment and timestamp can be ignored in the comparison.

| improve this answer | |

You can use dvitype, that converts a DVI file to "human readable" form. The start of the obtained file is

This is DVItype, Version 3.6 (TeX Live 2012)
Options selected:
  Starting page = * 
  Maximum number of pages = 1000000
  Output level = 4 (the works)
  Resolution = 300.00000000 pixels per inch
magnification=1000;       0.00006334 pixels per DVI unit
' TeX output 2013.02.15:1014'

and so you should ignore the lines up to and including the last shown line with the time stamp that will surely be different.

The rest of the file will contain something like

Postamble starts at byte 353.
maxv=41484288, maxh=26673152, maxstackdepth=13, totalpages=1
Font 14: cmtt10---loaded at size 655360 DVI units 
Font 7: cmr10---loaded at size 655360 DVI units 

42: beginning of page 1 
87: down4 41484288 v:=0+41484288=41484288, vv:=2628 
92: push 
level 0:(h=0,v=41484288,w=0,x=0,y=0,z=0,hh=0,vv=2628) 
93: down4 -39649280 v:=41484288-39649280=1835008, vv:=116 
98: down4 37683200 v:=1835008+37683200=39518208, vv:=2503 
103: push 

that are low level instructions for associating fonts to a unique number and for setting type on the pages.

| improve this answer | |

The dvii utility can calculate message digest for each page, e.g.

dvii -p -M1 filex > before.md
cat before.md
[message digest: simple sum (ignore font)]

You can then compare .md files, instead of .dvi.

| improve this answer | |

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.