Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,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 2.20 / 5
  You rated: 3 / 5 (5 votes cast)
 
[13,622 views]  

Hide temporary files created by TeXShop | 12 comments | Create New Account
Click here to return to the 'Hide temporary files created by TeXShop' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Hide temporary files created by TeXShop
Authored by: chtito on Sep 07, '07 08:15:17AM
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 Sep 11, '07 12:52:21PM

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 Sep 07, '07 09:46:40AM

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 Sep 07, '07 02:58:24PM

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 Sep 07, '07 03:26:01PM

And where can I set this Output-Directory?



[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: chtito on Sep 08, '07 01:03:25AM

The script does that for you.



[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: itistoday on Sep 10, '07 07:04:16AM

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 Oct 02, '07 12:39:26PM
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 Sep 17, '07 09:26:14AM

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 Apr 11, '08 06:39:15AM
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 | # ]
Hide temporary files created by TeXShop
Authored by: kannaguchio on Sep 12, '12 11:41:39PM

When I try this hint, I get an error if my filename has any spaces in it. When I use the LaTeX engine normally, this doesn't happen, though. Is this a problem with python not parsing spaces in names correctly? Any way to correct it?



[ Reply to This | # ]
Hide temporary files created by TeXShop
Authored by: macmadness86 on Nov 17, '12 10:44:12PM

I changed the script to do two things:

  • Include spaces in filenames
  • use xelatex to compile the .tex
  • getting it to compile with xelatex was easy. the tricky part was getting support for file name spaces, because you can't use the join(args) command. Therefore, I just switched the command variable to concatenated variables.

    The Catch:

    You must first browse to the folder containing the .tex file. You cannot run, for example, xelatex "/Users/macmadness86/test 1.tex". You must run xelatex "test 1.tex" and it will work. I have tested this with TeXShop and it works fine!
    
    #!/usr/bin/python
    
    import os, sys, shutil, subprocess
    
    OUTPUT_ARGUMENT = '--output-directory='
    DEFAULT_OUTPUT_PATH = '/tmp'
    
    # Grab the output directory from the arguments
    output_arg_specified = False
    output_dir = None
    for arg in sys.argv:
        if arg.startswith(OUTPUT_ARGUMENT):
            output_arg_specified = True
            output_dir = arg.split('=')[1]
            break
    
    # If an output directory argument was not found, then set it to the default
    if output_dir is None:
        output_dir = DEFAULT_OUTPUT_PATH
    
    # The output pdf will be named the same as the tex file
    tex_file = sys.argv[-1] #variable includes spaces in file name no problem here
    pdf_file_name, extention = os.path.splitext(tex_file) #no problem here with space in filename
    pdf_file_name = pdf_file_name
    tex_file = tex_file
    print "tex_file --> " + tex_file + " pdf_file_name --> " + pdf_file_name + " extention --> " + extention
    
    # Not sure why this is necessary
    assert extention == '.tex'
    
    if not os.path.isdir(output_dir):
        os.mkdir(output_dir)
    
    # If command arguments did not contain the oput directory argument, then since
    # we set it to have a new detault, add it to the arguments we will pass on
    args = sys.argv[1:]
    if not output_arg_specified:
        args.insert(0, OUTPUT_ARGUMENT + output_dir)
    
    command = 'xelatex ' + OUTPUT_ARGUMENT + output_dir + ' ' + '"' + tex_file + '"'
    # %s' % ' '.join(args)
    print '%s Executing: %s' % (sys.argv[0], command)
    
    print command
    # Run the original command which generates all the files
    os.system(command)
    
    pdf_file_src = output_dir + '%s' % (os.path.sep) + pdf_file_name + '.pdf' 
    pdf_file_dest = '%s%s' % (os.curdir, os.path.sep) + pdf_file_name + '.pdf'
    
    # If the destination pdf already exists, delete it so that the new one may be
    # coppied.
    if os.path.isfile(pdf_file_dest):
        os.remove(pdf_file_dest)
    
    # Move the pdf back to where it normally is
    shutil.move(pdf_file_src, os.curdir)
    


    [ Reply to This | # ]