feat: tabular parameters

This commit is contained in:
Krzysztof Rudnicki 2023-05-03 21:41:49 +02:00
parent 7562f3e06c
commit 0e1ed2b2b8
10 changed files with 138 additions and 149 deletions

View File

@ -1,99 +0,0 @@
/* start css.sty */
.cmtt-10{font-family: monospace,monospace;}
p{margin-top:0;margin-bottom:0}
p.indent{text-indent:0;}
p + p{margin-top:1em;}
p + div, p + pre {margin-top:1em;}
div + p, pre + p {margin-top:1em;}
a { overflow-wrap: break-word; word-wrap: break-word; word-break: break-word; hyphens: auto; }
@media print {div.crosslinks {visibility:hidden;}}
table.tabular{border-collapse: collapse; border-spacing: 0;}
a img { border-top: 0; border-left: 0; border-right: 0; }
center { margin-top:1em; margin-bottom:1em; }
td center { margin-top:0em; margin-bottom:0em; }
.Canvas { position:relative; }
img.math{vertical-align:middle;}
div.par-math-display, div.math-display{text-align:center;}
li p.indent { text-indent: 0em }
li p:first-child{ margin-top:0em; }
li p:last-child, li div:last-child { margin-bottom:0.5em; }
li p:first-child{ margin-bottom:0; }
li p~ul:last-child, li p~ol:last-child{ margin-bottom:0.5em; }
.enumerate1 {list-style-type:decimal;}
.enumerate2 {list-style-type:lower-alpha;}
.enumerate3 {list-style-type:lower-roman;}
.enumerate4 {list-style-type:upper-alpha;}
div.newtheorem { margin-bottom: 2em; margin-top: 2em;}
div.newtheorem .head{font-weight: bold;}
.obeylines-h,.obeylines-v {white-space: nowrap; }
div.obeylines-v p { margin-top:0; margin-bottom:0; }
.overline{ text-decoration:overline; }
.overline img{ border-top: 1px solid black; }
td.displaylines {text-align:center; white-space:nowrap;}
.centerline {text-align:center;}
.rightline {text-align:right;}
pre.verbatim {font-family: monospace,monospace; text-align:left; clear:both; }
.fbox {padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; }
div.fbox {display:table}
div.center div.fbox {text-align:center; clear:both; padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; }
div.minipage{width:100%;}
div.center, div.center div.center {text-align: center; margin-left:1em; margin-right:1em;}
div.center div {text-align: left;}
div.flushright, div.flushright div.flushright {text-align: right;}
div.flushright div {text-align: left;}
div.flushleft {text-align: left;}
.underline{ text-decoration:underline; }
.underline img{ border-bottom: 1px solid black; margin-bottom:1pt; }
.framebox-c, .framebox-l, .framebox-r { padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; }
.framebox-c {text-align:center;}
.framebox-l {text-align:left;}
.framebox-r {text-align:right;}
span.thank-mark{ vertical-align: super }
span.footnote-mark sup.textsuperscript, span.footnote-mark a sup.textsuperscript{ font-size:80%; }
div.tabular, div.center div.tabular {text-align: center; margin-top:0.5em; margin-bottom:0.5em; }
table.tabular td p{margin-top:0em;}
table.tabular {margin-left: auto; margin-right: auto;}
td p:first-child{ margin-top:0em; }
td p:last-child{ margin-bottom:0em; }
div.td00{ margin-left:0pt; margin-right:0pt; }
div.td01{ margin-left:0pt; margin-right:5pt; }
div.td10{ margin-left:5pt; margin-right:0pt; }
div.td11{ margin-left:5pt; margin-right:5pt; }
table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; }
td.td00{ padding-left:0pt; padding-right:0pt; }
td.td01{ padding-left:0pt; padding-right:5pt; }
td.td10{ padding-left:5pt; padding-right:0pt; }
td.td11{ padding-left:5pt; padding-right:5pt; }
table[rules] {border-left:solid black 0.4pt; border-right:solid black 0.4pt; }
.hline hr, .cline hr{ height : 0px; margin:0px; }
.hline td, .cline td{ padding: 0; }
.hline hr, .cline hr{border:none;border-top:1px solid black;}
.hline {border-top: 1px solid black;}
.hline + .vspace:last-child{display:none;}
.hline:first-child{border-bottom:1px solid black;border-top:none;}
.tabbing-right {text-align:right;}
div.float, div.figure {margin-left: auto; margin-right: auto;}
div.float img {text-align:center;}
div.figure img {text-align:center;}
.marginpar,.reversemarginpar {width:20%; float:right; text-align:left; margin-left:auto; margin-top:0.5em; font-size:85%; text-decoration:underline;}
.marginpar p,.reversemarginpar p{margin-top:0.4em; margin-bottom:0.4em;}
.reversemarginpar{float:left;}
table.equation {width:100%;}
.equation td{text-align:center; }
td.equation { margin-top:1em; margin-bottom:1em; }
td.equation-label { width:5%; text-align:center; }
td.eqnarray4 { width:5%; white-space: normal; }
td.eqnarray2 { width:5%; }
table.eqnarray-star, table.eqnarray {width:100%;}
div.eqnarray{text-align:center;}
div.array {text-align:center;}
div.pmatrix {text-align:center;}
table.pmatrix {width:100%;}
span.pmatrix img{vertical-align:middle;}
div.pmatrix {text-align:center;}
table.pmatrix {width:100%;}
span.bar-css {text-decoration:overline;}
img.cdots{vertical-align:middle;}
/* end css.sty */

View File

@ -1,38 +0,0 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html >
<head><title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="generator" content="TeX4ht (https://tug.org/tex4ht/)">
<meta name="originator" content="TeX4ht (https://tug.org/tex4ht/)">
<!-- html -->
<meta name="src" content="simpletable.tex">
<link rel="stylesheet" type="text/css" href="simpletable.css">
</head><body
>
<div class="tabular"> <table id="TBL-1" class="tabular"
><colgroup id="TBL-1-1g"><col
id="TBL-1-1"><col
id="TBL-1-2"><col
id="TBL-1-3"></colgroup><tr
style="vertical-align:baseline;" id="TBL-1-1-"><td style="white-space:nowrap; text-align:left;" id="TBL-1-1-1"
class="td11">1</td><td style="white-space:nowrap; text-align:center;" id="TBL-1-1-2"
class="td11">2</td><td style="white-space:nowrap; text-align:right;" id="TBL-1-1-3"
class="td11">3</td></tr><tr
style="vertical-align:baseline;" id="TBL-1-2-"><td style="white-space:nowrap; text-align:left;" id="TBL-1-2-1"
class="td11">4 </td> <td style="white-space:nowrap; text-align:center;" id="TBL-1-2-2"
class="td11">5</td> <td style="white-space:nowrap; text-align:right;" id="TBL-1-2-3"
class="td11">6</td>
</tr><tr
style="vertical-align:baseline;" id="TBL-1-3-"><td style="white-space:nowrap; text-align:left;" id="TBL-1-3-1"
class="td11">7 </td><td style="white-space:nowrap; text-align:center;" id="TBL-1-3-2"
class="td11">8</td><td style="white-space:nowrap; text-align:right;" id="TBL-1-3-3"
class="td11">9</td></tr><tr
style="vertical-align:baseline;" id="TBL-1-4-"><td style="white-space:nowrap; text-align:left;" id="TBL-1-4-1"
class="td11"> </td> </tr></table> </div>
</body></html>

View File

@ -1,8 +1,7 @@
\documentclass{article}
\begin{document}
\begin{tabular}{ l | c | r }
test & 2 & test \\
4 & 5 & 6 \\
7 & 8 & 9 \\
\begin{tabular}{c}
\end{tabular}
\end{document}

View File

@ -1,2 +0,0 @@
/* css.sty */

View File

@ -5,6 +5,13 @@
from code.latex_classes.latex_classes import return_latex_classes
from code.error_messages.error_arrays import return_error_arrays
def command_name_check(latex_string, command_name):
error_arrays = return_error_arrays()
if latex_string[1 : (len(command_name) + 1)] != command_name:
print(latex_string + error_arrays[4])
return "Error!"
return
def generic_checks(latex_string):
error_arrays = return_error_arrays()
if latex_string == "":
@ -16,6 +23,8 @@ def generic_checks(latex_string):
if latex_string[0] != "\\":
print(latex_string + error_arrays[6])
return "Error!"
return
def document_class(latex_string):
@ -29,8 +38,7 @@ def document_class(latex_string):
if latex_string[len("\\documentclass{") - 1] != "{":
print(latex_string + error_arrays[3])
return "Error!"
if latex_string[1 : (len("documentclass") + 1)] != "documentclass":
print(latex_string + error_arrays[4])
if command_name_check(latex_string, "documentclass") == "Error!":
return "Error!"
document_type = latex_string[len("\\documentclass{") : (len(latex_string) - 1)]
latex_classes = return_latex_classes()
@ -46,12 +54,30 @@ def begin_document(latex_string):
"""
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])
if command_name_check(latex_string, "begin") == "Error!":
return "Error!"
return "<html>"
def begin_tabular(latex_string):
r"""
Checks if LaTeX begin tabular method is correct
"""
if generic_checks(latex_string) == "Error!":
return "Error!"
if command_name_check(latex_string, "begin") == "Error!":
return "Error!"
return "<table>"
def tabular_parameters(latex_string):
r"""
Checks if LaTeX tabular environment has any parameters
"""
if latex_string == "":
return ""
if latex_string == "[]":
return ""
return "Error!"
if __name__ == "__main__":
document_class("")

View File

@ -19,7 +19,7 @@ def given_not_closed_then_error():
When: N/A
Then: Error message
"""
assert begin_document(r"\begin{document") == "Error!"
assert begin_document(r"\\begin{document") == "Error!"
def given_no_opening_then_error():

View File

@ -0,0 +1,67 @@
"""
Tests begin document function
"""
from code.main import begin_tabular
# Write python tests for a function translating LaTeX documentclass to html
def given_empty_then_error():
"""
Given: ""
When: N/A
Then: Error message
"""
assert begin_tabular("") == "Error!"
def given_not_closed_then_error():
r"""
Given: command not closed
When: N/A
Then: Error message
"""
assert begin_tabular(r"\\begin{tabular") == "Error!"
def given_no_opening_then_error():
"""
Given: No opening curly bracket
When: N/A
Then: Error message
"""
assert begin_tabular(r"\\begintabular}") == "Error!"
def given_misspeled_then_error():
"""
Given: misspelled begin tabular
When: N/A
Then: Error message
"""
assert begin_tabular(r"\\begim{tabular}") == "Error!"
def given_no_slash_then_error():
"""
Given: no backslash at start
When: N/A
Then: Error message
"""
assert begin_tabular(r"begin{tabular}") == "Error!"
def given_correct_then_html():
"""
Given: \begin{tabular}
When: N/A
Then: <!DOCTYPE html><html>
"""
assert begin_tabular(r"\begin{tabular}") == "<table>"
def test_begin_tabular():
given_correct_then_html()
given_empty_then_error()
given_misspeled_then_error()
given_no_opening_then_error()
given_not_closed_then_error()
given_no_slash_then_error()

View File

@ -0,0 +1,36 @@
"""
Tests tabular_parameters function
"""
from code.main import tabular_parameters
def given_empty_then_empty():
"""
Given:
When: N/A
Then: <!DOCTYPE html><html>
"""
assert tabular_parameters("") == ""
def given_empty_brackets_then_empty():
"""
Given: []
When: N/A
Then: <!DOCTYPE html><html>
"""
assert tabular_parameters("[]") == ""
def given_non_empty_then_error():
"""
Given: [c]
When: N/A
Then: <!DOCTYPE html><html>
"""
assert tabular_parameters("[c]") == "Error!"
def test_tabular_parameters():
given_empty_then_empty()
given_empty_brackets_then_empty()
given_non_empty_then_error()