Exemple #1
0
def test_space_around_operators():
    input_string = "a+b=c"
    out = blacktex.clean(input_string)
    assert out == "a+b = c"

    input_string = "a+b&=&c"
    out = blacktex.clean(input_string)
    assert out == "a+b &=& c"
Exemple #2
0
def test_comments():
    input_string = "lorem  %some comment  \n %sit amet"
    out = blacktex.clean(input_string)
    assert out == "lorem"

    input_string = "% lorem some comment  \n sit amet"
    out = blacktex.clean(input_string)
    assert out == " sit amet"

    input_string = "A % lorem some comment  \n sit amet"
    out = blacktex.clean(input_string)
    assert out == "A\n sit amet"
Exemple #3
0
def test_linebreak_around_begin_end():
    input_string = (
        "A\\begin{equation}a+b\\end{equation} B \n\\begin{a}\nd+e\n\\end{a}\nB"
    )
    out = blacktex.clean(input_string)
    ref = "A\n\\begin{equation}\na+b\n\\end{equation}\nB\n\\begin{a}\nd+e\n\\end{a}\nB"
    assert out == ref

    # indentation is okay
    input_string = "A\n  \\begin{equation}\n  a+b\n  \\end{equation}"
    out = blacktex.clean(input_string)
    assert out == "A\n  \\begin{equation}\n  a+b\n  \\end{equation}"
Exemple #4
0
def test_env_label():
    input_string = "A\n\\begin{lemma}\n\\label{lvalpp}"
    out = blacktex.clean(input_string)
    assert out == "A\n\\begin{lemma}\\label{lvalpp}"

    input_string = "A\n\\section{Intro}\n\\label{lvalpp}"
    out = blacktex.clean(input_string)
    assert out == "A\n\\section{Intro}\\label{lvalpp}"

    input_string = "A\n\\subsection{Intro}\n\\label{lvalpp}"
    out = blacktex.clean(input_string)
    assert out == "A\n\\subsection{Intro}\\label{lvalpp}"
Exemple #5
0
def test_multiple_spaces():
    input_string = "lorem   ipsum dolor sit  amet"
    out = blacktex.clean(input_string)
    assert out == "lorem ipsum dolor sit amet"

    # It's allowed as indentation at the beginning of lines
    input_string = "a\n    b\nc"
    out = blacktex.clean(input_string)
    assert out == "a\n    b\nc"

    input_string = "\\[\n  S(T)\\leq S(P_n).\n\\]\n"
    out = blacktex.clean(input_string)
    assert out == "\\[\n  S(T)\\leq S(P_n).\n\\]\n"
Exemple #6
0
def test_subsuperscript_space():
    input_string = "2^ng"
    out = blacktex.clean(input_string)
    assert out == "2^n g"

    input_string = "2_ng"
    out = blacktex.clean(input_string)
    assert out == "2_n g"

    input_string = "$1/n^3$."
    out = blacktex.clean(input_string)
    assert out == "$1/n^3$."

    input_string = "${n^3}$."
    out = blacktex.clean(input_string)
    assert out == "${n^3}$."

    input_string = "$(n^3)$."
    out = blacktex.clean(input_string)
    assert out == "$(n^3)$."

    input_string = "n^\\alpha"
    out = blacktex.clean(input_string)
    assert out == "n^\\alpha"

    input_string = "a^2_PP^2"
    out = blacktex.clean(input_string)
    assert out == "a^2_P P^2"

    input_string = "a_2^PP_2"
    out = blacktex.clean(input_string)
    assert out == "a_2^P P_2"
Exemple #7
0
def test_coloneqq():
    input_string = "A:=b+c"
    out = blacktex.clean(input_string)
    assert out == "A\\coloneqq b+c"

    input_string = "A := b+c"
    out = blacktex.clean(input_string)
    assert out == "A \\coloneqq b+c"

    input_string = "A : = b+c"
    out = blacktex.clean(input_string)
    assert out == "A \\coloneqq b+c"

    input_string = "b+c =  : A"
    out = blacktex.clean(input_string)
    assert out == "b+c \\eqqcolon A"
Exemple #8
0
def main(argv=None):
    parser = _get_parser()
    args = parser.parse_args(argv)

    out = blacktex.clean(args.infile.read())

    if args.in_place:
        with open(args.infile.name, "w") as f:
            f.write(out)
    else:
        args.outfile.write(out)
Exemple #9
0
def test_readme():
    input_string = (
        "Because   of $$a+b=c$$ ({\\it Pythogoras}),\n"
        "% @johnny remember to insert name,\n"
        "and $y=2^ng$ with $n=1,...,10$, we have ${\\Gamma \\over 2}=8.$")

    out = blacktex.clean(input_string)
    assert out == (
        "Because of\n"
        "\\[\n"
        "a+b = c\n"
        "\\]\n"
        "(\\textit{Pythogoras}),\n"
        "and $y = 2^n g$ with $n = 1,\\dots,10$, we have $\\frac{\\Gamma}{2} = 8$."
    )
Exemple #10
0
def main(argv=None):
    parser = _get_parser()
    args = parser.parse_args(argv)

    stdout = []
    return_code = 0
    for fl in args.infiles:
        with open(fl.name, encoding=args.encoding) as f:
            content = f.read()
        out = blacktex.clean(content, args.keep_comments,
                             args.keep_dollar_math)
        if args.in_place:
            return_code = return_code or int(content != out)
            with open(fl.name, "w", encoding=args.encoding) as f:
                f.write(out)
        else:
            stdout.append(out)

    if not args.in_place:
        print("\n".join(stdout), end="")

    return return_code
Exemple #11
0
def test_env_option_spec():
    input_string = "\\begin{table} \n [h!]G"
    out = blacktex.clean(input_string)
    assert out == "\\begin{table}[h!]\nG"

    input_string = "\\begin{table}   [h!]G"
    out = blacktex.clean(input_string)
    assert out == "\\begin{table}[h!]\nG"

    input_string = "\\begin{table}   [h!]\nG"
    out = blacktex.clean(input_string)
    assert out == "\\begin{table}[h!]\nG"

    input_string = "\\begin{table} \n [h!]G"
    out = blacktex.clean(input_string)
    assert out == "\\begin{table}[h!]\nG"

    input_string = "\\begin{table} \n [h!]\\label{foo}"
    out = blacktex.clean(input_string)
    assert out == "\\begin{table}[h!]\\label{foo}"

    input_string = "\\begin{table} \n [h!]\\label{foo}\nG"
    out = blacktex.clean(input_string)
    assert out == "\\begin{table}[h!]\\label{foo}\nG"
Exemple #12
0
def test_obsolete_text_mod():
    input_string = "lorem {\\it ipsum dolor} sit amet"
    out = blacktex.clean(input_string)
    assert out == "lorem \\textit{ipsum dolor} sit amet"
Exemple #13
0
def test_trailing_whitespace():
    input_string = "lorem    \n sit amet"
    out = blacktex.clean(input_string)
    assert out == "lorem\n sit amet"
Exemple #14
0
def test_over_frac_warn():
    input_string = "Some $2\\over 3^{4+x}$."
    with pytest.warns(UserWarning):
        out = blacktex.clean(input_string)
    assert out == "Some $2\\over 3^{4+x}$."
Exemple #15
0
def test_comment_last():
    input_string = "somemacro{%\n" "foobar% \n" "}"
    out = blacktex.clean(input_string)
    ref = "somemacro{%\nfoobar%\n}"
    assert out == ref, f"{repr(out)} != {repr(ref)}"
Exemple #16
0
def test_multiple_comment_lines():
    input_string = "A\n%\n%\nB"
    out = blacktex.clean(input_string)
    assert out == "A\nB"
Exemple #17
0
def test_text_mods():
    input_string = "{\\em it's me!}"
    out = blacktex.clean(input_string)
    assert out == "\\emph{it's me!}"
Exemple #18
0
def test_multiple_newlines():
    input_string = "lorem  \n\n\n\n\n\n ipsum dolor sit  amet"
    out = blacktex.clean(input_string)
    assert out == "lorem\n\n\n ipsum dolor sit amet"
Exemple #19
0
def test_tabular_column_spec():
    input_string = "\\begin{tabular} \n {ccc}\ncontent"
    out = blacktex.clean(input_string)
    assert out == "\\begin{tabular}{ccc}\ncontent"
Exemple #20
0
def test_linebreak_after_double_backslash():
    input_string = "Some $2\\\\3 4\\\\\n6\\\\[2mm]7$."
    out = blacktex.clean(input_string)
    assert out == "Some $2\\\\\n3 4\\\\\n6\\\\\n[2mm]7$."
Exemple #21
0
def test_nbsp_space():
    input_string = "Some ~thing."
    out = blacktex.clean(input_string)
    assert out == "Some thing."
Exemple #22
0
def test_keywords_without_backslash():
    input_string = "maximum and logarithm $max_x log(x)$"
    out = blacktex.clean(input_string)
    assert out == "maximum and logarithm $\\max_x \\log(x)$"
Exemple #23
0
def test_eqnarray_align():
    input_string = "A\\begin{eqnarray*}a+b\\end{eqnarray*}F"
    out = blacktex.clean(input_string)
    assert out == "A\n\\begin{align*}\na+b\n\\end{align*}\nF"
Exemple #24
0
def test_centerline():
    input_string = "\\centerline{foobar}"
    out = blacktex.clean(input_string)
    assert out == "{\\centering foobar}"
Exemple #25
0
def test_curly_around_round_with_exponent():
    input_string = "$(a+b)^n \\left(a+b\\right)^{n+1}$"
    out = blacktex.clean(input_string)
    assert out == "${(a+b)}^n {\\left(a+b\\right)}^{n+1}$"
Exemple #26
0
def test_over_frac():
    input_string = "Some ${2\\over 3^{4+x}}$ equation ${\\pi \\over4}$."
    out = blacktex.clean(input_string)
    assert out == "Some $\\frac{2}{3^{4+x}}$ equation $\\frac{\\pi}{4}$."
Exemple #27
0
def test_spaces_with_brackets():
    input_string = "( 1+2 ) { 3+4 } \\left( 5+6 \\right)"
    out = blacktex.clean(input_string)
    assert out == "(1+2) {3+4} \\left(5+6\\right)"
Exemple #28
0
def test_overline_warn():
    input_string = "\\overline"
    out = blacktex.clean(input_string)
    assert out == "\\overline"
Exemple #29
0
def test_dollar_dollar():
    input_string = "a $$a + b = c$$ b"
    out = blacktex.clean(input_string)
    assert out == "a\n\\[\na + b = c\n\\]\nb"
Exemple #30
0
def test_def_newcommand():
    input_string = "\\def\\e{\\text{r}}"
    out = blacktex.clean(input_string)
    assert out == "\\newcommand{\\e}{\\text{r}}"