summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/semantex/semantex.tex
blob: c273d1dcecf3e4550f5200ea0f2aa8de0034afcf (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
\documentclass[a4paper,article,oneside,english,10pt]{memoir}

\makeatletter

\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage[noDcommand,slantedGreeks]{kpfonts}

\frenchspacing

\usepackage{mathtools,etoolbox,	microtype,xspace,color}

\usepackage[shortlabels]{enumitem}%control lists

\usepackage[draft]{fixme}

%Setup of memoir:
\pagestyle{plain} %change to heading for running headings
\nouppercaseheads %running heads should not be capitalized
\captionnamefont{\small} %captions with small font
\captiontitlefont{\small}
\makeevenhead{headings}{\thepage}{}{\itshape\leftmark} %make headings italic instead of slanted (though we do not use headings right now)
\makeoddhead{headings}{\itshape\rightmark}{}{\thepage}

\raggedbottomsectiontrue%less harse than \raggedbottom
%\allowdisplaybreaks %long equations may break

\g@addto@macro\bfseries{\boldmath} %make math in bold text automatically bold

\usepackage[english=american]{csquotes}

\usepackage[hidelinks]{hyperref}
	
\usepackage[nameinlink]{cleveref}

\title{Seman\!\TeX: Semantic mathematics (v$0.2\alpha$)}
\date{\today}
\author{Sebastian Ørsted (\href{mailto:sorsted@gmail.com}{sorsted@gmail.com})}

\hypersetup{
	pdfauthor={Sebastian Ørsted},
	pdftitle={SemanTeX: Object-oriented mathematics},
	%pdfsubject={},
	%pdfkeywords={},
	%pdfproducer={Latex with hyperref, or other system},
	%pdfcreator={pdflatex, or other tool},
}




% Settup up SemanTeX:

\usepackage{semantex}

\NewVariableClass\MyVar[
	output=\MyVar,
]

\NewObject\MyVar\va{a}
\NewObject\MyVar\vb{b}
\NewObject\MyVar\vc{c}
\NewObject\MyVar\vd{d}
\NewObject\MyVar\ve{e}
\NewObject\MyVar\vf{f}
\NewObject\MyVar\vg{g}
\NewObject\MyVar\vh{h}
\NewObject\MyVar\vi{i}
\NewObject\MyVar\vj{j}
\NewObject\MyVar\vk{k}
\NewObject\MyVar\vl{l}
\NewObject\MyVar\vm{m}
\NewObject\MyVar\vn{n}
\NewObject\MyVar\vo{o}
\NewObject\MyVar\vp{p}
\NewObject\MyVar\vq{q}
\NewObject\MyVar\vr{r}
\NewObject\MyVar\vs{s}
\NewObject\MyVar\vt{t}
\NewObject\MyVar\vu{u}
\NewObject\MyVar\vv{v}
\NewObject\MyVar\vw{w}
\NewObject\MyVar\vx{x}
\NewObject\MyVar\vy{y}
\NewObject\MyVar\vz{z}

\NewObject\MyVar\vA{A}
\NewObject\MyVar\vB{B}
\NewObject\MyVar\vC{C}
\NewObject\MyVar\vD{D}
\NewObject\MyVar\vE{E}
\NewObject\MyVar\vF{F}
\NewObject\MyVar\vG{G}
\NewObject\MyVar\vH{H}
\NewObject\MyVar\vI{I}
\NewObject\MyVar\vJ{J}
\NewObject\MyVar\vK{K}
\NewObject\MyVar\vL{L}
\NewObject\MyVar\vM{M}
\NewObject\MyVar\vN{N}
\NewObject\MyVar\vO{O}
\NewObject\MyVar\vP{P}
\NewObject\MyVar\vQ{Q}
\NewObject\MyVar\vR{R}
\NewObject\MyVar\vS{S}
\NewObject\MyVar\vT{T}
\NewObject\MyVar\vU{U}
\NewObject\MyVar\vV{V}
\NewObject\MyVar\vW{W}
\NewObject\MyVar\vX{X}
\NewObject\MyVar\vY{Y}
\NewObject\MyVar\vZ{Z}

\NewObject\MyVar\valpha{\alpha}
\NewObject\MyVar\vvaralpha{\varalpha}
\NewObject\MyVar\vbeta{\beta}
\NewObject\MyVar\vgamma{\gamma}
\NewObject\MyVar\vdelta{\delta}
\NewObject\MyVar\vepsilon{\epsilon}
\NewObject\MyVar\vvarepsilon{\varepsilon}
\NewObject\MyVar\vzeta{\zeta}
\NewObject\MyVar\veta{\eta}
\NewObject\MyVar\vtheta{\theta}
\NewObject\MyVar\viota{\iota}
\NewObject\MyVar\vkappa{\kappa}
\NewObject\MyVar\vlambda{\lambda}
\NewObject\MyVar\vmu{\mu}
\NewObject\MyVar\vnu{\nu}
\NewObject\MyVar\vxi{\xi}
\NewObject\MyVar\vpi{\pi}
\NewObject\MyVar\vvarpi{\varpi}
\NewObject\MyVar\vrho{\rho}
\NewObject\MyVar\vsigma{\sigma}
\NewObject\MyVar\vtau{\tau}
\NewObject\MyVar\vupsilon{\upsilon}
\NewObject\MyVar\vphi{\phi}
\NewObject\MyVar\vvarphi{\varphi}
\NewObject\MyVar\vchi{\chi}
\NewObject\MyVar\vpsi{\psi}
\NewObject\MyVar\vomega{\omega}

\NewObject\MyVar\vGamma{\Gamma}
\NewObject\MyVar\vDelta{\Delta}
\NewObject\MyVar\vTheta{\Theta}
\NewObject\MyVar\vLambda{\Lambda}
\NewObject\MyVar\vXi{\Xi}
\NewObject\MyVar\vPi{\Pi}
\NewObject\MyVar\vSigma{\Sigma}
\NewObject\MyVar\vUpsilon{\Upsilon}
\NewObject\MyVar\vPhi{\Phi}
\NewObject\MyVar\vPsi{\Psi}
\NewObject\MyVar\vOmega{\Omega}

\NewObject\MyVar\sheafF{\mathcal{F}}
\NewObject\MyVar\sheafG{\mathcal{G}}
\NewObject\MyVar\sheafreg{\mathcal{O}}
\NewObject\MyVar\sheafHom{\mathop{\mathcal{H}om}}

\NewObject\MyVar\Hom{\operatorname{Hom}}

\NewCohomologyClass\MyCohomology[
	parent=\MyVar,
	gradingposition=upper,
]

\NewCohomologyClass\MyHomology[
	parent=\MyCohomology,
	gradingposition=lower,
]

\NewObject\MyCohomology\co{H}

\NewObject\MyHomology\ho{H}

\usepackage{showexpl,newunicodechar}

\newunicodechar{⟨}{\textlangle}
\newunicodechar{⟩}{\textrangle}

\makeatother

\begin{document}

\maketitle

\lstset{%
	language=[LaTeX]TeX,
	basicstyle=\ttfamily\small,
	commentstyle=\itshape\ttfamily\small,
	extendedchars=true,
	breaklines=true,
	breakindent={0pt},
	captionpos=t,
	pos=r,
	tabsize=2,
	inputencoding=utf8,
	extendedchars=true,
	explpreset={numbers=none,},
	literate={⟨}{\textlangle}1 {⟩}{\textrangle}1,
}



\newcommand\mybs{$\backslash$}

\newcommand\commandname[1]{\mybs\texttt{#1}}

\let\pack=\texttt

\newcommand\semantex{Seman\!\TeX\xspace}

\noindent
The \semantex package for \LaTeX\ delivers a more semantic, systematized way of writing mathematics, compared to the classical math syntax in~\LaTeX.
The system uses keyval syntax and is highly customizable. At the same time, care has been taken to make it the syntax as simple, natural, practical, and lightweight as possible.
\textbf{Note: \semantex is still in its alpha stage and cannot be considered stable at this point. You are more than welcome to report bugs and come with suggestions!}

\begingroup
	\SetupClass\MyVar{
		singlekeys={
			{conj}{overline},
			{inv}{upper={-1}},
			{inverseimage}{upper={-1},nopar},
		},
		valuekeys={
			{der}{upper={ (#1) } },
			{res}{ return ,symbolputright ={|}, lower ={#1} },
			{stalk}{clower={#1}},
			% "clower" means "comma lower", i.e. lower index
			% separated from any previous lower index by a comma
		},
	}
	
	
	Let us take an example from elementary analysis
	to demonstrate the idea of the package:
	Suppose we want to take the complex conjugate of a function~\( \vf \)
	and then derive it \( \vn \)~times, i.e.~take~\( \smash{ \vf[conj,der=\vn] } \).
	\semantex allows you to typeset this something like this:
\begin{LTXexample}
$ \vf[conj,der=\vn] $
\end{LTXexample}
	I shall explain the syntax in detail below, but some immediate comments are in order: First and foremost, the~\lstinline!v!
	in the command names \lstinline!\vf! and~\lstinline!\vn! stands for~\enquote{variable}, so these commands are the
	variables \( \vf \) and~\( \vn \).
	In \semantex, it is usually best to create
	commands \lstinline!\va!, \lstinline!\vA!, \lstinline!\vb!, \lstinline!\vB!, \ldots
	for each variable you are using, upper- and lowercase.
	However, it is completely up to the user how to do that and what to call them.
	Note also that all of the keys
	\lstinline!inv!,~\lstinline!res!,~etc.\ are defined by the
	\emph{user}, and they can be modified and adjusted for all sorts of situations in any kinds of mathematics.
	In other words, for the most part, you get to choose your own syntax.
	
	Next, suppose we want to invert a function~\( \vg \) and restrict it to a subset~\( \vU \), and then apply it to~\( \vx \),
	i.e.~take~\( \vg[inv,res=\vU]{\vx} \). This can be done by writing
\begin{LTXexample}
$ \vg[inv,res=\vU]{\vx} $
\end{LTXexample}
	
	Next, let us take an example from algebraic geometry:
	Suppose \( \sheafF \)~is a sheaf and \( \vh \)~a~map,
	and that we want to typeset the
	equation~\( \smash{
		\vh[inverseimage]{\sheafF}[
			spar,stalk=\vp]
		=
		\sheafF[stalk=\vh{\vp}]
	} \),
	saying that the stalk of the inverse image~\( \vh[inverseimage]{\sheafF} \)
	at the point~\( \vp \) is~\( \smash{ \sheafF[stalk=\vh{\vp}] } \).
	This can be accomplished by typing
\begin{LTXexample}
$ \vh[inverseimage]{\sheafF}[spar,stalk=\vp]
=
\sheafF[stalk=\vh{\vp}] $
\end{LTXexample}
	Here, \lstinline!spar! (an abbreviation for~\enquote{symbol parentheses})
	is the key that adds the parentheses around~\( \vh[inverseimage]{\sheafF} \).
	
	Let us see how you could set up all the above notation:
\begin{lstlisting}
\documentclass{article}

\usepackage{amsmath,semantex}

\NewVariableClass\MyVar % creates a new class of variables, called "\MyVar"

% Now we create a couple of variables of the class \MyVar:
\NewObject\MyVar\vf{f}
\NewObject\MyVarr\vg{g}
\NewObject\MyVar\vh{h}
\NewObject\MyVar\sheafF{\mathcal{F}}

% Now we set up the class \MyVar:
\SetupClass\MyVar{
	output=\MyVar,	% This means that the output of an object
                 	% of class \MyVar is also of class \MyVar
	% We add a few keys for use with the class \MyVar:
	singlekeys={ % keys taking no values
		{inv}{upper={-1}},
		{conj}{overline},
		{inverseimage}{upper={-1},nopar},
	},
	valuekeys={ % keys taking a value
		{der}{upper={(#1)}},
		{stalk}{clower={#1}},
		% "clower" means "comma lower", i.e. lower index
		% separated from any previous lower index by a comma
		{res}{ return ,symbolputright ={|}, lower ={#1} },
	},
}
\end{lstlisting}
\endgroup

%\begingroup
%	\SetupClass\MyVar{
%		singlekeys={
%			{inverseimage}{upper={-1},nopar},
%		},
%		valuekeys={
%			{stalk}{lower=#1},
%			{res}{ return,symbolputright={|}, lower={#1} },
%		},
%		argvaluekeys={
%			{coef}{othersep={;}{#1}},
%		},
%	}
%	
%	Traditional math notation in \TeX\ is not particularly semantic -- you usually type the raw \emph{notation} rather than the underlying
%	\emph{meaning} of your math.
%	Take, for instance, the following equations from algebraic geometry:
%	\begin{align*}
%		\vf[inverseimage]{\sheafF}[spar,stalk=\vp]
%		&=
%		\sheafF[stalk=\vf{\vp}] ,
%	\\
%		\sheafreg[\vU]
%		&=
%		\sheafreg[\vX,res=\vU] ,
%	\\
%		\sheafHom{ \sheafF , \sheafG }{\vU}
%		&=
%		\Hom[\sheafreg[\vU]]{ \sheafF[res=\vU] , \sheafG[res=\vU] } ,
%	\\
%		\co{0}{\vU,coef=\sheafreg[\vX]}
%		&= \sheafreg[\vX]{\vU} 
%		.
%	\end{align*}
%	Here, \( \sheafF \) and~\( \sheafG \)
%	are sheaves on some scheme~\( \vX \),
%	\( \sheafreg[\vX] \)~is the structure sheaf,
%	and~\( \vU \subset \vX \) an open subset.
%	In traditional \TeX, you would probably define a collection of commands \lstinline!\sheafF!, \lstinline!\sheafG!, \lstinline!\sheafreg!, and~\lstinline!\sheafHom! for~\( \sheafF \),~\( \sheafG \), \( \sheafreg \), and~\( \sheafHom \) and then proceed
%	something like
%	\begin{lstlisting}
%(f^{-1}\sheafF)_{p}=\sheafF_{f(p)},
%\sheafreg_{U} = \sheafreg_{X}|_{U},
%\sheafHom( \sheafF , \sheafG)(U)
%	= \Hom_{\sheafreg_{X} ( \sheafF|_{U} , \sheafG|_{V} ),
%	H^{0}(U;\sheafF) = \sheafF(U).
%	\end{lstlisting}
%	For more than~90~\% of all mathematicians, this solution will be completely satisfactory; it prints what it is supposed to, and that's that.
%	If this is how you feel, there is absolutely no reason for you to continue reading. This package is for the remaining less than~10~\% who would prefer to write
%	something like the following instead:
%	\begin{lstlisting}
%\vf[inverseimage]{ \sheafF }[spar,stalk=\vp]
%	= \sheafF[ stalk=\vf{\vp} ] ,
%\sheafreg[\vU] = \sheafreg[ \vX, res=\vU ],
%\sheafHom{ \sheafF , \sheafG }{\vU}
%	= \Hom[\sheafreg[\vU]]{ \sheafF[res=\vU],	\sheafG[res=\vU] },
%\co{0}{ \vU, coef=\sheafreg[\vX] } = \sheafreg[\vX]{\vU}.
%	\end{lstlisting}
%	
%	A lot of comments are in order.
%	The whole syntax will be explained in later chapters, but let us take a moment to look at these examples and understand the logic.
%	First of all, what is up with all the~\lstinline!v!'s in the command names \lstinline!\vf!, \lstinline!\vX!, \lstinline!\vU!? The~\lstinline!v!~stands for \textquote{variable}, and it is the prefix I recommend using for all standard variables. So for all letters in the alphabet, uppercase and lowercase, as well as the Greek ones, there will be a command: \lstinline!\va!, \lstinline!\vA!, \lstinline!\vb!, \lstinline!\vB!,~etc.
%	It is not always necessary to use them; for instance, in the above example, both \lstinline!\vX! and \lstinline!\vU! could have been replaced by simply~\lstinline!X!,~\lstinline!U! without changing anything. This is because we did not apply any arguments to these symbols. However, for the sake of consistency, I prefer to switch completely to using commands instead of writing the symbols directly.
%	How \emph{you} use the system is completely up to you.
%	
%	In \semantex, all entries are being built up from the inside and out.
%	The basic syntax layout for most \semantex commands is
%	\begin{lstlisting}
%\⟨object⟩[⟨options⟩]{⟨argument⟩}
%	\end{lstlisting}
%	Let us try focusing on the first example from above:
%	\begin{LTXexample}
%$\vf[inverseimage]{\sheafF}[spar,stalk=\vp]$
%	\end{LTXexample}
%	You always start with a central piece: a \emph{⟨symbol⟩}.
%	In the case of~\lstinline!\vf!, the symbol is~\( f \). After the symbol follows the options we apply to it, written in brackets~\lstinline![...]!. In this case, we the option~\lstinline!inverseimage!. This tells \semantex that we want the inverse image functor~\( \vf[inverseimage] \), so it adds a superscript~\lstinline!-1! to the symbol. After this, we apply the function~\lstinline!\vf[inverseimage]! to something, namely the sheaf~{$\sheafF$}. This is done by enclosing them in braces~\lstinline!{...}!.\footnote{You should be aware that this argument in braces~\texttt{\{...\}} is \emph{optional}. You can simply write~\texttt{$\backslash$vf[inverseimage]} if you want, and it will produce~\smash{\( \vf[inverseimage] \)}.}
%	
%	
%	Next, we want to take the stalk of this sheaf at the point~\( \vp \). If we simply wrote~\lstinline!\vf[inverseimage]{\sheafF}[stalk=\vp]!, we would get~\smash{\( \vf[inverseimage]{\sheafF}[stalk=\vp] \)}, which looks confusing. So we want to enclose~\smash{\( \vf[inverseimage]{\sheafF} \)} in parentheses before taking the stalk. This is done with the key~\lstinline!spar! (an abbreviation for \textquote{symbol parentheses}).
%	This key takes whatever has been typed so far, symbol and indices, and adds parentheses around it (of course, type and size is adjustable).
%	This~\lstinline!spar! is a key you fill find yourself using a lot.
%\endgroup

\chapter{Getting started}

To get started using \semantex, load down the package
with
\begin{lstlisting}
\usepackage{semantex}
\end{lstlisting}
The \semantex system is object-oriented; all entities are objects of some class. When you load the package, there
is only one class by default, which is simply called \lstinline!\SemantexVariable!.
You should think of this as a low-level class, the parent of all other classes. Therefore, I highly advice against using it directly or modifying it.
Instead, we create a new, more high-level variable class.
We choose to call it \lstinline!\MyVar!.
It is best to always start class names with uppercase letters to separate them from objects.
We could write \lstinline!\NewVariableClass\MyVar!, but we choose to
pass some options to it in~\lstinline![...]!:
\begin{lstlisting}
\NewVariableClass\MyVar[output=\MyVar]
\end{lstlisting}
This \lstinline!output=\MyVar! option will be explained better below.
Roughly speaking, it tells \semantex that everything
a variable \emph{outputs} will also be a variable.
For instance, if the function~\lstinline!\vf! (i.e.~\( \vf \)) is of class~\lstinline!\MyVar!,
then \lstinline!\vf{\vx}!~(i.e.~\( \vf{\vx} \))~will also of class~\lstinline!\MyVar!.

Now we have a class, but we do not have any objects.
To create the object~\lstinline!\vf! of class~\lstinline!\MyVar! with symbol~\( f \),
we write~\lstinline!\NewObject\MyVar\vf{f}!.
In general, when you have class~\lstinline!\⟨Class⟩!, you
can create objects of that class wtih the syntax
\begin{lstlisting}
\NewObject\⟨Class⟩\⟨object⟩{⟨object symbol⟩}[⟨options⟩]
\end{lstlisting}
To distinguish objects from classes, it is a good idea to denote
objects by lowercase letters.\footnote{We shall not follow this convention strictly, as we shall later create objects with names like~\commandname{Hom}; using lowercase letters for these would just look weird.}
So after writing,
\begin{lstlisting}
\NewObject\MyVar\vf{f}
\NewObject\MyVar\vx{x}
\end{lstlisting}
we get two variables \lstinline!\vf! and~\lstinline!\vx! with symbols \( f \) resp.~\( x \).
Let us perform a stupid test to see if the variables work:
\begin{LTXexample}
$\vf$, $\vx$
\end{LTXexample}
Th general syntax of a variable-type object is
\begin{lstlisting}
\⟨object⟩[⟨options⟩]{⟨argument⟩}
\end{lstlisting}
Both \lstinline!⟨options⟩! and \lstinline!⟨argument⟩! are optional
arguments (they can be left out if you do not need them).
The \lstinline!⟨options⟩! should consist of a list of options separated by commas, using keyval syntax. On the other hand, \lstinline!⟨argument⟩! is the actual argument of the function.
By design, \semantex does not distinguish between variables and functions, so all variables can take arguments.
This is a design choice to make the system easier to use; after all, it is fairly common in mathematics that something is first a variable and then a moment later takes an argument.
So we may write:
\begin{LTXexample}
$\vf{1}$, $\vf{\vx}$,
$\vx{\vx}$
\end{LTXexample}

So far, we do not have very many options to write in the
\lstinline!⟨options⟩! position, since we have not added any keys yet. However, we do have access
to the most important of all options: the \emph{index}.
There is a simple shortcut for writing an index: You simply write the index itself in the options tag:
\begin{LTXexample}
$\vf[1]$, $\vf[\vf]$,
$\vf[1,2,\vf]{2}$
\end{LTXexample}
As long as what you write in the options tag is not recognized as a predefined key, it will be printed as the index.
Other than that, there are two important predefined keys: \lstinline!upper! and \lstinline!lower! which simply add something to the upper and lower index:
\begin{LTXexample}
$\vf[upper=2]$,
$\vf[lower=3]$
\end{LTXexample}

We are soon going to need more variables
than just \( \vf \) and~\( \vx \).
In fact, I advise you to create a variable for each letter in the Latin and Greek alphabets, both uppercase and lowercase.
This is pretty time-consuming, so I did it for you already:
\begin{lstlisting}
\NewObject\MyVar\va{a}
\NewObject\MyVar\vb{b}
\NewObject\MyVar\vc{c}
\NewObject\MyVar\vd{d}
\NewObject\MyVar\ve{e}
\NewObject\MyVar\vf{f}
\NewObject\MyVar\vg{g}
\NewObject\MyVar\vh{h}
\NewObject\MyVar\vi{i}
\NewObject\MyVar\vj{j}
\NewObject\MyVar\vk{k}
\NewObject\MyVar\vl{l}
\NewObject\MyVar\vm{m}
\NewObject\MyVar\vn{n}
\NewObject\MyVar\vo{o}
\NewObject\MyVar\vp{p}
\NewObject\MyVar\vq{q}
\NewObject\MyVar\vr{r}
\NewObject\MyVar\vs{s}
\NewObject\MyVar\vt{t}
\NewObject\MyVar\vu{u}
\NewObject\MyVar\vv{v}
\NewObject\MyVar\vw{w}
\NewObject\MyVar\vx{x}
\NewObject\MyVar\vy{y}
\NewObject\MyVar\vz{z}

\NewObject\MyVar\vA{A}
\NewObject\MyVar\vB{B}
\NewObject\MyVar\vC{C}
\NewObject\MyVar\vD{D}
\NewObject\MyVar\vE{E}
\NewObject\MyVar\vF{F}
\NewObject\MyVar\vG{G}
\NewObject\MyVar\vH{H}
\NewObject\MyVar\vI{I}
\NewObject\MyVar\vJ{J}
\NewObject\MyVar\vK{K}
\NewObject\MyVar\vL{L}
\NewObject\MyVar\vM{M}
\NewObject\MyVar\vN{N}
\NewObject\MyVar\vO{O}
\NewObject\MyVar\vP{P}
\NewObject\MyVar\vQ{Q}
\NewObject\MyVar\vR{R}
\NewObject\MyVar\vS{S}
\NewObject\MyVar\vT{T}
\NewObject\MyVar\vU{U}
\NewObject\MyVar\vV{V}
\NewObject\MyVar\vW{W}
\NewObject\MyVar\vX{X}
\NewObject\MyVar\vY{Y}
\NewObject\MyVar\vZ{Z}

\NewObject\MyVar\valpha{\alpha}
\NewObject\MyVar\vvaralpha{\varalpha}
\NewObject\MyVar\vbeta{\beta}
\NewObject\MyVar\vgamma{\gamma}
\NewObject\MyVar\vdelta{\delta}
\NewObject\MyVar\vepsilon{\epsilon}
\NewObject\MyVar\vvarepsilon{\varepsilon}
\NewObject\MyVar\vzeta{\zeta}
\NewObject\MyVar\veta{\eta}
\NewObject\MyVar\vtheta{\theta}
\NewObject\MyVar\viota{\iota}
\NewObject\MyVar\vkappa{\kappa}
\NewObject\MyVar\vlambda{\lambda}
\NewObject\MyVar\vmu{\mu}
\NewObject\MyVar\vnu{\nu}
\NewObject\MyVar\vxi{\xi}
\NewObject\MyVar\vpi{\pi}
\NewObject\MyVar\vvarpi{\varpi}
\NewObject\MyVar\vrho{\rho}
\NewObject\MyVar\vsigma{\sigma}
\NewObject\MyVar\vtau{\tau}
\NewObject\MyVar\vupsilon{\upsilon}
\NewObject\MyVar\vphi{\phi}
\NewObject\MyVar\vvarphi{\varphi}
\NewObject\MyVar\vchi{\chi}
\NewObject\MyVar\vpsi{\psi}
\NewObject\MyVar\vomega{\omega}

\NewObject\MyVar\vGamma{\Gamma}
\NewObject\MyVar\vDelta{\Delta}
\NewObject\MyVar\vTheta{\Theta}
\NewObject\MyVar\vLambda{\Lambda}
\NewObject\MyVar\vXi{\Xi}
\NewObject\MyVar\vPi{\Pi}
\NewObject\MyVar\vSigma{\Sigma}
\NewObject\MyVar\vUpsilon{\Upsilon}
\NewObject\MyVar\vPhi{\Phi}
\NewObject\MyVar\vPsi{\Psi}
\NewObject\MyVar\vOmega{\Omega}
\end{lstlisting}

Just like~\lstinline!\vf!, these can all be regarded as functions, so~\lstinline!\va{\vb}!~produces~\( \va{\vb} \).
Importantly,
\textbf{parentheses can be scaled}.
To make parentheses bigger, use the following keys:
\begin{LTXexample}
$\vf{\vx}$,
$\vf[par=\big]{\vx}$,
$\vf[par=\Big]{\vx}$,
$\vf[par=\bigg]{\vx}$,
$\vf[par=\Bigg]{\vx}$,
$\vf[par=auto]{\frac{1}{2}}$
\end{LTXexample}
Using \lstinline!par=auto! corresponds to using \lstinline!\left...\right!. Just as for ordinary math, I advice you to use manual scaling rather than automatic scaling, as \TeX\ has a tendency to scale things wrong. If you do not want parentheses at all, you can pass the key~\lstinline!nopar! (it will still print parentheses if there is more than one argument, though; to exclude this behaviour, run~\lstinline!neverpar! instead):
\begin{LTXexample}
$\vf[nopar]{\vx}$
\end{LTXexample}
Primes are added via the key~\lstinline!prime!
or the keys~\lstinline!'!,~\lstinline!''! and~\lstinline!'''!:
\begin{LTXexample}
$\vf['] = \vf[prime]$,
$\vf[''] = \vf[prime,prime]$
$\vf['''] = \vf[prime,prime,prime]$
\end{LTXexample}

So far, so good, but our variables cannot really do anything yet. For this, we need to assign \emph{keys} to them. The more pieces of math notation you need, the more keys you will have to define.
Keys are being added via two different keys:
\begin{center}
	\lstinline!singlekeys!
	\qquad\qquad and \qquad\qquad
	\lstinline!valuekeys!.
\end{center}
In short, \lstinline!singlekeys! is for keys that do \emph{not} take a value (i.e.~keys using the syntax~\lstinline!\⟨object⟩[key]!), and \lstinline!valuekeys! is for keys that \emph{do} take a value
(i.e.~keys using the syntax~\lstinline!\⟨object⟩[key=value]!)).
We explain the syntax for using them in the next section where we show how to make keyval syntax for elementary calculus.

\begingroup\color{red}%
For the rest of the manual, we assume that you have already defined a class~\lstinline!\MyVar! and the variables~\lstinline!\va!, \lstinline!\vA!, \lstinline!\vb!, \lstinline!\vB!, \ldots, as above.
\endgroup

\chapter{Example: Elementary calculus}

One thing we might want to do to a variable
is \emph{invert} it. We therefore add a key~\lstinline!inv!
that adds an upper index~\lstinline!-1! to the symbol.
We add this key using the key \lstinline!singlekeys!,
which is for keys that do not take a value:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{inv}{ upper={-1} },
	},
}
\end{lstlisting}
\SetupClass\MyVar{
singlekeys={
	{inv}{ upper={-1} },
},
}
Now the key \lstinline!inv!
has been defined to be equivalent to \lstinline!upper={-1}!.
Now we can do the following:
\begin{LTXexample}
$\va[inv]$, $\vf[inv]$,
$\vg[1,2,inv]$,
$\vh[\va,\vb,inv]$
\end{LTXexample}

Other keys might need to take a value.
For defining such, we have the command~\lstinline!valuekeys!.
%There are two different keys for adding new keys
%to a class: \lstinline!singlekeys! and \lstinline!valuekeys!.
%The difference is that
For instance, suppose we want a command for deriving a function \( n \)~times.
For this, we add the key~\lstinline!der!:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{inv}{ upper={-1} },
	},
	valuekeys={
		{der}{ upper={(#1)} },
	},
}
\end{lstlisting}
\SetupClass\MyVar{
valuekeys={
	{der}{ upper={(#1)} },
},
}
The~\lstinline!#1! will contain whatever the
user wrote as the value of the key.
Now we can write:
\begin{LTXexample}
$\vf[der=\vn]{\vx}$
\end{LTXexample}
Maybe we also want a more elementary key~\lstinline!power! for raising a variable to a power:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{inv}{ upper={-1} },
	},
	valuekeys={
		{der}{ upper={(#1)} },
		{power}{ upper={#1} },
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{power}{ upper={#1} },
	},
}
This allows us to write
\begin{LTXexample}
$\vx[power=2]$,
$\vy[1,power=2] + \vy[2,power=2]$
\end{LTXexample}

Let us try doing something a bit more complicated: adding a key for restricting a function to a smaller subset.
For this, we do the following:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{inv}{ upper={-1} },
	},
	valuekeys={
		{der}{ upper={(#1)} },
		{power}{ upper={#1} },
		{res}{ return,symbolputright={|}, lower={#1} },
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{res}{ return,symbolputright={|}, lower={#1} },
	},
}
This adds a horizonal line~\enquote{$|$}
to the right of the symbol followed by
a lower index containing whatever you passed to the key
(contained in the \mbox{command~\lstinline!#1!)}.
(There is also an extra key, \lstinline!return!, which is a bit more advanced and should be taken for granted for now. Roughly speaking, it is there to make sure that the restriction symbol is printed \emph{after} all indices that you might have added before. More details in \cref{ch:return}.)
Now we may write the following:
\begin{LTXexample}
$\vf[res=\vU]{\vx}$,
$\vg[1,res=\vY]{\vy}$,
$\vh[inv,res=\vT]{\vz}$
\end{LTXexample}

If the reader starts playing around with the \semantex functions, they will discover that whenever you apply a function to something, the result becomes a new function that can take an argument itself (this is why we wrote~\lstinline!output=\MyVar! in the definition of the class~\lstinline!\MyVar!). This behaviour is both useful and extremely necessary in order for the package to be useful in practice. For instance, you may write
\begin{LTXexample}
$\vf[der=\vn]{\vx}{\vy}{\vz}
=\vg{\vu,\vv,\vw}[3]{
	\vx[1],\vx[2]}[8,1,der=2]{
		\vt}$
\end{LTXexample}
Some people prefer to be able to scale the vertical line in the restriction notation. I rarely do that, but for this purpose, we could do the following:
\begin{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{bigres}{ return, symbolputright=\big\vert, lower={#1} },
		{Bigres}{ return, symbolputright=\Big\vert, lower={#1} },
		{biggres}{ return, symbolputright=\bigg\vert, lower={#1} },
		{Biggres}{ return, symbolputright=\Bigg\vert, lower={#1} },
		{autores}{ return, Otherspar={.}{\vert}{auto},
		lower={#1} },
		% This auto scales the vertical bar. See the chapter on the
		% spar key for information about sparsize and Otherspar
	},
}
\end{lstlisting}

So to sum up, we first defined a class~\lstinline!\MyVar!
via \lstinline!\NewVariableClass! and then used \lstinline!\SetupClass! to add keys to it. In fact, we could have done it all at once by passing these options directly to \lstinline!\NewVariableClass!:
\begin{lstlisting}
\NewVariableClass\MyVar[
	output=\MyVar,	% This means that the output of an object
	                % of class \MyVar is also of class \MyVar
	singlekeys={
		{inv}{ upper={-1} },
	},
	valuekeys={
		{der}{ upper={(#1)} },
		{power}{ upper={#1} },
		{res}{ rightreturn, symbolputright={|},
			lower={#1} },
	},
]
\end{lstlisting}
As we proceed in this guide, we shall use \lstinline!\SetupClass!
to add more and more keys to~\lstinline!\MyVar!. However, when you set up your own system, you may as well just add all of the keys at once like this when you create the class and then be done with it.

Let me add that it is possible to create subclasses of existing classes. You just write \lstinline!parent=\⟨Class⟩! in the class declaration to tell that \lstinline!\⟨Class⟩! is the parent class. \textbf{But a word of warning:} It is a natural idea to create different classes for different mathematical entities, each with their own keyval syntax that fits whatever class you are in; for instance, you could have one class for algebraic structures like rings and modules with keys for opposite rings and algebraic closure, and you could have another class for topological spaces with keys for closure and interior. However, as the reader can probably imagine, this becomes extremely cumbersome to work with in practice since an algebraic structure might very well also carry a topology. So at the end of the day, I advice you to use a single superclass \lstinline!\MyVar! that has all the keyval syntax and mainly use subclasses for further customization. We shall see examples of this below.

\chapter{Example: Elementary algebra}

\SetupClass\MyVar{
	singlekeys={
		{poly}{
			par, 	% This tells semantex to use parentheses around
						% the argument in the first place, in case this
						% had been turned off
			leftpar=[,rightpar=],
		},
	},
}

Let us try to use \semantex to build some commands
for doing algebra.
As an algebraist, one of the first things you might want to do is to create polynomial rings~\( \vk[poly]{\vx,\vy,\vz} \). Since all variables can already be used as functions (this is a design choice we discussed earlier), all we need to do is find a way to change from using parentheses to square brackets. This can be done the following way:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{poly}{
			par, 	% This tells semantex to use parentheses around
						% the argument in the first place, in case this
						% had been turned off
			leftpar=[,rightpar=],
		},
	},
}
\end{lstlisting}
Now we may write
\begin{LTXexample}
	$\vk[poly]{\vx,\vy,\vz}$
\end{LTXexample}
It is straightforward how to do adjust this to instead write the \emph{field} generated by the variables~\( x, y, z \):
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{poly}{
			par, 	% This tells semantex to use parentheses around
						% the argument in the first place, in case this
						% had been turned off
			leftpar=[,rightpar=],
		},
		{field}{
			par,
			leftpar=(,rightpar=),
		},
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{field}{
			par,
			leftpar=(,rightpar=),
		},
	},
}
Now \lstinline!\vk[field]{\vx,\vy,\vz}! produces~\( \vk[field]{\vx,\vy,\vz} \). Of course, leaving out the \lstinline!field!
key would produce the same result with the current configuration of the class~\lstinline!\MyVar!. However, it is still best to use a key for this, both because this makes the semantics more clear, but also because you might later change some settings that would cause the default behaviour to be different.

Adding support for free algebras, power series, and Laurent series is almost as easy, but there is a catch:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{poly}{
			par, 	% This tells semantex to use parentheses around
						% the argument in the first place, in case this
						% had been turned off
			leftpar=[,rightpar=],
		},
		{field}{
			par,
			leftpar=(,rightpar=),
		},
		{freealg}{
			par,
			leftpar=\noexpand\langle,
			rightpar=\noexpand\rangle,
		},
		{powerseries}{
			par,
			leftpar=\noexpand\llbracket,
			rightpar=\noexpand\rrbracket,
		},
		{laurent}{
			par,
			leftpar=(, rightpar=),
			prearg={\!\!\noexpand\SemantexDelimiterSize(},
			postarg={\noexpand\SemantexDelimiterSize)\!\!},
			% These are printed before and after the argument.
			% The command "\SemantexDelimiterSize" is substituted
			% by \big, \Big, ..., or whatever size the
			% argument delimiters have
		},
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{freealg}{
			par,
			leftpar=\noexpand\langle,
			rightpar=\noexpand\rangle,
		},
		{powerseries}{
			par,
			leftpar=\noexpand\llbracket,
			rightpar=\noexpand\rrbracket,
		},
		{laurent}{
			par,
			leftpar=(, rightpar=),
			prearg={\!\!\noexpand\SemantexDelimiterSize(},
			postarg={\noexpand\SemantexDelimiterSize)\!\!},
			% These are printed before and after the argument.
			% The command "\SemantexDelimiterSize" is substituted
			% by \big, \Big, ..., or whatever size the
			% argument delimiters have
		},
	},
}
For expansion reasons (which I am not completely sure of),
we need \lstinline!\noexpand! before these commands.
In general, whenever something fails, try throwing in \lstinline!\noexpand!'s in front of suspicious-looking commands,
and things will usually work out just fine. See for yourself:
\begin{LTXexample}
$\vk[freealg]{\vx}$,
$\vk[powerseries]{\vy}$,
$\vk[laurent]{\vz}$
\end{LTXexample}


Let us look at some other algebraic operations that we can control via \semantex:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{op}{upper={\noexpand\mathrm{op}}},
			% opposite groups, rings, categories, etc.
		{algclosure}{overline},
			% algebraic closure
		{conj}{overline},
			% complex conjugation
		{dual}{upper=*},
			% dual vector space
		{perp}{upper=\perp},
			% orthogonal complement
	},
	valuekeys={
		{mod}{symbolputright={/#1}},
			% for modulo notation like R/I
		{dom}{symbolputleft={#1\backslash}},
			% for left modulo notation like I\R
			% "dom" is "mod" spelled backwards
		{oplus}{upper={\oplus#1}},
			% for notation like R^{\oplus n}
		{tens}{upper={\otimes#1}},
			% for notation like R^{\otimes n}
		{localize}{symbolputright={ \relax [#1^{-1}] }},
			% localization at a multiplicative subset;
			% the \relax is necessary becauese, in some cases,
			% the [...] can be interpreted as an optional argument
		{localizeprime}{lower={#1}},
			% for localization at a prime ideal
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{op}{upper={\noexpand\mathrm{op}}},
			% opposite groups, rings, categories, etc.
		{algclosure}{overline},
			% algebraic closure
		{conj}{overline},
			% complex conjugation
		{dual}{upper=*},
			% dual vector space
		{perp}{upper=\perp},
			% orthogonal complement
	},
	valuekeys={
		{mod}{symbolputright={/#1}},
			% for modulo notation like R/I
		{dom}{symbolputleft={#1\backslash}},
			% for left modulo notation like I\R
			% "dom" is "mod" spelled backwards
		{oplus}{upper={\oplus#1}},
			% for notatoin like R^{\oplus n}
		{tens}{upper={\otimes#1}},
			% for notation like R^{\otimes n}
		{localize}{symbolputright={ [#1^{-1}] }},
			% localization at a multiplicative subset
		{localizeprime}{lower={#1}},
			% for localization at a prime ideal
	},
}
Let us see it in practice:
\begin{LTXexample}
$\vR[op]$, $\vk[algclosure]$,
$\vz[conj]$, $\vV[dual]$,
$\vR[mod=\vI]$,$\vR[dom=\vJ]$,
$\vR[oplus=\vn]$,
$\vV[tens=\vm]$,
$\vR[localize=\vS]$,
$\vR[localizeprime=\vI]$,
$\vk[freealg]{\vS}[op]$,
$\vV[perp]$
\end{LTXexample}

\chapter{The \texttt{spar} key}

The \lstinline!spar! key is one of the most important commands in \semantex at all. To understand why we need it, imagine you want to derive a function \( \vn \)~times and then invert it. Writing something like
\begin{LTXexample}
$\vf[der=\vn,inv]$
\end{LTXexample}
does not yield a satisfactory result. However, the \lstinline!spar! key saves the day:
\begin{LTXexample}
$\vf[der=\vn,spar,inv]$
\end{LTXexample}
So \lstinline!spar! simply adds a pair of parentheses around the current symbol, complete with all indices that you may have added to it so far. The name \lstinline!spar! stands for \enquote{symbol parentheses}. You can add as many as you like:
\begin{LTXexample}
$ \vf[1,res=\vV,spar,conj,op,spar,0,inv,spar,mod=\vI,spar,dual]{\vx} $
\end{LTXexample}
If it becomes too messy, you can scale the parentheses, too. Simply use the syntax
\lstinline!spar=\big!, \lstinline!spar=\Big!, etc.
You can also get auto-scaled parentheses base on \lstinline!\left...\right!,
using the key \lstinline!spar=auto!:
\begin{LTXexample}
$\vf[spar]$,
$\vf[spar=\big]$,
$\vf[spar=\Big]$,
$\vf[spar=\bigg]$,
$\vf[spar=\Bigg]$,
$\vf[spar=auto]$
\end{LTXexample}
So returning to the above example, we can write
\begin{LTXexample}
$\vf[1,res=\vV,spar,conj,op,spar=\big,0,inv,spar=\Big,mod=\vI,spar=\bigg,dual]{\vx}$
\end{LTXexample}
To adjust the type of brackets, use the \lstinline!leftspar! and \lstinline!rightspar! keys:
\begin{LTXexample}
$\vf[leftspar={[},rightspar={\}},spar,spar=\Bigg]$
\end{LTXexample}
Occassionally, it is useful to be able to input a particular kind of brackets just once,
without adjusting any settings. For this purpose, we have the
\lstinline!otherspar! and~\lstinline!Otherspar!~keys. They use the syntax
\begin{lstlisting}
otherspar={⟨opening bracket⟩}{⟨closing bracket⟩}
Otherspar={⟨opening bracket⟩}{⟨closing bracket⟩}{⟨size⟩}
\end{lstlisting}
Let us see them in action:
\begin{LTXexample}
$\vf[otherspar={[}{)},otherspar={\{}{\rangle},
	Otherspar={\langle}{\rangle}{\Bigg},spar]$
\end{LTXexample}

\chapter{The \texorpdfstring{\texttt{$\backslash$⟨Class⟩}}{Class} command}

So far, we have learned that every mathematical entity should be treated
as an object of some class. However, then we run into issues the moment we
want to write expressions like
\[
	\MyVar{\vf\circ\vg}[spar,der=\vn]{\vx}.
\]
We do not want to have to define a new variable
with symbol~\( \vf\circ\vg \) just to write something like this.
Fortunately, once you have created the class~\lstinline!\MyVar!,
you can actually use~\lstinline!\MyVar! as a command to create a quick instance of the class.
More precisely \lstinline!\MyVar{⟨symbol⟩}!~creates a variable on the spot with symbol~\lstinline!⟨symbol⟩!.
So the above equation can be written
\begin{LTXexample}
$\MyVar{\vf\circ\vg}[
	spar,der=\vn]{\vx}$
\end{LTXexample}
More generally, when you crate the class~\lstinline!\⟨Class⟩!,
you can use it as a command with the following syntax:
\begin{lstlisting}
\⟨Class⟩{⟨symbol⟩}[⟨options⟩]⟨usual syntax of class⟩
\end{lstlisting}

\chapter{The \texttt{return} keys}\label{ch:return}

Suppose you want to take the complex conjugate of the variable~\( \vz[1] \). Then you might write something like
\begin{LTXexample}
$\vz[1,conj]$
\end{LTXexample}
Notice that the bar has only been added over the~\( \vz \), as is standard mathematical typography; you normally do not write~\( \vz[1,return,conj] \).
This reveals a design choice that has been made in \semantex:
When you add an index or a command via the \lstinline{command} key,
it is not immediately applied to the symbol.
Rather, both commands and indices are added to a register and are then applied at the very last, right before the symbol is printed.
This allows us to respect standard mathematical typography, as shown above.

However, there are other times when this behaviour is not what you want.
For instance, if you want to comjugate the inverse of a function, the following looks wrong:
\begin{LTXexample}
$\vf[inv,conj]$
\end{LTXexample}
Therefore, there is a command \lstinline!return! that can be applied at any point to invoke the routine of adding all indices and commands to the symbol. Let us try it out:
\begin{LTXexample}
$\vf[inv,return,conj]$
\end{LTXexample}
In fact, \lstinline!return! is an umbrella key that invokes three different return routines: \lstinline!leftreturn!, \lstinline!innerreturn!, and \lstinline!rightreturn!. The command \lstinline!leftreturn! adds the left indices to the symbol (we have not discussed left indices yet, though). The command \lstinline!innerreturn! adds all commands to the symbol (those defined using the \lstinline!command!~key).
Finally, \lstinline!rightreturn! adds all right indices and arguments to the symbol.
In general, the user should probably be satisfied with just using \lstinline!return!.


\chapter{The \texttt{command} key}

Above, we used the key \lstinline!overline! a couple of times:
\begin{LTXexample}
$\va[overline]$,
$\vH[overline]$
\end{LTXexample}
This command applies the command \lstinline!\overline!
to the symbol. In fact, you can create similar commands yourself via
the \lstinline!command! key.
In fact, you could have defined the \lstinline!overline! yourself as follows:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{overline}{command=\noexpand\overline},
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{overline}{command=\noexpand\overline},
	},
}
This is how the key \lstinline!overline! is defined internally, except it is defined on the level of the superclass \lstinline!\SemantexVariable! instead. We need the key \lstinline!\noexpand! in order for everything to expand properly. This is only necessary for some commands, and to tell the truth, I haven't quite figured out the system of which commands need it and which ones do not. However, as usual, if something does not work, try throwing in some \lstinline!\noexpand!'s and see if it solves the problem.
Here are some more examples of predefined keys that use the command key:
\begin{lstlisting}
\SetupClass\MyVar{ % do not add these -- they are already predefined!
	novalueskeys={
		{smash}{command=\noexpand\smash},
		{tilde}{command=\noexpand\tilde},
		{widetilde}{command=\widetilde},
		{bar}{command=\noexpand\bar},
		{bold}{command=\noexpand\mathbf},
		{roman}{command=\noexpand\mathrm},
	},
}
\end{lstlisting}
Let us test:
\begin{LTXexample}
$\va[widetilde]$,
$\va[bold]$,
$\va[roman]$,
$\va[bar]$
\end{LTXexample}


\chapter{Example: Algebraic geometry}

Let us discuss how to typeset sheaves and operations on morphisms in algebraic geometry.
First of all, adding commands for sheaves is not a big deal:
\begin{lstlisting}
\NewObject\MyVar\sheafF{\mathcal{F}}
\NewObject\MyVar\sheafG}{\mathcal{G}}
\NewObject\MyVar\sheafH{\mathcal{H}}
\NewObject\MyVar\sheafreg{\mathcal{O}}
	% sheaf of regular functions
\NewObject\MyVar\sheafHom{\mathop{\mathcal{H}om}}
\end{lstlisting}
You can of course add as many sheaf commands as you need.

Next, for morphisms of schemes~\( \vf \colon \vX \to \vY \),
we need to be able to typeset comorphisms as well as the one hundred thousand different pullback and pushforward operations. For this, we add some keys to the \lstinline!\MyVar! key:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{comorphism}{upper=\#},
			% comorphisms, i.e. f^{\#}
		{inverseimage}{upper={-1},nopar},
			% inverse image of sheaves
		{sheafpull}{upper=*,nopar},
			% sheaf *-pullback
		{sheafpush}{lower=*,nopar},
			% sheaf *-pushforward
		{sheaf!pull}{upper=!,nopar},
			% sheaf !-pullback
		{sheaf!push}{lower=!,nopar},
			% sheaf !-pushforward
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{comorphism}{upper=\#},
			% comorphisms, i.e. f^{\#}
		{inverseimage}{upper={-1},nopar},
			% inverse image of sheaves
		{sheafpull}{upper=*,nopar},
			% sheaf *-pullback
		{sheafpush}{lower=*,nopar},
			% sheaf *-pushforward
		{sheaf!pull}{upper=!,nopar},
			% sheaf !-pullback
		{sheaf!push}{lower=!,nopar},
			% sheaf !-pushforward
	},
}
We have added the command \lstinline!nopar! to all pullback and pushforward commands since it is custom to write, say,~\( \vf[sheafpull]{\sheafF} \) rather than~\( \vf[sheafpull,par]{\sheafF} \). Of course, you can decide that for yourself, and in any case, you can write~\lstinline!\vf[sheafpull,par]{\sheafF}! if you want to force it to use parentheses in a particular case. Of course, since all \semantex variables can be used as functions, so can whatever these pullback and pushforward operations output. So we may write:
\begin{LTXexample}
For a morphism~$ \vf \colon
\vX \to \vY $ with
comorphism~$ \vf[comorphism]
\colon \sheafreg[\vY] \to
\vf[sheafpush]{\sheafreg[\vX]} $,
and for a sheaf~$ \sheafF $ on~$ \vY $, we can define the
pullback~$ \vf[sheafpull]{
\sheafF} $ by letting~$
\vf[sheafpull]{ \sheafF}{\vU} = \cdots $ and the $ ! $-pullback by letting~$
\vf[sheaf!pull]{\sheafF}{\vU} = \cdots $.
\end{LTXexample}
Maybe some people would write \lstinline!pull!, \lstinline!push!, etc.~instead, but there are many different kinds of pullbacks in mathematics, so I prefer to use the \lstinline!sheaf!~prefix to show that this is for sheaves.
Probably, in the long run, an algebraic geometer might also want
to abbreviate~\lstinline!inverseimage! to~\lstinline!invim!.

There are a number of other operations we might want to do for sheaves. We already defined the key~\lstinline!res! for restriction, so there is no need to define this again.
However, we might need to stalk, sheafify, take dual sheaves, and twist sheaves. Let us define keys for this:
\begin{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{stalk}{clower={#1}},
		% "clower" means "comma lower", i.e. lower index
		% separated from any previous lower index by a comma
		{sheaftwist}{return,symbolputright={(#1)}},
	},
	singlekeys={
		{sheafify}{upper=+},
		{sheafdual}{upper=\vee},
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{stalk}{clower={#1}},
		% "clower" means "comma lower", i.e. lower index
		% separated from any previous lower index by a comma
		{sheaftwist}{return,symbolputright={(#1)}},
	},
	singlekeys={
		{sheafify}{upper=+},
		{sheafdual}{upper=\vee},
	},
}
The key \lstinline!clower! stands for \enquote{comma lower}.
It is like \lstinline!lower!, except that it checks whether the index
is already non-empty, and if so, it separates the new index from the previous index by a comma. There is, of course, a \lstinline!cupper!~key that does the same with the upper index.
\begin{LTXexample}
$\sheafF[res=\vU,stalk=\vp]$,
$\sheafF[res=\vU,spar,stalk=
\vp]$, 
$\sheafreg[\vX,stalk=\vp]$,
$\sheafG[sheafify]$,
$\vf[inverseimage]{\sheafreg[
\vY]}[spar,stalk=\vx]$
$\sheafG[sheafdual]$,
$\sheafreg[\vX][sheaftwist=-1]$,
$\sheafreg[sheaftwist=1,sheafdual]$
\end{LTXexample}

\chapter{Example: Homological algebra}

Before you venture into homological algebra, you should probably
define some keys for the standard constructions:

\begin{lstlisting}
\NewObject\MyVar\Hom{\operatorname{Hom}}
\NewObject\MyVar\Ext{\operatorname{Ext}}
\NewObject\MyVar\Tor{\operatorname{Tor}}
\end{lstlisting}
\NewObject\MyVar\Ext{\operatorname{Ext}}
\NewObject\MyVar\Tor{\operatorname{Tor}}
Now the ability to easily print indices via the options key will come in handy:
\begin{LTXexample}
$\Hom[\vA]{\vM,\vN}$,
$\Ext[\vA]{\vM,\vN}$
\end{LTXexample}
\SetupClass\MyVar{
valuekeys={
		{shift}{ return,symbolputright={ \relax [ {#1} ] } },
		% \relax is necessary since otherwise [...] can
		% occasionally be interpreted as an optional argument
	},
}
You will probably need several keyval interfaces, some of which will be covered below. But right now, we shall implement a shift operation~\( \vX\mapsto\vX[shift=\vn] \):
\begin{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{shift}{ return,symbolputright={ \relax [ {#1} ] } },
		% \relax is necessary since otherwise [...] can
		% occasionally be interpreted as an optional argument
	},
}
\end{lstlisting}
Let us see that it works:
\begin{LTXexample}
$\vX\mapsto\vX[shift=\vn]$
\end{LTXexample}
Finally, let us define a command for the differential (in the homolgoical algebra sense):
\begin{lstlisting}
\NewObject\MyVar\dif{d}[nopar]
\end{lstlisting}%
\NewObject\MyVar\dif{d}[nopar]%
\begin{LTXexample}
$\dif{\vx} = 0$
\end{LTXexample}

\section{The keys \texttt{i = index} and \texttt{d = deg = degree}}

Homological algebra is a place where people
have very different opinions about the positions of the gradings.
As an algebraist, I am used to \emph{upper} gradings (\enquote{cohomological} grading), whereas many topologists prefer \emph{lower} gradings (\enquote{homological} grading). The \semantex system
supports both, but the default is upper gradings (the package author has the privilege to decide).
You can adjust this by writing
\lstinline!gradingposition=upper! or~\lstinline!gradingposition=lower!.


We already learned about the keys \lstinline!upper! and~\lstinline!lower!.
There are two more, \enquote{relative} keys that print the index either as an upper index or as a lower index, depending on your preference for cohomological or homological grading. They are called
\begin{center}
	\lstinline!index!
	\qquad\qquad and\qquad\qquad
	\lstinline!degree!
\end{center}
The \lstinline!degree! is the actual grading in the homological algebra
sense. The \lstinline!index! is an additional index where you can put extra information that you might need.
To understand the difference, keep the following two examples
in mind: the hom complex~\( \Hom[*,index=\vA] \) and the simplicial homology~\( \ho[*,index=\vDelta] \) (we will define the command~\lstinline!\ho! for homology in the next section):
\begin{LTXexample}
$\Hom[index=\vA,degree=0]$,
$\ho[index=\vDelta,degree=1]$
\end{LTXexample}
These names are not perfect; many people would say that the degree is also
an index, but feel free to come up with a more satisfactory naming principle, and I shall be happy to consider it. These names probably become a bit too heavy to write in the long run, so both keys have abbreviated equivalents:
\begin{center}
	\lstinline!i! = \lstinline!index!
	\qquad\qquad and\qquad\qquad
	\lstinline!d! = \lstinline!deg! = \lstinline!degree!
\end{center}
Let us see them in action:
\begingroup\begin{LTXexample}
$ \vX[d=3,i=\vk] $

\SetupObject\vX{
	gradingposition=lower
}

$ \vX[d=3,i=\vk] $
\end{LTXexample}\endgroup
\noindent (We haven't seen the command \lstinline!\SetupObject! before, but I imagine you can guess what it does).
If you want to print a bullet as the degree, there is the predefined key~\lstinline!*! for this:
\begingroup\begin{LTXexample}
$ \vX[*] $

\SetupObject\vX{
	gradingposition=lower
}

$ \vX[*] $
\end{LTXexample}\endgroup

I guess it is also time to reveal that the previously mentioned shorthand notation~\lstinline!\vx[1]! for indices always prints the~\lstinline!1! on the \lstinline{index} position. So changing the grading position changes the position of the index:
\begingroup\begin{LTXexample}
$ \vX[1] $

\SetupObject\vX{
	gradingposition=lower
}

$ \vX[1] $
\end{LTXexample}\endgroup
In other words, in the first example above, we could have written
\begin{LTXexample}
$\Hom[\vA,d=0]$,
$\ho[\vDelta,d=1]$
\end{LTXexample}


Note that the use of the short notations \lstinline!d! and~\lstinline!i! does not prevent you from writing \lstinline!\vx[d]! and~\lstinline!\vx[i]!.
This still works fine:
\begin{LTXexample}
$\vf[i]$, $\vf[i=]$,
$\vf[d]$, $\vf[d=]$
\end{LTXexample}
As we see, it is only when a \lstinline!d! or~\lstinline!i! key is followed by an equality sign~\lstinline!=!
that the routines of these keys are invoked.
In fact, \semantex carefully separates
\lstinline!valuekeys! from \lstinline!singlekeys!.

\section{The \texorpdfstring{\texttt{Cohomology}}{Cohomology} class type}

Now homological algebra is hard unless we can do \emph{cohomology} and \emph{homology}. In principle, this is not hard
to do, as we can write e.g.~\lstinline!\vH[d=0]{\vX}! to get~\( \vH[d=0]{\vX} \).
However, some people might find it cumbersome to have to write~\lstinline!d=! every time you want to print an index.
This is probably the right time to reveal that \semantex supports multiple class \emph{types}.
So far, we have been exclusively using the \lstinline!Variable!
class type, which is what you create when you apply the command~\lstinline!\NewVariableClass!.
The first other class type we shall need is the \lstinline!Cohomology! class type, which has a different input syntax that fits cohomology.
Let us try to use it:
\begin{lstlisting}
\NewCohomologyClass\MyCohomology[
	parent=\MyVar,gradingposition=upper
]

\NewObject\MyCohomology\co{H}

\NewCohomologyClass\MyHomology[
	parent=\MyCohomology,gradingposition=lower
]

\NewObject\MyHomology\ho{H}
\end{lstlisting}
The cohomology command~\lstinline!\co! in general works very much
like a command of \lstinline!Variable! type. However, the input syntax is a bit different:
\begin{lstlisting}
\co[⟨options⟩]{⟨degree⟩}{⟨argument⟩}
\end{lstlisting}
All three arguments are optional. Let us see it in practice:
\begin{LTXexample}
$\co{0}$, $\co{*}$,
$\co{\vi}{\vX}$,
$\co[\vG]{0}$,
$\co[\vH]{*}$,
$\co[\vDelta]{\vi}{\vX}$
\end{LTXexample}

\begin{LTXexample}
$\ho{0}$, $\ho{*}$,
$\ho{\vi}{\vX}$,
$\ho[\vG]{0}$,
$\ho[\vH]{*}$,
$\ho[\vDelta]{\vi}{\vX}$
\end{LTXexample}
Of course, you can define similar commands for cocycles, coboundaries, and all sorts of other entities that show up in homological algebra.

You might also want to implement feature like reduced cohomology, \v{C}ech cohomology,
and hypercohomology. This is quite easy with the \lstinline!command! key:
\begin{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{reduced}{command=\widetilde},
		{cech}{command=\noexpand\check},
		{hyper{command=\noexpand\mathbb},
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	singlekeys={
		{reduced}{command=\widetilde},
		{cech}{command=\noexpand\check},
		{hyper}{command=\noexpand\mathbb},
	},
}

\begin{LTXexample}
$\co[reduced]{i}$,
$\co[cech]{*}$,
$\co[hyper,cech]{0}{\vX}$
\end{LTXexample}

The \lstinline!Cohomology! class type also provides a nice way
to implement derived functors:
\begin{lstlisting}
\NewObject\MyCohomology\Lder{\mathbb{L}}[nopar]
\NewObject\MyCohomology\Rder{\mathbb{R}}[nopar]
\end{lstlisting}
\NewObject\MyCohomology\Lder{\mathbb{L}}[nopar]
\NewObject\MyCohomology\Rder{\mathbb{R}}[nopar]
For instance, we can write
\begin{LTXexample}
$\Lder{\vi}{\vf}$,
$\Rder{0}{\vf}$
\end{LTXexample}

Alternatively, the user might prefer to use keyval syntax
on the level of the function itself (\( \vf \)~in this case).
This can be done the following way:
\begin{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{Lder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{L}^{#1},
		},
		{Rder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{R}^{#1},
		},
	},
	singlekeys={
		{Lder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{L},
		},
		{Rder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{R},
		},
	},
}
\end{lstlisting}
\SetupClass\MyVar{
	valuekeys={
		{Lder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{L}^{#1},
		},
		{Rder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{R}^{#1},
		},
	},
	singlekeys={
		{Lder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{L},
		},
		{Rder} {
			innerreturn,leftreturn,
			symbolputleft=\noexpand\mathbb{R},
		},
	},
}
Then the syntax becomes:
\begin{LTXexample}
$\vF[Lder=\vi]$,
$\vF[Lder]{\vX[*]}$,
$\vF[Rder]{\vX[*]}$,
$\Hom[Rder]{\vX,\vY}$
\end{LTXexample}
If you get tired of having to write \lstinline!\Hom[Rder]! all
the time, you can create a shortcut:
\begin{lstlisting}
\NewObject\MyVar\RHom[clone=\Hom,Rder]
\end{lstlisting}
\NewObject\MyVar\RHom[clone=\Hom,Rder]
The \lstinline!clone! key is like the \lstinline!parent! key,
except it allows you to inherit the settings from an \emph{object} rather than a \emph{class}. Notice that we did not specify a symbol; the symbol argument is optional, and in this case, it was unnecessary, as the symbol was inherited from~\lstinline!\Hom!. Let us see it in action:
\begin{LTXexample}
$\RHom{\vX,\vY}$
\end{LTXexample}

\chapter{Keyval syntax in arguments (Example: Cohomology with coefficients)}

\SetupClass\MyVar{
	argvaluekeys={
		{coef}{ othersep={;}{#1}  },
	},
}

\SetupObject\co{
	valuekeys={
		{arg}{argwithkeyval={#1}},
	},
}%

Imagine we want to do cohomology with coefficients in some ring~\( \vR \).
It is common to write this as~\( \co{*}{\vX,coef=\vR} \)
with a semicolon instead of a comma. This can be implemented, too, with the syntax
\begin{LTXexample}
$\co{*}{\vX,coef=\vR}$
\end{LTXexample}
This shows that arguments of functions also support keyval syntax.
In order to customize this, there are two extra keys:
\begin{center}
\lstinline!argsinglekeys!
\qquad\qquad\text{and}\qquad\qquad
\lstinline!argvaluekeys!
\end{center}
These work exactly like \lstinline!singlekeys! and~\lstinline!valuekeys!.
\begin{lstlisting}
\SetupClass\MyVar{
	argvaluekeys={
		{coef}{ othersep={;}{#1}  },
	},
}
\end{lstlisting}
(But it will not quite work yet -- stay tuned for a moment!)
The key \lstinline!othersep! is a key that controls the separator
between the current argument and the previous argument (it will only be printed if there was a previous argument). By default, this separator is a comma. So in the syntax~\lstinline!\co{*}{\vX,coef=\vR}!,
there are two arguments, \lstinline!\vX! and~\lstinline!\vR!, and the separator is a semicolon.

However, even with the above setup, the notation \lstinline!\co{*}{\vX,coef=\vR}! will not work
just yet. For the keys you define using \lstinline!argvaluekeys!
are turned off by default. To turn them on for the object~\lstinline!\co!, run the following code:
\begin{lstlisting}
\SetupObject\co{
	valuekeys={
		{arg}{argwithkeyval={#1}},
	},
}
\end{lstlisting}
The reason the keys are turned off by default is that keys in arguments that support values are only used in very rare cases, like cohomology with coefficients. If such keys were turned on in general, it would mess up
every occurrence of an equality sign in arguments, and the following
would not work:
\begin{LTXexample}
$\Hom[\sheafreg[\vU]]{
	\sheafF[res=\vU],
	\sheafG[res=\vU]
}$
\end{LTXexample}

It should be noted that there are several predefined
keys (of type \mbox{\lstinline!singlekey!)} which are defined on the level
of the class \lstinline!\SemantexVariable!. The full list is:\fxfatal{Finish this}

\begin{itemize}
	\item slot, \ldots
\end{itemize}

We should also talk about the \lstinline!arg! key.

\chapter{Multi-value keys}

\SetupClass\MyVar{
	2valuekeys={
		{projquotient}{ symbolputright={ /\!\!/ _ { #1 } #2 } },
	}
}

Sometimes, a key with one value is simply not enough. For instance, if you
work in~GIT, you will eventually have to take the proj
quotient~\( \vX[projquotient={\vchi}{\vG}] \) of~\( \vX \) with respect to the action of the group~\( \vG \) and the character~\( \vchi \). In other words, the proj quotient depends on two parameters, \( \vchi \) and~\( \vG \). For this purpose, we have the key~\lstinline!2valuekeys!. It works exactly like \lstinline!valuekeys!, except you get to use two arguments instead of one:
\begin{lstlisting}
\SetupClass\MyVar{
	2valuekeys={
		{projquotient}{ symbolputright={ /\!\!/ _ { #1 } #2 } },
	}
}
\end{lstlisting}

\begin{LTXexample}
$\vX[projquotient={\vchi}{\vG}] $
\end{LTXexample}
There are also commands \lstinline!3valuekeys!, \lstinline!4valuekeys!, \ldots, \lstinline!9valuekeys!. The syntax for these is completely analoguous.
There are also commands \lstinline!arg2valuekeys!, \lstinline!arg3valuekeys!, \ldots, \lstinline!arg9valuekeys! for keys in arguments with multiple values.


\chapter{The \texttt{Simple} class type (Example: Derived tensor products and fibre products)}

\NewSimpleClass\MyBinaryOperator[
	singlekeys={
		{Lder}{upper=L},
		{Rder}{upper=R},
	},
	mathbin, % this makes sure that the output is wrapped in \mathbin
]

\NewObject\MyBinaryOperator\tensor{\otimes}[
	singlekeys={
		{der}{Lder},
	},
]

\NewObject\MyBinaryOperator\fibre{\times}[
	% Americans are free to call it \fiber instead
	singlekeys={
		{der}{Rder},
	},
]

The \semantex system has facilities for printing tensor products~\( \tensor \) as well as derived tensor products~\( \tensor[der] \).
For this, we need the \lstinline!Simple! class type.
This has exactly the same syntax as the \lstinline!Variable!
class type, except that it cannot take an argument.
In other words, its syntax is
\begin{lstlisting}
\⟨object⟩[⟨options⟩]
\end{lstlisting}
(You should normally only use it for special constructions like binary operators and not for e.g.\ variables -- the ability to add arguments to variables comes in handy much more often than one might imagine.)
Let us try to use it to define tensor products and fibre products:
\begin{lstlisting}
\NewSimpleClass\MyBinaryOperator[
	singlekeys={
		{Lder}{upper=L},
		{Rder}{upper=R},
	},
	mathbin,
	% this makes sure that the output is wrapped in \mathbin
]

\NewObject\MyBinaryOperator\tensor{\otimes}[
	singlekeys={
		{der}{Lder},
	},
]

\NewObject\MyBinaryOperator\fibre{\times}[
	% Americans are free to call it \fiber instead
	singlekeys={
		{der}{Rder},
	},
]
\end{lstlisting}
As you see, this is one of the few cases where I recommend adding keyval
syntax to other classes than your superclass~\lstinline!\MyVar!. Also, notice that it does not have any~\lstinline!parent=\MyVar!, as I do not really see any reason to inherit all the keyval syntax from the \lstinline!\MyVar!~class.
Now we first define keys \lstinline!Lder! and~\lstinline!Rder! for left and right derived binary operators. Next, we build in a shortcut in both \lstinline!\tensor! and~\lstinline!\fibre!
so that we can write simply~\lstinline!der! and get the correct notion of derived functor. Let us see it in action:
\begin{LTXexample}
$\vA \tensor \vB$,
$\vX[*] \tensor[\vR] \vY[*]$
$\vk \tensor[\vA,der] \vk$,
$\vX \fibre[\vY,der] \vX$
\end{LTXexample}

\chapter{Class types}

The \semantex system uses several different \emph{class types}.
We have been almost exclusively using the \lstinline!Variable! class type (which is by far the most important one), but in the last chpaters, we were introduced to the \lstinline!Cohomology! and the \lstinline!Simple! class types.

In fact, all class types are identical internally; the low-level machinery of \semantex does not \enquote{know} what type a class has.
The only difference between the class types is the \emph{input syntax}.
In other words, it determines which arguments an object of that class
can take. The syntax for creating new objects
also varies.

The current implementation has the following
class types:

\begin{itemize}
	\item \lstinline!Variable!:
	A new class is declared with the
	syntax
	\begin{lstlisting}
		\NewVariableClass{\⟨Class⟩}[⟨options⟩]
	\end{lstlisting}
	A new object is declared by
	\begin{lstlisting}
		\NewObject\⟨Class⟩\⟨object⟩{⟨symbol⟩}[⟨options⟩]
	\end{lstlisting}
	The syntax for this object is
	\begin{lstlisting}
		\⟨object⟩[⟨options⟩]{⟨argument⟩}
	\end{lstlisting}
	\item \lstinline!Cohomology!:
	A new class is declared with the
	syntax
	\begin{lstlisting}
		\NewCohomologyClass\⟨Class⟩[⟨options⟩]
	\end{lstlisting}
	A new object is declared by
	\begin{lstlisting}
		\NewObject\⟨Class⟩\⟨object⟩{⟨symbol⟩}[⟨options⟩]
	\end{lstlisting}
	The syntax for this object is
	\begin{lstlisting}
		\⟨object⟩[⟨options⟩]{⟨degree⟩}{⟨argument⟩}
	\end{lstlisting}
	\item \lstinline!Simple!:
	A new class is declared with the
	syntax
	\begin{lstlisting}
		\NewSimpleClass\⟨Class⟩[⟨options⟩]
	\end{lstlisting}
	A new object is declared by
	\begin{lstlisting}
		\NewObject\⟨Class⟩\⟨object⟩{⟨symbol⟩}[⟨options⟩]
	\end{lstlisting}
	The syntax for this object is
	\begin{lstlisting}
		\⟨object⟩[⟨options⟩]{⟨argument⟩}
	\end{lstlisting}
	\item \lstinline!Delimiter!:
	A new class is declared with the syntax
	\begin{lstlisting}
		\NewDelimiterClass\⟨Class⟩[⟨options⟩]
	\end{lstlisting}
	A new object is declared by
	\begin{lstlisting}
		\NewObject\⟨Class⟩\⟨object⟩{⟨left bracket⟩}{⟨right bracket⟩}[⟨options⟩]
	\end{lstlisting}
	The syntax for this object is
	\begin{lstlisting}
		\⟨object⟩[⟨options⟩]{⟨argument⟩}
	\end{lstlisting}
\end{itemize}

Let me add that \semantex uses a very clear separation between the input syntax and the underlying machinery. Because of this, if the user needs a different kind of class type, it is not very hard to create one. You must simply open the source code of \semantex, find the class you want to modify, and then copy the definition of the command~\lstinline!\New⟨Class type⟩Class! and modify it in whatever way you want.

\chapter{The \texorpdfstring{\texttt{Delimiter}}{Delimiter} class type}

\NewDelimiterClass\MyDelim[parent=\MyVar]
\NewObject\MyDelim\norm{\lVert}{\rVert}
\NewObject\MyDelim\inner{\langle}{\rangle}

Delimiters are what they sound like: functions like \( \norm{slot} \) and~\( \inner{slot,slot} \)
that are defined using brackets only. Let us define a class of type \lstinline!Delimiter!:
\begin{lstlisting}
\NewDelimiterClass\MyDelim[parent=\MyVar]
\end{lstlisting}
Now we can create instances of the class~\lstinline!\MyDelim! with the following syntax:
\begin{lstlisting}
\NewObject\MyDelim\⟨object⟩{⟨left bracket⟩}{⟨right bracket⟩}[⟨options⟩
\end{lstlisting}
Now we can do the following:
\begin{lstlisting}
\NewObject\MyDelim\norm{\lVert}{\rVert}
\NewObject\MyDelim\inner{\langle}{\rangle}
\end{lstlisting}
Indeed:
\begin{LTXexample}
$\norm{\va}$,
$\inner{\va,\vb}$,
$\inner{slot,slot}$
\end{LTXexample}
We can also use it for more complicated constructions, like sets.
The following is inspired from the \pack{mathtools} package where a similar construction is created using the commands from that package. My impression is that Lars Madsen is the main mastermind behind the code I use for the \lstinline!\where!~command:
\begin{lstlisting}
\newcommand\where{
	\nonscript\:
	\SemantexDelimiterSize\vert
	\allowbreak
	\nonscript\:
	\mathopen{}
}

\NewObject\MyDelim\Set{\lbrace}{\rbrace}[
	prearg={\,},postarg={\,},
	% adds \, inside {...}, as recommended by D. Knuth
	valuekeys={
		{arg}{argwithoutkeyval={#1}},
		% this turns off all keyval syntax in the argument
	}
]
\end{lstlisting}
\newcommand\where{
	\nonscript\:
	\SemantexDelimiterSize\vert
	\allowbreak
	\nonscript\:
	\mathopen{}
}

\NewObject\MyDelim\Set{\lbrace}{\rbrace}[
	prearg={\,},postarg={\,},
	% adds \, inside {...}, as recommended by D. Knuth
	valuekeys={
		{arg}{argwithoutkeyval={#1}},
		% this turns off all keyval syntax in the argument
	}
]
Now you can use
\begin{LTXexample}
$\Set{ \vx \in \vY \where
\vx \ge 0 }$
\end{LTXexample}
Don't forget that anything created with \semantex
outputs as a variable-type object. So you can do stuff like
\begin{LTXexample}
$\Set{
	\vx \in \vY[\vi]
	\where
	\vx \ge 0
}[conj,\vi\in\vI]$
\end{LTXexample}


Tuple-like commands are also possible:
\begin{lstlisting}
\NewObject\MyDelim\tup{(}{)} % tuples
\NewObject\MyDelim\pcoor{[}{]}[ % projective coordinates
	setargsep=\mathpunct{:},
		% changes the argument separator to colon
	setargdots=\cdots,
		% changes what is inserted  if you write "..."
]
\end{lstlisting}
\NewObject\MyDelim\tup{(}{)} % tuples
\NewObject\MyDelim\pcoor{[}{]}[ % projective coordinates
	setargsep=\mathpunct{:}, % changes the argument separator to :
	setargdots=\cdots, % changes what is inserted if you write "..."
]
Let us see them in action:
\begin{LTXexample}
$\tup{\va,\vb,...,\vz}$,
$\pcoor{\va,\vb,...,\vz}$
\end{LTXexample}

One can also use tuples for other, less obvious purposes, like calculus differentials:
\begin{lstlisting}
\NewDelimiterClass\CalculusDifferential[
	parent=\MyVar,
	argvaluekeys={
		{default}{s={d\!#1}},
		% default is the key that is automatically applied by the
		% system to anything you write in the argument. The s key
		% is a key that prints the value of the key with the
		% standard argument separator in front.
	},
	setargdots=\cdots,
	neverpar,
	% neverpar is like nopar, except nopar will still print
	% parentheses when there is more than one argument
	% -- neverpar does not even print parentheses in this case
]
	
\NewObject\CalculusDifferential\intD{(}{)}[setargsep={\,},iffirstarg=false]

\NewObject\CalculusDifferential\wedgeD{(}{)}[setargsep=\wedge]
\end{lstlisting}
\NewDelimiterClass\CalculusDifferential[
	parent=\MyVar,
	argvaluekeys={
		{default}{s={d\!#1}},
	},
	setargdots=\cdots,
	neverpar,
	% neverpar is like nopar, except nopar will still print
	% parentheses when there is more than one argument
	% -- neverpar does not even print parentheses in this case
]
	
\NewObject\CalculusDifferential\intD{(}{)}[setargsep={\,},ifnextargwithsep=false]

\NewObject\CalculusDifferential\wedgeD{(}{)}[setargsep=\wedge]

\begin{LTXexample}
$\int \vf \intD{\vx[1],
	\vx[2],...,\vx[n]}$,

$\int \vf \wedgeD{\vx[1],
	\vx[2],...,\vx[n]}$
\end{LTXexample}

\chapter{The \texttt{parse} routine}

As you can see above, \semantex has a ``waterfall-like'' behaviour. It runs keys in the order it receives them. This works fine most of the time, but for some more complicated constructions, it is useful to be able to provide a data set in any order and have them printed in a fixed order. For this purpose, we have the \lstinline!parse! routine.



Suppose we want to be able to write the set of \( \vn \times \vm \)-matrices with entries in~\( \vk \) as~\( \MyVar{\operatorname{Mat}}[\vn\times\vm]{\vk} \). We can in principle do the following:
\begingroup\begin{LTXexample}
\NewObject\MyVar\Mat{
	\operatorname{Mat}}
$ \Mat[\vn\times\vm]{\vk} $.
\end{LTXexample}\endgroup%
\noindent However, this is not quite as systematic and semantic as we might have wanted. Indeed, what if later you would like to change the notation to~\( \MyVar{\operatorname{Mat}}[\vn,\vm]{\vk} \)?
Therefore, we do something like the following instead (we explain the notation below):
\begin{lstlisting}
\NewObject\MyVar\Mat{\operatorname{Mat}}[
	execute={
		\SemantexDataProvide{rows}
		\SemantexDataProvide{columns}
		 % provides data sets for number of rows and columns
		 % for this object
	},
	valuekeys={
		{rows}{
			execute={
				\SemantexDataSet{rows}{#1}
			},
		},
		{columns}{
			execute={
				\SemantexDataSet{columns}{#1}
			},
		},
	},
	parseoptions={
		execute={
			\SemantexStrIfEqTF{\SemantexDataGetExpNot{columns}}
			{\SemantexDataGetExpNot{rows}}
			% tests if rows = columns
			{
				\SemantexKeysSetx{
					lower={
						\SemantexDataGetExpNot{columns}
					}
				}
			}
			{
				\SemantexKeysSetx{
					lower={
						\SemantexDataGetExpNot{rows}
						\times
						\SemantexDataGetExpNot{columns}
					}
				}
			}
		},
	},	
]
\end{lstlisting}%
\NewObject\MyVar\Mat{\operatorname{Mat}}[
	execute={
		\SemantexDataProvide{rows}
		\SemantexDataProvide{columns}
	},
	valuekeys={
		{rows}{
			execute={
				\SemantexDataSet{rows}{#1}
			},
		},
		{columns}{
			execute={
				\SemantexDataSet{columns}{#1}
			},
		},
	},
	parseoptions={
		execute={
			\SemantexStrIfEqTF{\SemantexDataGetExpNot{columns}}{\SemantexDataGetExpNot{rows}}
			{
				\SemantexKeysSetx{
					lower={
						\SemantexDataGetExpNot{columns}
					}
				}
			}
			{
				\SemantexKeysSetx{
					lower={
						\SemantexDataGetExpNot{rows}
						\times
						\SemantexDataGetExpNot{columns}
					}
				}
			}
		},
	},	
]%
Now we can do the following:
\begin{LTXexample}
$ \Mat[rows=\vn,columns=\vm]{\vk} $, $ \Mat[rows=\vn,columns=\vn]{\vk} $
\end{LTXexample}

The key~\lstinline!execute! is a key that basically just executes code. You can in principle write any \TeX\ code there, and it will be applied right at the spot. However, inside the \lstinline!execute!~key, you can also use the following locally defined commands. These can be used to handle the data that is associated with the object in question. I don't have time to document them right now, so you'll have to guess what they do from the name for now, or you can find their definition in the source code of the package.
\begin{lstlisting}
\SemantexDataProvide
\SemantexDataSet
\SemantexDataSetx
\SemantexDataPutRight
\SemantexDataPutRightx
\SemantexDataPutLeft
\SemantexDataPutLeftx
\SemantexDataGet
\SemantexDataGetExpNot
\SemantexDataClear
\SemantexKeysSet
\SemantexKeysSetx
\SemantexStrIfEqTF
\SemantexStrIfEqT
\SemantexStrIfEqF
\SemantexIfBlankTF
\SemantexIfBlankT
\SemantexIfBlankF
\SemantexBoolProvide
\SemantexBoolSetTrue
\SemantexBoolSetFalse
\SemantexBoolIfTF
\SemantexBoolIfT
\SemantexBoolIfF
\SemantexIntProvide
\SemantexIntGet
\SemantexIntClear
\SemantexIntIncr
\SemantexIntSet
\SemantexIntIfPositiveTF
\SemantexIntIfPositiveT
\SemantexIntIfPositiveF
\SemantexIntIfGreaterThanOneTF
\SemantexIntIfGreaterThanOneT
\SemantexIntIfGreaterThanOneF
\SemantexExpNot
\end{lstlisting}

The key~\lstinline!parseoptions! is a key that is executed right before rendering the object.  This is where you write whatever the system is supposed to \emph{do} with the data sets you provide. You can also force it to be applied at any point by using the \lstinline!parse!~key.

Let us look at a more complicated example: Let us create a command for partial derivatives:

\NewObject\MyVar\partialdif[
	nopar,
	execute={
		\SemantexBoolProvide{raisedfunction}
		\SemantexBoolSetTrue{raisedfunction}
	},
	setidots=\cdots,
	setisep=\,,
	valuekeys={
		{default}{
			si={\partial #1},
		},
	},
	singlekeys={
		{raisedfunction}{
			execute={
				\SemantexBoolSetTrue{raisedfunction}
			},
		},
		{noraisedfunction}{
			execute={
				\SemantexBoolSetFalse{raisedfunction}
			},
		},
	},
	parseoptions={
		execute={
			\SemantexIfBlankTF{ \SemantexDataGet{upper} }
			{
				\SemantexKeysSetx{
					symbol={
						\frac
						{
							\partial ^ { \SemantexIntGet{numberoflowerindices} }
							\SemantexBoolIfT{raisedfunction}
							{
								\SemantexDataGetExpNot{arg}
							}
						}
						{
							\SemantexDataGetExpNot{lower}
						}
					},
				}
			}
			{
				\SemantexKeysSetx{
					symbol={
						\frac
						{
							\partial ^ { \SemantexDataGet{upper} }
							\SemantexBoolIfT{raisedfunction}
							{
								\SemantexDataGetExpNot{arg}
							}
						}
						{
							\SemantexDataGetExpNot{lower}
						}
					},
				}
			}
			\SemantexDataClear{lower}
			\SemantexDataClear{upper}
			\SemantexBoolIfT{raisedfunction}
			{
				\SemantexDataClear{arg}
				\SemantexIntClear{numberofarguments}
			}
		},
	},
]

\begin{lstlisting}
\NewObject\MyVar\partialdif[
	nopar,
	execute={
		\SemantexBoolProvide{raisedfunction}
		\SemantexBoolSetTrue{raisedfunction}
	},
	setidots=\cdots,
	setisep=\,,
	valuekeys={
		{default}{
			si={\partial #1},
		},
	},
	singlekeys={
		{raisedfunction}{
			execute={
				\SemantexBoolSetTrue{raisedfunction}
			},
		},
		{noraisedfunction}{
			execute={
				\SemantexBoolSetFalse{raisedfunction}
			},
		},
	},
	parseoptions={
		execute={
			\SemantexIfBlankTF{ \SemantexDataGet{upper} }
			{
				\SemantexKeysSetx{
					symbol={
						\frac
						{
							\partial ^ { \SemantexIntGet{numberoflowerindices} }
							\SemantexBoolIfT{raisedfunction}
							{
								\SemantexDataGetExpNot{arg}
							}
						}
						{
							\SemantexDataGetExpNot{lower}
						}
					},
				}
			}
			{
				\SemantexKeysSetx{
					symbol={
						\frac
						{
							\partial ^ { \SemantexDataGet{upper} }
							\SemantexBoolIfT{raisedfunction}
							{
								\SemantexDataGetExpNot{arg}
							}
						}
						{
							\SemantexDataGetExpNot{lower}
						}
					},
				}
			}
			\SemantexDataClear{lower}
			\SemantexDataClear{upper}
			\SemantexBoolIfT{raisedfunction}
			{
				\SemantexDataClear{arg}
				\SemantexIntClear{numberofarguments}
			}
		},
	},
]
\end{lstlisting}
Let us see it in action:
\begin{LTXexample}
\[
	\partialdif[\vx,\vy,\vz]{
		\vf } ,
	\partialdif[\vu^2,\vv^2,
		d=4]{ \vf },
	\partialdif[\vx[1],
		\vx[2],...,\vx[\vn],
		d=\vn]{ \vf }
\]
\[
	\partialdif[\vx,\vy,\vz,noraisedfunction]{ \vf } ,
	\partialdif[\vu^2,\vv^2,
		d=4,noraisedfunction]{
			\vf },
	\partialdif[\vx[1],
		\vx[2],...,\vx[\vn],
		d=\vn,noraisedfunction]{
			\vf	}
\]
\end{LTXexample}
As you see, we use the \lstinline!d!~key to tell the command what superscript it should put on the~\( \partial \) in the enumerator. If it does not receive a~\lstinline!d!, it counts the number of variables you wrote and prints that. That is why the following would give the wrong result:
\begin{LTXexample}
\[
	\partialdif[\vu^2,\vv^2]{
		\vf },
	\partialdif[\vx[1],
		\vx[2],...,\vx[\vn]]{
		\vf }
\]
\end{LTXexample}

\chapter{Bugs}

Lots of things can be improved in the system, including the order in which things are being expanded internally. I am not going to explain this is detail for now, but hope to correct this in the future. For now, the system seems to work fine as long as you do \enquote{normal} things and insert~\lstinline!\noexpand!'s whenever something goes wrong. The only real bug that I currently know of occurs if you use the key~\lstinline!Othersep! in a heading. Then it all dies painfully.
Then again, why the heck would you do that in the first place? Who scales parentheses in headings?

%\input{testground}

\end{document}