assignment.py 610 Bytes
Newer Older
Martin Bauer's avatar
Martin Bauer committed
1
# -*- coding: utf-8 -*-
2
3
4
5
6
7
8
9
10
11
12
13
14
from sympy.codegen.ast import Assignment
from sympy.printing.latex import LatexPrinter

__all__ = ['Assignment']


def print_assignment_latex(printer, expr):
    """sympy cannot print Assignments as Latex. Thus, this function is added to the sympy Latex printer"""
    printed_lhs = printer.doprint(expr.lhs)
    printed_rhs = printer.doprint(expr.rhs)
    return f"{printed_lhs} \leftarrow {printed_rhs}"


Martin Bauer's avatar
Martin Bauer committed
15
16
17
18
19
def assignment_str(assignment):
    return f"{assignment.lhs}{assignment.rhs}"


Assignment.__str__ = assignment_str
20
LatexPrinter._print_Assignment = print_assignment_latex