TeX tables.
This commit is contained in:
parent
5e475f6881
commit
1e2b306b15
2 changed files with 22 additions and 4 deletions
7
test.md
7
test.md
|
@ -142,11 +142,11 @@ To Do:
|
||||||
i. bro
|
i. bro
|
||||||
ii. wym bro
|
ii. wym bro
|
||||||
|
|
||||||
<!--
|
|
||||||
+---------------------+-----------------------+
|
+---------------------+-----------------------+
|
||||||
| Location | Temperature 1961-1990 |
|
| Location | Temperature 1961-1990 |
|
||||||
| | in degree Celsius |
|
| | in degree Celsius |
|
||||||
| +-------+-------+-------+
|
+---------------------+-------+-------+-------+
|
||||||
| | min | mean | max |
|
| | min | mean | max |
|
||||||
+=====================+=======+=======+======:+
|
+=====================+=======+=======+======:+
|
||||||
| Antarctica | -89.2 | N/A | 19.8 |
|
| Antarctica | -89.2 | N/A | 19.8 |
|
||||||
|
@ -154,10 +154,9 @@ ii. wym bro
|
||||||
| Earth | -89.2 | 14 | 56.7 |
|
| Earth | -89.2 | 14 | 56.7 |
|
||||||
+---------------------+-------+-------+-------+
|
+---------------------+-------+-------+-------+
|
||||||
|
|
||||||
|
|
||||||
------- ------ ---------- -------
|
------- ------ ---------- -------
|
||||||
12 12 12 12
|
12 12 12 12
|
||||||
123 123 123 123
|
123 123 123 123
|
||||||
1 1 1 1
|
1 1 1 1
|
||||||
------- ------ ---------- -------
|
------- ------ ---------- -------
|
||||||
-->
|
|
||||||
|
|
19
tex.py
19
tex.py
|
@ -136,6 +136,25 @@ def tex(e, indent_level: int=0, indent_str: str="\t") -> str:
|
||||||
if inlinify(e) is not None:
|
if inlinify(e) is not None:
|
||||||
return f'\\fn{{{tex(inlinify(e), 0, "")}}}'
|
return f'\\fn{{{tex(inlinify(e), 0, "")}}}'
|
||||||
|
|
||||||
|
if isinstance(e, Table):
|
||||||
|
aligns = {
|
||||||
|
"AlignLeft": "\\quad#\\quad\\hfil",
|
||||||
|
"AlignRight": "\\quad\\hfil#\\quad",
|
||||||
|
"AlignCenter": "\\quad\\hfil#\\hfil\\quad",
|
||||||
|
"AlignDefault": "\\quad#\\quad\\hfil"
|
||||||
|
}
|
||||||
|
text = "\strut"+"&".join([aligns[col[0]] for col in e.colspec])+"\cr\n"
|
||||||
|
text += tex(e.head.content, 0, "")
|
||||||
|
text += "\\noalign{\\hrule}\n"
|
||||||
|
text += tex(e.content[0].content, 0, "")
|
||||||
|
text += "\\noalign{\\hrule}\n"
|
||||||
|
text += tex(e.foot.content, 0, "")
|
||||||
|
return "\\vskip1em\n\\halign{"+text+"}\n\\vskip1em\n"
|
||||||
|
# FIXME: Implement rowspan
|
||||||
|
|
||||||
|
if isinstance(e, TableRow):
|
||||||
|
return "&".join([("\\multispan"+str(cell.colspan)+" " if cell.colspan > 1 else "")+tex(cell.content, 0, "") for cell in e.content])+"\cr\n"
|
||||||
|
|
||||||
if isinstance(e, RawInline):
|
if isinstance(e, RawInline):
|
||||||
if e.format == "tex":
|
if e.format == "tex":
|
||||||
return e.text
|
return e.text
|
||||||
|
|
Loading…
Reference in a new issue