Saturday, August 15, 2009

Getting DocView to work on Windows Emacs

Emacs 23 has a new document viewer called docview.  From the manual

is a viewer for DVI, Postscript (PS),and PDF documents.  It provides features such as slicing, zooming, and searching inside documents.  It works by converting the document to a set of images using the `gs' (GhostScript) command, and displaying those images.

To get it to work on Windows, you'd at least need to have a working LaTeX system like MiKTeX.  And also have ghostscript installed.  Now, if you read the Docview info, this is all you need to get it work but on Windows you need to jump through additional hoops to view it.

As a first step, M-x getenv RET PATH should show something like this.

C:\MiKTeX2.7\miktex\bin;C:\cygwin\bin;C:\cygwin\usr\bin;C:\gnu\bin\;....

Next configure all doc-view-*-program to point to the correct binaries.
Upto this point, docview will work to convert the DVI or PDF file to a PNG file.  In order to view the files, you need to have Emacs with Image support.  On Windows, the following DLLs are required to make it work.
glut32.dll
jpeg62.dll
libimage.dll
libpng12.dll
libpng13.dll
libpng3.dll
librle3.dll
libtiff3.dll
zlib1.dll
which can be had from downloading the following from the gnuwin32 site.
libpng-1.2.37-bin.zip
libpng-1.2.37-dep.zip
tiff-3.8.2-1-bin.zip
jpeg-6b-4-bin.zip                        
tiff-3.8.2-1-dep.zip
jpeg-6b-4-dep.zip                        
Note that the actual version numbers may differ.  Just take only the DLLs and dump them in the Emacs bin directory. Or you could put them somewhere in the search path, so that you don't have to do this step every time a new Emacs version is released.

Docview should now work without a hitch.  The added bonus is that other image formats can also be viewed within Emacs with all the other DLLs plugged in, in Image mode.

In my set up, docview program variables point to a mix of MiKTeX and Cygwin binaries and that has not created any issues so far.

9 comments:

simulyant said...

Hello, I done all steps in your instruction for setup doc-view for emacs in Windows. But doc-view still doesn't work for me. When I open PDF file it opens as a source ("%PDF-1.2 %...")

sivaram said...

I assume that you have ghostscript installed. Make sure all the doc-view*-program variables are pointing to the correct binaries especially ghostscript.
doc-view-ghostscript-program is currently c:/cygwin/bin/gs.exe for me.

What is it for you?

Sivaram

sivaram said...

I assume that you have ghostscript installed. Make sure all the doc-view*-program variables are pointing to the correct binaries especially ghostscript.
doc-view-ghostscript-program is currently c:/cygwin/bin/gs.exe for me.

What is it for you?

Sivaram

Anonymous said...

Can you explain what you mean by the
doc-view*-program variables ?

How does one change them or the place they are pointing to?

Anonymous said...

M-x customize-group RET
doc-view RET

You can enter the correct paths to the programs there.

Remington said...

Thanks for all the instructions. This got me running!

Anonymous said...

Hi there, new versions of emacs requires libpng14-14.dll or libpng14.dll which are not yet available on gnuwin32. You can find it here for example http://trac.mccode.org/browser/branches/mcstas-1.x/support/Win32/gnuplot/libpng14-14.dll?rev=3081

alfalfasprossen said...

it took me quite some time to get my emacs (23.3) to actually displaying png files. the solution for me was to drop libpng14-14.dll AND libpng14.dll into my bin folder

and don't forget to tell docview where to find ghostscript. took me another hour to find out, why it won't display the pdf files, after i got it to display png files.

Anonymous said...

alternatively consider the emacs package provided by Vincent Goulet http://vgoulet.act.ulaval.ca/en/emacs/.

He keeps his packages up-to-date usually and most things like docview and supporting files are pre-packaged. Pretty painless and highly recommended