import os

from .errors import parse_log


class LatexError(Exception):
    pass


class LatexBuildError(LatexError):
    """LaTeX call exception."""

    def __init__(self, logfn=None):
        if os.path.exists(logfn):
            # the binary log is probably latin1 or utf8?
            # utf8 throws errors occasionally, so we try with latin1
            # and ignore invalid chars
            binlog = open(logfn, 'rb').read()
            self.log = binlog.decode('latin1', 'ignore')
        else:
            self.log = None

    def __str__(self):
        return str(self.log)

    def get_errors(self, *args, **kwargs):
        """Parse the log for errors.

        Any arguments are passed on to :func:`.parse_log`.

        :return: The return of :func:`.parse_log`, applied to the log
                 associated with this build error.
        """
        return parse_log(self.log)

@@ -148,86 +148,8 @@
 %22%22%0A%0A
-    def __init__(self, logfn=None):%0A        if os.path.exists(logfn):%0A        
     
@@ -193,24 +193,16 @@
 r utf8?%0A
-        
     # ut
@@ -254,24 +254,16 @@
  latin1%0A
-        
     # an
@@ -285,16 +285,125 @@
 d chars%0A
+    LATEX_MESSAGE_ENCODING = 'latin1'%0A%0A    def __init__(self, logfn=None):%0A        if os.path.exists(logfn):%0A
         
@@ -477,24 +477,43 @@
 .decode(
-'latin1'
+self.LATEX_MESSAGE_ENCODING
 , 'ignor

Make encoding configurable.