How to use the pylatexenc.latexwalker.__init__.LatexWalkerEndOfStream function in pylatexenc

To help you get started, we’ve selected a few pylatexenc examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github phfaist / pylatexenc / pylatexenc / latexwalker / __init__.py View on Github external
if 'brackets_are_chars' in kwargs:
            if not kwargs.pop('brackets_are_chars'):
                brace_chars += [('[', ']')]


        s = self.s # shorthand

        space = ''
        while pos < len(s) and s[pos].isspace():
            space += s[pos]
            pos += 1
            if space.endswith('\n\n'):  # two \n's indicate new paragraph.
                return LatexToken(tok='char', arg='\n\n', pos=pos-2, len=2, pre_space=space[:-2])

        if pos >= len(s):
            raise LatexWalkerEndOfStream(final_space=space)

        if s[pos] == '\\':
            # escape sequence
            if pos+1 >= len(s):
                raise LatexWalkerEndOfStream()
            macro = s[pos+1] # next char is necessarily part of macro
            # following chars part of macro only if all are alphabetical
            isalphamacro = False
            i = 2
            if s[pos+1].isalpha():
                isalphamacro = True
                while pos+i
github phfaist / pylatexenc / pylatexenc / latexwalker / __init__.py View on Github external
if stop_upon_closing_brace:
                            expecting = "'"+stop_upon_closing_brace+"'"
                        elif stop_upon_end_environment:
                            expecting = r"\end{"+stop_upon_end_environment+"}"
                        elif stop_upon_closing_mathmode:
                            expecting = "'"+stop_upon_closing_mathmode+"'"
                        raise LatexWalkerError("Unexpected end of stream, was looking for {}"
                                               .format(expecting))
                    else:
                        r_endnow = False
                else:
                    r_endnow = e

            if r_endnow:
                # add last chars and last space
                if isinstance(r_endnow, LatexWalkerEndOfStream):
                    p.lastchars += r_endnow.final_space
                    p.pos += len(r_endnow.final_space)
                if p.lastchars:
                    strnode = self.make_node(LatexCharsNode,
                                             parsing_state=p.parsing_state,
                                             chars=p.lastchars,
                                             pos=p.lastchars_pos, len=len(p.lastchars))
                    nodelist.append(strnode)
                return (nodelist, origpos, p.pos - origpos)

        raise LatexWalkerError(                # lgtm [py/unreachable-statement]
            "CONGRATULATIONS !! "
            "You are the first human to telepathically break an infinite loop !!!!!!!"
github phfaist / pylatexenc / pylatexenc / latexwalker / __init__.py View on Github external
p.parsing_state = mdic['new_parsing_state']

                if read_max_nodes and len(nodelist) >= read_max_nodes:
                    return True
                return None

            if tok.tok == 'specials':
                # read the specials. see if it expects/has arguments.
                sspec = tok.arg

                p.pos = tok.pos + tok.len
                nodeargd = None

                try:
                    res = sspec.parse_args(w=self, pos=p.pos, parsing_state=p.parsing_state)
                except (LatexWalkerEndOfStream, LatexWalkerParseError) as e:
                    raise self._get_exc_for_parseerror_or_eof(
                        e, tok, "arguments of specials \"{}\"".format(sspec.specials_chars)
                    )

                if res is not None:
                    # specials expects arguments, read them
                    if len(res) == 4:
                        (nodeargd, mapos, malen, spdic) = res
                    else:
                        (nodeargd, mapos, malen) = res
                        spdic = {}

                    p.pos = mapos + malen

                else:
                    spdic = {}
github phfaist / pylatexenc / pylatexenc / latexwalker / __init__.py View on Github external
s = self.s # shorthand

        space = ''
        while pos < len(s) and s[pos].isspace():
            space += s[pos]
            pos += 1
            if space.endswith('\n\n'):  # two \n's indicate new paragraph.
                return LatexToken(tok='char', arg='\n\n', pos=pos-2, len=2, pre_space=space[:-2])

        if pos >= len(s):
            raise LatexWalkerEndOfStream(final_space=space)

        if s[pos] == '\\':
            # escape sequence
            if pos+1 >= len(s):
                raise LatexWalkerEndOfStream()
            macro = s[pos+1] # next char is necessarily part of macro
            # following chars part of macro only if all are alphabetical
            isalphamacro = False
            i = 2
            if s[pos+1].isalpha():
                isalphamacro = True
                while pos+i