Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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?

share|improve this question
    
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 Aug 15 '12 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 Aug 15 '12 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 Aug 15 '12 at 17:49

2 Answers 2

up vote 1 down vote accepted

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.

share|improve this answer
    
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 Aug 16 '12 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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.