Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemath
GitHub Repository: sagemath/sagelib
Path: blob/master/sage/combinat/output.py
4057 views
1
"""
2
Output functions
3
"""
4
5
def tex_from_array(a):
6
r"""
7
EXAMPLES::
8
9
sage: from sage.combinat.output import tex_from_array
10
sage: print tex_from_array([[1,2,3],[4,5]])
11
{\def\lr#1{\multicolumn{1}{|@{\hspace{.6ex}}c@{\hspace{.6ex}}|}{\raisebox{-.3ex}{$#1$}}}
12
\raisebox{-.6ex}{$\begin{array}[b]{ccc}
13
\cline{1-1}\cline{2-2}\cline{3-3}
14
\lr{1}&\lr{2}&\lr{3}\\
15
\cline{1-1}\cline{2-2}\cline{3-3}
16
\lr{4}&\lr{5}\\
17
\cline{1-1}\cline{2-2}
18
\end{array}$}
19
}
20
"""
21
rows = len(a)
22
cols = len(a[0])
23
s = ""
24
s += "{\\def\\lr#1{\\multicolumn{1}{|@{\\hspace{.6ex}}c@{\\hspace{.6ex}}|}{\\raisebox{-.3ex}{$#1$}}}\n"
25
s += "\\raisebox{-.6ex}{$"
26
s += "\\begin{array}[b]{"+"c"*cols+"}\n"
27
for j in range(cols):
28
if a[0][j] is not None:
29
s += "\\cline{" + str(j+1) + "-" + str(j+1) + "}"
30
s += "\n"
31
for i in range(rows):
32
cols = len(a[i])
33
if len(a[i])>0 and a[i][0] is not None:
34
for j in range(cols):
35
if a[i][j] is not None:
36
s += "\\lr{" + str(a[i][j]) + "}"
37
if j < cols-1:
38
s += "&"
39
s += "\\\\\n"
40
for j in range(cols):
41
if a[i][j] is not None:
42
s += "\\cline{" + str(j+1) + "-" + str(j+1) + "}"
43
s += "\n"
44
s += "\\end{array}$}\n}"
45
return s
46
47
48
49