-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_markdown.py
46 lines (36 loc) · 1.07 KB
/
write_markdown.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import source_text
text_source = source_text.ArxivSource()
def make_md_table(rows):
"""
rows is a matrix containing the character counts for each cell in the table
"""
st = text_source.get_words(1)
st += "\n\n"
for index, cols in enumerate(rows):
for i in cols:
st+=" | "
st+= text_source.get_words(i)
st+=" | "
st+="\n"
if index == 0:
for i in cols:
st+=" | "
st+= "-"
st+=" | "
st+="\n"
return st
def make_latex_table(rows, col_widths, total_width):
"""
rows is a matrix containing the character counts for each cell in the table
"""
widths = [el/sum(col_widths)*total_width for el in col_widths]
st = text_source.get_words(1)
st += "\n\n"
st += r"\begin{tabular}"
st+='\n'
st += "{"+"|".join([f"p{{{w:.2f}\linewidth}}" for w in widths])+"}"
for cols in rows:
st+= " & ".join([text_source.get_words(i) for i in cols])
st+=r" \\"+"\n"
st+=r"\end{tabular}"
return st