Example #1
0
def parse():
    """
    Converts mixed files from source to an intermediate based on the extension of the template file. Once converted the
    intermediate is run through the default filters and the extension formatter's processors.

    :return: A list of intermediates corresponding to each of the mixed files
    """
    intermediates, parser = [], get_format(options.state.template())
    if not parser['format']:
        raise FormatError('This format is export only!')
    # Loop through all weaved files
    for file in fileutil.with_extension('.tex'):
        options.post('Using ' + parser['name'] + ' format to parse ' + file)
        intermediate = util.Map({
            'ast': [],
            'src': parser['parser_preprocessor'](fileutil.read(file)),
            'fmt': parser,
            'name': file.replace('.tex', '')
        })
        intermediate.ast = parse_tokens(intermediate.src, parser)
        for default_filter in config.default_filters:
            intermediate.ast = default_filter(intermediate.ast)
        intermediate = parser['parser_postprocessor'](intermediate)
        intermediates.append(intermediate)
        fileutil.write(options.state.cwd() + '/parsed-ast', ''.join(str_token(intermediate.ast)))
    options.post('Successfully parsed', parser['name'] + '.')
    return intermediates
Example #2
0
def pdf_compile():
    """
    Compiles any tex files in the out directory to PDF or DVI depending on what `compile_format` is set to. All
    additional files (aux, log, tex) are removed once compilation completes.
    """
    options.state.cwd(options.state.out())
    options.post('Compiling', len(fileutil.with_extension('.tex')), 'files.')
    for file in fileutil.with_extension('.tex'):
        if compile_format == 'dvi':
            fileutil.write(file, '%&latex\n' + fileutil.read(file))
        try:
            fileutil.remove(file.replace('.tex', '.pdf'))
        except:
            pass
        for i in range(options.state.recomps()):
            lib_loader.pdflatex(file)
    fileutil.remove(fileutil.with_extension(['.aux', '.log', '.tex']))
    options.post('Finished compiling.\n')
Example #3
0
def pdf_compile():
    """
    Compiles any tex files in the out directory to PDF or DVI depending on what `compile_format` is set to. All
    additional files (aux, log, tex) are removed once compilation completes.
    """
    options.state.cwd(options.state.out())
    options.post('Compiling', len(fileutil.with_extension('.tex')), 'files.')
    for file in fileutil.with_extension('.tex'):
        if compile_format == 'dvi':
            fileutil.write(file, '%&latex\n' + fileutil.read(file))
        try:
            fileutil.remove(file.replace('.tex', '.pdf'))
        except:
            pass
        for i in range(options.state.recomps()):
            lib_loader.pdflatex(file)
    fileutil.remove(fileutil.with_extension(['.aux', '.log', '.tex']))
    options.post('Finished compiling.\n')