-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlatac
executable file
·133 lines (123 loc) · 3.76 KB
/
latac
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/gawk -f
##################################################
# File:
# latac
#
# Maintainer:
# Sepp Tannhuber
#
# Version:
# 1
#
# Sections:
# -> Table font definitions
# -> Awk field seperators
# -> Basic table layout (begin)
# -> Line formatting
# -> Basic table layout (end)
##################################################
BEGIN{
##############################################
# => Table font definitions
##############################################
HEADERFONT="\\\\footnotesize\\\\sffamily\\\\bfseries "
FONT="\\small"
##############################################
# => Awk field seperators
##############################################
FS="&"
ORS=""
##############################################
# => Basic table layout (begin)
##############################################
print "\\begin{table}[]\n\t"
print "\\caption{}\n\t"
print "\\smallskipamount=1pt\n\t"
print "\\centering\n\t"
# Set table body font
print FONT"\n\t\t"
}
{
# Calculate number of columns and print rest of table header
if(NR==1) {
for(i=1; i<=NF; i++) {
if($i ~ /:[[:digit:]+]$/)
COLFORMAT[i]=gensub(/.*:([[:digit:]+])/, "*{\\1}l", "g", $i)
if($i ~ /:[[:digit:]+]\$/)
COLFORMAT[i]=gensub(/.*:([[:digit:]+])\$/, "*{\\1}{>$r<$}", "g", $i)
if($i ~ /:\$/)
COLFORMAT[i]=gensub(/.*/, ">$r<$", "g", $i)
if($i ~ /:[[:digit:]+][^$\s]/)
COLFORMAT[i]=gensub(/.*:([[:digit:]+])(.)/, "*{\\1}{\\2}", "g", $i)
if($i ~ /:[^[:digit:]$]+/)
COLFORMAT[i]=gensub(/.*:(.*)/, "\\1", "g", $i)
if(COLFORMAT[i]=="")
COLFORMAT[i]="l"
}
print "\\begin{tabular}{"
for(i in COLFORMAT) {
print COLFORMAT[i]
COLS=gensub(/.*\*\{([[:digit:]+])\}.*/, "\\1", "g", COLFORMAT[i])
if(COLS !~ /^[[:digit:]+]$/)
COLS=1
COLNUMS+=COLS
}
print "}\n\t\t"
print "\\toprule\n\t\t"
}
##############################################
# => Line formatting
##############################################
for(i=1; i<=NF; i++) {
if($i ~ /[[:digit:]*]-[[:digit:]*]/)
a=$i
else
a=gensub(/(.+)/, HEADERFONT"\\1", "g", $i)
# Format the midrules, alignment depends on position
firstcol=gensub(/([[:digit:]+])-[[:digit:]+]/, "\\1", "g", a)
lastcol=gensub(/[[:digit:]+]-([[:digit:]+])/, "\\1", "g", a)
if(firstcol==1)
f=""
else
f="l"
if(lastcol==COLNUMS)
l=""
else
l="r"
b=gensub(/([[:digit:]+]-[[:digit:]+])/, "\\\\cmidrule("f l"){\\1}", "g", a)
# Format multicolumns, always left aligned
c=gensub(/(.+):([[:digit:]+]).*/, "\\\\multicolumn{\\2}{l}{\\1}", "g", b)
if(NR != 1 || $1 !~ /^:/)
print c
# Insert field separators and line breaks
if($i ~ /[[:digit:]*]-[[:digit:]*]/)
{
if(i==NF)
{
print "\n\t\t"
HEADERFONT=""
}
}
else {
if(i<NF) {
if(HEADERFONT != "")
separator="&\n\t\t"
else
separator="& "
}
else
separator="\\\\\n\t\t"
if(NR != 1 || $1 !~ /^:/)
print separator
}
}
}
##############################################
# => Basic table layout (end)
##############################################
END{
print "\\bottomrule\n\t"
print "\\end{tabular}"
print "\\label{tbl:}\n"
print "\\end{table}"
}