def test_add_to_super_before_alternative(cursor):
    elems = from_latex("xy^{z}")
    cursor.reparent(elems, 2)
    cursor.handle_movement(Direction.LEFT, select=True)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{yz}"
    assert cursor.owner is elems[1].exponent
Example #2
0
def test_delete_into(cursor):
    elems = from_latex(r"\frac{abc}{def}")
    cursor.reparent(elems, 0)
    cursor.backspace(plots.utils.Direction.RIGHT)
    assert elems.to_latex() == r"\frac{bc}{def}"
    assert cursor.owner is elems[0].numerator
    assert cursor.pos == 0
Example #3
0
def test_select_all_backspace():
    cursor = Cursor()
    elems = from_latex("abcd")
    cursor.reparent(elems, 2)
    cursor.select_all(elems)
    cursor.backspace(None)
    assert len(elems) == 0
def test_add_to_super_after(cursor):
    elems = from_latex("x^{2}2")
    cursor.reparent(elems, -1)
    cursor.handle_movement(Direction.LEFT, select=True)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{22}"
    assert cursor.owner is elems[1].exponent
Example #5
0
 def undo(self, app):
     row = app.rows[self.index]
     row.editor.set_expr(parser.from_latex(self.before.formula))
     row.color_picker.set_rgba(self.before.rgba)
     row.editor.grab_focus()
     row.editor.queue_draw()
     row.edited(None, record=False)
Example #6
0
def test_backspace_into(cursor):
    elems = from_latex(r"\frac{abc}{def}")
    cursor.reparent(elems, -1)
    cursor.backspace(plots.utils.Direction.LEFT)
    assert elems.to_latex() == r"\frac{abc}{de}"
    assert cursor.owner is elems[0].denominator
    assert cursor.pos == 2
Example #7
0
def test_calculate_selection_deep(cursor):
    elems = from_latex(r"x\abs{3}-3\sqrt{\frac{2}{x}}+4")
    cursor.reparent(elems[1].argument, -1)
    cursor.secondary_owner = elems[4].radicand[0].denominator
    cursor.secondary_pos = 0
    _range, ancestor = cursor.calculate_selection()
    assert _range == range(1, 5)
    assert ancestor is elems
Example #8
0
 def undo(self, app):
     if self.last:
         app.rows[0].delete(None, record=False, replace_if_last=False)
     row = formularow.FormulaRow(app)
     app.insert_row(self.index, row)
     row.editor.set_expr(parser.from_latex(self.formula))
     row.color_picker.set_rgba(self.rgba)
     row.edited(None, record=False)
     row.editor.grab_focus()
Example #9
0
def test_ancestors(cursor):
    elems = from_latex(
        r"\sqrt{\operatorname{cos}\frac{3}{4\abs{\sum_{i=1}^{3}}}}")
    expected = [
        elems[0].radicand[1].denominator[1].argument[0].bottom,
        elems[0].radicand[1].denominator[1].argument,
        elems[0].radicand[1].denominator,
        elems[0].radicand,
        elems,
    ]
    actual = cursor.ancestors(
        elems[0].radicand[1].denominator[1].argument[0].bottom)
    for e, a in zip(expected, actual):
        assert e is a
Example #10
0
def test_frac_accept_selection(cursor):
    elems = from_latex(r"xyz")
    cursor.select_all(elems)
    cursor.greedy_insert(e.Frac)
    assert elems.to_latex() == r"\frac{xyz}{}"
    assert cursor.owner is elems[0].denominator
Example #11
0
def test_add_super_to_sub(cursor):
    elems = from_latex("x_{3}")
    cursor.reparent(elems, -1)
    cursor.insert_superscript_subscript(superscript=True)
    assert elems.to_latex() == "x_{3}^{}"
    assert cursor.owner is elems[1].exponent
Example #12
0
def test_add_sub_to_super(cursor):
    elems = from_latex("x^{3}")
    cursor.reparent(elems, -1)
    cursor.insert_superscript_subscript(superscript=False)
    assert elems.to_latex() == "x_{}^{3}"
    assert cursor.owner is elems[1].subscript
Example #13
0
def test_mouse_select_list(cursor):
    elems = from_latex(r"3x\abs{}")
    cursor.mouse_select(elems[2].argument, Direction.RIGHT, drag=False)
    assert cursor.owner is elems[2].argument
    assert cursor.pos is 0
Example #14
0
def test_greedy_insert_with_numbers(cursor):
    elems = from_latex(r"3.238923829-4")
    cursor.reparent(elems, 6)
    cursor.greedy_insert(e.Frac)
    assert elems.to_latex() == r"\frac{3.2389}{23829}-4"
Example #15
0
def test_handle_movement_down_out(cursor):
    elems = from_latex(r"\abs{x}")
    cursor.reparent(elems[0].argument, -1)
    cursor.handle_movement(Direction.DOWN)
    assert cursor.owner is elems
    assert cursor.pos == 1
Example #16
0
def test_sum_to_glsl(latex, body, expr):
    f.Sum.glsl_var_counter = 0
    glsl = from_latex(latex).to_glsl()
    assert clean(glsl[0]) == clean(body)
    assert glsl[1] == expr
Example #17
0
def test_insert_empty_super(cursor):
    elems = from_latex("x")
    cursor.reparent(elems, -1)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == r"x^{}"
    assert cursor.owner is elems[1].exponent
Example #18
0
def test_move_to_previous_list(cursor):
    elems = from_latex(r"\frac{3}{2}")
    cursor.reparent(elems[0].denominator, 0)
    cursor.handle_movement(Direction.LEFT)
    assert cursor.owner is elems[0].numerator
    assert cursor.pos == 1
Example #19
0
def test_move_to_next_list(cursor):
    elems = from_latex(r"\frac{3}{2}")
    cursor.reparent(elems[0].numerator, -1)
    cursor.handle_movement(Direction.RIGHT)
    assert cursor.owner is elems[0].denominator
    assert cursor.pos == 0
Example #20
0
def test_backspace():
    cursor = Cursor()
    elems = from_latex("abcd")
    cursor.reparent(elems, 2)
    cursor.backspace(Direction.LEFT)
    assert elems.to_latex() == "acd"
Example #21
0
def test_dissolve(cursor):
    elems = from_latex(r"\frac{abc}{def}")
    cursor.reparent(elems[0].numerator, 0)
    cursor.backspace(plots.utils.Direction.LEFT)
    assert elems.to_latex() == "abcdef"
    assert cursor.owner is elems
Example #22
0
def test_greedy_insert(cursor):
    elems = from_latex(r"3\sqrt{x}(x(9-x))-4")
    cursor.reparent(elems, 2)
    cursor.greedy_insert(e.Frac)
    assert elems.to_latex() == r"3\frac{\sqrt{x}}{(x(9-x))}-4"
Example #23
0
def test_move_to_super_before(cursor):
    elems = from_latex("x^{2}")
    cursor.reparent(elems, 1)
    cursor.insert_superscript_subscript()
    assert elems.to_latex() == "x^{2}"
    assert cursor.owner is elems[1].exponent
Example #24
0
def test_mouse_select_then_drag(cursor):
    elems = from_latex(r"abcd")
    cursor.mouse_select(elems[1], Direction.LEFT, drag=False)
    cursor.mouse_select(elems[3], Direction.LEFT, drag=True)
    assert cursor.owner is elems
    assert cursor.selection_bounds == range(1, 3)
Example #25
0
def do_convert_specials(name):
    elems = from_latex(name)
    cursor = Cursor()
    cursor.reparent(elems, -1)
    elems.convert_specials(cursor)
    return elems
Example #26
0
def test_delete_super(cursor):
    elems = from_latex("x_{4}^{3}")
    cursor.reparent(elems[1].exponent, 0)
    cursor.backspace(Direction.LEFT)
    assert elems.to_latex() == "x_{4}3"
Example #27
0
def test_greedy_insert_with_parens(cursor):
    elems = from_latex(r"3(x+1)(x(9-x))-4")
    cursor.reparent(elems, 6)
    cursor.greedy_insert(e.Frac)
    assert elems.to_latex() == r"3\frac{(x+1)}{(x(9-x))}-4"
Example #28
0
def test_delete_sub(cursor):
    elems = from_latex("x_{4}^{3}")
    cursor.reparent(elems[1].subscript, 0)
    cursor.backspace(Direction.LEFT)
    assert elems.to_latex() == "x4^{3}"
Example #29
0
 def paste(self):
     text = self.clipboard.wait_for_text()
     elements = parser.from_latex(text)
     if self.selecting:
         self.backspace(None)
     self.owner.insert_elementlist(elements, self, self.pos)
Example #30
0
def test_mouse_select_right(cursor):
    elems = from_latex(r"abcd")
    cursor.mouse_select(elems[1], Direction.RIGHT, drag=False)
    assert cursor.owner is elems
    assert cursor.pos is 2