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
|
% luamodulartables
% version 1.0
% Authors: Chetan Shirore and Ajit Kumar
% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
\ProvidesPackage{luamodulartables}[1.0]
\RequirePackage{xkeyval}
\RequirePackage{luacode}
\begin{luacode*}
function modulomult(n,label, headline, midline)
label = label or '$\\times$'
headline = headline or ''
midline = midline or ''
local str2 = label
for i = 0, n - 1 do
str2 = str2 .. " & " .. "$" .. tostring(i) .."$"
end
str2 = str2 .. "\\\\ " .. headline
local tbl = {}
for i = 0, n - 1 do
k = 1
tbl[k] = "$" .. tostring(i) .."$"
k = k + 1
for j = 0, n - 1 do
tbl[k] = "$" .. tostring((i * j) % n) .."$"
k = k + 1
end
if i ~= n - 1 then
str2 = str2 .. table.concat(tbl, " & ") .. "\\\\ " .. midline
else
str2 = str2 .. table.concat(tbl, " & ")
end
end
return (str2)
end
function moduloadd(n,label, headline, midline)
label = label or '$+$'
headline = headline or ''
midline = midline or ''
local str3 =label
for i = 0, n - 1 do
str3 = str3 .. " & " .. "$" .. tostring(i) .."$"
end
str3 = str3 .. "\\\\ " .. headline
local tbl = {}
for i = 0, n - 1 do
k = 1
tbl[k] = "$" .. tostring(i) .."$"
k = k + 1
for j = 0, n - 1 do
tbl[k] = "$" .. tostring((i + j) % n) .."$"
k = k + 1
end
if i ~= n - 1 then
str3 = str3 .. table.concat(tbl, " & ") .. "\\\\ " .. midline
else
str3 = str3 .. table.concat(tbl, " & ")
end
end
return (str3)
end
\end{luacode*}
% ========= KEY DEFINITIONS =========
\define@key{luamodular}{multlabel}
{\edef\luamod@multlabel{\luastringN{#1}}}
\define@key{luamodular}{addlabel}
{\edef\luamod@addlabel{\luastringN{#1}}}
\define@key{luamodular}{headline}
{\edef\luamod@headline{\luastringN{#1}}}
\define@key{luamodular}{midline}
{\edef\luamod@midline{\luastringN{#1}}}
% ========= KEY DEFAULTS =========
\setkeys{luamodular}{multlabel=$\times$}%
\setkeys{luamodular}{addlabel=$+$}%
\setkeys{luamodular}{headline = }%
\setkeys{luamodular}{midline = }%
% ========= Defining Command =========
\newcommand{\luaModularMult}[2][]{%
\setkeys{luamodular}{#1}
\directlua{tex.sprint(modulomult(#2,\luamod@multlabel,
\luamod@headline,\luamod@midline))}}%
\newcommand{\luaModularAdd}[2][]{%
\setkeys{luamodular}{#1}
\directlua{tex.sprint(moduloadd(#2,\luamod@addlabel,
\luamod@headline,\luamod@midline))}}%
%
\endinput
|