def test_command(): cmd_lines = t.iter_command("section") expect = [ Text([ TextLine(line_num=1, char_num_start=1, text=r"Corrections for $\PT > 50 \GeV$") ]) ] for e, m in zip(expect, cmd_lines): assert (len(e.text_contents) == len(m.text_contents)) for e_l, m_l in zip(e.text_contents, m.text_contents): assert (e_l.line_num == m_l.line_num) assert (e_l.text == m_l.text) cmd_lines = t.iter_command("drums") expect = [ Text([TextLine(line_num=10, char_num_start=1, text=r"yes")]), Text([TextLine(line_num=10, char_num_start=1, text=r"big")]), ] for e, m in zip(expect, cmd_lines): assert (len(e.text_contents) == len(m.text_contents)) for e_l, m_l in zip(e.text_contents, m.text_contents): assert (e_l.line_num == m_l.line_num) assert (e_l.text == m_l.text)
def test_inline_maths(): math_lines = t.iter_inline_delim("$") expect = [ Text([TextLine(line_num=1, char_num_start=1, text=r"\PT > 50 \GeV")]), Text([TextLine(line_num=5, char_num_start=1, text="12:30")]), ] for e, m in zip(expect, math_lines): assert (len(e.text_contents) == len(m.text_contents)) for e_l, m_l in zip(e.text_contents, m.text_contents): assert (e_l.line_num == m_l.line_num) assert (e_l.text == m_l.text)
def test_environment_inner(): env_lines = t.iter_environment("center") expect = [ Text([ TextLine(line_num=13, char_num_start=1, text=r" It's gonna take a lot to take me away from you "), TextLine( line_num=14, char_num_start=1, text= r" There's nothing that a $$100$$ men or more could ever do "), TextLine(line_num=15, char_num_start=1, text=r" I bless the rains down in Africa "), TextLine( line_num=16, char_num_start=1, text=r" Gonna take some time to do the things we never had "), TextLine(line_num=17, char_num_start=1, text=r" \caption{Bah bah}\label{chorus1} "), ]) ] for e, m in zip(expect, env_lines): assert (len(e.text_contents) == len(m.text_contents)) for e_l, m_l in zip(e.text_contents, m.text_contents): assert (e_l.line_num == m_l.line_num) assert (e_l.text == m_l.text)
def test_inline_maths2(): math_lines = t.iter_inline_delim(delim="$$") expect = [Text([TextLine(line_num=14, char_num_start=1, text="100")])] for e, m in zip(expect, math_lines): assert (len(e.text_contents) == len(m.text_contents)) for e_l, m_l in zip(e.text_contents, m.text_contents): assert (e_l.line_num == m_l.line_num) assert (e_l.text == m_l.text)
def check_content_files(filenames, do_comments=False): """Iterate through normal latex files and check each, printing out errors""" problems_dict = OrderedDict() for filename in filenames: with open(filename) as f: text = Text(f.readlines()) print_filename_header(filename) these_problems = check_and_report_errors(text, do_comments) problems_dict[filename] = these_problems return problems_dict
def check_root_file(filename): """Check elements of the main TeX file""" with open(filename) as f: root_text = Text(f.readlines()) problems_dict = OrderedDict() abstract_text = list(root_text.iter_command("abstract"))[0] print_filename_header(filename + " (ABSTRACT)") abstract_problems = check_and_report_errors(abstract_text, do_comments=False) problems_dict[filename + " [ABSTRACT]"] = abstract_problems title_text = list(root_text.iter_command("title"))[0] print_filename_header(filename + " (TITLE)") title_problems = check_and_report_errors(title_text, do_comments=False) problems_dict[filename + " [TITLE]"] = title_problems return problems_dict
\begin{chorus} \begin{center} It's gonna take a lot to take me away from you There's nothing that a $$100$$ men or more could ever do I bless the rains down in Africa Gonna take some time to do the things we never had \caption{Bah bah}\label{chorus1} \end{center} \end{chorus} """ # DO ALL IMPORTS HERE TO AVOID SCREWING UP LINE NUMBERS import re t = Text(doc.splitlines()) def test_inline_maths(): math_lines = t.iter_inline_delim("$") expect = [ Text([TextLine(line_num=1, char_num_start=1, text=r"\PT > 50 \GeV")]), Text([TextLine(line_num=5, char_num_start=1, text="12:30")]), ] for e, m in zip(expect, math_lines): assert (len(e.text_contents) == len(m.text_contents)) for e_l, m_l in zip(e.text_contents, m.text_contents): assert (e_l.line_num == m_l.line_num) assert (e_l.text == m_l.text)