forked from caenrigen/LatexKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
create string.js
70 lines (56 loc) · 1.3 KB
/
create string.js
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
function create_string(spec) {
// Get the arguments from object spec
var matrix = spec.matrix;
var colFeats = spec.colFeats;
var rowFeats = spec.rowFeats;
var output = '';
output += "\\begin{tabular}";
output += "{" + columns_align(colFeats) + "}\r\n";
if(rowFeats[0].get_hline())
output += ' \\hline\r\n';
var i,j;
for(i=0;i<matrix.length;i++)
{
for(j=0;j<matrix[i].length;j++)
{
output+=matrix[i][j].pvalue;
}
if(rowFeats[i+1].get_bigstrutTop()){
output+='\\bigstrut';
if(rowFeats[i+1].get_bigstrutBot()){}
else output+='[t]'
}
else if(rowFeats[i+1].get_bigstrutBot())
output+='\\bigstrut[b]';
output+='\\\\';
if(rowFeats[i+1].get_hline())
output+=' \\hline';
output+='\r\n';
}
output+= "\\end{tabular}\r\n";
return output;
}
function columns_align(colFeats){
var str='';
for(var i=0;i<colFeats.length;i++)
{
if(colFeats[i].get_lbar())
str+='|';
switch (colFeats[i].alignment) {
case 'left':
str+='l';
break;
case 'center':
str+='c';
break;
case 'right':
str+='r';
break;
default:
str+='c';
}
if(colFeats[i].get_rbar())
str+='|';
}
return str;
}