| 1 |
%%%============================================================================== |
| 2 |
% WinEdt pragmas |
| 3 |
% !Mode:: "TeX:EN" |
| 4 |
% Default Compile engines: |
| 5 |
% !TEX program = pdflatex |
| 6 |
% !PDFTeXify ext = --enable-etex --restrict-write18 |
| 7 |
% !PDFLaTeX ext = --enable-etex --restrict-write18 |
| 8 |
% !BIB program = biber |
| 9 |
%%%============================================================================== |
| 10 |
%% Copyright 2026-present by Alceu Frigeri |
| 11 |
%% |
| 12 |
%% This work may be distributed and/or modified under the conditions of |
| 13 |
%% |
| 14 |
%% * The [LaTeX Project Public License](http://www.latex-project.org/lppl.txt), |
| 15 |
%% version 1.3c (or later), and/or |
| 16 |
%% * The [GNU Affero General Public License](https://www.gnu.org/licenses/agpl-3.0.html), |
| 17 |
%% version 3 (or later) |
| 18 |
%% |
| 19 |
%% This work has the LPPL maintenance status *maintained*. |
| 20 |
%% |
| 21 |
%% The Current Maintainer of this work is Alceu Frigeri |
| 22 |
%% |
| 23 |
%% This is version {1.0} {2026/02/18} |
| 24 |
%% |
| 25 |
%% The list of files that compose this work can be found in the README.md file at |
| 26 |
%% https://ctan.org/pkg/tokgroupmark |
| 27 |
%% |
| 28 |
%%%============================================================================== |
| 29 |
\documentclass[10pt]{article} |
| 30 |
\RequirePackage[verbose,a4paper,marginparwidth=27.5mm,top=2.5cm,bottom=1.5cm,hmargin={40mm,20mm},marginparsep=2.5mm,columnsep=10mm,asymmetric]{geometry} |
| 31 |
\usepackage[T1]{fontenc} |
| 32 |
\usepackage[utf8]{inputenc} |
| 33 |
\usepackage{lmodern} |
| 34 |
\usepackage[infograb,silence]{codedescribe} |
| 35 |
\RequirePackage[inline]{enumitem} |
| 36 |
\SetEnumitemKey{miditemsep}{parsep=0ex,itemsep=0.4ex} |
| 37 |
|
| 38 |
\usepackage{tokgroupmark} |
| 39 |
|
| 40 |
%% if needed |
| 41 |
\RequirePackage[backend=biber]{biblatex} |
| 42 |
\addbibresource{tokgroupmark.bib} |
| 43 |
|
| 44 |
\newcodekey{groupmark} |
| 45 |
{ |
| 46 |
letter = {_}, |
| 47 |
texcs = [3]{groupmark_new }, |
| 48 |
emph = [3]{myMarkA, myMarkA_aftergroup,myMarkA_groupmark,myMarkB, myMarkB_aftergroup,myMarkB_groupmark}, |
| 49 |
keywd = [2]{l__mytest_tmpa_bool,l__mytest_tmpb_bool,l__mytest_tmpc_bool,mytest_show_bools}, |
| 50 |
codeprefix = {}, |
| 51 |
resultprefix = {}, |
| 52 |
} |
| 53 |
\RequirePackage[hidelinks,hypertexnames=false]{hyperref} |
| 54 |
|
| 55 |
\begin{document} |
| 56 |
\tstitle{ |
| 57 |
author={Alceu Frigeri\footnote{\tsverb{https://github.com/alceu-frigeri/tokgroupmark}}}, |
| 58 |
date={\tsdate}, |
| 59 |
title={The tokgroupmark Package\break Version \PkgInfo{tokgroupmark}{version}} |
| 60 |
} |
| 61 |
|
| 62 |
|
| 63 |
\begin{typesetabstract} |
| 64 |
This package aims at solving the problem of how to preserve some tokens beyond a variable number of nested groups. |
| 65 |
\end{typesetabstract} |
| 66 |
|
| 67 |
\tableofcontents |
| 68 |
|
| 69 |
\tsOn |
| 70 |
|
| 71 |
\section{Introduction} |
| 72 |
|
| 73 |
When it's necessary to preserve the value of some tokens beyond a local group, in simple cases, it's enough to use !:[code,or]{\group_insert_after:N,\aftergroup}. |
| 74 |
|
| 75 |
But, sometimes you don't have (or can't use) this information, see \cite{exchange}, for instance. For those cases, this package deploys one of the strategies presented and compared in \cite{xstacks}, based on !:{\aftergroup}. |
| 76 |
|
| 77 |
\section{Custom Group Mark Commands} |
| 78 |
|
| 79 |
\begin{codedescribe}{\groupmark_new:n} |
| 80 |
\begin{codesyntax} |
| 81 |
!!?{\groupmark_new:n}{mark-prefix} |
| 82 |
\end{codesyntax} |
| 83 |
This will globally create two commands (below), named after !:[marg]{mark-prefix}, to ``mark'' and ``restore'' a token up to that ``mark''. |
| 84 |
\begin{tsremark} |
| 85 |
Internally, an unique integer will be created to track the group mark. |
| 86 |
\end{tsremark} |
| 87 |
\begin{tsremark} |
| 88 |
An error will be raised if !:[marg]{mark-prefix} is already used. |
| 89 |
\end{tsremark} |
| 90 |
\end{codedescribe} |
| 91 |
|
| 92 |
\begin{codedescribe}{\<mark-prefix>_groupmark:,\<mark-prefix>_aftergroup:N} |
| 93 |
\begin{codesyntax}% |
| 94 |
!!?{\<mark-prefix>_groupmark:}{} |
| 95 |
!!?{\<mark-prefix>_aftergroup:N}{token} |
| 96 |
\end{codesyntax} |
| 97 |
The !:{\<mark-prefix>_groupmark:} will save, local assignment, the current group level, so that, when using !:{\<mark-prefix>_aftergroup:N} the token will be restored once the same group level is reached once again (similar to !:{\aftergroup}, but going beyond a single group). |
| 98 |
|
| 99 |
\begin{tsremark} |
| 100 |
It is possible to have multiple, nested marks, associated with the same set, see example of use. |
| 101 |
\end{tsremark} |
| 102 |
\begin{tsremark} |
| 103 |
If !:{\<mark-prefix>_aftergroup:N} is called at the same level (or above) of !:{\<mark-prefix>_groupmark:}, it will behave as a simple !:{\group_insert_after:N} |
| 104 |
\end{tsremark} |
| 105 |
|
| 106 |
|
| 107 |
\end{codedescribe} |
| 108 |
|
| 109 |
|
| 110 |
\section{Examples of Use} |
| 111 |
In the following examples, two sets of mark commands will be used, !:[marg]{myMarkA,myMarkB}. |
| 112 |
|
| 113 |
\begin{codestore}[grpmark] |
| 114 |
\ExplSyntaxOn |
| 115 |
% Just a set of booleans for testing |
| 116 |
\bool_new:N \l__mytest_tmpa_bool |
| 117 |
\bool_new:N \l__mytest_tmpb_bool |
| 118 |
\bool_new:N \l__mytest_tmpc_bool |
| 119 |
\cs_new:Npn \mytest_show_bools:n #1 |
| 120 |
{ \underline{#1:}\par |
| 121 |
\bool_if:NTF \l__mytest_tmpa_bool {{\color{red}a~true}}{a~false} ~-~ |
| 122 |
\bool_if:NTF \l__mytest_tmpb_bool {{\color{red}b~true}}{b~false} ~-~ |
| 123 |
\bool_if:NTF \l__mytest_tmpc_bool {{\color{red}c~true}}{c~false} \par |
| 124 |
} |
| 125 |
|
| 126 |
\groupmark_new:n {myMarkA} |
| 127 |
\groupmark_new:n {myMarkB} |
| 128 |
\ExplSyntaxOff |
| 129 |
\end{codestore} |
| 130 |
|
| 131 |
\tscode*[groupmark]{grpmark} |
| 132 |
\tsexec{grpmark} |
| 133 |
|
| 134 |
\subsection{Trivial Case, Single Mark} |
| 135 |
Note that, despite the group level at which the booleans were saved, they are all restored at the same group level, \emph{T3} in the example below. |
| 136 |
\begin{codestore}[grpmark] |
| 137 |
\ExplSyntaxOn |
| 138 |
\group_begin: |
| 139 |
\myMarkA_groupmark: |
| 140 |
{{ \myMarkA_aftergroup:N \bool_set_true:N |
| 141 |
\myMarkA_aftergroup:N \l__mytest_tmpa_bool |
| 142 |
{ |
| 143 |
\myMarkB_groupmark: %dummy, not used... |
| 144 |
{{ \myMarkA_aftergroup:N \bool_set_true:N |
| 145 |
\myMarkA_aftergroup:N \l__mytest_tmpb_bool |
| 146 |
\mytest_show_bools:n {T1} |
| 147 |
}} |
| 148 |
\mytest_show_bools:n {T2} |
| 149 |
} |
| 150 |
}} |
| 151 |
\mytest_show_bools:n {T3} |
| 152 |
\group_end: |
| 153 |
\ExplSyntaxOff |
| 154 |
\end{codestore} |
| 155 |
|
| 156 |
\tsdemo[groupmark]{grpmark}[2] |
| 157 |
|
| 158 |
\subsection{Multiple Marks, Single Command Set} |
| 159 |
Note that !:{\myMarkA_groupmark:} is called twice in the example below, effectively defining two, nested, restoring points. |
| 160 |
\begin{codestore}[grpmark] |
| 161 |
\ExplSyntaxOn |
| 162 |
\group_begin: |
| 163 |
\myMarkA_groupmark: |
| 164 |
{{ \myMarkA_aftergroup:N \bool_set_true:N |
| 165 |
\myMarkA_aftergroup:N \l__mytest_tmpa_bool |
| 166 |
{ |
| 167 |
\myMarkA_groupmark: %second call ! |
| 168 |
{{ \myMarkA_aftergroup:N \bool_set_true:N |
| 169 |
\myMarkA_aftergroup:N \l__mytest_tmpb_bool |
| 170 |
\mytest_show_bools:n {T1} |
| 171 |
}} |
| 172 |
\mytest_show_bools:n {T2} |
| 173 |
} |
| 174 |
}} |
| 175 |
\mytest_show_bools:n {T3} |
| 176 |
\group_end: |
| 177 |
\ExplSyntaxOff |
| 178 |
\end{codestore} |
| 179 |
|
| 180 |
\tsdemo[groupmark]{grpmark}[3] |
| 181 |
|
| 182 |
\newpage |
| 183 |
\subsection{Multiple Command Sets} |
| 184 |
This variant is less prone to errors than the previous one, when setting various, nested, restoring points. |
| 185 |
\begin{codestore}[grpmark] |
| 186 |
\ExplSyntaxOn |
| 187 |
\group_begin: |
| 188 |
\myMarkA_groupmark: |
| 189 |
{{ \myMarkA_aftergroup:N \bool_set_true:N |
| 190 |
\myMarkA_aftergroup:N \l__mytest_tmpa_bool |
| 191 |
{ |
| 192 |
\myMarkB_groupmark: |
| 193 |
{{ \myMarkB_aftergroup:N \bool_set_true:N |
| 194 |
\myMarkB_aftergroup:N \l__mytest_tmpb_bool |
| 195 |
\mytest_show_bools:n {T1} |
| 196 |
}} |
| 197 |
\mytest_show_bools:n {T2} |
| 198 |
} |
| 199 |
}} |
| 200 |
\mytest_show_bools:n {T3} |
| 201 |
\group_end: |
| 202 |
\ExplSyntaxOff |
| 203 |
\end{codestore} |
| 204 |
|
| 205 |
\tsdemo[groupmark]{grpmark}[4] |
| 206 |
|
| 207 |
|
| 208 |
%% if needed |
| 209 |
\printbibliography |
| 210 |
|
| 211 |
\end{document} |