Beispiel #1
0
def process_article(filename):
    """Returns TexParserBase derived object on success, None on failure."""

    # get the tex file
    filename, file_obj, tarfile_obj = get_tex_file(filename)
    if file_obj is None:
        return None

    # detect the type of file
    kind = detect_file_kind(file_obj)

    # act on the type of file
    parser = None
    if kind == 'PS':
        print('skipping postscript file')
    elif kind == 'auto-ignore':
        print('asked to ignore file, most likely it was withdrawn')
        parser = WithdrawnPaper()
    if kind == 'tex':
        print('parsing as TeX')
        parser = TexParser(filename, file_obj, tarfile_obj)
    elif kind == 'latex':
        print('parsing as LaTeX')
        parser = LatexParser(filename, file_obj, tarfile_obj)
    else:
        print('cannot determine kind of file')

    # attempt to parse the document
    try:
        if parser is not None:
            parser.parse()
    except Exception as e:
        print('exception while trying to parse file:')
        print(str(e))
        parser = None

    # close the files
    file_obj.close()
    if tarfile_obj is not None:
        tarfile_obj.close()

    # return the parsed document
    return parser
Beispiel #2
0
 def __init__(self, maker):
     Depend.__init__(self, maker)
     self.logfile = None
     self.auxfile = None
     self.srcfile = None
     self.srcbase = None
     self.outfile = None
     self.program = "latex"
     self.engine = "TeX"
     self.paper = ""
     self.prods = []
     self.must_compile = 0
     self.something_done = 0
     self.failed_module = None
     self.watcher = Watcher()
     self.log = LogParser()
     self.modules = Modules(self)
     self.parser = TexParser(self)
     self.date = None
     # Is the final output expected?
     self.draft_only = False
     self.draft_support = False
     self.batch = 1
     self.opts = []