summaryrefslogtreecommitdiff
path: root/macros/luatex/latex/luacomplex/luacomplex.tex
blob: d630d46e7395ed4044740bbba816c0d9d163850e (plain)
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
\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 Dr. 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}



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