Configure pdf-tools in Emacs running on MacOS

Viewed 419

I am unable to successfully utilize the pdf-tools package.

Environment:

  • macOS Monterey 12.0.1
  • Emacs 27.2

To the best of my understanding, I have followed the installation instructions as outline on https://github.com/politza/pdf-tools:

  • I've installed and confirmed that the installations of poppler and automake are up-to-date
  • Though it doesn't seem to be required for the MacOS install, I've installed and confirmed that the installations of gcc and glib are up-to-date.
  • I've set the PKG_CONFIG_PATH in the init.el file using setenv and confirmed its settings using getenv
(setenv "PKG_CONFIG_PATH" "/usr/local/Cellar/zlib/1.2.8/lib/pkgconfig:/usr/local/lib/pkgconfig:/opt/X11/lib/pkgconfig")

When I try to execute pdf-tools-install and select y in response to the question "Need to (re)build the epdfinfo program, do it now?" I get a compilation error which reads:

mode: compilation; default-directory: "~/.emacs.d/elpa/pdf-tools-20211110.513/build/server/" Comint started at Thu Dec 2 09:17:05

/Users/username/.emacs.d/elpa/pdf-tools-20211110.513/build/server/autobuild -i /Users/username/.emacs.d/elpa/pdf-tools-20211110.513/ Failed to recognize this system, trying to continue.

Configuring and compiling

No such program: autoreconf

Comint exited abnormally with code 1 at Thu Dec 2 09:17:05

I have confirmed that the referenced directory exits and that autoreconf is installed and up-to-date.

2 Answers

For a long while, I had a working pdf-tools setup on my Mac (thank you Andreas Politz and all the other contributors for such a fabulous tool). Suddenly, I don´t really know how or why, it stopped working. I also deleted my homebrew HEAD version of pdf-tools, which made things worse, because I have never again managed to install pdf-tools from Homebrew.

I tried many tweaks, until, finally, I believe the trick that really got things running again was setting the PKG_CONFIG_PATH to everything that mattered inside the init.el file (and downloading XQuartz to get a X11 environment, with the only purpose of having renderproto in the system; it may have been available in an easier way, but it was only like this that I managed to do it).

Here are all the key steps involved in getting pdf-tools back to work in my MacOS Monterey 12.5 running Emacs 28.1 :-)

  1. Download and install XQuartz to get X11 in your Mac (this might be unnecessary, but it helped me).

  2. In case you haven't already, install other dependencies through homebrew:

      brew install poppler automake pkg-config
    
  3. Through M-x list-packages, install pdf-tools.

  4. In your init.el file, set the PKG_CONFIG_PATH using setenv:

      (setenv "PKG_CONFIG_PATH" "/usr/local/Cellar/zlib/1.2.12/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig:/usr/local/Cellar/poppler/22.06.0_1/lib/pkgconfig:/opt/x11/share/pkgconfig")
    

    Of course, you will have to use your own version numbers and update them every time you upgrade zlib and poppler. (zlib now ships with mac OS. If like me you're on mac OS 12.6 or later--and most probably even earlier--you can use /usr/local/opt/zlib/lib/pkgconfig:, which won't have to be updated manually).

  5. Personally, I did all this through the use-package configuration macro that helps organize the init.el file:

      (use-package pdf-tools
       :ensure t
       :config
       (setenv "PKG_CONFIG_PATH" "/usr/local/Cellar/zlib/1.2.12/lib/pkgconfig:/usr/local/lib/pkgconfig:/usr/X11/lib/pkgconfig:/usr/local/Cellar/poppler/22.06.0_1/lib/pkgconfig:/opt/x11/share/pkgconfig")
       (pdf-tools-install)
       (custom-set-variables          
        '(pdf-tools-handle-upgrades t)))
    
  6. Close Emacs and and re open it in the Terminal and, type y when prompted to "(re)build the epdfinfo program". (For some reason, rebuilding the epdfinfo program seems to work better in the Terminal than in the GUI version of Emacs).

That's all it should take to get pdf-tools to work. It did for me, anyway.

try installing the package 'autoconf' the same way you installed 'automake'.

Related