\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}