/
l3tl.dtx
3280 lines (3280 loc) · 125 KB
/
l3tl.dtx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse meta-comment
%
%% File: l3tl.dtx
%
% Copyright (C) 1990-2019 The LaTeX3 Project
%
% It may be distributed and/or modified under the conditions of the
% LaTeX Project Public License (LPPL), either version 1.3c of this
% license or (at your option) any later version. The latest version
% of this license is in the file
%
% https://www.latex-project.org/lppl.txt
%
% This file is part of the "l3kernel bundle" (The Work in LPPL)
% and all files in that bundle must be distributed together.
%
% -----------------------------------------------------------------------
%
% The development version of the bundle can be found at
%
% https://github.com/latex3/latex3
%
% for those people who are interested.
%
%<*driver>
\documentclass[full,kernel]{l3doc}
\begin{document}
\DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{^^A
% The \pkg{l3tl} package\\ Token lists^^A
% }
%
% \author{^^A
% The \LaTeX3 Project\thanks
% {^^A
% E-mail:
% \href{mailto:latex-team@latex-project.org}
% {latex-team@latex-project.org}^^A
% }^^A
% }
%
% \date{Released 2019-01-13}
%
% \maketitle
%
% \begin{documentation}
%
% \TeX{} works with tokens, and \LaTeX3 therefore provides a number of
% functions to deal with lists of tokens. Token lists may be present
% directly in the argument to a function:
% \begin{verbatim}
% \foo:n { a collection of \tokens }
% \end{verbatim}
% or may be stored in a so-called \enquote{token list variable}, which
% have the suffix \texttt{tl}: a token list variable can also be used as
% the argument to a function, for example
% \begin{verbatim}
% \foo:N \l_some_tl
% \end{verbatim}
% In both cases, functions are available to test and manipulate the lists
% of tokens, and these have the module prefix \texttt{tl}.
% In many cases, functions which can be applied to token list variables
% are paired with similar functions for application to explicit lists
% of tokens: the two \enquote{views} of a token list are therefore collected
% together here.
%
% A token list (explicit, or stored in a variable) can be seen either
% as a list of \enquote{items},
% or a list of \enquote{tokens}. An item is whatever \cs{use:n} would
% grab as its argument: a single non-space token or a brace group,
% with optional leading explicit space characters (each item is thus
% itself a token list). A token is either a normal \texttt{N} argument,
% or \verb*| |, |{|, or |}| (assuming normal \TeX{} category codes).
% Thus for example
% \begin{verbatim}
% { Hello } ~ world
% \end{verbatim}
% contains six items (\texttt{Hello}, \texttt{w}, \texttt{o}, \texttt{r},
% \texttt{l} and \texttt{d}), but thirteen tokens (|{|, \texttt{H}, \texttt{e},
% \texttt{l}, \texttt{l}, \texttt{o}, |}|, \verb*| |, \texttt{w}, \texttt{o},
% \texttt{r}, \texttt{l} and \texttt{d}).
% Functions which act on items are often faster than their analogue acting
% directly on tokens.
%
% \section{Creating and initialising token list variables}
%
% \begin{function}{\tl_new:N, \tl_new:c}
% \begin{syntax}
% \cs{tl_new:N} \meta{tl~var}
% \end{syntax}
% Creates a new \meta{tl~var} or raises an error if the
% name is already taken. The declaration is global. The
% \meta{tl~var} is initially empty.
% \end{function}
%
% \begin{function}{\tl_const:Nn, \tl_const:Nx, \tl_const:cn, \tl_const:cx}
% \begin{syntax}
% \cs{tl_const:Nn} \meta{tl~var} \Arg{token list}
% \end{syntax}
% Creates a new constant \meta{tl~var} or raises an error
% if the name is already taken. The value of the
% \meta{tl~var} is set globally to the \meta{token list}.
% \end{function}
%
% \begin{function}{\tl_clear:N, \tl_clear:c, \tl_gclear:N, \tl_gclear:c}
% \begin{syntax}
% \cs{tl_clear:N} \meta{tl~var}
% \end{syntax}
% Clears all entries from the \meta{tl~var}.
% \end{function}
%
% \begin{function}
% {\tl_clear_new:N, \tl_clear_new:c, \tl_gclear_new:N, \tl_gclear_new:c}
% \begin{syntax}
% \cs{tl_clear_new:N} \meta{tl~var}
% \end{syntax}
% Ensures that the \meta{tl~var} exists globally by applying
% \cs{tl_new:N} if necessary, then applies \cs[index=tl_clear:N]{tl_(g)clear:N} to leave
% the \meta{tl~var} empty.
% \end{function}
%
% \begin{function}
% {
% \tl_set_eq:NN, \tl_set_eq:cN, \tl_set_eq:Nc, \tl_set_eq:cc,
% \tl_gset_eq:NN, \tl_gset_eq:cN, \tl_gset_eq:Nc, \tl_gset_eq:cc
% }
% \begin{syntax}
% \cs{tl_set_eq:NN} \meta{tl~var_1} \meta{tl~var_2}
% \end{syntax}
% Sets the content of \meta{tl~var_1} equal to that of
% \meta{tl~var_2}.
% \end{function}
%
% \begin{function}[added = 2012-05-18]
% {
% \tl_concat:NNN, \tl_concat:ccc,
% \tl_gconcat:NNN, \tl_gconcat:ccc
% }
% \begin{syntax}
% \cs{tl_concat:NNN} \meta{tl~var_1} \meta{tl~var_2} \meta{tl~var_3}
% \end{syntax}
% Concatenates the content of \meta{tl~var_2} and \meta{tl~var_3}
% together and saves the result in \meta{tl~var_1}. The \meta{tl~var_2}
% is placed at the left side of the new token list.
% \end{function}
%
% \begin{function}[EXP, pTF, added=2012-03-03]{\tl_if_exist:N, \tl_if_exist:c}
% \begin{syntax}
% \cs{tl_if_exist_p:N} \meta{tl~var}
% \cs{tl_if_exist:NTF} \meta{tl~var} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests whether the \meta{tl~var} is currently defined. This does not
% check that the \meta{tl~var} really is a token list variable.
% \end{function}
%
% \section{Adding data to token list variables}
%
% \begin{function}
% {
% \tl_set:Nn, \tl_set:NV, \tl_set:Nv, \tl_set:No, \tl_set:Nf, \tl_set:Nx,
% \tl_set:cn, \tl_set:cV, \tl_set:cv, \tl_set:co, \tl_set:cf, \tl_set:cx,
% \tl_gset:Nn, \tl_gset:NV, \tl_gset:Nv,
% \tl_gset:No, \tl_gset:Nf, \tl_gset:Nx,
% \tl_gset:cn, \tl_gset:cV, \tl_gset:cv,
% \tl_gset:co, \tl_gset:cf, \tl_gset:cx
% }
% \begin{syntax}
% \cs{tl_set:Nn} \meta{tl~var} \Arg{tokens}
% \end{syntax}
% Sets \meta{tl~var} to contain \meta{tokens},
% removing any previous content from the variable.
% \end{function}
%
% \begin{function}
% {
% \tl_put_left:Nn, \tl_put_left:NV, \tl_put_left:No, \tl_put_left:Nx,
% \tl_put_left:cn, \tl_put_left:cV, \tl_put_left:co, \tl_put_left:cx,
% \tl_gput_left:Nn, \tl_gput_left:NV, \tl_gput_left:No, \tl_gput_left:Nx,
% \tl_gput_left:cn, \tl_gput_left:cV, \tl_gput_left:co, \tl_gput_left:cx
% }
% \begin{syntax}
% \cs{tl_put_left:Nn} \meta{tl~var} \Arg{tokens}
% \end{syntax}
% Appends \meta{tokens} to the left side of the current content of
% \meta{tl~var}.
% \end{function}
%
% \begin{function}
% {
% \tl_put_right:Nn, \tl_put_right:NV, \tl_put_right:No, \tl_put_right:Nx,
% \tl_put_right:cn, \tl_put_right:cV, \tl_put_right:co, \tl_put_right:cx,
% \tl_gput_right:Nn, \tl_gput_right:NV, \tl_gput_right:No,
% \tl_gput_right:Nx,
% \tl_gput_right:cn, \tl_gput_right:cV, \tl_gput_right:co,
% \tl_gput_right:cx
% }
% \begin{syntax}
% \cs{tl_put_right:Nn} \meta{tl~var} \Arg{tokens}
% \end{syntax}
% Appends \meta{tokens} to the right side of the current content of
% \meta{tl~var}.
% \end{function}
%
% \section{Modifying token list variables}
%
% \begin{function}[updated = 2011-08-11]
% {
% \tl_replace_once:Nnn, \tl_replace_once:cnn,
% \tl_greplace_once:Nnn, \tl_greplace_once:cnn
% }
% \begin{syntax}
% \cs{tl_replace_once:Nnn} \meta{tl~var} \Arg{old tokens} \Arg{new tokens}
% \end{syntax}
% Replaces the first (leftmost) occurrence of \meta{old tokens} in the
% \meta{tl~var} with \meta{new tokens}. \meta{Old tokens}
% cannot contain |{|, |}| or |#|
% (more precisely, explicit character tokens with category code $1$
% (begin-group) or $2$ (end-group), and tokens with category code $6$).
% \end{function}
%
% \begin{function}[updated = 2011-08-11]
% {
% \tl_replace_all:Nnn, \tl_replace_all:cnn,
% \tl_greplace_all:Nnn, \tl_greplace_all:cnn
% }
% \begin{syntax}
% \cs{tl_replace_all:Nnn} \meta{tl~var} \Arg{old tokens} \Arg{new tokens}
% \end{syntax}
% Replaces all occurrences of \meta{old tokens} in the
% \meta{tl~var} with \meta{new tokens}. \meta{Old tokens}
% cannot contain |{|, |}| or |#|
% (more precisely, explicit character tokens with category code $1$
% (begin-group) or $2$ (end-group), and tokens with category code $6$).
% As this function
% operates from left to right, the pattern \meta{old tokens}
% may remain after the replacement (see \cs{tl_remove_all:Nn}
% for an example).
% \end{function}
%
% \begin{function}[updated = 2011-08-11]
% {
% \tl_remove_once:Nn, \tl_remove_once:cn,
% \tl_gremove_once:Nn, \tl_gremove_once:cn
% }
% \begin{syntax}
% \cs{tl_remove_once:Nn} \meta{tl~var} \Arg{tokens}
% \end{syntax}
% Removes the first (leftmost) occurrence of \meta{tokens} from the
% \meta{tl~var}. \meta{Tokens} cannot contain |{|, |}| or |#|
% (more precisely, explicit character tokens with category code $1$
% (begin-group) or $2$ (end-group), and tokens with category code $6$).
% \end{function}
%
% \begin{function}[updated = 2011-08-11]
% {
% \tl_remove_all:Nn, \tl_remove_all:cn,
% \tl_gremove_all:Nn, \tl_gremove_all:cn
% }
% \begin{syntax}
% \cs{tl_remove_all:Nn} \meta{tl~var} \Arg{tokens}
% \end{syntax}
% Removes all occurrences of \meta{tokens} from the
% \meta{tl~var}. \meta{Tokens} cannot contain |{|, |}| or |#|
% (more precisely, explicit character tokens with category code $1$
% (begin-group) or $2$ (end-group), and tokens with category code $6$).
% As this function
% operates from left to right, the pattern \meta{tokens}
% may remain after the removal, for instance,
% \begin{quote}
% \cs{tl_set:Nn} \cs{l_tmpa_tl} |{abbccd}|
% \cs{tl_remove_all:Nn} \cs{l_tmpa_tl} |{bc}|
% \end{quote}
% results in \cs{l_tmpa_tl} containing \texttt{abcd}.
% \end{function}
%
% \section{Reassigning token list category codes}
%
% These functions allow the rescanning of tokens: re-apply \TeX{}'s
% tokenization process to apply category codes different from those
% in force when the tokens were absorbed. Whilst this functionality is
% supported, it is often preferable to find alternative approaches
% to achieving outcomes rather than rescanning tokens (for example
% construction of token lists token-by-token with intervening category
% code changes or using \cs{char_generate:nn}).
%
% \begin{function}[updated = 2015-08-11]
% {
% \tl_set_rescan:Nnn, \tl_set_rescan:Nno, \tl_set_rescan:Nnx,
% \tl_set_rescan:cnn, \tl_set_rescan:cno, \tl_set_rescan:cnx,
% \tl_gset_rescan:Nnn, \tl_gset_rescan:Nno, \tl_gset_rescan:Nnx,
% \tl_gset_rescan:cnn, \tl_gset_rescan:cno, \tl_gset_rescan:cnx
% }
% \begin{syntax}
% \cs{tl_set_rescan:Nnn} \meta{tl~var} \Arg{setup} \Arg{tokens}
% \end{syntax}
% Sets \meta{tl~var} to contain \meta{tokens}, applying the category
% code r\'{e}gime specified in the \meta{setup} before carrying out
% the assignment. (Category codes applied to tokens not explicitly covered
% by the \meta{setup} are those in force at the point of use of
% \cs{tl_set_rescan:Nnn}.)
% This allows the \meta{tl~var} to contain material
% with category codes other than those that apply when \meta{tokens}
% are absorbed. The \meta{setup} is run within a group and may
% contain any valid input, although only changes in category codes
% are relevant. See also \cs{tl_rescan:nn}.
% \begin{texnote}
% The \meta{tokens} are first turned into a string (using
% \cs{tl_to_str:n}). If the string contains one or more characters
% with character code \tn{newlinechar} (set equal to
% \tn{endlinechar} unless that is equal to $32$, before the user
% \meta{setup}), then it is split into lines at these characters,
% then read as if reading multiple lines from a file, ignoring
% spaces (catcode $10$) at the beginning and spaces and tabs
% (character code $32$ or $9$) at the end of every line.
% Otherwise, spaces (and tabs) are retained at both ends of the
% single-line string, as if it appeared in the middle of a line
% read from a file.
% \end{texnote}
% \end{function}
%
% \begin{function}[updated = 2015-08-11]{\tl_rescan:nn}
% \begin{syntax}
% \cs{tl_rescan:nn} \Arg{setup} \Arg{tokens}
% \end{syntax}
% Rescans \meta{tokens} applying the category code r\'{e}gime
% specified in the \meta{setup}, and leaves the resulting tokens in
% the input stream. (Category codes applied to tokens not explicitly covered
% by the \meta{setup} are those in force at the point of use of
% \cs{tl_rescan:nn}.)
% The \meta{setup} is run within a group and may
% contain any valid input, although only changes in category codes
% are relevant. See also \cs{tl_set_rescan:Nnn}, which is more
% robust than using \cs{tl_set:Nn} in the \meta{tokens} argument of
% \cs{tl_rescan:nn}.
% \begin{texnote}
% The \meta{tokens} are first turned into a string (using
% \cs{tl_to_str:n}). If the string contains one or more characters
% with character code \tn{newlinechar} (set equal to
% \tn{endlinechar} unless that is equal to $32$, before the user
% \meta{setup}), then it is split into lines at these characters,
% then read as if reading multiple lines from a file, ignoring
% spaces (catcode $10$) at the beginning and spaces and tabs
% (character code $32$ or $9$) at the end of every line.
% Otherwise, spaces (and tabs) are retained at both ends of the
% single-line string, as if it appeared in the middle of a line
% read from a file.
% \end{texnote}
% \end{function}
%
% \section{Token list conditionals}
%
% \begin{function}[EXP,pTF]{\tl_if_blank:n, \tl_if_blank:V, \tl_if_blank:o}
% \begin{syntax}
% \cs{tl_if_blank_p:n} \Arg{token list}
% \cs{tl_if_blank:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token list} consists only of blank spaces
% (\emph{i.e.}~contains no item). The test is \texttt{true} if
% \meta{token list} is zero or more explicit space characters
% (explicit tokens with character code~$32$ and category code~$10$),
% and is \texttt{false} otherwise.
% \end{function}
%
% \begin{function}[EXP,pTF]{\tl_if_empty:N, \tl_if_empty:c}
% \begin{syntax}
% \cs{tl_if_empty_p:N} \meta{tl~var}
% \cs{tl_if_empty:NTF} \meta{tl~var} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token list variable} is entirely empty
% (\emph{i.e.}~contains no tokens at all).
% \end{function}
%
% \begin{function}[added = 2012-05-24, updated = 2012-06-05, EXP,pTF]
% {\tl_if_empty:n, \tl_if_empty:V, \tl_if_empty:o}
% \begin{syntax}
% \cs{tl_if_empty_p:n} \Arg{token list}
% \cs{tl_if_empty:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token list} is entirely empty
% (\emph{i.e.}~contains no tokens at all).
% \end{function}
%
% \begin{function}[EXP,pTF]
% {\tl_if_eq:NN, \tl_if_eq:Nc, \tl_if_eq:cN, \tl_if_eq:cc}
% \begin{syntax}
% \cs{tl_if_eq_p:NN} \meta{tl~var_1} \meta{tl~var_2}
% \cs{tl_if_eq:NNTF} \meta{tl~var_1} \meta{tl~var_2} \Arg{true code} \Arg{false code}
% \end{syntax}
% Compares the content of two \meta{token list variables} and
% is logically \texttt{true} if the two contain the same list of
% tokens (\emph{i.e.}~identical in both the list of characters they
% contain and the category codes of those characters). Thus for example
% \begin{verbatim}
% \tl_set:Nn \l_tmpa_tl { abc }
% \tl_set:Nx \l_tmpb_tl { \tl_to_str:n { abc } }
% \tl_if_eq:NNTF \l_tmpa_tl \l_tmpb_tl { true } { false }
% \end{verbatim}
% yields \texttt{false}.
% \end{function}
%
% \begin{function}[TF]{\tl_if_eq:nn}
% \begin{syntax}
% \cs{tl_if_eq:nnTF} \Arg{token list_1} \Arg{token list_2} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token list_1} and \meta{token list_2} contain the
% same list of tokens, both in respect of character codes and category
% codes.
% \end{function}
%
% \begin{function}[TF]{\tl_if_in:Nn, \tl_if_in:cn}
% \begin{syntax}
% \cs{tl_if_in:NnTF} \meta{tl~var} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token list} is found in the content of the
% \meta{tl~var}. The \meta{token list} cannot contain
% the tokens |{|, |}| or |#|
% (more precisely, explicit character tokens with category code $1$
% (begin-group) or $2$ (end-group), and tokens with category code $6$).
% \end{function}
%
% \begin{function}[TF]
% {\tl_if_in:nn, \tl_if_in:Vn, \tl_if_in:on, \tl_if_in:no}
% \begin{syntax}
% \cs{tl_if_in:nnTF} \Arg{token list_1} \Arg{token list_2} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token list_2} is found inside \meta{token list_1}.
% The \meta{token list_2} cannot contain the tokens |{|, |}| or |#|
% (more precisely, explicit character tokens with category code $1$
% (begin-group) or $2$ (end-group), and tokens with category code $6$).
% \end{function}
%
% \begin{function}[added = 2017-11-14, EXP,pTF]{\tl_if_novalue:n}
% \begin{syntax}
% \cs{tl_if_novalue_p:n} \Arg{token list}
% \cs{tl_if_novalue:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token list} is exactly equal to the special
% \cs{c_novalue_tl} marker. This function is intended to allow construction
% of flexible document interface structures in which missing optional
% arguments are detected.
% \end{function}
%
% \begin{function}[updated = 2011-08-13, EXP,pTF]
% {\tl_if_single:N, \tl_if_single:c}
% \begin{syntax}
% \cs{tl_if_single_p:N} \meta{tl~var}
% \cs{tl_if_single:NTF} \meta{tl~var} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the content of the \meta{tl~var} consists of a single item,
% \emph{i.e.}~is a single normal token (neither an explicit space
% character nor a begin-group character) or a single brace group,
% surrounded by optional spaces on both sides. In other words, such a
% token list has token count $1$ according to \cs{tl_count:N}.
% \end{function}
%
% \begin{function}[updated = 2011-08-13, EXP,pTF]{\tl_if_single:n}
% \begin{syntax}
% \cs{tl_if_single_p:n} \Arg{token list}
% \cs{tl_if_single:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token list} has exactly one item, \emph{i.e.}~is
% a single normal token (neither an explicit space character nor a
% begin-group character) or a single brace group, surrounded by
% optional spaces on both sides. In other words, such a token list has
% token count $1$ according to \cs{tl_count:n}.
% \end{function}
%
% \begin{function}[added = 2013-07-24, EXP, noTF]{\tl_case:Nn, \tl_case:cn}
% \begin{syntax}
% \cs{tl_case:NnTF} \meta{test token list variable} \\
% ~~"{" \\
% ~~~~\meta{token list variable case_1} \Arg{code case_1} \\
% ~~~~\meta{token list variable case_2} \Arg{code case_2} \\
% ~~~~\ldots \\
% ~~~~\meta{token list variable case_n} \Arg{code case_n} \\
% ~~"}" \\
% ~~\Arg{true code}
% ~~\Arg{false code}
% \end{syntax}
% This function compares the \meta{test token list variable} in turn
% with each of the \meta{token list variable cases}. If the two
% are equal (as described for \cs{tl_if_eq:NNTF})
% then the associated \meta{code} is left in the input
% stream and other cases are discarded. If any of the
% cases are matched, the \meta{true code} is also inserted into the
% input stream (after the code for the appropriate case), while if none
% match then the \meta{false code} is inserted. The function
% \cs{tl_case:Nn}, which does nothing if there is no match, is also
% available.
% \end{function}
%
% \section{Mapping to token lists}
%
% \begin{function}[updated = 2012-06-29, rEXP]
% {\tl_map_function:NN, \tl_map_function:cN}
% \begin{syntax}
% \cs{tl_map_function:NN} \meta{tl~var} \meta{function}
% \end{syntax}
% Applies \meta{function} to every \meta{item} in the \meta{tl~var}.
% The \meta{function} receives one argument for each iteration.
% This may be a number of tokens if the \meta{item} was stored within
% braces. Hence the \meta{function} should anticipate receiving
% \texttt{n}-type arguments. See also \cs{tl_map_function:nN}.
% \end{function}
%
% \begin{function}[updated = 2012-06-29, rEXP]{\tl_map_function:nN}
% \begin{syntax}
% \cs{tl_map_function:nN} \Arg{token list} \meta{function}
% \end{syntax}
% Applies \meta{function} to every \meta{item} in the \meta{token list},
% The \meta{function} receives one argument for each iteration.
% This may be a number of tokens if the \meta{item} was stored within
% braces. Hence the \meta{function} should anticipate receiving
% \texttt{n}-type arguments. See also \cs{tl_map_function:NN}.
% \end{function}
%
% \begin{function}[updated = 2012-06-29]
% {\tl_map_inline:Nn, \tl_map_inline:cn}
% \begin{syntax}
% \cs{tl_map_inline:Nn} \meta{tl~var} \Arg{inline function}
% \end{syntax}
% Applies the \meta{inline function} to every \meta{item} stored within the
% \meta{tl~var}. The \meta{inline function} should consist of code which
% receives the \meta{item} as |#1|. See also \cs{tl_map_function:NN}.
% \end{function}
%
% \begin{function}[updated = 2012-06-29]{\tl_map_inline:nn}
% \begin{syntax}
% \cs{tl_map_inline:nn} \Arg{token list} \Arg{inline function}
% \end{syntax}
% Applies the \meta{inline function} to every \meta{item} stored within the
% \meta{token list}. The \meta{inline function} should consist of code which
% receives the \meta{item} as |#1|. See also \cs{tl_map_function:nN}.
% \end{function}
%
% \begin{function}[updated = 2012-06-29]
% {\tl_map_variable:NNn, \tl_map_variable:cNn}
% \begin{syntax}
% \cs{tl_map_variable:NNn} \meta{tl~var} \meta{variable} \Arg{code}
% \end{syntax}
% Stores each \meta{item} of the \meta{tl~var} in turn in the (token
% list) \meta{variable} and applies the \meta{code}. The \meta{code}
% will usually make use of the \meta{variable}, but this is not
% enforced. The assignments to the \meta{variable} are local. See
% also \cs{tl_map_inline:Nn}.
% \end{function}
%
% \begin{function}[updated = 2012-06-29]{\tl_map_variable:nNn}
% \begin{syntax}
% \cs{tl_map_variable:nNn} \Arg{token list} \meta{variable} \Arg{code}
% \end{syntax}
% Stores each \meta{item} of the \meta{token list} in turn in the
% (token list) \meta{variable} and applies the \meta{code}. The
% \meta{code} will usually make use of the \meta{variable}, but this
% is not enforced. The assignments to the \meta{variable} are local.
% See also \cs{tl_map_inline:nn}.
% \end{function}
%
% \begin{function}[updated = 2012-06-29, rEXP]{\tl_map_break:}
% \begin{syntax}
% \cs{tl_map_break:}
% \end{syntax}
% Used to terminate a \cs[no-index]{tl_map_\ldots} function before all
% entries in the \meta{token list variable} have been processed. This
% normally takes place within a conditional statement, for example
% \begin{verbatim}
% \tl_map_inline:Nn \l_my_tl
% {
% \str_if_eq:nnT { #1 } { bingo } { \tl_map_break: }
% % Do something useful
% }
% \end{verbatim}
% See also \cs{tl_map_break:n}.
% Use outside of a \cs[no-index]{tl_map_\ldots} scenario leads to low
% level \TeX{} errors.
% \begin{texnote}
% When the mapping is broken, additional tokens may be inserted
% before the \meta{tokens} are
% inserted into the input stream.
% This depends on the design of the mapping function.
% \end{texnote}
% \end{function}
%
% \begin{function}[updated = 2012-06-29, rEXP]{\tl_map_break:n}
% \begin{syntax}
% \cs{tl_map_break:n} \Arg{code}
% \end{syntax}
% Used to terminate a \cs[no-index]{tl_map_\ldots} function before all
% entries in the \meta{token list variable} have been processed, inserting
% the \meta{code} after the mapping has ended. This
% normally takes place within a conditional statement, for example
% \begin{verbatim}
% \tl_map_inline:Nn \l_my_tl
% {
% \str_if_eq:nnT { #1 } { bingo }
% { \tl_map_break:n { <code> } }
% % Do something useful
% }
% \end{verbatim}
% Use outside of a \cs[no-index]{tl_map_\ldots} scenario leads to low
% level \TeX{} errors.
% \begin{texnote}
% When the mapping is broken, additional tokens may be inserted
% before the \meta{code} is
% inserted into the input stream.
% This depends on the design of the mapping function.
% \end{texnote}
% \end{function}
%
% \section{Using token lists}
%
% \begin{function}[EXP]{\tl_to_str:n, \tl_to_str:V}
% \begin{syntax}
% \cs{tl_to_str:n} \Arg{token list}
% \end{syntax}
% Converts the \meta{token list} to a \meta{string}, leaving the
% resulting character tokens in the input stream. A \meta{string}
% is a series of tokens with category code $12$ (other) with the exception
% of spaces, which retain category code $10$ (space).
% This function requires only a single expansion.
% Its argument \emph{must} be braced.
% \begin{texnote}
% This is the \eTeX{} primitive \tn{detokenize}.
% Converting a \meta{token list} to a \meta{string} yields a
% concatenation of the string representations of every token in the
% \meta{token list}.
% The string representation of a control sequence is
% \begin{itemize}
% \item an escape character, whose character code is given by the
% internal parameter \tn{escapechar}, absent if the
% \tn{escapechar} is negative or greater than the largest
% character code;
% \item the control sequence name, as defined by \cs{cs_to_str:N};
% \item a space, unless the control sequence name is a single
% character whose category at the time of expansion of
% \cs{tl_to_str:n} is not \enquote{letter}.
% \end{itemize}
% The string representation of an explicit character token is that
% character, doubled in the case of (explicit) macro parameter
% characters (normally |#|).
% In particular, the string representation of a token list may
% depend on the category codes in effect when it is evaluated, and
% the value of the \tn{escapechar}: for instance |\tl_to_str:n {\a}|
% normally produces the three character \enquote{backslash},
% \enquote{lower-case a}, \enquote{space}, but it may also produce a
% single \enquote{lower-case a} if the escape character is negative
% and \texttt{a} is currently not a letter.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP]{\tl_to_str:N, \tl_to_str:c}
% \begin{syntax}
% \cs{tl_to_str:N} \meta{tl~var}
% \end{syntax}
% Converts the content of the \meta{tl~var} into a series of characters
% with category code $12$ (other) with the exception of spaces, which
% retain category code $10$ (space). This \meta{string} is then left
% in the input stream. For low-level details, see the notes given for
% \cs{tl_to_str:n}.
% \end{function}
%
% \begin{function}[EXP]{\tl_use:N, \tl_use:c}
% \begin{syntax}
% \cs{tl_use:N} \meta{tl~var}
% \end{syntax}
% Recovers the content of a \meta{tl~var} and places it
% directly in the input stream. An error is raised if the variable
% does not exist or if it is invalid. Note that it is possible to use
% a \meta{tl~var} directly without an accessor function.
% \end{function}
%
% \section{Working with the content of token lists}
%
% \begin{function}[added = 2012-05-13, EXP]
% {\tl_count:n, \tl_count:V, \tl_count:o}
% \begin{syntax}
% \cs{tl_count:n} \Arg{tokens}
% \end{syntax}
% Counts the number of \meta{items} in \meta{tokens} and leaves this
% information in the input stream. Unbraced tokens count as one
% element as do each token group (|{|\ldots|}|). This process
% ignores any unprotected spaces within \meta{tokens}. See also
% \cs{tl_count:N}. This function requires three expansions,
% giving an \meta{integer denotation}.
% \end{function}
%
% \begin{function}[added = 2012-05-13, EXP]{\tl_count:N, \tl_count:c}
% \begin{syntax}
% \cs{tl_count:N} \meta{tl~var}
% \end{syntax}
% Counts the number of token groups in the \meta{tl~var}
% and leaves this information in the input stream. Unbraced tokens
% count as one element as do each token group (|{|\ldots|}|). This
% process ignores any unprotected spaces within the \meta{tl~var}.
% See also \cs{tl_count:n}. This function requires three expansions,
% giving an \meta{integer denotation}.
% \end{function}
%
% \begin{function}[updated = 2012-01-08, EXP]
% {\tl_reverse:n, \tl_reverse:V, \tl_reverse:o}
% \begin{syntax}
% \cs{tl_reverse:n} \Arg{token list}
% \end{syntax}
% Reverses the order of the \meta{items} in the \meta{token list},
% so that \meta{item_1}\meta{item_2}\meta{item_3} \ldots \meta{item_n}
% becomes \meta{item_n}\ldots \meta{item_3}\meta{item_2}\meta{item_1}.
% This process preserves unprotected space within the
% \meta{token list}. Tokens are not reversed within braced token
% groups, which keep their outer set of braces.
% In situations where performance is important,
% consider \cs{tl_reverse_items:n}.
% See also \cs{tl_reverse:N}.
% \begin{texnote}
% The result is returned within \tn{unexpanded}, which means that the token
% list does not expand further when appearing in an \texttt{x}-type
% argument expansion.
% \end{texnote}
% \end{function}
%
% \begin{function}[updated = 2012-01-08]
% {\tl_reverse:N, \tl_reverse:c, \tl_greverse:N, \tl_greverse:c}
% \begin{syntax}
% \cs{tl_reverse:N} \meta{tl~var}
% \end{syntax}
% Reverses the order of the \meta{items} stored in \meta{tl~var}, so
% that \meta{item_1}\meta{item_2}\meta{item_3} \ldots \meta{item_n}
% becomes \meta{item_n}\ldots \meta{item_3}\meta{item_2}\meta{item_1}.
% This process preserves unprotected spaces within the
% \meta{token list variable}. Braced token groups are copied without
% reversing the order of tokens, but keep the outer set of braces.
% See also \cs{tl_reverse:n}, and, for improved performance,
% \cs{tl_reverse_items:n}.
% \end{function}
%
% \begin{function}[added = 2012-01-08, EXP]{\tl_reverse_items:n}
% \begin{syntax}
% \cs{tl_reverse_items:n} \Arg{token list}
% \end{syntax}
% Reverses the order of the \meta{items} stored in \meta{tl~var},
% so that \Arg{item_1}\Arg{item_2}\Arg{item_3} \ldots \Arg{item_n}
% becomes \Arg{item_n} \ldots{} \Arg{item_3}\Arg{item_2}\Arg{item_1}.
% This process removes any unprotected space within the
% \meta{token list}. Braced token groups are copied without
% reversing the order of tokens, and keep the outer set of braces.
% Items which are initially not braced are copied with braces in
% the result. In cases where preserving spaces is important,
% consider the slower function \cs{tl_reverse:n}.
% \begin{texnote}
% The result is returned within \tn{unexpanded}, which means that the token
% list does not expand further when appearing in an \texttt{x}-type
% argument expansion.
% \end{texnote}
% \end{function}
%
% \begin{function}[added = 2011-07-09, updated = 2012-06-25, EXP]
% {\tl_trim_spaces:n, \tl_trim_spaces:o}
% \begin{syntax}
% \cs{tl_trim_spaces:n} \Arg{token list}
% \end{syntax}
% Removes any leading and trailing explicit space characters
% (explicit tokens with character code~$32$ and category code~$10$)
% from the \meta{token list} and leaves the result in the input
% stream.
% \begin{texnote}
% The result is returned within \tn{unexpanded}, which means that the token
% list does not expand further when appearing in an \texttt{x}-type
% argument expansion.
% \end{texnote}
% \end{function}
%
% \begin{function}[added = 2018-04-12, EXP]
% {\tl_trim_spaces_apply:nN, \tl_trim_spaces_apply:oN}
% \begin{syntax}
% \cs{tl_trim_spaces_apply:nN} \Arg{token list} \meta{function}
% \end{syntax}
% Removes any leading and trailing explicit space characters (explicit
% tokens with character code~$32$ and category code~$10$) from the
% \meta{token list} and passes the result to the \meta{function} as an
% \texttt{n}-type argument.
% \end{function}
%
% \begin{function}[added = 2011-07-09]
% {
% \tl_trim_spaces:N, \tl_trim_spaces:c,
% \tl_gtrim_spaces:N, \tl_gtrim_spaces:c
% }
% \begin{syntax}
% \cs{tl_trim_spaces:N} \meta{tl~var}
% \end{syntax}
% Removes any leading and trailing explicit space characters
% (explicit tokens with character code~$32$ and category code~$10$)
% from the content of the \meta{tl~var}. Note that this therefore
% \emph{resets} the content of the variable.
% \end{function}
%
% \begin{function}[added = 2017-02-06]
% {\tl_sort:Nn, \tl_sort:cn, \tl_gsort:Nn, \tl_gsort:cn}
% \begin{syntax}
% \cs{tl_sort:Nn} \meta{tl var} \Arg{comparison code}
% \end{syntax}
% Sorts the items in the \meta{tl var} according to the
% \meta{comparison code}, and assigns the result to
% \meta{tl var}. The details of sorting comparison are
% described in Section~\ref{sec:l3sort:mech}.
% \end{function}
%
% \begin{function}[added = 2017-02-06, EXP]{\tl_sort:nN}
% \begin{syntax}
% \cs{tl_sort:nN} \Arg{token list} \meta{conditional}
% \end{syntax}
% Sorts the items in the \meta{token list}, using the
% \meta{conditional} to compare items, and leaves the result in the
% input stream. The \meta{conditional} should have signature |:nnTF|,
% and return \texttt{true} if the two items being compared should be
% left in the same order, and \texttt{false} if the items should be
% swapped. The details of sorting comparison are
% described in Section~\ref{sec:l3sort:mech}.
% \begin{texnote}
% The result is returned within \cs{exp_not:n}, which means that the
% token list does not expand further when appearing in an
% \texttt{x}-type argument expansion.
% \end{texnote}
% \end{function}
%
% \section{The first token from a token list}
%
% Functions which deal with either only the very first item (balanced
% text or single normal token) in a token list, or the remaining tokens.
%
% \begin{function}[updated = 2012-09-09, EXP]
% {\tl_head:N, \tl_head:n, \tl_head:V, \tl_head:v, \tl_head:f}
% \begin{syntax}
% \cs{tl_head:n} \Arg{token list}
% \end{syntax}
% Leaves in the input stream the first \meta{item} in the
% \meta{token list}, discarding the rest of the \meta{token list}.
% All leading explicit space characters
% (explicit tokens with character code~$32$ and category code~$10$)
% are discarded; for example
% \begin{verbatim}
% \tl_head:n { abc }
% \end{verbatim}
% and
% \begin{verbatim}
% \tl_head:n { ~ abc }
% \end{verbatim}
% both leave |a| in the input stream. If the \enquote{head} is a
% brace group, rather than a single token, the braces are removed, and
% so
% \begin{verbatim}
% \tl_head:n { ~ { ~ ab } c }
% \end{verbatim}
% yields \verb*| ab|.
% A blank \meta{token list} (see \cs{tl_if_blank:nTF}) results in
% \cs{tl_head:n} leaving nothing in the input stream.
% \begin{texnote}
% The result is returned within \cs{exp_not:n}, which means that the token
% list does not expand further when appearing in an \texttt{x}-type
% argument expansion.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP]{\tl_head:w}
% \begin{syntax}
% \cs{tl_head:w} \meta{token list} | { } | \cs{q_stop}
% \end{syntax}
% Leaves in the input stream the first \meta{item} in the
% \meta{token list}, discarding the rest of the \meta{token list}.
% All leading explicit space characters
% (explicit tokens with character code~$32$ and category code~$10$)
% are discarded.
% A blank \meta{token list} (which consists only of space characters)
% results in a low-level \TeX{} error, which may be avoided by the
% inclusion of an empty group in the input (as shown), without the need
% for an explicit test. Alternatively, \cs{tl_if_blank:nF} may be used to
% avoid using the function with a \enquote{blank} argument.
% This function requires only a single expansion, and thus is suitable for
% use within an \texttt{o}-type expansion. In general, \cs{tl_head:n} should
% be preferred if the number of expansions is not critical.
% \end{function}
%
% \begin{function}[updated = 2012-09-01, EXP]
% {\tl_tail:N, \tl_tail:n, \tl_tail:V, \tl_tail:v, \tl_tail:f}
% \begin{syntax}
% \cs{tl_tail:n} \Arg{token list}
% \end{syntax}
% Discards all leading explicit space characters
% (explicit tokens with character code~$32$ and category code~$10$)
% and the first \meta{item} in the \meta{token list}, and leaves the
% remaining tokens in the input stream. Thus for example
% \begin{verbatim}
% \tl_tail:n { a ~ {bc} d }
% \end{verbatim}
% and
% \begin{verbatim}
% \tl_tail:n { ~ a ~ {bc} d }
% \end{verbatim}
% both leave \verb*| {bc}d| in the input stream. A blank
% \meta{token list} (see \cs{tl_if_blank:nTF}) results
% in \cs{tl_tail:n} leaving nothing in the input stream.
% \begin{texnote}
% The result is returned within \cs{exp_not:n}, which means that the
% token list does not expand further when appearing in an \texttt{x}-type
% argument expansion.
% \end{texnote}
% \end{function}
%
% \begin{function}[updated = 2012-07-09, EXP, pTF]{\tl_if_head_eq_catcode:nN}
% \begin{syntax}
% \cs{tl_if_head_eq_catcode_p:nN} \Arg{token list} \meta{test token}
% \cs{tl_if_head_eq_catcode:nNTF} \Arg{token list} \meta{test token}
% ~~\Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the first \meta{token} in the \meta{token list} has the
% same category code as the \meta{test token}. In the case where the
% \meta{token list} is empty, the test is always \texttt{false}.
% \end{function}
%
% \begin{function}[updated = 2012-07-09, EXP, pTF]
% {\tl_if_head_eq_charcode:nN, \tl_if_head_eq_charcode:fN}
% \begin{syntax}
% \cs{tl_if_head_eq_charcode_p:nN} \Arg{token list} \meta{test token}
% \cs{tl_if_head_eq_charcode:nNTF} \Arg{token list} \meta{test token}
% ~~\Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the first \meta{token} in the \meta{token list} has the
% same character code as the \meta{test token}. In the case where the
% \meta{token list} is empty, the test is always \texttt{false}.
% \end{function}
%
% \begin{function}[updated = 2012-07-09, EXP, pTF]{\tl_if_head_eq_meaning:nN}
% \begin{syntax}
% \cs{tl_if_head_eq_meaning_p:nN} \Arg{token list} \meta{test token}
% \cs{tl_if_head_eq_meaning:nNTF} \Arg{token list} \meta{test token}
% ~~\Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the first \meta{token} in the \meta{token list} has the
% same meaning as the \meta{test token}. In the case where
% \meta{token list} is empty, the test is always \texttt{false}.
% \end{function}
%
% \begin{function}[added = 2012-07-08, EXP, pTF]{\tl_if_head_is_group:n}
% \begin{syntax}
% \cs{tl_if_head_is_group_p:n} \Arg{token list}
% \cs{tl_if_head_is_group:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the first \meta{token} in the \meta{token list}
% is an explicit begin-group character (with category code~$1$
% and any character code), in other words, if the \meta{token list}
% starts with a brace group. In particular, the test is \texttt{false}
% if the \meta{token list} starts with an implicit token such as
% \cs{c_group_begin_token}, or if it is empty.
% This function is useful to implement actions on token lists on
% a token by token basis.
% \end{function}
%
% \begin{function}[added = 2012-07-08, EXP, pTF]{\tl_if_head_is_N_type:n}
% \begin{syntax}
% \cs{tl_if_head_is_N_type_p:n} \Arg{token list}
% \cs{tl_if_head_is_N_type:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the first \meta{token} in the \meta{token list}
% is a normal \texttt{N}-type argument. In other words,
% it is neither an explicit space character
% (explicit token with character code~$32$ and category code~$10$)
% nor an explicit begin-group character
% (with category code~1 and any character code). An empty
% argument yields \texttt{false}, as it does not have a \enquote{normal}
% first token.
% This function is useful to implement actions on token lists on
% a token by token basis.
% \end{function}
%
% \begin{function}[updated = 2012-07-08, EXP, pTF]{\tl_if_head_is_space:n}
% \begin{syntax}
% \cs{tl_if_head_is_space_p:n} \Arg{token list}
% \cs{tl_if_head_is_space:nTF} \Arg{token list} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the first \meta{token} in the \meta{token list}
% is an explicit space character
% (explicit token with character code~$12$ and category code~$10$).
% In particular, the test is \texttt{false} if the \meta{token list}
% starts with an implicit token such as \cs{c_space_token}, or if it
% is empty.
% This function is useful to implement actions on token lists on
% a token by token basis.
% \end{function}
%
% \section{Using a single item}
%
% \begin{function}[added = 2014-07-17, EXP]
% {\tl_item:nn, \tl_item:Nn, \tl_item:cn}
% \begin{syntax}
% \cs{tl_item:nn} \Arg{token list} \Arg{integer expression}
% \end{syntax}
% Indexing items in the \meta{token list} from~$1$ on the left, this