algebraixlib.util.html module

A conversion utility that manipulates a math object into a LaTeX representation.

class algebraixlib.util.html.DataAlgebraHtmlDescriptor(input_title, data_algebra_construct, description_brief)

Bases: tuple

static __new__(_cls, input_title, data_algebra_construct, description_brief)

Create new instance of DataAlgebraHtmlDescriptor(input_title, data_algebra_construct, description_brief)

__repr__()

Return a nicely formatted representation string

data_algebra_construct

Alias for field number 1

description_brief

Alias for field number 2

input_title

Alias for field number 0

algebraixlib.util.html.math_object_as_html(title: str, data_algebra_html_descriptors: [], header_template: str=None, footer_template: str=None, mathobject_template: str=None) → str[source]

Return the contents of an HTML webpage representing a math object, using templates.

Parameters:
  • title – The title for this page of math objects.
  • data_algebra_html_descriptors – An array of DataAlgebraHtmlDescriptor instances (containing math objects and their related descriptive strings).
  • header_template – HTML markup that starts the webpage. May contain the template page_title; it is set to the value of title.
  • footer_template – HTML markup that ends the page.
  • mathobject_template – The HTML markup that is emited for each math object. May contain the templates input_title, description_brief and data_algebra_construct, which are replaced with the respective values in the associated DataAlgebraHtmlDescriptor.
Returns:

The final HTML webpage.

algebraixlib.util.html.as_html_handle_basic_parameter(html_input: str) → str[source]

Convert the string of html_input into an HTML-safe character sequence.

Parameters:html_input – The value to convert so that it can be added to HTML content.
Returns:An HTML-safe string.
algebraixlib.util.html.as_html_handle_data_algebra(mathobj)[source]

Add some logic to allow the client to provide the math object in several ways:

  • If it is a mathobject, it will be turnied into LaTeX and wrapped in the mathjax escape token.
  • If it is a container of mathobjects, then each one will be turned into LaTeX and presented on its own line.
  • If it is not a mathobject then the str function will be invoked.
Parameters:mathobj – The data algebra construct to be rendered on HTML
Returns:The HTML snippet of the mathobject.
algebraixlib.util.html.build_descriptors_from_math_obj(mathobjects)[source]

A utility function if a client does not wish to create their own descriptor objects. This function will create a descriptor array from a list of mathobjects.

Parameters:mathobjects – List to build descriptors out of.
Returns:DataAlgebraHtmlDescriptors
algebraixlib.util.html.create_simple_web_page(mathobj: algebraixlib.mathobjects.mathobject.MathObject) → str[source]

Convert a math object into an HTML file. This does not offer much client specification or HTML injection. Create a basic webpage for one mathobject.

Parameters:mathobj – The mathobject to create a webpage for.
Returns:The web page (HTML) for mathobj.
class algebraixlib.util.html.DataAlgToWebTest(methodName='runTest')[source]

Bases: unittest.case.TestCase

Test the latex printer functions.

Create an instance of the class that will use the named test method when executed. Raises a ValueError if the instance does not have a method with the specified name.

test_data_alg_to_web_simple()[source]
test_data_alg_to_web()[source]