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))
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))
def test_mdsection_simple(self): parser = Parser() # BREAKPOINT >>> # import pdb; pdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" = section 1 = this is in section \emph{section 1} == subsection 1.1 == this is in section \emph{subsection 1.1} == subsection 1.2 == this is in section \emph{subsection 1.2} = section 2 = this is in section \emph{section 2} == subsection 2.1 == this is in section \emph{subsection 2.1} == subsection 2.2 == this is in section \emph{subsection 2.2} """) print("doc 8 = {}".format(ret))
def test_section_simple(self): parser = Parser() # BREAKPOINT >>> # import ipdb; ipdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" \section{section 1} this is in section \emph{section 1} \subsection{subsection 1.1} this is in section \emph{subsection 1.1} \subsection{subsection 1.2} this is in section \emph{subsection 1.2} \section{section 2} this is in section \emph{section 2} \subsection{subsection 2.1} this is in section \emph{subsection 2.1} \subsection{subsection 2.2} this is in section \emph{subsection 2.2} """) print("doc 7 = {}".format(ret))
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))
def test_parentheses(self): parser = Parser() # BREAKPOINT >>> # import pdb; pdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" text (in parentheses) """) print("doc 6 = {}".format(ret))
def test_inline_preformated(self): parser = Parser() ret = parser.parse_from_string(r""" The following is `inline preformated` and not the rest. """) print("doc 11 = {}".format(ret))
def test_line_comment(self): parser = Parser() ret = parser.parse_from_string(""" % this is a comment % after some space """) print("doc 1 = {}".format(ret))
def test_mdlist_simple(self): parser = Parser() ret = parser.parse_from_string(r""" - item 1.1 - item 1.2 * item 2.1 * item 2.2 """) print("doc 10 = {}".format(ret))
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));
def test_command_simple(self): parser = Parser() # BREAKPOINT >>> # import pdb; pdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" % this is a comment \mycommand[key1=value1,key2=value2]{ contents of the command % a comment in the command } % after some space """) print("doc 2 = {}".format(ret))
def test_command_simple_preformated(self): parser = Parser() # BREAKPOINT >>> # import pdb; pdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" % this is a comment \mycommand[key1=value1,key2=value2]{{{ contents of the command is preformated with { curly brackets allowed } % a comment in the command }}} % after some space """) print("doc 2 bis = {}".format(ret))
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()
def test_env_simple(self): parser = Parser() # BREAKPOINT >>> # import pdb; pdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" % a comment before the environment \begin{env} % this is a comment \mycommand[key1=value1,key2=value2]{ contents of the command % a comment in the command } % after some space \end{env} % a last comment outside the environment """) print("doc 3 = {}".format(ret))
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()
def test_env_itemize2(self): parser = Parser() # BREAKPOINT >>> # import pdb; pdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" % a comment before the environment \begin{itemize} \item 1 \item 2 \begin{itemize} \item a (b) \item 3.2 \end{itemize} \item 4 \end{itemize} % a last comment outside the environment """) print("doc 5 = {}".format(ret))
def test_list_simple(self): parser = Parser() ret = parser.parse_from_string(r""" \begin{itemize} \item item 1.1 \item item 1.2 \begin{enumerate} \item item 2.1 \item item 2.2 \end{enumerate} \end{itemize} """) print("doc 9 = {}".format(ret))
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()
def test_env_itemize(self): parser = Parser() # BREAKPOINT >>> # import pdb; pdb.set_trace() # <<< BREAKPOINT # ret = parser.parse_from_string(r""" % a comment before the environment \begin{itemize} % this is a comment \item first item \item second item with command \mycommand[key1=value1,key2=value2]{ contents of the command % a comment in the command } \item an item % after some space \end{itemize} % a last comment outside the environment """) print("doc 4 = {}".format(ret))
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))