Commits

JanKanis  committed e18b897

Updates to error handling, added preliminary test file

- update patterns to hopefully match the entire error message
- try to make the desktop notifications show more of the useful parts of latex errors.
- add preliminary test file

  • Participants
  • Parent commits 7d7e151

Comments (0)

Files changed (2)

File latexmake.py

 __version__ = '0.5dev'
 __license__ = 'GPL3+'
 
+def rejoin(*args):
+  return '|'.join('(?:'+r+')' for r in args)
 
 BIB_PATTERN = re.compile(r'\\bibdata\{(.*)\}')
 CITE_PATTERN = re.compile(r'\\citation\{(.*)\}')
 BIBCITE_PATTERN = re.compile(r'\\bibcite\{(.*)\}\{(.*)\}')
 BIBENTRY_PATTERN = re.compile(r'@.*\{(.*),\s')
-ERROR_PATTERN = re.compile(r'(?:^! (.*\nl\..*)$)|(?:^! (.*)$)|'
-                            '(No pages of output.)', re.M)
-LATEX_RERUN_PATTERN = re.compile('|'.join(
-                        [r'LaTeX Warning: Reference .* undefined',
+FILE_NOT_FOUND_PATTERN = re.compile(rejoin(
+    r"^No file\s*(.*)\.$",
+    r"^! LaTeX Error: File `([^']*)' not found\.",
+    r".*?:\d*: LaTeX Error: File `([^']*)' not found\.",
+    r"^LaTeX Warning: File `([^']*)' not found",
+    r"^Package .* [fF]ile `([^']*)' not found",
+    r"Error: pdflatex \(file ([^\)]*)\): cannot find image file",
+), re.M)
+
+ERROR_PATTERN = re.compile(rejoin(
+    r'^! ((?:.|\n)*?)\n$',
+    # r'^! (.*\nl\..*)$',
+    r'^! (.*)$',
+    r'(No pages of output.)'
+), re.M)
+LATEX_RERUN_PATTERN = re.compile(rejoin(
+                         r'LaTeX Warning: Reference .* undefined',
                          r'LaTeX Warning: There were undefined references\.',
                          r'LaTeX Warning: Label\(s\) may have changed\.',
                          r'.*Warning:.*Rerun to get.*', 
                         # PDFLaTeX are read in by XeLaTeX. Rerunning resolves 
                         # it.
                          r'\*\* WARNING \*\* Failed to convert input string to UTF16',
-                        ]))
+                         ))
 TEXLIPSE_MAIN_PATTERN = re.compile(r'^mainTexFile=(.*)(?:\.tex)$', re.M)
 
 LATEX_FLAGS = ['-interaction=nonstopmode', '-shell-escape', '--synctex=1']
         if not errors:
             return True
         else:
-            self.log.error('! Errors occurred:')
+            error = ['! Errors occurred:']
+            error += [e.replace('\r', '').strip() for e
+                      in chain(*errors) if e.strip()]
+            error.append('! See "%s.log" for details.' % self.project_name)
 
-            error = '\n'.join(
-                [error.replace('\r', '').strip() for error
-                 in chain(*errors) if error.strip()]
-            )
-            
-            self.log.error(error)
-
-            self.log.error('! See "%s.log" for details.' % self.project_name)
+            self.log.error('\n'.join(error))
 
             if self.opt.exit_on_error:
-                raise LatexMkError('\n'.join((error, 
-                    'See "{}.log" for details.'.format(self.project_name))
-                ))
+                raise LatexMkError('\n'.join(error))
             return False
 
     def generate_citation_counter(self):
     A Logging handler that sends messages to the Gnome notification system
     using the notify2 library. Default level is WARN. 
     '''
+
+    # The Gnome notification system only shows the last 10 lines of the message
+    maxlines = 10
+
     def __init__(self, level=logging.WARN, *args):
         logging.Handler.__init__(self, *args, level=level)
         self.notification = notify2.Notification('')
         now = time.time()
         if now - self.timestamp > 10:
             del self.errors[:]
-        self.errors.append(record.getMessage())
+        if self.errors:
+            self.errors.append('...')
+            self.errors.extend(record.getMessage().split('\n')[:self.maxlines-1])
+        else:
+            self.errors.extend(record.getMessage().split('\n')[:self.maxlines])
+
         self.notification.update(
             'LatexMk error:', '\n'.join(self.errors), icon='dialog-error')
         self.notification.show()

File testpatterns.txt

+Error:
+
+"""
+...
+! Missing $ inserted.
+<inserted text> 
+                $
+l.242 ...ic feature \texttt{"constraint_instance"}
+                                                   set to true.
+I've inserted a begin-math/end-math symbol since I think
+you left one out. Proceed, with fingers crossed.
+
+...
+"""
+