예제 #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
            def round_finished(parser, fatal_error, number_errors, number_warnings):
                update_marks(cache_filename, parser.marks)

                #don't want sync as it doesn't work with multiple source files
                use_pdfsync = False; #'pdfsync' in packages or synctex
                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'],
                        use_pdfsync, line_number)
                if number_errors > 0: #bring html output window to front
                    command = '''/usr/bin/osascript -e 'tell application "System Events" to perform action "AXRaise" of (first window whose name contains "…") of process "TextMate"' '''

                    process = Popen(command, shell=True, stdout=PIPE, stdin=PIPE,
                                    stderr=STDOUT, close_fds=True)                        

                    process.wait()
예제 #4
0
            def round_finished(parser, fatal_error, number_errors,
                               number_warnings):
                update_marks(cache_filename, parser.marks)

                #don't want sync as it doesn't work with multiple source files
                use_pdfsync = False
                #'pdfsync' in packages or synctex
                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'], use_pdfsync,
                        line_number)
                if number_errors > 0:  #bring html output window to front
                    command = '''/usr/bin/osascript -e 'tell application "System Events" to perform action "AXRaise" of (first window whose name contains "…") of process "TextMate"' '''

                    process = Popen(command,
                                    shell=True,
                                    stdout=PIPE,
                                    stdin=PIPE,
                                    stderr=STDOUT,
                                    close_fds=True)

                    process.wait()
예제 #5
0
        process = Popen(command,
                        shell=True,
                        stdout=PIPE,
                        stdin=PIPE,
                        stderr=STDOUT,
                        close_fds=True,
                        universal_newlines=True)

        command_parser = LaTexMkParser(process.stdout, verbose, filename,
                                       False, None)

        status = command_parser.parse_stream()

        tex_status = process.wait()

        update_marks(cache_filename, command_parser.marks)
        fatal_error, number_errors, number_warnings = status
        number_runs = command_parser.number_runs

        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)

    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))
예제 #6
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":
예제 #7
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