Andrew Stacey


About
Andrew Stacey
Information about my research, teaching, and other interests.

By: Andrew Stacey
Contact details


Andrew Stacey


blosxom icon


Mon, 11th Dec 2006 (HowDidIDoThat :: Unix)

Changing XPdf Keys

Documents produced by LaTeX tend to have a lot of whitespace around them when produced with a "standard" paper size such as A4 or USLetter. When viewing such documents on the screen I tend to zoom in to make the actual text fill the window. When changing the page it is nice if the viewer program displays the next page in the same position as the previous one. With XDvi this is achieved with the resource xdvi.keepPosition (and toggling this feature is usually bound to the key k). GV can also be easily configured to do this. However although XPdf has this feature, it is only enabled when the NumLock is on. Who uses NumLock these days? Not me. This behaviour is coded in so to alter it required altering the source code. Here's how to do it.


You need to get hold of the source for XPdf and the latest patch. Put these somewhere reasonable, untar the source, and apply the patch.


tar xzf xpdf-3.01.tar.gz
patch -p0 < xpdf-3.01pl2.patch

Depending on what you want to do, either hack the code yourself or apply the following patch. The file containing the keystrokes is xpdf-3.01/xpdf/XPDFViewer.cc. The patch xpdf-3.01pl2-centred.patch switches the behaviour of the keys n and p so that they keep the position if the NumLock is off and don't keep position if it is on. There are other keys that don't keep position if NumLock is off so this effectively means that you don't need to worry about the NumLock key. To apply this patch:

patch -p0 < xpdf-3.01pl2-centred.patch

When trying to compile this on my system, I found that it would not compile due to a few problems with the file splash/SplashFTFont.cc. I didn't have the libt1-dev package installed and so these problems might go away if that package is installed (depends on whether XPdf prefers TrueType or Type1 fonts). If when compiling the code you find errors occuring with that file (the errors that I encountered can be found in the make.log), apply the patch xpdf-3.01pl2-splash.patch.

patch -p0 < xpdf-3.01pl2-splash.patch

Now just compile the code and install it. Probably best not to install it on top of the existing xpdf but put it somewhere else higher up your path (or create an alias to ensure that invoking xpdf calls this version and not the original one). On my system I needed to tell it explicitly where the freetype2 headers were.


./configure --prefix=/share \\
--with-freetype2-includes=/usr/include/freetype2
make
make install

Note: XPdf needs libfreetype6-dev but the configure script won't fail if it only finds freetype2-dev. Check the output of the configure script to see if any other libraries are needed.

That's it! Isn't open source wonderful?

Update: New version of XPdf out soon

I am reliably informed that a new version of XPdf is due out soon which will fix both of the issues in this entry: it will compile against the most recent freetype library and will have customisable key bindings. Oh, and for NumLock in the above you should read ScrollLock. Even worse on my iBook as it doesn't even have a ScrollLock key (as opposed to the NumLock which changes half the keyboard).

[Full link]
Last modified on:
Mon, 11th Dec 2006