texlive[64231] Master/texmf-dist: hereapplies (29aug22)

commits+karl at tug.org commits+karl at tug.org
Mon Aug 29 22:02:26 CEST 2022


Revision: 64231
          http://tug.org/svn/texlive?view=revision&revision=64231
Author:   karl
Date:     2022-08-29 22:02:26 +0200 (Mon, 29 Aug 2022)
Log Message:
-----------
hereapplies (29aug22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/hereapplies/ChangeLog.md
    trunk/Master/texmf-dist/doc/latex/hereapplies/README.md
    trunk/Master/texmf-dist/doc/latex/hereapplies/hereapplies-example.pdf
    trunk/Master/texmf-dist/doc/latex/hereapplies/hereapplies-example.tex
    trunk/Master/texmf-dist/doc/latex/hereapplies/lyx-module/hereapplies-example.lyx
    trunk/Master/texmf-dist/doc/latex/hereapplies/package.json
    trunk/Master/texmf-dist/tex/latex/hereapplies/hereapplies.sty

Modified: trunk/Master/texmf-dist/doc/latex/hereapplies/ChangeLog.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/hereapplies/ChangeLog.md	2022-08-29 20:01:55 UTC (rev 64230)
+++ trunk/Master/texmf-dist/doc/latex/hereapplies/ChangeLog.md	2022-08-29 20:02:26 UTC (rev 64231)
@@ -2,6 +2,18 @@
 ==========
 
 
+## 0.7.0 (2022-08-29)
+
+Changes:
+
+* All restrictions have been lifted concerning the characters that are allowed
+  in the identifiers passed to `\hereapplies` and `\whereapplies`; leading and
+  trailing spaces from now on will be trimmed
+* I/O operations now rely on one auxiliary file only
+* Code review
+* Documentation
+
+
 ## 0.6.0 (2022-08-23)
 
 Changes:

Modified: trunk/Master/texmf-dist/doc/latex/hereapplies/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/hereapplies/README.md	2022-08-29 20:01:55 UTC (rev 64230)
+++ trunk/Master/texmf-dist/doc/latex/hereapplies/README.md	2022-08-29 20:02:26 UTC (rev 64231)
@@ -7,28 +7,28 @@
 Overview
 --------
 
-**Here Applies** is a LaTeX package that allows to create groups of labels and
+**Here Applies** is a LaTeX package that allows to collect groups of labels and
 reference them altogether. It can be used for creating informal glossaries that
 cross-link concepts to their applications, or simply mentioning multiple pages
 that share something in common.
 
-The package offers two macros: `\hereapplies` and `\whereapplies` (plus their
+The package offers two commands: `\hereapplies` and `\whereapplies` (plus their
 “starred” versions `\hereapplies*` and `\whereapplies*`). In both cases an
 identifier is passed as argument – and this can be any string invented in the
-moment, as long as it contains only letters (`\hereapplies` additionally
-supports more than one identifier in the form of a comma-separated list).
+moment (`\hereapplies` additionally supports more than one identifier in the
+form of a comma-separated list).
 
 Every time `\hereapplies` is invoked with known identifiers, the document is
 made aware that the place shares some kind of connection with other places in
 which the same identifiers were used. And so, every time the `\whereapplies`
-macro is invoked with a known identifier, all the occurrences of the latter
+command is invoked with a known identifier, all the occurrences of the latter
 within the entire document will be printed in the form of a linkable page list
 (e.g. “pp. 1, 5, 8–9, 14–20…”).
 
 As `\hereapplies` is designed to be invoked in the middle of a chapter or a
-section, and that location must be made linkable, the `\phantomsection` macro
-is invoked by default before a label is added. To avoid calling
-`\phantomsection`, the “starred” macro `\hereapplies*` is available.
+section and that location must be made linkable, the `\phantomsection`
+directive is invoked by default before a label is added. To avoid calling
+`\phantomsection`, the “starred” command `\hereapplies*` is available.
 
 Finally, like `\whereapplies` resembles a pluralizable version of `\pageref`,
 its “starred” version `\whereapplies*` will resemble a pluralizable version of
@@ -62,19 +62,19 @@
 This is concept two. To find this concept applied, please
 see \whereapplies{conceptTwo}.\newpage
 
-\hereapplies{conceptOne}This is page \thepage. As you can see, ``concept
-one'' applies here.\newpage
+\hereapplies{conceptOne} This is page \thepage. As you can see,
+``concept one'' applies here.\newpage
 
-\hereapplies{conceptTwo}This is page \thepage. As you can see, ``concept
-two'' applies here.\newpage
+\hereapplies{conceptTwo} This is page \thepage. As you can see,
+``concept two'' applies here.\newpage
 
-\hereapplies{conceptOne,conceptTwo}This is page \thepage. As you
+\hereapplies{conceptOne, conceptTwo} This is page \thepage. As you
 can see, both ``concept one'' and ``concept two'' apply here.\newpage
 
-\hereapplies{conceptTwo}This is page \thepage. As you can see, ``concept
-two'' applies here.\newpage
+\hereapplies{conceptTwo} This is page \thepage. As you can see,
+``concept two'' applies here.\newpage
 
-\hereapplies[myref]{conceptOne}This is page \thepage. As you can
+\hereapplies[myref]{conceptOne} This is page \thepage. As you can
 see, ``concept one'' applies here. This point in the document is
 labeled \texttt{myref}.
 
@@ -87,38 +87,44 @@
 A minimal tutorial
 ------------------
 
-### Macro `\hereapplies[label]{identifiers}`
+### Command `\hereapplies[label]{identifiers}`
 
-The `\hereapplies` macro notifies the document that one or more identifiers
+The `\hereapplies` command notifies the document that one or more identifiers
 apply to a particular point and adds a label to it.
 
 If the optional argument is passed the label created will be named accordingly,
-otherwise an opaque name will be assigned to it. This argument may contain only
-what is legal for `\pageref`.
+otherwise an opaque name will be chosen. This argument may contain only what is
+legal for `\pageref`.
 
-The `identifiers` argument must be a comma-separated list of identifiers. Each
-of these may contain only Latin letters and the "at" sign (`/^[A-Za-z@]+$/`).
-These strings will remain confined within the internal scope of the package and
-will not create conflicts with possible macros or labels of the same names.
+The `identifiers` argument must be a comma-separated list of identifiers
+(leading and trailing spaces around each member will be ignored). Each of these
+strings will remain confined within the internal scope of the package and will
+not create conflicts with possible macros or labels of the same names.
 
-The “starred” version of this macro (`\hereapplies*`) will not invoke the
-`\phantomsection` directive.
+After storing some internal values, `\hereapplies` will expand exactly to
 
+``` tex
+\phantomsection
+\label{...}
+```
 
-### Macro `\whereapplies{identifier}`
+Its “starred” version (`\hereapplies*`) will not invoke the `\phantomsection`
+directive.
 
-The `\whereapplies` macro prints all the occurrences of an identifier, in the
+
+### Command `\whereapplies{identifier}`
+
+The `\whereapplies` command prints all the occurrences of an identifier, in the
 form “p. …” or “pp. …” (with page range support).
 
-The `identifier` argument may contain only Latin letters and the "at" sign
-(`/^[A-Za-z@]+$/`). This string will remain confined within the internal scope
-of the package and will not create conflicts with possible macros or labels of
-the same name.
+The `identifier` argument will remain confined within the internal scope of the
+package and will not create conflicts with possible commands or labels of the
+same name. Leading and trailing spaces around this string will be ignored.
 
 If the same `identifier` is not passed to `\hereapplies` at least once
 throughout the document, `\whereapplies` will print “**??**”.
 
-The “starred” version of this macro (`\whereapplies*`) will use `\pageref*`
+The “starred” version of this command (`\whereapplies*`) will use `\pageref*`
 instead of `\pageref` for generating the page list.
 
 
@@ -140,7 +146,7 @@
 % English: `\ and\ `
 \gdef\halastdelimiter{\ und\ }
 % English: `,\ ` (exactly like in German -- leave it)
-% \gdef\hadelimiter{,\ }
+%\gdef\hadelimiter{,\ }
 ```
 
 will translate “pp. 2, 4 and 6” into “S. 2, 4 und 6”.

Modified: trunk/Master/texmf-dist/doc/latex/hereapplies/hereapplies-example.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/hereapplies/hereapplies-example.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/hereapplies/hereapplies-example.tex	2022-08-29 20:01:55 UTC (rev 64230)
+++ trunk/Master/texmf-dist/doc/latex/hereapplies/hereapplies-example.tex	2022-08-29 20:02:26 UTC (rev 64231)
@@ -16,20 +16,21 @@
 This is concept two. To find this concept applied, please
 see \whereapplies{conceptTwo}.\newpage
 
-\hereapplies{conceptOne}This is page \thepage. As you can see, ``concept
-one'' applies here.\newpage
+\hereapplies{conceptOne} This is page \thepage. As you can see,
+``concept one'' applies here.\newpage
 
-\hereapplies{conceptTwo}This is page \thepage. As you can see, ``concept
-two'' applies here.\newpage
+\hereapplies{conceptTwo} This is page \thepage. As you can see,
+``concept two'' applies here.\newpage
 
-\hereapplies{conceptOne,conceptTwo}This is page \thepage. As you
+\hereapplies{conceptOne, conceptTwo} This is page \thepage. As you
 can see, both ``concept one'' and ``concept two'' apply here.\newpage
 
-\hereapplies{conceptTwo}This is page \thepage. As you can see, ``concept
-two'' applies here.\newpage
+\hereapplies{conceptTwo} This is page \thepage. As you can see,
+``concept two'' applies here.\newpage
 
-\hereapplies[myref]{conceptOne}This is page \thepage. As you can
+\hereapplies[myref]{conceptOne} This is page \thepage. As you can
 see, ``concept one'' applies here. This point in the document is
 labeled \texttt{myref}.
 
 \end{document}
+

Modified: trunk/Master/texmf-dist/doc/latex/hereapplies/lyx-module/hereapplies-example.lyx
===================================================================
--- trunk/Master/texmf-dist/doc/latex/hereapplies/lyx-module/hereapplies-example.lyx	2022-08-29 20:01:55 UTC (rev 64230)
+++ trunk/Master/texmf-dist/doc/latex/hereapplies/lyx-module/hereapplies-example.lyx	2022-08-29 20:02:26 UTC (rev 64231)
@@ -106,6 +106,7 @@
 status open
 
 \begin_layout Plain Layout
+
 conceptOne
 \end_layout
 
@@ -121,6 +122,7 @@
 status open
 
 \begin_layout Plain Layout
+
 conceptTwo
 \end_layout
 
@@ -141,12 +143,13 @@
 status open
 
 \begin_layout Plain Layout
+
 conceptOne
 \end_layout
 
 \end_inset
 
-This is page 
+ This is page 
 \begin_inset ERT
 status collapsed
 
@@ -180,12 +183,13 @@
 status open
 
 \begin_layout Plain Layout
+
 conceptTwo
 \end_layout
 
 \end_inset
 
-This is page 
+ This is page 
 \begin_inset ERT
 status collapsed
 
@@ -219,12 +223,13 @@
 status open
 
 \begin_layout Plain Layout
-conceptOne,conceptTwo
+
+conceptOne, conceptTwo
 \end_layout
 
 \end_inset
 
-This is page 
+ This is page 
 \begin_inset ERT
 status collapsed
 
@@ -269,12 +274,13 @@
 status open
 
 \begin_layout Plain Layout
+
 conceptTwo
 \end_layout
 
 \end_inset
 
-This is page 
+ This is page 
 \begin_inset ERT
 status collapsed
 
@@ -308,10 +314,12 @@
 status open
 
 \begin_layout Plain Layout
+
 \begin_inset Argument 1
 status open
 
 \begin_layout Plain Layout
+
 myref
 \end_layout
 
@@ -322,7 +330,7 @@
 
 \end_inset
 
-This is page 
+ This is page 
 \begin_inset ERT
 status collapsed
 

Modified: trunk/Master/texmf-dist/doc/latex/hereapplies/package.json
===================================================================
--- trunk/Master/texmf-dist/doc/latex/hereapplies/package.json	2022-08-29 20:01:55 UTC (rev 64230)
+++ trunk/Master/texmf-dist/doc/latex/hereapplies/package.json	2022-08-29 20:02:26 UTC (rev 64231)
@@ -1,6 +1,6 @@
 {
 	"name": "hereapplies.sty",
-	"version": "0.6.0",
+	"version": "0.7.0",
 	"description": "A LaTeX package for referencing groups of pages that share something in common",
 	"homepage": "https://madmurphy.github.io/hereapplies.sty",
 	"author": "madmurphy",

Modified: trunk/Master/texmf-dist/tex/latex/hereapplies/hereapplies.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/hereapplies/hereapplies.sty	2022-08-29 20:01:55 UTC (rev 64230)
+++ trunk/Master/texmf-dist/tex/latex/hereapplies/hereapplies.sty	2022-08-29 20:02:26 UTC (rev 64231)
@@ -1,4 +1,4 @@
-%  -*- Mode: latex; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*-
+%  -*- Mode: latex; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*-
 %
 %
 % hereapplies.sty
@@ -8,7 +8,7 @@
 %
 % https://github.com/madmurphy/hereapplies.sty
 %
-% Version 0.6.0
+% Version 0.7.0
 %
 % Copyright (C) 2022 madmurphy <madmurphy333 at gmail.com>
 %
@@ -47,19 +47,19 @@
 %     This is concept two. To find this concept applied, please
 %     see \whereapplies{conceptTwo}.\newpage
 %
-%     \hereapplies{conceptOne}This is page \thepage. As you can see, ``concept
-%     one'' applies here.\newpage
+%     \hereapplies{conceptOne} This is page \thepage. As you can see,
+%     ``concept one'' applies here.\newpage
 %
-%     \hereapplies{conceptTwo}This is page \thepage. As you can see, ``concept
-%     two'' applies here.\newpage
+%     \hereapplies{conceptTwo} This is page \thepage. As you can see,
+%     ``concept two'' applies here.\newpage
 %
-%     \hereapplies{conceptOne,conceptTwo}This is page \thepage. As you
+%     \hereapplies{conceptOne, conceptTwo} This is page \thepage. As you
 %     can see, both ``concept one'' and ``concept two'' apply here.\newpage
 %
-%     \hereapplies{conceptTwo}This is page \thepage. As you can see, ``concept
-%     two'' applies here.\newpage
+%     \hereapplies{conceptTwo} This is page \thepage. As you can see,
+%     ``concept two'' applies here.\newpage
 %
-%     \hereapplies[myref]{conceptOne}This is page \thepage. As you can
+%     \hereapplies[myref]{conceptOne} This is page \thepage. As you can
 %     see, ``concept one'' applies here. This point in the document is
 %     labeled \texttt{myref}.
 %
@@ -66,7 +66,7 @@
 %     \end{document}
 %
 %
-\ProvidesPackage{hereapplies}[2022/08/23 Here Applies]
+\ProvidesPackage{hereapplies}[2022/08/29 Here Applies]
 \RequirePackage{hyperref}
 \RequirePackage{refcount}
 %
@@ -77,121 +77,210 @@
 %
 %
 % The abbreviation of one single page
-\providecommand{\hapage}{p.\ }
+\providecommand*{\hapage}{p.\ }
 % The abbreviation of two or more pages
-\providecommand{\hapages}{pp.\ }
+\providecommand*{\hapages}{pp.\ }
 % The delimiter between page numbers
-\providecommand{\hadelimiter}{,\ }
+\providecommand*{\hadelimiter}{,\ }
 % The delimiter before the last page number
-\providecommand{\halastdelimiter}{\ and\ }
+\providecommand*{\halastdelimiter}{\ and\ }
 %
 %
 %
+%         ABSTRACT UTILITIES
+%         ==================
+%
+% These macros are not strictly related to this package, but are required.
+%
+%
+% Macro: `\@ha at ifcomma text to check,\@then{if yes}{if no}`
+% *****************************************************************************
+%
+% Check if a string contains a comma
+%
+% This macro is mainly for internal purposes (but nothing forbids invoking it
+% directly). When invoked it checks whether a comma is present in `text to
+% check`, then expands to `if yes` or `if no` accordingly.
+
+% Please do not put curly brackets around the text to check. The comma at the
+% end of the text is mandatory.
+%
+\long\gdef\@ha at ifcomma#1,#2\@then#3#4{%
+    \if\relax\detokenize{#2}\relax#4\else#3\fi%
+}
+%
+%
+% Macro: `\ha at trim{text}`
+% *****************************************************************************
+%
+% Trim leading and trailing spaces from a string
+%
+% This macro is mainly for internal purposes (but nothing forbids invoking it
+% directly).
+%
+\begingroup
+% Temporarily change the categories of `<` and `>`, for trimming safely
+\catcode`\<=4\catcode`\>=3
+% Helper macro
+\long\gdef\@ha at trm< #1 >< #2 >< #3 >< #4 >< #5 >< #6 >< #7 >< #8 >< #9 >/{%
+    \ifcase\numexpr2#3#8\relax\or#2\or#7\or#5\or#1\fi%
+}
+% Usable macro
+\long\gdef\ha at trim#1{%
+    \@ha at trm< #1 >< #1>< - >< + >< ? ><#1 ><#1>< 0 >< 2 >< 1 >< 3 >< 2 >< ! >/%
+}
+\endgroup
+%
+%
+%
 %         PRIVATE ENVIRONMENT
 %         ===================
 %
+% These macros regulate the internal functioning of the package and should not
+% be invoked directly.
 %
-% Assign a unique number to each identifier
-\newcounter{@ha at identifier@counter}
-% Assign a unique number to each unnamed occurrence of an identifier
+%
+% Assign a unique number to each unlabeled occurrence of an identifier
 \newcounter{@ha at unlabeled@counter}
 %
 %
-% Macro `\@ha at makeoccurrencelist{hypermacro}{labels}`
+% Macro `\@ha at makepagelist{hypermacro}{labels}`
 % *****************************************************************************
 %
 % Generate the list of page numbers (with page range support)
 %
-% This macro is for internal purposes. When invoked, it scans the
+% This macro is for internal purposes only. When invoked, it scans the
 % comma-separated list of labels provided (`labels`), checks which labels refer
 % to duplicate page numbers and which page numbers can be grouped together, and
 % finally prints a list.
 %
-% The `hypermacro` argument is the macro from the `hyperref` package that will
-% process the label name. This should be either `T at pageref` -- equivalent to
-% `\pageref` -- or `@pagerefstar` -- equivalent to `\pageref*`.
+% The `hypermacro` argument is the macro (usually from the `hyperref` package)
+% that will process the label name.
 %
-% The `labels` must be a comma-separated list of labels.
+% The `labels` argument must be a comma-separated list of labels.
 %
-\newcommand{\@ha at makeoccurrencelist}[2]{%
-	% Reset the current page number
-	\def\@ha at tmp@@currp{-1}%
-	% Reset the current range offset
-	\def\@ha at tmp@@prangeoffs{-1}%
-	% Ensure no comma before the first page number
-	\def\@ha at tmp@@psep{}%
-	% Ensure no text before the last page number if it is also the first one
-	\def\@ha at tmp@@lastpsep{}%
-	% Iterate through the `labels` argument
-	\@for\@ha at tmp@@thislabel:=#2\do{%
-		% Store the page number associated with this label
-		\edef\@ha at tmp@@nextp{\getpagerefnumber{\@ha at tmp@@thislabel}}%
-		% Check that we are not on the same page as in the last iteration
-		\unless\ifnum\@ha at tmp@@currp=\@ha at tmp@@nextp%
-			% This is not the same page as in the last iteration
-			% Is this the first page in which this identifier appears?
-			\unless\ifnum\@ha at tmp@@currp=-1%
-				% This is not the first page in which this identifier appears
-				% Does this page follow immediately the previous label's page?
-				\ifnum\numexpr\@ha at tmp@@currp+1=\@ha at tmp@@nextp%
-					% This page follows immediately the previous label's page
-					% Are these the first contiguous pages that we encounter?
-					\ifnum\@ha at tmp@@prangeoffs=-1%
-						% These are the first contiguous pages we encounter
-						% Store the first page number of the pair
-						\edef\@ha at tmp@@prangeoffs{\@ha at tmp@@currp}%
-						% Store the first label of the pair
-						\edef\@ha at tmp@@currrangelbl{\@ha at tmp@@currlbl}%
-					\fi%
-				\else%
-					% This page is far from the previous label's page
-					% Was the previous page part of a contiguous range?
-					\ifnum\@ha at tmp@@prangeoffs=-1%
-						% The previous page was a standalone page
-						% Print "[, ]<p>"
-						{\@ha at tmp@@psep\csname
-							#1\endcsname{\@ha at tmp@@currlbl}}%
-					\else%
-						% The previous page was part of a contiguous range
-						% Print "[, ]<p--q>"
-						{\@ha at tmp@@psep\csname
-							#1\endcsname{\@ha at tmp@@currrangelbl}--\csname
-							#1\endcsname{\@ha at tmp@@currlbl}}%
-						% Reset the current range offset
-						\def\@ha at tmp@@prangeoffs{-1}%
-					\fi%
-					% Ensure a comma before the next page number
-					\let\@ha at tmp@@psep\hadelimiter%
-					% Ensure " and " before the last page number
-					\let\@ha at tmp@@lastpsep\halastdelimiter%
-				\fi%
-			\fi%
-			% Prepare the next page number
-			\edef\@ha at tmp@@currp{\@ha at tmp@@nextp}%
-			% Prepare the next label
-			\edef\@ha at tmp@@currlbl{\@ha at tmp@@thislabel}%
-		\fi%
-	}%
-	% Print the last page number
-	% Is there at least one page to print?
-	\unless\ifnum\@ha at tmp@@currp=-1%
-		% There is at least one page to print
-		% Was the previous page part of a contiguous range?
-		\ifnum\@ha at tmp@@prangeoffs=-1%
-			% The previous page was a standalone page
-			% Print "[ and ]<p>"
-			{\@ha at tmp@@lastpsep\csname #1\endcsname{\@ha at tmp@@currlbl}}%
-		\else%
-			% The previous page was part of a contiguous range
-			% Print "[ and ]<p--q>"
-			{\@ha at tmp@@lastpsep\csname
-				#1\endcsname{\@ha at tmp@@currrangelbl}--\csname
-				#1\endcsname{\@ha at tmp@@currlbl}}%
-		\fi%
-	\fi%
+\gdef\@ha at makepagelist#1#2{%
+    \begingroup%
+    % Reset the current page number
+    \def\@ha at tmp@@currp{-1}%
+    % Reset the current range offset
+    \def\@ha at tmp@@prangeoffs{-1}%
+    % Ensure no comma before the first page number
+    \def\@ha at tmp@@psep{}%
+    % Ensure no text before the last number if it is also the first one
+    \def\@ha at tmp@@lastpsep{}%
+    % Iterate through the `labels` argument
+    \@for\@ha at tmp@@thislabel:=#2\do{%
+        % Store the page number associated with this label
+        \edef\@ha at tmp@@nextp{\getpagerefnumber{\@ha at tmp@@thislabel}}%
+        % Check that we are not on the same page as in the last iteration
+        \ifnum\@ha at tmp@@currp=\@ha at tmp@@nextp\else%
+            % This is not the same page as in the last iteration
+            % Is this the first page in which this identifier appears?
+            \ifnum\@ha at tmp@@currp>-1%
+                % We have already met pages in which this identifiers appears
+                % Does this page follow immediately the previous page?
+                \ifnum\numexpr\@ha at tmp@@currp+1=\@ha at tmp@@nextp%
+                    % This page follows immediately the previous page
+                    % Are these the first two contiguous pages of the range?
+                    \ifnum\@ha at tmp@@prangeoffs=-1%
+                        % These are the first two contiguous pages of the range
+                        % Store the first page number of the pair
+                        \let\@ha at tmp@@prangeoffs\@ha at tmp@@currp%
+                        % Store the first label of the pair
+                        \let\@ha at tmp@@currrangelbl\@ha at tmp@@currlbl%
+                    \fi%
+                \else%
+                    % This page is far from the previous label's page
+                    % Was the previous page part of a contiguous range?
+                    \ifnum\@ha at tmp@@prangeoffs=-1%
+                        % The previous page was a standalone page
+                        % Print "[, ]<p>"
+                        {\@ha at tmp@@psep\csname
+                            #1\expandafter\endcsname%
+                            \expandafter{\@ha at tmp@@currlbl}}%
+                    \else%
+                        % The previous page was part of a contiguous range
+                        % Print "[, ]<p--q>"
+                        {\@ha at tmp@@psep\csname
+                            #1\expandafter\endcsname%
+                            \expandafter{\@ha at tmp@@currrangelbl}--\csname
+                            #1\expandafter\endcsname%
+                            \expandafter{\@ha at tmp@@currlbl}}%
+                        % Reset the current range offset
+                        \def\@ha at tmp@@prangeoffs{-1}%
+                    \fi%
+                    % Ensure a comma before the next page number
+                    \let\@ha at tmp@@psep\hadelimiter%
+                    % Ensure " and " before the last page number
+                    \let\@ha at tmp@@lastpsep\halastdelimiter%
+                \fi%
+            \fi%
+            % Prepare the next page number
+            \let\@ha at tmp@@currp\@ha at tmp@@nextp%
+            % Prepare the next label
+            \let\@ha at tmp@@currlbl\@ha at tmp@@thislabel%
+        \fi%
+    }%
+    % Print the last page number
+    % Is there at least one page to print?
+    \ifnum\@ha at tmp@@currp>-1%
+        % There is at least one page to print
+        % Was the previous page part of a contiguous range?
+        \ifnum\@ha at tmp@@prangeoffs=-1%
+            % The previous page was a standalone page
+            % Print "[ and ]<p>"
+            {\@ha at tmp@@lastpsep\csname
+                #1\expandafter\endcsname%
+                \expandafter{\@ha at tmp@@currlbl}}%
+        \else%
+            % The previous page was part of a contiguous range
+            % Print "[ and ]<p--q>"
+            {\@ha at tmp@@lastpsep\csname
+                #1\expandafter\endcsname%
+                \expandafter{\@ha at tmp@@currrangelbl}--\csname
+                #1\expandafter\endcsname%
+                \expandafter{\@ha at tmp@@currlbl}}%
+        \fi%
+    \fi%
+    \endgroup%
 }
 %
 %
+% Macro `\@ha at makeoutputstrings{identifier}{preamble}{labels}`
+% *****************************************************************************
+%
+% Generate the output strings of `\whereapplies` and `\whereapplies*`
+%
+% This macro is for internal purposes only. When invoked, it updates the two
+% macros `@ha at prop@@soutput at ...` and `@ha at prop@@doutput at ...`.
+%
+% The `identifier` argument remains confined within the internal scope of the
+% package and does not create conflicts with possible macros or labels of the
+% same name. Leading and trailing spaces around this string will **not** be
+% ignored.
+%
+% The `preamble` argument is the text that will be expanded before the page
+% list (usually "p." or "pp.").
+%
+% The `labels` argument must be a comma-separated list of labels.
+%
+\gdef\@ha at makeoutputstrings#1#2#3{%
+    % Write "p./pp. \pageref..." to the output
+    \expandafter\gdef\csname @ha at prop@@doutput@#1\endcsname{%
+        % `\T at pageref` is a synonym of `\pageref`
+        #2\@ha at makepagelist{T at pageref}{#3}%
+    }%
+    % Write "p./pp. \pageref*..." to the starred output
+    \expandafter\gdef\csname @ha at prop@@soutput@#1\endcsname{%
+        % `\@pagerefstar` is a synonym of `\pageref*`
+        #2\@ha at makepagelist{@pagerefstar}{#3}%
+    }%
+    % Make the list of labels available to the API (via `\get at hainfo`)
+    \expandafter\gdef\csname @ha at prop@@labels@#1\endcsname{#3}%
+}
+%
+%
 % Macro `\@ha at newidentifier{identifier}`
 % *****************************************************************************
 %
@@ -202,153 +291,170 @@
 % identifier. If the identifier was already initialized the macro will be no
 % op.
 %
-% The `identifier` argument may contain only Latin letters and the "at" sign
-% (`/^[A-Za-z@]+$/`). This string remains confined within the internal scope of
-% the package and does not create conflicts with possible macros or labels of
-% the same name.
+% The `identifier` argument remains confined within the internal scope of the
+% package and does not create conflicts with possible macros or labels of the
+% same name. Leading and trailing spaces around this string will **not** be
+% ignored.
 %
-\newcommand{\@ha at newidentifier}[1]{%
-	% Was this identifier already initialized?
-	\unless\ifcsname @ha at prop@@count@#1\endcsname%
-		% The identifier was never initialized
-		% Set the output to "??" - it will be updated by the .haN file
-		\expandafter\gdef\csname @ha at prop@@uoutput@#1\endcsname{\textbf{??}}%
-		% Set the starred output to "??" - it will be updated by the .haN file
-		\expandafter\gdef\csname @ha at prop@@soutput@#1\endcsname{\textbf{??}}%
-		% Use "p." for the preamble when there is only one occurrence
-		\global\expandafter\let\csname @ha at prop@@preamble@#1\endcsname\hapage%
-		% Increase the counter of identifiers
-		\stepcounter{@ha at identifier@counter}%
-		% Store the current value of the counter of identifiers
-		\expandafter\xdef\csname
-			@ha at prop@@count@#1\endcsname{\the at ha@identifier at counter}%
-		% Initialize the .haN file
-		% Previous versions had this line, which created unwanted whitespaces:
-		%\@starttoc{ha\csname @ha at prop@@count@#1\endcsname}%
-		% I am thankful to David Carlisle for the following replacement:
-		{\endlinechar=\m at ne\@starttoc{ha\csname @ha at prop@@count@#1\endcsname}}%
-		% Store all the occurrences when the document reaches the end
-		\AtEndDocument{%
-			% Make sure that there are occurrences
-			\ifcsname @ha at prop@@labels@#1\endcsname%
-				% There are occurrences
-				% Set the .haN file as output
-				\addtocontents{ha\csname @ha at prop@@count@#1\endcsname}{%
-					% Write "p./pp. \pageref..." to the output
-					\gdef\expandafter\protect\csname @ha at prop@@uoutput@#1\endcsname{%
-						% Preamble (either "p." or "pp.")
-						\csname @ha at prop@@preamble@#1\endcsname%
-						% `\T at pageref` is a synonym of `\pageref`
-						\expandafter\protect\csname
-							@ha at makeoccurrencelist\endcsname{T at pageref}{\csname
-								@ha at prop@@labels@#1\endcsname}%
-					}%
-					% Write "p./pp. \pageref*..." to the starred output
-					\gdef\expandafter\protect\csname @ha at prop@@soutput@#1\endcsname{%
-						% Preamble (either "p." or "pp.")
-						\csname @ha at prop@@preamble@#1\endcsname%
-						% `\@pagerefstar` is a synonym of `\pageref*`
-						\expandafter\protect\csname
-							@ha at makeoccurrencelist\endcsname{@pagerefstar}{\csname
-								@ha at prop@@labels@#1\endcsname}%
-					}%
-				}%
-			\fi%
-		}%
-	\fi%
+\gdef\@ha at newidentifier#1{%
+    % Was this identifier already initialized?
+    \ifcsname @ha at iter@@preamble@#1\endcsname\else%
+        % The identifier was never initialized
+        % Was the .hax input already initialized during this run?
+        \ifdefined\@ha at commons@@haxcontent\else%
+            % The .hax input was never initialized
+            % Previous versions created unwanted whitespaces; I am thankful to
+            % David Carlisle for suggesting `\endlinechar=\m at ne`
+            {\endlinechar=\m at ne\@starttoc{hax}}%
+            % Initialize the content to export to the .hax file
+            \gdef\@ha at commons@@haxcontent{}%
+            % Export the content when the document reaches the end
+            \AtEndDocument{%
+                \addtocontents{hax}{\@ha at commons@@haxcontent}%
+            }%
+        \fi%
+        % Was a .hax file already exported during a previous run?
+        \ifcsname @ha at prop@@labels@#1\endcsname\else%
+            % This is the first run
+            % Set the output to "??" - to be updated by the .hax file
+            \expandafter\gdef\csname
+                @ha at prop@@doutput@#1\endcsname{\textbf{??}}%
+            % Set the starred output to "??" - to be updated by the .hax file
+            \expandafter\gdef\csname
+                @ha at prop@@soutput@#1\endcsname{\textbf{??}}%
+            % Set the list of labels to an empty value
+            \expandafter\gdef\csname @ha at prop@@labels@#1\endcsname{}%
+        \fi%
+        % Use "p." for the preamble when there is only one occurrence
+        \global\expandafter\let\csname @ha at iter@@preamble@#1\endcsname\hapage%
+        % Generate the output strings
+        \g at addto@macro\@ha at commons@@haxcontent{%
+            % Make sure that there are occurrences
+            \ifcsname @ha at iter@@labels@#1\endcsname%
+                % There are occurrences
+                % Generate the output strings
+                \protect\@ha at makeoutputstrings{#1}{\csname
+                    @ha at iter@@preamble@#1\endcsname}{\csname
+                    @ha at iter@@labels@#1\endcsname}%
+            \fi%
+        }%
+    \fi%
 }
 %
 %
-% Macro: `\@ha at getpropat{field}{identifier}`
-% *****************************************************************************
 %
-% Get the value of an identifier's property
+%         LIBRARY ENVIRONMENT
+%         ===================
 %
-% This macro is for internal purposes (but nothing forbids invoking it
-% directly). If the identifier was never initialized the macro will initialize
-% it.
+% These macros are not directly available to the user, but are callable by
+% other packages, if needed.
 %
-% Possible values for the `field` argument are: `count`, `labels`, `preamble`,
-% `soutput`, `uoutput`.
 %
-% The `identifier` argument may contain only Latin letters and the "at" sign
-% (`/^[A-Za-z@]+$/`). This string remains confined within the internal scope of
-% the package and does not create conflicts with possible macros or labels of
-% the same name.
+% Macro: `\starred at labeled@hereapplies{label}{identifiers}`
+% *****************************************************************************
 %
-\newcommand{\@ha at getpropat}[2]{%
-	% Make sure that the identifier is initialized
-	\@ha at newidentifier{#2}%
-	% Print the identifier's property
-	\csname @ha at prop@@#1@#2\endcsname%
+% Identical to `\hereapplies*`, but the two arguments are both mandatory
+%
+% This macro is mainly for internal purposes (but nothing forbids invoking it
+% directly). See the documentation of `\hereapplies` for more information.
+%
+\newcommand*{\starred at labeled@hereapplies}[2]{%
+    \begingroup%
+    % Assign a label to this occurrence
+    \label{#1}%
+    % Iterate through the comma-separated list `identifiers`
+    \@for\@ha at tmp@@litem:=#2\do{%
+        % Remove trailing and leading spaces
+        \edef\@ha at tmp@@id{\expandafter\ha at trim\expandafter{\@ha at tmp@@litem}}%
+        % Make sure that the identifier is initialized
+        \expandafter\@ha at newidentifier\expandafter{\@ha at tmp@@id}%
+        % Is this the first time this identifier is mentioned?
+        \ifcsname @ha at iter@@labels@\@ha at tmp@@id\endcsname%
+            % This is *not* the first time this identifier is mentioned
+            % Add this label to the list
+            \expandafter\g at addto@macro\csname
+                @ha at iter@@labels@\@ha at tmp@@id\endcsname{,#1}%
+            % Use "pp." for the preamble when there are multiple occurrences
+            \global\expandafter\let\csname
+                @ha at iter@@preamble@\@ha at tmp@@id\endcsname\hapages%
+        \else%
+            % This is the first time this identifier is mentioned
+            % Set up the list with this label as value
+            \expandafter\gdef\csname
+                @ha at iter@@labels@\@ha at tmp@@id\endcsname{#1}%
+        \fi%
+    }%
+    \endgroup%
 }
 %
 %
-% Macro: `\starred at labeled@hereapplies{label}{identifiers}`
+% Macro: `\starred at hereapplies[label]{identifiers}`
 % *****************************************************************************
 %
-% Equivalent to `\hereapplies*`, but the two arguments are both mandatory
+% Identical to `\hereapplies*`
 %
-% This macro is for internal purposes (but nothing forbids invoking it
+% This macro is mainly for internal purposes (but nothing forbids invoking it
 % directly). See the documentation of `\hereapplies` for more information.
 %
-\newcommand{\starred at labeled@hereapplies}[2]{%
-	% Assign a label to this occurrence
-	\label{#1}%
-	% Iterate through the comma-separated list `identifiers`
-	\@for\@ha at tmp@@id:=#2\do{%
-		% Make sure that the identifier is initialized
-		{\edef\tmp{\noexpand\@ha at newidentifier{\@ha at tmp@@id}}\tmp}%
-		% Is this the first time this identifier is mentioned?
-		\ifcsname @ha at prop@@labels@\@ha at tmp@@id\endcsname%
-			% This is *not* the first time this identifier is mentioned
-			% Add this label to the list
-			\expandafter\g at addto@macro\csname
-				@ha at prop@@labels@\@ha at tmp@@id\endcsname{,#1}%
-			% Use "pp." for the preamble when there are multiple occurrences
-			\global\expandafter\let\csname
-				@ha at prop@@preamble@\@ha at tmp@@id\endcsname\hapages%
-		\else%
-			% This is the first time this identifier is mentioned
-			% Set up the list with this label as value
-			\expandafter\gdef\csname
-				@ha at prop@@labels@\@ha at tmp@@id\endcsname{#1}%
-		\fi%
-	}%
+\newcommand*{\starred at hereapplies}[2][]{%
+    % Check whether the macro has been called with one or two arguments
+    \if\relax\detokenize{#1}\relax%
+        % The macro has been called with only one argument
+        % Assign a unique number to the unnamed occurrence
+        \stepcounter{@ha at unlabeled@counter}%
+        % Call `\starred at hereapplies` with an opaque label
+        {\edef\@ha at tmp@@mcall{\noexpand\starred at labeled@hereapplies{%
+            hereapplies:unnamed\the at ha@unlabeled at counter}{#2}%
+        }\@ha at tmp@@mcall}%
+    \else%
+        % The macro has been called with two arguments
+        % Call `\starred at labeled@hereapplies` with the same arguments
+        \starred at labeled@hereapplies{#1}{#2}%
+    \fi%
 }
 %
 %
-% Macro: `\starred at hereapplies[label]{identifiers}`
+% Macro: `\get at hainfo[property]{identifier}`
 % *****************************************************************************
 %
-% Equivalent to `\hereapplies*`
+% Get the value of an identifier's property
 %
-% This macro is for internal purposes (but nothing forbids invoking it
-% directly). See the documentation of `\hereapplies` for more information.
+% This macro is mainly for internal purposes (but nothing forbids invoking it
+% directly). If the identifier was never initialized the macro will initialize
+% it.
 %
-\newcommand{\starred at hereapplies}[2][]{%
-	% Check whether the macro has been called with one or two arguments
-	\if\relax\detokenize{#1}\relax%
-		% The macro has been called with only one argument
-		% Assign a unique number to the unnamed occurrence
-		\stepcounter{@ha at unlabeled@counter}%
-		% Call `\starred at hereapplies` with an opaque label
-		{\edef\tmp{\noexpand\starred at labeled@hereapplies{%
-			hereapplies:unnamed\the at ha@unlabeled at counter}{#2}%
-		}\tmp}%
-	\else%
-		% The macro has been called with two arguments
-		% Call `\starred at labeled@hereapplies` with the same arguments
-		\starred at labeled@hereapplies{#1}{#2}%
-	\fi%
+% Possible values for the `property` argument are: `doutput`, `labels` and
+% `soutput`. When omitted it defaults to `labels`.
+%
+% The `identifier` argument remains confined within the internal scope of the
+% package and does not create conflicts with possible macros or labels of the
+% same name. Leading and trailing spaces around this string will be ignored.
+%
+\newcommand*{\get at hainfo}[2][labels]{%
+    \begingroup%
+    % Trim leading and trailing spaces from the identifier
+    \edef\@ha at tmp@@id{\ha at trim{#2}}%
+    % Make sure that there are no commas
+    \expandafter\@ha at ifcomma\@ha at tmp@@id,\@then{%
+        \PackageError{hereapplies}{Comma detected in "#2"}{%
+            It is possible to query only one single identifier at a time.%
+        }%
+    }{}%
+    % Make sure that the identifier is initialized
+    \expandafter\@ha at newidentifier\expandafter{\@ha at tmp@@id}%
+    % Print the identifier's property
+    \csname @ha at prop@@#1@\@ha at tmp@@id\endcsname%
+    \endgroup%
 }
 %
 %
 %
-%         PUBLIC ENVIRONMENT
-%         ===================
+%         USER ENVIRONMENT
+%         ================
 %
+% These macros are directly available to the user.
 %
+%
 % Macro: `\hereapplies[label]{identifiers}`
 % *****************************************************************************
 %
@@ -356,20 +462,21 @@
 % and add a label to it
 %
 % If the optional argument is passed the label created will be named
-% accordingly, otherwise an opaque name will be assigned to it. This argument
-% may contain only what is legal for `\pageref`.
+% accordingly, otherwise an opaque name will be chosen. This argument may
+% contain only what is legal for `\pageref`.
 %
-% The `identifiers` argument must be a comma-separated list of identifiers.
-% Each of these may contain only Latin letters and the "at" sign (`@`). These
-% strings will remain confined within the internal scope of the package and
-% will not create conflicts with possible macros or labels of the same names.
+% The `identifiers` argument must be a comma-separated list of identifiers
+% (leading and trailing spaces around each member will be ignored). Each of
+% these strings will remain confined within the internal scope of the package
+% and will not create conflicts with possible macros or labels of the same
+% names.
 %
-% The starred version of this macro (`\hereapplies*`) does not invoke the
+% The starred version of this command (`\hereapplies*`) will not invoke the
 % `\phantomsection` directive.
 %
-\newcommand{\hereapplies}{%
-	% Check if a star is present in the invocation of the command
-	\@ifstar{\starred at hereapplies}{\phantomsection\relax\starred at hereapplies}%
+\newcommand*{\hereapplies}{%
+    % Check if a star is present in the invocation of the command
+    \@ifstar{\starred at hereapplies}{\phantomsection\starred at hereapplies}%
 }
 %
 %
@@ -377,21 +484,21 @@
 % *****************************************************************************
 %
 % Print all the occurrences of an identifier in the form "p. ..." or "pp. ..."
-% with page range support
+% (with page range support)
 %
-% The `identifier` argument may contain only Latin letters and the "at"
-% sign (`@`). This string will remain confined within the internal scope of the
-% package and will not create conflicts with possible macros or labels of the
-% same name.
+% The `identifier` argument remains confined within the internal scope of the
+% package and does not create conflicts with possible macros or labels of the
+% same name. Leading and trailing spaces around this string will be ignored.
 %
 % If the same `identifier` is not passed to `\hereapplies` at least once
 % throughout the document, `\whereapplies` will print "??".
 %
-% The starred version of this macro (`\whereapplies*`) will use `\pageref*`
+% The starred version of this command (`\whereapplies*`) will use `\pageref*`
 % instead of `\pageref` for generating the page list.
 %
-\newcommand{\whereapplies}{%
-	% Check if a star is present in the invocation of the command
-	\@ifstar{\@ha at getpropat{soutput}}{\@ha at getpropat{uoutput}}%
+\newcommand*{\whereapplies}{%
+    % Check if a star is present in the invocation of the command
+    \@ifstar{\get at hainfo[soutput]}{\get at hainfo[doutput]}%
 }%
+% EOF
 



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