How to use the pylatexenc.latexwalker.LatexGroupNode 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 / test / test_latexwalker.py View on Github external
good_parsed_structure = lambda ps1, ps2a, ps2b, ps3: [
            LatexMacroNode(
                parsing_state=ps1,
                macroname='mbox',
                nodeargd=macrospec.ParsedMacroArgs(argspec='{', argnlist=[
                    LatexGroupNode(parsing_state=ps2a,
                                   delimiters=('{', '}'),
                                   nodelist=[
                                       LatexCharsNode(parsing_state=ps2a,
                                                      chars='Prob',
                                                      pos=p-29+37,len=41-37)
                                   ],
                                   pos=p-29+36,len=42-36),
                ]),
                pos=p-29+31,len=42-31),
            LatexCharsNode(parsing_state=ps1,
                           chars='(',
                           pos=p-29+42,len=1),
            LatexMacroNode(
                parsing_state=ps1,
                macroname='mbox',
                nodeargd=macrospec.ParsedMacroArgs(argspec='{', argnlist=[
github phfaist / pylatexenc / test / test_macrospec.py View on Github external
def test_oarg_0(self):
        lw = latexwalker.LatexWalker(r'\cmd[ab] xyz')
        s = MacroStandardArgsParser('[')
        parsing_state = lw.make_parsing_state()
        (argd, p, l) = s.parse_args(lw, len(r'\cmd'), parsing_state=parsing_state)
        self.assertPMAEqual(
            argd,
            ParsedMacroArgs(argspec='[', argnlist=[
                LatexGroupNode(
                    parsing_state=parsing_state,
                    delimiters=('[', ']'),
                    nodelist=[
                        LatexCharsNode(parsing_state=parsing_state,
                                       chars='ab',
                                       pos=5,len=2)
                    ],
                    pos=4,len=4)
            ])
github phfaist / pylatexenc / test / test_macrospec.py View on Github external
def test_marg_0(self):
        lw = latexwalker.LatexWalker(r'{ab}')
        s = MacroStandardArgsParser('{')
        parsing_state = lw.make_parsing_state()
        (argd, p, l) = s.parse_args(lw, 0, parsing_state=parsing_state)
        self.assertPMAEqual(
            argd,
            ParsedMacroArgs(
                argspec='{',
                argnlist=[ LatexGroupNode(
                    parsing_state=parsing_state,
                    delimiters=('{','}'),
                    nodelist=[
                        LatexCharsNode(parsing_state=parsing_state,
                                       chars='ab',
                                       pos=1,len=2)
                    ],
                    pos=0,len=4)
                ])
github phfaist / pylatexenc / test / test_latexwalker.py View on Github external
macroname='item',
                                   nodeargd=macrospec.ParsedMacroArgs(argspec='[', argnlist=[None]),
                                   macro_post_space=' ',
                                   pos=p+23, len=6),
                    LatexCharsNode(parsing_state=parsing_state,
                                   chars='Hi there!  ',
                                   pos=p+23+6, len=17-6),
                    LatexCommentNode(parsing_state=parsing_state,
                                     comment=' here goes a comment',
                                     comment_post_space='\n ',
                                     pos=p+23+17, len=38-17+2),
                    LatexMacroNode(
                        parsing_state=parsing_state,
                        macroname='item',
                        nodeargd=macrospec.ParsedMacroArgs(argspec='[', argnlist=[
                            LatexGroupNode(
                                parsing_state=parsing_state,
                                delimiters=('[', ']'),
                                nodelist=[
                                    LatexCharsNode(parsing_state=parsing_state,
                                                   chars='a',
                                                   pos=p+23+39+7, len=1)
                                ],
                                pos=p+23+39+6, len=3)
                        ]),
                        pos=p+23+39+1,
                        len=9-1
                    ),
                    LatexCharsNode(parsing_state=parsing_state,
                                   chars=' Hello!  @@@\n     ',
                                   pos=p+23+39+9,
                                   len=22+5-9)
github phfaist / pylatexenc / test / test_latexwalker.py View on Github external
([
                LatexCharsNode(parsing_state=parsing_state,
                               chars='\n',
                               pos=0, len=1),
                LatexMacroNode(parsing_state=parsing_state,
                               macroname='documentclass',
                               nodeargd=macrospec.ParsedMacroArgs(argspec='[{', argnlist=[
                                   LatexGroupNode(parsing_state=parsing_state,
                                                  delimiters=('[', ']'),
                                                  nodelist=[
                                                      LatexCharsNode(parsing_state=parsing_state,
                                                                     chars='stuff',
                                                                     pos=1+15,len=20-15),
                                                  ],
                                                  pos=1+14,len=21-14),
                                   LatexGroupNode(parsing_state=parsing_state,
                                                  delimiters=('{', '}'),
                                                  nodelist=[
                                                      LatexCharsNode(parsing_state=parsing_state,
                                                                     chars='docclass',
                                                                     pos=1+22,len=30-22),
                                                  ],
                                                  pos=1+21,len=31-21)
                               ]),
                               pos=1+0,len=31),
                LatexCharsNode(parsing_state=parsing_state,
                               chars='\n\n',
                               pos=1+31, len=2),
            ], p, 34))
github phfaist / pylatexenc / test / test_latexwalker.py View on Github external
lw = LatexWalker(latextext, tolerant_parsing=True)

        parsing_state = lw.make_parsing_state()

        self.assertEqual(lw.get_latex_expression(pos=0, parsing_state=parsing_state),
                         (LatexCharsNode(parsing_state=parsing_state,
                                         chars='T',
                                         pos=0, len=1),0,1,))
        p = latextext.find(r'\`')
        self.assertEqual(lw.get_latex_expression(pos=p, parsing_state=parsing_state),
                         (LatexMacroNode(parsing_state=parsing_state,
                                         macroname='`',
                                         nodeargd=None, pos=p, len=2),p,2,))
        p = latextext.find(r'{')
        self.assertEqual(lw.get_latex_expression(pos=p, parsing_state=parsing_state),
                         (LatexGroupNode(parsing_state=parsing_state,
                                         nodelist=[
                                             LatexCharsNode(parsing_state=parsing_state,
                                                            chars='bold text',
                                                            pos=p+1,len=9)
                                         ],
                                         pos=p, len=11),
                          p,11,))
        p = latextext.find(r'%')-2 # check: correctly skips comments also after space
        self.assertEqual(lw.get_latex_expression(pos=p, parsing_state=parsing_state),
                         (LatexMacroNode(parsing_state=parsing_state,
                                         macroname='item',
                                         nodeargd=None,
                                         pos=p+2+len('% here goes a comment\n'),
                                         len=5),
                          p+2+len('% here goes a comment\n'),5,))
        # check correct behavior if directly on brace close
github phfaist / pylatexenc / test / test_latexwalker.py View on Github external
latextext = r'''Text and \`accent and \textbf{bold text} and $\vec b$ more stuff for Fran\c cois
\begin{enumerate}[(i)]
\item Hi there!  % here goes a comment
\item[a] Hello!  @@@
     \end{enumerate}
Indeed thanks to \cite[Lemma 3]{Author}, we know that...
'''
        lw = LatexWalker(latextext, tolerant_parsing=False)

        parsing_state = lw.make_parsing_state()

        p = latextext.find(r'\textbf')+len(r'\textbf')
        self.assertEqual(lw.get_latex_maybe_optional_arg(pos=p, parsing_state=parsing_state), None)
        p = latextext.find(r'\cite')+len(r'\cite')
        self.assertEqual(lw.get_latex_maybe_optional_arg(pos=p, parsing_state=parsing_state),
                         (LatexGroupNode(
                             parsing_state=parsing_state,
                             delimiters=('[', ']'),
                             nodelist=[
                                 LatexCharsNode(
                                     parsing_state=parsing_state,
                                     chars='Lemma 3',
                                     pos=p+1,
                                     len=len('Lemma 3'),
                                 )
                             ],
                             pos=p,
                             len=9
                         ),p,9,))
github phfaist / pylatexenc / test / test_latexwalker.py View on Github external
def test_get_latex_braced_group(self):

        latextext = r'''Text and \`accent and \textbf{bold text} and $\vec b$ more stuff for Fran\c cois
\begin{enumerate}[(i)]
\item Hi there!  % here goes a comment
\item[a] Hello!  @@@
     \end{enumerate}
Indeed thanks to \cite[Lemma 3]{Author}, we know that...
Also: {\itshape some italic text}.
'''
        lw = LatexWalker(latextext, tolerant_parsing=False)
        parsing_state = lw.make_parsing_state()

        p = latextext.find(r'Also: {')+len('Also:') # points on space after 'Also:'
        good_parsed_structure = \
            ( LatexGroupNode(
                parsing_state=parsing_state,
                delimiters=('{','}'),
                nodelist=[
                    LatexMacroNode(parsing_state=parsing_state,
                                   macroname='itshape',
                                   macro_post_space=' ',
                                   pos=p+2,
                                   len=len(r'\itshape ')),
                    LatexCharsNode(parsing_state=parsing_state,
                                   chars='some italic text',
                                   pos=(p+16-5),
                                   len=32-16)
                ],
                pos=p+1,
                len=len(r'{\itshape some italic text}')
              ),
github phfaist / pylatexenc / pylatexenc / latex2text / __init__.py View on Github external
def _groupnodecontents_to_text(self, groupnode):
        if groupnode is None:
            return ''
        if not groupnode.isNodeType(latexwalker.LatexGroupNode):
            return self.node_to_text(groupnode)
        return self.nodelist_to_text(groupnode.nodelist)