2026-06-29 opening pdfs in pdf-tools

As I wrote many times, I use pdf-tools as main pdf viewer. I thought that one thing that would be nice is being able to open pdfs in it from outside Emacs. For example, texdoc could use it instead of Evince (which is pretty nice, but it’s not Emacs!).

Finally, I sat down to it. (Of course, my solution is Linux-centric; it might work on a Mac, but I have no access to such a weird machine to check it.) The first step is to create an emacsclient.desktop file in ~/.local/share/applications:

[Desktop Entry]
Name=Emacs
Exec=emacsclient -r -a emacs
Type=Application
MimeType=application/pdf;text/plain;text/x-tex
NoDisplay=false
Terminal=false

You can add more MimeType​s if you want. Then you run update-desktop-database ~/.local/share/applications/ so that file managers (other than Dired) will know about “opening with Emacs”. Finally, make this the default for pdfs: xdg-mime default emacs-pdf.desktop application/pdf. And from now on, double-clicking a pdf in a graphical file manager or launching texdoc <package-name> will open pdf files in Emacs (using the current Emacs instance if the server is running).

CategoryEnglish, CategoryBlog, CategoryEmacs, CategoryTeX