Exemplo n.º 1
0
    def test_macro_ev_nested_replace(self):
        parser = Parser()

        doc = parser.parse_from_string(r"""

% macro definition
\defEnv{new}[0]{New}{Old}
\defEnv{hello}[1]{hello #1}{#1 world}

% macro expansion
\begin{hello}{\begin{new}
    crazy
\end{new}}
brave
\end{hello} 

""")

        print("env_nested_replace (before expansion) = {}".format(doc))

        processor = DocumentProcessor(doc)

        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        processor.process()

        print("env_nested_replace (after expansion) = {}".format(doc))
Exemplo n.º 2
0
    def test_macro_simple_text(self):
        parser = Parser()

        doc = parser.parse_from_string(r"""

% macro definition
\defCommand{\hello}[0]{brave world}
\defCommand{\hello2}{brave world 2}

% macro expansion
Hello \hello 

% macro expansion
Hello \hello2 

""")

        print("simple_text (before expansion) = {}".format(doc))

        processor = DocumentProcessor(doc)

        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        processor.process()

        print("simple_text (after expansion) = {}".format(doc))
Exemplo n.º 3
0
    def test_macro_env_simple_text(self):
        parser = Parser()

        doc = parser.parse_from_string(r"""

% macro definition
\defEnv{hello}[0]{hello}{world}
\defEnv{hello2}{hello2}{world2}

% macro expansion
\begin{hello}
brave
\end{hello}

% macro expansion
\begin{hello2}
brave 
\end{hello2}

""")

        print("env_simple_text (before expansion) = {}".format(doc))

        processor = DocumentProcessor(doc)

        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        processor.process()

        print("env_simple_text (after expansion) = {}".format(doc))
Exemplo n.º 4
0
    def test_exos_liste(self):
        # 1) parsing
        
        parser = Parser()
        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        doc = parser.parse_from_file("../examples/exosliste.tango.tex")

        # 2) processing
        processor = DocumentProcessor(doc)
        core.register_core_processors(processor)
        py_ctx = codeactive.PythonContext(dict())
        codeactive.register_processors(processor, py_ctx)

        try:
            processor.process()
        except codeactive.CheckPythonFailure:
            print("CheckPython failed, aborpting ...")
            return

        #print("After process = \n" + str(doc))

        # 3) generating
        latex_config = LatexConfiguration()
        latex_config.document_class = "article"
        generator = LatexDocumentGenerator(doc, latex_config)
        generator.generate()
Exemplo n.º 5
0
    def test_count_item(self):
        parser = Parser()
        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        doc = parser.parse_from_file("../examples/basic.tango.tex")

        processor = DocumentProcessor(doc)

        count = TestCommandProcess.CountItem()
        processor.register_command_processor("item",count)

        processor.process()

        #print("count = {}".format(count.count))
        self.assertEqual(count.count, 5)
Exemplo n.º 6
0
    def test_eval_python(self):
        parser = Parser()
        doc = parser.parse_from_string("""
\evalPython{{{3+2}}}
""")

        print("Before processing = \n" + str(doc));

        process = DocumentProcessor(doc)
        py_ctx = codeactive.PythonContext(dict())
        codeactive.register_processors(process, py_ctx)
        process.process()

        print("After processing = \n" + str(doc));
Exemplo n.º 7
0
    def test_def_python(self):
        parser = Parser()
        doc = parser.parse_from_string("""
\defPython[fact]{{{
def fact(n):
    return 1 if n<=1 else n*fact(n-1)
}}}

\evalPython{{{3+fact(4)}}}
""")

        #print("Before processing = \n" + str(doc));

        process = DocumentProcessor(doc)
        py_ctx = codeactive.PythonContext(dict())
        codeactive.register_processors(process, py_ctx)
        process.process()
Exemplo n.º 8
0
    def test_macro_simple_replace(self):
        parser = Parser()

        doc = parser.parse_from_string(r"""

% macro definition
        \defCommand{\hello}[1]{brave #1 world}

% macro expansion
Hello \hello{new} 

""")

        # print("simple_replace (before expansion) = {}".format(doc))

        processor = DocumentProcessor(doc)

        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        processor.process()
Exemplo n.º 9
0
    def test_basic_example(self):
        # 1) parsing
        
        parser = Parser()

        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        doc = parser.parse_from_file("../examples/basic.tango.tex")

        # 2) processing
        processor = DocumentProcessor(doc)
        core.register_core_processors(processor)
        processor.process()

        # 3) generating
        latex_config = LatexConfiguration()
        latex_config.document_class = "article"

        generator = LatexDocumentGenerator(doc, latex_config)
        generator.generate()

        print("Output =\n" + str(generator.output))
Exemplo n.º 10
0
    def test_macro_env_simple_replace(self):
        parser = Parser()

        doc = parser.parse_from_string(r"""

% macro definition
\defEnv{hello}[1]{hello #1}{#1 world}

% macro expansion
\begin{hello}{brave}
new
\end{hello}

""")

        #print("env_simple_replace (before expansion) = {}".format(doc))

        processor = DocumentProcessor(doc)

        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        processor.process()
Exemplo n.º 11
0
    def test_macro_env_active_simple(self):
        parser = Parser()

        doc = parser.parse_from_string(r"""

% macro definition
\defEnv{myenv}{
\execPython{{{
enter_count += 1
}}}
}{
\execPython{{{
leave_count += 1
}}}
}

\execPython{{{
enter_count = 0
leave_count = 0
}}}

% macro expansion
\begin{myenv}
enter then leave
\end{myenv}

""")

        print("env_active_simple (before expansion) = {}".format(doc))

        processor = DocumentProcessor(doc)

        # BREAKPOINT >>> # import pdb; pdb.set_trace()  # <<< BREAKPOINT #
        processor.process()

        print("env_active_simple (after expansion) = {}".format(doc))
Exemplo n.º 12
0
    parser = Parser()

    tangoPrintln("Parsing from file '{}' ...".format(args.input_filename))

    doc = parser.parse_from_file(args.input_filename)

    tangoPrintln("==> parsing done.")

    # 2) processing

    if enable_process_phase:

        tangoPrintln("Processing phase ...")

        processor = DocumentProcessor(doc)
        core.register_core_processors(processor)

        # support for active python code
        if args.code_active:
            tangoPrintln("Enabling active python code processors")

            py_ctx = codeactive.PythonContext(tangolib.globalvars.TANGO_EVAL_GLOBAL_ENV)
            codeactive.register_processors(processor, py_ctx)

        try:
            processor.process()
        except codeactive.CheckPythonFailure as e:
            tangoErrln("CheckPython failed ...")
            fatal(str(e))