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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
|
\documentclass{article}
\renewcommand{\baselinestretch}{1.2}
\usepackage{float,listings,color,booktabs,longtable,array,hyperref,luamaths,amsmath,amssymb}
\usepackage[top=1in, bottom=1in, left=1.1in, right=1.1in]{geometry}
\hypersetup{colorlinks,urlcolor=blue}
\lstset{frame=none,
language=[LaTeX]{TeX},
aboveskip=3mm,
belowskip=2mm,
showstringspaces=false,
columns=flexible,
basicstyle={\ttfamily},
numbers=none,
numberstyle=\tiny\color{gray},
stringstyle=\color{mauve},
breaklines=true,
breakatwhitespace=true,
tabsize=1
}
\usepackage{microtype,graphicx,amsmath,amssymb,float}
\usepackage[backend=bibtex]{biblatex}
\addbibresource{luamaths}
\begin{document}
\title{The luamaths package in LaTeX}
\author{Chetan Shirore\thanks{Email id: mathsbeauty@gmail.com} \space and Ajit Kumar}
\maketitle
\section{Introduction}\label{section:introduction}
The \verb|luamaths| package is developed to perform standard mathematical operations inside LaTeX documents using Lua. It provides an easy way to perform standard mathematical operations. There is no particular environment in the package for performing mathematical operations. The package commands can be used in any environment (including the mathematics environment). It is written in Lua, and tex file is to be compiled with LuaLatex engine. The time required for operations is not an issue while compiling with LuaLaTeX. There is no need to install Lua on the users system as tex distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. It is useful to perform standard operations (addition, subtraction, multiplication, division, powers, roots etc.) in tex file itself. The package supports the nesting of commands for multiple operations. It can be modified or extended by writing custom Lua programs.
The Lua \cite{online.luaorg} programming language is a scripting language that can be embedded across platforms. With\verb|LuaTeX| \cite{online.luatex} and\verb|luacode| \cite{online.luacode} packages, it is possible to use Lua in LaTeX. The TeX \cite{online.tex} or LaTeX has scope for programming \cite{online.texscript}. However, with the weird internals of TeX, there are several limitations, especially for performing calculations on numbers in LaTeX documents. There are packages like \emph{pgf} \cite{online.pgf} and \emph{xparse} \cite{online.xparse} in LaTeX which provides some programming capabilities inside LaTeX documents. However, such packages do not provide the complete programming structure that Lua programming languages provide. The \verb|luacode| \cite{online.luacode} package is used in its development apart from the \verb|luacode| package. There is no need to install Lua on users system as TeX distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. The package can be modified or extended by writing custom Lua programs.
\section{Installation and License}
The installation of \verb|luamaths| package is similar to plain latex package, where the \texttt{.sty} file is in \LaTeX directory of texmf tree. The package can be included with \verb|\usepackage{luamaths}| command in the preamble of the LaTeX document. The TeX file is to be compiled using the LuaLaTeX engine.
The \verb|luamaths| package is released under the LaTeX Project Public License v1.3c or later. The complete license text is available at \url{http://www.latex-project.org/lppl.txt}. It is developed in Lua. Lua is available as a certified open-source software. Its license is simple and liberal, which is compatible with GPL.
\section{Commands in the luamaths package}
Table \ref{tbl:opluamaths} lists operations in the \verb|luamaths| package.
\begin{center}
\begin{longtable}{llm{6.5cm}}
\toprule
\multicolumn{1}{c}{\textcolor{blue}{Function}} & \multicolumn{1}{l}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\
\toprule
\begin{lstlisting}
\mathOp
\end{lstlisting} &
\begin{lstlisting}
\mathOp{expression}
\end{lstlisting} & Evaluates mathematical expression. For example, \lstinline|\mathop{2+3}| will evaluate to 5. It supports usual operations like\lstinline| -, *, \, ^ | etcetera, apart from the standard functions. \\
\midrule
\begin{lstlisting}
\mathAbs
\end{lstlisting} &
\begin{lstlisting}
\mathAbs{number}
\end{lstlisting} & Gives the absolute value of a real number.\\
\midrule
\begin{lstlisting}
\mathAcos
\end{lstlisting} &
\begin{lstlisting}
\mathAcos{number}
\end{lstlisting} & Gives the arc cosine of a real number in radians.\\
\midrule
\begin{lstlisting}
\mathAsin
\end{lstlisting} &
\begin{lstlisting}
\mathAsin{number}
\end{lstlisting} & Gives the arc sine of a real number in radians.\\
\midrule
\begin{lstlisting}
\mathAtan
\end{lstlisting} &
\begin{lstlisting}
\mathAtan{number}
\end{lstlisting} & Gives the arc tangent of a real number in radians.\\
\midrule
\begin{lstlisting}
\mathCeil
\end{lstlisting} &
\begin{lstlisting}
\mathCeil{number}
\end{lstlisting} & Gives the smallest integer greater than or equal to a real number.\\
\midrule
\begin{lstlisting}
\mathCos
\end{lstlisting} &
\begin{lstlisting}
\mathCos{number}
\end{lstlisting} & Gives the cosine of a real number.Here the number is in radians.\\
\midrule
\begin{lstlisting}
\mathExp
\end{lstlisting} &
\begin{lstlisting}
\mathExp{x}
\end{lstlisting} & Calculates \(\mathrm{e}^x \). Here \(\mathrm{e} \) is the Euler number.\\
\midrule
\begin{lstlisting}
\mathFloor
\end{lstlisting} &
\begin{lstlisting}
\mathFloor{number}
\end{lstlisting} & Gives the smallest integer less than or equal to a real number.\\
\midrule
\begin{lstlisting}
\mathInf
\end{lstlisting} & \begin{lstlisting}
\mathInf
\end{lstlisting} & The infinity.\\
\midrule
\begin{lstlisting}
\mathLog
\end{lstlisting} &
\begin{lstlisting}
\mathLog{x}
\end{lstlisting} & Calculates \(\log x \). Here the logarithm is to the natural base \(\mathrm{e} \).\\
\midrule
\begin{lstlisting}
\mathMax
\end{lstlisting} &
\begin{lstlisting}
\mathMax\end{lstlisting}\{\(x_1,x_2,\ldots,x_n\)\}
& Gives the maximum of numbers \(x_1,x_2,\ldots,x_n\).\\
\midrule
\begin{lstlisting}
\mathMin
\end{lstlisting} &
\begin{lstlisting}
\mathMin\end{lstlisting}\{\(x_1,x_2,\ldots,x_n\)\}
& Gives the minimum of numbers \(x_1,x_2,\ldots,x_n\).\\
\midrule
\begin{lstlisting}
\mathPi
\end{lstlisting} &
\begin{lstlisting}
\mathPi
\end{lstlisting} & Gives the numeric value of the constant \(\pi \). \\
\midrule
\begin{lstlisting}
\mathRad
\end{lstlisting} &
\begin{lstlisting}
\mathRad{degree}
\end{lstlisting} & Converts degrees into radians. \\
\midrule
\begin{lstlisting}
\mathRandom
\end{lstlisting} & \begin{lstlisting}
\mathRandom
\end{lstlisting} & Generates a random number between \(0 \) and \(1 \). \\
\midrule
\begin{lstlisting}
\mathRound
\end{lstlisting} &
\begin{lstlisting}
\mathRound{number}{digits}
\end{lstlisting} & It rounds off a real number to a specified number of decimal places. \\
\midrule
\begin{lstlisting}
\mathSin
\end{lstlisting} &
\begin{lstlisting}
\mathSin{number}
\end{lstlisting} & Gives the sine of a real number. Here the number is in radians.\\
\midrule
\begin{lstlisting}
\mathSqrt
\end{lstlisting} &
\begin{lstlisting}
\mathSqrt{number}
\end{lstlisting} & Gives the non-negative square root of a non-negative real number.\\
\midrule
\begin{lstlisting}
\mathTan
\end{lstlisting} &
\begin{lstlisting}
\mathTan{number}
\end{lstlisting} & Gives the tangent of a real number. Here the number is in radians.\\
\midrule
\begin{lstlisting}
\complexRound
\end{lstlisting} &
\begin{lstlisting}
\complexRound{cx_num}{digits}
\end{lstlisting} & It rounds off a complex number to a specified number of decimal places.\\
\midrule
\begin{lstlisting}
\luaChkeqnum
\end{lstlisting} &
\begin{lstlisting}
\luaChkeqnum{x}{y}
\end{lstlisting} & It returns true if x = y, otherwise returns false.\\
\bottomrule \\
\caption{Operations in the luamaths package}
\label{tbl:opluamaths}
\end{longtable}
\end{center}
Numbers can also be entered in scientific notation. For example, the number \(1860000\) can be entered as \(1.86e6\), and the number \(0.000186\) can be entered as \(1.86e-4\).
\subsection*{Illustrations of commands in the luamaths package}
Table \ref{tbl:illluamaths} illustrates operations in the \verb|luamaths| package with examples.
\begin{center}
\begin{longtable}{lc}
\toprule
\multicolumn{1}{c}{\textcolor{blue}{LaTeX input}} &\multicolumn{1}{c}{\textcolor{blue}{Output}} \\
\toprule
\begin{lstlisting}
\mathOp{(3+3)^4-4}
\end{lstlisting} & \(\mathOp{(3+3)^4-4}\)\\
\midrule
\begin{lstlisting}
\mathAbs{-6.96}
\end{lstlisting} & \(\mathAbs{-6.96}\)\\
\midrule
\begin{lstlisting}
\mathFloor{-6.9}
\end{lstlisting} & \(\mathFloor{-6.9}\) \\
\midrule
\begin{lstlisting}
\mathFloor{9.9}
\end{lstlisting} & \(\mathFloor{9.9}\)\\
\midrule
\begin{lstlisting}
\mathCeil{-9.9}
\end{lstlisting} & \(\mathCeil{-9.9}\) \\
\midrule
\begin{lstlisting}
\mathCeil{6.3}
\end{lstlisting} &\(\mathCeil{6.3}\)\\
\midrule
\begin{lstlisting}
\mathRound{9.678884}{3}
\end{lstlisting} & \(\mathRound{9.678884}{3}\)\\
\midrule
\begin{lstlisting}
\mathMax{20,30,100}
\end{lstlisting} &\(\mathMax{20,30,100}\) \\
\midrule
\begin{lstlisting}
\mathMin{20,30,100}
\end{lstlisting} &\(\mathMin{20,30,100}\)\\
\midrule
\begin{lstlisting}
\mathPi
\end{lstlisting} & \(\mathPi\)\\
\midrule
\begin{lstlisting}
\mathRound{\mathPi}{6}
\end{lstlisting} & \(\mathRound{\mathPi}{6}\)\\
\midrule
\begin{lstlisting}
\mathInf
\end{lstlisting} & \(\mathInf\)\\
\midrule
\begin{lstlisting}
\mathOp{\mathInf/2}
\end{lstlisting} &\(\mathOp{\mathInf/2}\) \\
\midrule
\begin{lstlisting}
\mathSqrt{9}
\end{lstlisting} & \(\mathSqrt{9}\)\\
\midrule
\begin{lstlisting}
\mathLog{2}
\end{lstlisting} & \(\mathLog{2}\)\\
\midrule
\begin{lstlisting}
\mathExp{3}
\end{lstlisting} & \(\mathExp{3}\) \\
\midrule
\begin{lstlisting}
\mathRad{1800}
\end{lstlisting} & \(\mathRad{1800}\)\\
\midrule
\begin{lstlisting}
\mathSin{0}
\end{lstlisting} &\(\mathSin{0}\)\\
\midrule
\begin{lstlisting}
\mathCos{0}
\end{lstlisting} & \(\mathCos{0}\)\\
\midrule
\begin{lstlisting}
\mathTan{0}
\end{lstlisting} & \(\mathTan{0}\)\\
\midrule
\begin{lstlisting}
\mathAsin{0}
\end{lstlisting} & \(\mathAsin{0}\)\\
\midrule
\begin{lstlisting}
\mathAcos{0}
\end{lstlisting} & \(\mathAcos{0}\)\\
\midrule
\begin{lstlisting}
\mathAtan{0}
\end{lstlisting} & \(\mathAtan{0}\)\\
\midrule
\begin{lstlisting}
\mathRound{\mathOp{9+\mathSin{4}}}{6}
\end{lstlisting} & \(\mathRound{\mathOp{9+\mathSin{4}}}{6}\)\\
\midrule
\begin{lstlisting}
\complexRound{lcomplex(\mathPi,6)}{4}
\end{lstlisting} & \(\complexRound{lcomplex(\mathPi,6)}{4}\)\\
\midrule
\begin{lstlisting}
\luaChkeqnum{\mathCos{0}}{1}
\end{lstlisting} & \luaChkeqnum{\mathCos{0}}{1}\\
\bottomrule \\
\caption{Illustrations of commands in the luamaths package}
\label{tbl:illluamaths}
\end{longtable}
\end{center}
The package supports fractions; numerators and denominators must be integers. A fraction can be specified with the Lua function: \verb|lfrac|. This function has the syntax \verb|lfrac(n,d,mode)|: \(n\) is an integer and \(d\) is a non-zero integer. The mode is optional. It can be \verb|fracs| or \verb|nofracs|. The default mode is \verb|fracs|. If fractions are input, the package will display vectors and matrices in fraction mode wherever possible. The package does not attempt to convert floats into fractions. If fractions are expected, then the input should contain fractions. If fractions are input and answers are expected in numbers, the mode can be specified as \verb|nofracs|.
The Lua function \verb|lcomplex| defines the complex numbers. It has the syntax \verb|lcomplex(x,y)|, where \(x\) is a real part, and \(y\) is an imaginary part. \(x\) and \(y\) can also be fractions (numerators and denominators should be integers). The package has a command \verb|\imUnit| which provides typesetting for the imaginary unit. Its default value is \verb|\mathrm{i}|. It can be redefined. For example, one can redefine it as \verb|\renewcommand{\imUnit}{j}}|.
Table \ref{tbl:illluamaths2} illustrates calculations on fractions and complex numbers using the \verb|luamaths| package. The numbers \(x, y, c\) and \(d\) are defined using the following commands.
\begin{lstlisting}
\def\x{lfrac(1,2)}
\def\y{lfrac(-3,4)}
\def\c{lcomplex(lfrac(3,4),6)}
\def\d{lcomplex(3,-9)}
\end{lstlisting}
\subsection*{Some Illustrations}
\def\x{lfrac(1,2)}
\def\y{lfrac(-3,4)}
\def\c{lcomplex(lfrac(3,4),6)}
\def\d{lcomplex(3,-9)}
\begin{center}
\begin{longtable}{lc}
\toprule
\multicolumn{1}{c}{\textcolor{blue}{LaTeX input}} &\multicolumn{1}{c}{\textcolor{blue}{Output}} \\
\toprule
\begin{lstlisting}
\(x + y = \mathOp{\x + \y}\)
\end{lstlisting}
& \(x + y = \mathOp{\x + \y}\) \\ \hline
\begin{lstlisting}
\(x - y = \mathOp{\x - \y}\)
\end{lstlisting}
& \(x - y = \mathOp{\x - \y}\) \\ \hline
\begin{lstlisting}
\(xy = \mathOp{\x*\y}\)
\end{lstlisting}
& \(xy = \mathOp{\x*\y}\) \\ \hline
\begin{lstlisting}
\(\frac{x}{y} = \mathOp{\x / \y}\)
\end{lstlisting}
& \(\frac{x}{y} = \mathOp{\x / \y}\) \\ \hline
\begin{lstlisting}
\(c + d = \mathOp{\c + \d}\)
\end{lstlisting}
& \(c + d = \mathOp{\c + \d}\) \\ \hline
\begin{lstlisting}
\(c - d = \mathOp{\c - \d}\)
\end{lstlisting}
& \(c - d = \mathOp{\c - \d}\) \\ \hline
\begin{lstlisting}
\(cd = \mathOp{\c*\d}\)
\end{lstlisting}
& \(cd = \mathOp{\c*\d}\) \\ \hline
\begin{lstlisting}
\(\frac{c}{d} = \mathOp{\c / \d}\)
\end{lstlisting}
& \(\frac{c}{d} = \mathOp{\c / \d}\) \\ \hline
\begin{lstlisting}
\(x + c - y + d = \mathOp{\x + \c - \y + \d}\)
\end{lstlisting}
& \(x + c - y + d = \mathOp{\x + \c - \y + \d}\) \\
\bottomrule \\
\caption{Calculations on fractions and complex numbers}
\label{tbl:illluamaths2}
\end{longtable}
\end{center}
\printbibliography
\end{document}
|