Debian Codegraph @

texmf-dist/doc/lualatex/luacomplex/luacomplex.tex

raw
1 \documentclass{article}
2 \usepackage{listings,color,booktabs,longtable,array,hyperref,multicol,framed,luacomplex}
3 \usepackage[ top=1in, bottom = 1in, left=1in, right=1in]{geometry}
4 \hypersetup{colorlinks,urlcolor=blue}
5 \lstset{frame=none,
6 language=[LaTeX]{TeX},
7 aboveskip=3mm,
8 belowskip=3mm,
9 showstringspaces=false,
10 columns=flexible,
11 basicstyle={\ttfamily},
12 numbers=none,
13 numberstyle=\tiny\color{gray},
14 stringstyle=\color{mauve},
15 breaklines=true,
16 breakatwhitespace=true,
17 tabsize=1,
18 upquote=true
19 }
20 \usepackage[backend=bibtex]{biblatex}
21 \begin{document}
22 \title{The luacomplex Package in LaTeX}
23 \author{Chetan Shirore\thanks{Email id: [email protected]} \space and Ajit Kumar}
24 \maketitle
25 \section{Introduction}\label{section:introduction}
26 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.
27
28 \section{Installation and License}
29
30 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.
31
32 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.
33
34 \subsection{Defining and Printing Complex Numbers}
35 A complex number can be defined by using the \verb|\cpxNew| command. It has the following syntax.
36 \begin{lstlisting}
37 \cpxNew{a}{x,y}
38 \end{lstlisting}
39 \(x\) and \(y\) are real and imaginary parts of complex number \(a\).
40 The following commands define complex numbers \( a \) and \(b\).
41 \begin{lstlisting}
42 \cpxNew{a}{3,4}
43 \cpxNew{b}{1,3}
44 \end{lstlisting}
45 A complex number can be printed by using the \verb|\cpxPrint| command. For example, the commands
46 \begin{lstlisting}
47 \(a=\cpxPrint{a}\) \\
48 \(b=\cpxPrint{b}\) }
49 \end{lstlisting}
50 output to \\
51 \(a = 3 + 4i\)\\
52 \(b = 1 + 3i\)
53
54 \section{Commands in the luacomplex package}
55 Table \ref{tbl:luacomplex} lists operations in the \verb|luacomplex| package.
56 \begin{longtable}{llm{6cm}}
57 \toprule
58 \multicolumn{1}{c}{\textcolor{blue}{Function}} & \multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}}\\
59 \toprule
60 \begin{lstlisting}
61 \cpxNew
62 \end{lstlisting} &
63 \begin{lstlisting}
64 \cpxNew{c}{r}{i}
65 \end{lstlisting} & Defines complex number \(c\) with real part \(r\) and imaginary part \(i\). \\
66 \midrule
67 \begin{lstlisting}
68 \cpxPrint
69 \end{lstlisting} &
70 \begin{lstlisting}
71 \cpxPrint{a}
72 \end{lstlisting} & Prints complex number \(a\). \\
73 \midrule
74 \begin{lstlisting}
75 \cpxAdd
76 \end{lstlisting} &
77 \begin{lstlisting}
78 \cpxAdd{c}{a}{b}
79 \end{lstlisting} & Defines complex number \(c\) obtained by adding complex numbers \(a\) and \(b\). \\
80 \midrule
81 \begin{lstlisting}
82 \cpxSub
83 \end{lstlisting} &
84 \begin{lstlisting}
85 \cpxSub{d}{a}{b}
86 \end{lstlisting} & Defines complex number \(d\) obtained by subtracting complex number \(b\) from \(a\). \\
87 \midrule
88 \begin{lstlisting}
89 \cpxMul
90 \end{lstlisting} &
91 \begin{lstlisting}
92 \cpxMul{e}{a}{b}
93 \end{lstlisting} & Defines complex number \(e\) obtained by multiplying complex number \(a\) by \(b\). \\
94 \midrule
95 \begin{lstlisting}
96 \cpxDiv
97 \end{lstlisting} &
98 \begin{lstlisting}
99 \cpxDiv{f}{a}{b}
100 \end{lstlisting} & Defines complex number \(f\) obtained by dividing complex number \(a\) by \(b\). \\
101 \midrule
102 \begin{lstlisting}
103 \cpxInv
104 \end{lstlisting} &
105 \begin{lstlisting}
106 \cpxInv{g}{a}
107 \end{lstlisting} & Defines complex number \(g\) obtained by taking inverse of complex number \(a\). \\
108 \midrule
109 \begin{lstlisting}
110 \cpxRe
111 \end{lstlisting} &
112 \begin{lstlisting}
113 \cpxRe{h}{a}
114 \end{lstlisting} & Defines \(h\) as a real part of complex number \(a\). \\
115 \midrule
116 \begin{lstlisting}
117 \cpxIm
118 \end{lstlisting} &
119 \begin{lstlisting}
120 \cpxIm{j}{a}
121 \end{lstlisting} & Defines \(j\) as an imaginary part of complex number \(a\). \\
122 \midrule
123 \begin{lstlisting}
124 \cpxMod
125 \end{lstlisting} &
126 \begin{lstlisting}
127 \cpxMod{m}{a}
128 \end{lstlisting} & Defines \(m\) as modulus of complex number \(a\). \\
129 \midrule
130 \begin{lstlisting}
131 \cpxPrinArg
132 \end{lstlisting} &
133 \begin{lstlisting}
134 \cpxPrinArg{p}{a}
135 \end{lstlisting} & Defines \(p\) as the principal argument of complex number \(a\). \\
136 \midrule
137 \begin{lstlisting}
138 \cpxOp
139 \end{lstlisting} &
140 \begin{lstlisting}
141 \cpxOp{n}{some operations}
142 \end{lstlisting} & Defines \(n\) as a resulting complex number by performing some operations on complex numbers. It supports all standard operations such as \(+,-,*, /, \) \^{}.\\
143 \bottomrule
144 \caption{Commands in the luacomplex package}
145 \label{tbl:luacomplex}
146 \end{longtable}
147
148 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}}|.
149
150
151 \section{Examples and Usage}
152 The latex document (Listing: \ref{code:illluacomplex}) makes use of various commands in \verb|luacomplex| package.
153 \begin{lstlisting}[label={code:illluacomplex}, caption={LaTeX document with luacomplex package}]
154 \documentclass{article}
155 \usepackage{luacomplex}
156 \begin{document}
157 \renewcommand{\imgUnit}{\mathrm{i}}
158 \cpxNew{a}{3,4}
159 \cpxNew{b}{1,3}
160 \(a=\cpxPrint{a}\) \\
161 \(b=\cpxPrint{b}\) \\
162 \cpxAdd{c}{a}{b}
163 \(c=a+b=\cpxPrint{c}\) \\
164 \cpxSub{d}{a}{b}
165 \(d=a-b=\cpxPrint{d}\) \\
166 \cpxMul{e}{a}{b}
167 \(e=a.b=\cpxPrint{e}\) \\
168 \cpxDiv{f}{a}{b}
169 \(f=\frac{a}{b}=\cpxPrint{f}\) \\
170 \cpxInv{g}{a}
171 \(g=\frac{1}{a}=\cpxPrint{g}\) \\
172 \cpxRe{h}{a}
173 \(h=Re(a)=\cpxPrint{h}\) \\
174 \cpxIm{j}{a}
175 \(j=Im(a)=\cpxPrint{j}\) \\
176 \cpxMod{m}{a}
177 \(m=|a|=\cpxPrint{m}\) \\
178 \cpxOp{n}{a+b*c-d}
179 \(n=a+bc-d=\cpxPrint{n}\) \\
180 \cpxPrinArg{p}{a}
181 \(p = prinArg(a) =\mathRound{\cpxPrint{p}}{4}\)
182 \end{document}
183 \end{lstlisting}
184
185 This latex document (listing: \ref{code:illluacomplex}) outputs the following on compiling with the LuaLaTeX engine. \\
186 \cpxNew{a}{3,4}
187 \cpxNew{b}{1,3}
188
189 \begin{minipage}{0.4\textwidth}
190 \begin{framed}
191 \noindent\(a=\cpxPrint{a}\) \\
192 \(b=\cpxPrint{b}\) \\
193 \cpxAdd{c}{a}{b}
194 \(c=a+b=\cpxPrint{c}\) \\
195 \cpxSub{d}{a}{b}
196 \(d=a-b=\cpxPrint{d}\) \\
197 \cpxMul{e}{a}{b}
198 \(e=a.b=\cpxPrint{e}\) \\
199 \cpxDiv{f}{a}{b}
200 \(f=\frac{a}{b}=\cpxPrint{f}\)
201 \end{framed}
202 \end{minipage}
203 \begin{minipage}{0.4\textwidth}
204 \begin{framed}
205 \cpxInv{g}{a}
206 \(g=\frac{1}{a}=\cpxPrint{g}\) \\
207 \cpxRe{h}{a}
208 \(h=Re(a)=\cpxPrint{h}\) \\
209 \cpxIm{j}{a}
210 \(j=Im(a)=\cpxPrint{j}\) \\
211 \cpxMod{m}{a}
212 \(m=|a|=\cpxPrint{m}\) \\
213 \cpxOp{n}{a+b*c-d}
214 \(n=a+bc-d=\cpxPrint{n}\) \\
215 \cpxPrinArg{p}{a}
216 \(p = prinArg(a) =\mathRound{\cpxPrint{p}}{4}\)
217 \end{framed}
218 \end{minipage} \\
219
220 The package can be modified or extended by adding custom Lua programs.
221
222 \printbibliography
223 \end{document}