[Tex/LaTex] Use TeXShop Preview window when different output-dir is set

texshop

In TeXShop, under Preferences -> Engines I have modified the LaTeX command by adding -output-dir=/tmp. All of my auxiliary and final output files end up in this directory instead of where my source file is. That's what I want and this currently works.

However, when output-dir is set as anything, the output pdf does not open in the TeXShop Preview window following a successful typeset. I can open the pdf manually from /tmp with another pdf viewer. Also, the Window-> Source<=>Preview menu item does nothing.

Is there anyway to restore the automatic Preview functionality in combination with a different output directory?

Best Answer

Let me explain a little more the solution suggested in my above comments. In TeXShop, you can choose which "engine" to call when pressing the Typeset button. An "Engineā€œ is basically a shell script which calls standard TeX commands, and sometimes much more (see the TeXShop help panel or this post for instance). In your case, modifying the pdfTeX command in the TeXShop Preferences changes the standard LaTeX engine. As a result of your modification, TeXShop cannot open the PDF preview automatically after typesetting. One way to restore this behaviour is to write a new engine.

To do so, you can simply create a shell script containing the following code

#!/bin/bash
pdflatex --output-dir=/tmp "$1"
open -a TeXShop /tmp/$(echo $1 | sed 's/\(.*\)\..*/\1\.pdf/')

Make sure the execution bit is active (chmod +x), change the extension to .engine and move the script to the ~/Library/TeXShop/Engines folder. Launch TeXShop and select your new engine in the popup menu next to the Typeset button, then press Typeset.

There may be a more elegant solution, but this works.

Related Question