use insta::assert_snapshot;
use math_core::{LatexToMathML, MathCoreConfig, MathDisplay, PrettyPrint};
#[test]
fn main() {
let problems = [
("empty", r""),
("only_whitespace", r" "),
("starts_with_whitespace", r" x "),
("newline", r"x\\y"),
("text", r"\text{hi}xx"),
("text_multi_space", r"\text{x y}"),
("text_no_braces", r"\text x"),
("text_no_braces_space_after", r"\text x y"),
("text_no_braces_more_space", r"\text xx"),
("text_then_space", r"\text{x}~y"),
("text_nested", r"\text{ \text{a}}"),
("text_nested_it", r"\text{ \textit{a}}"),
("text_nested_it_braces", r"\text{ {\textit{a}b}c}"),
("text_nested_it_some_braces", r"\text{ {\textit a b}c}"),
("text_nested_space", r"\text{{\textit \; b}c}"),
("text_rq", r"\text{\rq}"),
(
"text_diacritics",
r#"\text{\'{a} \~{a} \.{a} \H{a} \`{a} \={a} \"{a} \v{a} \^{a} \u{a} \r{a} \c{c}}"#,
),
("text_diacritics_no_braces", r#"\text{\'a \`a \"a \^a}"#),
("text_diacritics_multiple", r#"\text{\'{aa} \`{aa}}"#),
("text_spaces", r"\text{x\;x\:x\,x\>x\ x~x}"),
("text_with_escape_brace", r"\text{a\}b}"),
("text_with_weird_o", r"\text{x\o y}"),
("text_with_group", r"\text{x{y}z{}p{}}"),
(
"text_with_special_symbols",
r#"\text{!"\#\$\%'()*+,-./:;=?@[]\_`|}"#,
),
("text_html_escape", r"\text{<\&>}"),
("text_greek_direct_input", r"\text{Γγ}"),
("textbackslash", r"\text{\textbackslash}"),
("textit", r"\textit{x}"),
("textbf", r"\textbf{x}"),
("textbf_with_digit", r"\textbf{1234}"),
("textbf_with_digit_dot", r"\textbf{1234.}"),
("textbf_with_digit_decimal", r"\textbf{1234.5}"),
("texttt", r"\texttt{x}"),
("mathtt", r"\mathtt{x}"),
("mathtt_with_digit", r"\mathtt2"),
("mathbf_with_digit", r"\mathbf{1234}"),
("mathbf_with_digit_dot", r"\mathbf{1234.}"),
("mathbf_with_digit_decimal", r"\mathbf{1234.5}"),
("bf", r"{\bf x}"),
("bf_subscript", r"{\bf_2 x}"),
("bf_x_subscript", r"{x\bf_2 x}"),
("bf_spacing", r"{x+\bf x}{x\bf + x}{x+\bf)}"),
("nested_style_combinations", r"\mathtt{x{\it ab\bf asbc}x}"),
("integer", r"0"),
("rational_number", r"3.14"),
("long_number", r"3{,}453{,}435.3453"),
("number_with_dot", r"4.x"),
("long_sub_super", r"x_{92}^{31415}"),
("single_variable", r"x"),
("greek_letter", r"\alpha"),
("greek_letters", r"\phi/\varphi"),
(
"greek_letter_tf",
r"\Gamma\varGamma\boldsymbol{\Gamma\varGamma}",
),
("greek_letter_boldsymbol", r"\boldsymbol{\alpha}"),
("simple_expression", r"x = 3+\alpha"),
("sine_function", r"\sin x"),
("sine_function_parens", r"\sin(x)"),
("sine_function_stretch_parens", r"\sin\left(x\right)"),
("sine_function_sqbrackets", r"\sin[x]"),
("sine_function_brackets", r"\sin\{x\}"),
("sine_sine", r"\sin\sin x"),
("sine_at_group_start", r"x{\sin x}"),
("sine_at_group_end", r"{x\sin}x"),
("sine_at_left", r"x\left(\sin x\right)"),
("sine_at_right", r"x\left(x\sin \right)x"),
("square_root", r"\sqrt 2"),
("square_root_without_space", r"\sqrt12"),
("square_root_with_space", r"\sqrt 12"),
("complex_square_root", r"\sqrt{x+2}"),
("cube_root", r"\sqrt[3]{x}"),
("simple_fraction", r"\frac{1}{2}"),
("fraction_without_space", r"\frac12"),
("fraction_with_space", r"\frac 12"),
("slightly_more_complex_fraction", r"\frac{12}{5}"),
("over", r"{\log x + a^n - \sin(\theta+\eta) \over x}"),
(
"infix_fractions",
r"{a\atop b}, {a\choose b}, {a\brace b}, {a\brack b}",
),
("superscript", r"x^2"),
("sub_superscript", r"x^2_3"),
("super_subscript", r"x_3^2"),
("double_subscript", r"g_{\mu\nu}"),
("subscript_relation", r"g_{1=1}"),
("simple_accent", r"\dot{x}"),
("operator_name", r"\operatorname{sn} x"),
("operator_name_with_spaces", r"\operatorname{ hel lo }"),
("operator_name_with_single_char", r"\operatorname{a}"),
("operator_name_with_space_cmd", r"\operatorname{arg\,max}"),
(
"operator_name_with_text",
r"\operatorname{\text{ab}c\textit{de}f}",
),
("simple_binomial_coefficient", r"\binom12"),
("stretchy_parentheses", r"\left( x \right)"),
("stretchy_one-sided_parenthesis", r"\left( x \right."),
("simple_integral", r"\int dx"),
("contour_integral", r"\oint_C dz"),
("simple_overset", r"\overset{n}{X}"),
("integral_with_bounds", r"\int_0^1 dx"),
("integral_with_lower_bound", r"\int_0 dx"),
("integral_with_upper_bound", r"\int^1 dx"),
("integral_with_reversed_bounds", r"\int^1_0 dx"),
("integral_with_complex_bound", r"\int_{0+1}^\infty"),
("integral_with_limits", r"\int\limits_0^1 dx"),
("integral_with_lower_limit", r"\int\limits_0 dx"),
("integral_with_upper_limit", r"\int\limits^1 dx"),
("integral_with_reversed_limits", r"\int\limits^1_0 dx"),
("integral_pointless_limits", r"\int\limits dx"),
("max_with_limits", r"\max\limits_x y"),
("max_with_sup_limits", r"\max\limits^x"),
("max_with_relation", r"\max_{x\in X}"),
("log_with_limits", r"\log\limits_x"),
("log_with_subscript", r"\log_x"),
("bold_font", r"\bm{x}"),
("black_board_font", r"\mathbb{R}"),
("sum_with_special_symbol", r"\sum_{i = 0}^∞ i"),
("sum_with_limit", r"\sum\limits_{i=1}^N"),
("sum_pointless_limits", r"\sum\limits n"),
("sum_log", r"\sum\log n"),
("product", r"\prod_n n"),
("underscore", r"x\ y"),
("stretchy_brace", r"\left\{ x ( x + 2 ) \right\}"),
("stretchy_bracket", r"\left[ x ( x + 2 ) \right]"),
("matrix", r"\begin{pmatrix} x \\ y \end{pmatrix}"),
(
"align",
r#"\begin{align} f ( x ) &= x^2 + 2 x + 1 \\ &= ( x + 1 )^2\end{align}"#,
),
("align_rel_then_amp", r#"\begin{align}&x\\=\;&2\end{align}"#),
("notag", r#"\begin{align} 1\notag\\2\end{align}"#),
("notag2", r#"\begin{align} 1\mathbf{\notag}\\2\end{align}"#),
("notag3", r#"\begin{align} \notag1\\2\end{align}"#),
("notag4", r#"\begin{align} 1\\\notag2\end{align}"#),
("notag_in_the_wild", r#"(\notag + 1)"#),
("tag", r#"\begin{align} 1\nonumber\tag{32}\\2\end{align}"#),
(
"tag2",
r#"\begin{align} 1\mathbf{\tag{32}}\\2\tag{64}\end{align}"#,
),
("tag3", r#"\begin{align} 1\\2\nonumber\tag{32}\end{align}"#),
("tag4", r#"\begin{align*} 1\\2\tag{32}\end{align*}"#),
("tag5", r#"\begin{align*} \tag{32}1\\2\end{align*}"#),
("label", r#"\begin{align} 1\label{eq:1}\\2\end{align}"#),
(
"label_and_tag",
r#"\begin{align*} 1\label{eq:1}\tag{32}\\2\end{align*}"#,
),
(
"label_in_subscript",
r#"\begin{align} 1_{x\label{eq:1}}\\2\end{align}"#,
),
(
"eqref",
r#"\begin{align} 1\label{eq:1}\\\eqref{eq:1}\end{align}"#,
),
("align_star", r#"\begin{align*}x&=1\\y=2\end{align*}"#),
("equation", r#"\begin{equation}x\\=1\end{equation}"#),
("equation_star", r#"\begin{equation*}x\\=1\end{equation*}"#),
("gather", r#"\begin{gather}x=1\\y=2\end{gather}"#),
(
"gather_nonumber_tag",
r#"\begin{gather}x=1\nonumber\\\tag{32}y=2\end{gather}"#,
),
(
"gather_star",
r#"\begin{gather*}x=1\\y=2\tag{1}\end{gather*}"#,
),
("multline", r#"\begin{multline}x=\\1+\\2\end{multline}"#),
(
"multline_tag",
r#"\begin{multline}x=\tag{4}\\1+\\2\end{multline}"#,
),
(
"text_transforms",
r#"{fi}\ \mathit{fi}\ \mathrm{fi}\ \texttt{fi}"#,
),
("colon_fusion", r"a := 2 \land b :\equiv 3"),
("double_colon", r"a :: b"),
("colon_first_group", r"x{:x}"),
("colon_last_group", r"{x:}x"),
("colon_alone_group", r"x{:}x"),
("colon_approx", r"x:\approx 2"),
("colon_sqrt", r"\sqrt :"),
("colon_subscript", r"x_{x:x}"),
(
"cases",
r"f(x):=\begin{cases}0 &\text{if } x\geq 0\\1 &\text{otherwise.}\end{cases}",
),
("mathstrut", r"\mathstrut"),
("greater_than", r"x > y"),
("text_transform_sup", r"\mathbb{N} \cup \mathbb{N}^+"),
("overbrace", r"\overbrace{a+b+c}^{d}"),
("underbrace", r"\underbrace{a+b+c}_{d}"),
("prod", r"\prod_i \prod^n \prod^n_i \prod_i^n"),
(
"scriptstyle",
r"\sum_{\genfrac{}{}{0pt}{}{\scriptstyle 0 \le i \le m}{\scriptstyle 0 < j < n}} P(i, j)",
),
("scriptstyle_relation", r"{\scriptstyle 1=1}"),
("genfrac", r"\genfrac(]{0pt}{2}{a+b}{c+d}"),
("genfrac_1pt", r"\genfrac(]{1pt}{2}{a+b}{c+d}"),
(
"genfrac_1pt_with_space",
r"\genfrac(]{ 1pt }{2}{a+b}{c+d}",
),
("genfrac_0.4pt", r"\genfrac(]{0.4pt}{2}{a+b}{c+d}"),
("genfrac_0.4ex", r"\genfrac(]{0.4ex}{2}{a+b}{c+d}"),
("genfrac_4em", r"\genfrac(]{4em}2{a+b}{c+d}"),
("not_subset", r"\not\subset"),
("not_less_than", r"\not\lt"),
("not_less_than_symbol", r"\not< x"),
("not_equal", r"\not="),
("not_exists", r"\not\exists"),
("mathrm_with_superscript", r"\mathrm{x}^2"),
("mathrm_with_sin", r"\mathrm{x\sin}"),
("mathrm_with_sin2", r"\mathrm{\sin x}"),
("mathrm_no_brackets", r"\mathrm x"),
("mathit_no_brackets", r"\mathit x"),
("mathbb_no_brackets", r"\mathbb N"),
("mathit_of_max", r"\mathit{ab \max \alpha\beta}"),
("mathit_of_operatorname", r"\mathit{a\operatorname{bc}d}"),
(
"mathit_of_operatorname_single",
r"\mathit{\operatorname{a}}",
),
("nested_transform", r"\mathit{\mathbf{a}b}"),
("mathrm_nested", r"\mathit{\mathrm{a}b}"),
("mathrm_nested2", r"\mathrm{\mathit{a}b}"),
("mathrm_nested3", r"\mathrm{ab\mathit{cd}ef}"),
("mathrm_nested4", r"\mathit{\mathrm{a}}"),
("mathrm_multiletter", r"\mathrm{abc}"),
(
"complicated_operatorname",
r"\operatorname {{\pi} o \Angstrom a}",
),
("operatorname_with_other_operator", r"x\operatorname{\max}"),
(
"continued_fraction",
r"a_0 + \cfrac{1}{a_1 + \cfrac{1}{a_2 + \cfrac{1}{a_3 + \cfrac{1}{a_4}}}}",
),
("standalone_underscore", "_2F_3"),
("really_standalone_underscore", "_2"),
("standalone_superscript", "^2F_3"),
("really_standalone_superscript", "^2"),
("prime", r"f'"),
("double_prime", r"f''"),
("triple_prime", r"f'''"),
("quadruple_prime", r"f''''"),
("quintuple_prime", r"f'''''"),
("prime_alone", "'"),
("prime_and_super", r"f'^2"),
("sub_prime_super", r"f_3'^2"),
("double_prime_and_super", r"f''^2"),
("double_prime_and_super_sub", r"f''^2_3"),
("double_prime_and_sub_super", r"f''_3^2"),
("sum_prime", r"\sum'"),
("int_prime", r"\int'"),
("vec_prime", r"\vec{x}'"),
("overset_spacing", r"x\overset{!}{=}x"),
("overset_with_prime", r"\overset{!}{=}'x"),
("overset_prime", r"\overset{'}{=}x"),
("overset_real_prime", r"\overset{\prime}{=}x"),
("overset_plus", r"\overset{!}{+}"),
("overset_implies", r"\overset{\implies}{xxxxxxx}"),
("overset_with_left_right", r"\overset{!}{\left(x+\right)}"),
("exclamation_mark_spacing", r"x=!=x"),
("int_limit_prime", r"\int\limits'"),
("prime_command", r"f^\prime"),
("prime_command_braces", r"f^{\prime}"),
("transform_group", r"\mathit{a{bc}d}"),
("nabla_in_mathbf", r"\mathbf{\nabla} + \nabla"),
("mathcal_vs_mathscr", r"\mathcal{A}, \mathscr{A}"),
("mathcal_vs_mathscr_single", r"\mathcal A, \mathscr A"),
("mathcal_vs_mathscr_multi", r"\mathcal{AB}, \mathscr{AB}"),
("vertical_line", r"P(x|y)"),
("lvert_and_rvert", r"x + \lvert + y + \rvert + z"),
("lVert_and_rVert2", r"x + \lVert + y + \rVert + z"),
("mid", r"P(x\mid y)"),
("special_symbols", r"\%\$\#"),
("lbrack_instead_of_bracket", r"\sqrt\lbrack 4]{2}"),
("middle_vert", r"\left(\frac12\middle|\frac12\right)"),
(
"middle_uparrow",
r"\left(\frac12\middle\uparrow\frac12\right)",
),
("middle_bracket", r"\left(\frac12\middle]\frac12\right)"),
("left_right_different_stretch", r"\left/\frac12\right)"),
("double_struck_cmds", r"\N\R\Z"),
("odv", r"\odv{f}{x}"),
("xrightarrow", r"\xrightarrow{x}"),
("xrightarrow_character_class", r"x+\xrightarrow{x}=y"),
("xrightarrow_with_under", r"\xrightarrow[a]{b}"),
("xleftarrow_with_under", r"\xleftarrow[a]{b}"),
("xLeftarrow", r"\xLeftarrow{x}"),
("xhookleftarrow", r"\xhookleftarrow{x}"),
("xhookrightarrow", r"\xhookrightarrow{x}"),
("xleftharpoondown", r"\xleftharpoondown{x}"),
("xleftharpoonup", r"\xleftharpoonup{x}"),
("xleftrightarrow", r"\xleftrightarrow{x}"),
("xleftrightharpoons", r"\xleftrightharpoons{x}"),
("xlongequal", r"\xlongequal{x}"),
("xmapsto", r"\xmapsto{x}"),
("xrightharpoondown", r"\xrightharpoondown{x}"),
("xrightharpoonup", r"\xrightharpoonup{x}"),
("xrightleftharpoons", r"\xrightleftharpoons{x}"),
("xtofrom", r"\xtofrom{x}"),
("xtwoheadleftarrow", r"\xtwoheadleftarrow{x}"),
("xtwoheadrightarrow", r"\xtwoheadrightarrow{x}"),
("slashed", r"\slashed{\partial}"),
("plus_after_equal", r"x = +4"),
("plus_after_equal_with_space", r"x =\, +4"),
("plus_after_bigl", r"\bigl)+ x"),
("plus_after_bigr", r"\bigr(+ x"),
("plus_after_open_paren", r"(+x)"),
("plus_before_open_paren", r"x+(x)"),
("plus_after_closing_paren", r"(x)+x"),
("plus_before_closing_paren", r"(x+)"),
("equal_after_plus", r"x+ = 4"),
("equal_after_plus_and_space", r"x+ \,= 4"),
("plus_in_braces", r"4{+}4"),
("plus_before_punctuation", r"4+,"),
("plus_before_eof", r"4+"),
("plus_at_group_end", r"{4+}x"),
("equal_at_group_begin", r"x{=x}"),
("equal_at_group_end", r"{x=}x"),
("equal_at_start_of_pseudo_row", r"x \displaystyle = x"),
("equal_at_start_of_pseudo_row_punct", r", \displaystyle = x"),
("equal_before_right", r"\left(x=\right)x"),
("sqrt_equal_three", r"\sqrt{=3}"),
("equal_squared", r"==^2 x"),
("equal_vectored", r"=\vec{=}x"),
("sqrt_sum", r"\sqrt\sum"),
("sqrt_log_braces", r"\sqrt{\log}"),
("root_op", r"\sqrt[+]{x}"),
("root_log", r"\sqrt[\log]{x}"),
("log_in_big", r"\bigl(\log\bigr) + \big(\log\big)"),
("bigl_pipe", r"\bigl| x \bigr|"),
("big_pipe", r"\big| x \big|"),
("bigl_double_pipe", r"\bigl\| x \bigr\|"),
("bigm_pipe", r"2+\bigm|)"),
("bigm_close_paren", r"2+\bigm()"),
("bigm_uparrow", r"x\bigm\uparrow x"),
("bigm_slash", r"x\bigm/ x"),
("plus_after_sum", r"\sum + 4"),
("plus_before_sum", r"4 + \sum"),
("plus_after_equal_subscript", r"x =_+4"),
("plus_after_equal_subscript2", r"x =_2 +4"),
("plus_after_equal_subscript3", r"x =_{2} + 4"),
("equal_equal", r"4==4"),
("equal_equal_with_space", r"4=\;=4"),
("subscript_equal_equal", r"x_==4"),
("color", r"{\color{Blue}x^2}"),
("hspace", r"\hspace{1cm}"),
("hspace_whitespace", r"\hspace{ 4em }"),
("hspace_whitespace_in_between", r"\hspace{ 4 em }"),
("math_spaces", r"x\qquad x\quad x\;x\:x\>x\,x\ x~x\space x"),
("array_simple", r"\begin{array}{lcr} 0 & 1 & 2 \end{array}"),
(
"array_lines",
r"\begin{array}{ |l| |rc| } 10 & 20 & 30\\ 4 & 5 & 6 \end{array}",
),
(
"array_many_lines",
r"\begin{array}{ ||::|l } 10\\ 2 \end{array}",
),
(
"subarray",
r"\sum_{\begin{subarray}{c} 0 \le i \le m\\ 0 < j < n \end{subarray}}",
),
("mod", r"a \equiv r \mod n"),
("nested_custom_cmd", r"\odv{\odv f x} x"),
("and_between_letters", r"x\And x"),
("and_before_relation", r"x\And =x"),
("idotsint", r"x \idotsint ="),
("idotsint_with_limits", r"\idotsint\limits_0^1 xy"),
("cdots_before_open", r"4 + \cdots ()"),
("cdots_before_close", r"{\sum \cdots}"),
("dots_in_subscript", r"x_{\ldots\log}"),
("infix_double_bar", r"x \| y"),
("underset_tilde", r"\underset{z\sim Z}{\mathbb{E}}"),
("bra_and_ket", r"x\bra{\uparrow} + \ket{\downarrow}y"),
("mathbin", r"x\mathbin{|}y"),
("mathbin_no_braces", r"x\mathbin|y"),
("mathbin_paren", r"{\frac12\mathbin)y}"),
("mathbin_after_dots", r"\dots\mathbin+, \dots+"),
("comma_before_close_paren", r"4,)"),
];
let config = MathCoreConfig {
pretty_print: PrettyPrint::Always,
..Default::default()
};
let converter = LatexToMathML::new(config).unwrap();
for (name, problem) in problems.into_iter() {
let mathml = converter
.convert_with_local_counter(problem, MathDisplay::Inline)
.expect(format!("failed to convert `{}`", problem).as_str());
assert_snapshot!(name, &mathml, problem);
}
}