Basically that is the question - if we have a DVI file can we get on the base on it the original TeX file?

  • 4
    no, that is not possible. – user2478 Mar 4 '12 at 17:39
  • 2
    It is comparable to the task of decomposing a once baked cake into its ingredients. – Thorsten Donig Nov 11 '12 at 8:42

The simple answer is no. If you have a dvi and have lost the TeX there are tools such as dvi2tty which will extract the text and some of the paragraph structure, but in general you will have to add the markup back by hand.


Somewhat alike to disassembling a compiled executable: Yes, technically it can be done - but you will lose much of the information that was contained in the original TeX source.

For example, the DVI contains the text "see also chapter 11.2".

You might be able to turn this into text again, but the information that this was originally written as see also chapter \ref{sec:FooBar} is irrevocably lost.

Since this is the case, I don't think anyone has ever made the effort to write such a DVI-to-text converter, since the usability of such text would be severly limited.


No, technically it cannot be done. DVI, PDF and postscript contain text arranged on a page according to instructions in a (La)TeX document. You can extract the text, and you can try to guess at commands that would generate a similar page, and you might even guess well. But you'd be doing it by matching the result. If there is a number in the text, for example, you can never know for sure if it was typed literally or came from a TeX counter. Imagine eating a cake and trying to reconstruct the recipe: If you're good you can identify the ingredients and guess a lot about what was done, but the recipe itself is not in the cake.

Despite what some others said, it's not at all like disassembling: Executable code contains the algorithm, and disassembly just translates it to a human-readable language. Going from dvi to LaTeX is more like trying to reconstruct a C program from its output: Reverse engineering is a better term for it.


PS files would be tremendously difficult to convert back to TeX.

With DVI files I think it would at least be partially possible. Of course all high-level macros and stuff like that would be lost. Compare the task to recovering, e.g., C++ code from a compiled binary file.


Technically it is not impossible to get a Tex file that compiles to the given DVI or PS file.

For simple documents, one could devise a method that first performs OCR on the DVI or PS file, and then converts the result into a Tex file. By re-compiling the Tex document and comparing the results to the DVI or PS file, errors could be identified, which in turn could be corrected by iterating over several possible characters.

For complex documents, though, this procedure may not be sufficient.

Edit: Here is a proof of concept: http://www.inftyreader.org/

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.