forked from caenrigen/LatexKit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
set for print.js
72 lines (60 loc) · 2.2 KB
/
set for print.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
71
72
// This function takes the matrix of values and properties and creates a new property
// named pvalue (printing value) which has the \multirow and \multicolumn settings and $\pm$ for uncertainties
// Example of actuation on a cell obj
// Cell obj: { value : 7.5 ,
// rowSpan : 2 ,
// colSpan : 3 ,
// errValue : 0.4 }
//
// The above cell obj is transformed into:
// Cell obj: { value : 7.5 ,
// rowSpan : 2 ,
// colSpan : 3 ,
// errValue : 0.4 ,
// pvalue : \multicolumn{3}{c}{\multirow{2}{*}{7.5 $\pm$ 0.4}} }
function set_forPrint(spec , err_printer ) {
// Get the arguments from object spec
var matrix = spec.matrix;
var colFeats = spec.colFeats;
//
var i,j;
for(i=0;i<matrix.length;i++)
for(j=0;j<matrix[i].length;j++)
{
// auxiliar reference to obj to ease the reading of the code
var aux=matrix[i][j];
// This block treats row and column spans for elements which have uncertainties
if(aux.errValue)
{
if(aux.rowSpan>1)
{
aux.pvalue = '\\multirow{' + aux.rowSpan + '}{*}{ ' + err_printer(aux) + ' }';
if(aux.colSpan>1)
aux.pvalue = '\\multicolumn{' + aux.colSpan + '}{c}{' + aux.pvalue + '}';
}
else if(aux.colSpan>1)
aux.pvalue = '\\multicolumn{' + aux.colSpan + '}{c}{ ' + err_printer(aux) + ' }';
else
aux.pvalue = aux.dvalue + ' $\\pm$ ' + aux.errValue;
}
// This block treats row and column spans for elements which DO NOT have uncertainties
else
{
if(aux.rowSpan>1)
{
aux.pvalue = '\\multirow{' + aux.rowSpan + '}{*}{ ' + aux.dvalue + ' }';
if(aux.colSpan>1)
aux.pvalue = '\\multicolumn{' + aux.colSpan + '}{c}{ ' + aux.pvalue + ' }';
}
else if(aux.colSpan>1)
aux.pvalue = '\\multicolumn{' + aux.colSpan + '}{c}{ ' + aux.dvalue + ' }';
else
aux.pvalue = aux.dvalue;
}
}
return 0;
}
// Default notation for uncertainties
function def_err_printer(aux){
return aux.dvalue + ' $\\pm$ ' + aux.errValue;
}