summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/scontents/scontents.dtx
blob: fd0504e7a2c1dc9aa2d62d00452e466135f1ab2f (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
% \iffalse meta-comment
%
% Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl>
%
% This work may be distributed and/or modified under the conditions of the
% LaTeX Project Public License, either version 1.3c of this license or (at
% your option) any later version. The latest version of this license is in
%
%     http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX version
% 2005/12/01 or later.
% 
% This work is "maintained" (as per the LPPL maintenance status)
% by Pablo González Luengo.
% 
% This work consists of the file  scontents.dtx
% and the derived files           scontents.ins,
%                                 scontents.pdf and
%                                 scontents.sty.
%
%<*internal>
\def\nameofplainTeX{plain}
\ifx\fmtname\nameofplainTeX\else
  \expandafter\begingroup
\fi
%</internal>
%<*install>
\input l3docstrip.tex
\keepsilent
\askforoverwritefalse
\preamble

Copyright (C) 2019 by Pablo González L <pablgonz@educarchile.cl>

This work may be distributed and/or modified under the conditions of the
LaTeX Project Public License, either version 1.3c of this license or (at
your option) any later version. The latest version of this license is in

 http://www.latex-project.org/lppl.txt

and version 1.3c or later is part of all distributions of LaTeX version
2005/12/01 or later.

This work is "maintained" (as per the LPPL maintenance status)
by Pablo González Luengo.

This work consists of the file  scontents.dtx
and the derived files           scontents.ins,
                                scontents.pdf and
                                scontents.sty.

\endpreamble
\usedir{tex/latex/scontents}
\generate{%
  \file{\jobname.sty}{\from{\jobname.dtx}{package}}%
}%
%</install>
%<install>\endbatchfile
%<*internal>
\usedir{source/latex/scontents}
\generate{
  \file{\jobname.ins}{\from{\jobname.dtx}{install}}
}
\ifx\fmtname\nameofplainTeX
  \expandafter\endbatchfile
\else
  \expandafter\endgroup
\fi
%</internal>
%<*driver>
\documentclass[full]{l3doc}
% imakeidx also opens a write stream for the .idx file, and that conflicts
% with the one opened by l3doc. Here we close that write stream:
\makeatletter
\immediate\closeout\@indexfile
\makeatother
% and later we will copy the write stream opened by imakeidx into \@indexfile
% so that entries written to both streams end up in the same file.
\usepackage[top=0.5in,bottom=0.5in,left=2in,right=0.7in,footskip=0.2in,headsep=10pt]{geometry}
\usepackage[osf,mono=false,scale=0.95,llscaled=0.95]{libertine}
\usepackage{unicode-math}
\setmathfont[Scale = 0.95]{latinmodern-math.otf}
\usepackage[osf,scale=0.80,semibold]{sourcecodepro}
\usepackage{fontawesome5}
\newfontfamily\lmmitalic{lmmono10-italic.otf}[
   Scale             = 0.95,%
   Extension         = .otf,%
   ItalicFont        = lmmono10-italic,%
   SmallCapsFont     = lmmonocaps10-oblique,%
   SlantedFont       = lmmonoslant10-regular,
   ]
\newfontfamily\fetamontotf{ffmw10.otf}[
   Scale             = 0.95,%
   RawFeature        = {+latn,+rand,+kern,+size},%
   ]
\usepackage[svgnames]{xcolor}
\usepackage[sf,bf,compact,medium,pagestyles]{titlesec}
\usepackage{hyperxmp,lastpage,imakeidx,microtype,attachfile2}
\usepackage{adjustbox,multicol,listings,accsupp,titletoc}
\usepackage{scontents} % main
\usepackage[osf,scale=0.80,semibold]{sourcecodepro}
\usepackage[contents]{colordoc}

% Patching colordoc.sty to work with l3doc.cls
\ExplSyntaxOn
\cs_new_eq:cN { liii@xmacro@code } \__codedoc_xmacro_code:n
\ExplSyntaxOff
\begingroup
\makeatletter
\catcode`\[\@ne\catcode`\]\tw@
\@makebracesactive
\gdef{[\@openingbrace[\char'173]]
\gdef}[\@closingbrace[\char'175]]
\catcode`\|\z@\catcode`\%12
\catcode`\ \active\catcode`\\\active
|gdef|xmacro@code#1%    \end{macrocode}[|liii@xmacro@code[#1]|end[macrocode]]
|catcode`| 12|gdef|sxmacro@code#1%    \end{macrocode*}[|liii@xmacro@code[#1]|end[macrocode*]]
|endgroup

\EnableCrossrefs
% \PageIndex % \CodelineIndex undoes what \PageIndex does
% \CodelineIndex tries to open another write stream for the index file. We don't
% want that, so we temporarily make \makeindex a no-op:
\let\ORGmakeindex\makeindex
\def\makeindex{}
\CodelineIndex
\let\makeindex\ORGmakeindex
\DoNotIndex{\ , \1,\^}
\expandafter\DoNotIndex\expandafter{\string\{}
\expandafter\DoNotIndex\expandafter{\string\}}
\expandafter\DoNotIndex\expandafter{\string\begin}
\newcommand{\HP}[1]{\emph{\hyperpage{#1}}\normalsize}
\def\MYSortIndex#1#2{\index[userdoc]{#1\actualchar#2|HP}}

\indexsetup{level=\section,firstpagestyle=myheader}
\makeindex[name=userdoc,options=-s gind.ist,columnsep=15pt,title={Index of Documentation}]
\makeindex[options=-s gind.ist,columnsep=15pt,title={Index of Implementation}]
% Now, after imakeidx opens the write stream for the index file, we copy
% the reference to \@indexfile:
\makeatletter
\let\@indexfile\scontents@idxfile
\makeatother

\setlength{\parindent}{0pt}

%%-------------------- ONLY FOR DOCUMENTATION ------------------------%%
% Colors for options
\definecolor{optcolor}{rgb}{0.281,0.275,0.485}
\definecolor{mypkgcolor}{RGB}{0,128,128}%
% Custom \meta[...]{...}, \marg[...]{...} and \oarg[...]{...} with color
\ExplSyntaxOn
% User level commands
\NewDocumentCommand{\mymeta}{O{}m}
  {
   \userdoc_meta_generic:Nnn \userdoc_meta:n { #1 } { #2 }
  }
\NewDocumentCommand{\mymarg}{O{}m}
  {
   \userdoc_meta_generic:Nnn \userdoc_marg:n { #1 } { #2 }
  }
\NewDocumentCommand{\myoarg}{O{}m}
  {
   \userdoc_meta_generic:Nnn \userdoc_oarg:n { #1 } { #2 }
  }
% Variables and keys
\tl_new:N \l_userdoc_meta_font_tl

\keys_define:nn { userdoc / mymeta }
  {
   type .choice:,
   type / tt .code:n = \tl_set:Nn \l_userdoc_meta_font_tl { \ttfamily },
   type / rm .code:n = \tl_set:Nn \l_userdoc_meta_font_tl { \rmfamily },
   type .initial:n = rm,
   cf .tl_set:N = \l_userdoc_meta_color_tl,
   cf .initial:n = optcolor,
   ac .tl_set:N = \l_userdoc_meta_anglecolor_tl,
   ac .initial:n = lightgray,
   sbc .tl_set:N = \l_userdoc_meta_brackcolor_tl,
   sbc .initial:n = gray,
   cbc .tl_set:N = \l_userdoc_meta_bracecolor_tl,
   cbc .initial:n = gray,
  }
% Internal commands
\cs_new_protected:Npn \userdoc_meta_generic:Nnn #1 #2 #3
  {
   \group_begin:
   \keys_set:nn { userdoc / mymeta } { #2 }
   \color{ \l_userdoc_meta_color_tl }
   \l_userdoc_meta_font_tl
   #1 { #3 } % #1 is \userdoc_meta:n, \userdoc_marg:n or \userdoc_oarg:n
   \group_end:
  }
\cs_new_protected:Npn \userdoc_meta:n #1
  {
   \userdoc_meta_angle:n { \textlangle }
   \userdoc_meta_meta:n { #1 }
   \userdoc_meta_angle:n { \textrangle }
  }
\cs_new_protected:Npn \userdoc_marg:n #1
  {
   \userdoc_meta_brace:n { \textbraceleft }
   \userdoc_meta:n { #1 }
   \userdoc_meta_brace:n { \textbraceright }
  }
\cs_new_protected:Npn \userdoc_oarg:n #1
  {
   \userdoc_meta_brack:n { [ }
   \userdoc_meta:n { #1 }
   \userdoc_meta_brack:n { ] }
  }
\cs_new_protected:Npn \userdoc_meta_meta:n #1
  {
   \textnormal{\textit{#1}}
  }
\cs_new_protected:Npn \userdoc_meta_angle:n #1
  {
   \group_begin:
   \fontfamily{lmr}\selectfont
   \textcolor{\l_userdoc_meta_anglecolor_tl}{#1}
   \group_end:
  }
\cs_new_protected:Npn \userdoc_meta_brace:n #1
  {
   \group_begin:
   \color{\l_userdoc_meta_bracecolor_tl}
    #1
   \group_end:
  }
\cs_new_protected:Npn \userdoc_meta_brack:n #1
  {
   \textcolor{\l_userdoc_meta_brackcolor_tl}{#1}
  }

% \envexamp{m}
\newsavebox{\boxexaenv}
\NewDocumentCommand{\envexamp}{m}
  {
   \begin{lrbox}{\boxexaenv}%
    \begin{minipage}[t]{\marginparwidth}%
     \raggedright\ttfamily\small
     \textcolor{gray}{\textbackslash begin\{\textcolor{mypkgcolor}{{#1}}\}\myoarg
     [type=tt,sbc=gray,ac=lightgray,cf=optcolor]{keyval ~ list}}\par%
     \hspace{0.5cm}\mymeta[type=tt,ac=lightgray,cf=gray]{env ~ contents}\par%
     \textcolor{gray}{\textbackslash end\{{\textcolor{mypkgcolor}{{#1}}}\}}\par
    \end{minipage}%
   \end{lrbox}%
   \usebox{\boxexaenv}
  }

% \cmdexamp{s m o m o}
\DeclareDocumentCommand{\cmdexamp}{o m o m o}
  {
  \group_begin:
  \small\ttfamily
  \textcolor{mypkgcolor}{\textbackslash#2}
  \IfValueT{#1}{ \textcolor{red}{#1} }
  \IfValueT{#3}{ \myoarg[type=tt,sbc=gray,ac=lightgray,cf=optcolor]{#3} }
  \IfValueTF{#5}
    {
     \mymeta[ac=gray,type=tt,cf=MediumOrchid]{#5}%
     \mymeta[type=tt,ac=gray,cf=optcolor]{#4}
     \mymeta[ac=gray,type=tt,cf=MediumOrchid]{#5}%
    }
    { \mymarg[type=tt,cbc=gray,ac=lightgray,cf=optcolor]{#4} }
  \par
  \group_end:
  \MYSortIndex{Commands}{Commands ~ provide  ~ by  ~ \textcolor{gray}{scontents}>\texttt{\textbackslash#2}}%
  }

% \keyexamp{mmm}
\DeclareDocumentCommand{\keyexamp}{ m m m }
  {
    \par
    \adjustbox{outer=-\marginparsep}{\textcolor{black}{\small\ttfamily{#1}}}
    \textcolor{gray}{\,\bfseries\texttt{=}}\,{}
    \mymarg[type=tt,cbc=gray,ac=lightgray,cf=optcolor]{\small{#2}}
    \hfill\textcolor{gray}{ \small (\textsf{default}:~\emph{#3})}
    \par
    \MYSortIndex{Keys}{Keys>\texttt{#1}}%
  }

% \mypkg{sm}
\NewDocumentCommand{\mypkg}{sm}
  {
    \group_begin:
    \IfBooleanTF{#1}
      {
        \textsf{\textcolor{mypkgcolor}{s}\textcolor{OrangeRed}{content}\textcolor{mypkgcolor}{s}}
        \MYSortIndex{packages}{Packages>\texttt{#2}}
      }
      {
        \textcolor{darkgray}{\textsf{#2}}
        \MYSortIndex{packages}{Packages>\texttt{#2}}%
      }
     \group_end:
  }

% \myenv{sm}
\DeclareDocumentCommand{\myenv}{sm}
  {
    \IfBooleanTF{#1}
      {
       \textcolor{mypkgcolor}{\ttfamily{#2}}%
       \MYSortIndex{environment}{Environment ~ provide ~ by ~ \textcolor{gray}{scontents}:>\texttt{#2}}
      }
      {
       \textcolor{darkgray}{\ttfamily{#2}}%
       \MYSortIndex{environment}{Environments>\texttt{#2}}
      }
  }

% \ics{sm}
\DeclareDocumentCommand{\ics}{sm}
  {
    \IfBooleanTF{#1}
      {
        \tl_set:Nn \l_tmpa_tl { #2 }
        \regex_replace_once:nnN { (\*) } { \c{textcolor}\cB\{red\cE\}\cB\{\1\cE\} } \l_tmpa_tl
        \textcolor{mypkgcolor}{\ttfamily\textbackslash{\tl_use:N \l_tmpa_tl}}
        \MYSortIndex{Commands}{Commands ~ provide  ~ by  ~ \textcolor{gray}{scontents}>\texttt{\textbackslash#2}}
      }
      {
        \textcolor{darkgray}{\ttfamily\textbackslash{#2}}
        \MYSortIndex{#2}{\texttt{\textbackslash#2}}
      }
  }
\ExplSyntaxOff

% email https://tex.stackexchange.com/a/663
\catcode`\_=11\relax%
\newcommand\email[1]{\_email #1\q_nil}%
\def\_email#1@#2\q_nil{%
  \href{mailto:#1@#2}{{\emailfont #1\emailampersat #2}}%
}%
\newcommand\emailfont{\sffamily}%
\newcommand\emailampersat{{\color{optcolor}\footnotesize @}}%
\catcode`\_=8\relax%

\makeatletter
% Logo whit fetamont font for title
\newsavebox{\logobox}
\savebox{\logobox}{%
  \normalsize\fetamontotf{\textcolor{mypkgcolor}{s}\textcolor{OrangeRed}{content}\textcolor{mypkgcolor}{s}}}
\newcommand{\mylogo}{%
  \settoheight{\@tempdima}{L}%
  \resizebox{!}{\@tempdima}{\usebox{\logobox}}%
 }
\makeatother

% Custom vertamimsc
\makeatletter
\let\verbatimsc\@undefined
\let\endverbatimsc\@undefined
\makeatother
\usepackage{listings}
\lstnewenvironment{verbatimsc}
  {
    \lstset{
       language=,%
       basicstyle= \ttfamily,
       columns   = fullflexible,
       gobble    = 2,%
           }
   }{}
\makeatother

% Don't copy numbers in code example
\newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}

% Create a language for documentation
\lstdefinelanguage{scontents-doc}{
    texcsstyle=*,%
    escapechar=`,%
    showstringspaces=false,%
    extendedchars=true, %
    stringstyle= {\color{red}},%
    basicstyle=\ttfamily\small,%
    alsoletter=-,%
% comments
    morecomment=[l]{\%},%
    commentstyle=\lmmitalic\small\itshape\color{lightgray},%
% Important words 1
    keywordstyle=[1]{\color{gray}},%
    keywords=[1]{begin,end},%
% Other words 2
    keywordstyle=[2]{\color{blue!75}},%
    keywords=[2]{usepackage,section,documentclass},%
% Other words 3
    keywordstyle=[3]{\color{optcolor!85}},%
    keywords=[3]{document,article},%
% Reserved words 4 (scontents pkg)
    keywordstyle=[4]{\color{mypkgcolor}},%
    keywords=[4]{scontents,Scontents,getstored,typestored,verbatimsc,%
                 endverbatimsc,countsc,meaningsc},%
% Reserved in red
    keywordstyle=[5]{\color{red}},%
    keywords=[5]{makeatletter,makeatother,let},%
% Reserved in orange
    keywordstyle=[6]{\color{optcolor}},%
    keywords=[6]{verb,myverb,store-cmd,store-env,print-env,write-env,%
                 write-out,width-tab,force-eol,inner,outer,I,J,M,L,Ascheol},%
% Reserved in orange
    keywordstyle=[7]{\color{OrangeRed}},%
    keywords=[7]{foreach,DefineVerbatimEnvironment,lstnewenvironment,newminted},%
% literateee
    literate=*{\{}{{\textcolor{gray}{\{}}}{1}
              {\}}{{\textcolor{gray}{\}}}}{1}
              {[}{{\textcolor{gray}{[}}}{1}
              {]}{{\textcolor{gray}{]}}}{1}
              {,}{{\textcolor{gray}{,}}}{1}
              {>}{{\textcolor{OrangeRed}{\guillemotright}}}{1}
              {*}{{\textcolor{red}{*}}}{1}
              {@}{{\textcolor{red}{@}}}{1}
              {\^}{{\textcolor{optcolor}{\textasciicircum}}}{1}
              {=}{{\textcolor{gray}{=}}}{1},%
}[keywords,tex,comments,strings]% end languaje

% \begin{examplecode}[key=val]...\end{examplecode}
\lstnewenvironment{examplecode}[1][]{%
\lstset{
    language=scontents-doc,%
    stringstyle= {\color{red}},%
    basicstyle=\ttfamily\small,%
    numbersep=1em,%
    numberstyle=\tiny\color{lightgray}\noaccsupp,%
    rulecolor=\color{gray!50},%
    framesep=\fboxsep,%
    framerule=\fboxrule,%
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,%
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,%
           #1,%
    }% close lstset
}{}% close examplecode

% \lstinline[style=inline]|...|
\lstdefinestyle{inline}
  {
   language=scontents-doc,%
   escapechar=`,%
   upquote=true,%
   numbersep=1em,%
   numberstyle=\tiny\color{lightgray}\noaccsupp,%
   literate=*{\%}{{\bfseries\textcolor{gray}{\%}}}{1}
  }

% Set default \lstinline style
\lstset{style=inline}
\lstMakeShortInline[language=scontents-doc,basicstyle=\ttfamily]§

% Get file info
\GetFileInfo{\jobname.sty}

% Config hyperref
\hypersetup{
   linkcolor          = blue!50,
   citecolor          = red!50,%
   urlcolor           = magenta,%
   colorlinks         = true,%
   linktoc            = all,%
   pdftitle           = {.:: The scontents package --- \fileinfo{} ::.},%
   pdfauthor          = {Pablo González L},
   pdfsubject         = {Documentation for \fileversion{} [\filedate] },%
   pdfcopyright       = {\textcopyright 2019 by Pablo González},
   pdfcontacturl      = {https://github.com/pablgonz/scontents},
   pdfkeywords        = {contents, external files, expl3, xparse, l3seq, Store contents},
   pdfstartview       = {FitH},%
   bookmarksopenlevel = 1,%
  }

% Configuration titleps and titlesec
\settitlemarks{section}
\renewpagestyle{plain}[\color{gray}\small\sffamily]{
\setfoot{}{}{\thepage/\pageref{LastPage}}}

\newpagestyle{myheader}[\color{gray}\small\sffamily]{
\renewcommand\makeheadrule{\color{gray}\rule[0.45\baselineskip]{\linewidth}{0.4pt}}
\setfoot{\scalebox{0.8}{\mylogo}\space\textcopyright\space 2019 by Pablo González}
        {}
        {\thepage/\pageref{LastPage}}
\sethead{\raisebox{0.75\baselineskip}{Documentation for \fileversion\space[\filedate]}}
        {}
        {\raisebox{0.75\baselineskip}{\scshape\small\S.\thesection\space\sectiontitle}}
}

\setlength{\headheight}{21pt}%

\titlecontents{section}[0mm]{}%
    {\bfseries\contentspush{\makebox[5mm][l]{\thecontentslabel\hfill}}}%
    {\hspace*{-5mm}}% numberless
    {\hspace{0.25em}\titlerule*[6pt]{.}\contentspage}%
\titlecontents{subsection}[5mm]{}%
    {\contentspush{\makebox[6mm][l]{\thecontentslabel\hfill}}}
    {\hspace*{-11mm}}% numberless
    {\hspace{0.25em}\titlerule*[6pt]{.}\contentspage}%

% Table of contents
\makeatletter
\renewcommand\tableofcontents{%
\begingroup%
\section*{\contentsname\quad{\color{gray}\leaders\hrule height 5pt depth -4.4pt\hfill}%
  \@mkboth{%
    \MakeUppercase\contentsname}{\MakeUppercase\contentsname}}%
\vspace*{-14pt}
\setlength{\columnsep}{10pt}%
 \begin{multicols}{2}%
    \@starttoc{toc}%
\end{multicols}%
\vspace*{-3pt}{\color{gray}\hrule height 0.6pt}%
\vspace*{5pt}
\endgroup
}
\makeatother
\begin{document}
  \DocInput{\jobname.dtx}
\end{document}
%</driver>
% \fi
%
% \title{
%    \scalebox{1.025}{\mylogo}\\[2pt]
%    \Large
%    \textsf{Stores \hologo{LaTeX} contents}\\[3pt]
%    \fileversion{} --- \filedate\thanks{
%    This file describes a documentation for \fileversion, last revised
%    \filedate.}\\[25pt]
%    \author{
%    \large
%    \raisebox{-1pt}{\textcopyright}{}2019 by Pablo González
%    \thanks{E-mail: \textsf{\guillemotleft}\email{pablgonz@educarchile.cl}\textsf{\guillemotright}}%
%    }
% \small
% \textsc{ctan}: \url{http://www.ctan.org/pkg/scontents}\\
% \textsc{git}: \url{https://github.com/pablgonz/scontents}
% \vspace*{-2cm}
% }
% \date{}
% \maketitle
%
% \begin{scontents}[store-env=abstract,print-env=true]
% \begin{abstract}
% The \mypkg*{scontents} package stores valid \hologo{(La)TeX} code in
% \mymeta{sequences} using the \mypkg{l3seq} module of \mypkg{expl3}.
% The \mymeta{stored content}, including \emph{verbatim}, can be used
% as many times as desired in the document, additionally can be written
% to \mymeta{external files}.
% \end{abstract}
% \end{scontents}
%
% \tableofcontents
%
% \setlength{\parskip}{3pt}
%
% \section{Motivation and Acknowledgments}
%
% In \hologo{(La)TeX} there is no direct way to record content for later use, although
% you can do this using "\macros", recording \mymeta{verbatim content}  is a
% problem, usually you can avoid this by creating external files or boxes. The
% general idea of this package is to try to imitate this implementation
% \emph{buffers} that has \hologo{ConTeXt} which allows you to save content in
% memory, including \emph{verbatim}, to be used later. The package
% \mypkg{filecontentsdef} solves this problem and since \mypkg{expl3} has an
% excellent way to manage data, ideas were combined giving rise to this package.
%
% This package would not be possible without the great work of \textsc{Jean
% Fran\c{c}ois Burnol} who was kind enough to take my requirements into account
% and add the \myenv{filecontentsdefmacro} environment. Also a special thanks to
% Phelype Oleinik who has collaborated and adapted a large part of the code and
% all \hologo{LaTeX3} team for their great work and to the different members
% of the \href{https://tex.stackexchange.com}{TeX-SX} community who have provided
% great answers and ideas. Here a note of the main ones:
%
% \begin{enumerate}[nosep]
% \item \href{https://tex.stackexchange.com/q/45946/7832}{Stack datastructure using LaTeX}
%
% \item \href{https://tex.stackexchange.com/q/5338/7832}{LaTeX equivalent of ConTeXt buffers}
%
% \item \href{https://tex.stackexchange.com/q/215563/7832}{Storing an array of strings in a command}
%
% \item \href{https://tex.stackexchange.com/q/184503/7832}{Collecting contents of environment and store them for later retrieval}
%
% \item \href{https://tex.stackexchange.com/q/373647/7832}{Collect contents of an environment (that contains verbatim content)}
% \end{enumerate}
%
% \section{License and Requirements}
% \label{sec:licence}
%
% Permission is granted to copy, distribute and/or modify this software under
% the terms of the LaTeX Project Public License (lppl), version 1.3 or later
% (\url{http://www.latex-project.org/lppl.txt}). The software has the status
% \enquote{maintained}.
%
% \medskip
%
% The \mypkg*{scontents} package loads \mypkg{expl3}, \mypkg{xparse} and
% \mypkg{l3keys2e}. This package can be used with "xelatex", "lualatex"
% , "pdflatex" and the classical workflow §latex>dvips>ps2pdf§.
%
% \thispagestyle{plain}
%
% \newpage
%
% \pagestyle{myheader}
%
% \section{The \texttt{scontents} package}
% \label{sec:pkgscontents}
%
% \subsection{Description of the package and load}
%
% \begin{scontents}[store-env=description, print-env=true]
% The \mypkg*{scontents} package allows to \mymeta{store contents} in
% \mymeta{sequences} or \mymeta{external files}. In some ways it is
% similar to the \mypkg{filecontentsdef} package, with the difference
% in which the \mymeta{content} is stored. The idea behind this package
% is to get an approach to \hologo{ConTeXt} \enquote{\emph{buffers}}
% by making use \mymeta{sequences}.
% \end{scontents}
%
% The package uses a \myoarg{key \textnormal{\textcolor{gray}{=}} val}
% system for the options and is loaded in the usual way:
%
% \iffalse
%<*example>
% \fi
\begin{examplecode}[frame=single]
\usepackage{scontents}
\end{examplecode}
% \iffalse
%</example>
% \fi
% \vspace*{-5pt}
% or
% \iffalse
%<*example>
% \fi
\begin{examplecode}[frame=single]
\usepackage`\small\myoarg{key \textnormal{\textcolor{gray}{=}} val}`{scontents}
\end{examplecode}
% \iffalse
%</example>
% \fi
%
% \subsection{The TAB character}
% \label{sec:tabcharacter}
%
% Some users use horizontal "TAB"s \enquote{\LKeyTab} from keyboard to indented the source
% code of the document and depending on the text editor used, some will use real "TAB"s
% (\enquote{hard tabs}), others with \enquote{soft tabs}(\verbvisiblespace\verbvisiblespace{}
% or \verbvisiblespace\verbvisiblespace\verbvisiblespace\verbvisiblespace) or both.
%
% At first glance it may seem the same, but the way in which "TAB"s (\enquote{hard tabs})
% are processed according to the context in which they are found within
% a file, both in \mymeta{reading}\footnote{Check the answer given by Ulrich Diez
% in \href{https://tex.stackexchange.com/a/508103/7832}{Keyboard TAB
% character in argument v (xparse)}.} and \mymeta{writing}\footnote{Check the answer
% given by Enrico Gregorio in \href{https://tex.stackexchange.com/a/58740/7832}{How to output a
% tabulation into a file}.} are different and may have adverse consequences.
%
% In a standard \hologo{LaTeX} document, the character "TAB" \enquote{\LKeyTab}
% are treated as explicit spaces (in most contexts) and is the behavior when
% \mymeta{stored contents}, but when \mymeta{writing files} these are preserved.
%
% With a \hologo{TeX}Live distribution, the "TAB" character is \enquote{printable}
% for "latex", "pdflatex" and "lualatex", but if you use "xelatex" you
% must add the \texttt{\textcolor{optcolor}{-8bit}} option on the command
% line, otherwise you will get \hologo{TeX}-"TAB" (§^^I§) in the \mymeta{output file}.
%
% As a general recommendation \enquote{Do not use "TAB" character unless strictly
% necessary}, for example within a \emph{verbatim} environment that supports
% this character such as §Verbatim§ of the package \mypkg{fancyvrb} or §lstlisting§
% of the package \mypkg{listings} or when you want to generate a §MakeFile§ file.
%
% \subsection{Configuration of the options}
% \label{sec:confopt}
%
% Most of the options can be passed directly to the package or using the
% command \ics*{setupsc}. All boolean keys can be passed using the
% equal sign \enquote{\textnormal{\textcolor{optcolor}{=}}} or just the
% name of the key, all unknown keys will return an error. In this section
% are described some of the options, a summary of all options is shown in
% section \ref{sec:optover}.
%
% \vspace*{-10pt}
%
% \begin{function}{\setupsc}
%   \begin{syntax}
%       \cmdexamp{setupsc}{keyval list}
%   \end{syntax}
%
% The command \ics*{setupsc} sets the \mymeta{keys} in a global way,
% it can be used both in the preamble and in the body of the document
% as many times as desired.
% \end{function}
%
% \keyexamp{verb-font}{font family}{\textnormal{\ttfamily\textbackslash{}ttfamily}}
% Sets the \mymeta{font family} used to display the \mymeta{stored content} for the
% commands \ics*{typestored} and \ics*{meaningsc}. This key is only available
% as a package option or using \ics*{setupsc}.
%
% \medskip
%
% \keyexamp{store-all}{seq name}{not used}
% It is a \mymeta{meta-key} that sets the §store-env§ key of the \myenv*{scontents}
% environment and the §store-cmd§ key of the \ics*{Scontents} command. This key is
% only available as a package option or using \ics*{setupsc}.
%
% \medskip
%
% \keyexamp{print-all}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
% It is a \mymeta{meta-key} that sets the §print-env§ key of the \myenv*{scontents}
% environment and the §print-cmd§ key of the \ics*{Scontents} command. This key is
% only available as a package option or using \ics*{setupsc}.
%
% \medskip
%
% \keyexamp{force-eol}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
% Sets if the end of line for the \mymeta{stored content} is hidden or not.
% This key is necessary only if the last line is the closing of some
% environment defined by the \mypkg{fancyvrb} package as §\end{Verbatim}§
% or another environment that does not support a comments \enquote{\textcolor{gray}{\%}}
% after closing §\end{...}%§. This key is available for the \myenv*{scontents}
% environment and the \ics*{Scontents} command.
%
% \keyexamp{width-tab}{integer}{1}
% Sets the equivalence in \mymeta{spaces} for the character "TAB"
% used when displaying stored content in \emph{verbatim style}. The value
% must be a \mymeta{positive integer}. This key is available for the \ics*{typestored}
% and the \ics*{meaningsc} commands.
%
% \subsection{Options Overview}
% \label{sec:optover}
%
% \newcommand*{\xmark}{\textcolor{red}{✘}}%
% \newcommand*{\cmark}{\textcolor{green}{✔}}%
%
% Summary of available options.
%
% \setlength{\tabcolsep}{0.25em}
% \begin{center}
% \small
% \begin{tabular}{cccccccc}
% \toprule
% \texttt{key} &package &\ics{setupsc} &\myenv*{scontents} &\ics*{Scontents} &\ics*{Scontents*} &\ics*{typestored} &\ics*{meaningsc}\\
% \midrule
%  \texttt{store-env} & \cmark  & \cmark  &  \cmark  & \xmark  & \xmark  & \xmark  & \xmark \\
%  \texttt{store-cmd} & \cmark  & \cmark  &  \xmark  & \cmark  & \cmark  & \xmark  & \xmark \\
%  \texttt{print-env} & \cmark  & \cmark  &  \cmark  & \xmark  & \xmark  & \xmark  & \xmark \\
%  \texttt{print-cmd} & \cmark  & \cmark  &  \xmark  & \cmark  & \cmark  & \xmark  & \xmark \\
%  \texttt{print-all} & \cmark  & \cmark  &  \xmark  & \xmark  & \xmark  & \xmark  & \xmark \\
%  \texttt{store-all} & \cmark  & \cmark  &  \xmark  & \xmark  & \xmark  & \xmark  & \xmark \\
%  \texttt{write-env} & \xmark  & \xmark  &  \cmark  & \xmark  & \xmark  & \xmark  & \xmark \\
%  \texttt{write-out} & \xmark  & \xmark  &  \cmark  & \xmark  & \xmark  & \xmark  & \xmark \\
%  \texttt{width-tab} & \cmark  & \cmark  &  \xmark  & \xmark  & \xmark  & \cmark  & \cmark \\
%  \texttt{force-eol} & \cmark  & \cmark  &  \cmark  & \xmark  & \cmark  & \xmark  & \xmark \\
%  \texttt{verb-font} & \cmark  & \cmark  &  \xmark  & \xmark  & \xmark  & \xmark  & \xmark \\
% \bottomrule
% \end{tabular}
% \end{center}
%
% \section{User interface}
% \label{sec:interface}
%
% The user interface consists in \myenv*{scontents} environment, \ics*{Scontents}
% and \ics*{Scontents*} commands to \mymeta{stored content} and \ics*{getstored}
% command to get the \mymeta{stored content} along with other utilities described
% in this documentation.
%
% \subsection{The environment \env{scontents}}
% \label{sec:scontents}
%
% \vspace*{-10pt}
%
% \begin{function}{scontents}
%   \begin{syntax}
%   \envexamp{scontents}
%   \end{syntax}
%
% The \myenv*{scontents} environment allows you to \mymeta{store} and \mymeta{write}
% content, including \emph{verbatim} material. After the package has been loaded,
% the environment can be used both in the preamble and in the body of the document.
%
% For the correct operation §\begin{scontents}§ and §\end{scontents}§ must be in
% different lines, all \mymeta{keys} must be passed in a \mymeta{single line} separated
% by commas \enquote{without vertical spaces} and \enquote{without separation} of
% the start of the environment.
% \end{function}
%
% Comments \enquote{\textcolor{gray}{\%}} or \enquote{any character} after
% §\begin{scontents}§ or \myoarg{keyval list} on the same line are not
% supported, the package will return an \enquote{error} message if this happens.
% In a similar way comments \enquote{\textcolor{gray}{\%}} or \enquote{any character} after
% §\end{scontents}§ on the same line the package will return a \enquote{warning} message.
%
% The environment can be \mymeta{nested} if it is properly balanced and
% does not appear \enquote{literally} in commented lines or in some \emph{verbatim}
% environment or command. As an example:
%
% \iffalse
%<*example>
% \fi
\begin{examplecode}[frame=single]
\begin{scontents}[store-env=outer]
This text is in the outer environment (before nested).
\begin{scontents}[store-env=inner]
This text is found in the inner environment (inside of nested).
\end{scontents}
This text is in the outer environment (after nested).
\end{scontents}
\end{examplecode}
% \iffalse
%</example>
% \fi
%
% Of course, content stored in the \mymeta{inner} sequence is only available
% after content stored in the \mymeta{outer} sequence one has been retrieved,
% either by using the key §print-env§ or §\getstored§ command.
%
% It is advisable to store content within sequences with different names,
% so as not to get lost in the order in which content is stored.
%
% \subsection*{Options for environment}
%
% The environment options can be configured globally using option
% in package or the \ics*{setupsc} command and locally using
% \myoarg{key \textnormal{\textcolor{gray}{=}} val} in the environment.
% The key §force-eol§ is available for this environment.
%
% \keyexamp{store-env}{seq name}{contents}
% Sets the name of the \mymeta{sequence} in which the contents will be
% stored. If the sequence does not exist, it will be created globally.
%
% \medskip
%
% \keyexamp{print-env}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
% Sets if the \mymeta{stored content} is displayed or not at the time of
% running the environment. The content is extracted from the \mymeta{sequence}
% in which it is stored.
%
% \newpage
%
% \keyexamp{write-env}{file.ext}{not used}
% Sets the name of the \mymeta{external file} in which the \mymeta{contents} of
% the environment will be written. The \mymeta{file.ext} will be created
% in the working directory, if \mymeta{file.ext} exists it will be overwritten,
% relative or absolute paths are not supported.
% The characters "TAB"s will be written in \mymeta{file.ext} and the \mymeta{contents}
% will be stored in the sequence established at that time. \hologo{XeLaTeX} users
% using the "TAB" character must add \texttt{\textcolor{optcolor}{-8bit}}
% at the command line, otherwise you will get \hologo{TeX}-"TAB" (§^^I§)
% in \mymeta{file.ext}.
%
% \medskip
%
% \keyexamp{write-out}{file.ext}{not used}
% Sets the name of the \mymeta{external file} in which the \mymeta{contents} of
% the environment will be written. The \mymeta{file.ext} will be created
% in the working directory, if \mymeta{file.ext} exists it will be overwritten,
% relative or absolute paths are not supported.
% The characters "TAB"s will be written in \mymeta{file.ext}, the rest of the
% \mymeta{keys} will not be available and the \mymeta{contents} will NOT
% be stored in any sequence. \hologo{XeLaTeX} users using the "TAB" character
% must add \texttt{\textcolor{optcolor}{-8bit}} at the command line,
% otherwise you will get \hologo{TeX}-"TAB" (§^^I§) in \mymeta{file.ext}.
%
% \subsection{The command \cs{Scontents}}
% \label{sec:Scontents}
%
% \vspace*{-10pt}
%
% \begin{function}{\Scontents}
%   \begin{syntax}
%     \cmdexamp{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument}
%     \cmdexamp[*]{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument}
%     \cmdexamp[*]{Scontents}[key \textnormal{\textcolor{gray}{=}} val]{argument}[del]
%   \end{syntax}
% \end{function}
%
% The \ics*{Scontents} command reads the \mymarg{argument} in standard
% mode. It is not possible to pass environments such as \emph{verbatim},
% but it is possible to use the implementation of \ics{Verb} provided by
% the \mypkg{fvextra} package for contents on one line and \ics{lstinline}
% from \mypkg{listings} package, but it is preferable to use the starred
% version.
%
% The \ics*{Scontents*} command reads the \mymarg{argument} under \emph{verbatim}
% category code regimen. If its first delimiter is a brace, it will be
% assumed that the \mymarg{argument} is nested into braces. Otherwise it
% will be assumed that the ending of that \mymeta{argument} is delimited by that
% first delimiter \mymeta[cf=MediumOrchid]{del} like command \ics{verb}.
%
% Blank lines are preserved, escaped braces \enquote{\texttt{\textcolor{gray}{\textbackslash\hspace{-1pt}\{}}} and
% \enquote{\texttt{\textcolor{gray}{\textbackslash\}}}} must also be
% balanced if the argument is used with braces and "TAB"s characters typed
% from the keyboard are converted into spaces.
%
% Both versions can be used anywhere in the document and cannot be used
% as an \mymeta{argument} for other command.
%
% \subsection*{Options for command}
% \label{sec:optcmdsc}
%
% The command options can be configured globally using option in package
% or the \ics*{setupsc} command and locally using \myoarg{key \textnormal{\textcolor{gray}{=}} val}.
% The key §force-eol§ is available for this command.
%
% \keyexamp{store-cmd}{seq name}{contents}
% Sets the name of the \mymeta{sequence} in which the contents will be stored.
% If the sequence does not exist, it will be created globally.
%
% \medskip
%
% \keyexamp{print-cmd}{true \textnormal{\textcolor{lightgray}{\textbar}} false}{false}
% Sets if the \mymeta{stored content} is displayed or not at the time of
% running the command. The content is extracted from the \mymeta{sequence}
% in which it is stored.
%
% \subsection{The command \cs{getstored}}
% \label{sec:getstored}
%
% \vspace*{-10pt}
%
% \begin{function}{\getstored}
%   \begin{syntax}
%      \cmdexamp{getstored}[index]{seq name}
%   \end{syntax}
% \end{function}
%
% The command \ics*{getstored} gets the content stored in \mymeta{seq name}
% according to the \mymeta{index} in which it was stored. The command is
% robust and can be used as an \mymeta{argument} for another command. If the
% optional argument is not passed it defaults to the first element stored
% in the \mymeta{seq name}.
%
% \subsection{The command \cs{typestored}}
% \label{sec:typestored}
%
% \vspace*{-10pt}
%
% \begin{function}{\typestored}
%   \begin{syntax}
%      \cmdexamp{typestored}[index\textnormal{\textcolor{gray}{,}} width-tab \textnormal{\textcolor{gray}{=}} number]{seq name}
%   \end{syntax}
% The command \ics*{typestored} internally places the content stored in
% the \mymeta{seq name} into the \myenv*{verbatimsc} environment. The \mymeta{index}
% number corresponds to the position in which the content is stored in
% the \mymeta{seq name}.
% \end{function}
%
% If the optional argument is not passed it defaults to the first element
% stored in the \mymeta{seq name}. The key §width-tab§ is available for
% this command.
%
% The \mypkg{verbatim} package is not compatible with the implementation
% of the \myenv*{verbatimsc} environment used by this command, if you are
% a user of that package consider customizing the \myenv*{verbatimsc}
% environment.
%
% \newpage
%
% \subsection{The environment \env{verbatimsc}}
% \label{sec:verbatimsc}
%
% \vspace*{-10pt}
%
% \begin{function}{verbatimsc}
% Internal environment used by \ics*{typestored} to display \mymeta{verbatim style}
% contents.
% \end{function}
%
% One consideration to keep in mind is that this is a \emph{representation}
% of the \mymeta{stored content} in a \emph{verbatim} environment and not
% a real \emph{verbatim} environment.
%
%
% The \myenv*{verbatimsc} environment can be customized in the
% following ways:
%
% Using the package \mypkg{fancyvrb}:
% \iffalse
%<*example>
% \fi
\begin{examplecode}[frame=single]
\makeatletter
\let\verbatimsc\@undefined
\let\endverbatimsc\@undefined
\makeatother
\DefineVerbatimEnvironment{verbatimsc}{Verbatim}{numbers=left}
\end{examplecode}
% \iffalse
%</example>
% \fi
% Using the package \mypkg{minted}:
% \iffalse
%<*example>
% \fi
\begin{examplecode}[frame=single]
\makeatletter
\let\verbatimsc\@undefined
\let\endverbatimsc\@undefined
\makeatother
\usepackage{minted}
\newminted{tex}{linenos}
\newenvironment{verbatimsc}{\VerbatimEnvironment\begin{texcode}}{\end{texcode}}
\end{examplecode}
% \iffalse
%</example>
% \fi
% Using the package \mypkg{listings}:
% \iffalse
%<*example>
% \fi
\begin{examplecode}[frame=single]
\makeatletter
\let\verbatimsc\@undefined
\let\endverbatimsc\@undefined
\makeatother
\usepackage{listings}
\lstnewenvironment{verbatimsc}
  {
   \lstset{
           basicstyle=\small\ttfamily,
           columns=fullflexible,
           language=[LaTeX]TeX,
           numbers=left,
           numberstyle=\tiny\color{gray},
           keywordstyle=\color{red}
          }
  }{}
\end{examplecode}
% \iffalse
%</example>
% \fi
%
% \section{Other commands provided}
%
% \subsection{The command \cs{meaningsc}}
% \label{sec:meaningsc}
%
% \vspace*{-10pt}
%
% \begin{function}{\meaningsc}
%   \begin{syntax}
%      \cmdexamp{meaningsc}[index\textnormal{\textcolor{gray}{,}} width-tab \textnormal{\textcolor{gray}{=}} number]{seq name}
%   \end{syntax}
% The command \ics*{meaningsc} executes \ics{meaning} on the content stored
% in \mymeta{seq name}. The \mymeta{index} number corresponds to the position
% in which the content is stored in the \mymeta{seq name}.
% \end{function}
%
% If the optional argument is not passed it defaults to the first element
% stored in the \mymeta{seq name}. The key §width-tab§ is available for
% this command.
%
% \subsection{The command \cs{countsc}}
% \label{sec:countsc}
%
% \vspace*{-10pt}
%
% \begin{function}{\countsc}
%   \begin{syntax}
%      \cmdexamp{countsc}{seq name}
%   \end{syntax}
% The command \ics*{countsc} count a number of contents stored in \mymeta{seq name}.
% \end{function}
%
% \subsection{The command \cs{cleanseqsc}}
% \label{sec:cleansc}
%
% \vspace*{-10pt}
%
% \begin{function}{\cleanseqsc}
%   \begin{syntax}
%      \cmdexamp{cleanseqsc}{seq name}
%   \end{syntax}
% The command \ics*{cleanseqsc} remove all contents stored in \mymeta{seq name}.
% \end{function}
%
% \newpage
%
% \pdfstringdefDisableCommands{%
%      \RenewExpandableDocumentCommand{\mypkg}{sm}{#2}%
%    }
% \section{The \mypkg*{scontents} package in action}
% Remember the abstract on the first page?, this is it:
%
% \getstored{abstract}
%
% And the description of the package?
%
% \getstored{description}
%
% \medskip
%
% I've only written:
%
% \typestored{abstract}
%
% and
%
% \typestored{description}
%
% Of course, I didn't copy and paste. The real code they were written with is:
%
% \iffalse
%<*example>
% \fi
\begin{examplecode}[numbers=left]
\begin{scontents}[store-env=abstract,print-env=true]
\begin{abstract}
The \mypkg*{scontents} package stores valid \hologo{(La)TeX} code in
\mymeta{sequences} using the \mypkg{l3seq} module of \mypkg{expl3}.
The \mymeta{stored content}, including \emph{verbatim}, can be used
as many times as desired in the document, additionally can be written
to \mymeta{external files}.
\end{abstract}
\end{scontents}
\end{examplecode}
% \iffalse
%</example>
% \fi
%
% and
%
% \iffalse
%<*example>
% \fi
\begin{examplecode}[numbers=left]
\begin{scontents}[store-env=description, print-env=true]
The \mypkg*{scontents} package allows to \mymeta{store contents} in
\mymeta{sequences} or \mymeta{external files}. In some ways it is
similar to the \mypkg{filecontentsdef} package, with the difference
in which the \mymeta{content} is stored. The idea behind this package
is to get an approach to \hologo{ConTeXt} \enquote{\emph{buffers}}
by making use \mymeta{sequences}.
\end{scontents}
\end{examplecode}
% \iffalse
%</example>
% \fi
%
% I stored the content in memory and then ran §\getstored§ and
% §\typestored§. This is one of the ways you can use \mypkg*{scontents}.
%
% \newpage
%
% \section{Examples}
%
% These are some (adapted) examples that have served as inspiration for
% the creation of this package.
%
% \subsection{From answers package}
%
% \subsubsection*{Example 1}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp1.ltx]
\documentclass[12pt,a4paper]{article}
\usepackage[store-cmd=solutions]{scontents}
\usepackage{pgffor}
\newtheorem{ex}{Exercise}
\begin{document}
\section{Problems}
\begin{ex}
First exercise
\Scontents{
   First solution.
}
\end{ex}

\begin{ex}
Second exercise
\Scontents{
  Second solution.
}
\end{ex}

\section{Solutions}
\foreach \i in {1,...,\countsc{solutions}} {
\noindent\textbf{\i} \getstored[\i]{solutions}\par
}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Adaptation of example 1 (ansexam1) of the package \mypkg{answers}
% \textattachfile[color=0 0 1]{scexamp1.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp1.ltx}
%
% \subsection{From filecontentsdef package}
%
% \subsubsection*{Example 2}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp2.ltx]
\documentclass{article}
\usepackage[store-env=defexercise,store-cmd=defexercise]{scontents}
\usepackage{pgffor}
\pagestyle{empty}
\begin{document}
% not starred
\Scontents{
Prove that \[x^n+y^n=z^n\] is not solvable in positive integers if $n$ is at
most $-3$.\par
}
% starred
\Scontents*|Refute the existence of black holes in less than $140$ characters.|
% write environment to \jobname.txt
\begin{scontents}[write-env=\jobname.txt]
\def\NSA{NSA}%
Prove that factorization is easily done via probabilistic algorithms and
advance evidence from knowledge of the names of its employees in the
seventies that the \NSA\ has known that for 40 years.\par
\end{scontents}
% see all stored
\foreach \i in {1,...,3} {
\begin{itemize}
\item \getstored[\i]{defexercise}
\end{itemize}}
% \getstored are robust :)
\section{\getstored[2]{defexercise}}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Adaptation of example from package \mypkg{filecontentsdef}
% \textattachfile[color=0 0 1]{scexamp2.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp2.ltx}
%
% \subsection{From TeX-SX}
%
% \subsubsection*{Example 3}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp3.ltx]
\documentclass{article}
\usepackage[store-cmd=tikz]{scontents}
\usepackage{tikz}
\pagestyle{empty}
\Scontents*{\matrix{ \node (a) {$a$} ; & \node (b) {$b$} ; \\ } ;}
\Scontents*{\matrix[ampersand replacement=\&]
{ \node (a) {$a$} ; \& \node (b) {$b$} ; \\ } ;}
\Scontents*{\matrix{\node (a) {$a$} ; & \node (b) {$b$} ; \\ } ; }
\begin{document}
\section{tikzpicture}
\begin{tikzpicture}
\getstored[1]{tikz}
\end{tikzpicture}

\begin{tikzpicture}
\getstored[2]{tikz}
\end{tikzpicture}

\begin{tikzpicture}
\getstored[3]{tikz}
\end{tikzpicture}

\section{source}
\typestored[1]{tikz}
\typestored[2]{tikz}
\typestored[3]{tikz}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Adapted from \href{https://tex.stackexchange.com/q/5338/7832}{LaTeX equivalent of ConTeXt buffers}
% \textattachfile[color=0 0 1]{scexamp3.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp3.ltx}
%
% \subsubsection*{Example 4}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp4.ltx]
\documentclass{article}
\usepackage{scontents}
\usepackage{pgffor}
\pagestyle{empty}
\begin{document}
\begin{scontents}[store-env=a]
Something for a
\end{scontents}

\begin{scontents}[store-env=a]
Something for b
\end{scontents}

\begin{scontents}[store-env=a]
Something with no label
\end{scontents}

\textbf{Let's print them}

This is a: \getstored[1]{a}\par
This is b: \getstored[2]{a}

\textbf{Print all of them}

\foreach \i in {1,...,\countsc{a}} {\getstored[\i]{a}\par}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Adapted from \href{https://tex.stackexchange.com/q/184503/7832}{Collecting contents of environment and store them for later retrieval}
% \textattachfile[color=0 0 1]{scexamp4.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp4.ltx}
%
% \subsubsection*{Example 5}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp5.ltx]
\documentclass{article}
\usepackage{scontents}
\pagestyle{empty}
\setlength{\parindent}{0pt}
\begin{document}
\section{Problem stated the first time}
\begin{scontents}[print-env=true,store-env=problem]
This is normal text.
\verb|This is from the verb command.|
\verb*|This is from the verb* command.|
This is normal text.
\begin{verbatim}
This is from the verbatim environment:
&%{}~
\end{verbatim}
\end{scontents}
\section{Problem restated}
\getstored[1]{problem}
\section{Problem restated once more}
\getstored[1]{problem}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Adapted from \href{https://tex.stackexchange.com/q/373647/7832}{Collect contents of an environment (that contains verbatim content)}
% \textattachfile[color=0 0 1]{scexamp5.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp5.ltx}
%
% \subsection{Customization of verbatimsc}
%
% \subsubsection*{Example 6}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp6.ltx]
\documentclass{article}
\usepackage{scontents}
\makeatletter
\let\verbatimsc\@undefined
\let\endverbatimsc\@undefined
\makeatother
\usepackage{fvextra}
\usepackage{xcolor}
\definecolor{mygray}{gray}{0.9}
\usepackage{tcolorbox}
\newenvironment{verbatimsc}%
{\VerbatimEnvironment
\begin{tcolorbox}[colback=mygray, boxsep=0pt, arc=0pt, boxrule=0pt]
\begin{Verbatim}[fontsize=\scriptsize, breaklines, breakafter=*, breaksymbolsep=0.5em,
breakaftersymbolpre={\,\tiny\ensuremath{\rfloor}}]}%
{\end{Verbatim}%
\end{tcolorbox}}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\begin{document}
\section{Test \texttt{\textbackslash begin\{scontents\}} whit \texttt{fancyvrb}}
Test \verb+{scontents}+ \par

\begin{scontents}
Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+contents+
with index 1.

Prove new \Verb*{ fancyvrb whit braces } and environment \verb+Verbatim*+
\begin{verbatim}
 verbatim  environment
\end{verbatim}
\end{scontents}

\section{Test \texttt{\textbackslash Scontents} whit \texttt{fancyvrb}}
\Scontents{ We have coded this in \LaTeX: $E=mc^2$.}

\section{Test \texttt{\textbackslash getstored}}
\getstored[1]{contents}\par
\getstored[2]{contents}

\section{Test \texttt{\textbackslash meaningsc}}
\meaningsc[1]{contents}\par
\meaningsc[2]{contents}

\section{Test \texttt{\textbackslash typestored}}
\typestored[1]{contents}
\typestored[2]{contents}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Customization of \myenv*{verbatimsc} using the \mypkg{fancyvrb} and
% \mypkg{tcolorbox} package
% \textattachfile[color=0 0 1]{scexamp6.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp6.ltx}
%
% \subsubsection*{Example 7}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp7.ltx]
\documentclass{article}
\usepackage{scontents}
\makeatletter
\let\verbatimsc\@undefined
\let\endverbatimsc\@undefined
\makeatother
\usepackage{xcolor}
\usepackage{listings}
\lstnewenvironment{verbatimsc}
  {
   \lstset{
           basicstyle=\small\ttfamily,
           breaklines=true,
           columns=fullflexible,
           language=[LaTeX]TeX,
           numbers=left,
           numbersep=1em,
           numberstyle=\tiny\color{gray},
           keywordstyle=\color{red}
          }
  }{}
\setlength{\parindent}{0pt}
\pagestyle{empty}
\begin{document}
\section{Test \texttt{\textbackslash begin\{scontents\}} whit \texttt{listings}}
Test \verb+{scontents}+ \par

\begin{scontents}
Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+contents+ with index 1.\par

Prove \lstinline[basicstyle=\ttfamily]| lstinline | and environment \verb+Verbatim*+
\begin{verbatim}
  verbatim  environment
\end{verbatim}
\end{scontents}

\section{Test \texttt{\textbackslash Scontents*} whit \texttt{listings}}

\Scontents*+ We have coded this in \lstinline[basicstyle=\ttfamily]|\LaTeX: $E=mc^2$|
and more.+

\section{Test \texttt{\textbackslash getstored}}
\getstored[2]{contents}\par
\getstored[1]{contents}

\section{Test \texttt{\textbackslash typestored}}
\typestored[1]{contents}
\typestored[2]{contents}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Customization of \myenv*{verbatimsc} using the \mypkg{listings} package
% \textattachfile[color=0 0 1]{scexamp7.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp7.ltx}
%
% \subsubsection*{Example 8}
%
% \iffalse
%<*example>
% \fi
\begin{scontents}[write-out=scexamp8.ltx]
% need --shell-escape
\documentclass{article}
\usepackage{scontents}
\makeatletter
\let\verbatimsc\@undefined
\let\endverbatimsc\@undefined
\makeatother
\usepackage{minted}
\newminted{tex}{linenos}
\newenvironment{verbatimsc}{\VerbatimEnvironment\begin{texcode}}{\end{texcode}}
\pagestyle{empty}
\begin{document}
\section{Test \texttt{\textbackslash begin\{scontents\}} whit \texttt{minted}}
Test \verb+{scontents}+ \par

\begin{scontents}[write-env=usingtab.tex,force-eol=true]
Using \verb+scontents+ env no \verb+[key=val]+, save in seq \verb+contents+
with index 1.\par

Prove new \Verb*{ new fvextra whit braces } and environment \verb+Verbatim*+
% Real TABs here :)
\begin{Verbatim}[obeytabs, showtabs, tab=\rightarrowfill, tabcolor=red,showspaces, spacecolor=blue]
No tab
	One real tab
		Two real Tab plus 	one tab
\end{Verbatim}
\end{scontents}

\section{Test \texttt{\textbackslash Scontents} whit \texttt{minted}}

\Scontents{ We have coded \par this in \LaTeX: $E=mc^2$.}

\section{Test \texttt{\textbackslash getstored}}
\getstored[1]{contents}\par
\getstored[2]{contents}

\section{Test \texttt{\textbackslash typestored}}
\typestored[1]{contents}
\typestored[2]{contents}
\end{document}
\end{scontents}
% \iffalse
%</example>
% \fi
%
% Customization of \myenv*{verbatimsc} using the \mypkg{minted} package
% \textattachfile[color=0 0 1]{scexamp8.ltx}{\faFile*[regular]}.
% \lstinputlisting[language=scontents-doc,numbers=left]{scexamp8.ltx}
%
% \section{Change history}
% \label{sec:changes}
%
% In this section you will find some (not all) of the changes in \mypkg*{scontents}
% development, from the first public implementation using the \mypkg{filecontentsdef}
% package to the current version with only \mypkg{expl3}.
%
% \setlist[itemize,1]{label=\textendash,wide=0.5em,nosep,noitemsep,leftmargin=10pt}
% \newlength\descrwidth
% \settowidth{\descrwidth}{\textsf{v1.0, (ctan), 2019/07/30} }
%
% \begin{description}[font=\small\sffamily,wide=0pt,style=multiline,leftmargin=\descrwidth,nosep,noitemsep]
% \item [\fileversion{} (ctan), \filedate]
%    \begin{itemize}
%        \item Add |store-all| key.
%        \item Messages and keys were separated.
%        \item Restructuring of documentation.
%        \item Now the version of |expl3| is checked instead of |xparse|.
%        \item The internal behavior of \verb+force-eol+ has been modified.
%    \end{itemize}
% \item [v1.3 (ctan), 2019/09/24]
%    \begin{itemize}
%        \item The environment can now nest.
%        \item Added \verb+force-eol+, \verb+verb-font+ and \verb+width-tab+ keys.
%        \item The extra space has been removed when you run \verb+\getstored+.
%        \item Internal code has been rewritten more efficiently.
%        \item Remove \verb+\typestored*+.
%        \item Remove \verb+filecontentsdef+ dependency.
%        \item Changing \verb+\regex_replace_all:+ for \verb+\tl_replace_all:+.
%    \end{itemize}
% \item [v1.2 (ctan), 2019/08/28]
%    \begin{itemize}
%        \item Restructuring of documentation.
%        \item Added copy of \verb+\tex_scantokens:D+.
%    \end{itemize}
% \item [v1.1 (ctan), 2019/08/12]
%    \begin{itemize}
%        \item Extension of documentation.
%        \item Replace \verb+\tex_endinput:D+ by \verb+\file_input_stop:+.
%    \end{itemize}
% \item [v1.0 (ctan), 2019/07/30]
%    \begin{itemize}
%        \item First public release,
%    \end{itemize}
% \end{description}
%
% \newpage
%
% \printindex[userdoc]
%
% \newpage
%
% \StopEventually{^^A
% \newgeometry{top=0.5in,bottom=0.5in,left=1.0in,right=0.5in,footskip=0.2in,headsep=10pt}
% \addtocontents{toc}{\protect\setcounter{tocdepth}{2}}
% \cleardoublepage
% \phantomsection
% \printindex
% }
%
% \section{Implementation}
% \label{sec:Implementation}
% \addtocontents{toc}{\protect\setcounter{tocdepth}{0}}
%
% \iffalse
%<*package>
% \fi
%
% \subsection{Declaration of the package}
%
% First we set up the module name for \pkg{l3doc}:
%    \begin{macrocode}
%<@@=scontents>
%    \end{macrocode}
%
% Then, we can give the traditional declaration of a package written with
% \pkg{expl3} and the necessary packages for its operation.
%
%    \begin{macrocode}
\RequirePackage{l3keys2e}
\RequirePackage{xparse}[2019/05/28]
\ProvidesExplPackage{scontents}{2019/10/03}{1.4}
  {Stores LaTeX contents in memory or files}
%    \end{macrocode}
%
% A check to make sure that \pkg{expl3} is not too old
%
%    \begin{macrocode}
\@ifpackagelater { expl3 } { 2019/09/19 }
  { }
  {
    \PackageError { scontents } { Support~package~expl3~too~old }
      {
        You~need~to~update~your~installation~of~the~bundles~
        'l3kernel'~and~'l3packages'.\MessageBreak
        Loading~scontents~will~abort!
      }
    \file_input_stop:
  }
%    \end{macrocode}
%
% \subsection{Definition of common keys}
%
% We create some common \mymeta{keys} that will be used by the options passed to
% the package as well as by the environments and commands defined.
%
%    \begin{macrocode}
\keys_define:nn { scontents }
  {
    store-env .tl_set:N         = \l_@@_name_seq_env_tl,
    store-env .initial:n        = contents,
    store-env .value_required:n = true,
    store-cmd .tl_set:N         = \l_@@_name_seq_cmd_tl,
    store-cmd .initial:n        = contents,
    store-cmd .value_required:n = true,
    verb-font .tl_set:N         = \l_@@_verb_font_tl,
    verb-font .initial:n        = \ttfamily,
    verb-font .value_required:n = true,
    print-env .bool_set:N       = \l_@@_print_env_bool,
    print-env .initial:n        = false,
    print-env .default:n        = true,
    print-cmd .bool_set:N       = \l_@@_print_cmd_bool,
    print-cmd .initial:n        = false,
    print-cmd .default:n        = true,
    force-eol .bool_set:N       = \l_@@_forced_eol_bool,
    force-eol .initial:n        = false,
    force-eol .default:n        = true,
    width-tab .int_set:N        = \l_@@_tab_width_int,
    width-tab .initial:n        = 1,
    width-tab .value_required:n = true,
    print-all .meta:n           = { print-env = #1 , print-cmd = #1 },
    print-all .default:n        = true,
    store-all .meta:n           = { store-env = #1 , store-cmd = #1 },
    store-all .value_required:n = true
  }
%    \end{macrocode}
%
% We process the \mymeta{keys} as options passed on to the package, the
% package \pkg{l3keys2e} will verify the \mymeta{keys} and will return
% an error when they are \emph{unknown}.
%
%    \begin{macrocode}
\ProcessKeysOptions { scontents }
%    \end{macrocode}
%
% \subsection{Internal variables}
%
% Now we declare the internal variables we will use.
%
% \begin{macro}{\l_@@_macro_tmp_tl,\l_@@_fname_out_tl,\l_@@_temp_tl,
%     \l_@@_file_tl,\g_@@_temp_tl}
%   \cs{l_@@_macro_tmp_tl} is a temporary token list to hold the contents
%   of the macro/environment, \cs{l_@@_fname_out_tl} is used as the name
%   of the output file, when there's one, \cs{l_@@_file_tl} holds the contents
%   of an environment as it's being read, and \cs{l_@@_temp_tl} and
%   \cs{g_@@_temp_tl} are generic temporary token lists.
%
%    \begin{macrocode}
\tl_new:N \l_@@_macro_tmp_tl
\tl_new:N \l_@@_fname_out_tl
\tl_new:N \l_@@_temp_tl
\tl_new:N \l_@@_file_tl
\tl_new:N \g_@@_temp_tl
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_seq_item_int,\l_@@_env_nesting_int,\l_@@_tmpa_int}
%   \cs{l_@@_seq_item_int} stores the index in the sequence of the item
%   requested to \cs{typestored} or \cs{meaningsc}. \cs{l_@@_env_nesting_int}
%   stores the current nesting level of the \env{scontents} environment.
%
%    \begin{macrocode}
\int_new:N \l_@@_seq_item_int
\int_new:N \l_@@_env_nesting_int
\int_new:N \l_@@_tmpa_int
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_writing_bool,\l_@@_storing_bool}
%   The boolean \cs{l_@@_writing_bool} keeps track of whether we should write
%   to a file, and \cs{l_@@_storing_bool} determines whether it is in write-only
%   mode when the §write-out§ option is used.
%
%    \begin{macrocode}
\bool_new:N \l_@@_writing_bool
\bool_set_false:N \l_@@_writing_bool
\bool_new:N \l_@@_storing_bool
\bool_set_true:N  \l_@@_storing_bool
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\g_@@_end_verbatimsc_tl,\c_@@_end_env_tl}
%   A token list to match when ending \env{verbatimsc} and \env{scontents}
%   environments.
%
%    \begin{macrocode}
\tl_new:N \g_@@_end_verbatimsc_tl
\tl_gset_rescan:Nnn
  \g_@@_end_verbatimsc_tl
  {
    \char_set_catcode_other:N \\
    \char_set_catcode_other:N \{
    \char_set_catcode_other:N \}
  }
  { \end{verbatimsc} }
\tl_const:Nx \c_@@_end_env_tl
  { \c_backslash_str end \c_left_brace_str scontents \c_right_brace_str }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\c_@@_hidden_space_str}
%   \cs{c_@@_hidden_space_str} is a constant \emph{string} to used to hide
%   the \mymeta{forced space} added by \hologo{TeX} when recording content
%   in a macro. This \emph{string} contains the \emph{reserved phrase}
%   ``§%§§^^Ascheol%§'' which is added to the end of the argument stored
%   in |seq| when the key §force-eol§ is false.
%
%    \begin{macrocode}
\str_const:Nx \c_@@_hidden_space_str
  { \c_percent_str \c_circumflex_str \c_circumflex_str A scheol \c_percent_str }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\q_@@_stop,\q_@@_mark}
%   Some quarks used along the code as macro delimiters.
%
%    \begin{macrocode}
\quark_new:N \q_@@_stop
\quark_new:N \q_@@_mark
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\l_@@_file_iow}
%   An output stream for saving the contents of an environment to a file.
%
%    \begin{macrocode}
\iow_new:N \l_@@_file_iow
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_rescan_tokens:n}
%   \cs{tl_rescan:nn} doesn't fit the needs of this package because
%   it does not allow catcode changes inside the argument, so verbatim
%   commands used inside one of \mypkg*{scontents}'s commands/environments
%   will not work. Here we create a private copy of \cs{tex_scantokens:D}
%   which will serve our purposes.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_rescan_tokens:n #1 { \tex_scantokens:D {#1} }
\cs_generate_variant:Nn \@@_rescan_tokens:n { V, x }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_tab:,\@@_par:}
%   Control sequences to replace tab (§^^I§) and form feed (§^^L§) characters.
%
%    \begin{macrocode}
\cs_new:Npx \@@_tab: { \c_space_tl }
\cs_new:Npn \@@_par: { ^^J ^^J }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[int]{\tl_remove_once:NV,\tl_replace_all:Nxx,
%     \tl_replace_all:Nxn,\tl_replace_all:Nnx,\tl_if_empty:fTF}
%   Some nonstandard variants.
%
%    \begin{macrocode}
\cs_generate_variant:Nn \tl_remove_once:Nn { NV }
\cs_generate_variant:Nn \tl_replace_all:Nnn { Nx, Nxx, Nnx }
\prg_generate_conditional_variant:Nnn \tl_if_empty:n { f } { TF }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Defining keys for the environment and commands}
%
% We add the \mymeta{keys} divided into subgroups to handle errors and
% \emph{unknown} \mymeta{keys} separately.
%
% \subsubsection{Keys for environment \env{scontents}}
%
% We define a set of \mymeta{keys} for environment §scontents§.
%
%    \begin{macrocode}
\keys_define:nn { scontents / scontents }
  {
    write-env .code:n           = {
                                    \bool_set_true:N \l_@@_writing_bool
                                    \tl_set:Nn \l_@@_fname_out_tl {#1}
                                  },
    write-out .code:n           = {
                                    \bool_set_false:N \l_@@_storing_bool
                                    \bool_set_true:N  \l_@@_writing_bool
                                    \tl_set:Nn \l_@@_fname_out_tl {#1}
                                  },
    write-env .value_required:n = true,
    write-out .value_required:n = true,
    print-env .meta:nn          = { scontents } { print-env = #1 },
    print-env .default:n        = true,
    store-env .meta:nn          = { scontents } { store-env = #1 },
    force-eol .meta:nn          = { scontents } { force-eol = #1 },
    force-eol .default:n        = true,
    unknown   .code:n           = { \@@_parse_environment_keys:n {#1} }
  }
%    \end{macrocode}
%
% \subsubsection{Keys for command \cs{Scontents}}
%
% We define a set of \mymeta{keys} for commands §\Scontents§ and
% §\Scontents*§.
%
%    \begin{macrocode}
\keys_define:nn { scontents / Scontents }
  {
    print-cmd .meta:nn   = { scontents } { print-cmd = #1 },
    print-cmd .default:n = true,
    store-cmd .meta:nn   = { scontents } { store-cmd = #1 },
    force-eol .meta:nn   = { scontents } { force-eol = #1 },
    force-eol .default:n = true,
    unknown   .code:n    = { \@@_parse_command_keys:n {#1} }
  }
%    \end{macrocode}
%
% \subsubsection{Key for commands \cs{typestored} and \cs{meaningsc}}
%
% We define a \mymeta{key} for command §\typestored§ and §\meaningsc§.
% Both commands accept the same type of optional arguments, just define
% a common \mymeta{key}.
%
%    \begin{macrocode}
\keys_define:nn { scontents / typemeaning }
  {
    width-tab .meta:nn = { scontents } { width-tab = #1 },
    unknown   .code:n  = { \@@_parse_type_meaning_key:n {#1} }
  }
%    \end{macrocode}
%
% \subsection{Handling undefined keys}
%
% The \mymeta{keys} are stored in the token list variable \cs{l_keys_key_tl},
% and the value (if any) is passed as an argument to each \mymeta{function}.
%
% \subsubsection{Undefined keys for environment \env{scontents}}
%
% \begin{macro}{\@@_parse_environment_keys:n,
%               \@@_parse_environment_keys:nn}
%
%   We check the \mymeta{keys} passed to the environment
%   §scontents§ and process it with \cs{@@_parse_environment_keys:n}
%   if the \mymeta{key} is \emph{unknown} we return an error message.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_parse_environment_keys:n #1
  { \exp_args:NV \@@_parse_environment_keys:nn \l_keys_key_tl {#1} }
\cs_new_protected:Npn \@@_parse_environment_keys:nn #1#2
  {
    \tl_if_blank:nTF {#2}
      { \msg_error:nnn { scontents } { env-key-unknown } {#1} }
      { \msg_error:nnnn { scontents } { env-key-value-unknown } {#1} {#2} }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Undefined keys for \cs{Scontents} and \cs{Scontents*}}
%
% \begin{macro}{\@@_parse_command_keys:n,
%               \@@_parse_command_keys:nn}
%
%   We check the \meta{keys} passed to commands §\Scontents§ or
%   §\Scontents*§ and process it with \cs{@@_parse_command_keys:n}
%   if the \mymeta{key} is \emph{unknown} we return an error message.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_parse_command_keys:n #1
  { \exp_args:NV \@@_parse_command_keys:nn \l_keys_key_tl {#1} }
\cs_new_protected:Npn \@@_parse_command_keys:nn #1#2
  {
    \tl_if_blank:nTF {#2}
      { \msg_error:nnn { scontents } { cmd-key-unknown } {#1} }
      { \msg_error:nnnn { scontents } { cmd-key-value-unknown } {#1} {#2} }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{Undefined keys for \cs{typestored} and \cs{meaningsc}}
%
% \begin{macro}{\@@_parse_type_meaning_key:n,
%               \@@_parse_type_meaning_key:nn}
%
%   The commands §\typestored§ and §\meaningsc§ accept an optional
%   argument for setting the §width-tab§ to print the stored
%   contents. However their optional argument also contains the number
%   of the item to retrieve from the stored sequence. To avoid the
%   awkward §\typestored[]§\myoarg[type=tt]{options}§{...}§ syntax, we'll make the
%   commands have a single optional argument which is processed by
%   \pkg{l3keys}, and the unknown keys are brought here to
%   \cs{@@_parse_typemeaning_key:n} to process.
%
%   First we check if the \mymeta{key} is an integer using \cs{int_to_roman:n}.
%   If it is, we check that the value passed to the key is blank
%   (otherwise something odd as |1=1| might have been used). If everything
%   is correct, then set the value of the integer which holds the \mymeta{index}.
%   Otherwise raise an error about an \emph{unknown} option.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_parse_type_meaning_key:n #1
  { \exp_args:NV \@@_parse_type_meaning_key:nn \l_keys_key_tl {#1} }
\cs_new_protected:Npn \@@_parse_type_meaning_key:nn #1#2
  {
    \tl_if_empty:fTF { \int_to_roman:n { -0 #1 } }
      {
        \tl_if_blank:nTF {#2}
          { \int_set:Nn \l_@@_seq_item_int {#1} }
          { \msg_error:nnnn { scontents } { type-key-value-unknown } {#1} {#2} }
      }
      {
        \tl_if_blank:nTF {#2}
          { \msg_error:nnn { scontents } { type-key-unknown } {#1} }
          { \msg_error:nnnn { scontents } { type-key-value-unknown } {#1} {#2} }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Programming of the sequences}
%
%   The storage of the package is done using |seq| variables.  Here we
%   set up the macros that will manage the variables.
% \begin{macro}{\@@_append_contents:nn}
%   \cs{@@_append_contents:nn} creates a seq variable if one didn't
%   exist and appends the contents in the argument to the right of the
%   sequence.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_append_contents:nn #1#2
  {
    \tl_if_blank:nT {#1}
      { \msg_error:nn { scontents } { empty-store-cmd } }
    \seq_if_exist:cF { g_@@_name_#1_seq }
      { \seq_new:c { g_@@_name_#1_seq } }
    \seq_gput_right:cn { g_@@_name_#1_seq } {#2}
  }
\cs_generate_variant:Nn \@@_append_contents:nn { Vx }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_getfrom_seq:nn,\@@_getfrom_seq:nnn}
%   \cs{@@_getfrom_seq:nn} retrieves the saved item from the
%   sequence.
%
%    \begin{macrocode}
\cs_new:Npn \@@_getfrom_seq:nn #1#2
  {
    \seq_if_exist:cTF { g_@@_name_#2_seq }
      {
        \exp_args:Nf \@@_getfrom_seq:nnn
          { \seq_count:c { g_@@_name_#2_seq } }
          {#1} {#2}
      }
      { \msg_expandable_error:nnn { scontents } { undefined-storage } {#2} }
  }
\cs_new:Npn \@@_getfrom_seq:nnn #1#2#3
  {
    \bool_lazy_or:nnTF
      { \int_compare_p:nNn {#2} = { 0 } }
      { \int_compare_p:nNn { \int_abs:n {#2} } > {#1} }
      { \msg_expandable_error:nnnnn { scontents } { index-out-of-range } {#2} {#3} {#1} }
      { \seq_item:cn { g_@@_name_#3_seq } {#2} }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_lastfrom_seq:n}
%   \cs{@@_lastfrom_seq:n} retrieves the last saved item from the
%   sequence when \cs{l_@@__print_env_bool} or \cs{l_@@__print_cmd_bool}
%   is true.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_lastfrom_seq:n #1
  {
    \tl_gset:Nx \g_@@_temp_tl { \seq_item:cn { g_@@_name_#1_seq } {-1} }
    \group_insert_after:N \@@_rescan_tokens:V
    \group_insert_after:N \g_@@_temp_tl
    \group_insert_after:N \tl_gclear:N
    \group_insert_after:N \g_@@_temp_tl
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_store_to_seq:NN}
%   The \cs{@@_store_to_seq:NN} writes the recorded contents
%   in |#1| to the log and stores it in |#2|.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_store_to_seq:NN #1#2
  {
    \tl_log:N #1
    \@@_append_contents:Vx #2 { \exp_not:V #1 }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Construction of environment \env{scontents}}
%
% We define the environment \env{scontents}, next to the system
% \myoarg{key \textnormal{\textcolor{gray}{=}} val}. The environment
% is divided into three parts. This implementation is taken from answer
% by Enrico Gregorio in \url{https://tex.stackexchange.com/a/487746/7832}.
%
% \begin{macro}{scontents}
%   This is the main environment used in the document.
%
%    \begin{macrocode}
\NewDocumentEnvironment { scontents } { }
  {
    \char_set_catcode_active:N \^^M
    \@@_start_environment:w
  }
  {
    \@@_stop_environment:
    \@@_atend_environment:
  }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{key val for environment}
%
% Define a \myoarg{key \textnormal{\textcolor{gray}{=}} val} for
% environment \env{scontents}
%
% \begin{macro}{\@@_environment_inline:w,\@@_environment_keys:w,
%      \@@_environment_junk:nw,\@@_environment_junk:xw}
%   The macro \cs{@@_environment_inline:w} is called from the
%   \env{scontents} environment with the tokens following the
%   §\begin{scontents}§. If the immediate next token (ignoring spaces)
%   is a §[§, then we look for an optional argument delimited by a §]§.
%   All the remaining tokens are treated as junk and an error is raised
%   if they are non-blank.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_environment_inline:w
  {
    \peek_charcode_ignore_spaces:NTF [ % ]
      { \@@_environment_keys:w }
      {
        \@@_environment_junk:xw
          { after~\c_backslash_str begin{scontents} }
      }
  }
\cs_new_protected:Npn \@@_environment_keys:w [ #1 ]
  {
    \keys_set:nn { scontents / scontents } {#1}
    \@@_environment_junk:xw
      { after~optional~argument~to~\c_backslash_str begin{scontents} }
  }
\cs_new_protected:Npn \@@_environment_junk:nw #1 #2 \q_@@_mark
  {
    \tl_if_blank:nF {#2}
      { \msg_error:nnnn { scontents } { junk-after-begin } {#1} {#2} }
  }
\cs_generate_variant:Nn \@@_environment_junk:nw { x }
%    \end{macrocode}
% \end{macro}
%
% \subsubsection{The environment itself}
%
% \begin{macro}{\@@_start_environment:w,\@@_stop_environment:}
%   Here we make §^^I§, §^^L§ and §^^M§ active characters so that the end of
%   line can be \enquote{seen} to be used as a delimiter, and \hologo{TeX} doesn't try to
%   eliminate space-like characters.  First we check if the line
%   directly after §\begin{scontents}§ contains an optional argument
%   enclosed in §[...]§ or other tokens. The trailing tokens are
%   treated as junk and an error is raised.  The
%   \cs{@@_environment_inline:w} macro checks for those cases.
%
%   \cs{@@_start_environment:w} calls the \cs{@@_file_tl_write_start:V}
%   function, which will then read the contents of the environment and
%   optionally store them in a token list or write to an external file.
%
%   When that's done, \cs{@@_file_write_stop:N} does the cleanup and the
%   read token list is smuggled out of the verbatim group. This part of
%   the code is inspired and adapted from the code of the package \pkg{xsimverb}
%   by Clemens Niederberger.
%
%^^A Hm... Apparently this is not the verbatim group, but one level above. Is
%^^A this group really necessary?
%^^A Reply : I've checked it several times, it seems to be correct.
%
%    \begin{macrocode}
\group_begin:
  \char_set_catcode_active:N \^^I
  \char_set_catcode_active:N \^^L
  \char_set_catcode_active:N \^^M
  \cs_new_protected:Npn \@@_start_environment:w #1 ^^M
    {
      \@@_environment_inline:w #1 \q_@@_mark
      \@@_make_control_chars_active:
      \group_begin:
        \@@_file_tl_write_start:V \l_@@_fname_out_tl
    }
  \cs_new_protected:Npn \@@_stop_environment:
    {
        \@@_file_write_stop:N \l_@@_macro_tmp_tl
        \exp_args:NNNV
      \group_end:
      \tl_set:Nn \l_@@_macro_tmp_tl \l_@@_macro_tmp_tl
    }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{
%     \@@_file_tl_write_start:n,
%     \@@_file_tl_write_start:V,
%     \@@_verb_processor_iterate:w,
%     \@@_file_write_stop:N,
%     \@@_remove_leading_nl:n,
%     \@@_remove_leading_nl:w,
%   }
%   This is the main macro to collect the contents of a verbatim environment.
%   The macro starts a group, opens the output file, if necessary, sets verbatim
%   catcodes, and then issues §^^M§ (set equal to \cs{@@_ret:w}) to read the
%   environment line by line until reaching its end. The output token list will
%   be appended with an active §^^J§ character and the line just read, and this
%   line is written to the output file, if any. At the end of the environment
%   the output file is closed (if it was open), and the output token list is
%   smuggled out of the verbatim group. A leading §^^J§ is removed from the
%   token list using \cs{@@_remove_leading_nl:n} (which expects an active §^^J§
%   token at the head of the token list; a low level \hologo{TeX} error is raised
%   otherwise).
%
%    \begin{macrocode}
  \cs_new_protected:Npn \@@_file_tl_write_start:n #1
    {
      \group_begin:
        \bool_if:NT \l_@@_writing_bool
          {
            \file_if_exist:nTF {#1}
              { \msg_warning:nnx { scontents } { rewriting-file } {#1} }
              { \msg_warning:nnx { scontents } { writing-file } {#1} }
            \iow_open:Nn \l_@@_file_iow {#1}
          }
        \tl_clear:N \l_@@_file_tl
        \seq_map_function:NN \l_char_special_seq \char_set_catcode_other:N
        \int_step_function:nnN { 128 } { 255 } \char_set_catcode_letter:n
        \cs_set_protected:Npx \@@_ret:w ##1 ^^M
          {
            \exp_not:N \@@_verb_processor_iterate:w
            ##1 \c_@@_end_env_tl
                \c_@@_end_env_tl
                \exp_not:N \q_@@_stop
          }
        \@@_make_control_chars_active:
        \@@_ret:w
    }
  \use:x
    {
      \cs_new:Npn \exp_not:N \@@_verb_processor_iterate:w
        ##1 \c_@@_end_env_tl
        ##2 \c_@@_end_env_tl
        ##3 \exp_not:N \q_@@_stop
    } {
        \tl_if_blank:nTF {#3}
          {
            \@@_analyse_nesting:n {#1}
            \@@_verb_processor_output:n {#1}
          }
          {
            \@@_if_nested:TF
              {
                \@@_nesting_decr:
                \@@_verb_processor_output:x
                  { \exp_not:n {#1} \c_@@_end_env_tl \exp_not:n {#2} }
              }
              {
                \tl_if_blank:nF {#1}
                  { \@@_verb_processor_output:n {#1} }
                \cs_set_protected:Npx \@@_ret:w
                  {
                    \exp_not:N \end{scontents}
                    \bool_lazy_or:nnF
                      { \tl_if_blank_p:n {#2} }
                      { \str_if_eq_p:ee {#2} { \c_percent_str } }
                      {
                        \msg_warning:nnn { scontents } { rescanning-text } {#2}
                        \@@_rescan_tokens:n {#2}
                      }
                  }
                \char_set_active_eq:NN ^^M \@@_ret:w
              }
          }
        ^^M
      }
  \cs_new_protected:Npn \@@_file_write_stop:N #1
    {
      \bool_if:NT \l_@@_writing_bool
        { \iow_close:N \l_@@_file_iow }
      \use:x
        {
          \group_end:
          \bool_if:NT \l_@@_storing_bool
            {
              \tl_set:Nn \exp_not:N #1
                { \exp_args:NV \@@_remove_leading_nl:n \l_@@_file_tl }
            }
        }
    }
  \cs_new:Npn \@@_remove_leading_nl:n #1
    { \exp_not:o { \@@_remove_leading_nl:w #1 } }
  \cs_new:Npn \@@_remove_leading_nl:w ^^J { }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{
%     \@@_verb_processor_output:n,
%     \@@_verb_processor_output:x,
%     \@@_analyse_nesting:n,
%     \@@_analyse_nesting:w,
%     \@@_nesting_decr:,
%     \@@_use_none_delimit_by_q_stop:w,
%   }
% \begin{macro}[TF]{\@@_if_nested:}
%   \cs{@@_verb_processor_output:n} does the output of each line read,
%   to a token list and to a file, depending on the booleans
%   \cs{l_@@_writing_bool} and \cs{l_@@_storing_bool}.
%
%   \cs{@@_analyse_nesting:n} looks for nested §\begin{scontents}§
%   and adds to a \cs{l_@@_env_nesting_int} counter. The \cs{@@_if_nested:}
%   conditional tests if we're in a nested environment, and
%   \cs{@@_nesting_decr:} reduces the nesting level, if an §\end{scontents}§
%   is found.
%
%   Multiple §\end{scontents}§ in the same line are not supported...
%    \begin{macrocode}
  \cs_new_protected:Npn \@@_verb_processor_output:n #1
    {
      \bool_if:NT \l_@@_writing_bool
        { \iow_now:Nn \l_@@_file_iow {#1} }
      \bool_if:NT \l_@@_storing_bool
        { \tl_put_right:Nn \l_@@_file_tl { ^^J #1 } }
    }
  \cs_generate_variant:Nn \@@_verb_processor_output:n { x }
  \cs_new_protected:Npx \@@_analyse_nesting:n #1
    {
      \int_zero:N \l_@@_tmpa_int
      \exp_not:N \@@_analyse_nesting:w #1
        \c_backslash_str begin
          \c_left_brace_str \exp_not:N \q_@@_mark \c_right_brace_str
      \exp_not:N \q_@@_stop
      \int_compare:nNnT { \l_@@_tmpa_int } > { 1 }
        { \msg_warning:nn { scontents } { multiple-begin } }
    }
  \use:x
    {
      \cs_new_protected:Npn \exp_not:N \@@_analyse_nesting:w ##1
        \c_backslash_str begin \c_left_brace_str ##2 \c_right_brace_str
    }   {
          \if_meaning:w \q_@@_mark #2
            \exp_after:wN \use_i:nn
          \else:
            \exp_after:wN \use_ii:nn
          \fi:
            { \@@_use_none_delimit_by_q_stop:w }
            {
              \str_if_eq:eeT {#2} {scontents}
                {
                  \int_incr:N \l_@@_env_nesting_int
                  \int_incr:N \l_@@_tmpa_int
                  \@@_analyse_nesting:w
                }
              \@@_analyse_nesting:w
            }
        }
  \cs_new_protected:Npn \@@_nesting_decr:
    { \int_decr:N \l_@@_env_nesting_int }
  \prg_new_protected_conditional:Npnn \@@_if_nested: { TF }
    {
      \int_compare:nNnTF { \l_@@_env_nesting_int } > { \c_zero_int }
        { \prg_return_true: }
        { \prg_return_false: }
    }
  \cs_new:Npn \@@_use_none_delimit_by_q_stop:w #1 \q_@@_stop { }
\group_end:
\cs_generate_variant:Nn \@@_file_tl_write_start:n { V }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsubsection{Recording of the content in the sequence}
%
% \begin{macro}{\@@_atend_environment:}
%   Finishes the environment by optionally calling \cs{@@_store_to_seq:}
%   and then clearing the temporary token list.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_atend_environment:
  {
    \bool_if:NT \l_@@_storing_bool
      {
        \bool_if:NF \l_@@_forced_eol_bool
          { \tl_put_right:Nx \l_@@_macro_tmp_tl { \c_@@_hidden_space_str } }
        \@@_store_to_seq:NN \l_@@_macro_tmp_tl \l_@@_name_seq_env_tl
        \bool_if:NT \l_@@_print_env_bool
          { \@@_lastfrom_seq:n \l_@@_name_seq_env_tl }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \cs{Scontents} command}
%
% User command to \mymeta{stored content}, adapted from
% \url{https://tex.stackexchange.com/a/500281/7832}.
%
% \begin{macro}{\Scontents,\@@_norm_arg:n,\@@_verb_arg:w}
%   The §\Scontents§ macro starts by parsing an optional argument and
%   then delegates to \cs{@@_verb_arg:w} or \cs{@@_norm_arg:n} depending whether
%   a star (§*§) argument is present.
%
%   \cs{@@_norm_arg:n} grabs a normal argument, adds it to the |seq| varaible,
%   and optionally prints it.
%
%   \cs{@@_verb_arg:w} grabs a verbatim argument using \pkg{xparse}'s |+v|
%   argument parser.
%
%    \begin{macrocode}
\NewDocumentCommand { \Scontents }{ !s !O{} }
  {
    \group_begin:
      \IfNoValueF {#2}
        { \keys_set:nn { scontents / Scontents } {#2} }
      \char_set_catcode_active:n { 9 }
      \IfBooleanTF {#1}
        { \@@_verb_arg:w }
        { \@@_norm_arg:n }
  }
\cs_new_protected:Npn \@@_norm_arg:n #1
  {
      \tl_set:Nx \l_@@_temp_tl { \exp_not:n {#1} }
      \tl_put_right:Nx \l_@@_temp_tl { \c_@@_hidden_space_str }
      \@@_store_to_seq:NN \l_@@_temp_tl \l_@@_name_seq_cmd_tl
      \bool_if:NT \l_@@_print_cmd_bool
        { \@@_lastfrom_seq:n \l_@@_name_seq_cmd_tl }
    \group_end:
  }
\NewDocumentCommand { \@@_verb_arg:w } { +v }
  {
      \tl_set:Nx \l_@@_temp_tl { \exp_not:n {#1} }
      \tl_replace_all:Nxx \l_@@_temp_tl { \iow_char:N \^^M } { \iow_char:N \^^J }
      \bool_if:NF \l_@@_forced_eol_bool
        { \tl_put_right:Nx \l_@@_temp_tl { \c_@@_hidden_space_str } }
      \@@_store_to_seq:NN \l_@@_temp_tl \l_@@_name_seq_cmd_tl
      \bool_if:NT \l_@@_print_cmd_bool
        { \@@_lastfrom_seq:n \l_@@_name_seq_cmd_tl }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{The command \cs{getstored}}
%
% \begin{macro}{\getstored}
%   User command §\getstored§ to extract \mymeta{stored content} in |seq|
%   (robust).
%
%    \begin{macrocode}
\NewDocumentCommand { \getstored } { O{1} m }
  {
    \group_begin:
      \@@_rescan_tokens:x
        { \@@_getfrom_seq:nn {#1} {#2} }
    \group_end:
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{The \cs{typestored} command}
%
% This implementation is an adaptation taken from answer by Phelype Oleinik
% in (\url{https://tex.stackexchange.com/a/497651/7832}).
%
% \begin{macro}{\typestored,\@@_verb_print:N,\@@_xverb:w,verbatimsc}
%   The §\typestored§ commands fetches a buffer from memory, prints it
%   to the log file, and then calls \cs{@@_verb_print:N}.
%
%    \begin{macrocode}
\NewDocumentCommand { \typestored } { o m }
  {
    \group_begin:
      \int_set:Nn \l_@@_seq_item_int { 1 }
      \IfValueT {#1} { \keys_set:nn { scontents / typemeaning } {#1} }
      \tl_set:Nx \l_@@_temp_tl
        {
          \exp_args:NV \@@_getfrom_seq:nn \l_@@_seq_item_int {#2}
        }
      \tl_remove_once:NV \l_@@_temp_tl \c_@@_hidden_space_str
      \tl_log:N \l_@@_temp_tl
      \tl_if_empty:NF \l_@@_temp_tl
        { \@@_verb_print:N \l_@@_temp_tl }
    \group_end:
  }
%    \end{macrocode}
%
%   The \cs{@@_verb_print:N} macro is defined with active carriage return
%   (\textsc{ascii} 13) characters to mimick an actual verbatim environment
%   \enquote{on the loose}. The contents of the environment are placed in a
%   §verbatimsc§ environment and rescanned using \cs{@@_rescan_tokens:x}.
%
%    \begin{macrocode}
\group_begin:
  \char_set_catcode_active:N \^^M
  \cs_new_protected:Npn \@@_verb_print:N #1
    {
      \tl_if_blank:VT #1
        { \msg_error:nnn { scontents } { empty-variable } {#1} }
      \cs_set_eq:NN \@@_verb_print_EOL: ^^M
      \cs_set_eq:NN ^^M \scan_stop:
      \cs_set_eq:cN { do@noligs } \@@_do_noligs:N
      \@@_rescan_tokens:x
        {
          \exp_not:N \begin{verbatimsc} ^^M
          \exp_not:V #1 ^^M
          \g_@@_end_verbatimsc_tl
        }
      \cs_set_eq:NN ^^M \@@_verb_print_EOL:
    }
\group_end:
%    \end{macrocode}
%
%   Finally, the §verbatimsc§ environment is defined.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_xverb:
  {
    \char_set_catcode_active:n { 9 }
    \char_set_active_eq:nN { 9 } \@@_tabs_to_spaces:
    \@@_xverb:w
  }
\use:x
  {
    \cs_new_protected:Npn \exp_not:N \@@_xverb:w
      ##1 \g_@@_end_verbatimsc_tl
  }
      { #1 \end{verbatimsc} }
\NewDocumentEnvironment { verbatimsc } { }
  {
    \cs_set_eq:cN { @xverbatim } \@@_xverb:
    \verbatim
  }
  { }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Some auxiliaries}
%
% \begin{macro}{\@@_tabs_to_spaces:}
%   In a verbatim context the |TAB| character is made active and set
%   equal to \cs{@@_tabs_to_spaces:}, to produce as many spaces as
%   the §width-tab§ key was set to.
%
%    \begin{macrocode}
\cs_new:Npn \@@_tabs_to_spaces:
  { \prg_replicate:nn { \l_@@_tab_width_int } { ~ } }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_do_noligs:N}
%   \cs{@@_do_noligs:N} is an alternative definition for \LaTeXe's
%   \cs{do@noligs} which makes sure to not consume following space
%   tokens. The \LaTeXe{} version ends with \cs{char}|`#1|, which
%   leaves \TeX{} still looking for an \mymeta{optional~space}.
%   This version uses \cs{char_generate:nn} to ensure that doesn't
%   happen.
%
%    \begin{macrocode}
\cs_new:Npn \@@_do_noligs:N #1
  {
    \char_set_catcode_active:N #1
    \char_set_active_eq:Nc #1 { @@_active_char_ \token_to_str:N #1 : }
    \cs_set:cpx { @@_active_char_ \token_to_str:N #1 : }
      {
        \mode_leave_vertical:
        \tex_kern:D \c_zero_dim
        \char_generate:nn { `#1 } { 12 }
      }
  }
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{
%     \@@_set_active_eq:NN,
%     \@@_make_control_chars_active:,
%   }
%   Shortcut definitions for common catcode changes.
%
%    \begin{macrocode}
\cs_new_protected:Npn \@@_set_active_eq:NN #1
  {
    \char_set_catcode_active:N #1
    \char_set_active_eq:NN #1
  }
\cs_new_protected:Npn \@@_make_control_chars_active:
  {
    \@@_set_active_eq:NN \^^I \@@_tab:
    \@@_set_active_eq:NN \^^L \@@_par:
    \@@_set_active_eq:NN \^^M \@@_ret:w
  }
%    \end{macrocode}
% \end{macro}
%
% \subsection{The command \cs{setupsc}}
%
% User command §\setupsc§ to setup module.
%
% \begin{macro}{\setupsc}
%   A user-level wrapper for \cs{keys_set:nn}§{ scontents }§.
%
%    \begin{macrocode}
\NewDocumentCommand { \setupsc } { +m }
  { \keys_set:nn { scontents } {#1} }
%    \end{macrocode}
% \end{macro}
%
% \subsection{The command meaningsc}
%
% \begin{macro}{\meaningsc}
%   User command §\meaningsc§ to see content stored in |seq|.
%
%    \begin{macrocode}
\NewDocumentCommand { \meaningsc } { o m }
  {
    \group_begin:
      \int_set:Nn \l_@@_seq_item_int { 1 }
      \IfValueT {#1} { \keys_set:nn {  scontents / typemeaning } {#1} }
      \@@_meaningsc:n {#2}
    \group_end:
  }
\group_begin:
  \char_set_catcode_active:N \^^I
  \cs_new_protected:Npn \@@_meaningsc:n #1
    {
      \tl_set:Nx \l_@@_temp_tl
        {
          \exp_args:NV \@@_getfrom_seq:nn \l_@@_seq_item_int {#1}
        }
      \tl_replace_all:Nxn \l_@@_temp_tl { \iow_char:N \^^J } { ~ }
      \tl_remove_once:NV  \l_@@_temp_tl \c_@@_hidden_space_str
      \tl_log:N \l_@@_temp_tl
      \tl_use:N \l_@@_verb_font_tl
      \tl_replace_all:Nnx \l_@@_temp_tl { ^^I } { \@@_tabs_to_spaces: }
      \cs_replacement_spec:N \l_@@_temp_tl
    }
\group_end:
%    \end{macrocode}
% \end{macro}
%
% \subsection{The command \cs{countsc}}
%
%
% \begin{macro}{\countsc}
%   User command §\countsc§ to count number of contents stored in |seq|.
%
%    \begin{macrocode}
\NewExpandableDocumentCommand { \countsc } { m }
  { \seq_count:c { g_@@_name_#1_seq } }
%    \end{macrocode}
% \end{macro}
%
% \subsection{The command \cs{cleanseqsc}}
%
%
% \begin{macro}{\cleanseqsc}
%   A user command §\cleanseqsc§ to clear (remove) a defined |seq|.
%
%    \begin{macrocode}
\NewDocumentCommand { \cleanseqsc } { m }
  { \seq_clear_new:c { g_@@_name_#1_seq } }
%    \end{macrocode}
% \end{macro}
%
% \subsection{Warning and error messages}
%
% Warning and error messages used throughout the package.
%
%    \begin{macrocode}
\msg_new:nnn { scontents } { junk-after-begin }
  {
    Junk~characters~#1~\msg_line_context: :
    \\ \\
    #2
  }
\msg_new:nnn { scontents } { empty-stored-content }
  { Empty~value~for~key~'getstored'~\msg_line_context:. }
\msg_new:nnn { scontents } { empty-variable }
  { Variable~'#1'~empty~\msg_line_context:. }
\msg_new:nnn { scontents } { rewriting-file }
  { Overwriting ~ file ~ '#1' }
\msg_new:nnn { scontents } { writing-file }
  { Writing ~ file ~ '#1' }
\msg_new:nnn { scontents } { rescanning-text }
  { Rescanning~text~'#1'~after~\c_backslash_str end{scontents}~\msg_line_context:.}
\msg_new:nnn { scontents } { multiple-begin }
  { Multiple~\c_backslash_str begin{scontents}~\msg_line_context:.}
\msg_new:nnn { scontents } { undefined-storage }
  { Storage~named~'#1'~is~not~defined. }
\msg_new:nnn { scontents } { index-out-of-range }
  {
    \int_compare:nNnTF {#1} = { 0 }
      { Index~of~sequence~cannot~be~zero. }
      {
        Index~'#1'~out~of~range~for~'#2'.~
        \int_compare:nNnTF {#1} > { 0 }
          { Max = } { Min = -} #3.
      }
  }
\msg_new:nnnn { scontents } { env-key-unknown }
  { The~key~'#1'~is~unknown~by~environment~'scontents'~and~is~being~ignored.}
  {
    The~environment~'scontents'~does~not~have~a~key~called~'#1'.\\
    Check~that~you~have~spelled~the~key~name~correctly.
  }
\msg_new:nnnn { scontents } { env-key-value-unknown }
  { The~key~'#1=#2'~is~unknown~by~environment~'scontents'~and~is~being~ignored. }
  {
    The~environment~'scontents'~does~not~have~a~key~called~'#1'.\\
    Check~that~you~have~spelled~the~key~name~correctly.
  }
\msg_new:nnnn { scontents } { cmd-key-unknown }
  { The~key~'#1'~is~unknown~by~'\c_backslash_str Scontents'~and~is~being~ignored.}
  {
    The~command~'\c_backslash_str Scontents'~does~not~have~a~key~called~'#1'.\\
    Check~that~you~have~spelled~the~key~name~correctly.
  }
\msg_new:nnnn { scontents } { cmd-key-value-unknown }
  { The~key~'#1=#2'~is~unknown~by~'\c_backslash_str Scontents'~and~is~being~ignored. }
  {
    The~command~'\c_backslash_str Scontents'~does~not~have~a~key~called~'#1'.\\
    Check~that~you~have~spelled~the~key~name~correctly.
  }
\msg_new:nnnn { scontents } { type-key-unknown }
  { The~key~'#1'~is~unknown~and~is~being~ignored. }
  {
    This~command~does~not~have~a~key~called~'#1'.\\
    This~command~only~accepts~the~key~'width-tab'.
  }
\msg_new:nnnn { scontents } { type-key-value-unknown }
  { The~key~'#1'~to~which~you~passed~'#2'~is~unknown~and~is~being~ignored. }
  {
    This~command~does~not~have~a~key~called~'#1'.\\
    This~command~only~accepts~the~key~'width-tab'.
  }
%    \end{macrocode}
%
% \subsection{Finish package}
%
% Finish package implementation.
%
%    \begin{macrocode}
\file_input_stop:
%    \end{macrocode}
% \iffalse
%</package>
% \fi
% \Finale