diff --git a/src/common/latex.py b/src/common/latex.py
index cedf2f19b0494217834d1c0752db206e75321b77..6a8b08aaec4312dd5a575c681226e53f747259ff 100644
--- a/src/common/latex.py
+++ b/src/common/latex.py
@@ -166,6 +166,8 @@ def latex_to_image(str_):
 
     if exitcode == 0:
         os.rename(tmpfile + '.png', tmppng)
+    else:
+        os.remove(tmppng)
 
     os.rmdir(tmpdir)