diff options
Diffstat (limited to 'macros/luatex')
-rw-r--r-- | macros/luatex/latex/luamaths/README.txt | 18 | ||||
-rw-r--r-- | macros/luatex/latex/luamaths/luamaths.bib | 39 | ||||
-rw-r--r-- | macros/luatex/latex/luamaths/luamaths.pdf | bin | 0 -> 176909 bytes | |||
-rw-r--r-- | macros/luatex/latex/luamaths/luamaths.sty | 41 | ||||
-rw-r--r-- | macros/luatex/latex/luamaths/luamaths.tex | 325 |
5 files changed, 423 insertions, 0 deletions
diff --git a/macros/luatex/latex/luamaths/README.txt b/macros/luatex/latex/luamaths/README.txt new file mode 100644 index 0000000000..02466225a8 --- /dev/null +++ b/macros/luatex/latex/luamaths/README.txt @@ -0,0 +1,18 @@ +# Introduction +The 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). + + +# License +The luamaths package is released under the LaTeX Project Public License v1.3c or later. +The complete license text is available at 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. + +#Installation and Inclusion +The installation of luamaths package is similar to plain latex package, where the .sty file is in LATEXdirectory of texmf tree. +The package can be included with \usepackage{luamaths} command in the preamble of the LaTeX document. +The TeX file is to be compiled using the LuaLaTeX engine. diff --git a/macros/luatex/latex/luamaths/luamaths.bib b/macros/luatex/latex/luamaths/luamaths.bib new file mode 100644 index 0000000000..4069c4adc2 --- /dev/null +++ b/macros/luatex/latex/luamaths/luamaths.bib @@ -0,0 +1,39 @@ +\begin{filecontents}{luamodtbl.bib} + +@online{online.luaorg, + title = {Lua Programming Language}, + url = {https://www.lua.org/manual/5.4}, + note = {visited on 2022-03-26} +} +@online{online.tex, + title = {TeX Language}, + url = {https://www.cs.mcgill.ca/~rwest/wikispeedia/wpcd/wp/t/TeX.htm}, + note = {visited on 2022-03-26} +} +@online{online.texscript, + title = {TEX and Scripting Languages}, + year = 2022, + url = {https://tug.org/TUGboat/tb25-1/richter.pdf}, +note = {visited on 2022-01-01} +} +@online{online.luacode, + title = {luacode package}, + year = 2012, + url = {https://mirror.kku.ac.th/CTAN/macros/luatex/latex/luacode/luacode.pdf}, + note = {visited on 2022-03-10} +} +@online{online.luatex, + title = {luatex Package}, + url = {https://ctan.org/pkg/luatex?lang=en}, + note = {visited on 2022-01-22} +} +@online{online.pgf, + title = {pgf Package}, + url = {https://ctan.org/pkg/pgf?lang=en}, +note = {visited on 2021-01-10} +} +@online{online.xparse, + title = {xparse Package}, + url = {https://ctan.org/pkg/xparse?lang=en}, + note = {visited on 2021-03-10} +} diff --git a/macros/luatex/latex/luamaths/luamaths.pdf b/macros/luatex/latex/luamaths/luamaths.pdf Binary files differnew file mode 100644 index 0000000000..a9ffe78a82 --- /dev/null +++ b/macros/luatex/latex/luamaths/luamaths.pdf diff --git a/macros/luatex/latex/luamaths/luamaths.sty b/macros/luatex/latex/luamaths/luamaths.sty new file mode 100644 index 0000000000..c3bc4d51e0 --- /dev/null +++ b/macros/luatex/latex/luamaths/luamaths.sty @@ -0,0 +1,41 @@ +% luaset package +% version 1.0 +% Authors: Chetan Shirore and Ajit Kumar +% Licensed under LaTeX Project Public License v1.3c or later. The complete license text is available at http://www.latex-project.org/lppl.txt. + +\ProvidesPackage{luaset}[1.0] +\RequirePackage{xkeyval} +\RequirePackage{amsmath} +\RequirePackage{luacode} +\begin{luacode*} +function mathop(...) +inf = math.huge +return ... +end + +function mathround(num, numDecimalPlaces) + local mult = 10^(numDecimalPlaces or 0) + return math.floor(num * mult + 0.5) / mult +end +\end{luacode*} +\newcommand\mathOp[1]{\directlua{tex.sprint(tostring(mathop(#1)))}} +\newcommand\mathAbs[1]{\directlua{tex.sprint(math.abs(#1))}} +\newcommand\mathAcos[1]{\directlua{tex.sprint(math.acos(#1))}} +\newcommand\mathAsin[1]{\directlua{tex.sprint(math.asin(#1))}} +\newcommand\mathAtan[1]{\directlua{tex.sprint(math.atan(#1))}} +\newcommand\mathCeil[1]{\directlua{tex.sprint(math.ceil(#1))}} +\newcommand\mathCos[1]{\directlua{tex.sprint(math.cos(#1))}} +\newcommand\mathExp[1]{\directlua{tex.sprint(math.exp(#1))}} +\newcommand\mathFloor[1]{\directlua{tex.sprint(math.floor(#1))}} +\newcommand\mathHuge{\directlua{tex.sprint(math.huge)}} +\newcommand\mathLog[1]{\directlua{tex.sprint(math.log(#1))}} +\newcommand\mathMax[1]{\directlua{tex.sprint(math.max(#1))}} +\newcommand\mathMin[1]{\directlua{tex.sprint(math.min(#1))}} +\newcommand\mathPi{\directlua{tex.sprint(math.pi)}} +\newcommand\mathRandom[1]{\directlua{tex.sprint(math.random(#1))}} +\newcommand\mathSin[1]{\directlua{tex.sprint(tostring(math.sin(#1)))}} +\newcommand\mathSqrt[1]{\directlua{tex.sprint(math.sqrt(#1))}} +\newcommand\mathTan[1]{\directlua{tex.sprint(math.tan(#1))}} +\newcommand\mathRad[1]{\directlua{tex.sprint(math.rad(#1))}} +\newcommand\mathRound[2]{\directlua{tex.sprint(mathround(#1,#2))}} +\endinput diff --git a/macros/luatex/latex/luamaths/luamaths.tex b/macros/luatex/latex/luamaths/luamaths.tex new file mode 100644 index 0000000000..0c5abbbe94 --- /dev/null +++ b/macros/luatex/latex/luamaths/luamaths.tex @@ -0,0 +1,325 @@ +\documentclass{article} +\usepackage{listings,color,booktabs,longtable,array,hyperref,multicol} +\usepackage[ 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 +} +\usepackage[backend=bibtex]{biblatex} +\addbibresource{luamaths} +\begin{document} +\title{The luamaths Package in LaTeX} +\author{Chetan Shirore and Dr. 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{6cm}} +\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 digits. \\ +\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.\\ +\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} & \(1292.0\)\\ +\midrule +\begin{lstlisting} +\mathAbs{-6.96} +\end{lstlisting} & \(6.96\)\\ +\midrule + + +\begin{lstlisting} +\mathFloor{-6.9} +\end{lstlisting} & \(-7\) \\ +\midrule + +\begin{lstlisting} +\mathFloor{9.9} +\end{lstlisting} & \(9\)\\ +\midrule + + +\begin{lstlisting} +\mathCeil{-9.9} +\end{lstlisting} & \(-9\) \\ +\midrule + +\begin{lstlisting} +\mathCeil{6.3} +\end{lstlisting} &\(7\)\\ +\midrule + +\begin{lstlisting} +\mathRound{9.678884}{3} +\end{lstlisting} & \(9.679\)\\ +\midrule + +\begin{lstlisting} +\mathMax{20,30,100} +\end{lstlisting} &\(100\) \\ +\midrule + +\begin{lstlisting} +\mathMin{20,30,100} +\end{lstlisting} &\(20\)\\ +\midrule + + +\begin{lstlisting} +\mathPi +\end{lstlisting} & \(3.1415926535898\)\\ +\midrule + + +\begin{lstlisting} +\mathRound{\mathPi}{6} +\end{lstlisting} & \(3.141593\)\\ +\midrule + +\begin{lstlisting} +\mathInf +\end{lstlisting} & \(Inf\)\\ +\midrule + +\begin{lstlisting} +\mathOp{\mathInf/2} +\end{lstlisting} &\(Inf\) \\ +\midrule + +\begin{lstlisting} +\mathSqrt{9} +\end{lstlisting} & \(3.0\)\\ +\midrule + +\begin{lstlisting} +\mathLog{2} +\end{lstlisting} & \(0.69314718055995\)\\ +\midrule + +\begin{lstlisting} +\mathExp{3} +\end{lstlisting} & \(20.085536923188\) \\ +\midrule + +\begin{lstlisting} +\mathRad{1800} +\end{lstlisting} & \(31.415926535898\)\\ +\midrule + + +\begin{lstlisting} +\mathSin{0} +\end{lstlisting} &\(0.0\)\\ +\midrule + +\begin{lstlisting} +\mathCos{0} +\end{lstlisting} & \(1.0\)\\ +\midrule + + +\begin{lstlisting} +\mathTan{0} +\end{lstlisting} & \(0.0\)\\ +\midrule + +\begin{lstlisting} +\mathAsin{0} +\end{lstlisting} & \(0.0\)\\ +\midrule + +\begin{lstlisting} +\mathAcos{0} +\end{lstlisting} & \(1.5707963267949\)\\ +\midrule + +\begin{lstlisting} +\mathAtan{0} +\end{lstlisting} & \(0.0\)\\ +\midrule + +\begin{lstlisting} +\mathRound{\mathOp{9+\mathSin{4}}}{6} +\end{lstlisting} & \(8.243198\)\\ +\midrule +\caption{Illustrations of commands in the luamaths package} +\label{tbl:illluamaths} +\end{longtable} +\end{center} + +\printbibliography +\end{document} |