Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

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: 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!
    import os, sys, shutil, subprocess
    OUTPUT_ARGUMENT = '--output-directory='
    # 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]
    # 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):
    # 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
    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):
    # Move the pdf back to where it normally is
    shutil.move(pdf_file_src, os.curdir)

    [ Reply to This | # ]