示例#1
0
def run_latex(ltxcmd, texfile, cache_filename, verbose=False):
    """Run the flavor of latex specified by ltxcmd on texfile.

    This function returns:

        - the return value of ``ltxcmd``,

        - a value specifying if there were any fatal flaws (``True``) or not
          (``False``), and

        - the number of errors and

        - the number of warnings encountered while processing ``texfile``.

    Arguments:

        cache_filename

            The path to the cache file for the current tex project. This file
            is used to store information about gutter marks between runs of
            ``texmate``.

        ltxcmd

            The latex command which should be used translate ``texfile``.

        texfile

            The path of the tex file which should be translated by ``ltxcmd``.

    Returns: ``(int, bool, int, int)``

    Examples:

        >>> chdir('Tests/TeX')
        >>> run_latex(ltxcmd='pdflatex',
        ...           cache_filename='.external_bibliography.lb',
        ...           texfile='external_bibliography.tex') # doctest:+ELLIPSIS
        <h4>...
        ...
        (0, False, 0, 0)
        >>> chdir('../..')

    """
    run_object = Popen("{} {}".format(ltxcmd, shellquote(texfile)),
                       shell=True,
                       stdout=PIPE,
                       stdin=PIPE,
                       stderr=STDOUT,
                       close_fds=True,
                       universal_newlines=True)
    lp = LaTexParser(run_object.stdout, verbose, texfile)
    fatal, errors, warnings = lp.parse_stream()
    stat = run_object.wait()
    update_marks(cache_filename, lp.marks)
    return stat, fatal, errors, warnings
示例#2
0
def run_latex(ltxcmd, texfile, cache_filename, verbose=False):
    """Run the flavor of latex specified by ltxcmd on texfile.

    This function returns:

        - the return value of ``ltxcmd``,

        - a value specifying if there were any fatal flaws (``True``) or not
          (``False``), and

        - the number of errors and

        - the number of warnings encountered while processing ``texfile``.

    Arguments:

        cache_filename

            The path to the cache file for the current tex project. This file
            is used to store information about gutter marks between runs of
            ``texmate``.

        ltxcmd

            The latex command which should be used translate ``texfile``.

        texfile

            The path of the tex file which should be translated by ``ltxcmd``.

    Returns: ``(int, bool, int, int)``

    Examples:

        >>> chdir('Tests/TeX')
        >>> run_latex(ltxcmd='pdflatex',
        ...           cache_filename='.external_bibliography.lb',
        ...           texfile='external_bibliography.tex') # doctest:+ELLIPSIS
        <h4>...
        ...
        (0, False, 0, 0)
        >>> chdir('../..')

    """
    run_object = Popen("{} {}".format(ltxcmd, shellquote(texfile)),
                       shell=True, stdout=PIPE, stdin=PIPE, stderr=STDOUT,
                       close_fds=True, universal_newlines=True)
    lp = LaTexParser(run_object.stdout, verbose, texfile)
    fatal, errors, warnings = lp.parse_stream()
    stat = run_object.wait()
    update_marks(cache_filename, lp.marks)
    return stat, fatal, errors, warnings
示例#3
0
                 </strong></p>
              '''.format(filename, problematic_characters.group(0)))
    # Run the command passed on the command line or modified by preferences
    elif command == 'latexmk':
        engine_options = construct_engine_options(typesetting_directives,
                                                  tm_engine_options, synctex)
        write_latexmkrc(engine, engine_options, '/tmp/latexmkrc')
        latexmkrc_path = "{}/config/latexmkrc".format(tm_bundle_support)
        command = "latexmk -pdf{} -f -r /tmp/latexmkrc -r {} {}".format(
            'ps' if engine == 'latex' else '', shellquote(latexmkrc_path),
            shellquote(filename))
        process = Popen(command, shell=True, stdout=PIPE, stdin=PIPE,
                        stderr=STDOUT, close_fds=True, universal_newlines=True)
        command_parser = LaTexMkParser(process.stdout, verbose, filename)
        status = command_parser.parse_stream()
        update_marks(cache_filename, command_parser.marks)
        fatal_error, number_errors, number_warnings = status
        tex_status = process.wait()
        remove("/tmp/latexmkrc")
        if tm_autoview and number_errors < 1 and not suppress_viewer:
            viewer_status = run_viewer(
                viewer, filepath, pdffile_path,
                number_errors > 1 or number_warnings > 0 and
                tm_preferences['latexKeepLogWin'],
                'pdfsync' in packages or synctex, line_number)
        number_runs = command_parser.number_runs

    elif command == 'bibtex':
        use_biber = exists('{}.bcf'.format(file_without_suffix))
        status = (run_biber(file_without_suffix) if use_biber else
                  run_bibtex(file_without_suffix))
示例#4
0
                                                  tm_engine_options, synctex)
        write_latexmkrc(engine, engine_options, '/tmp/latexmkrc')
        latexmkrc_path = "{}/config/latexmkrc".format(tm_bundle_support)
        command = "latexmk -pdf{} -f -r /tmp/latexmkrc -r {} {}".format(
            'ps' if engine == 'latex' else '', shellquote(latexmkrc_path),
            shellquote(filename))
        process = Popen(command,
                        shell=True,
                        stdout=PIPE,
                        stdin=PIPE,
                        stderr=STDOUT,
                        close_fds=True,
                        universal_newlines=True)
        command_parser = LaTexMkParser(process.stdout, verbose, filename)
        status = command_parser.parse_stream()
        update_marks(cache_filename, command_parser.marks)
        fatal_error, number_errors, number_warnings = status
        tex_status = process.wait()
        remove("/tmp/latexmkrc")
        if tm_autoview and number_errors < 1 and not suppress_viewer:
            viewer_status = run_viewer(
                viewer, filepath, pdffile_path, number_errors > 1
                or number_warnings > 0 and tm_preferences['latexKeepLogWin'],
                'pdfsync' in packages or synctex, line_number)
        number_runs = command_parser.number_runs

    elif command == 'bibtex':
        use_biber = exists('{}.bcf'.format(file_without_suffix))
        status = (run_biber(file_without_suffix)
                  if use_biber else run_bibtex(file_without_suffix))
        tex_status, fatal_error, number_errors, number_warnings = status
示例#5
0
            exit(0)
    else:
        # Depending on the error the tex engine might return a log file in a
        # different encoding.
        for encoding in encodings:
            try:
                texparser = LaTexMkParser(open(logfile, encoding=encoding),
                                          verbose=False,
                                          filename=texfile)
                texparser.parse_stream()
                break
            except UnicodeDecodeError:
                continue
        # Sort marks by line number
        marks = sorted(texparser.marks, key=lambda marks: marks[1])
        update_marks(cachefile, marks)
        messages = [
            "{:<7} {}:{} — {}".format(severity.upper(), basename(filename),
                                      line, message)
            for (filename, line, severity, message) in marks
        ]
        if not messages:
            messages = [
                "Could not find any messages containing line information.",
                "Please take a look at the log file {}.latexmk.log ".format(
                    basename(arguments.file)) +
                "to find the source of the problem."
            ]

        try:
            # Try to update data in cache file
示例#6
0
            # Fail silently
            exit(0)
    else:
        # Depending on the error the tex engine might return a log file in a
        # different encoding.
        for encoding in encodings:
            try:
                texparser = LaTexMkParser(open(logfile, encoding=encoding),
                                          verbose=False, filename=texfile)
                texparser.parse_stream()
                break
            except UnicodeDecodeError:
                continue
        # Sort marks by line number
        marks = sorted(texparser.marks, key=lambda marks: marks[1])
        update_marks(cachefile, marks)
        messages = ["{:<7} {}:{} — {}".format(severity.upper(),
                    basename(filename), line, message)
                    for (filename, line, severity, message) in marks]
        if not messages:
            messages = [
                "Could not find any messages containing line information.",
                "Please take a look at the log file {}.latexmk.log ".format(
                    basename(arguments.file)) +
                "to find the source of the problem."]

        try:
            # Try to update data in cache file
            with open(cachefile, 'r+b') as storage:
                typesetting_data = load(storage)
                typesetting_data['messages'] = messages