\documentclass{article}
\usepackage{listings,color,booktabs,longtable,array,hyperref,multicol,framed}
\usepackage[ top=1in, bottom = 1in, left=1in, right=1in]{geometry}
\hypersetup{colorlinks,urlcolor=blue}
\lstset{frame=none,
  language=[LaTeX]{TeX},
  aboveskip=3mm,
  belowskip=3mm,
  showstringspaces=false,
  columns=flexible,
  basicstyle={\ttfamily},
  numbers=none,
  numberstyle=\tiny\color{gray},
  stringstyle=\color{mauve},
  breaklines=true,
  breakatwhitespace=true,
  tabsize=1,
 upquote=true
}
\usepackage[backend=bibtex]{biblatex}
\begin{document}
\title{The luacomplex Package in LaTeX}
\author{Chetan Shirore and Ajit Kumar}
\maketitle
\section{Introduction}\label{section:introduction}
The  \verb|luacomplex| package is developed to define complex numbers and perform basic arithmetic on complex numbers in LaTeX. It also loads the \texttt{luamaths} package. It provides an easy way to define complex numbers and perform operations on complex numbers. The package has no particular environment for performing operations on complex numbers. The package commands can be used in any environment (including the mathematics environment). It is written in Lua, and the tex file is to be compiled with the LuaLatex engine. The time required for operations on complex numbers 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 may also save users' efforts to copy complex numbers from other software (which may not be in latex-compatible format) and to use them in a tex file. 

\section{Installation and License}

The installation of \verb|luacomplex| 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{luacomplex}| command in the preamble of the LaTeX document. The TeX file is to be compiled using the LuaLaTeX engine.

The \verb|luacomplex| 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.

\subsection{Defining and Printing Complex Numbers}
A complex number can be defined by using the \verb|\cpxNew| command. It has the following syntax.
\begin{lstlisting}
\cpxNew{a}{x,y}
\end{lstlisting}
\(x\) and \(y\) are  real and imaginary parts of   complex number \(a\).
The following commands define complex numbers \( a \) and \(b\).
\begin{lstlisting}
\cpxNew{a}{3,4}
\cpxNew{b}{1,3}
\end{lstlisting}
A complex number can be printed by using the \verb|\cpxPrint| command. For example, the commands
 \begin{lstlisting}
\(a=\cpxPrint{a}\) \\
\(b=\cpxPrint{b}\) }
\end{lstlisting}
output to \\
\(a = 3 + 4i\)\\
\(b = 1 + 3i\)

\section{Commands in the luacomplex package}
Table \ref{tbl:luacomplex} lists operations in the \verb|luacomplex| package.
\begin{longtable}{llm{6cm}}
\toprule
\multicolumn{1}{c}{\textcolor{blue}{Function}} & \multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}}\\
\toprule
\begin{lstlisting}
\cpxNew
\end{lstlisting} &
\begin{lstlisting}
\cpxNew{c}{r}{i}
\end{lstlisting} & Defines complex number \(c\) with real part \(r\) and imaginary part \(i\). \\
\midrule
\begin{lstlisting}
\cpxPrint
\end{lstlisting} &
\begin{lstlisting}
\cpxPrint{a}
\end{lstlisting} & Prints complex number \(a\). \\
\midrule
\begin{lstlisting}
\cpxAdd
\end{lstlisting} &
\begin{lstlisting}
\cpxAdd{c}{a}{b}
\end{lstlisting} & Defines complex number \(c\) obtained by adding complex numbers \(a\) and \(b\). \\
\midrule
\begin{lstlisting}
\cpxSub
\end{lstlisting} &
\begin{lstlisting}
\cpxSub{d}{a}{b}
\end{lstlisting} & Defines complex number \(d\) obtained by subtracting complex number \(b\) from  \(a\). \\
\midrule
\begin{lstlisting}
\cpxMul
\end{lstlisting} &
\begin{lstlisting}
\cpxMul{e}{a}{b}
\end{lstlisting} & Defines complex number \(e\) obtained by multiplying complex number \(a\) by \(b\). \\
\midrule
\begin{lstlisting}
\cpxDiv
\end{lstlisting} &
\begin{lstlisting}
\cpxDiv{f}{a}{b}
\end{lstlisting} & Defines complex number \(f\) obtained by dividing complex number \(a\) by \(b\). \\
\midrule
\begin{lstlisting}
\cpxInv
\end{lstlisting} &
\begin{lstlisting}
\cpxInv{g}{a}
\end{lstlisting} & Defines complex number \(g\) obtained by taking inverse of complex number \(a\). \\
\midrule
\begin{lstlisting}
\cpxRe
\end{lstlisting} &
\begin{lstlisting}
\cpxRe{h}{a}
\end{lstlisting} & Defines  \(h\) as a real part of complex number \(a\). \\
\midrule
\begin{lstlisting}
\cpxIm
\end{lstlisting} &
\begin{lstlisting}
\cpxIm{j}{a}
\end{lstlisting} & Defines  \(j\) as an imaginary part of complex number \(a\). \\
\midrule
\begin{lstlisting}
\cpxMod
\end{lstlisting} &
\begin{lstlisting}
\cpxMod{m}{a}
\end{lstlisting} & Defines  \(m\) as modulus of complex number \(a\). \\
\midrule
\begin{lstlisting}
\cpxPrinArg
\end{lstlisting} &
\begin{lstlisting}
\cpxPrinArg{p}{a}
\end{lstlisting} & Defines  \(p\) as the principal argument of complex number \(a\). \\
\midrule
\begin{lstlisting}
\cpxOp
\end{lstlisting} &
\begin{lstlisting}
\cpxOp{n}{some operations}
\end{lstlisting} & Defines \(n\) as a resulting complex number by performing some operations on complex numbers. It supports all standard operations such as \(+,-,*, /, \)   \^{}.\\
\bottomrule
\caption{Commands in the luacomplex package}
\label{tbl:luacomplex}
\end{longtable}

The package has a command \verb|\imgUnit| which provides typesetting for the imaginary unit. Its default value is \(i\). It can be redefined. For example, one can redefine it as  \verb|\renewcommand{\imgUnit}{\mathrm{i}}| or as \verb|\renewcommand{\imgUnit}{j}}|.


\section{Examples and Usage}
The latex document (Listing: \ref{code:illluacomplex}) makes use of  various commands in \verb|luacomplex| package.
\begin{lstlisting}[label={code:illluacomplex}, caption={LaTeX document with luacomplex package}]
\documentclass{article}
\usepackage{luacomplex}
\begin{document}
\cpxNew{a}{3,4}
\cpxNew{b}{1,3}
\(a=\cpxPrint{a}\) \\
\(b=\cpxPrint{b}\) \\
\cpxAdd{c}{a}{b}
\(c=a+b=\cpxPrint{c}\) \\
\cpxSub{d}{a}{b}
\(d=a-b=\cpxPrint{d}\) \\
\cpxMul{e}{a}{b}
\(e=a.b=\cpxPrint{e}\) \\
\cpxDiv{f}{a}{b}
\(f=\frac{a}{b}=\cpxPrint{f}\) \\
\cpxInv{g}{a}
\(g=\frac{1}{a}=\cpxPrint{g}\) \\
\cpxRe{h}{a}
\(h=Re(a)=\cpxPrint{h}\) \\
\cpxIm{j}{a}
\(j=Im(a)=\cpxPrint{j}\) \\
\cpxMod{m}{a}
\(m=|a|=\cpxPrint{m}\) \\
\cpxOp{n}{a+b*c-d}
\(n=a+bc-d=\cpxPrint{n}\) \\
\cpxPrinArg{p}{a}
\(p = prinArg(a) =\mathRound{\cpxPrint{p}}{4}\) 
\end{document}
\end{lstlisting}
This latex document (listing: \ref{code:illluacomplex}) outputs  the following on compiling with the LuaLaTeX engine.
\begin{framed}
\noindent\(a = 3 + 4i\)\\
\(b = 1 + 3i\)\\
\(c = a + b = 4 + 7i\)\\
\(d=a-b=2+i\)\\
\(e = a.b = -9 + 13i\)\\
\(f = ab = 1.5 - 0.5i\)\\
\(g = a1 = 0.12 - 0.16i\)\\
\(h = Re(a) = 3\)\\
\(j = Im(a) = 4\)\\
\(m = |a| = 25\)\\
\(n =a+bc-d= -16 + 22i\)\\
\(p = prinArg(a) = 0.9273\)
\end{framed}

The package can be modified or extended by adding custom Lua programs.

\printbibliography
\end{document}
