summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/macrolist
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-07-26 03:01:05 +0000
committerNorbert Preining <norbert@preining.info>2021-07-26 03:01:05 +0000
commit84465d50d746dfed1bfbe7bb5065279665fa87de (patch)
treeda55fef72f0ee348f2d7d0cfdde6a7b4aa9fa263 /macros/latex/contrib/macrolist
parent70e05e80042e1e0b40202c65384883b446f03654 (diff)
CTAN sync 202107260301
Diffstat (limited to 'macros/latex/contrib/macrolist')
-rw-r--r--macros/latex/contrib/macrolist/README.md2
-rw-r--r--macros/latex/contrib/macrolist/macrolist.dtx53
-rw-r--r--macros/latex/contrib/macrolist/macrolist.pdfbin184302 -> 192607 bytes
3 files changed, 51 insertions, 4 deletions
diff --git a/macros/latex/contrib/macrolist/README.md b/macros/latex/contrib/macrolist/README.md
index 8eff3b4f96..ea16d986ea 100644
--- a/macros/latex/contrib/macrolist/README.md
+++ b/macros/latex/contrib/macrolist/README.md
@@ -1,4 +1,4 @@
-# The LaTeX package macrolist - version 1.1.1 (2021/07/23)
+# The LaTeX package macrolist - version 1.2.0 (2021/07/23)
> Copyright (C) 2021 Dennis Chen <proofprogram@gmail.com>
>
diff --git a/macros/latex/contrib/macrolist/macrolist.dtx b/macros/latex/contrib/macrolist/macrolist.dtx
index 3ccbc85edc..382faf2930 100644
--- a/macros/latex/contrib/macrolist/macrolist.dtx
+++ b/macros/latex/contrib/macrolist/macrolist.dtx
@@ -16,7 +16,7 @@
%<*package>
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{macrolist}[2021/07/23 v1.1.1 Create lists of macros and perform operations on them]
+\ProvidesPackage{macrolist}[2021/07/23 v1.2.0 Create lists of macros and perform operations on them]
\RequirePackage{pgffor}
%</package>
@@ -56,8 +56,7 @@
% \end{abstract}
%
% \section{Usage}
-%
-% The scope of lists is always global. This seems to provide the most
+% The scope of lists is always global. This provides the most consistency and functionality for developers in places that are usually local (part of a group), such as environments and loops.
%
% \DescribeMacro{\newlist}
% To create a list, pass in |\newlist{listname}| to create a list with the name \textsf{listname}.
@@ -95,6 +94,50 @@
\csname macrolist@list@#1\the\numexpr #2\relax\endcsname%
}
% \fi
+% \changes{v1.2.0}{2021/07/23}{Add listindexof and listcontains}
+% \DescribeMacro{\listindexof}
+%
+% This works similar to \textsf{indexof} in almost any ordinary programming language. Write |\listindexof{list}{element}| to get the index of where \textsf{element} first appears in \textsf{list}. If it never does, then the macro will expand to \textsf{0}.
+%
+% The command uses |\ifx| instead of |\if|; this means that if you have |\macro| as an element with the definition \textsf{this is a macro} (assuming that \textsf{this is a macro} is not an element itself), then |\listindexof{listname}{this is a macro}| will expand to \textsf{0}.
+%
+% Because of the implementation of this macro, it can't actually be parsed as a number. (See the `Limitations' section for more information.)
+% \iffalse
+\newcommand{\listindexof}[2]{%
+ \def\macrolist@listindex{0}%
+ \macrolist@exists{#1}%
+ \def\macrolist@el{#2}%
+ \listforeach{#1}{\macrolist@listindexel}[\listsize{#1}][1]{%
+ \ifx\macrolist@el\macrolist@listindexel
+ \xdef\macrolist@listindex{\macrolist@index}%
+ \fi
+ }%
+ \macrolist@listindex%
+ \let\macrolist@listindex\relax%
+}
+% \fi
+%
+% \DescribeMacro{\listcontains}
+%
+% Writing |\listcontains{listname}{element}{true branch}{false branch}| checks whether list \textsf{listname} contains \textsf{element}, executing \textsf{true branch} if it does and \textsf{false branch} if it does not.
+%
+% \iffalse
+\newcommand{\listcontains}[4]{%
+ \def\macrolist@listindex{0}%
+ \macrolist@exists{#1}%
+ \def\macrolist@el{#2}%
+ \listforeach{#1}{\macrolist@listindexel}[\listsize{#1}][1]{%
+ \ifx\macrolist@el\macrolist@listindexel
+ \xdef\macrolist@listindex{\macrolist@index}%
+ \fi
+ }%
+ \ifnum\macrolist@listindex>0\relax
+ #3%
+ \else
+ #4%
+ \fi
+}
+% \fi
%
% \DescribeMacro{\listadd}
%
@@ -299,6 +342,10 @@
%\end{document}
% \end{verbatim}
%
+% \section{Limitations}
+%
+% The |\listindexof| macro cannot be parsed as a number. This is because we have to compare each element of the list to the passed in element and requires storing the index in a macro, which requires some unexpandable macros. (This is why we do not directly use |\listindexof| when defining |\listcontains|.)
+%
% \section{Implementation details}
%
% All internal macros are namespaced to prevent package conflicts.
diff --git a/macros/latex/contrib/macrolist/macrolist.pdf b/macros/latex/contrib/macrolist/macrolist.pdf
index 94986e435d..2ee450e2bc 100644
--- a/macros/latex/contrib/macrolist/macrolist.pdf
+++ b/macros/latex/contrib/macrolist/macrolist.pdf
Binary files differ