2023-05-03 14:59:06 +02:00
|
|
|
"""
|
|
|
|
|
Program for converting Latex files into html files
|
|
|
|
|
"""
|
|
|
|
|
|
2023-05-03 20:29:08 +02:00
|
|
|
from code.latex_classes.latex_classes import return_latex_classes
|
|
|
|
|
from code.error_messages.error_arrays import return_error_arrays
|
|
|
|
|
|
2023-05-03 20:55:46 +02:00
|
|
|
def generic_checks(latex_string):
|
|
|
|
|
error_arrays = return_error_arrays()
|
|
|
|
|
if latex_string == "":
|
|
|
|
|
print(latex_string + error_arrays[0])
|
|
|
|
|
return "Error!"
|
|
|
|
|
if "}" not in latex_string:
|
|
|
|
|
print(latex_string + error_arrays[1])
|
|
|
|
|
return "Error!"
|
|
|
|
|
if latex_string[0] != "\\":
|
|
|
|
|
print(latex_string + error_arrays[6])
|
|
|
|
|
return "Error!"
|
|
|
|
|
|
2023-05-03 14:59:06 +02:00
|
|
|
|
|
|
|
|
def document_class(latex_string):
|
2023-05-03 20:29:08 +02:00
|
|
|
r"""
|
2023-05-03 14:59:06 +02:00
|
|
|
Converts LaTeX documentclass method to html
|
2023-05-03 20:29:08 +02:00
|
|
|
\documentclass{article}
|
2023-05-03 14:59:06 +02:00
|
|
|
"""
|
2023-05-03 20:29:08 +02:00
|
|
|
error_arrays = return_error_arrays()
|
2023-05-03 20:55:46 +02:00
|
|
|
if generic_checks(latex_string) == "Error!":
|
2023-05-03 20:29:08 +02:00
|
|
|
return "Error!"
|
|
|
|
|
if latex_string[len("\\documentclass{") - 1] != "{":
|
2023-05-03 20:55:46 +02:00
|
|
|
print(latex_string + error_arrays[3])
|
2023-05-03 20:29:08 +02:00
|
|
|
return "Error!"
|
2023-05-03 20:55:46 +02:00
|
|
|
if latex_string[1 : (len("documentclass") + 1)] != "documentclass":
|
|
|
|
|
print(latex_string + error_arrays[4])
|
2023-05-03 20:29:08 +02:00
|
|
|
return "Error!"
|
2023-05-03 20:55:46 +02:00
|
|
|
document_type = latex_string[len("\\documentclass{") : (len(latex_string) - 1)]
|
|
|
|
|
latex_classes = return_latex_classes()
|
2023-05-03 20:29:08 +02:00
|
|
|
if document_type not in latex_classes:
|
|
|
|
|
return f"Error! class {document_type} is not known!"
|
2023-05-03 20:55:46 +02:00
|
|
|
return "<!DOCTYPE html>"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def begin_document(latex_string):
|
|
|
|
|
r"""
|
|
|
|
|
Converts LaTeX begin document method to html
|
|
|
|
|
\begin{document}
|
|
|
|
|
"""
|
|
|
|
|
if generic_checks(latex_string) == "Error!":
|
|
|
|
|
return "Error!"
|
|
|
|
|
error_arrays = return_error_arrays()
|
|
|
|
|
if latex_string[1 : (len("begin") + 1)] != "begin":
|
|
|
|
|
print(latex_string + error_arrays[4])
|
|
|
|
|
return "Error!"
|
|
|
|
|
return "<html>"
|
|
|
|
|
|
2023-05-03 20:29:08 +02:00
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
document_class("")
|