I am currently using Windows 7, TeXLive2011, and TeXworks 0.4.3.

I want to put all temporary files in tmp directory located in the same working directory as the .tex file. But, I want the final .pdf file in the same directory as the .tex file, not in tmp directory.

I did the following:

pdflatex -synctex=1 -output-directory=tmp foo.tex

It put all temporary files in tmp directory, but also foo.pdf. So, I created a batch file to copy foo.pdf from tmpdirectory to the working directory.

:: %1 = tex file basename (without extension)
:: %2 = working directory

:: remove quotes in the basename tossed by TeXworks
for /f "useback tokens=*" %%a in ('%1') do set basename=%%~a
:: remove spaces in the basename tossed by TeXworks
set basename=%basename: =%

:: change / to \ in the directory name tossed by TeXworks
set dirname=%2
set dirname=%dirname:/=\%

:: create tmp directory if not exist
IF NOT EXIST %dirname%\tmp mkdir %dirname%\tmp

pdflatex -synctex=1 -output-directory=tmp %basename%.tex

:: open pdf in tmp so that synctex works in TeXworks
texworks %dirname%\tmp\%basename%.pdf

copy %dirname%\tmp\%basename%.pdf %dirname%\%basename%.pdf

But I have to open foo.pdf in tmp to make the forward/inverse search work in TeXworks. This works good enough to me, except one thing.

After executing the above batch file, TeXworks opens two windows: one for foo.tex, one for tmp\foo.pdf. Inverse search from tmp\foo.pdf to foo.tex works good, but if I do Ctrl+click in foo.tex, it opens foo.pdf, but synchronizes with tmp\foo.pdf. Of course, foo.tex does not synchronize with foo.pdf, because sync file is written for tmp\foo.pdf.

If I do not copy tmp\foo.pdf to foo.pdf in the original working directory, it works well, because there is no foo.pdf that TeXworks can open.

Would there be any workaround for this?


You could use the -aux_directory=tmp option instead of -output-directory=tmp.

This will use the tmp directory for the auxillary files, and leave your PDF in the source directory so you don't need to move it. There is still the .synctex that gets created in the source directory. In my tests, I was able to remove that and still get the synctex features to work so could change your script to delete that file too.

| improve this answer | |
  • 3
    -aux-directory=tmp seems work only with MikTeX. Unfortunately I use TeXlive. – Chang Oct 18 '11 at 0:05

I always copy the .synctex (or .synctex.gz) file together with the PDF. This is everything that is required for SyncTeX to work, but it must be in the same directory as the PDF file.

See also this answer to a related question.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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