texlive[67852] Master/texmf-dist: luacomplex (8aug23)

commits+karl at tug.org commits+karl at tug.org
Tue Aug 8 21:53:38 CEST 2023


Revision: 67852
          http://tug.org/svn/texlive?view=revision&revision=67852
Author:   karl
Date:     2023-08-08 21:53:38 +0200 (Tue, 08 Aug 2023)
Log Message:
-----------
luacomplex (8aug23)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/lualatex/luacomplex/README.txt
    trunk/Master/texmf-dist/doc/lualatex/luacomplex/luacomplex.pdf
    trunk/Master/texmf-dist/doc/lualatex/luacomplex/luacomplex.tex
    trunk/Master/texmf-dist/tex/lualatex/luacomplex/luacomplex.sty

Modified: trunk/Master/texmf-dist/doc/lualatex/luacomplex/README.txt
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/luacomplex/README.txt	2023-08-08 19:53:29 UTC (rev 67851)
+++ trunk/Master/texmf-dist/doc/lualatex/luacomplex/README.txt	2023-08-08 19:53:38 UTC (rev 67852)
@@ -1,3 +1,8 @@
+# The luacomplex package
+# version 1.3
+# Authors: Chetan Shirore and Ajit Kumar
+# Email: mathsbeauty at gmail.com
+
 # Introduction
 The luacomplex package is developed to define complex numbers and perform basic arithmetic on complex numbers in LaTeX. 
 It also loads the luamaths package. 
@@ -14,6 +19,6 @@
 Its license is simple and liberal, which is compatible with GPL.
 
 #Installation and Inclusion
-The installation of luagcd package is similar to plain latex package, where the .sty file is in LaTeX directory of texmf tree. 
-The package can be included with \usepackage{luacomplex } command in the preamble of the LaTeX document. 
+The installation of luacomplex package is similar to plain latex package, where the .sty file is in LaTeX directory of texmf tree. 
+The package can be included with \usepackage{luacomplex} command in the preamble of the LaTeX document. 
 The TeX file is to be compiled using the LuaLaTeX engine. 
\ No newline at end of file

Modified: trunk/Master/texmf-dist/doc/lualatex/luacomplex/luacomplex.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/lualatex/luacomplex/luacomplex.tex
===================================================================
--- trunk/Master/texmf-dist/doc/lualatex/luacomplex/luacomplex.tex	2023-08-08 19:53:29 UTC (rev 67851)
+++ trunk/Master/texmf-dist/doc/lualatex/luacomplex/luacomplex.tex	2023-08-08 19:53:38 UTC (rev 67852)
@@ -1,5 +1,5 @@
 \documentclass{article}
-\usepackage{listings,color,booktabs,longtable,array,hyperref,multicol,framed}
+\usepackage{listings,color,booktabs,longtable,array,hyperref,multicol,framed,luacomplex}
 \usepackage[ top=1in, bottom = 1in, left=1in, right=1in]{geometry}
 \hypersetup{colorlinks,urlcolor=blue}
 \lstset{frame=none,
@@ -20,7 +20,7 @@
 \usepackage[backend=bibtex]{biblatex}
 \begin{document}
 \title{The luacomplex Package in LaTeX}
-\author{Chetan Shirore and Ajit Kumar}
+\author{Chetan Shirore\thanks{Email id: mathsbeauty at gmail.com} \space 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. 
@@ -149,11 +149,12 @@
 
 
 \section{Examples and Usage}
-The latex document (Listing: \ref{code:illluacomplex}) makes use of  various commands in \verb|luacomplex| package.
+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}
+\renewcommand{\imgUnit}{\mathrm{i}}
 \cpxNew{a}{3,4}
 \cpxNew{b}{1,3}
 \(a=\cpxPrint{a}\) \\
@@ -180,21 +181,41 @@
 \(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.
+
+This latex document (listing: \ref{code:illluacomplex}) outputs  the following on compiling with the LuaLaTeX engine. \\
+\cpxNew{a}{3,4}
+\cpxNew{b}{1,3}
+
+ \begin{minipage}{0.4\textwidth}
 \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\)
+\noindent\(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}\)
 \end{framed}
+\end{minipage}
+\begin{minipage}{0.4\textwidth}
+\begin{framed}
+\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{framed}
+\end{minipage} \\
 
 The package can be modified or extended by adding custom Lua programs.
 

Modified: trunk/Master/texmf-dist/tex/lualatex/luacomplex/luacomplex.sty
===================================================================
--- trunk/Master/texmf-dist/tex/lualatex/luacomplex/luacomplex.sty	2023-08-08 19:53:29 UTC (rev 67851)
+++ trunk/Master/texmf-dist/tex/lualatex/luacomplex/luacomplex.sty	2023-08-08 19:53:38 UTC (rev 67852)
@@ -1,62 +1,66 @@
-% luacomplex package
-% version 1.2 Date: 14-Feb-2023
+% The luacomplex package
+% Version 1.3 Date: 08-Aug-2023
 % Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt.
 % Authors: Chetan Shirore and Ajit Kumar
 
-\ProvidesPackage{luacomplex}[1.2]
+\ProvidesPackage{luacomplex}[1.3]
 \RequirePackage{xkeyval}
 \RequirePackage{amsmath}
 \RequirePackage{luacode}
 \RequirePackage{luamaths}
 \begin{luacode*}
-complex = {} -- global complex numbers registry
-M = {}         -- the module
+complexZ = {} -- global complex numbers registry
+CM = {}         -- the module
 local mt = {} --metatable for complex numbers
-setmetatable(_ENV, {__index = complex})
-   function new (r, i)
+setmetatable(_ENV, {__index = complexZ})
+   function CM.new (r, i)
        local cp = {}
         cp = {r=r, i=i}
         return setmetatable(cp,mt)
       end
-      M.new = new        -- add 'new' to the module
+     
       -- create constant 'i'
-      M.i = new(0, 1)
+      CM.i = CM.new(0, 1)
 
-      function M.add (c1, c2)
-        return new(c1.r + c2.r, c1.i + c2.i)
+      function CM.add (c1, c2)
+        return CM.new(c1.r + c2.r, c1.i + c2.i)
       end
 
-      function M.sub (c1, c2)
-        return new(c1.r - c2.r, c1.i - c2.i)
+      function CM.sub (c1, c2)
+        return CM.new(c1.r - c2.r, c1.i - c2.i)
       end
+	  
+	  function CM.minus (c1)
+        return CM.new(-c1.r, -c1.i)
+      end
 
-      function M.mul (c1, c2)
-        return new(c1.r*c2.r - c1.i*c2.i, c1.r*c2.i + c1.i*c2.r)
+      function CM.mul (c1, c2)
+        return CM.new(c1.r*c2.r - c1.i*c2.i, c1.r*c2.i + c1.i*c2.r)
       end
 
-    function M.inv (c)
+    function CM.inv (c)
         local n = c.r^2 + c.i^2
-        return new(c.r/n, -c.i/n)
+        return CM.new(c.r/n, -c.i/n)
       end
 
-      function M.div (c1, c2)
-        return M.mul(c1, M.inv(c2))
+      function CM.div (c1, c2)
+        return CM.mul(c1, CM.inv(c2))
       end
 
-      function M.re (c)
-        return new(c.r,0)
+      function CM.re (c)
+        return CM.new(c.r,0)
       end
 
-      function M.im (c)
-        return new(c.i,0)
+      function CM.im (c)
+        return CM.new(c.i,0)
       end
 
-      function M.mod (c)
+      function CM.mod (c)
         local n = c.r^2 + c.i^2
-        return new(n,0)
+        return CM.new(n,0)
       end
 	  
-	  function M.prinarg(c)
+	  function CM.prinarg(c)
         local arg
         if c.r > 0 then
         arg = math.atan(c.i/c.r)
@@ -71,14 +75,14 @@
         else 
         error("Principal argument not defined.")
         end
-        return arg
+        return CM.new(arg,0)
 	  end
 
-    function M.op (...)
+    function CM.op (...)
         return ...
       end
 
-      function M.tostring (c,imgunit)
+      function CM.tostring (c,imgunit)
 	  imgunit = "\\imgUnit"
         if c.i ==0 then
         return string.format("%g", c.r)
@@ -92,69 +96,70 @@
       end
       
     --Setting Metatable operations.
-    mt.__add = M.add
-    mt.__mul = M.mul
-    mt.__sub = M.sub
-    mt.__tostring = M.tostring
+    mt.__add = CM.add
+    mt.__mul = CM.mul
+    mt.__sub = CM.sub
+	mt.__unm = CM.minus
+    mt.__tostring = CM.tostring
 \end{luacode*}
 \newcommand\cpxNew[2]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.new(#2)
+        complexZ[\luastringN{#1}] = CM.new(#2)
     }%
 }
 \newcommand\cpxPrint[1]{%
-    \directlua{tex.sprint(tostring(complex[\luastringN{#1}]))}%
+    \directlua{tex.sprint(CM.tostring(complexZ[\luastringN{#1}]))}%
 }
 \newcommand\cpxAdd[3]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.add(complex[\luastringN{#2}],complex[\luastringN{#3}])
+        complexZ[\luastringN{#1}] = CM.add(complexZ[\luastringN{#2}],complexZ[\luastringN{#3}])
     }%
 }
 \newcommand\cpxSub[3]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.sub(complex[\luastringN{#2}],complex[\luastringN{#3}])
+        complexZ[\luastringN{#1}] = CM.sub(complexZ[\luastringN{#2}],complexZ[\luastringN{#3}])
     }%
 }
 \newcommand\cpxMul[3]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.mul(complex[\luastringN{#2}],complex[\luastringN{#3}])
+        complexZ[\luastringN{#1}] = CM.mul(complexZ[\luastringN{#2}],complexZ[\luastringN{#3}])
     }%
 }
 \newcommand\cpxDiv[3]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.div(complex[\luastringN{#2}],complex[\luastringN{#3}])
+        complexZ[\luastringN{#1}] = CM.div(complexZ[\luastringN{#2}],complexZ[\luastringN{#3}])
     }%
 }
 \newcommand\cpxInv[2]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.inv(complex[\luastringN{#2}])
+        complexZ[\luastringN{#1}] = CM.inv(complexZ[\luastringN{#2}])
     }%
 }
 \newcommand\cpxRe[2]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.re(complex[\luastringN{#2}])
+        complexZ[\luastringN{#1}] = CM.re(complexZ[\luastringN{#2}])
     }%
 }
 \newcommand\cpxIm[2]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.im(complex[\luastringN{#2}])
+        complexZ[\luastringN{#1}] = CM.im(complexZ[\luastringN{#2}])
     }%
 }
 \newcommand\cpxMod[2]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.mod(complex[\luastringN{#2}])
+        complexZ[\luastringN{#1}] = CM.mod(complexZ[\luastringN{#2}])
     }%
 }
 
 \newcommand\cpxPrinArg[2]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.prinarg(complex[\luastringN{#2}])
+        complexZ[\luastringN{#1}] = CM.prinarg(complexZ[\luastringN{#2}])
     }%
 }
 
 \newcommand\cpxOp[2]{%
     \directlua{%
-        complex[\luastringN{#1}] = M.op(#2)
+        complexZ[\luastringN{#1}] = CM.op(#2)
     }%
 }
 



More information about the tex-live-commits mailing list.