summaryrefslogtreecommitdiff
path: root/macros/generic/tokcycle/tokcycle.tex
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2021-03-11 03:00:51 +0000
committerNorbert Preining <norbert@preining.info>2021-03-11 03:00:51 +0000
commit8379a45cf223651b1c06ebf5c680db900d83c6a5 (patch)
tree38feea3589200f62c13997bfe3954ce9359e83cb /macros/generic/tokcycle/tokcycle.tex
parentf808c98da8e34907b93b8b1c2ef473539b88c504 (diff)
CTAN sync 202103110300
Diffstat (limited to 'macros/generic/tokcycle/tokcycle.tex')
-rw-r--r--macros/generic/tokcycle/tokcycle.tex102
1 files changed, 74 insertions, 28 deletions
diff --git a/macros/generic/tokcycle/tokcycle.tex b/macros/generic/tokcycle/tokcycle.tex
index eeba320682..9aaec68b72 100644
--- a/macros/generic/tokcycle/tokcycle.tex
+++ b/macros/generic/tokcycle/tokcycle.tex
@@ -1,7 +1,7 @@
\def\tcname {tokcycle}
-\def\tcver {1.2}
+\def\tcver {1.3}
%
-\def\tcdate {2020/10/01}
+\def\tcdate {2021/03/10}
%
% Author : Steven B Segletes, Christian Tellechea (contributor)
% Maintainer : Steven B Segletes
@@ -22,8 +22,7 @@
\expandafter\the\expandafter\cytoks\expanded{#5}\endtokcycraw}
% ENVIRONMENT FORM
\long\def\tokencycle#1#2#3#4{\begingroup\let\endtokencycle\endtokcycraw
- \aftertokcycle{\the\cytoks\expandafter\endgroup\expandafter\tcenvscope
- \expandafter{\the\cytoks}}\tokcycraw{#1}{#2}{#3}{#4}}
+ \aftertokcycle{\the\cytoks\tcendgroup}\tokcycraw{#1}{#2}{#3}{#4}}
% XPRESS-INTERFACE MACRO FORM
\long\def\tokcyclexpress#1{\tokcycrawxpress#1\endtokcycraw}
% XPRESS-INTERFACE \expanded-ARGUMENT MACRO FORM
@@ -31,16 +30,16 @@
\expandafter\tokcycrawxpress\expanded{#1}\endtokcycraw}
% XPRESS-INTERFACE ENVIRONMENT FORM
\def\tokencyclexpress{\begingroup\let\endtokencyclexpress\endtokcycraw
- \aftertokcycle{\the\cytoks\expandafter\endgroup\expandafter\tcenvscope
- \expandafter{\the\cytoks}}\tokcycrawxpress}
+ \aftertokcycle{\the\cytoks\tcendgroup}\tokcycrawxpress}
% INITIALIZATION & INTERNAL TOOLS
+\def\tcendgroup{\expandafter\endgroup\expandafter\tcenvscope\expandafter{\the\cytoks}}
\def\tcenvscope{\cytoks}% CAN SET TO \global\cytoks TO OVERCOME SCOPE LIMITS
\edef\restorecatcode{\catcode\number`\@=\number\catcode`\@\relax}
\catcode`\@11
\newif\iftc@implicitgrp
\newif\if@argnext
\newtoks\tc@tok
-\newcount\tc@depth
+\newcount\tcdepth
\def\tc@gobble#1{}
\def\tc@deftok#1#2{\let#1= #2\empty}
\tc@deftok\tc@sptoken{ }
@@ -54,9 +53,8 @@
\long\def\tc@testxifx{\tc@earg\tctestifx}
\long\def\test@ifmacro#1{\tctestifcatnx#1\relax}
\def\tc@addtoks#1#2{\toks#1\expandafter{\the\toks#1#2}}
-\def\addtc@depth{\advance\tc@depth 1}
-\def\subtc@depth{\tc@depth=\numexpr\tc@depth-1\relax}
-\def\tc@resetifs{\activetokfalse\implicittokfalse\tc@implicitgrpfalse
+\def\add@tcdepth{\advance\tcdepth 1\relax}
+\def\sub@tcdepth{\advance\tcdepth-1\relax}\def\tc@resetifs{\activetokfalse\implicittokfalse\tc@implicitgrpfalse
\catSIXfalse\activecharfalse\activetokunexpandablefalse
\def\theactivespace{}}
\long\def\count@stringtoks#1{\tc@earg\count@toks{\string#1}}
@@ -79,18 +77,29 @@
\long\def\tokcycleenvironment#1#2#3#4#5{\expandafter\def\expandafter#1%
\expandafter{\expandafter\let\csname end\expandafter\tc@gobble
\string#1\endcsname\endtokcycraw\tokencycle{#2}{#3}{#4}{#5}}}
-\long\def\processtoks#1{\addtc@depth\@tokcycle#1\endtokcycraw }
+\long\def\xtokcycleenvironment#1#2#3#4#5#6#7{\expandafter\def\expandafter
+ #1\expandafter{\expandafter\let\csname end\expandafter\tc@gobble
+ \string#1\endcsname\endtokcycraw\begingroup
+ \long\def\tcafterenv####1{\tc@defx\tcendgroup{\tcendgroup####1}}%
+ \aftertokcycle{#7\the\cytoks\tcendgroup}#6\tokcycraw{#2}{#3}{#4}{#5}}}
+\long\def\processtoks#1{\@tokcycle#1\endtokcycraw}
\def\whennotprocessingparameter#1#2{\tctestifcon\if@argnext{\@argnextfalse\cytoks
\expandafter{\the\cytoks###1}}{\tctestifcon\ifcatSIX{\@argnexttrue}{#2}}}
+\long\def\truncategroup#1{\tctestifx{\endtokcycraw#1}{#1}{\truncategroup}}
+\long\def\truncatecycle#1{\tctestifx{\endtokcycraw#1}{\tctestifnum{\tcdepth=0}
+ {#1}{\truncatecycle}}{\tctestifx{\sub@tcdepth#1}{#1}
+ {\tctestifx{\exit@grouped#1}{#1}{}}\truncatecycle}}
+\long\def\truncategroupiftokis#1#2{\tctestifx{\tc@next#1}{\truncategroup}{#2}}
+\long\def\truncatecycleiftokis#1#2{\tctestifx{\tc@next#1}{\truncatecycle}{#2}}
% ESSENTIAL METHOD: STREAMING MACRO WITH TERMINATOR:
% \tokcycraw{<Char>}{<Group>}{<Macro>}{<Space>}<input-stream>\endtokcycraw
\long\def\tokcycraw#1#2#3#4{\def\@chrT##1{#1}\long\def\@grpT##1{#2}%
\long\def\@macT##1{#3}\def\@spcT##1{#4}\tokcycrawxpress}
% ENTRY POINT FOR XPRESS METHOD WITHOUT EXPLICIT ARGUMENTS
-\def\tokcycrawxpress{\cytoks{}\tc@depth=1\relax\@tokcycle}
+\def\tokcycrawxpress{\cytoks{}\tcdepth=0\relax\@tokcycle}
% CODE TO EXECUTE AT COMPLETION
\long\def\aftertokcycle#1{\def\@aftertokcycle{#1}}
-\def\endtokcycraw{\subtc@depth\tctestifnum{\tc@depth=0}{\@aftertokcycle}{}}
+\def\endtokcycraw{\tctestifnum{\tcdepth=0}{\@aftertokcycle}{}}
% LOOP ENTRY POINT
\def\@tokcycle{\tc@resetifs\futurelet\tc@next\detect@CANTabsorb}
\def\detect@CANTabsorb{\tctestifx{\tc@next\tc@sptoken}{\stringify\@@@@@@spcT}%
@@ -126,8 +135,8 @@
{\begingroup\catcode`#1=\active \xdef\@tmp{\scantokens{#1\noexpand}}\endgroup
\expandafter\implicitgrpfork\@tmp\@tokcycle}% ACTIVE CHAR \bgroup
}}
-\def\@@grpT#1{\tctestifcon\ifstripgrouping{\@grpT{#1}}%
- {\groupedcytoks{\@grpT{#1}}}\@tokcycle}
+\long\def\@@grpT#1{\add@tcdepth\tctestifcon{\ifstripgrouping}{%
+ \@grpT{#1}}{\groupedcytoks{\@grpT{#1}}}\sub@tcdepth\@tokcycle}
% \ COMMANDS (MACROS AND IMPLICITS)
\long\def\backslashcmds#1{%
\test@ifmacro#1{\tctestifcon\ifcatSIX{\implicittoktrue\@chrT#1}{\@macT#1}}%
@@ -146,12 +155,12 @@
\global\let\implicitsixtok\six@str\tc@tok{\implicitsixtok}}%
{\tc@tok\expandafter{\string#1}\tctestifnum{\number\catcode`#1=6}%
{}{\activetoktrue\implicittoktrue}}}
-% DIRECTIVES FOR HANDLING GROUPS RECURSIVELY; DEFINE tokcycle GROUPING CHARS
-\def\@defgroupedcytoks#1{\long\def\groupedcytoks##1{%
- \begingroup\cytoks{}##1\expandafter\endgroup\expandafter
+% DIRECTIVES FOR HANDLING GROUPED OUTPUT; DEFINE tokcycle GROUPING CHARS
+\long\def\groupedcytoks#1{\begingroup\cytoks{}#1\exit@grouped}
+\def\defineexit@grouped#1{\def\exit@grouped{\expandafter\endgroup\expandafter
\addcytoks\expandafter{\expandafter#1}}}
\def\settcGrouping#1{\def\@tmp##1{#1}\tc@defx\@@tmp{\@tmp{\the\cytoks}}%
- \tc@earg\@defgroupedcytoks{\@@tmp}}
+ \tc@earg\defineexit@grouped{\@@tmp}}
% FAUX TOKENIZATION OF COMMAND NAME (WHEN cat0 TOKEN HAS BEEN MADE cat12)
\def\csmk#1{\def\csaftermk{#1}\toks0{}\@csmkA}
\def\@csmkA{\futurelet\@tmp\@csmkB}
@@ -208,10 +217,10 @@
\endinput
EDIT HISTORY
-v1.0 2019/8/21
+v1.0 2019/08/21
- Initial release
-v1.1 2019/9/27
+v1.1 2019/09/27
- Introduced \ifactivechar, \ifactivetokunexpandable
- Tightened up consistent definition of implicit (to exclude primitives)
- Rewrote active token trapping logic, to differentiate between active
@@ -230,10 +239,47 @@ v1.12 2020/02/11
- Redefined \tc@defx and \tc@earg to omit #2 as part of definition
- Corrected \trapcatSIXb definition to account for revised \tc@earg definition.
-v1.2 2020/10/1
- -Added/fixed capability to handle active-implicit spaces. While the
- #1 passed to the \Spacedirective, in such a case, is an implicit
- space \tc@sptoken, the name of the active character from whence it
- originated in the input stream is stored as an explicit cat-12 token
- in the definition \theactivespace. The flags \implicittok and \activetok
- are both set true, and the \activechar flag is checked, as well. \ No newline at end of file
+v1.2 2020/10/01
+ - Added/fixed capability to handle active-implicit spaces. While the
+ #1 passed to the \Spacedirective, in such a case, is an implicit
+ space \tc@sptoken, the name of the active character from whence it
+ originated in the input stream is stored as an explicit cat-12 token
+ in the definition \theactivespace. The flags \implicittok and \activetok
+ are both set true, and the \activechar flag is checked, as well.
+
+v1.3 2021/03/09
+ - Introduced \xtokcycleenvironment, similar to \tokcycleenvironment, but
+ allows two additional arguments, defining the setup and trailing code
+ that will be run prior to the invocation and following conclusion of the
+ token cycle.
+ - Introduced \truncategroup, a directive to discard remaining tokens in the
+ current token-cycle group and close the group.
+ - Introduced \truncatecycle, a directive to discard remaining tokens in the
+ token-cycle input stream, but closing any open groups.
+ - Introduced \truncategroupiftokis{}{} to conditionally issue a \truncategroup
+ if the current token under consideration matches the 1st argument.
+ - Introduced \truncatecycleiftokis{}{} to conditionally issue a \truncatecycle
+ if the current token under consideration matches the 1st argument.
+ - Introduced \tcendgroup as a form of \endgroup that saves contents of
+ \cytoks upon group exit. Gives clarity to definitions of \tokencycle
+ and \tokencyclexpress environments. Available for general used.
+ - Fixed bug. Made \@@grpT \long, in the event that \par occurs inside a
+ group.
+ - Fixed bug. Added \relax to end of \add@tcdepth definition, the absence
+ of which had prevented timely update of the \tcdepth count.
+ - Documentation correction: improved explanation of implicit-cat-6 token
+ limitations. Likewise, added warning regarding active-implicit spaces.
+ - Documentation prepared with lmodern font, rather than default cm,
+ for reasons of better PDF hinting.
+ - Introduced \exit@grouped to the \groupedcytoks definition, for clarity and
+ ease of \expandafter.
+ - Reworked logic so that \tcdepth is associated with nested calls to the
+ Group directive, rather than with each invocation of \processtoks.
+ This primarily required redefinition of \@@grpT and its components.
+ - Changed name of \tc@depth to \tcdepth, as it may be a useful parameter for
+ users to check the token-cycle nesting depth. Therefore, also renamed
+ \subtc@depth to \sub@tcdepth, \addtc@depth to \add@tcdepth.
+ - Excised \sub@tcdepth from \endtokcycraw as part of new logic making
+ \tcdepth associated with the Group directive (also, outer token cycle
+ operates with depth = 0 rather than 1).
+ - Renamed \@defgroupedcytoks to \defineexit@grouped, to better match function.