예제 #1
0
def as_html_handle_data_algebra(mathobj):
    r"""Return ``mathobj`` converted into a string safe to be used in HTML.

    -   If ``mathobj`` is a `MathObject`, it will be represented as LaTeX markup and wrapped in the
        mathjax escape token.
    -   If it is a container of `MathObject`\s, then each one will be represented as LaTeX
        markup and displayed on its own line.
    -   If it is not a `MathObject` then the ``str`` function will be invoked.
    """
    if isinstance(mathobj, _mo.MathObject):
        # print this one math object
        return "$$" + _html.escape(_latexprinter.math_object_to_latex(mathobj)) + "$$"
    elif isinstance(mathobj, _collections.Iterable):
        temp = ""
        for elem in mathobj:
            if isinstance(elem, _mo.MathObject):
                # latex
                temp += r"$$\(\require{color}\)\(\require{xcolor}\)" + \
                        _html.escape(_latexprinter.math_object_to_latex(elem)) + "$$ <br //>"
            else:
                # str
                temp += _html.escape(str(elem)) + "<br //>"

        return temp
    else:
        # print this one non-math object using str(mathobjects)
        return _html.escape(str(mathobj))
예제 #2
0
def as_html_handle_data_algebra(mathobj):
    r"""Return ``mathobj`` converted into a string safe to be used in HTML.

    -   If ``mathobj`` is a `MathObject`, it will be represented as LaTeX markup and wrapped in the
        mathjax escape token.
    -   If it is a container of `MathObject`\s, then each one will be represented as LaTeX
        markup and displayed on its own line.
    -   If it is not a `MathObject` then the ``str`` function will be invoked.
    """
    if isinstance(mathobj, _mo.MathObject):
        # print this one math object
        return "$$" + _html.escape(_latexprinter.math_object_to_latex(mathobj)) + "$$"
    elif isinstance(mathobj, _collections.Iterable):
        temp = ""
        for elem in mathobj:
            if isinstance(elem, _mo.MathObject):
                # latex
                temp += r"$$\(\require{color}\)\(\require{xcolor}\)" + \
                        _html.escape(_latexprinter.math_object_to_latex(elem)) + "$$ <br //>"
            else:
                # str
                temp += _html.escape(str(elem)) + "<br //>"

        return temp
    else:
        # print this one non-math object using str(mathobjects)
        return _html.escape(str(mathobj))
예제 #3
0
 def test_set_printer(self):
     self._enable_colorization(False)
     # Actual LaTeX Output Data
     latex_set1 = math_object_to_latex(self._s1)
     latex_set2 = math_object_to_latex(self._s2)
     if self._print_examples:
         print("test_set_printer Begin:")
         print('\tSet={s!s}'.format(s=self._s1))
         print('\tLatex={l!s}'.format(l=latex_set1))
         print('\tSet={s!s}'.format(s=self._s2))
         print('\tLatex={l!s}'.format(l=latex_set2))
         print("Test End.")
예제 #4
0
 def test_set_printer(self):
     self._enable_colorization(False)
     # Actual LaTeX Output Data
     latex_set1 = math_object_to_latex(self._s1)
     latex_set2 = math_object_to_latex(self._s2)
     if self._print_examples:
         print("test_set_printer Begin:")
         print('\tSet={s!s}'.format(s=self._s1))
         print('\tLatex={l!s}'.format(l=latex_set1))
         print('\tSet={s!s}'.format(s=self._s2))
         print('\tLatex={l!s}'.format(l=latex_set2))
         print("Test End.")
예제 #5
0
    def test_set_of_set_printer(self):
        self._enable_colorization(False)
        # large comparisons needs diff size increased
        self.maxDiff = None
        # Actual LaTeX Output Data
        latex_set = math_object_to_latex(self._s3)

        # Expected LaTeX Output Data
        latex_set_ex_p1 = (
            "\left\{\mbox{'mystery'}{\mapsto}{\mbox{'van'}},"
            "\ \mbox{'scooby'}{\mapsto}{\mbox{'doo'}},\ "
            "\mbox{'shaggy'}{\mapsto}{\mbox{'rogers'}}\\right\}")

        latex_set_ex_p2 = (
            "\left\{\mbox{'daphne'}{\mapsto}{\mbox{'blake'}},\ "
            "\mbox{'fred'}{\mapsto}{\mbox{'jones'}},\ "
            "\mbox{'mystery'}{\mapsto}{\mbox{'team'}},\ "
            "\mbox{'velma'}{\mapsto}{\mbox{'dinkley'}}\\right\}")

        latex_set_ex = "\left\{\\begin{array}{l}" + \
                       latex_set_ex_p2 + ",\\\\\n" + latex_set_ex_p1 + \
                       "\end{array}\\right\}"
        self.assertEqual(latex_set_ex, latex_set)

        if self._print_examples:
            print("test_set_of_set_printer Begin:")
            print('Set={s!s}'.format(s=self._s3))
            print('Act={l!s}'.format(l=latex_set))
            print('Exp={l!s}'.format(l=latex_set_ex))
            print("Test End.")
예제 #6
0
    def test_set_of_set_printer(self):
        self._enable_colorization(False)
        # large comparisons needs diff size increased
        self.maxDiff = None
        # Actual LaTeX Output Data
        latex_set = math_object_to_latex(self._s3)

        # Expected LaTeX Output Data
        latex_set_ex_p1 = ("\left\{\mbox{'mystery'}{\mapsto}{\mbox{'van'}},"
                           "\ \mbox{'scooby'}{\mapsto}{\mbox{'doo'}},\ "
                           "\mbox{'shaggy'}{\mapsto}{\mbox{'rogers'}}\\right\}")

        latex_set_ex_p2 = ("\left\{\mbox{'daphne'}{\mapsto}{\mbox{'blake'}},\ "
                           "\mbox{'fred'}{\mapsto}{\mbox{'jones'}},\ "
                           "\mbox{'mystery'}{\mapsto}{\mbox{'team'}},\ "
                           "\mbox{'velma'}{\mapsto}{\mbox{'dinkley'}}\\right\}")

        latex_set_ex = "\left\{\\begin{array}{l}" + \
                       latex_set_ex_p2 + ",\\\\\n" + latex_set_ex_p1 + \
                       "\end{array}\\right\}"
        self.assertEqual(latex_set_ex, latex_set)

        if self._print_examples:
            print("test_set_of_set_printer Begin:")
            print('Set={s!s}'.format(s=self._s3))
            print('Act={l!s}'.format(l=latex_set))
            print('Exp={l!s}'.format(l=latex_set_ex))
            print("Test End.")
예제 #7
0
    def test_couplet_printer(self):
        self._enable_colorization(False)
        # Actual LaTeX Output Data
        latex_couplet = math_object_to_latex(self._c1)
        # Expected LaTeX Output Data
        latex_couplet_ex = "\mbox{'scooby'}{\mapsto}{\mbox{'doo'}}"
        self.assertEqual(latex_couplet_ex, latex_couplet)

        if self._print_examples:
            print("test_couplet_printer Begin:")
            print('\tCouplet={c!s}'.format(c=self._c1))
            print('\tLatex={l!s}'.format(l=latex_couplet))
            print("Test End.")
예제 #8
0
    def test_couplet_printer(self):
        self._enable_colorization(False)
        # Actual LaTeX Output Data
        latex_couplet = math_object_to_latex(self._c1)
        # Expected LaTeX Output Data
        latex_couplet_ex = "\mbox{'scooby'}{\mapsto}{\mbox{'doo'}}"
        self.assertEqual(latex_couplet_ex, latex_couplet)

        if self._print_examples:
            print("test_couplet_printer Begin:")
            print('\tCouplet={c!s}'.format(c=self._c1))
            print('\tLatex={l!s}'.format(l=latex_couplet))
            print("Test End.")
예제 #9
0
    def test_atom_printer(self):
        self._enable_colorization(False)

        # Actual LaTeX Output Data
        latex_atom = math_object_to_latex(self._a1)
        # Expected LaTeX Output Data
        latex_atom_ex = "\mbox{'scooby'}"
        self.assertEqual(latex_atom_ex, latex_atom)

        if self._print_examples:
            print("test_atom_printer Begin:")
            print('\tAtom={a!s}'.format(a=self._a1))
            print('\tLatex={l!s}'.format(l=latex_atom))
            print("Test End.")
예제 #10
0
    def test_atom_printer(self):
        self._enable_colorization(False)

        # Actual LaTeX Output Data
        latex_atom = math_object_to_latex(self._a1)
        # Expected LaTeX Output Data
        latex_atom_ex = "\mbox{'scooby'}"
        self.assertEqual(latex_atom_ex, latex_atom)

        if self._print_examples:
            print("test_atom_printer Begin:")
            print('\tAtom={a!s}'.format(a=self._a1))
            print('\tLatex={l!s}'.format(l=latex_atom))
            print("Test End.")
예제 #11
0
    def test_set_printer(self):
        self._enable_colorization(False)
        # Actual LaTeX Output Data
        latex_set1 = math_object_to_latex(self._s1)
        latex_set2 = math_object_to_latex(self._s2)

        # Expected LaTeX Output Data
        latex_set_ex1 = ("\left\{\ \mbox{'van'}^{\mbox{'mystery'}},\ "
                         "\mbox{'doo'}^{\mbox{'scooby'}},\ "
                         "\mbox{'rogers'}^{\mbox{'shaggy'}}\ \\right\}")

        latex_set_ex2 = ("\left\{\ \mbox{'blake'}^{\mbox{'daphne'}},\ "
                         "\mbox{'jones'}^{\mbox{'fred'}},\ "
                         "\mbox{'team'}^{\mbox{'mystery'}},\ "
                         "\mbox{'dinkley'}^{\mbox{'velma'}}\ \\right\}")
        latex_mixed_set_with_couplet = math_object_to_latex(Set('a', Couplet('x', 'y')))
        if self._print_examples:
            print("test_set_printer Begin:")
            print('\tSet={s!s}'.format(s=self._s1))
            print('\tLatex={l!s}'.format(l=latex_set1))
            print('\tSet={s!s}'.format(s=self._s2))
            print('\tLatex={l!s}'.format(l=latex_set2))
            print("Test End.")
예제 #12
0
def create_simple_web_page(mathobj: _mo.MathObject) -> str:
    """Return an HTML string for a simple HTML page from a single `MathObject`."""
    web_template = r"""\
<html>
    <head>
        <script
        src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'>
        </script>
        <script type="text/javascript">
        //<![CDATA[  //]]>
        </script>
        <style>
            body {{background-color: #F8F8FF}}
            #latexArea, #dataAlgebraArea{{
                width: 1000px;
                height: 200px;
                border: 1px solid black;
                padding: 5px;
                overflow: scroll;
                background-color: white;
                resize: both;
            }}
        </style>
    </head>
    <body>
        <h1>MathJax is Easy!</h1>
        <h2>Input:</h2>
        <div id="dataAlgebraArea">{data_algebra_in!s}</div>
        <h2>Output:</h2>
        <div id="latexArea">$$\(\require{color}\){latex_out}$$</div>
    </body></html>
    """
    web_out = web_template.format(
        data_algebra_in=mathobj,
        latex_out=_latexprinter.math_object_to_latex(mathobj))
    print(web_out)
    return web_out
예제 #13
0
def create_simple_web_page(mathobj: _mo.MathObject) -> str:
    """Return an HTML string for a simple HTML page from a single `MathObject`."""
    web_template = r"""\
<html>
    <head>
        <script
        src='https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML'>
        </script>
        <script type="text/javascript">
        //<![CDATA[  //]]>
        </script>
        <style>
            body {{background-color: #F8F8FF}}
            #latexArea, #dataAlgebraArea{{
                width: 1000px;
                height: 200px;
                border: 1px solid black;
                padding: 5px;
                overflow: scroll;
                background-color: white;
                resize: both;
            }}
        </style>
    </head>
    <body>
        <h1>MathJax is Easy!</h1>
        <h2>Input:</h2>
        <div id="dataAlgebraArea">{data_algebra_in!s}</div>
        <h2>Output:</h2>
        <div id="latexArea">$$\(\require{color}\){latex_out}$$</div>
    </body></html>
    """
    web_out = web_template.format(
        data_algebra_in=mathobj, latex_out=_latexprinter.math_object_to_latex(mathobj))
    print(web_out)
    return web_out