-
Notifications
You must be signed in to change notification settings - Fork 177
/
l3token.dtx
3075 lines (3073 loc) · 117 KB
/
l3token.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: l3token.dtx
%
% Copyright (C) 2005-2022 The LaTeX 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{l3token} package\\ Token manipulation^^A
% }
%
% \author{^^A
% The \LaTeX{} Project\thanks
% {^^A
% E-mail:
% \href{mailto:latex-team@latex-project.org}
% {latex-team@latex-project.org}^^A
% }^^A
% }
%
% \date{Released 2022-09-28}
%
% \maketitle
%
% \begin{documentation}
%
% This module deals with tokens. Now this is perhaps not the most
% precise description so let's try with a better description: When
% programming in \TeX{}, it is often desirable to know just what a
% certain token is: is it a control sequence or something
% else. Similarly one often needs to know if a control sequence is
% expandable or not, a macro or a primitive, how many arguments it
% takes etc. Another thing of great importance (especially when it
% comes to document commands) is looking ahead in the token stream to
% see if a certain character is present and maybe even remove it or
% disregard other tokens while scanning. This module provides
% functions for both and as such has two primary function
% categories: |\token_| for anything that deals with tokens and
% |\peek_| for looking ahead in the token stream.
%
% Most functions we describe here can be used on control sequences,
% as those are tokens as well.
%
% It is important to distinguish two aspects of a token: its
% \enquote{shape} (for lack of a better word), which affects the
% matching of delimited arguments and the comparison of token lists
% containing this token, and its \enquote{meaning}, which affects
% whether the token expands or what operation it performs. One can have
% tokens of different shapes with the same meaning, but not the
% converse.
%
% For instance, \cs{if:w}, \cs{if_charcode:w}, and \cs[no-index]{tex_if:D} are
% three names for the same internal operation of \TeX{}, namely the
% primitive testing the next two characters for equality of their
% character code. They have the same meaning hence behave identically
% in many situations. However, \TeX{} distinguishes them when searching
% for a delimited argument. Namely, the example function
% |\show_until_if:w| defined below takes everything until \cs{if:w}
% as an argument, despite the presence of other copies of \cs{if:w}
% under different names.
% \begin{verbatim}
% \cs_new:Npn \show_until_if:w #1 \if:w { \tl_show:n {#1} }
% \show_until_if:w \tex_if:D \if_charcode:w \if:w
% \end{verbatim}
% A list of all possible shapes and a list of all possible meanings are
% given in section~\ref{sec:l3token:all-tokens}.
%
% \section{Creating character tokens}
%
% \begin{function}[updated = 2015-11-12]
% {
% \char_set_active_eq:NN, \char_set_active_eq:Nc,
% \char_gset_active_eq:NN, \char_gset_active_eq:Nc
% }
% \begin{syntax}
% \cs{char_set_active_eq:NN} \meta{char} \meta{function}
% \end{syntax}
% Sets the behaviour of the \meta{char} in situations where it is
% active (category code $13$) to be equivalent to that of the
% \meta{function}. The category code of the \meta{char} is
% \emph{unchanged} by this process. The \meta{function} may itself
% be an active character.
% \end{function}
%
% \begin{function}[added = 2015-11-12]
% {
% \char_set_active_eq:nN, \char_set_active_eq:nc,
% \char_gset_active_eq:nN, \char_gset_active_eq:nc
% }
% \begin{syntax}
% \cs{char_set_active_eq:nN} \Arg{integer expression} \meta{function}
% \end{syntax}
% Sets the behaviour of the \meta{char} which has character
% code as given by the \meta{integer expression} in situations
% where it is active (category code $13$) to be equivalent to that of the
% \meta{function}. The category code of the \meta{char} is
% \emph{unchanged} by this process. The \meta{function} may itself
% be an active character.
% \end{function}
%
% \begin{function}[EXP, added = 2015-09-09, updated = 2019-01-16]
% {\char_generate:nn}
% \begin{syntax}
% \cs{char_generate:nn} \Arg{charcode} \Arg{catcode}
% \end{syntax}
% Generates a character token of the given \meta{charcode} and \meta{catcode}
% (both of which may be integer expressions). The \meta{catcode} may be
% one of
% \begin{itemize}
% \item $1$ (begin group)
% \item $2$ (end group)
% \item $3$ (math toggle)
% \item $4$ (alignment)
% \item $6$ (parameter)
% \item $7$ (math superscript)
% \item $8$ (math subscript)
% \item $10$ (space)
% \item $11$ (letter)
% \item $12$ (other)
% \item $13$ (active)
% \end{itemize}
% and other values raise an error. The \meta{charcode} may be any one valid
% for the engine in use, except that for \meta{catcode} $10$, \meta{charcode}
% $0$ is not allowed.
% Active characters cannot be generated in older versions of \XeTeX{}.
% Another way to build token lists with unusual category codes is
% \cs{regex_replace:nnN} |{.*}| \Arg{replacement} \meta{tl~var}.
% \begin{texnote}
% Exactly two expansions are needed to produce the character.
% \end{texnote}
% \end{function}
%
% \begin{function}[added = 2020-01-09, EXP]
% {
% \char_lowercase:N, \char_uppercase:N,
% \char_titlecase:N, \char_foldcase:N,
% \char_str_lowercase:N, \char_str_uppercase:N,
% \char_str_titlecase:N, \char_str_foldcase:N
% }
% \begin{syntax}
% \cs{char_lowercase:N} \meta{char}
% \end{syntax}
% Converts the \meta{char} to the equivalent case-changed character
% as detailed by the function name (see \cs{str_foldcase:n}
% and \cs{text_titlecase:n} for details of these terms). The case mapping
% is carried out with no context-dependence (\emph{cf.}~\cs{text_uppercase:n},
% \emph{etc.}) The \texttt{str} versions always generate \enquote{other}
% (category code $12$) characters, whilst the standard versions generate
% characters with the category code of the \meta{char} (i.e.~only
% the character code changes).
% \end{function}
%
% \begin{variable}[added = 2011-09-05]{\c_catcode_other_space_tl}
% Token list containing one character with category code $12$,
% (\enquote{other}), and character code $32$ (space).
% \end{variable}
%
% \section{Manipulating and interrogating character tokens}
%
% \begin{function}[updated = 2015-11-11]
% {
% \char_set_catcode_escape:N ,
% \char_set_catcode_group_begin:N ,
% \char_set_catcode_group_end:N ,
% \char_set_catcode_math_toggle:N ,
% \char_set_catcode_alignment:N ,
% \char_set_catcode_end_line:N ,
% \char_set_catcode_parameter:N ,
% \char_set_catcode_math_superscript:N ,
% \char_set_catcode_math_subscript:N ,
% \char_set_catcode_ignore:N ,
% \char_set_catcode_space:N ,
% \char_set_catcode_letter:N ,
% \char_set_catcode_other:N ,
% \char_set_catcode_active:N ,
% \char_set_catcode_comment:N ,
% \char_set_catcode_invalid:N
% }
% \begin{syntax}
% \cs{char_set_catcode_letter:N} \meta{character}
% \end{syntax}
% Sets the category code of the \meta{character} to that indicated in
% the function name. Depending on the current category code of the
% \meta{token} the escape token may also be needed:
% \begin{verbatim}
% \char_set_catcode_other:N \%
% \end{verbatim}
% The assignment is local.
% \end{function}
%
% \begin{function}[updated = 2015-11-11]
% {
% \char_set_catcode_escape:n ,
% \char_set_catcode_group_begin:n ,
% \char_set_catcode_group_end:n ,
% \char_set_catcode_math_toggle:n ,
% \char_set_catcode_alignment:n ,
% \char_set_catcode_end_line:n ,
% \char_set_catcode_parameter:n ,
% \char_set_catcode_math_superscript:n ,
% \char_set_catcode_math_subscript:n ,
% \char_set_catcode_ignore:n ,
% \char_set_catcode_space:n ,
% \char_set_catcode_letter:n ,
% \char_set_catcode_other:n ,
% \char_set_catcode_active:n ,
% \char_set_catcode_comment:n ,
% \char_set_catcode_invalid:n
% }
% \begin{syntax}
% \cs{char_set_catcode_letter:n} \Arg{integer expression}
% \end{syntax}
% Sets the category code of the \meta{character} which has character
% code as given by the \meta{integer expression}. This version can be
% used to set up characters which cannot otherwise be given
% (\emph{cf.}~the \texttt{N}-type variants). The assignment is local.
% \end{function}
%
% \begin{function}[updated = 2015-11-11]{\char_set_catcode:nn}
% \begin{syntax}
% \cs{char_set_catcode:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
% These functions set the category code of the \meta{character} which
% has character code as given by the \meta{integer expression}.
% The first \meta{integer expression}
% is the character code and the second is the category code to apply.
% The setting applies within the current \TeX{} group. In general, the
% symbolic functions \cs[no-index]{char_set_catcode_\meta{type}} should be preferred,
% but there are cases where these lower-level functions may be useful.
% \end{function}
%
% \begin{function}[EXP]{\char_value_catcode:n}
% \begin{syntax}
% \cs{char_value_catcode:n} \Arg{integer expression}
% \end{syntax}
% Expands to the current category code of the \meta{character} with
% character code given by the
% \meta{integer expression}.
% \end{function}
%
% \begin{function}{\char_show_value_catcode:n}
% \begin{syntax}
% \cs{char_show_value_catcode:n} \Arg{integer expression}
% \end{syntax}
% Displays the current category code of the \meta{character} with
% character code given by the \meta{integer expression} on the
% terminal.
% \end{function}
%
% \begin{function}[updated = 2015-08-06]{\char_set_lccode:nn}
% \begin{syntax}
% \cs{char_set_lccode:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
% Sets up the behaviour of the \meta{character} when
% found inside \cs{text_lowercase:n}, such that \meta{character_1}
% will be converted into \meta{character_2}. The two \meta{characters}
% may be specified using an \meta{integer expression} for the character code
% concerned. This may include the \TeX{} |`|\meta{character}
% method for converting a single character into its character
% code:
% \begin{verbatim}
% \char_set_lccode:nn { `\A } { `\a } % Standard behaviour
% \char_set_lccode:nn { `\A } { `\A + 32 }
% \char_set_lccode:nn { 50 } { 60 }
% \end{verbatim}
% The setting applies within the current \TeX{} group.
% \end{function}
%
% \begin{function}[EXP]{\char_value_lccode:n}
% \begin{syntax}
% \cs{char_value_lccode:n} \Arg{integer expression}
% \end{syntax}
% Expands to the current lower case code of the \meta{character} with
% character code given by the
% \meta{integer expression}.
% \end{function}
%
% \begin{function}{\char_show_value_lccode:n}
% \begin{syntax}
% \cs{char_show_value_lccode:n} \Arg{integer expression}
% \end{syntax}
% Displays the current lower case code of the \meta{character} with
% character code given by the \meta{integer expression} on the
% terminal.
% \end{function}
%
% \begin{function}[updated = 2015-08-06]{\char_set_uccode:nn}
% \begin{syntax}
% \cs{char_set_uccode:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
% Sets up the behaviour of the \meta{character} when
% found inside \cs{text_uppercase:n}, such that \meta{character_1}
% will be converted into \meta{character_2}. The two \meta{characters}
% may be specified using an \meta{integer expression} for the character code
% concerned. This may include the \TeX{} |`|\meta{character}
% method for converting a single character into its character
% code:
% \begin{verbatim}
% \char_set_uccode:nn { `\a } { `\A } % Standard behaviour
% \char_set_uccode:nn { `\A } { `\A - 32 }
% \char_set_uccode:nn { 60 } { 50 }
% \end{verbatim}
% The setting applies within the current \TeX{} group.
% \end{function}
%
% \begin{function}[EXP]{\char_value_uccode:n}
% \begin{syntax}
% \cs{char_value_uccode:n} \Arg{integer expression}
% \end{syntax}
% Expands to the current upper case code of the \meta{character} with
% character code given by the
% \meta{integer expression}.
% \end{function}
%
% \begin{function}{\char_show_value_uccode:n}
% \begin{syntax}
% \cs{char_show_value_uccode:n} \Arg{integer expression}
% \end{syntax}
% Displays the current upper case code of the \meta{character} with
% character code given by the \meta{integer expression} on the
% terminal.
% \end{function}
%
% \begin{function}[updated = 2015-08-06]{\char_set_mathcode:nn}
% \begin{syntax}
% \cs{char_set_mathcode:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
% This function sets up the math code of \meta{character}.
% The \meta{character} is specified as
% an \meta{integer expression} which will be used as the character
% code of the relevant character. The setting applies within the
% current \TeX{} group.
% \end{function}
%
% \begin{function}[EXP]{\char_value_mathcode:n}
% \begin{syntax}
% \cs{char_value_mathcode:n} \Arg{integer expression}
% \end{syntax}
% Expands to the current math code of the \meta{character} with
% character code given by the
% \meta{integer expression}.
% \end{function}
%
% \begin{function}{\char_show_value_mathcode:n}
% \begin{syntax}
% \cs{char_show_value_mathcode:n} \Arg{integer expression}
% \end{syntax}
% Displays the current math code of the \meta{character} with
% character code given by the \meta{integer expression} on the
% terminal.
% \end{function}
%
% \begin{function}[updated = 2015-08-06]{\char_set_sfcode:nn}
% \begin{syntax}
% \cs{char_set_sfcode:nn} \Arg{intexpr_1} \Arg{intexpr_2}
% \end{syntax}
% This function sets up the space factor for the \meta{character}.
% The \meta{character} is specified as
% an \meta{integer expression} which will be used as the character
% code of the relevant character. The setting applies within the
% current \TeX{} group.
% \end{function}
%
% \begin{function}[EXP]{\char_value_sfcode:n}
% \begin{syntax}
% \cs{char_value_sfcode:n} \Arg{integer expression}
% \end{syntax}
% Expands to the current space factor for the \meta{character} with
% character code given by the
% \meta{integer expression}.
% \end{function}
%
% \begin{function}{\char_show_value_sfcode:n}
% \begin{syntax}
% \cs{char_show_value_sfcode:n} \Arg{integer expression}
% \end{syntax}
% Displays the current space factor for the \meta{character} with
% character code given by the \meta{integer expression} on the
% terminal.
% \end{function}
%
% \begin{variable}[added = 2012-01-23, updated = 2015-11-11]{\l_char_active_seq}
% Used to track which tokens may require special handling at the document
% level as they are (or have been at some point)
% of category \meta{active} (catcode~$13$). Each entry in
% the sequence consists of a single escaped token, for example |\~|.
% Active tokens should be added to the sequence when they are defined for
% general document use.
% \end{variable}
%
% \begin{variable}[added = 2012-01-23, updated = 2015-11-11]{\l_char_special_seq}
% Used to track which tokens will require special handling when working with
% verbatim-like material at the document level as they are not of categories
% \meta{letter} (catcode~$11$) or \meta{other} (catcode~$12$). Each entry in
% the sequence consists of a single escaped token, for example |\\| for the
% backslash or |\{| for an opening brace. ^^A \}
% Escaped tokens should be added to the sequence when they are defined for
% general document use.
% \end{variable}
%
% \section{Generic tokens}
%
% \begin{variable}[module = token]
% {
% \c_group_begin_token,
% \c_group_end_token,
% \c_math_toggle_token,
% \c_alignment_token,
% \c_parameter_token,
% \c_math_superscript_token,
% \c_math_subscript_token,
% \c_space_token
% }
% These are implicit tokens which have the category code described
% by their name. They are used internally for test purposes but
% are also available to the programmer for other uses.
% \end{variable}
%
% \begin{variable}
% {
% \c_catcode_letter_token,
% \c_catcode_other_token
% }
% These are implicit tokens which have the category code described
% by their name. They are used internally for test purposes and should
% not be used other than for category code tests.
% \end{variable}
%
% \begin{variable}{\c_catcode_active_tl}
% A token list containing an active token. This is used internally
% for test purposes and should not be used other than in
% appropriately-constructed category code tests.
% \end{variable}
%
% \section{Converting tokens}
%
% \begin{function}[EXP]{\token_to_meaning:N, \token_to_meaning:c}
% \begin{syntax}
% \cs{token_to_meaning:N} \meta{token}
% \end{syntax}
% Inserts the current meaning of the \meta{token} into the input
% stream as a series of characters of category code $12$ (other).
% This is the primitive \TeX{} description of the \meta{token},
% thus for example both functions defined by \cs{cs_set_nopar:Npn}
% and token list variables defined using \cs{tl_new:N} are described
% as |macro|s.
% \begin{texnote}
% This is the \TeX{} primitive \tn{meaning}.
% The \meta{token} can thus be an explicit space tokens or an
% explicit begin-group or end-group character token (|{|~or~|}| when
% normal \TeX{} category codes apply) even though these are not
% valid \texttt{N}-type arguments.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP]{\token_to_str:N, \token_to_str:c}
% \begin{syntax}
% \cs{token_to_str:N} \meta{token}
% \end{syntax}
% Converts the given \meta{token} into a series of characters with
% category code $12$ (other). If the \meta{token} is a control
% sequence, this will start with the current escape character with
% category code $12$ (the escape character is part of the
% \meta{token}). This function requires only a single expansion.
% \begin{texnote}
% \cs{token_to_str:N} is the \TeX{} primitive \tn{string} renamed.
% The \meta{token} can thus be an explicit space tokens or an
% explicit begin-group or end-group character token (|{|~or~|}| when
% normal \TeX{} category codes apply) even though these are not
% valid \texttt{N}-type arguments.
% \end{texnote}
% \end{function}
%
% \section{Token conditionals}
%
% \begin{function}[EXP,pTF]{\token_if_group_begin:N}
% \begin{syntax}
% \cs{token_if_group_begin_p:N} \meta{token} \\
% \cs{token_if_group_begin:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of a begin group token
% (|{| when normal \TeX{} category codes are in ^^A }
% force).
% Note that an explicit begin group token cannot be tested in this way,
% as it is not a valid \texttt{N}-type argument.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_group_end:N}
% \begin{syntax}
% \cs{token_if_group_end_p:N} \meta{token} \\
% \cs{token_if_group_end:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of an end group token
% (^^A {
% |}| when normal \TeX{} category codes are in force).
% Note that an explicit end group token cannot be tested in this way,
% as it is not a valid \texttt{N}-type argument.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_math_toggle:N}
% \begin{syntax}
% \cs{token_if_math_toggle_p:N} \meta{token} \\
% \cs{token_if_math_toggle:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of a math shift token
% (|$| when normal \TeX{} category codes are in force).
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_alignment:N}
% \begin{syntax}
% \cs{token_if_alignment_p:N} \meta{token} \\
% \cs{token_if_alignment:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of an alignment token
% (|&| when normal \TeX{} category codes are in force).
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_parameter:N}
% \begin{syntax}
% \cs{token_if_parameter_p:N} \meta{token} \\
% \cs{token_if_parameter:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of a macro parameter token
% (|#| when normal \TeX{} category codes are in force).
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_math_superscript:N}
% \begin{syntax}
% \cs{token_if_math_superscript_p:N} \meta{token} \\
% \cs{token_if_math_superscript:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of a superscript token
% (|^| when normal \TeX{} category codes are in force).
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_math_subscript:N}
% \begin{syntax}
% \cs{token_if_math_subscript_p:N} \meta{token} \\
% \cs{token_if_math_subscript:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of a subscript token
% (|_| when normal \TeX{} category codes are in force).
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_space:N}
% \begin{syntax}
% \cs{token_if_space_p:N} \meta{token} \\
% \cs{token_if_space:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of a space token.
% Note that an explicit space token with character code $32$ cannot
% be tested in this way, as it is not a valid \texttt{N}-type argument.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_letter:N}
% \begin{syntax}
% \cs{token_if_letter_p:N} \meta{token} \\
% \cs{token_if_letter:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of a letter token.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_other:N}
% \begin{syntax}
% \cs{token_if_other_p:N} \meta{token} \\
% \cs{token_if_other:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of an \enquote{other}
% token.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_active:N}
% \begin{syntax}
% \cs{token_if_active_p:N} \meta{token} \\
% \cs{token_if_active:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if \meta{token} has the category code of an active character.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_eq_catcode:NN}
% \begin{syntax}
% \cs{token_if_eq_catcode_p:NN} \meta{token_1} \meta{token_2} \\
% \cs{token_if_eq_catcode:NNTF} \meta{token_1} \meta{token_2} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the two \meta{tokens} have the same category code.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_eq_charcode:NN}
% \begin{syntax}
% \cs{token_if_eq_charcode_p:NN} \meta{token_1} \meta{token_2} \\
% \cs{token_if_eq_charcode:NNTF} \meta{token_1} \meta{token_2} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the two \meta{tokens} have the same character code.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_eq_meaning:NN}
% \begin{syntax}
% \cs{token_if_eq_meaning_p:NN} \meta{token_1} \meta{token_2} \\
% \cs{token_if_eq_meaning:NNTF} \meta{token_1} \meta{token_2} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the two \meta{tokens} have the same meaning when expanded.
% \end{function}
%
% \begin{function}[updated = 2011-05-23, EXP,pTF]{\token_if_macro:N}
% \begin{syntax}
% \cs{token_if_macro_p:N} \meta{token} \\
% \cs{token_if_macro:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is a \TeX{} macro.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_cs:N}
% \begin{syntax}
% \cs{token_if_cs_p:N} \meta{token} \\
% \cs{token_if_cs:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is a control sequence.
% \end{function}
%
% \begin{function}[EXP,pTF]{\token_if_expandable:N}
% \begin{syntax}
% \cs{token_if_expandable_p:N} \meta{token} \\
% \cs{token_if_expandable:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is expandable. This test returns \meta{false}
% for an undefined token.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_long_macro:N}
% \begin{syntax}
% \cs{token_if_long_macro_p:N} \meta{token} \\
% \cs{token_if_long_macro:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is a long macro.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_protected_macro:N}
% \begin{syntax}
% \cs{token_if_protected_macro_p:N} \meta{token} \\
% \cs{token_if_protected_macro:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is a protected macro: for a macro which
% is both protected and long this returns \texttt{false}.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_protected_long_macro:N}
% \begin{syntax}
% \cs{token_if_protected_long_macro_p:N} \meta{token} \\
% \cs{token_if_protected_long_macro:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is a protected long macro.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_chardef:N}
% \begin{syntax}
% \cs{token_if_chardef_p:N} \meta{token} \\
% \cs{token_if_chardef:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a chardef.
% \begin{texnote}
% Booleans, boxes and small integer constants are implemented as
% \tn{chardef}s.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_mathchardef:N}
% \begin{syntax}
% \cs{token_if_mathchardef_p:N} \meta{token} \\
% \cs{token_if_mathchardef:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a mathchardef.
% \end{function}
%
% \begin{function}[EXP,pTF, added=2020-10-27]{\token_if_font_selection:N}
% \begin{syntax}
% \cs{token_if_font_selection_p:N} \meta{token} \\
% \cs{token_if_font_selection:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a font selection command.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_dim_register:N}
% \begin{syntax}
% \cs{token_if_dim_register_p:N} \meta{token} \\
% \cs{token_if_dim_register:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a dimension register.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_int_register:N}
% \begin{syntax}
% \cs{token_if_int_register_p:N} \meta{token} \\
% \cs{token_if_int_register:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a integer register.
% \begin{texnote}
% Constant integers may be implemented as integer registers,
% \tn{chardef}s, or \tn{mathchardef}s depending on their value.
% \end{texnote}
% \end{function}
%
% \begin{function}[EXP,pTF, added=2012-02-15]{\token_if_muskip_register:N}
% \begin{syntax}
% \cs{token_if_muskip_register_p:N} \meta{token} \\
% \cs{token_if_muskip_register:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a muskip register.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_skip_register:N}
% \begin{syntax}
% \cs{token_if_skip_register_p:N} \meta{token} \\
% \cs{token_if_skip_register:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a skip register.
% \end{function}
%
% \begin{function}[EXP,pTF, updated=2012-01-20]{\token_if_toks_register:N}
% \begin{syntax}
% \cs{token_if_toks_register_p:N} \meta{token} \\
% \cs{token_if_toks_register:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is defined to be a toks register
% (not used by \LaTeX3).
% \end{function}
%
% \begin{function}[updated = 2020-09-11, EXP,pTF]{\token_if_primitive:N}
% \begin{syntax}
% \cs{token_if_primitive_p:N} \meta{token} \\
% \cs{token_if_primitive:NTF} \meta{token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the \meta{token} is an engine primitive. In \LuaTeX{}
% this includes primitive-like commands defined using |{token.set_lua}|.
% \end{function}
%
% \begin{function}[added = 2020-12-03, EXP, noTF]
% {\token_case_catcode:Nn, \token_case_charcode:Nn, \token_case_meaning:Nn}
% \begin{syntax}
% \cs{token_case_meaning:NnTF} \meta{test token} \\
% ~~"{" \\
% ~~~~\meta{token case_1} \Arg{code case_1} \\
% ~~~~\meta{token case_2} \Arg{code case_2} \\
% ~~~~\ldots \\
% ~~~~\meta{token case_n} \Arg{code case_n} \\
% ~~"}" \\
% ~~\Arg{true code}
% ~~\Arg{false code}
% \end{syntax}
% This function compares the \meta{test token} in turn with each of
% the \meta{token cases}. If the two are equal (as described for
% \cs{token_if_eq_catcode:NNTF}, \cs{token_if_eq_charcode:NNTF} and
% \cs{token_if_eq_meaning:NNTF}, respectively) 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 functions \cs{token_case_catcode:Nn},
% \cs{token_case_charcode:Nn}, and \cs{token_case_meaning:Nn}, which
% do nothing if there is no match, are also available.
% \end{function}
%
% \section{Peeking ahead at the next token}
%
% There is often a need to look ahead at the next token in the input
% stream while leaving it in place. This is handled using the
% \enquote{peek} functions. The generic \cs{peek_after:Nw} is provided
% along with a family of predefined tests for common cases. As peeking
% ahead does \emph{not} skip spaces the predefined tests include both a
% space-respecting and space-skipping version. In addition, using
% \cs{peek_analysis_map_inline:n}, one can map through the following
% tokens in the input stream and repeatedly perform some tests.
%
% \begin{function}{\peek_after:Nw}
% \begin{syntax}
% \cs{peek_after:Nw} \meta{function} \meta{token}
% \end{syntax}
% Locally sets the test variable \cs{l_peek_token} equal to \meta{token}
% (as an implicit token, \emph{not} as a token list), and then
% expands the \meta{function}. The \meta{token} remains in
% the input stream as the next item after the \meta{function}.
% The \meta{token} here may be \verb*| |, |{| or |}| (assuming
% normal \TeX{} category codes), \emph{i.e.}~it is not necessarily the
% next argument which would be grabbed by a normal function.
% \end{function}
%
% \begin{function}{\peek_gafter:Nw}
% \begin{syntax}
% \cs{peek_gafter:Nw} \meta{function} \meta{token}
% \end{syntax}
% Globally sets the test variable \cs{g_peek_token} equal to \meta{token}
% (as an implicit token, \emph{not} as a token list), and then
% expands the \meta{function}. The \meta{token} remains in
% the input stream as the next item after the \meta{function}.
% The \meta{token} here may be \verb*| |, |{| or |}| (assuming
% normal \TeX{} category codes), \emph{i.e.}~it is not necessarily the
% next argument which would be grabbed by a normal function.
% \end{function}
%
% \begin{variable}{\l_peek_token}
% Token set by \cs{peek_after:Nw} and available for testing
% as described above.
% \end{variable}
%
% \begin{variable}{\g_peek_token}
% Token set by \cs{peek_gafter:Nw} and available for testing
% as described above.
% \end{variable}
%
% \begin{function}[updated = 2012-12-20, TF]{\peek_catcode:N}
% \begin{syntax}
% \cs{peek_catcode:NTF} \meta{test token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the next \meta{token} in the input stream has the same
% category code as the \meta{test token} (as defined by the test
% \cs{token_if_eq_catcode:NNTF}). Spaces are respected by the test
% and the \meta{token} is left in the input stream after
% the \meta{true code} or \meta{false code} (as appropriate to the
% result of the test).
% \end{function}
%
% \begin{function}[updated = 2012-12-20, TF]{\peek_catcode_remove:N}
% \begin{syntax}
% \cs{peek_catcode_remove:NTF} \meta{test token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the next \meta{token} in the input stream has the same
% category code as the \meta{test token} (as defined by the test
% \cs{token_if_eq_catcode:NNTF}). Spaces are respected by the test
% and the \meta{token} is removed from the input stream if the
% test is true. The function then places either the
% \meta{true code} or \meta{false code} in the input stream (as
% appropriate to the result of the test).
% \end{function}
%
% \begin{function}[updated = 2012-12-20, TF]{\peek_charcode:N}
% \begin{syntax}
% \cs{peek_charcode:NTF} \meta{test token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the next \meta{token} in the input stream has the same
% character code as the \meta{test token} (as defined by the test
% \cs{token_if_eq_charcode:NNTF}). Spaces are respected by the test
% and the \meta{token} is left in the input stream after
% the \meta{true code} or \meta{false code} (as appropriate to the
% result of the test).
% \end{function}
%
% \begin{function}[updated = 2012-12-20, TF]{\peek_charcode_remove:N}
% \begin{syntax}
% \cs{peek_charcode_remove:NTF} \meta{test token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the next \meta{token} in the input stream has the same
% character code as the \meta{test token} (as defined by the test
% \cs{token_if_eq_charcode:NNTF}). Spaces are respected by the test
% and the \meta{token} is removed from the input stream if the
% test is true. The function then places either the
% \meta{true code} or \meta{false code} in the input stream (as
% appropriate to the result of the test).
% \end{function}
%
% \begin{function}[updated = 2011-07-02, TF]{\peek_meaning:N}
% \begin{syntax}
% \cs{peek_meaning:NTF} \meta{test token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the next \meta{token} in the input stream has the same
% meaning as the \meta{test token} (as defined by the test
% \cs{token_if_eq_meaning:NNTF}). Spaces are respected by the test
% and the \meta{token} is left in the input stream after
% the \meta{true code} or \meta{false code} (as appropriate to the
% result of the test).
% \end{function}
%
% \begin{function}[updated = 2011-07-02, TF]{\peek_meaning_remove:N}
% \begin{syntax}
% \cs{peek_meaning_remove:NTF} \meta{test token} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the next \meta{token} in the input stream has the same
% meaning as the \meta{test token} (as defined by the test
% \cs{token_if_eq_meaning:NNTF}). Spaces are respected by the test
% and the \meta{token} is removed from the input stream if the
% test is true. The function then places either the
% \meta{true code} or \meta{false code} in the input stream (as
% appropriate to the result of the test).
% \end{function}
%
% \begin{function}[added = 2018-10-01]{\peek_remove_spaces:n}
% \begin{syntax}
% \cs{peek_remove_spaces:n} \Arg{code}
% \end{syntax}
% Peeks ahead and detect if the following token is a space (category code
% $10$ and character code $32$). If so, removes the token and checks the
% next token. Once a non-space token is found, the \meta{code} will be
% inserted into the input stream. Typically this will contain a \texttt{peek}
% operation, but this is not required.
% \end{function}
%
% \begin{function}[added = 2022-01-10]{\peek_remove_filler:n}
% \begin{syntax}
% \cs{peek_remove_filler:n} \Arg{code}
% \end{syntax}
% Peeks ahead and detect if the following token is a space (category code
% $10$) or has meaning equal to \cs{scan_stop:}. If so,
% removes the token and checks the next token. If neither of these cases
% apply, expands the next token using \texttt{f}-type expansion, then checks
% the resulting leading token in the same way. If after expansion the next
% token is neither of the two test cases, the \meta{code} will be inserted
% into the input stream. Typically this will contain a \texttt{peek}
% operation, but this is not required.
% \begin{texnote}
% This is essentially a macro-based implementation of how \TeX{} handles
% the search for a left brace after for example \tn{everypar}, except that
% any non-expandable token cleanly ends the \meta{filler} (i.e.~it does not
% lead to a \TeX{} error).
%
% In contrast to \TeX{}'s filler removal, a construct
% \verb|\exp_not:N \foo| will be treated in the same way as \verb|\foo|.
% \end{texnote}
% \end{function}
%
% \begin{function}[TF, updated = 2012-12-20]{\peek_N_type:}
% \begin{syntax}
% \cs{peek_N_type:TF} \Arg{true code} \Arg{false code}
% \end{syntax}
% Tests if the next \meta{token} in the input stream can be safely
% grabbed as an \texttt{N}-type argument. The test is \meta{false}
% if the next \meta{token} is either an explicit or implicit
% begin-group or end-group token (with any character code), or
% an explicit or implicit space character (with character code $32$
% and category code $10$), or an outer token (never used in \LaTeX3)
% and \meta{true} in all other cases.
% Note that a \meta{true} result ensures that the next \meta{token} is
% a valid \texttt{N}-type argument. However, if the next \meta{token}
% is for instance \cs{c_space_token}, the test takes the
% \meta{false} branch, even though the next \meta{token} is in fact
% a valid \texttt{N}-type argument. The \meta{token} is left
% in the input stream after the \meta{true code} or \meta{false code}
% (as appropriate to the result of the test).
% \end{function}
%
% \begin{function}[added = 2020-12-03, updated = 2022-10-03]
% {\peek_analysis_map_inline:n}
% \begin{syntax}
% \cs{peek_analysis_map_inline:n} \Arg{inline function}
% \end{syntax}
% Repeatedly removes one \meta{token} from the input stream and
% applies the \meta{inline function} to it, until
% \cs{peek_analysis_map_break:} is called. The \meta{inline function}
% receives three arguments for each \meta{token} in the input stream:
% \begin{itemize}
% \item \meta{tokens}, which both \texttt{o}-expand and
% \texttt{x}-expand to the \meta{token}. The detailed form of
% \meta{tokens} may change in later releases.
% \item \meta{char code}, a decimal representation of the character
% code of the \meta{token}, $-1$ if it is a control sequence.
% \item \meta{catcode}, a capital hexadecimal digit which denotes the
% category code of the \meta{token} (0:~control sequence,
% 1:~begin-group, 2:~end-group, 3:~math shift, 4:~alignment tab,
% 6:~parameter, 7:~superscript, 8:~subscript, A:~space, B:~letter,
% C:~other, D:~active). This can be converted to an integer by
% writing |"|\meta{catcode}.
% \end{itemize}
% These arguments are the same as for \cs{tl_analysis_map_inline:nn}
% defined in \pkg{l3tl-analysis}. The \meta{char code} and
% \meta{catcode} do not take the meaning of a control sequence or
% active character into account: for instance, upon encountering the
% token \cs{c_group_begin_token} in the input stream,
% \cs{peek_analysis_map_inline:n} calls the \meta{inline function}
% with |#1| being \cs{exp_not:n} |{| \cs{c_group_begin_token} |}|
% (with the current implementation),
% |#2|~being~$-1$, and
% |#3|~being~$0$, as for any other control sequence. In contrast,
% upon encountering an explicit begin-group token~|{|, % ^^A |}|
% the \meta{inline function} is called with arguments
% \cs{exp_after:wN} |{| \cs{if_false:} |}| \cs{fi:}, $123$ and~$1$.
%
% The mapping is done at the current group level, \emph{i.e.}~any
% local assignments made by the \meta{inline function} remain in