Pick of the Week - Nov 10 [Show all picks]
Path Finder 5 - A feature-laden Finder replacement
Submit Hint Search The Forums LinksStatsPollsFAQHeadlinesRSS
12,000 hints and counting!

Hide temporary files created by TeXShop Apps
The problem: (pdf)LaTeX creates loads of intermediate files before it creates the PDF file. This results in your directory being cluttered by useless files (.log, .aux, .vrb and so on). You may try to get rid of them by using the command pdflatex --output-directory=.tmp in TeXShop, but then your PDF file won't automatically show up (because it also ends up in the temporary directory). Here comes a possible solution.

Save the following python script in a location of your choice (say /Library » TeX » Root » bin » pdflatex.py):

tmp_dir = '.tmp'
import os, sys, shutil
tex_file = sys.argv[-1]
f, ext = os.path.splitext(tex_file)
assert ext[1:] == 'tex'
if not os.path.isdir(tmp_dir):
  os.mkdir(tmp_dir)

os.system('pdflatex --shell-escape --output-directory=%s %s' % (tmp_dir, f))
shutil.move('%s%s%s.pdf' % (tmp_dir, os.path.sep, f), os.curdir)

Open the preference pane of TeXShop, and change the pdflatex command to this:
/usr/bin/python /Library/TeX/Root/bin/pdflatex.py
Now every time you hit the Typeset button in TeXShop, only the created PDF files will be visible in the Finder. If you want to access the intermediate files in the Finder, simply hit Shift-Command-G and type .tmp.
    •    
  • Currently 0.00 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (0 votes cast)
 
[6,836 views]  

Hide temporary files created by TeXShop | 10 comments | Create New Account
Click here to return to the 'Hide temporary files created by TeXShop' hint
The following comments are owned by whomever posted them. This site is not responsible for what they say.
Hide temporary files created by TeXShop
Authored by: chtito on Fri, Sep 7 2007 at 8:15AM PDT
I also have a slightly more polished version of the script:
import os
import sys
import shutil

tmp_dir = '.tmp'

# find out the name of the file to compile
tex_file = sys.argv[-1]
file_name, file_ext = os.path.splitext(tex_file)
assert file_ext[1:] == 'tex'

# create the temporary directory if it doesn't exist
if not os.path.isdir(tmp_dir):
  try:
    os.mkdir(tmp_dir)
  except OSError:
    raise IOError('A file named "%s" already exists in this catalog' % tmp_dir)

# run pdflatex
os.system('pdflatex --shell-escape --output-directory=%s %s' % (tmp_dir, file_name))

# move the pdf file back to the tex directory
try:
  shutil.move('%s%s%s.pdf' % (tmp_dir, os.path.sep, file_name), os.curdir)
except IOError:
  print '\n\nPdf file not found.'


[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: hamarkus on Tue, Sep 11 2007 at 12:52PM PDT
Nice improvement. Is there a way to make it show up in the Typset in TeXShop and not only in drop-down menu within the .tex file's window?

[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: lsequeir on Fri, Sep 7 2007 at 9:46AM PDT
Don't forget that these auxiliary files are necessary for cross-referencing, producing the table of contents, index, etc.

If you are producing documents that don't require any of those, then this ought to work.

Also, instead of replacing the standard pdflatex, it is better to make it an alternative "Engine", using this nice feature of TeXShop.

Save your script in ~/Library/TeXShop/Engines, as, say,
mypdflatex.engine, and don't forget to make it executable.
(Also, add the line
#!/usr/bin/python
at the top have python run the script when it's invoked)

Then you can access your engine as you would any other engine, like xetex, of latexmk, or whatever. You can select it from either the popup menu or include the line

%!TEX TS-program = mypdflatex

at the top of any tex file to have TeXShop compile it using your script.

---
Luís

[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: spicyj on Fri, Sep 7 2007 at 2:58PM PDT

Don't forget that these auxiliary files are necessary for cross-referencing, producing the table of contents, index, etc.

I believe that when you set the output-directory, it will also look there for the auxiliary files.



[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: hamarkus on Fri, Sep 7 2007 at 3:26PM PDT
And where can I set this Output-Directory?

[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: chtito on Sat, Sep 8 2007 at 1:03AM PDT
The script does that for you.

[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: itistoday on Mon, Sep 10 2007 at 7:04AM PDT
Great hint! But I don't see the point of putting it in a new hidden directory when you can just throw it in /tmp.

[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: chtito on Tue, Oct 2 2007 at 12:39PM PDT
It's easier to find the temporary files in a local directory than in a global /tmp directory. But I believe you can just set the variable tmp_dir to /tmp and the temporary files will be placed there.

[ Reply to This | # ]
Somebody forgot to tell BiBTex ...
Authored by: hamarkus on Mon, Sep 17 2007 at 9:26AM PDT
where it can find the .aux file. I've tried to create a new version of bibtex by creating a new engine 'hidebibtex.engine' along the same lines as outlined above. Alas, bibtex does not support the option --shell-escape nor --output-directory, or at least that is how I understand the error message.

[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: tammojan on Fri, Apr 11 2008 at 6:39AM PDT
Another way to hide files in the Finder is to use the command
SetFile -a V *.pdfsync *.log *.bbl *.aux *.blg
This has to be done only once for each file, but of course it could be called for each TeX file automatically. The files will remain visible in a terminal, and for latex. To undo this, use the same command with a lowercase v. Developer Tools are required for this to work.

[ Reply to This | # ]