Browse Source

TeX tables.

pull/28/head
Jan Černohorský 2 years ago
parent
commit
1e2b306b15
  1. 7
      test.md
  2. 19
      tex.py

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

@ -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…
Cancel
Save