add tag
It is often interesting to know if the output of two different documents (or the same document using different package/kernel versions) is the same.

Which different techniques can be used to test this?


Just as an example document for testing:


\vspace{0.1mm}% test with and without this line
abc def
Top Answer
One possible approach is to make a visual diff of the resulting documents.

The following script is rather hacky and has a lot of external dependencies, but maybe it can be used as a starting point.

The main idea is that each page of the documents gets converted into a pixelate image and then the pixel values are compared. If they differ, they are highlighted in red.

### Usage

It can be executed with 

lua pdfdiv.lua "document_old" "document_new"
and will produce an image `diff-<page number-1>.png` for every page that has differences



-- making a visual diff of two pdfs
function visual_div(old, new)

    -- stripping file ending from name
    doc_old = old:match("(.+).pdf") or old
    doc_new = new:match("(.+).pdf") or new

    -- getting number of pages in each document ---------------------
    local handle = io.popen("pdfinfo " .. doc_old .. ".pdf | grep Pages | awk '{print $2}'")
    local pages_old = handle:read("*a")
    local handle = io.popen("pdfinfo " .. doc_new .. ".pdf | grep Pages | awk '{print $2}'")
    local pages_new = handle:read("*a")

    ---- converting pdf's into png images ---------------------------
    os.execute("convert -density 300 " .. doc_old .. ".pdf " .. doc_old .. ".png")
    os.execute("convert -density 300 " .. doc_new .. ".pdf " .. doc_new .. ".png")

    -- loop over pages ----------------------------------------------
    for i = 0, pages_new-1, 1 

        -- check if page exists in old document ---------------------
        if( pages_old+0.0 >= i)

            -- suffix based on number of pages ----------------------
            if( pages_old+0.0 == 1.0 )
                suffix = ""
                suffix = "-" .. i
            end -- check if only one page

            -- calculating diff -------------------------------------
            os.execute("compare -compose src " .. doc_old .. suffix .. ".png " .. doc_new .. suffix .. ".png diff" .. suffix .. ".png")
            -- getting number of changed pixels ---------------------
            local handle = io.popen("convert diff" .. suffix .. ".png -print '%[fx:w*h*(1-mean)]'   null:")
            local diff_pixel = handle:read("*a")
            -- clean up ---------------------------------------------
            os.execute("rm " .. doc_new .. suffix .. ".png")
            os.execute("rm " .. doc_old .. suffix .. ".png")
            -- keeping only images with differences -----------------
            if(diff_pixel+0.0 > 0.0)
                -- print(diff_pixel)
                os.execute("rm diff" .. suffix .. ".png")

        end -- check if page exist

    end -- loop over pages

end -- end function

-- calling function

-- e.g. lua pdfdiv.lua "document_old" "document_new"
visual_div(arg[1], arg[2])

### Dependencies:

- `convert` and `compare` from the `ImageMagick` library
- pdfinfo
- grep
- awk
- whatever I forgot in the list above

### Disadvantages:

- slow (I really mean it, don't try with a very long document)

### Advantages:

- will not only show that something has changed, but provide visual context of what has changed. This way the user can for example judge if they mind that a word is 1 mm further down or not
- will sort out which pages actually do have changes, so no need to check all of them

### Output from the test document:

Answer #2
Ulrike Fischer made me aware of the `pdfpagediff` package



This will produce a new document with the two previous ones overlayed. If you have adobe reader, you can use the `layers` menu at the left hand site to toogle between the documents to see if there are any significant changes.

### Caveats: 

- If you have a document with opaque background (like beamer), you will only be able to see one layer at a time instead of both overlayed (but you will still be able to toggle between them)
- only works with pdfTeX

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.