diff options
author | Norbert Preining <norbert@preining.info> | 2022-12-28 03:01:37 +0000 |
---|---|---|
committer | Norbert Preining <norbert@preining.info> | 2022-12-28 03:01:37 +0000 |
commit | c593cd7fcc1d6af28601f82bf0354a13eca3ff93 (patch) | |
tree | a5dd863995adf7f9090c66b45a3aa95c31b54f4c /macros/luatex/latex/luaset | |
parent | 9dfeafbb128537c1633d77071d8cc9b9f8c5a800 (diff) |
CTAN sync 202212280301
Diffstat (limited to 'macros/luatex/latex/luaset')
-rw-r--r-- | macros/luatex/latex/luaset/README.txt | 19 | ||||
-rw-r--r-- | macros/luatex/latex/luaset/luaset.pdf | bin | 0 -> 134778 bytes | |||
-rw-r--r-- | macros/luatex/latex/luaset/luaset.sty | 142 | ||||
-rw-r--r-- | macros/luatex/latex/luaset/luaset.tex | 230 |
4 files changed, 391 insertions, 0 deletions
diff --git a/macros/luatex/latex/luaset/README.txt b/macros/luatex/latex/luaset/README.txt new file mode 100644 index 0000000000..ca7ffb3860 --- /dev/null +++ b/macros/luatex/latex/luaset/README.txt @@ -0,0 +1,19 @@ +# Introduction +The luaset package is developed to define finite sets and perform operations on them inside LaTeX documents. +There is no particular environment in the package for performing set 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 the LuaLatex engine. +The time required for operations on sets is not an issue while compiling with the LuaLaTeX engine. +There is no need to install Lua on the users' system as tex distributions (TeXLive or MikTeX) come bundled with LuaLaTeX. + +# License +The luaset 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 luaset 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{luaset} 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 diff --git a/macros/luatex/latex/luaset/luaset.pdf b/macros/luatex/latex/luaset/luaset.pdf Binary files differnew file mode 100644 index 0000000000..4e4545be84 --- /dev/null +++ b/macros/luatex/latex/luaset/luaset.pdf diff --git a/macros/luatex/latex/luaset/luaset.sty b/macros/luatex/latex/luaset/luaset.sty new file mode 100644 index 0000000000..2a4821d365 --- /dev/null +++ b/macros/luatex/latex/luaset/luaset.sty @@ -0,0 +1,142 @@ +% 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} +\RequirePackage{luamaths} +\begin{luacode*} +sets = {} +Set = {} +local mt = { + __tostring = function(self) + return "\\{" .. table.concat(table.sortedkeys(self), ", ") .. "\\}" + end +} + +function Set.new(str) + str = str or "" + local set = {} + for v in utilities.parsers.iterator(str) do + set[v] = true + end + return setmetatable(set, mt) +end + +function Set.union (a, b) + local union = {} + for k in pairs(a) do union[k] = true end + for k in pairs(b) do union[k] = true end + return setmetatable(union, mt) + end + +function Set.intersection (a, b) + local intersection = {} + for k in pairs(a) do + intersection[k] = b[k] + end + return setmetatable(intersection, mt) + end + +function Set.difference (a, b) + local difference = {} + for k in pairs(a) do + if b[k]~= true then + difference[k] = true + end + end + setmetatable(difference, mt) + return difference + end + +function Set.cardinal (a) + local len = 0 + for k in pairs(a) do + len = len + 1 + end + return len + end + +function Set.subseteq(a, b) + for k in pairs(a) do + if not b[k] then return false end + end + return true + end + +function Set.subset (a, b) + return Set.subseteq(a, b) and not (Set.subseteq(b, a) ) + end + + function Set.equal (a, b) + return Set.subseteq(a, b) and (Set.subseteq(b, a) ) + end + + +function Set.belongsto (x, s) + if s[x] then + return true + else + return false + end + end + +\end{luacode*} + +\newcommand\luaSetNew[2]{% + \directlua{% + sets[\luastringN{#1}] = Set.new(\luastringN{#2}) + }% +} + +\newcommand\luaSetUnion[3]{% + \directlua{% + sets[\luastringN{#1}] = Set.union(sets[\luastringN{#2}], + sets[\luastringN{#3}]) + }% +} + +\newcommand\luaSetIntersection[3]{% + \directlua{% + sets[\luastringN{#1}] = Set.intersection(sets[\luastringN{#2}], + sets[\luastringN{#3}]) + }% +} + +\newcommand\luaSetDifference[3]{% + \directlua{% + sets[\luastringN{#1}] = Set.difference(sets[\luastringN{#2}], + sets[\luastringN{#3}]) + }% +} + + +\newcommand\luaSetPrint[1]{% + \directlua{tex.sprint(tostring(sets[\luastringN{#1}]))}% +} + +\newcommand\luaSetCardinal[1]{% + \directlua{tex.sprint(tostring(Set.cardinal(sets[\luastringN{#1}])))}% +} + +\newcommand\luaSetSubseteq[2]{% + \directlua{tex.sprint(tostring(Set.subseteq(sets[\luastringN{#1}],sets[\luastringN{#2}])))}% +} + +\newcommand\luaSetSubset[2]{% + \directlua{tex.sprint(tostring(Set.subset(sets[\luastringN{#1}],sets[\luastringN{#2}])))}% +} + +\newcommand\luaSetEqual[2]{% + \directlua{tex.sprint(tostring(Set.equal(sets[\luastringN{#1}],sets[\luastringN{#2}])))}% +} + +\newcommand\luaSetBelongsto[2]{% + \directlua{tex.sprint(tostring(Set.belongsto("#1",sets[\luastringN{#2}])))}% +} + +\endinput diff --git a/macros/luatex/latex/luaset/luaset.tex b/macros/luatex/latex/luaset/luaset.tex new file mode 100644 index 0000000000..5a1a08534a --- /dev/null +++ b/macros/luatex/latex/luaset/luaset.tex @@ -0,0 +1,230 @@ +\documentclass{article} +\usepackage{listings,color,booktabs,longtable,array,hyperref,multicol,framed} +\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} +\begin{document} +\title{The luaset Package in LaTeX} +\author{Chetan Shirore and Dr. Ajit Kumar} +\maketitle +\section{Introduction}\label{section:introduction} +The \verb|luaset| package is developed to define finite sets and perform operations on finite sets inside LaTeX documents. There is no particular environment in the package for performing set 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 the LuaLaTeX engine. The time required for performing set 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. The package is helps to perform set operations (union, intersection, difference, etcetera) in LaTeX documents. It may also save the users' efforts to copy sets from other software (which may not be in LaTeX compatible format) and to use them in a tex file. The package supports the nesting of commands for multiple operations. + +\section{Installation and License} + +The installation of the \verb|luaset| 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{luaset}| command in the preamble of the LaTeX document. The TeX file is to be compiled using the LuaLaTeX engine. + +The \verb|luaset| 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. Questions on \url{https://tex.stackexchange.com} inspired a small part of the development of this package. The content on this site is available under the \verb|CC BY-SA| license. It also loads the \verb|luamaths| package, which is available under the LaTeX Project Public License v1.3c or later. This package is loaded to use the standard mathematical functions and computations on real numbers while performing operations on sets. + +\subsection{Defining and Displaying Sets} +A set can be defined by using the \verb|\luaSetNew| command. +\begin{lstlisting} +\luaSetNew{name}{set} +\end{lstlisting} +The following commands define sets \( A \) and \(B \). +\begin{lstlisting} +\luaSetNew{A}{a,b,c,10,d,10,a,30} +\luaSetNew{B}{d,e,f,10,20} +\end{lstlisting} +The set can be displayed or printed by using the \verb|\luaSetPrint| command. +\begin{lstlisting} +\luaSetPrint{name of set} +\end{lstlisting} + For example, the following commands + \begin{lstlisting} +\(A = \luaSetPrint{A}\) \\ +\(B = \luaSetPrint{B}\) +\end{lstlisting} +output to +\begin{framed} +\noindent \(A = \{10, 30, a, b, c, d\}\) \\ +\(B = \{10, 20, d, e, f\}\) +\end{framed} +The standard mathematical functions can also be used. +\subsection{Commands in the luaset package} +Table \ref{tbl:opluaset} summarises commands in the \verb|luaset| package. +\begin{center} +\begin{longtable}{llm{5cm}} +\toprule +\multicolumn{1}{c}{\textcolor{blue}{Function}} & \multicolumn{1}{c}{\textcolor{blue}{Command Format}} & \multicolumn{1}{c}{\textcolor{blue}{Description}} \\ +\toprule +\begin{lstlisting} +\luaSetUnion +\end{lstlisting} & +\begin{lstlisting} +\luaSetUnion{set}{set1}{set2} +\end{lstlisting} & Defines the new set as a union of set1 and set2. \\ +\midrule +\begin{lstlisting} +\luaSetIntersection +\end{lstlisting} & +\begin{lstlisting} +\luaSetIntersection{set}{set1}{set2} +\end{lstlisting} & Defines the new set as an intersection of set1 and set2. \\ +\midrule +\begin{lstlisting} +\luaSetDifference +\end{lstlisting} & +\begin{lstlisting} +\luaSetDifference{set}{set1}{set2} +\end{lstlisting} & Defines the new set as a difference of set1 and set2. \\ +\midrule +\begin{lstlisting} +\luaSetCardinal +\end{lstlisting} & +\begin{lstlisting} +\luaSetCardinal{set} +\end{lstlisting} & Gives the cardinality of a set (number of elements). \\ +\midrule +\begin{lstlisting} +\luaSetBelongsto +\end{lstlisting} & +\begin{lstlisting} +\luaSetBelongsto{element}{set} +\end{lstlisting} & Returns true if an element is in a set; otherwise, it returns false.\\ +\midrule +\begin{lstlisting} +\luaSetSubseteq +\end{lstlisting} & +\begin{lstlisting} +\luaSetSubseteq{set1}{set2} +\end{lstlisting} & Returns true if set1 is a subset of set2; otherwise, it returns false. \\ +\midrule +\begin{lstlisting} +\luaSetSubset +\end{lstlisting} & +\begin{lstlisting} +\luaSetSubset{set1}{set2} +\end{lstlisting} & Returns true if set1 is a proper subset of set2; otherwise, it returns false. \\ +\midrule +\begin{lstlisting} +\luaSetEqual +\end{lstlisting} & +\begin{lstlisting} +\luaSetEqual{set1}{set2} +\end{lstlisting} & Returns true if set1 is equal to set2; otherwise, it returns false. \\ +\bottomrule +\caption{Commands in the luaset package} +\label{tbl:opluaset} +\end{longtable} +\end{center} +\subsection{Examples and Usage} +The latex document (Listing: \ref{code:illluaset}) uses various commands in the \verb|luaset| package. +\begin{lstlisting}[label={code:illluaset}, caption={LaTeX document with luaset package}] +\documentclass{article} +\usepackage{luaset,parskip} +\begin{document} +\luaSetNew{A}{a,b,c,\mathCos{0},d,10,a,30} +\luaSetNew{B}{d,e,f,10,20} +\luaSetUnion{C}{A}{B} +\luaSetIntersection{D}{A}{B} +\luaSetDifference{E}{A}{B} +\luaSetDifference{F}{B}{A} +\(A = \luaSetPrint{A}\) % printing set A + +\(B = \luaSetPrint{B}\) % printing set B + +\(C = A \cup B = \luaSetPrint{C}\) % printing set C + +\(D = A\cap B = \luaSetPrint{D}\) % printing set D + +\(E = A-B = \luaSetPrint{E}\) % printing set E + +\(F = B-A = \luaSetPrint{F}\) % printing set F + +The Cardinality of set \(A\) is \luaSetCardinal{A}. + +It is \luaSetSubseteq{A}{B} that \(A \subseteq B \). + +It is \luaSetSubseteq{A}{C} that \(A \subseteq C \). + +It is \luaSetSubset{A}{B} that \(A \subset B \). + +It is \luaSetSubset{A}{C} that \(A \subset C \). + +\luaSetIntersection{G}{C}{A} + +\(G = C \cap A = \luaSetPrint{G}\) % printing set G + +It is \luaSetEqual{A}{B} that \(A=B \). + +It is \luaSetEqual{G}{A} that \(G=A \). + +It is \luaSetBelongsto{z}{A} that \(z \in A \). + +It is \luaSetBelongsto{10}{A} that \(10 \in A \). + +\luaSetNew{S}{a,10,b,x,y,z,100,200} + +\(S = \luaSetPrint{S}\) % printing set S + + +\luaSetIntersection{H}{C}{S} +\luaSetUnion{I}{D}{S} + +\(H = C \cap S = \luaSetPrint{H}\) % printing set H + +\(I = D \cup S = \luaSetPrint{I}\) % printing set I +\end{document} +\end{lstlisting} +The latex document (Listing: \ref{code:illluaset}) generates the following output on the compilation. + +\begin{framed} + +\(A = \{10, 30, 1.0, a, b, c, d\}\) % printing set A + +\(B =\{10, 20, d, e, f\}\) % printing set B + +\(C = A \cup B = \{10, 20, 30, 1.0, a, b, c, d, e, f\}\) % printing set C + +\(D = A\cap B = \{10, d\}\) % printing set D + +\(E = A-B = \{30, 1.0, a, b, c\}\) % printing set E + +\(F = B-A = \{20, e, f\}\) % printing set F + +The Cardinality of set \(A\) is 7. + +It is false that \(A \subseteq B \). + +It is true that \(A \subseteq C \). + +It is false that \(A \subset B \). + +It is true that \(A \subset C \). + +\(G = C \cap A = \{10, 30, 1.0, a, b, c, d\}\) % printing set G + +It is false that \(A=B \). + +It is true that \(G=A \). + +It is false that \(z \in A \). + +It is true that \(10 \in A \). + +\(S = \{10, 100, 200, a, b, x, y, z\}\) % printing set S + +\(H = C \cap S = \{10, a, b\}\) % printing set H + +\(I = D \cup S = \{10, 100, 200, a, b, d, x, y, z\}\) % printing set I +\end{framed} + + +The luaset package can be modified or extended by adding custom Lua programs. Advanced users acquainted with Lua can do so. + +\end{document} |