Math2Code’s Documentation

app.image2latex.call_mathpix_api(file_path: str) → dict

Gets the confidence score and latex string of an image from a specified file path using the Mathpix API.

Args:
Input: file_path: path of the specified image
Returns:
Output: Dictionary {‘confidence’:int , ‘latex_str’:str, ‘error’:bool, ‘error_msg’:str} ‘error_msg’={‘file size is more than 4 MB’, ‘Invalid file’, ‘low confidence’,’NA’}
app.latex2numpy.absolute(scope: list, index: int) → list

Replace || with np.absolute

app.latex2numpy.add_multiplier(scope: list, index: int, verbose=True) → list
Input:

scope = the list that you are currently working on index = the index of the element of the list called scope

that you are currently checking
Output:
A new list with asterisk symbol added if no operation is specified
app.latex2numpy.change_var_name(scope: list, index: int, list_of_names: list, verbose: bool) → list
Input:

scope = the list that you are currently working on index = the index of the element of the list called scope

that you are currently checking
Output:
A new list where (vec, hat, bar, prime, ect) change variable name thus turns into str See examples: 2, 12, 24, 25!
app.latex2numpy.clip_start(new_text: list) → list
app.latex2numpy.exp(text: list, index: int) → list
app.latex2numpy.expand_matrix(scope: list, index: int) → list
Input:

scope = the list that you are currently working on index = the index of the element of the list called scope

that you are currently checking
Output:
Check if scope is an expanded matrix (with numbers) and if so, turn that into a numpy matrix ex - np.matrix([[1, 2], [3, 4]]) See examples: 124
app.latex2numpy.exponent(scope: list, index: int, list_of_names: list) → list
app.latex2numpy.fix_caps(scope: list, index: int) → list

Replace S S E with SSE

app.latex2numpy.frac(scope: list, index: int) → list
app.latex2numpy.inject_list(index: int, big_list: list, small_list: list) → list
app.latex2numpy.latex2numpy(latex: str) → str

Primary function that transforms latex strings to numpy

Input: latex string from OCR API Output: numpy formatted string or Error message

app.latex2numpy.log(text: list, index: int) → list
app.latex2numpy.matrix_multiply(scope: list, index: int) → list
Input:

scope = the list that you are currently working on index = the index of the element of the list called scope

that you are currently checking
Output:
A new list where ‘cdot’ turns into A@B where A = scope[index-1] and B = scope[index+1] Note - ‘@’ is recommended over np.dot(A,B) See examples: 2
app.latex2numpy.operator_name(scope: list, index: int, operator_flag: bool) → list

Convert [‘operatorname’, [‘funct_name’], [‘arg1’, ‘arg2’] into def funct_name(arg1, arg2):

pass

funct_name(arg1, arg2)

app.latex2numpy.organize_functions(text: list, my_functs: dict) → list

identifies where a function starts and ends (happens right before the scope is joined together)

app.latex2numpy.parse_nested_regex(text, left, right, verbose, delimiter=', ')

https://stackoverflow.com/a/17141899/190597 (falsetru)

app.latex2numpy.recursive_walk(text: list, iter_var='', my_functs={}, verbose=False) → list
app.latex2numpy.replace_font_format(scope: list, index: int, verbose=True) → list
Input:

scope = the list that you are currently working on index = the index of the element of the list called scope

that you are currently checking
Output:
A new list where math_bf is replaced by <var>_bold where <var> is the variable in proceeding list
app.latex2numpy.split_operator(element: str) → list
app.latex2numpy.sqrt(scope: list, index: int) → list
app.latex2numpy.sum_prod_loop(scope: list, index: int) → list
app.latex2numpy.turn_into_var(scope: list, index: int, iter_var: str) → list
app.utils.get_mathpix_credentials()

Gets credentials for mathpix API.

app.utils.upload_to_aws(local_file, userid, s3_filename, bucket='math2code')

Write Image to s3://<bucket>/<bucket_path>. * Currently not a feature of Application *

class app.classes.LogInForm(formdata=<object object>, **kwargs)
password = <UnboundField(PasswordField, ('Password: ',), {'validators': [<wtforms.validators.DataRequired object>]})>
submit = <UnboundField(SubmitField, ('Login',), {})>
username = <UnboundField(StringField, ('Username: ',), {'validators': [<wtforms.validators.DataRequired object>]})>
class app.classes.RegistrationForm(formdata=<object object>, **kwargs)
email = <UnboundField(StringField, ('Email: ',), {'validators': [<wtforms.validators.DataRequired object>]})>
password = <UnboundField(PasswordField, ('Password: ',), {'validators': [<wtforms.validators.DataRequired object>]})>
submit = <UnboundField(SubmitField, ('Register',), {})>
username = <UnboundField(StringField, ('Username: ',), {'validators': [<wtforms.validators.DataRequired object>]})>
class app.classes.User(username, email, password)
check_password(password)
email
id
password_hash
set_password(password)
username
app.classes.load_user(id)
app.routes.about()
app.routes.allowed_file(filename)
app.routes.contact()
app.routes.home()
app.routes.index()
app.routes.login()
app.routes.logout()
app.routes.pricing()
app.routes.re_route(e)
app.routes.register()
app.routes.welcome()
tests.conftest.init_database()
tests.conftest.new_user()
tests.conftest.test_client()
tests.test_image2latex.test_img2latex_check_invalid()

Checks output for image with an invalid equation

tests.test_image2latex.test_img2latex_check_size()

Checks output for image with size > 4 MB

tests.test_image2latex.test_img2latex_check_valid()

Checks output for image with a valid equation

tests.test_latex2numy.test_SSE()

Checks variable handling functionality

tests.test_latex2numy.test_absolute()

Checks absolute value handling functionality

tests.test_latex2numy.test_add_multiplier()

Checks multiplier functionality

tests.test_latex2numy.test_clip_start()

Checks clipping functionality for equality sign

tests.test_latex2numy.test_dot()

Checks dot product functionality

tests.test_latex2numy.test_expand_matrix()

Checks matrix handling functionality

tests.test_latex2numy.test_fix_caps()

Checks variable handling functionality

tests.test_latex2numy.test_frac()

Checks functionality for fractions

tests.test_latex2numy.test_log()

Checks function for logarithmic transformation

tests.test_latex2numy.test_operator_name()

Checks operator handling functionality

tests.test_latex2numy.test_split_operator()

Checks splitting functionality on pre-defined operators

tests.test_latex2numy.test_sqrt()

Checks square root functionality

tests.test_latex2numy.test_sum_prod_loop()

Checks the summation and product wrapper functions

tests.test_latex2numy.test_turn_into_var()

Checks variable conversion functionality

This file (test_routes.py) contains the functional tests for our application.

These tests use GETs and POSTs to different URLs to check for the proper behavior of users on our app.

Insipred from the folllowing tutorial: https://www.patricksoftwareblog.com/testing-a-flask-application-using-pytest/

tests.functional.test_routes.test_home_page(test_client)

GIVEN a Flask application WHEN the ‘/’ page is requested (GET) THEN check the response is valid

tests.functional.test_routes.test_invalid_login(test_client, init_database)

GIVEN a Flask application WHEN the ‘/login’ page is posted to with invalid credentials (POST) THEN check if user goes back to login page

tests.functional.test_routes.test_invalid_registration(test_client, init_database)

GIVEN a Flask application WHEN the ‘/register’ page is posted to with invalid credentials (POST) THEN check an error message is returned to the user

tests.functional.test_routes.test_login_page(test_client)

GIVEN a Flask application WHEN the ‘/login’ page is requested (GET) THEN check the response is valid

tests.functional.test_routes.test_register_page(test_client)

GIVEN a Flask application WHEN the ‘/register’ page is requested (GET) THEN check the response is valid

tests.functional.test_routes.test_valid_login_logout(test_client, init_database)

GIVEN a Flask application WHEN the ‘/login’ page is posted to (POST) THEN check the response is valid

tests.functional.test_routes.test_valid_registration(test_client, init_database)

GIVEN a Flask application WHEN the ‘/register’ page is posted to (POST) THEN check the response is valid and the user is redirected to login page

tests.functional.test_routes.test_welcome_page(test_client)

GIVEN a Flask application WHEN the ‘/welcome’ page is requested (GET) THEN check that the webpage is rendered correctly

This file (test_classes.py) contains the unit tests for the classes.py file. Inspired from this tutorial : https://www.patricksoftwareblog.com/testing-a-flask-application-using-pytest/

tests.unit.test_classes.test_new_user(new_user)

GIVEN a User model WHEN a new User is created THEN check the email and password_hash fields are defined correctly

tests.unit.test_classes.test_setting_password(new_user)

GIVEN an existing User WHEN the password for the user is set THEN check the password is stored correctly and not as plaintext

tests.unit.test_classes.test_user_id(new_user)

GIVEN an existing User WHEN the ID of the user is defined to a value THEN check the user ID returns a string (and not an integer) as needed by

Flask-WTF