Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I know the general problem of converting an arbitrary PDF to .tex is either impossible or would result in unusable LaTeX (by expressing everything as vector graphics, for instance).

But if my PDF was generated from a LaTeX file (which I no longer have), is there a way to "reverse-engineer" it back into the source file?

share|improve this question
up vote 1 down vote accepted

Sorry, but it wouldn't help (much) if the file was generated by LaTex.

share|improve this answer
+1 agree with "no". I mean, it might be conceivably possible to create some LaTeX file that would produce the same PDF output, but even that would be really hard and probably beyond the limits of current technology. The problem is basically akin to decompiling a computer program, but the disconnect between LaTeX source and its PDF output is greater than in most computer programming languages (so it's harder). – David Z Jun 27 '10 at 20:50
Doesn't the generated PDF keep any latex-related metadata? – obvio171 Jun 28 '10 at 4:47
None that i know of. – lajuette Jun 28 '10 at 11:13

You have lost your .tex file and would like to recreate the pdf, perhaps to modify it. Depending on how long your file is and how "regular" your style file was, you could try to manually re-create it.

For the text, you you should be able to copy it from the PDF file (unless you used a weird security feature to disallow that) and then paste it into Emacs in big chunks. Using the fill commands you can deal with the page breaks and reconstruct the paragraph structure moderately well and with ease. You can then find/replace extraneous characters, like hyphens and accents. Keeping track of footnotes and captions will pose some problem; I suggest pasting them where they occur and formatting them accordingly before reconstructing the paragraph structure.

For the graphics, assuming they are vector images, you can use Illustrator or Inkscape to carve them out of the PDF file and save them as an appropriate file type that can be used by pdflatex. If they are jpgs, you are out of luck, since the quality will already be too compromised for them to be useful. If they were generated by LaTeX using PSTricks or something of the sort… you are out of luck as well.

Section and subsection headings should be easy enough to identify and reformat. As I write this, labeling and referencing start looking like a world of pain, but if you plan it on the paper, before manually parsing the file, it should be do-able.

Math equations, if you have anything extra complicated, you will have no problem rewriting it swiftly.

As for the references, you will have to recreate the .bib file (assuming you used one). I would recommend downloading the BibTeX entries that you can find online and filling out the rest by hand.

All in all, it looks like a (tedious) weekend project. I've done it before and it's not as hard as it sounds. Then again, it was a ~20-page document and not a doctoral dissertation, so be sure to pick your battles wisely. All I can say is Good luck.

share|improve this answer

I've put this here for any one looking for future proofing - sorry doesn't help unless you've already done someting like the following—

There are LaTeX packages for including/attaching the original (or any) files into your produced pdf.

I was going to put all the information here, but as a new user the system told me when I had finished writing, that I could only make two links, so here is the same information (in another discussion) I posted in the TeXworks mailing list after this posting initially failed.


share|improve this answer

If the PDF is mainly text, you could run pdf2text on the file to extract the raw text. But then you would still have to manually insert all LaTeX commands to get the formatting.

share|improve this answer

You must log in to answer this question.

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