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?

  • I don't know if there is a "built-in" TeXShop solution, but I guess a possible workaround would be to use a custom script that calls pdflatex with --output-dir=/tmp and then creates a copy (or a symbolic link) of the output pdf to the original directory (where your source file is).
    – Corentin
    Commented Aug 15, 2012 at 10:26
  • I did try creating a symbolic link to the output pdf and synctex files in the 'normal' directory where the latex source is. No luck though. The pdf preview does not open.
    – NoahR
    Commented Aug 15, 2012 at 14:04
  • Then instead of copying the output pdf (let us call it file.pdf), you should probably add open -a TeXShop /tmp/file.pdf at the end of your script.
    – Corentin
    Commented Aug 15, 2012 at 17:49

3 Answers 3


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

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.

  • Adding your suggested engine with the open command, the pdf preview does open up in TeXShop. I also get a second window named for the pdf filename and the typeset action drop-down is set to ConTeXt. The contents of the second window is empty. I can't seem to sync between pdf and source in the preview window. Overall this answers the question. Thank you. I tried, but could not find the built-in .engine / script that TeXShop uses when LaTeX is selected. I'd be curious to see if the command is the same as what you listed or different.
    – NoahR
    Commented Aug 16, 2012 at 2:04

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


Adding to the answer before, I found that a file name of platexmkrc (The character "p" is important here) is required, by which everything works as expected from within TexShop. This detail is explained in a file TexShop/Engines/Inactive/Latexmk/Latexmk For TeXShop.pdf by Herbert Schulz ([email protected]), also referenced in this answer.

I found out, because latexmk -commands responded by To run pdflatex, I use 'pdflatex -synctex=1 -halt-on-error %O %S; cp %D .', but TeXShop completely ignored this line in the latexmkrc (although it accounted for the other lines, creating a new directory and putting files in the directory defined by $out_dir = '_build'; in the latexmkrc). Therefore I have both files now, a latexmkrc and a platexmkrc.

I run

  • Latexmk, John Collins, 19 Jan. 2017. Version 4.52c
  • pdfTeX 3.14159265-2.6-1.40.18 (TeX Live 2017)
  • TeXShop Version 3.62 (3.62)

(This is my first post ever, so I couldn't edit/comment)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .