Commits

Panagiotis Mavrogiorgos committed 8830302

The created tex file has the same name as the TSF, so in case of compilation errors you can tell where the problem is.

Comments (0)

Files changed (1)

             old = pickle.load(f)
     return old
 
-def create_tex_file(cwd, main_file, tikz_source_path, preview):
+def create_tex_file(cwd, main_file, tikz_source_path, preview, name):
     """
     Create the source file and write to disk (at the current working folder)
     """
         source_file += f.read()
     source_file += "\n\\end{document}"
 
-    with open("temp.tex", "w") as f:
+    with open(name + ".tex", "w") as f:
         f.write(source_file)
 
-def create_pdf(tikz_source_path, ext, compiler):
+def create_pdf(tikz_source_path, ext, compiler, name):
     """
     Run XeLaTeX to the source file and copy it to the same folder as the tikz
     source code
     """
-    subprocess.call('%s temp.tex' % compiler, shell=True)
+    subprocess.call('%s %s.tex' % (compiler, name), shell=True)
 
-    filename = os.path.basename(tikz_source_path)[:-len(EXT)] + "pdf"
-
-    shutil.move("temp.pdf", filename) # File rename
-
+    filename = name + ".pdf"
     try: # old file removal
         os.remove(os.path.join(os.path.dirname(tikz_source_path),filename))
     except:
     # then move the newly created pdf to the same folder as the tikz source file.
     for (tikz_source_path,mod_time) in new.iteritems():
         if tikz_source_path not in old or mod_time != old[tikz_source_path]:
-            create_tex_file(cwd, MAIN_FILE, tikz_source_path, PREVIEW)
-            create_pdf(tikz_source_path, EXT, COMPILER)
-    #-------------------------------------------------------------------------------
-    # clean up code
-    for f in ("temp.aux", "temp.log", "temp.tex", "temp.out"):
-        try:
-            os.remove(f)
-        except:
-            pass
+            name = tikz_source_path.split(os.path.sep)[-1].replace("."+EXT, "")
+            create_tex_file(cwd, MAIN_FILE, tikz_source_path, PREVIEW, name)
+            create_pdf(tikz_source_path, EXT, COMPILER, name)
+            #----------------------------------------------------------------------
+            # clean up code
+            # The created extensions depend on the packages uses in the preamble
+            # If leftover, files are found, then just add more entires in the
+            # following tuple.
+            for f in (name + ".aux", name + ".log", name + ".tex",
+                      name + ".out", name + ".bcf", name + ".run.xml"):
+                try:
+                    os.remove(f)
+                except:
+                    pass
     #-------------------------------------------------------------------------------
     # pickle the new data
     with open(PICKLE_FILE, "w") as f: