-
Notifications
You must be signed in to change notification settings - Fork 7
/
app-isaquick-table-macros.tex
85 lines (84 loc) · 2.82 KB
/
app-isaquick-table-macros.tex
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
\ifcsname @app@isaquick@table@macros@tex\endcsname
\ea\endinput
\fi
\ea\gdef\csname @app@isaquick@table@macros@tex\endcsname{1}
\makeatletter
\newcount\@cherienctable@col
\newcount\@cherienctable@cols
\newcount\@cherienctable@colbits
\newcount\@cherienctable@row
\newcount\@cherienctable@rows
\newcount\@cherienctable@rowbits
\newcount\@cherienctable@tmp
\def\@cherienctable@addtoformat#1{\ea\global\ea\def\ea\@cherienctable@format\ea{\@cherienctable@format #1}}
\def\@cherienctable@addtobody#1{\ea\global\ea\def\ea\@cherienctable@body\ea{\@cherienctable@body #1}}
% cols func2str count
\newcommand{\@cherienctable}[3]{%
\@cherienctable@cols=\numexpr(#1)\relax%
\@cherienctable@rows=\numexpr(#3+\@cherienctable@cols-1)\relax%
\divide\@cherienctable@rows\@cherienctable@cols%
%
\let\@cherienctable@format\@empty%
\let\@cherienctable@body\@empty%
\ifnum\@cherienctable@rows>1%
\@cherienctable@addtoformat{r|}%
\@cherienctable@addtobody{ & }%
\fi%
%
\@cherienctable@colbits=1%
\@cherienctable@tmp=2%
\loop\ifnum\@cherienctable@tmp<\@cherienctable@cols%
\advance\@cherienctable@colbits 1%
\multiply\@cherienctable@tmp 2%
\repeat%
%
\@cherienctable@rowbits=1%
\@cherienctable@tmp=2%
\loop\ifnum\@cherienctable@tmp<\@cherienctable@rows%
\advance\@cherienctable@rowbits 1%
\multiply\@cherienctable@tmp 2%
\repeat%
%
\@cherienctable@col=0%
\loop\ifnum\@cherienctable@col<\@cherienctable@cols%
\@cherienctable@addtoformat{c}%
\ifnum\@cherienctable@col>0%
\@cherienctable@addtobody{ & }%
\fi%
\edef\@cherienctable@cell{\nbinary{\@cherienctable@colbits}{\the\@cherienctable@col}}%
\ea\@cherienctable@addtobody\ea{\@cherienctable@cell}%
\advance\@cherienctable@col 1%
\repeat%
\@cherienctable@addtobody{ \\ \hline}%
%
\@cherienctable@row=0%
\loop\ifnum\@cherienctable@row<\@cherienctable@rows%
\ifnum\@cherienctable@rows>1%
\edef\@cherienctable@cell{\nbinary{\@cherienctable@rowbits}{\the\@cherienctable@row}}%
\ea\@cherienctable@addtobody\ea{\@cherienctable@cell & }%
\fi%
\@cherienctable@col=0%
{%
\loop\ifnum\@cherienctable@col<\@cherienctable@cols%
\ifnum\@cherienctable@col>0%
\@cherienctable@addtobody{ & }%
\fi%
\edef\@cherienctable@cell{\csname #2\endcsname{\@cherienctable@row*\@cherienctable@cols + \@cherienctable@col}}%
\ifx\@cherienctable@cell\@empty%
\@cherienctable@addtobody{-}%
\else%
\ea\@cherienctable@addtobody\ea{\@cherienctable@cell}%
\fi%
\advance\@cherienctable@col 1%
\repeat%
}%
\@cherienctable@addtobody{ \\}%
\advance\@cherienctable@row 1%
\repeat%
%
\def\@cherienctable@begintabular{\begin{tabular}}%
\ea\@cherienctable@begintabular\ea{\@cherienctable@format}%
\@cherienctable@body%
\end{tabular}%
}
\makeatother