texlive[60063] Master/texmf-dist: macrolist (25jul21)
commits+karl at tug.org
commits+karl at tug.org
Sun Jul 25 22:48:39 CEST 2021
Revision: 60063
http://tug.org/svn/texlive?view=revision&revision=60063
Author: karl
Date: 2021-07-25 22:48:38 +0200 (Sun, 25 Jul 2021)
Log Message:
-----------
macrolist (25jul21)
Modified Paths:
--------------
trunk/Master/texmf-dist/doc/latex/macrolist/README.md
trunk/Master/texmf-dist/doc/latex/macrolist/macrolist.pdf
trunk/Master/texmf-dist/source/latex/macrolist/macrolist.dtx
trunk/Master/texmf-dist/tex/latex/macrolist/macrolist.sty
Modified: trunk/Master/texmf-dist/doc/latex/macrolist/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/macrolist/README.md 2021-07-25 20:48:26 UTC (rev 60062)
+++ trunk/Master/texmf-dist/doc/latex/macrolist/README.md 2021-07-25 20:48:38 UTC (rev 60063)
@@ -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 at gmail.com>
>
Modified: trunk/Master/texmf-dist/doc/latex/macrolist/macrolist.pdf
===================================================================
(Binary files differ)
Modified: trunk/Master/texmf-dist/source/latex/macrolist/macrolist.dtx
===================================================================
--- trunk/Master/texmf-dist/source/latex/macrolist/macrolist.dtx 2021-07-25 20:48:26 UTC (rev 60062)
+++ trunk/Master/texmf-dist/source/latex/macrolist/macrolist.dtx 2021-07-25 20:48:38 UTC (rev 60063)
@@ -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,9 +56,8 @@
% \end{abstract}
%
% \section{Usage}
+% 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.
%
-% The scope of lists is always global. This seems to provide the most
-%
% \DescribeMacro{\newlist}
% To create a list, pass in |\newlist{listname}| to create a list with the name \textsf{listname}.
%
@@ -95,7 +94,51 @@
\csname macrolist at 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 at listindex{0}%
+ \macrolist at exists{#1}%
+ \def\macrolist at el{#2}%
+ \listforeach{#1}{\macrolist at listindexel}[\listsize{#1}][1]{%
+ \ifx\macrolist at el\macrolist at listindexel
+ \xdef\macrolist at listindex{\macrolist at index}%
+ \fi
+ }%
+ \macrolist at listindex%
+ \let\macrolist at 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 at listindex{0}%
+ \macrolist at exists{#1}%
+ \def\macrolist at el{#2}%
+ \listforeach{#1}{\macrolist at listindexel}[\listsize{#1}][1]{%
+ \ifx\macrolist at el\macrolist at listindexel
+ \xdef\macrolist at listindex{\macrolist at index}%
+ \fi
+ }%
+ \ifnum\macrolist at listindex>0\relax
+ #3%
+ \else
+ #4%
+ \fi
+}
+% \fi
+%
% \DescribeMacro{\listadd}
%
% To add something to the list \textsf{listname}, pass in |\listadd{listname}[position]{element}|, where \textsf{position} is an optional argument. If nothing is passed in for \textsf{position}, then by default \textsf{element} will be added to the end of the list.
@@ -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.
Modified: trunk/Master/texmf-dist/tex/latex/macrolist/macrolist.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/macrolist/macrolist.sty 2021-07-25 20:48:26 UTC (rev 60062)
+++ trunk/Master/texmf-dist/tex/latex/macrolist/macrolist.sty 2021-07-25 20:48:38 UTC (rev 60063)
@@ -15,7 +15,7 @@
%% version 2005/12/01 or later.
\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}
@@ -32,6 +32,33 @@
\macrolist at inbounds{#1}{#2}%
\csname macrolist at list@#1\the\numexpr #2\relax\endcsname%
}
+\newcommand{\listindexof}[2]{%
+ \def\macrolist at listindex{0}%
+ \macrolist at exists{#1}%
+ \def\macrolist at el{#2}%
+ \listforeach{#1}{\macrolist at listindexel}[\listsize{#1}][1]{%
+ \ifx\macrolist at el\macrolist at listindexel
+ \xdef\macrolist at listindex{\macrolist at index}%
+ \fi
+ }%
+ \macrolist at listindex%
+ \let\macrolist at listindex\relax%
+}
+\newcommand{\listcontains}[4]{%
+ \def\macrolist at listindex{0}%
+ \macrolist at exists{#1}%
+ \def\macrolist at el{#2}%
+ \listforeach{#1}{\macrolist at listindexel}[\listsize{#1}][1]{%
+ \ifx\macrolist at el\macrolist at listindexel
+ \xdef\macrolist at listindex{\macrolist at index}%
+ \fi
+ }%
+ \ifnum\macrolist at listindex>0\relax
+ #3%
+ \else
+ #4%
+ \fi
+}
\newcommand{\listadd}[1]{
\macrolist at exists{#1}
\def\macrolist at currlist{#1}
More information about the tex-live-commits
mailing list.