Exemple #1
0
def save_equation(solutions, index, context):
    """
        (list, str) -> None

        Saving solution into onec of the following formats:
            -   LaTex 
            -   MathML
            -   MathJax
    """

    #equation_name = os.path.basename(py_file_name)[:-3]
    equation_name = context['MapppingCSVToLatex']['TargetNamePrefix']['value']

    # creating the folder for tex file
    create_directory(equation_name)

    if context['OutputType'] == 'latex':
        printer = LatexPrinter()
        extension = '.tex'
    elif context['OutputType'] == 'mathml':
        printer = MathMLPrinter()
        extension = '.html'
    elif context['OutputType'] == 'mathjax':
        printer = LatexPrinter()
        extension = '.html'
    else:
        print '[e] UNKNOWN type of output, set "latex", "mathml" or "mathjax"'
        return

    _file_name = '{0}/{1}{2}'.format(equation_name, equation_name + '-' + str(adjust_number(index)), extension)
    save_file(_file_name, to_template(solutions, context, printer))
    print '[i] {0} saved into "{1}"'.format(context['OutputType'], _file_name)
def test_mathml_order():
    expr = x**3 + x**2*y + 3*x*y**3 + y**4

    mp = MathMLPrinter({'order': 'lex'})
    mml = mp._print(expr)

    assert mml.childNodes[1].childNodes[0].nodeName == 'power'
    assert mml.childNodes[1].childNodes[1].childNodes[0].data == 'x'
    assert mml.childNodes[1].childNodes[2].childNodes[0].data == '3'

    assert mml.childNodes[4].childNodes[0].nodeName == 'power'
    assert mml.childNodes[4].childNodes[1].childNodes[0].data == 'y'
    assert mml.childNodes[4].childNodes[2].childNodes[0].data == '4'

    mp = MathMLPrinter({'order': 'rev-lex'})
    mml = mp._print(expr)

    assert mml.childNodes[1].childNodes[0].nodeName == 'power'
    assert mml.childNodes[1].childNodes[1].childNodes[0].data == 'y'
    assert mml.childNodes[1].childNodes[2].childNodes[0].data == '4'

    assert mml.childNodes[4].childNodes[0].nodeName == 'power'
    assert mml.childNodes[4].childNodes[1].childNodes[0].data == 'x'
    assert mml.childNodes[4].childNodes[2].childNodes[0].data == '3'
Exemple #3
0
def test_mathml_order():
    expr = x ** 3 + x ** 2 * y + 3 * x * y ** 3 + y ** 4

    mp = MathMLPrinter({"order": "lex"})
    mml = mp._print(expr)

    assert mml.childNodes[1].childNodes[0].nodeName == "power"
    assert mml.childNodes[1].childNodes[1].childNodes[0].data == "x"
    assert mml.childNodes[1].childNodes[2].childNodes[0].data == "3"

    assert mml.childNodes[4].childNodes[0].nodeName == "power"
    assert mml.childNodes[4].childNodes[1].childNodes[0].data == "y"
    assert mml.childNodes[4].childNodes[2].childNodes[0].data == "4"

    mp = MathMLPrinter({"order": "rev-lex"})
    mml = mp._print(expr)

    assert mml.childNodes[1].childNodes[0].nodeName == "power"
    assert mml.childNodes[1].childNodes[1].childNodes[0].data == "y"
    assert mml.childNodes[1].childNodes[2].childNodes[0].data == "4"

    assert mml.childNodes[4].childNodes[0].nodeName == "power"
    assert mml.childNodes[4].childNodes[1].childNodes[0].data == "x"
    assert mml.childNodes[4].childNodes[2].childNodes[0].data == "3"
Exemple #4
0
def test_mathml_order():
    expr = x**3 + x**2 * y + 3 * x * y**3 + y**4

    mp = MathMLPrinter({'order': 'lex'})
    mml = mp._print(expr)

    assert mml.childNodes[1].childNodes[0].nodeName == 'power'
    assert mml.childNodes[1].childNodes[1].childNodes[0].data == 'x'
    assert mml.childNodes[1].childNodes[2].childNodes[0].data == '3'

    assert mml.childNodes[4].childNodes[0].nodeName == 'power'
    assert mml.childNodes[4].childNodes[1].childNodes[0].data == 'y'
    assert mml.childNodes[4].childNodes[2].childNodes[0].data == '4'

    mp = MathMLPrinter({'order': 'rev-lex'})
    mml = mp._print(expr)

    assert mml.childNodes[1].childNodes[0].nodeName == 'power'
    assert mml.childNodes[1].childNodes[1].childNodes[0].data == 'y'
    assert mml.childNodes[1].childNodes[2].childNodes[0].data == '4'

    assert mml.childNodes[4].childNodes[0].nodeName == 'power'
    assert mml.childNodes[4].childNodes[1].childNodes[0].data == 'x'
    assert mml.childNodes[4].childNodes[2].childNodes[0].data == '3'
Exemple #5
0
from sympy import diff, Integral, Limit, sin, Symbol, Integer, Rational, cos, \
    tan, asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh, E, I, oo, \
    pi, GoldenRatio, EulerGamma, Sum, Eq, Ne, Ge, Lt
from sympy.printing.mathml import mathml, MathMLPrinter
from xml.dom.minidom import parseString

from sympy.utilities.pytest import raises

x = Symbol('x')
y = Symbol('y')
mp = MathMLPrinter()


def test_printmethod():
    assert mp.doprint(1 + x) == '<apply><plus/><ci>x</ci><cn>1</cn></apply>'


def test_mathml_core():
    mml_1 = mp._print(1 + x)
    assert mml_1.nodeName == 'apply'
    nodes = mml_1.childNodes
    assert len(nodes) == 3
    assert nodes[0].nodeName == 'plus'
    assert nodes[0].hasChildNodes() == False
    assert nodes[0].nodeValue is None
    assert nodes[1].nodeName in ['cn', 'ci']
    if nodes[1].nodeName == 'cn':
        assert nodes[1].childNodes[0].nodeValue == '1'
        assert nodes[2].childNodes[0].nodeValue == 'x'
    else:
        assert nodes[1].childNodes[0].nodeValue == 'x'
Exemple #6
0
def test_mathml_printer():
    m = MathMLPrinter()
    assert m.doprint(1 + x) == mp.doprint(1 + x)
Exemple #7
0
def test_mathml_printer():
    m = MathMLPrinter()
    assert m.doprint(1+x) == mp.doprint(1+x)
Exemple #8
0
def test_printing1():
    check(MathMLPrinter())