-
Notifications
You must be signed in to change notification settings - Fork 0
/
arr2tex.jl
70 lines (57 loc) · 1.97 KB
/
arr2tex.jl
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
module arr2tex
export array2latex
ident=" "; #identation is two spaces
T1 = Array{<:Union{Missing,Real},2};
T2 = Array{<:Union{Missing,String},2}; #the type used in the following function
function array2latex(A :: T1, topRow::Union{T2,Missing}=missing , leftCol::Union{T2,Missing}=missing)
nRows,nCols = size(A);
#decleration of the table
println(raw"\begin{table}")
println(ident,raw"\begin{center}")
#caption and label - you should change that
println(ident,ident,raw"\caption{Your caption here.}")
println(ident,ident,raw"\label{tab:table1}")
#table columns definition (everything centered)
colsString="{"
for i=1:nCols
colsString = colsString * "c|"
end
colsString =colsString * "c}"
println(ident,ident,raw"\begin{tabular}",colsString)
#table first row with the names of the columns
if ~ismissing(topRow)
headerString = "";
for i=1:nCols
headerString *= (dwm(topRow[i]) * raw" & ")
end
headerString *= (dwm(topRow[nCols+1]) * raw" \\ ")
println(ident,ident,headerString)
end
println(ident,ident,raw" \hline") #adding a line below the first row
# the content of the table. Each line start with the row name
for j=1:nRows
if ~ismissing(leftCol)
print(ident,ident,dwm(leftCol[j])," & ")
end
for i=1:nCols-1
print(dwm(A[j,i]))
print(raw" & ")
end
print(dwm(A[j,nCols]))
println(raw" \\ ")
end
println(ident,ident,raw" \hline") #adding a line at the bottom
#closing the table tags
println(ident,ident,raw"\end{tabular}")
println(ident,raw"\end{center}")
println(raw"\end{table}")
end #of function array2latex
function dwm(x :: Union{Missing,Real,String})
# dwm stands for Deal with Missing
if ismissing(x)
return ident
else
return x
end
end #of function dwm
end #of module