Saturday 30 October 2010

Kile + Okular on Mac OS X

For those that want to use Kile (2.1 beta 4)and Okular on Mac OS X, you may find here some useful information about configuring these applications. I am also hoping that someone will suggest better ways of doing things.

I currently use a MacBook Pro with Mac OS X 10.6.4 (Snow Leopard). Because I often write LaTeX documents, I needed a comfortable setup that suits my document editing work-flow. I know that there are many useful editors and (PDF) document viewers for Mac OS X and Linux, but I think the Kile and Okular combination is excellent. I have been a long-time fan of Kile on Linux, and I have used it with several DVI/PS/PDF viewers on that platform. Kile, on one hand, is full of features and its project management and auto-completion features are very useful, it is also very configurable. Okular on the other hand can auto-reload pdf when it changes on the file system, which is useful as you would like to immediately see changes to your document after compilation without having to "click" on a "reload" button. More importantly, the Kile and Okular support forward and inverse (via SyncTex) PDF search. This can be useful when editing large (multi-file) documents.

Now Kile and Okular are KDE applications, and I could not find Mac equivalents that have all the features of Kile in particular (after dabbling into many apps - TexShop almost came close, but does not match the customisability and auto-completion features of Kile that I had gotten so used to). My temporary solution was to run Linux within a virtual machine (VirtualBox) for my document editing work. But then, the launching and shutting down of a virtual machine soon became burdensome - I wanted an app that is easily launched like every other Mac app. There were also other annoyances with permission issues in the folder sharing between the ext4 Linux file-system in the virtual machine and the Mac file-system: the stable Kile version (2.0.3) would happily create files and projects on the shared folders, whereas the latest version (2.1 beta 4) would not - complaining of lack of permission. I know it is beta, but then the stable version is for KDE3, and I use KDE4.

Anyway, I decided to install Kile natively on Mac OS X via MacPorts. Note that to use the embedded Konsole in Kile, kdebase4 port must be installed. One of Kile dependencies is kdegraphics4 port, which provides Okular, which is great. Once installed, initially, Okular would not open PDF files! I later found that installing poppler with +qt4 +quartz on MacPorts, and rebuilding kdegraphics4 solved this problem.

To enable forward and inverse search in Kile and Okular, use the "modern" configuration for your build tools. For example, my PDFLaTex build configuration looks like this:

My "QuickBuild" tool only contains PDFLaTeX: I took out the additional default ViewPDF, because Okular is configured to reload on detecting a change to the file on the file-system. This bypasses a current bug in Okular which always shows the "Navigation Panel" whenever Okular is re-launched - regardless of whether the navigation panel is currently hidden or not. It would have been preferable for me to add ForwardPDF to my "QuickBuild" so that the PDF view in Okular is always synchronised with the point that I am editing within Kile. However, the navigation panel bug is so annoying, that I settle for doing ForwardPDF manually whenever I need to.

To ensure automatic document reload when your PDF file changes, make sure "Reload document on file change" is selected as shown below:



For PDF inverse search, I found out that selecting "Kile" as the Okular "Editor" does not work on Mac - although it works on Linux. To make inverse PDF search work, I chose the "Custom Text Editor" and used the following command:

/Applications/MacPorts/KDE4/kile.app/Contents/MacOS/kile --line %l

If you installed Kile elsewhere, you probably only need to change the path as necessary.
That should be it. Shift + left click within Okular should activate inverse search and take you to the relevant location in your LaTeX document within Kile.

1 comment:

  1. Well, there is nothing that stops one from compiling and using Kile and Okular on Mac OSX. Nowadays, I simply use TeXMaker or TeXStudio (used to be called TeXMakerX), and they both have good integration (PDF forward and inverse searching) with Skim (an excellent Mac OS X PDF reader/editor). If you are familiar with Kile, then TeXMaker would not feel too different (apparently the same author is/was behind both software).

    ReplyDelete