Use TeXShop Preview window when different output-dir is set
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.
My solution for this is to use one of the latexmk engines. I then use the following latexmkrc
file in the directory with my source (.tex
) file. (You could also add this to your global ~/latexmkrc
file.):
# latexmk Init File; -*-perl-*-
$pdf_mode = 1;
$out_dir = '_build';
mkdir $out_dir;
$pdflatex = 'pdflatex --synctex=1 %O %S; cp %D .';
This will first make sure that $out_dir
(set to _build
here) exists, then will call pdflatex
with the --output-directory=_build
flag (latexmk
does this). Finally, after each call to pdflatex
, the generated .pdf
file (specified by %D
will be copied to the current directory, overwriting the local file, triggering TeXShop's previewer to reload the file. (As the original poster mentioned, creating a symlink is not enough.)
I find this behaviour of copying the generated pdf file out of the _build
directory to be useful since I usually want to keep it, even when deleting all of the auxilliary files (which is just done by deleting the _build
directory).
By including the following comment
% !TEX TS-program = pdflatexmk
at the top of your source (.tex
) file, you can ensure that TeXShop will use the pdflatexmk
engine by default.
The advantage of this approach is that by distributing the latexmkrc
file with your .tex
file, everything will "just work"* for someone using TeXShop – even if they forget to select the pdflatexmk
engine.
* This will "just work" if TeXShop was installed at version 3.07 or later. Otherwise, you will need to (have your colleagues) copy the inactive pdflatexmk.engine
file to the active engine directory (note: ~/Library/
is the Library
folder in the $HOME
folder, not the system /Library
folder):
cp ~/Library/TeXShop/Engines/Inactive/Latexmk/pdflatexmk.engine ~/Library/TeXShop/Engines/
See Also
- latexmk
- TeXShop
- all-in-one-engine for TeXShop