Debian Codegraph @

texmf-dist/doc/latex/xstacks/xstacks.tex

raw
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.1} {2026/02/19}
24 %%
25 %% The list of files that compose this work can be found in the README.md file at
26 %% https://ctan.org/pkg/xstacks
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{midsep}{parsep=0ex,itemsep=0.4ex}
37
38 \usepackage{xstacks}
39
40 %% if needed
41 \RequirePackage[backend=biber]{biblatex}
42 \addbibresource{xstacks.bib}
43
44
45 \newcodekey{xstacks}
46 {
47 letter = {_},
48 texcs = [3]{xstacks_groupmark,xstacks_aftergroup,xstacks_cs_gset,xstacks_gset,
49 xstacks_gpush,xstacks_gput_right,xstacks_gput_left,xstacks_gpop,
50 xstacks_new_groupmark, groupmark_new, globalstack_csnew,
51 globalstack_new, globalstack_gpush, globalstack_gput_right, globalstack_gput_left, globalstack_gpop },
52 emph = [3]{myStack_gpush,myStack_gput_right,myStack_gput_left,myStack_gpop,
53 g_mytest_stack,myMark_int,myStack,MyMark, myMark_aftergroup,myMark_groupmark},
54 keywd = [2]{l__mytest_tmpa_bool,l__mytest_tmpb_bool,l__mytest_tmpc_bool,mytest_show_bools},
55 codeprefix = {},
56 resultprefix = {},
57 }
58 \RequirePackage[hidelinks,hypertexnames=false]{hyperref}
59
60 \begin{document}
61 \tsOn
62
63 \tstitle{
64 author={Alceu Frigeri\footnote{\tsfmt{\url{https://github.com/alceu-frigeri/xstacks}}}},
65 date={\tsdate},
66 title={The xstacks Package\break Version \PkgInfo{xstacks}{version}}
67 }
68
69
70 \begin{typesetabstract}
71
72 Originally this package aimed at solving the problem of preserving some tokens beyond a variable number of nested groups. Though, after some further testing and optimization, it became clear that (a) there was a lot of room for improvement (stacks) and (b) there was a better way to implement the aftergroup mechanism. As such, there are two new packages at CTAN, !:[pkg]{tokgroupmark}\cite{tokgroupmark} which implements (b) and !:[pkg]{tokglobalstack}\cite{tokglobalstack} which implements (a).
73
74 This package now loads these two, and set a series of aliases such that the ``user visible commands'' remain the same (but the user is invited to use one of the other two, instead of this). Moreover, the benchmark part got updated (see \ref{benchmark}).
75 \end{typesetabstract}
76
77 \tableofcontents
78
79 \section{Introduction}
80 (Original rationality behind this package) Sometimes one needs to preserve the value of some variables beyond a local group. In simple cases it's enough to use !:[code,or]{\group_insert_after:N,\aftergroup}, if you know how many nested groups you are in.
81
82 But, sometimes you don't have this information (see \cite{exchange}, for instance) in which case you have a few options:
83 \begin{itemize}[midsep]
84 \item use global variables, or
85 \item implement an after group strategy, as suggested by \citeauthor{exchange}, or
86 \item use a (global) stack.
87 \end{itemize}
88
89 The global variables way is, of course, the fastest (and easiest) if you don't have to worry about reentrant coding (like when you have nested groups inside an environment, which might get nested into itself).
90
91
92
93 \section{Simple mark point after group variant}\label{def:xstacks-aftergroup}
94
95 \begin{codedescribe}{\xstacks_groupmark:,\xstacks_aftergroup:N}
96 \begin{codesyntax}%
97 !!?{\xstacks_groupmark:}{}
98 !!?{\xstacks_aftergroup:N}{token}
99 \end{codesyntax}
100 These will use a single, internal, variable to `track' the target group level. Better said, upon calling !:{\xstacks_groupmark:} the current group will be saved (local assignment), so that, later on, !:{\xstacks_aftergroup:N} can be called from nested groups and !:[marg]{token} will be pushed into the marked group.
101 \end{codedescribe}
102 \begin{tsremark}
103 Since all assignments are local, it's possible to have multiple marks, for instance, one at group level 2, another at group level 5, so that anything saved with !:{\xstacks_aftergroup:N} on group level 6+ will be restored at group level 5... anything between level 3 until the other mark will be restored at level 2.
104 \end{tsremark}
105 \begin{tsremark}
106 if !:{\xstacks_aftergroup:N} is called at the same level (or above) of the mark, it will be equivalent to a simple !:{\group_insert_after:N}.
107 \end{tsremark}
108 \begin{tsremark}[\color{red}Attention:]
109 These should be considered \emph{deprecated}. They are less effective and flexible than !:{\groupmark_new:n} (from package !:[pkg]{tokgroupmark}).
110 \end{tsremark}
111
112 \section{Multiple mark points after group variant}\label{def:xstacks-aftergroup-int}
113
114 \begin{codedescribe}{\xstacks_groupmark:N,\xstacks_aftergroup:NN}
115 \begin{codesyntax}%
116 !!?{\xstacks_groupmark:N}{int-var}
117 !!?{\xstacks_aftergroup:NN}{int-var,token}
118 \end{codesyntax}
119 !:[marg]{int-var} must be an already declared integer variable, and will be used to mark/track a group level. That way it is possible to have multiple and independent return points. Otherwise it works exactly as the previous pair of commands. All assignments made to !:[marg]{int-var} are also local.
120 \end{codedescribe}
121 \begin{tsremark}[\color{red}Attention:]
122 These should be considered \emph{deprecated}. They are less effective and flexible than !:{\groupmark_new:n} (from package !:[pkg]{tokgroupmark}).
123 \end{tsremark}
124
125 \section{Custom Group Mark Commands}\label{def:groupmark-cmd}
126 This is defined in the package !:[pkg]{tokgroupmark}. The obvious distinction with the previous commands: this don't depend on the user reserving an integer for it (as in !:{\xstacks_groupmark:N}) and, unlike !:{\xstacks_groupmark:}, it allows for multiple sets (no commonalities).
127 \begin{codedescribe}{\groupmark_new:n}
128 \begin{codesyntax}
129 !!?{\groupmark_new:n}{mark-prefix}
130 \end{codesyntax}
131 This will globally create two commands (below), named after !:[marg]{mark-prefix}, to ``mark'' and ``restore'' a token up to that ``mark''.
132 \begin{tsremark}
133 Internally, an unique integer will be created to track the group mark.
134 \end{tsremark}
135 \begin{tsremark}
136 An error will be raised if !:[marg]{mark-prefix} is already used.
137 \end{tsremark}
138
139 \end{codedescribe}
140
141 \begin{codedescribe}{\<mark-prefix>_groupmark:,\<mark-prefix>_aftergroup:N}
142 \begin{codesyntax}%
143 !!?{\<mark-prefix>_groupmark:}{}
144 !!?{\<mark-prefix>_aftergroup:N}{token}
145 \end{codesyntax}
146 The !:{\<mark-prefix>_groupmark:} will ``mark'' (save) 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}).
147
148 \begin{tsremark}
149 !:{\<mark-prefix>_groupmark:} will save (local assignment) the current group in an (unique to the set) integer. Since the assignment is local, it is possible to have more than one mark associated with the same set.
150 \end{tsremark}
151
152 \end{codedescribe}
153
154
155 \newpage
156 \section{Stack command variant}\label{def:globalstack-cmd}
157
158 These are defined in the package !:[pkg]{tokglobalstack}.
159
160 \begin{codedescribe}{\globalstack_csnew:n}
161 \begin{codesyntax}%
162 !!?{\globalstack_csnew:n}{stack-prefix}
163 \end{codesyntax}
164 This will globally create a set of commands, named after !:[marg]{stack-prefix}, to push, put and pop items from a private global stack. All assignments to/from that stack will be global, and the stack itself will be unique to the command's set.
165 \begin{tsremark}[\color{red}Attention:]
166 This package defines !:{\xstacks_cs_gset:N,\xstacks_cs_gset:n} as aliases to this, for continuity, as it was originally defined in this package.
167 \end{tsremark}
168 \end{codedescribe}
169
170
171 \begin{codedescribe}{\<stack-prefix>_gpush:n,\<stack-prefix>_gput_right:n,\<stack-prefix>_gput_left:n,\<stack-prefix>_gpop:}
172 \begin{codesyntax}%
173 !!?{\<stack-prefix>_gpush:n}{tokens}
174 !!?{\<stack-prefix>_gput_right:n}{tokens}
175 !!?{\<stack-prefix>_gput_left:n}{tokens}
176 !!?{\<stack-prefix>_gput_gpop:}{}
177 \end{codesyntax}
178 The !:{\<stack-prefix>_gpush:n} will push !:[marg]{tokens} (can be any number of tokens) into a global, private, stack. !:{\<stack-prefix>_gput_right:n,\<stack-prefix>_gput_left:n} will amend tokens to it, and !:{\<stack-prefix>_gpop:}, as the name implies, will insert the top of the stack into the input stream. That way it is possible to have a very fine control of what, where and when the items are collected and used.
179 \end{codedescribe}
180
181
182 \section{Stack variable variant}\label{def:globalstack-var}
183 These are also defined in the package !:[pkg]{tokglobalstack}.
184
185 \begin{codedescribe}{\globalstack_gset:N,\globalstack_gpush:Nn,\globalstack_gput_right:Nn,\globalstack_gput_left:Nn,\globalstack_gpop:N}
186 \begin{codesyntax}%
187 !!?{\globalstack_gset:N}{stack-var}
188 !!?{\globalstack_gpush:Nn}{stack-var,tokens}
189 !!?{\globalstack_gput_right:Nn}{stack-var,tokens}
190 !!?{\globalstack_gput_left:Nn}{stack-var,tokens}
191 !!?{\globalstack_gpop:N}{stack-var}
192 \end{codesyntax}
193 !:{\globalstack_gset:N} will globally create a stack variable named !:[marg]{stack-var} (a specialized token list variable). Once created it is possible to push tokens into it (!:{\globalstack_gpush:Nn}), amend tokens to the top (!:{\globalstack_gput_right:Nn,\globalstack_gput_left:Nn}) and pop those tokens (!:{\globalstack_gpop:N}) into the input stream. All assignments being global.
194 \end{codedescribe}
195 \begin{tsremark}[\color{red}Attention:]
196 This package defines a series of aliases, for definition continuity, as follow:
197
198 \begin{tabular}{l@{ $\rightarrow$ }l}
199 !:{\xstacks_gset:N} & !:{\globalstack_new:N} \\
200 !:{\xstacks_gpush:Nn} & !:{\globalstack_gpush:Nn} \\
201 !:{\xstacks_gput_right:Nn} & !:{\globalstack_gput_right:Nn} \\
202 !:{\xstacks_gput_left:Nn} & !:{\globalstack_gput_left:Nn} \\
203 !:{\xstacks_gpop:N} & !:{\globalstack_gpop:N}
204 \end{tabular}
205
206 \end{tsremark}
207
208
209
210
211 \section{Benchmarks and Final Thoughts}\label{benchmark}
212 In the following, there is an exercise of \dots, better said, to evaluate the advantage/disadvantage of each approach, in an extreme case: multiple tokens, deeply nested groups.
213 The most effective strategy is the stack command variant (see \ref{def:globalstack-cmd}): \emph{40 ops} (\ref{globalstack-cmd}) versus \emph{160} (\ref{groupmark-cmd}). In lighter cases, taking in account that the stack variants are mostly `constant time' (they don't depend on how deep the grouping is, but just how many operations (push/pop) are needed), the difference diminishes, but the stack command variant still comes first (\emph{20 ops} versus \emph{35 ops}).
214
215 At the end, it's a case of flexibility, convenience and programming style versus performance. In case of the original problem, to save context past the end of a scope, the stack approach is the fastest, but the after group variant doesn't lags much behind, while behaving much like the !:{\aftergroup} primite: tokens are promptly restored past the end of a local group (at the target group).
216
217 \begin{codestore}[stack-bench]
218 \fp_set:Nn \g_benchmark_duration_target_fp {20}
219 \end{codestore}
220 \begin{tsremark}
221 About the after group variant, if !:{\int_if_compare:nNnTF} is used (instead of the primitive !:{\if_int_compare:w}), the number of \emph{ops} almost triple! Take a look at the code, the version with !:{\int_if_compare:nNnTF} is commented out.
222 \end{tsremark}
223 \begin{tsremark}
224 Not really needed, but since one is at it, you can try (for more stable results) !:{\fp_set:Nn} !:{\g_benchmark_duration_target_fp} !![code]{{20}}\ldots
225 \end{tsremark}
226
227 \tsOff
228 \begin{codestore}[stack-bench]
229
230 \benchmark:n
231 {
232 \group_begin:
233 \xstacks_groupmark:
234 {{
235 \xstacks_aftergroup:N \bool_set_true:N
236 \xstacks_aftergroup:N \l__mytest_tmpc_bool
237 \xstacks_aftergroup:N \bool_set_true:N
238 \xstacks_aftergroup:N \l__mytest_tmpc_bool
239 \xstacks_aftergroup:N \bool_set_true:N
240 \xstacks_aftergroup:N \l__mytest_tmpc_bool
241 {{
242 \xstacks_aftergroup:N \bool_set_true:N
243 \xstacks_aftergroup:N \l__mytest_tmpb_bool
244 \xstacks_aftergroup:N \bool_set_true:N
245 \xstacks_aftergroup:N \l__mytest_tmpb_bool
246 \xstacks_aftergroup:N \bool_set_true:N
247 \xstacks_aftergroup:N \l__mytest_tmpb_bool
248 {{
249 \xstacks_aftergroup:N \bool_set_true:N
250 \xstacks_aftergroup:N \l__mytest_tmpa_bool
251 \xstacks_aftergroup:N \bool_set_true:N
252 \xstacks_aftergroup:N \l__mytest_tmpa_bool
253 \xstacks_aftergroup:N \bool_set_true:N
254 \xstacks_aftergroup:N \l__mytest_tmpa_bool
255 {{
256 \xstacks_aftergroup:N \bool_set_true:N
257 \xstacks_aftergroup:N \l__mytest_tmpa_bool
258 \xstacks_aftergroup:N \bool_set_true:N
259 \xstacks_aftergroup:N \l__mytest_tmpa_bool
260 \xstacks_aftergroup:N \bool_set_true:N
261 \xstacks_aftergroup:N \l__mytest_tmpa_bool
262 {{
263 \xstacks_aftergroup:N \bool_set_true:N
264 \xstacks_aftergroup:N \l__mytest_tmpa_bool
265 \xstacks_aftergroup:N \bool_set_true:N
266 \xstacks_aftergroup:N \l__mytest_tmpa_bool
267 \xstacks_aftergroup:N \bool_set_true:N
268 \xstacks_aftergroup:N \l__mytest_tmpa_bool
269 }} }} }}
270 }} }}
271 \group_end:
272 }
273 \end{codestore}
274
275
276 \begin{codestore}[stack-bench]
277 \int_gzero_new:N \myMark_int
278 \benchmark:n
279 {
280 \group_begin:
281 \xstacks_groupmark:N \myMark_int
282 {{
283 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
284 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpc_bool
285 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
286 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpc_bool
287 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
288 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpc_bool
289 {{
290 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
291 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpb_bool
292 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
293 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpb_bool
294 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
295 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpb_bool
296 {{
297 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
298 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
299 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
300 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
301 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
302 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
303 {{
304 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
305 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
306 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
307 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
308 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
309 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
310 {{
311 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
312 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
313 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
314 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
315 \xstacks_aftergroup:NN \myMark_int \bool_set_true:N
316 \xstacks_aftergroup:NN \myMark_int \l__mytest_tmpa_bool
317 }} }} }}
318 }} }}
319 \group_end:
320 }
321 \end{codestore}
322
323
324
325 \begin{codestore}[stack-bench]
326 \groupmark_new:n {myMark}
327 \benchmark:n
328 {
329 \group_begin:
330 \myMark_groupmark:
331 {{
332 \myMark_aftergroup:N \bool_set_true:N
333 \myMark_aftergroup:N \l__mytest_tmpc_bool
334 \myMark_aftergroup:N \bool_set_true:N
335 \myMark_aftergroup:N \l__mytest_tmpc_bool
336 \myMark_aftergroup:N \bool_set_true:N
337 \myMark_aftergroup:N \l__mytest_tmpc_bool
338 {{
339 \myMark_aftergroup:N \bool_set_true:N
340 \myMark_aftergroup:N \l__mytest_tmpb_bool
341 \myMark_aftergroup:N \bool_set_true:N
342 \myMark_aftergroup:N \l__mytest_tmpb_bool
343 \myMark_aftergroup:N \bool_set_true:N
344 \myMark_aftergroup:N \l__mytest_tmpb_bool
345 {{
346 \myMark_aftergroup:N \bool_set_true:N
347 \myMark_aftergroup:N \l__mytest_tmpa_bool
348 \myMark_aftergroup:N \bool_set_true:N
349 \myMark_aftergroup:N \l__mytest_tmpa_bool
350 \myMark_aftergroup:N \bool_set_true:N
351 \myMark_aftergroup:N \l__mytest_tmpa_bool
352 {{
353 \myMark_aftergroup:N \bool_set_true:N
354 \myMark_aftergroup:N \l__mytest_tmpa_bool
355 \myMark_aftergroup:N \bool_set_true:N
356 \myMark_aftergroup:N \l__mytest_tmpa_bool
357 \myMark_aftergroup:N \bool_set_true:N
358 \myMark_aftergroup:N \l__mytest_tmpa_bool
359 {{
360 \myMark_aftergroup:N \bool_set_true:N
361 \myMark_aftergroup:N \l__mytest_tmpa_bool
362 \myMark_aftergroup:N \bool_set_true:N
363 \myMark_aftergroup:N \l__mytest_tmpa_bool
364 \myMark_aftergroup:N \bool_set_true:N
365 \myMark_aftergroup:N \l__mytest_tmpa_bool
366 }} }} }}
367 }} }}
368 \group_end:
369 }
370 \end{codestore}
371
372
373
374
375 \begin{codestore}[stack-bench]
376 \globalstack_csnew:n {myStack}
377 \benchmark:n
378 {
379 \group_begin:
380 {{
381 \myStack_gpush:n {
382 \bool_set_true:N \l__mytest_tmpb_bool
383 \bool_set_true:N \l__mytest_tmpb_bool
384 \bool_set_true:N \l__mytest_tmpb_bool
385 }
386 {{
387 \myStack_gput_right:n {
388 \bool_set_true:N \l__mytest_tmpb_bool
389 \bool_set_true:N \l__mytest_tmpb_bool
390 \bool_set_true:N \l__mytest_tmpb_bool
391 }
392 {{
393 \myStack_gput_right:n {
394 \bool_set_true:N \l__mytest_tmpb_bool
395 \bool_set_true:N \l__mytest_tmpb_bool
396 \bool_set_true:N \l__mytest_tmpb_bool
397 }
398 {{
399 \myStack_gput_right:n {
400 \bool_set_true:N \l__mytest_tmpb_bool
401 \bool_set_true:N \l__mytest_tmpb_bool
402 \bool_set_true:N \l__mytest_tmpb_bool
403 }
404 {{
405 \myStack_gput_right:n {
406 \bool_set_true:N \l__mytest_tmpb_bool
407 \bool_set_true:N \l__mytest_tmpb_bool
408 \bool_set_true:N \l__mytest_tmpb_bool
409 }
410 }} }} }}
411 }} }}
412 \myStack_gpop:
413 \group_end:
414 }
415 \end{codestore}
416
417
418 \begin{codestore}[stack-bench]
419 \globalstack_new:N \g_mytest_stack
420 \benchmark:n
421 {
422 \group_begin:
423 {{
424 \globalstack_gpush:Nn \g_mytest_stack {
425 \bool_set_true:N \l__mytest_tmpc_bool
426 \bool_set_true:N \l__mytest_tmpc_bool
427 \bool_set_true:N \l__mytest_tmpc_bool
428 }
429 {{
430 \globalstack_gput_right:Nn \g_mytest_stack {
431 \bool_set_true:N \l__mytest_tmpb_bool
432 \bool_set_true:N \l__mytest_tmpb_bool
433 \bool_set_true:N \l__mytest_tmpb_bool
434 }
435 {{
436 \globalstack_gput_right:Nn \g_mytest_stack {
437 \bool_set_true:N \l__mytest_tmpc_bool
438 \bool_set_true:N \l__mytest_tmpc_bool
439 \bool_set_true:N \l__mytest_tmpc_bool
440 }
441 {{
442 \globalstack_gput_right:Nn \g_mytest_stack {
443 \bool_set_true:N \l__mytest_tmpc_bool
444 \bool_set_true:N \l__mytest_tmpc_bool
445 \bool_set_true:N \l__mytest_tmpc_bool
446 }
447 {{
448 \globalstack_gput_right:Nn \g_mytest_stack {
449 \bool_set_true:N \l__mytest_tmpc_bool
450 \bool_set_true:N \l__mytest_tmpc_bool
451 \bool_set_true:N \l__mytest_tmpc_bool
452 }
453 }} }} }}
454 }} }}
455 \globalstack_gpop:N \g_mytest_stack
456 \group_end:
457 }
458 \end{codestore}
459
460
461 \tsOn
462 \subsection{Single mark, after group variant}\label{xstacks-aftergroup}
463 \tscode*[xstacks]{stack-bench}[2]
464 On average, it took about \emph{160 ops} (\emph{430 ops} if using !:{\int_if_compare:nNnTF}). If `only' the 4 first groups, the average goes down to just \emph{35 ops} (\emph{90 ops} if using !:{\int_if_compare:nNnTF}). Obviously, the number of after groups raises exponentially, $2^n$, with the number of nested groups.
465 \begin{tsremark}[\color{red}Attention:]
466 Again, these commands are to be considered \emph{deprecated}. They are less effective and flexible than !:{\groupmark_new:n} (from package !:[pkg]{tokgroupmark}).
467 \end{tsremark}
468
469 \subsection{Multiple marks, after group variant}\label{xstacks-aftergroup-int}
470 \tscode*[xstacks]{stack-bench}[3]
471 On average, it took about \emph{200 ops} (\emph{480 ops} if using !:{\int_if_compare:nNnTF}). If `only' the 4 first groups, the average goes down to just \emph{45 ops} (\emph{95 ops} if using !:{\int_if_compare:nNnTF}). Likewise, the number of after groups raises exponentially, $2^n$, with the number of nested groups (more expensive than the previous one because of the extra integer that has to be carried on).
472 \begin{tsremark}[\color{red}Attention:]
473 Again, these commands are to be considered \emph{deprecated}. They are less effective and flexible than !:{\groupmark_new:n} (from package !:[pkg]{tokgroupmark}).
474 \end{tsremark}
475
476
477 \subsection{Custom group mark commands variant}\label{groupmark-cmd}
478 \tscode*[xstacks]{stack-bench}[4]
479 On average, it took about \emph{160 ops} (\emph{430 ops} if using !:{\int_if_compare:nNnTF}). If `only' the 4 first groups, the average goes down to just \emph{35 ops} (\emph{90 ops} if using !:{\int_if_compare:nNnTF}). Obviously, the number of after groups raises exponentially, $2^n$, with the number of nested groups.
480
481 This has, naturally, the same performance/behaviour as \ref{xstacks-aftergroup}, but with the flexibility of \ref{xstacks-aftergroup-int}.
482
483
484 \subsection{Stack command variant}\label{globalstack-cmd}
485 \tscode*[xstacks]{stack-bench}[5]
486
487 On average, it took about \emph{40 ops}. If `only' the 4 first groups, the average goes down to about \emph{22 ops}. All operations, !:{\myStack_gpush:n, \myStack_gput_right:n, \myStack_gpop:} are, more or less, equally expensive.
488
489
490 The original implementation (version 1.0a) took, on average, about \emph{405 ops}. If `only' the 4 first groups, the average was about \emph{195 ops}. What's the difference? Using just \tsobj{\int_use:N} instead of \tsobj{\int_to_Alph:n} when creating internal variables (with \tsobj{\csname}) to save the tokens.
491
492 \subsection{Stack variable variant}\label{globalstack-var}
493 \tscode*[xstacks]{stack-bench}[6]
494 On average, it took about \emph{50 ops}. If `only' the 4 first groups, the average goes down to about \emph{30 ops}. The !:{\globalstack_gpush:Nn,\globalstack_gpop:N} are somewhat the more expensive operations.
495
496
497 The original implementation (version 1.0a) took, on average, about \emph{310 ops}. If `only' the 4 first groups, the average remained about \emph{290 ops}. What's the difference? Using just \tsobj{\int_use:N} instead of \tsobj{\int_to_Alph:n} when creating internal variables (with \tsobj{\csname}) to save the tokens.
498
499 \tsOff
500 %
501
502 %\ExplSyntaxOn
503 %\tsexec{stack-bench}[1]
504 %\tsexec{stack-bench}[2]
505 %\tsexec{stack-bench}[3]
506 %\tsexec{stack-bench}[4]
507 %\tsexec{stack-bench}[5]
508 %\tsexec{stack-bench}[6]
509 %\ExplSyntaxOff
510
511
512 %% if needed
513 \printbibliography
514
515
516 % 159 191 154 46.2 50.5
517 % 131 203 157 36.6 56.2
518 % 160 194 155 37.8 52
519
520 % 33.9 42 34.5 21.4 29.7
521 % 34.2 42 35.2 21.7 29.9
522
523
524
525 \end{document}