\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} \setlrmarginsandblock{4cm}{*}{*} \setulmarginsandblock{4cm}{*}{*} \checkandfixthelayout \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} %\newcommand\hypersetup[1]{} %\newcommand\href[2]{\texttt{#2}} %\newcommand\url[1]{\texttt{#1}} %\newcommand\texorpdfstring[2]{#1} \usepackage[nameinlink]{cleveref} \title{Seman\!\TeX: semantic, keyval-based mathematics (v0.463)} \date{\today} \author{Sebastian Ørsted (\href{mailto:sorsted@gmail.com}{sorsted@gmail.com})} \hypersetup{ pdfauthor={Sebastian Ørsted}, pdftitle={SemanTeX: semantic, keyval-based mathematics}, %pdfsubject={}, %pdfkeywords={}, %pdfproducer={Latex with hyperref, or other system}, %pdfcreator={pdflatex, or other tool}, } \usepackage{showexpl} \lstset{% language=[LaTeX]TeX, basicstyle=\ttfamily\small, commentstyle=\itshape\ttfamily\small, alsoletter={\\}, escapechar=@, breaklines=true, breakindent={0pt}, captionpos=t, pos=r, tabsize=2, %inputencoding=utf8, explpreset={numbers=none,}, texcl=false, wide=false, width=.45\textwidth, } \newcommand\mylst{\lstinline[mathescape]} \let\at=@ \def\<#1\>{\textrm{\textlangle\textit{#1}\textrangle}} \def\usercommand\<#1\>{\textrm{\textbackslash\textlangle\textit{#1}\textrangle}} \def\values\<#1\>{\textrm{\textlangle\textup{#1}\textrangle}} \def\num#1{\textsubscript{\textup{#1}}} \newcommand\default[1]{\smash{\underline{\smash{#1}}}} \newcommand\commandname[1]{\textbackslash\texttt{#1}} \let\pack=\texttt \newcommand\semantex{Seman\!\TeX\xspace} \newcommand\stripsemantex{\texttt{stripsemantex}\xspace} \usepackage{hologo} % Setting up SemanTeX: \usepackage{semantex} \usepackage{expkv} \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} \makeatother \begin{document} \maketitle \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 the user can define their own keys and customize the system down to the last detail. At the same time, care has been taken to make the syntax as simple, natural, practical, and lightweight as possible. Furthermore, the package has a companion package, called \stripsemantex, which allows you to completely strip your documents of \semantex markup to prepare them e.g.~for publication. The package is still in beta, but is considered feature-complete and more or less stable, so using it at this point should be safe. Still, suggestions, ideas, and bug reports are more than welcome! \setlength\cftsectionnumwidth{3em} \tableofcontents* \pagebreak \chapter{Introduction} \begingroup \SetupClass\MyVar{ definekeys={ {conj}{command=\overline}, {inv}{upper={-1}}, {inverseimage}{upper={-1},nopar}, }, definekeys[1]={ {der}{upper={ (#1) } }, {res}{ rightreturn, symbolputright={|}, lower={#1} }, {stalk}{seplower={#1}}, % "seplower" means "separator + lower", i.e. lower index % separated from any previous lower index by a separator, % which by default is 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\MyVar\vg{g} \NewObject\MyVar\vh{h} \NewObject\MyVar\vn{n} \NewObject\MyVar\vp{p} \NewObject\MyVar\vU{U} \NewObject\MyVar\vx{x} \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: definekeys={ % we define a few keys {inv}{upper={-1}}, {conj}{command=\overline}, % Applies \overline to the symbol {inverseimage}{upper={-1},nopar}, }, definekeys[1]={ % we define keys taking 1 value {der}{upper={(#1)}}, {stalk}{seplower={#1}}, % "seplower" means "separator + lower", i.e. lower index % separated from any previous lower index by a separator, % which by default is a comma {res}{ rightreturn, symbolputright={|}, lower={#1} }, }, } \begin{document} $ \vf[conj,der=\vn] $ $ \vg[inv,res=\vU]{\vx} $ $ \vh[inverseimage]{\sheafF}[spar,stalk=\vp] = \sheafF[stalk=\vh{\vp}] $ \end{document} \end{lstlisting} \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!\SemantexBaseObject!. 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 create this class by writing \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 be 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~\usercommand\, you can create objects of that class wtih the syntax \begin{lstlisting} \NewObject@\usercommand\\usercommand\@{@\@}[@\@] \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} @\usercommand\@[@\@]{@\@} \end{lstlisting} Both \ and \ are optional arguments (they can be left out if you do not need them). The \ should consist of a list of options separated by commas, using keyval syntax. Naturally, \ is the actual argument of the function. By a design choice, \semantex does not distinguish between variables and functions, so all variables can take arguments. This makes 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 \ 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 defined 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} In fact, there are quite a few keys for manipulating upper and lower indices. Right now, apart from \lstinline!upper! and~\lstinline!lower!, we shall only need a couple more: \lstinline!sepupper! and~\lstinline!seplower! mean \enquote{separator~+~upper} and \enquote{separator~+~lower}. These are like \lstinline!upper! and~\lstinline!lower!, but if there already was an upper or lower index, the new index will be separated from the old one by a separator. By default, this separator is a comma. There are also two more commands, \lstinline!commaupper! and~\lstinline!commalower!. These will use a comma as separator, even if you have changed the default separator. \section{Next step: Defining more variables} 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}$, $\vf[nopar]{\vx,\vy}$, $\vf[neverpar]{\vx}$, $\vf[neverpar]{\vx,\vy}$ \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} \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 \section{Defining keys} 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. To define keys, we use the command~\lstinline!\SetupClass! (or~\lstinline!\SetupObject! if you want to define it for an individual object) and the key~\lstinline!definekeys!. The syntax is as follows: \begin{lstlisting} \SetupClass\MyVar{ definekeys={ {@\@}{ @\@ }, {@\@}{ @\@ }, {@\@}{ @\@ }, @\ldots,@ }, } \end{lstlisting} For instance, you can do \begin{lstlisting} \SetupClass\MyVar{ definekeys={ {key1}{ upper=3, lower=7 }, {key2}{ lower=6, upper=4 }, }, } \end{lstlisting} Quite often, we shall also need to define keys that can \emph{take a value}. A key can take up to~\( 9 \)~values. To define a key taking \( n \)~values, use~\mylst!definekeys[$n$]! for~\( n = 0 , 1 , 2 , \ldots , 9 \). The syntax is similar to~\lstinline!definekeys!, except the values can be accessed by writing~\lstinline!#1!, \lstinline!#2!, \ldots, \lstinline!#9!. Except for a few special cases, you will probably only ever need~\lstinline!definekeys[1]!. So you can do \begin{lstlisting} \SetupClass\MyVar{ definekeys[1]={ {key3}{ upper=\{#1\} }, {key4}{ lower=(#1) }, }, definekeys[2]={ {key5}{ upper=3+#1, lower=7-#2 }, {key6}{ lower=6\cdot#1, upper=4/#2 }, }, } \end{lstlisting} \begingroup \SetupClass\MyVar{ definekeys={ {key1}{ upper=3, seplower=7 }, {key2}{ lower=6, sepupper=4 }, }, definekeys[1]={ {key3}{ sepupper=\{#1\} }, {key4}{ seplower=(#1) }, }, definekeys[2]={ {key5}{ sepupper=3+#1, seplower=7-#2 }, {key6}{ seplower=6\cdot#1, sepupper=4/#2 }, }, } Let us see these rather ridiculous keys in action: \begin{LTXexample} $ \vP[key1,key3=0,key5={3}{4}] $ \end{LTXexample} \endgroup \chapter{Some examples} \section{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!definekeys! since there is no reason for this key to take a value: \begin{lstlisting} \SetupClass\MyVar{ definekeys={ {inv}{ upper={-1} }, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys={ {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 one value. For defining these, we use a different key, \lstinline!definekeys[1]!. 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{ definekeys={ {inv}{ upper={-1} }, }, definekeys[1]={ {der}{ upper={(#1)} }, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys[1]={ {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{ definekeys={ {inv}{ upper={-1} }, }, definekeys[1]={ {der}{ upper={(#1)} }, {power}{ upper={#1} }, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys[1]={ {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{ definekeys={ {inv}{ upper={-1} }, }, definekeys[1]={ {der}{ upper={(#1)} }, {power}{ upper={#1} }, {res}{ rightreturn,symbolputright={|}, lower={#1} }, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys[1]={ {res}{ rightreturn,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!rightreturn!, 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{ definekeys[1]={ {bigres}{ rightreturn, symbolputright=\big|, lower={#1} }, {Bigres}{ rightreturn, symbolputright=\Big|, lower={#1} }, {biggres}{ rightreturn, symbolputright=\bigg|, lower={#1} }, {Biggres}{ rightreturn, symbolputright=\Bigg|, lower={#1} }, {autores}{ leftreturn, symbolputleft=\kern-\nulldelimiterspace, Otherspar={.}{|}{auto}, symbolputleft=\bgroup, symbolputright=\egroup, lower={#1}, }, % The last key auto-scales the vertical bar. See @\textit{\cref{sec:spar}}@ % for information about Otherspar. % Note that Otherspar automatically invokes rightreturn, % so no need to run that key twice. }, } \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 definekeys={ {inv}{ upper={-1} }, }, definekeys[1]={ {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 \mylst!parent=$\usercommand\$! in the class declaration to tell that \usercommand\ 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. \section{Example: Elementary algebra}\label{sec:algebra} \SetupClass\MyVar{ definekeys={ {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{ definekeys={ {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{ definekeys={ {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{ definekeys={ {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{ definekeys={ {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=\langle, rightpar=\rangle, }, {powerseries}{ par, leftpar=\llbracket, rightpar=\rrbracket, }, {laurent}{ par, leftpar=(, rightpar=), prearg={\!\mathopen{}\SemantexDelimiterSize(}, postarg={\SemantexDelimiterSize)\mathclose{}\!}, % The "prearg" and "postarg" are printed before after % the argument, if the argument is non-empty. % The command "\SemantexDelimiterSize" is substituted % by \big, \Big, ..., or whatever size the % argument delimiters have }, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys={ {freealg}{ par, leftpar=\langle, rightpar=\rangle, }, {powerseries}{ par, leftpar=\llbracket, rightpar=\rrbracket, }, {laurent}{ par, leftpar=(, rightpar=), prearg={\!\mathopen{}\SemantexDelimiterSize(}, postarg={\SemantexDelimiterSize)\mathclose{}\!}, % These are printed before and after the argument. % The command "\SemantexDelimiterSize" is substituted % by \big, \Big, ..., or whatever size the % argument delimiters have }, }, } 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{ definekeys={ {op}{upper={\mathrm{op}}}, % opposite groups, rings, categories, etc. {algclosure}{command=\overline}, % algebraic closure {conj}{command=\overline}, % complex conjugation {dual}{upper=*}, % dual vector space {perp}{upper=\perp}, % orthogonal complement }, definekeys[1]={ {mod}{rightreturn,symbolputright={/#1}}, % for modulo notation like R/I {dom}{leftreturn,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={ \lbrack #1^{-1} \rbrack }}, % localization at a multiplicative subset; % we use \lbrack and \rbrack rather than [ and ] since in some % cases (using constructions like in @{\itshape\cref{ch:the_class_command}}@), % the [...] might be interpreted as an optional argument. {localizeprime}{seplower={#1}}, % for localization at a prime ideal }, } \end{lstlisting} \SetupClass\MyVar{ definekeys={ {op}{upper={\mathrm{op}}}, % opposite groups, rings, categories, etc. {algclosure}{command=\overline}, % algebraic closure {conj}{command=\overline}, % complex conjugation {dual}{upper=*}, % dual vector space {perp}{upper=\perp}, % orthogonal complement }, definekeys[1]={ {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={ \lbrack #1^{-1} \rbrack }}, % localization at a multiplicative subset {localizeprime}{seplower={#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} \section{GIT quotients} \SetupClass\MyVar{ definekeys[2]={ {projquotient}{ symbolputright={ /\!\!/ _ { #1 } #2 } }, } } We include a slightly more advanced example to show the use of keys with more than one value. Sometimes, a key with one value is simply not enough. For instance, if you work in geometric invariant theory~(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 the the key~\lstinline!definekeys[2]!: \begin{lstlisting} \SetupClass\MyVar{ definekeys[2]={ {projquotient}{ symbolputright={ /\!\!/_{#1} #2 } }, } } \end{lstlisting} \begin{LTXexample} $ \vX[projquotient={\vchi}{\vG}] $ \end{LTXexample} \chapter{Some more techniques} \section{The \texttt{spar} key}\label{sec:spar} 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={@\@}{@\@} Otherspar={@\@}{@\@}{@\values\@} \end{lstlisting} The last argument in \lstinline!Otherspar! sets the size of the parentheses. Let us see them in action: \begin{LTXexample} $\vf[otherspar={[}{)}, otherspar={\{}{\rangle}, Otherspar={\langle}{\rangle}{\Bigg},spar]$ \end{LTXexample} \section{The \texorpdfstring{\texttt{$\backslash$\}}{Class} command}\label{ch:the_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 \mylst!\MyVar{$\$}!~creates a variable on the spot with symbol~\mylst!$\$!. 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~\usercommand\, you can use it as a command with the following syntax: \begin{lstlisting} @\usercommand\@{@\@}[@\@]@\@ \end{lstlisting} \section{The \texttt{command} key} \begingroup Above, we used the key~\lstinline!command! a couple of times: \begin{LTXexample} $\va[command=\overline]$, $\vH[command=\widetilde]$ \end{LTXexample} This key applies the given command to the symbol. Sometimes, it is useful to put these commands into keys instead. So you can do stuff like \begin{lstlisting} \SetupClass\MyVar{ definekeys={ {tilde}{command=\tilde}, {widetilde}{command=\widetilde}, {bar}{command=\bar}, {bold}{command=\mathbf}, {roman}{command=\mathrm}, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys={ {tilde}{command=\tilde}, {widetilde}{command=\widetilde}, {bar}{command=\bar}, {bold}{command=\mathbf}, {roman}{command=\mathrm}, }, } Let us test: \begin{LTXexample} $\va[widetilde]$, $\va[bold]$, $\va[roman]$, $\va[bar]$ \end{LTXexample} Note that there is a predefined key,~\lstinline!smash!, which is equivalent to~\lstinline!command=\smash!. \endgroup \section{The \texttt{return} keys}\label{ch:return} Let us suppose in this section that we have defined the key~\lstinline!conj! for complex conjugation, like in the introduction. 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 key, called \lstinline!return!, that can be applied at any point to invoke the routine of adding all current commands, indices, and arguments to the symbol. Let us try it out: \begin{LTXexample} $\vf[inv,return,conj]$ \end{LTXexample} Before we invoked~\lstinline!return!, the symbol was~\lstinline!f!, and the~\lstinline!-1! was stored as an upper index. But after the \lstinline!return! routine, the symbol is~\lstinline!f^{-1}!, and consequently, when we apply the~\lstinline!conj! key, you add a line above the whole thing. There are some cases when you do not want to add all commands, indices, and arguments to the symbol at the same time. Therefore, there exist a few extra, partial \lstinline!return! keys that only add some of them to the symbol and save the rest of later. We list the most important ones here and refer to~\cref{sec:fundamental_keys} for the remaining ones. Most users will probably only ever need the keys \lstinline!return! and~\lstinline!rightreturn!. \begin{itemize} \item \mylst!return! Invokes the return routine, i.e.\ adds all commands, indices, and arguments to the symbol, if any such exist. \item \mylst!innerreturn! Invokes the inner return routine, i.e.\ adds all commands to the symbol, if any such exist. \item \mylst!rightreturn! Invokes the right return routine, i.e.\ adds all commands, right indices, and right arguments to the symbol, if any such exist. \item \mylst!leftreturn! Invokes the left return routine, i.e.\ adds all commands, left indices, and left arguments to the symbol, if any such exist. \end{itemize} \section{Keyval syntax conflicts} You can pass anything you want as key values, including other objects. But you quickly run into the following problem: Imagine you try setting~\lstinline!\vx[1,power=2]! as the lower index of a the object~\lstinline!\va!. If you try \begin{lstlisting} $ \va[lower=\vx[1,power=2]] $ \end{lstlisting} then the system will break. Indeed, the system will see the object~\lstinline!\va! to which you have passed the two keys \begin{center} \lstinline!lower=\vx[1! \qquad\text{and}\qquad \lstinline!power=2]!. \end{center} To avoid this behaviour, you will have to enclose the key value in braces: \begin{LTXexample} $ \va[lower={\vx[1,power=2]}] $ \end{LTXexample} So far so good, but if you use our favourite shorthand notation for lower indices (simply writing the index in the options, like~\lstinline!\va[1]!), then it still goes wrong: \begin{lstlisting} $ \va[{\vx[1,power=2]}] $ \end{lstlisting} The reason is that in \LaTeX\ (really, the \pack{xparse} package from \LaTeX3) interprets \lstinline![{...}]! more or less like~\lstinline![...]! in this case. To make up for this, you can use either of the following strategies: \begin{LTXexample} $ \va[ {\vx[1,power=2]} ] $, $ \va[\vx[{1,power=2}]] $ \end{LTXexample} There is a similar problem in the arguments, since arguments also allow a kind of keyval syntax (the keys that need equality signs are turned off by default, though; more on that in \cref{ch:arg_keyval}). But it will still react on commas and keys like~\lstinline!...!. Therefore, in order to ensure the correct output, you will also have to enclose any argument containing commas with braces: \begin{LTXexample} $ \vf{ \vg[{upper=3,lower=2}] } $, $ \vf{ {\vg[upper=3,lower=2]} } $ \end{LTXexample} As mentioned in \cref{ch:arg_keyval}, you \emph{can} also turn keyval syntax in arguments completely off, avoiding such issues. This can be done by setting \begin{lstlisting} \SetupClass\MyVar{ argkeyval=false, } \end{lstlisting} \subsection{Cheating your way around keyval syntax conflicts} \begingroup If you grow tired of having to deal with such issues all the time, there are solutions to either partly or completely avoid this. The first solution we present does not solve the problem with~\lstinline!\va[\vx[1,power=2}]!, but it does solve problems like \begin{lstlisting} $ \va[lower=\vx[lower=3]] $ \end{lstlisting} Normally, this will not work, as the underlying keyval machinery of \LaTeX3 does not allow key values to contain equality signs. However, there is another keyval package that does: the excellent package \pack{expkv}. To switch to the keyval parser of this package, we do \begin{lstlisting} \usepackage{expkv} \SemantexSetup{ keyvalparser=\ekvparse, } \end{lstlisting} \SemantexSetup{ keyvalparser=\ekvparse, } Now you can do \begin{LTXexample} $ \va[lower=\vx[lower=3]] $ \end{LTXexample} In general, using the key \mylst!keyvalparser={$\$}! sets the keyval parser function to be the command~\. The \ must take three arguments: \mylst!$\\\${$\$}!. The \ must take one argument, while \~must take two. For a key-value list, \~will be applied to single keys taking no values, while \~will be applied to keys taking a value. By default, this key has been set to the command \lstinline!\keyval_parse:NNn! from~\LaTeX3. Changing this key will only affect keys for objects and classes, \emph{not} keys for use inside~\lstinline!\SemantexSetup!. \endgroup A more drastic solution is to use the package~\pack{stricttex}, which has been developed mainly as a companion package to~\semantex. Unfortunately, it only works in~\hologo{LuaTeX}. If you don't know what \hologo{LuaTeX} is, that means that you are not using \hologo{LuaTeX}, and you should note that switching is a rather drastic affair since your existing font settings might very well not work with LuaTeX. Also, \semantex does not exactly make your document faster, and \hologo{LuaTeX} makes it even slower, so think carefully before you make the switch just for this. In any case, with \pack{stricttex}, you will be able to make brackets \enquote{strict}, which means that any \lstinline![! will be replaced by a~\lstinline![{!, and that any~\lstinline!]! will be replaced by a~\lstinline!}]!. This will make all of the above work just fine: \begin{lstlisting} \StrictBracketsOn $ \va[lower=\vx[lower=3]] $ $ \va[\vx[1,power=2]] $ $ \vf{ \vg[upper=3,lower=2] } $ \StrictBracketsOff \end{lstlisting} There is no demonstration on the right since this manual has not been typeset using \hologo{LuaTeX}, so it would not work. \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{ definekeys={ {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{ definekeys={ {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{ definekeys[1]={ {stalk}{seplower={#1}}, % "seplower" means "separator + lower", i.e. lower index % separated from any previous lower index by a separator, % which by default is a comma {sheaftwist}{return,symbolputright={(#1)}}, }, definekeys={ {sheafify}{upper=+}, {sheafdual}{upper=\vee}, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys[1]={ {stalk}{seplower={#1}}, % "seplower" means "separator + lower", i.e. lower index % separated from any previous lower index by a separator, % which by default is a comma {sheaftwist}{return,symbolputright={(#1)}}, }, definekeys={ {sheafify}{upper=+}, {sheafdual}{upper=\vee}, }, } \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{ definekeys[1]={ {shift}{ rightreturn,symbolputright={ \relax [ {#1} ] } }, % we use \lbrack and \rbrack rather than [ and ] since in some % cases (using constructions like in @{\itshape\cref{ch:the_class_command}}@), % the [...] might 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{ definekeys[1]={ {shift}{ rightreturn,symbolputright={ \lbrack #1 \rbrack } }, % we use \lbrack and \rbrack rather than [ and ] since in some % cases (using constructions like in @{\itshape\cref{ch:the_class_command}}@), % the [...] might 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 \texttt{d}-index and the \texttt{i}-index} In branches of mathematics such as homological algebra, 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. You can adjust this by writing \lstinline!gradingposition=upper! or~\lstinline!gradingposition=lower!. We already learned about the keys \lstinline!upper! and~\lstinline!lower!, as well as their friends \lstinline!sepupper!, \lstinline!seplower!, \lstinline!commaupper!, \lstinline!commalower!, etc. There also exist \enquote{relative} versions of these 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!d!, \lstinline!sepd!, \lstinline!commad! \qquad\qquad and\qquad\qquad \lstinline!i!, \lstinline!sepi!, \lstinline!commai!, \end{center} and consequently, we shall refer to the indices they correspond to as the \enquote{\lstinline!d!-index} and the \enquote{\lstinline!i!-index}. The \lstinline!d! stands for \enquote{degree} and corresponds to the grading. The~\lstinline!i! stands for \enquote{index} and corresponds to the \enquote{other} index where you may store additional information.\footnote{These names are not perfect; you might object 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.} To understand the difference, keep the following two examples in mind: the hom complex~\( \Hom[*,i=\vA] \) and the simplicial homology~\( \ho[*,i=\vDelta] \) (we will define the command~\lstinline!\ho! for homology in the next section): \begin{LTXexample} $\Hom[i=\vA,d=0]$, $\ho[i=\vDelta,d=1]$ \end{LTXexample} 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 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! in the \lstinline!i!-index. 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 \noindent 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 actions of these keys are invoked. In fact, \semantex carefully separates keys taking a value from keys taking no values. \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! we just created works very much like a command of \lstinline!Variable! type. However, the input syntax is a bit different: \begin{lstlisting} \co[@\@]{@\@}{@\@} \end{lstlisting} All three arguments are optional. The~\ is printed in the \lstinline!d!-index. 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{ definekeys={ {reduced}{command=\widetilde}, {cech}{command=\check}, {hyper}{command=\mathbb}, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys={ {reduced}{command=\widetilde}, {cech}{command=\check}, {hyper}{command=\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{ definekeys[1]={ {Lder} { leftreturn, symbolputleft=\mathbb{L}^{#1}, }, {Rder} { leftreturn, symbolputleft=\mathbb{R}^{#1}, }, }, definekeys={ {Lder} { leftreturn, symbolputleft=\mathbb{L}, }, {Rder} { leftreturn, symbolputleft=\mathbb{R}, }, }, } \end{lstlisting} \SetupClass\MyVar{ definekeys[1]={ {Lder} { leftreturn, symbolputleft=\mathbb{L}^{#1}, }, {Rder} { leftreturn, symbolputleft=\mathbb{R}^{#1}, }, }, definekeys={ {Lder} { leftreturn, symbolputleft=\mathbb{L}, }, {Rder} { leftreturn, symbolputleft=\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[copy=\Hom,Rder] \end{lstlisting} \NewObject\MyVar\RHom[copy=\Hom,Rder] The \lstinline!copy! 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)}\label{ch:arg_keyval} \SetupClass\MyVar{ defineargkeys[1]={ {coef}{ othersep={;}{#1} }, }, } \SetupObject\co{ argkeyval=true, } 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. To define argument keys, we use the key~\lstinline!defineargkeys!, or~\mylst!defineargkeys[$n$]! if you want it to be able to take $n$~values for~$n=0,1,2,\ldots,9$. The syntax for these is just like the syntax for the keys~\lstinline!definekeys! and~\mbox{\mylst!definekeys[$n$]!}. However, for reasons we shall see in a moment, argument keys (at least those taking values) are actually turned off by default, so we shall have to turn them on first: \begin{lstlisting} \SetupClass\MyVar{ argkeyval=true, % this turns keyval syntax in arguments on defineargkeys[1]={ {coef}{ othersep={;}{#1} }, }, } \end{lstlisting} 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. We shall later (see~\cref{ch:parse_coho_coef}) see another, possibly more natural way to write cohomology with coefficients, and which avoids turning on keyval syntax in the argument. As mentioned, we had to turn keyval syntax on in order for it to work. By default, only keys taking no values are turned on in the argument. The reason is that argument keys taking values are only useful in very rare cases, such as 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} The key~\lstinline!argkeyval! can take four arguments: \lstinline!true! (which we used above, keyval syntax is completely on), \lstinline!false! (no keys allowed), \lstinline!singlekeys! (the default behaviour where only keys taking no values are allowed), and \lstinline!onesinglekey! (only allows one key, taking no value). It should be noted that there are several predefined argument keys on the level of the class \lstinline!\SemantexBaseObject!. The full list can be found in \cref{sec:predefined_arg_keys}. \chapter{Left indices} Left indices are a recurring problem in all \TeX-based systems since \TeX\ only has metrics for the positioning of right indices, none for left indices. And it seems that even the later \TeX\ engines are making no attempts at correcting this. So most packages for left indices use variations of the following approach: \begin{LTXexample} $ {}^{*} f $ \end{LTXexample} Notice the large space between the star and the~\( f \). To tackle this problem, the author has written the \pack{leftindex} package which at least attempts to improve this situation: \begin{LTXexample} $ \leftindex^{*} {f} $ \end{LTXexample} Roughly, what it does is to use a \enquote{height phantom} and a \enquote{slanting phantom} to position the left superscript. The vertical positions of the left indices will be calculated using the height phantom, and the indentation of the left superscript will be calculated using the slanting phantom. More precisely, it will copy the metrics for the positioning of right indices from the slanting phantom and use that to position the left superscript. By default, both phantoms are set to be equal to the symbol, which goes fine sometimes, and at other times, another slanting phantom has to be specified. Below, the~\lstinline!I!~is the specified, custom slanting phantom: \begin{LTXexample} $ \leftindex^{*} {\Gamma} $, $ \leftindex[I]^* {\Gamma} $, $ \leftindex^* {A} $, $ \leftindex[P]^* {A} $ \end{LTXexample} We refer to the manual of the package \pack{leftindex} for details, see \begin{center} \url{https://ctan.org/pkg/leftindex} \end{center} Our solution for left indices in \semantex is based directly on the one from \pack{leftindex}. However, it works much better if you use \semantex than if you just used \pack{leftindex} alone, due to the ability to centrally control all your notation. This allows you to choose height and slanting phantoms once and for all in the preamble and never have to worry about it in your document body. Just like we have the keys \lstinline!upper!, \lstinline!lower!, \lstinline!sepupper!, \lstinline!seplower!, \lstinline!commaupper!, \mbox{\lstinline!commalower!,} we have a similar collection of keys for left indices: \lstinline!upperleft!, \lstinline!lowerleft!, \mbox{\lstinline!sepupperleft!,} \lstinline!seplowerleft!, \lstinline!commaupperleft!, \lstinline!commalowerleft!: \begin{LTXexample} $ \vf[upperleft=*] $, $ \vGamma[upperleft=*] $, $ \vA[upperleft=*] $ \end{LTXexample} When you create a new object in \semantex, the height and slanting phantoms will automatically be set to be equal to the symbol. However, as we see above, we sometimes need to change them. This can be done using the keys \lstinline!heightphantom! and~\lstinline!slantingphantom!: \begin{LTXexample} \SetupObject\vGamma{ slantingphantom=I} \SetupObject\vA{slantingphantom=P} $ \vf[upperleft=*] $, $ \vGamma[upperleft=*] $, $ \vA[upperleft=*] $ \end{LTXexample} Sometimes, changing the slanting phantom is not quite enough. In the previous example, the star is still not quite close enough to the~\( \vA \), and there is no slanting phantom that is quite slanted enough to correct this. We solve this using the key~\lstinline!postupperleft!. What you add using this key will be printed after the upper left index, provided the upper left index is non-empty and hence will be printed in the first place. There is also a \lstinline!preupperleft!, and there are similarly \lstinline!prelowerleft!, \lstinline!postlowerleft!, \lstinline!preupper!, \lstinline!postupper!, \lstinline!prelower!, and~\lstinline!postlower!. Let us see it in action: \begin{LTXexample} \SetupObject\vA{ slantingphantom=P, postupperleft=\!, } $ \vA[upperleft=*] $ \end{LTXexample} Note that \semantex at least does its best to try to guess new height and slanting phantoms when you use operations on objects: \begin{LTXexample} $ \vA[spar=\Bigg,upperleft=*] $, $ \vP[command=\overline,return, upperleft=*] $ \end{LTXexample} \chapter{The \texorpdfstring{\texttt{Symbol}}{Symbol} class type (Example: Derived tensor products and fibre products)} \NewSymbolClass\MyBinaryOperator[ definekeys={ {Lder}{upper=L}, {Rder}{upper=R}, }, ] \NewObject\MyBinaryOperator\tensor{\otimes}[ definekeys={ {der}{Lder}, }, ] \NewObject\MyBinaryOperator\fibre{\times}[ % Americans are free to call it \fiber instead definekeys={ {der}{Rder}, }, ] \semantex has facilities for printing tensor products~\( \tensor \) as well as derived tensor products~\( \tensor[der] \). For this, we need the \lstinline!Symbol! 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} @\usercommand\@[@\@] \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 think. Let us try to use it to define tensor products and fibre products: \begin{lstlisting} \NewSymbolClass\MyBinaryOperator[ definekeys={ {Lder}{upper=L}, {Rder}{upper=R}, }, ] \NewObject\MyBinaryOperator\tensor{\otimes}[ definekeys={ {der}{Lder}, }, ] \NewObject\MyBinaryOperator\fibre{\times}[ % Americans are free to call it \fiber instead definekeys={ {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{The \texorpdfstring{\texttt{Delimiter}}{Delimiter} class type} \NewDelimiterClass\MyDelim[parent=\MyVar] \NewObject\MyDelim\norm{\lVert}{\rVert}[ definekeys[1]={ {default}{ outputoptions={ default={#1} } }, }, ] \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@\usercommand\@{@\@}{@\@}[@\@] \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} In the case where you want to use different kinds of norms, say \( \norm[2]{slot} \) or~\( \norm[\infty]{slot} \), you can use the key~\mylst!outputoptions={$\$}!. This allows you to pass the~\ to the output class (in this case,~\lstinline!\MyVar!): \begin{lstlisting} \SetupObject\norm{ definekeys[1]={ {default}{ outputoptions={ default={#1} } }, }, } \end{lstlisting} \begin{LTXexample} $\norm{\vx}$, $\norm[2]{\vx}$, $\norm[\infty]{\vx}$ \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!~construction: \begin{lstlisting} \newcommand\wherecommand[1]{ \nonscript\: #1\vert \allowbreak \nonscript\: \mathopen{} } \NewObject\MyVar\where{ \wherecommand{\SemantexDelimiterSize} } \NewObject\MyDelim\Set{\lbrace}{\rbrace}[ prearg={\,},postarg={\,}, % adds \, inside {...}, as recommended by D. Knuth argkeyval=false, % this turns off all keyval syntax in the argument ] \end{lstlisting} \newcommand\wherecommand[1]{ \nonscript\: #1\vert \allowbreak \nonscript\: \mathopen{} } \NewObject\MyVar\where{ \wherecommand{\SemantexDelimiterSize} } \NewObject\MyDelim\Set{\lbrace}{\rbrace}[ prearg={\,},postarg={\,}, % adds \, inside {...}, as recommended by D. Knuth argkeyval=false, % this turns off all keyval syntax in the argument ] \noindent As we briefly mentioned previously, \lstinline!\SemantexDelimiterSize!~is a command that returns the size of the delimiters in the argument. Now you can use \begin{LTXexample} $\Set{ \vx\in\vY \where \vx\ge0 }$, $\Set[par=\big]{ \vx\in\vY \where \vx\ge0 }$ \end{LTXexample} Don't forget that, since the class~\lstinline!\MyDelim! inherits from~\lstinline!\MyVar!, the output of any of these commands also belongs to class~\lstinline!\MyVar!. So you can do stuff like \begin{LTXexample} $\Set{ \vx \in \vY[\vi] \where \vx \ge 0 }[command=\overline,\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 delimiters for other, less obvious purposes, like calculus differentials: \begin{lstlisting} \NewDelimiterClass\CalculusDifferential[ parent=\MyVar, defineargkeys[1]={ {default}{sep={d\!#1}}, % default is the key that is automatically applied by the % system to anything you write in the argument that is % not recognized as an argument key. The sep 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={\,}, nextargwithsep=true, % because of this, even the first argument will % receive a separator, which in this case % is a small space ] \NewObject\CalculusDifferential\wedgeD{(}{)}[setargsep=\wedge] \end{lstlisting} \NewDelimiterClass\CalculusDifferential[ parent=\MyVar, defineargkeys[1]={ {default}{sep={d\!#1}}, % default is the key that is automatically applied by the % system to anything you write in the argument that is % not recognized as an argument key. The sep 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={\,},nextargwithsep=true] \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{Using \texorpdfstring{Seman\!\TeX{}}{SemanTeX} in other commands using \texorpdfstring{\texttt{\textbackslash UseClassInCommand}}{\UseClassInCommand}}\label{sec:UseClassInCommand} \SemantexRecordObject{\Frac} \newcommand\Frac[2]{ \SemantexRecordSource{\Frac{#1}{#2}} \UseClassInCommand\MyVar{ \frac{#1}{#2} } } Sometimes, it is useful to create other commands based on \semantex classes. For instance, if you grow tired of writing~\lstinline!\MyVar{ \frac{...}{...} }! whenever you want to apply keys to a fraction, it could make sense to create a command~\lstinline!\Frac! which automatically wraps the fraction in~\lstinline!\MyVar!. The first guess how to do that would be something like \begin{lstlisting} \newcommand\Frac[2]{ \MyVar{ \frac{#1}{#2} } } \end{lstlisting} \begin{LTXexample} \[ \Frac{1}{2}[spar=\Big,power=2] \] \end{LTXexample} Indeed, this will work fine for most people. In fact, the only case where this might cause issues is if you want to use the \pack{stripsemantex} algorithm to strip your document of \semantex markup. But in order to prepare yourself for this possibility, I recommend getting used from the start to doing it in a slightly more cumbersome way: \begin{lstlisting} \SemantexRecordObject{\Frac} \newcommand\Frac[2]{ \SemantexRecordSource{\Frac{#1}{#2}} \UseClassInCommand\MyVar{ \frac{#1}{#2} } } \end{lstlisting} \begin{LTXexample} \[ \Frac{1}{2}[spar=\Big,power=2] \] \end{LTXexample} First things first: We used the following command in front of~\lstinline!\MyVar!: \begin{lstlisting} \UseClassInCommand@\usercommand\@[@\@]{@\@}@\@ \end{lstlisting} So the first advantage to writing~\lstinline!\UseClassInCommand\MyVar! instead of just~\lstinline!\MyVar! is that you can pass an additional set of options to the class first. However, there is a more important difference, namely that this solution makes the command compatible with the \pack{stripsemantex} algorithm. The reason the first solution was not compatible with \pack{stripsemantex} is that, in this case, the algorithm will desperately look through your document for the code~\lstinline!\MyVar{ \frac{1}{2} }[spar=\Big,power=2]! in order to strip it from your document. But it will find it nowhere, as this code is hidden away in the \lstinline!\Frac!~command. Therefore, we do three things: \begin{itemize} \item We register the command~\lstinline!\Frac! as a \semantex command using the line \begin{lstlisting} \SemantexRecordObject{\Frac} \end{lstlisting} After this, \semantex \enquote{knows} that \lstinline!\Frac!~is part of the family of \semantex markup. \item We use the command~\lstinline!\SemantexRecordSource! to \enquote{record} the source of the command internally. This way, \pack{stripsemantex} will know what to look for when it moves through the document, trying to strip it of \semantex markup. It is therefore important that you record the source exactly like it will be written in the source. (You need not worry about missing braces, though; even if you write~\lstinline!\Frac12! in your document, \pack{stripsemantex} will still recognize the code and strip it as expected.) \item We write~\lstinline!\UseClassInCommand\MyVar! instead of just~\lstinline!\MyVar! in order to correctly record the output code internally. Roughly speaking, when you use the command~\lstinline!\UseClassInCommand!, \semantex \enquote{knows} that the class~\lstinline!\MyVar! is now used as part of some greater construction. \end{itemize} \section{Example: Category theory} \newcommand\categoryformat[1]{{\operatorname{\mathsf{#1}}}} % This means that we write categories with sans-serif fonts; % -- but you can change this to your own liking. % We use \operatorname since it will allow us to use ordinary % dashes (rather than minuses) in math mode. % We use an extra pair of braces around \operatorname % in order to make it an ordinary symbol (instead of an operator). % This solution is inspired by an answer by egreg (obviously), % see https://tex.stackexchange.com/a/567886/19809 \NewObject\MyVar\catset{\categoryformat{Set}} \NewObject\MyVar\cattop{\categoryformat{Top}} \NewObject\MyVar\catvect{\categoryformat{Vect}} \SemantexRecordObject{\catxmod} \newcommand\catxmod[1]{ \SemantexRecordSource{\catxmod{#1}} \UseClassInCommand\MyVar{#1\categoryformat{-mod}} } \SemantexRecordObject{\catmodx} \newcommand\catmodx[1]{ \SemantexRecordSource{\catmodx{#1}} \UseClassInCommand\MyVar{\categoryformat{mod-}#1} } \SemantexRecordObject{\catxmody} \newcommand\catxmody[2]{ \SemantexRecordSource{\catxmody{#1}{#2}} \UseClassInCommand\MyVar{#1\categoryformat{-mod-}#2} } \SemantexRecordObject{\catxmodx} \newcommand\catxmodx[1]{ \SemantexRecordSource{\catxmodx{#1}} \UseClassInCommand\MyVar{#1\categoryformat{-mod-}#1} } The above method can be used to create commands for typing categories. First and foremost, it is easy to create objects corresponding to simple categories like~\( \catset \), \( \cattop \) and~\( \catvect \): \begin{lstlisting} \newcommand\categoryformat[1]{{\operatorname{\mathsf{#1}}}} % This means that we write categories with sans-serif fonts; % -- but you can change this to your own liking. % We use \operatorname since it will allow us to use ordinary % dashes (rather than minuses) in math mode. % We use an extra pair of braces around \operatorname % in order to make it an ordinary symbol (instead of an operator). % This solution is inspired by an answer by egreg (obviously), % see @\itshape\url{https://tex.stackexchange.com/a/567886/19809}@ \NewObject\MyVar\catset{\categoryformat{Set}} \NewObject\MyVar\cattop{\categoryformat{Top}} \NewObject\MyVar\catvect{\categoryformat{Vect}} \end{lstlisting} \begin{LTXexample} $ \catset $, $ \cattop $, $ \catvect{\vk} $. \end{LTXexample} However, we run into issues with categories like~\( \catxmod{\vR} \) where we shall constantly have to change the ring~\( \vR \). For this, we use the constructions we learned at the introduction to this chapter: \begin{lstlisting} \SemantexRecordObject{\catxmod} \newcommand\catxmod[1]{ \SemantexRecordSource{\catxmod{#1}} \UseClassInCommand\MyVar{#1\categoryformat{-mod}} } \end{lstlisting} \begin{LTXexample} $ \catxmod{\vR} $, $ \catxmod{\vS} $, $ \catxmod{\vA}[spar,op] $ \end{LTXexample} (here, we used the key~\lstinline!op! which we defined in \cref{sec:algebra}). You can, of course, extend it to all sorts of other situations, like \( \catmodx{\vR} \) or~\( \catxmody{\vR}{\vS} \): \begin{lstlisting} \SemantexRecordObject{\catmodx} \newcommand\catmodx[1]{ \SemantexRecordSource{\catmodx{#1}} \UseClassInCommand\MyVar{\categoryformat{mod-}#1} } \SemantexRecordObject{\catxmody} \newcommand\catxmody[2]{ \SemantexRecordSource{\catxmody{#1}{#2}} \UseClassInCommand\MyVar{#1\categoryformat{-mod-}#2} } \SemantexRecordObject{\catxmodx} \newcommand\catxmodx[1]{ \SemantexRecordSource{\catxmodx{#1}} \UseClassInCommand\MyVar{#1\categoryformat{-mod-}#1} } \end{lstlisting} \chapter{The \texorpdfstring{\texttt{parse}}{parse} routine} \NewObject\MyVar\Mat{\operatorname{Mat}}[ % We provide data sets "rows" and "columns" to % be set up by the user later dataprovide={rows}, dataprovide={columns}, dataprovide={field}, definekeys[1]={ {rows}{ dataset={rows}{#1} }, % set the rows data set {columns}{ dataset={columns}{#1} }, % set the columns data set {field}{ dataset={field}{#1} }, % set the underlying field {arg}{ field={#1} }, % this way, setting the argument becomes equivalent % to specifying the underlying field }, parseoptions={ % Here we add code to the parse routine % We check whether columns = rows. If so, we only write % the number once strifeqTF={\SemantexDataGetExpNot{columns}}{\SemantexDataGetExpNot{rows}} { setkeysx={ lower={\SemantexDataGetExpNot{columns}}, }, } { setkeysx={ lower={ \SemantexDataGetExpNot{rows} \times \SemantexDataGetExpNot{columns} }, }, }, ifblankF={\SemantexDataGetExpNot{field}} { setargkeysx={ sep={\SemantexDataGetExpNot{field}}, }, }, }, ] \NewObject\MyVar\GL{\operatorname{GL}}[ % We provide a few data sets: dataprovide=order, % The "order" will be the number n in GL_n(k) dataprovide=field, % The "field" is of course the k in GL_n(k) definekeys[1]={ {order}{ dataset={order}{#1} }, % Sets the order {field}{ dataset={field}{#1} }, % Sets the field {arg}{ field={#1} }, % This way, setting the argument becomes equivalent % to setting the field }, parseoptions={ setkeysx={ % This means set the keys, but fully expand their values first lower={\SemantexDataGetExpNot{order}}, }, ifblankF={\SemantexDataGetExpNot{field}} { setargkeysx={ % Set the argument keys, but fully expand their values first sep={\SemantexDataGetExpNot{field}}, }, }, }, ] \SetupObject\co{ dataprovide=coefficient, dataprovide=space, definekeys[1]={ {coef}{ dataset={coefficient}{#1} }, {space}{ dataset={space}{#1} }, {arg}{ space={#1} }, }, parseoptions={ ifblankF={\SemantexDataGetExpNot{space}} { setargkeysx={ sep=\SemantexDataGetExpNot{space}, }, }, ifblankF={\SemantexDataGetExpNot{coefficient}} { setargkeysx={ othersep={;}{ \SemantexDataGetExpNot{coefficient} }, }, }, }, } As you can see above, \semantex has a \enquote{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 collection of data in any order, and have the system take care of printing them in the right places, according to how you program the object in the preamble. For this purpose, we have the \lstinline!parse!~routine. Using the \lstinline!parse! routine allows for a comfortable, HTML-like syntax, e.g.: \begin{LTXexample} $ \GL[order=\vn,field=\vk] $, $ \Mat[rows=\vm,columns=\vn, field=\vk] $, $ \co[d=0,coef=\vR,space=\vX] $ \end{LTXexample} The \lstinline!parse! routine is a collection of code which is executed right before an object (or class) is being rendered (but before it outputs). By default, the parse routine contains no code. However, you can add code to it using the key~\mylst!parseoptions={$\$}!. Even though the \lstinline!parse!~routine is automatically invoked right before rendering, you can also invoke it at any time by force using the key~\lstinline!parse!. This will also empty the code from the \lstinline!parse!~routine so that it will not be executed twice: \begin{LTXexample} $ \GL[order=\vn,field=\vk,parse, spar,op] $ \end{LTXexample} (here we used the key~\lstinline!op! from \cref{sec:algebra}). Alternatively, you can add a new pair of brackets, which will render the object and invoke the \lstinline!parse!~routine: \begin{LTXexample} $\GL[order=\vn,field=\vk][spar,op]$ \end{LTXexample} Note, though, that in this case, the \lstinline!spar! and~\lstinline!op!~keys are not being applied to the object~\lstinline!\GL! itself, but to the object (of class~\lstinline!\MyVar!) that it outputs. This should not cause any issues in practice, as long as the keys you are using are already defined on the level of~\lstinline!\MyVar!. \section{Example: Matrix sets and groups} Suppose we want to be able to write the group of invertible \( \vn \times \vn \)-matrices with entries in~\( \vk \) as~\( \GL[order=\vn,field=\vk] \). We can in principle do the following: \begingroup \SetupObject\GL{ dataclear=parseoptions, definekeys[1]={ {arg}{ setargkeys={sep=#1} } }, } \begin{lstlisting} \NewObject\MyVar\GL{\operatorname{GL}} \end{lstlisting} \begin{LTXexample} $ \GL[\vn]{\vk} $. \end{LTXexample}% However, this is not quite as systematic and semantic as we might have wanted. Indeed, what if later we would like to change the notation to~\( \GL{\vn,\vk} \)? We could in principle use a key with 2~values for this. However, in this section, we show how to use the \lstinline!parse!~routine to enable the syntax from the introduction to this chapter. \endgroup As mentioned there, we need to add code via the \lstinline!parse!~routine. However, to make proper use of it, we need some programming keys and programming commands. You can find an overview of these in~\cref{sec:programming_keys,sec:programming_commands}. To set up the notation from above, we do the following: \begin{lstlisting} \NewObject\MyVar\GL{\operatorname{GL}}[ % We provide a few data sets: dataprovide=order, % The "order" will be the number n in GL_n(k) dataprovide=field, % The "field" is of course the k in GL_n(k) definekeys[1]={ {order}{ dataset={order}{#1} }, % Sets the order {field}{ dataset={field}{#1} }, % Sets the field {arg}{ field={#1} }, % This way, setting the argument becomes equivalent % to setting the field }, parseoptions={ setkeysx={ % This means set the keys, but fully expand their values first lower={\SemantexDataGetExpNot{order}}, }, ifblankF={\SemantexDataGetExpNot{field}} { setargkeysx={ % Set the argument keys, but fully expand their values first sep={\SemantexDataGetExpNot{field}}, }, }, }, ] \end{lstlisting} Notice that we changed the \lstinline!arg!~key. This means that specifying the argument becomes equivalent to setting the field. This is what makes the first two pieces of syntax below equivalent: \begin{LTXexample} $ \GL[order=\vn,field=\vk] $, $ \GL[order=\vn]{\vk} $, $ \GL[order=\vn] $. \end{LTXexample} Let us look at a more complicated example: The set~\( \Mat[rows=\vn,columns=\vm,field=\vk] \) of \( \vn \times \vm \)-matrices with entries in~\( \vk \). What makes this example more complicated is not only that we have an additional piece of data, but that we require that if the number of rows and columns are equal, we want it to print~\( \Mat[rows=\vn,columns=\vn,field=\vk] \) rather than~\( \Mat[rows=\vn,columns={}\vn,field=\vk] \). We accomplish this by the following: \begin{lstlisting} \NewObject\MyVar\Mat{\operatorname{Mat}}[ % We provide data sets "rows" and "columns" to % be set up by the user later dataprovide={rows}, dataprovide={columns}, dataprovide={field}, definekeys[1]={ {rows}{ dataset={rows}{#1} }, % set the rows data set {columns}{ dataset={columns}{#1} }, % set the columns data set {field}{ dataset={field}{#1} }, % set the underlying field {arg}{ field={#1} }, % this way, setting the argument becomes equivalent % to specifying the underlying field }, parseoptions={ % Here we add code to the parse routine % We check whether columns = rows. If so, we only write % the number once strifeqTF={\SemantexDataGetExpNot{columns}}{\SemantexDataGetExpNot{rows}} { setkeysx={ lower={\SemantexDataGetExpNot{columns}}, }, } { setkeysx={ lower={ \SemantexDataGetExpNot{rows} \times \SemantexDataGetExpNot{columns} }, }, }, ifblankF={\SemantexDataGetExpNot{field}} { setargkeysx={ sep={\SemantexDataGetExpNot{field}}, }, }, }, ] \end{lstlisting} \begin{LTXexample} $ \Mat[rows=\vm,columns=\vn, field=\vk] $, $ \Mat[rows=\vn,columns=\vn, field=\vk] $. \end{LTXexample} \section{Example: Cohomology with coefficients, revisited}\label{ch:parse_coho_coef} As promised previously, we revisit cohomology with coefficients and show how to set up a syntax like the below: \begin{lstlisting} \SetupObject\co{ dataprovide=coefficient, dataprovide=space, definekeys[1]={ {coef}{ dataset={coefficient}{#1} }, {space}{ dataset={space}{#1} }, {arg}{ space={#1} }, }, parseoptions={ ifblankF={\SemantexDataGetExpNot{space}} { setargkeysx={ sep=\SemantexDataGetExpNot{space}, }, }, ifblankF={\SemantexDataGetExpNot{coefficient}} { setargkeysx={ othersep={;}{ \SemantexDataGetExpNot{coefficient} }, }, }, }, } \end{lstlisting} \begin{LTXexample} $\co[d=0]$, $\co[d=0,space=\vX]$, $\co[d=0,space=\vX,coef=\vR]$ \end{LTXexample} \section{Example: Partial derivatives} Let us look at a more complicated example: Let us create a command for partial derivatives: \NewObject\MyVar\partialdif[ nopar, boolprovide={raisefunction}, boolsettrue={raisefunction}, setidots=\cdots, setisep=\,, definekeys[1]={ {default}{ sepi={\partial #1}, }, {raise}{ strifeqTF={#1}{true} { boolsettrue={raisefunction}, } { strifeqTF={#1}{false} { boolsetfalse={raisefunction}, } { ERRORkeyvaluenotfound={raise}{#1}, }, }, }, }, parseoptions={ ifblankTF={ \SemantexDataGetExpNot{upper} } { intifgreaterTF={ \SemantexIntGet{numberoflowerindices} } { 1 } { setkeysx={ symbol={ \SemantexExpNot\frac { \partial ^ { \SemantexIntGet{numberoflowerindices} } \SemantexBoolIfT{raisefunction} { \SemantexDataGetExpNot{arg} } } { \SemantexDataGetExpNot{lower} } }, }, } { setkeysx={ symbol={ \SemantexExpNot\frac { \partial \SemantexBoolIfT{raisefunction} { \SemantexDataGetExpNot{arg} } } { \SemantexDataGetExpNot{lower} } }, } }, } { setkeysx={ symbol={ \SemantexExpNot\frac { \partial ^ { \SemantexDataGetExpNot{upper} } \SemantexBoolIfT{raisefunction} { \SemantexDataGetExpNot{arg} } } { \SemantexDataGetExpNot{lower} } }, }, }, dataclear={lower}, dataclear={upper}, boolifT={raisefunction} { dataclear={arg}, intclear={numberofarguments}, }, }, ] \begin{lstlisting} \NewObject\MyVar\partialdif[ nopar, boolprovide={raisefunction}, boolsettrue={raisefunction}, setidots=\cdots, setisep=\,, definekeys[1]={ {default}{ sepi={\partial #1}, }, {raise}{ strifeqTF={#1}{true} { boolsettrue={raisefunction}, } { strifeqTF={#1}{false} { boolsetfalse={raisefunction}, } { ERRORkeyvaluenotfound={raise}{#1}, }, }, }, }, parseoptions={ ifblankTF={ \SemantexDataGetExpNot{upper} } { intifgreaterTF={ \SemantexIntGet{numberoflowerindices} } { 1 } { setkeysx={ symbol={ \SemantexExpNot\frac { \partial ^ { \SemantexIntGet{numberoflowerindices} } \SemantexBoolIfT{raisefunction} { \SemantexDataGetExpNot{arg} } } { \SemantexDataGetExpNot{lower} } }, }, } { setkeysx={ symbol={ \SemantexExpNot\frac { \partial \SemantexBoolIfT{raisefunction} { \SemantexDataGetExpNot{arg} } } { \SemantexDataGetExpNot{lower} } }, } }, } { setkeysx={ symbol={ \SemantexExpNot\frac { \partial ^ { \SemantexDataGetExpNot{upper} } \SemantexBoolIfT{raisefunction} { \SemantexDataGetExpNot{arg} } } { \SemantexDataGetExpNot{lower} } }, }, }, dataclear={lower}, dataclear={upper}, boolifT={raisefunction} { dataclear={arg}, intclear={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,raise=false]{ \vf } , \partialdif[\vu^2,\vv^2, d=4,raise=false]{ \vf }, \] \[ \partialdif[\vx[1], \vx[2],...,\vx[\vn], d=\vn,raise=false]{ \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{\texorpdfstring{\texttt{stripsemantex}}{stripsemantex} -- stripping your document of \texorpdfstring{\semantex}{SemanTeX} markup} \semantex is a big, heavy package, and it might raise eyebrows if you try using it in submissions to journals. On top of that, \url{arXiv.org} is using \TeX~Live~2016 at the time of writing this, and it has an old version of \LaTeX3 that seems unable to run \semantex. To address this issue, \semantex has a companion package, called \pack{stripsemantex}, which allows you to strip the \semantex markup from your document and replace it with raw \LaTeX~code. While no such algorithm will ever be perfect, it generally works very well, even for quite complicated constructions, as long as you use the package in the \enquote{normal} and supported way. (If you want proof, have a look at my recent paper which was stripped using the algorithm: \url{https://arxiv.org/abs/2008.04794}.) The system has the following limitations: \begin{itemize} \item It is currently only able to strip the \semantex markup from your main document (so it will ignore anything in \lstinline!\input{...}! and~\lstinline!\include{...}!). So prior to running \pack{stripsemantex}, you should include your entire document body in your main \texttt{.tex}~file. \item Partly because of the previous point, no attempt is made to remove the \emph{setup} of \semantex, so commands like \lstinline!\NewObject!, \lstinline!\SetupObject!, and~\lstinline!\SetupClass! will remain in the document body. You will then have to remove these yourself afterwards. But the \semantex markup itself should be stripped completely from your document. \item As mentioned, as long as you do normal, supported things, everything should work fine. Non-normal, non-supported things are tings like \begin{lstlisting} \va[execute={\vb}] \end{lstlisting} \item Things might go wrong if you define new keys between \lstinline!\begin{document}! and~\lstinline!\end{document}! whose definitions make use of other \semantex objects or classes, since the algorithm will try to strip these from the definitions. For instance, don't do stuff like this after~\lstinline!\begin{document}!: \begin{lstlisting} \SetupObject\va{ definekeys[1]={ {weirdkey}{ upper=\vb[ {#1} ] } }, } \end{lstlisting} If you do, the algorithm will then try and strip this occurrence of~\lstinline!\vb! from the key definition. To avoid such issues, only ever define keys in your preamble, as the algorithm will ignore everything before \lstinline!\begin{document}!. \item When the document has just been stripped, it will load a small package called \pack{semtex}, which contains a couple of commands that the output will need in order to run. You will be able to replace all of these commands by other commands and then render the package \pack{semtex} unnecessary. More on this in \cref{sec:semtex_package}. \item When \semantex runs, the content of any argument is being wrapped between \lstinline!\begingroup! and~\lstinline!\endgroup!. This is part of what makes it possible to use the command~\lstinline!\SemantexDelimiterSize!. However, these \lstinline!\begingroup! and~\lstinline!\endgroup! will not appear in the stripped document. This means that if you do stuff like \begin{lstlisting} $ \def\foo{bar} \va{ \def\foo{barbar} \vx } \foo $ \end{lstlisting} then this will print~\( \va{\vx} bar \) before running \pack{stripsemantex}, but~\( \va{\vx} barbar \) after. In order to avoid this, simply don't define commands inside arguments, which you should never do in the first place (and why would you anyway?). \end{itemize} As a small proof of concept, this is what the example in the introduction would look like when stripped of \semantex markup: \begin{lstlisting} % Same preamble as before. \begin{document} $ \overline{f}^{(n)} $ $ g^{-1}|_{U} (x) $ $ (h^{-1} \mathcal{F})_{p} = \mathcal{F}_{h(p)} $ \end{document} \end{lstlisting} Yes, I know, this was a very simple, unconvincing example. If you want a less trivial example, as mentioned before, you can have a look at my latest paper, which was stripped with (a previous alpha version of) \pack{stripsemantex}: \begin{center} \url{https://arxiv.org/abs/2008.04794} \end{center} \section{The \texttt{semtex} package}\label{sec:semtex_package} When you have stripped your document and removed all \semantex package setup, it should be safe to remove the loading of \semantex from your preamble. However, the stripping algorithm will automatically add the following lines to your document right before~\lstinline!\begin{document}!: \begin{lstlisting} % The following was added by "stripsemantex": \usepackage{semtex,leftindex,graphicx} \providecommand\SemantexLeft{% \mathopen{}\mathclose\bgroup\left } \providecommand\SemantexRight{% \aftergroup\egroup\right } \makeatletter \DeclareRobustCommand\SemantexBullet{% \mathord{\mathpalette\SemantexBullet@\at@{0.5}}% } \newcommand\SemantexBullet@\at@[2]{% \vcenter{\hbox{\scalebox{#2}{$\m@\at@th#1\bullet$}}}% } \DeclareRobustCommand\SemantexDoubleBullet{\SemantexBullet \SemantexBullet} \makeatother \end{lstlisting} The package \pack{leftindex} is loaded to take care of any possible left indices. The package~\pack{graphicx} is loaded to provide the command~\lstinline!\scalebox!. This package~\pack{semtex} is a small package whose sole purpose is to be loaded by stripped \semantex documents. All it does is define the four commands \lstinline!\SemantexLeft!, \lstinline!\SemantexRight!, \lstinline!\SemantexBullet!, and~\lstinline!\SemantexDoubleBullet! so that you can remove these definitions from your document and just rely on the package instead. Let us take a look at the commands defined by \pack{semtex}: \begin{itemize} \item \mylst!\SemantexBullet!, \mylst!\SemantexDoubleBullet! The commands that contain the bullets we use in \semantex, i.e.~the superscript in~\( \co{*} \). These bullets are smaller (and prettier, in my opinion) than the standard \lstinline!\bullet! command from~\LaTeX. \item \mylst!\SemantexLeft!, \mylst!\SemantexRight! Like \lstinline!\left...\right!, but fixing some spacing issues around these. They are completely equivalent to~\lstinline!\mleft! and~\lstinline!\mright! from the package~\pack{mleftright}, so it is safe to just load that package and replace the above commands by \lstinline!\mleft...\mright! instead, or use the redefinitions mentioned above. \end{itemize} \section{The \texttt{stripsemantex} algorithm} The stripping algorithm works like this. It will work in any \TeX\ engine (\hologo{pdfTeX}, \hologo{XeTeX}, \hologo{LuaTeX}, etc.), but along the way, you will have to create a small, separate document and compile it with \hologo{LuaTeX}. Suppose in the following that you \TeX\ document is called~\texttt{mydoc.tex}. \begin{enumerate}[(1)] \item Make sure to collect all of the \semantex markup you want stripped in the main document,~\texttt{mydoc.tex}. Also make sure to follow the recommendations in \cref{sec:UseClassInCommand}, in case you have created commands of the form described there. \item Put the following somewhere in your preamble, after the loading of \semantex: \begin{lstlisting} \SemantexSetup{semtexfile=true} \end{lstlisting} \item Compile your document \texttt{mydoc.tex} using your preferred \TeX\ engine (\hologo{pdfTeX}, \hologo{XeTeX}, \hologo{LuaTeX}, or whatever). Because of the previous step, there will now be a new file, \texttt{mydoc.semtex}, in your folder, where the raw output of each \semantex command is stored. In a moment, \pack{stripsemantex} will use this information to replace each command by the raw code it outputs. \item Create another \TeX\ document in the same folder as \texttt{mydoc.tex}, and call it \texttt{stripdoc.tex} (or whatever you want). Put the following into it: \begin{lstlisting} \documentclass{article} \usepackage{stripsemantex} \begin{document} \StripSemantex{mydoc} \end{document} \end{lstlisting} Then compile it \textbf{with \hologo{LuaTeX}}. After this step, another document will have been created in the same folder, called~\lstinline!mydoc_prestripped.tex!. It will look just like \texttt{mydoc.tex}, but in the document body, each \semantex markup command will now have a command \mylst!\SemantexIDcommand{$\$}! preceding it. \item\label{pt:pre_strip_point} Compile the document \lstinline!mydoc_prestripped.tex! using the same \TeX\ engine as the one you used for \texttt{mydoc.tex}. \item\label{pt:strip_point} Compile the document~\lstinline!stripdoc.tex! again, this time also \textbf{using \hologo{LuaTeX}}. \item After the previous step, some (but usually not all) \semantex markup will have been removed from the file~\lstinline!mydoc_prestripped.tex!. If the stripping algorithm has terminated (which it almost never does after a single run), there will now be a new document in your folder, called~\lstinline!mydoc_stripped.tex!. If this document is not there, repeat the steps \ref{pt:pre_strip_point} and~\ref{pt:strip_point}. Continue this way until the file \lstinline!mydoc_stripped.tex! appears. It can easily require three or more iterations, but each iteration will usually be faster than the previous one, and eventually, the file~\lstinline!mydoc_stripped.tex! will appear. (Note that at the point~\ref{pt:strip_point}, \pack{stripsemantex} will also issue a warning if the algorithm has not yet terminated, asking you to repeat the steps \ref{pt:pre_strip_point} and~\ref{pt:strip_point}). Note again that your \semantex \textbf{setup} will not be removed, so there will still be commands like \lstinline!\NewObject!, \lstinline!\SetupObject!, \lstinline!\SetupClass!,~etc. left. You will then have to remove these few commands from your document manually. \end{enumerate} Apart from the machinery for stripping \semantex markup from documents, the package \pack{stripsemantex} also provides the command~\lstinline!\StripSemantexStripComments!, which is in principle completely unrelated to \semantex itself. This command allows you to strip all comments between \lstinline!\begin{document}! and~\lstinline!\end{document}!. If your document is again called~\lstinline!mydoc.tex!, you can create the following document and compile it \textbf{with \hologo{LuaTeX}}: \begin{lstlisting} \documentclass{article} \usepackage{stripsemantex} \begin{document} \StripSemantexStripComments{mydoc} \end{document} \end{lstlisting} This will create a new document, called \lstinline!mydoc_comments_stripped.tex!, where all comments in the document body have been removed. \chapter{Known bugs} If you write e.g.~\lstinline!Otherspar={[}{]}{\Bigg}! in a heading, your command will fail for some reason. It can be solved by omitting the braces around~\lstinline!\Bigg!, i.e.~by replacing it by~\lstinline!Otherspar={[}{]}\Bigg!. \chapter{The predefined keys, commands, and data} In this chapter, we give a complete list of the predefined keys. Firstly, the keys that can be used inside the command~\lstinline!\SemantexSetup! are: \begin{itemize} \item \mylst!keyvalparser={$\$}! Sets the keyval parser function to~\. The \ must take three arguments: \mylst!$\\\${$\$}!. The \ must take one argument, while \~must take two. For a key-value list, \~will be applied to single keys taking no values, while \~will be applied to keys taking a value. By default, this key has been set to the \LaTeX3 command~\mylst!\keyval_parse:NNn!. Another interesting possibility is the command~\lstinline!\ekvparse! from the package~\lstinline!expkv!. This choice will only affect keys for objects and classes, \emph{not} keys for use inside~\lstinline!\SemantexSetup!. \item \mylst!semtexfile={$\values\$}! When turned on, a \lstinline!.semtex! file will be created while processing the document. This is mainly relevant when using \lstinline!stripsemantex!. \end{itemize} Apart from this, \semantex has a large collection of keys that are predefined for the class \lstinline!\SemantexBaseObject!. In the following sections, we include the full list. \section{Keys for defining and removing keys} \begin{itemize} \item \mylst!definekeys={$\$}! Defines keys taking no values. The syntax is \begin{lstlisting} definekeys={ {key1}{ upper=3, lower=7 }, {key2}{ lower=6, upper=4 }, }, \end{lstlisting} \item \mylst!definekeys[$n$]={$\$}! Defines keys taking $n$~values, where $n=0,1,2,\ldots,9$. The values are accessed by writing \lstinline!#1!,~\lstinline!#2!, \ldots,~\lstinline!#9!. The syntax is \begin{lstlisting} definekeys[2]={ {key1}{ upper=3+#1, lower=7-#2 }, {key2}{ lower=6\cdot#1, upper=4/#2 }, }, \end{lstlisting} \item \mylst!removekey=$\$! Removes the key~\ taking no values. \item \mylst!removekey[$n$]=$\$! Removes the key~\ taking $n$~values, where $n=0,1,2,\ldots,9$. \item \mylst!defineargkeys={$\$}! Defines argument keys taking no values. The syntax is similar to the one for~\lstinline!definekeys!. \item \mylst!defineargkeys[$n$]={$\$}! Defines argument keys taking $n$~values, where $n=0,1,2,\ldots,9$. The syntax is similar to the one for~\mylst!definekeys[$n$]!. \item \mylst!removeargkey=$\$! Removes the argument key~\ taking no values. \item \mylst!removeargkey[$n$]=$\$! Removes the argument key~\ taking $n$~values, where $n=0,1,2,\ldots,9$. \end{itemize} \section{Programming keys}\label{sec:programming_keys} \begin{itemize} \item \mylst!execute={$\<\TeX\ code\>$}! Executes the \<\TeX\ code\> on the spot. \item \mylst!setkeys={$\$}!, \mylst!keysset={$\$}! Sets the keys \. \item \mylst!setkeysx={$\$}!, \mylst!keyssetx={$\$}! Sets the keys \, but fully expands their values. \item \mylst!dataprovide={$\$}! Provides a new piece of data consisting of a token list. \item \mylst!dataset={$\$}{$\$}! Sets the \ to \. \item \mylst!datasetx={$\$}{$\$}! Sets the \ to \, but fully expands the \ first. \item \mylst!dataputleft={$\$}{$\$}! Adds the \ to the left of \. \item \mylst!dataputleftx={$\$}{$\$}! Adds the \ to the left of \, but fully expands the \ first. \item \mylst!dataputright={$\$}{$\$}! Adds the \ to the right of \. \item \mylst!dataputrightx={$\$}{$\$}! Adds the \ to the right of \, but fully expands the \ first. \item \mylst!dataclear={$\$}! Clears the piece of data~\. \item \mylst!boolprovide={$\$}! Provides a new piece of data consisting of a boolean. \item \mylst!boolsettrue={$\$}! Sets the \ to true. \item \mylst!boolsettrue={$\$}! Sets the \ to false. \item \mylst!boolifTF={$\$}{$\$}{$\$}!, \\ \mylst!boolifT={$\$}{$\$}!, \\ \mylst!boolifTF={$\$}{$\$}! Runs \ or \, depending on the value of \. \item \mylst!intprovide={$\$}! Provides a new piece of data consisting of an integer. \item \mylst!intset={$\$}{$\$}! Sets the \ to \. \item \mylst!intincr={$\$}! Increases the \ by~\( 1 \). \item \mylst!intifeqTF={$\$}{$\$}{$\$}{$\$}!, \\ \mylst!intifeqT={$\$}{$\$}{$\$}!, \\ \mylst!intifeqF={$\$}{$\$}{$\$}! Checks whether the integers \ and \ are equal, and runs \ or \ accordingly. \item \mylst!intifgreaterTF={$\$}{$\$}{$\$}{$\$}!, \\ \mylst!intifgreaterT={$\$}{$\$}{$\$}!, \\ \mylst!intifgreaterF={$\$}{$\$}{$\$}! Checks whether the integer \ is greater than~\, and runs \ or \ accordingly. \item \mylst!intiflessTF={$\$}{$\$}{$\$}{$\$}!, \\ \mylst!intiflessT={$\$}{$\$}{$\$}!, \\ \mylst!intiflessF={$\$}{$\$}{$\$}! Checks whether the integer \ is less than~\, and runs \ or \ accordingly. \item \mylst!intclear={$\$}! Clears the \, i.e.~sets it to~\( 0 \). \item \mylst!ifblankTF={$\$}{$\$}{$\$}!,\\ \mylst!ifblankT={$\$}{$\$}!,\\ \mylst!ifblankF={$\$}{$\$}! Fully expands the \ and checks if it is blank, and runs \ or \ according to this. \item \mylst!strifeqTF={$\$}{$\$}{$\$}{$\$}!, \\ \mylst!strifeqT={$\$}{$\$}{$\$}!, \\ \mylst!strifeqF={$\$}{$\$}{$\$}! Checks whether the strings \ and \ are equal, and runs \ or \ accordingly. \item \mylst!ERROR={$\$}! Issues an generic error message. At the end of the message, it automatically adds \enquote{object~\usercommand\ on line~\} or \enquote{class~\usercommand\ on line~\}. \item \mylst!ERRORkeyvaluenotfound={$\$}{$\$}! Issues an error, saying that the key~\ was set to the unknown value~\. \item \mylst!ERRORargkeyvaluenotfound={$\$}{$\$}! Issues an error, saying that the argument key~\ was set to the unknown value~\. \end{itemize} \section{Fundamental keys for class/object information}\label{sec:fundamental_keys} \begin{itemize} \item \mylst!parent={$\$}! Sets the class to have parent~\. \item \mylst!class={$\$}! Sets the object to have class~\. \item \mylst!copy={$\$}! Sets the object to be a copy of~\. Then \ works as a \enquote{parent object}, and all information will be inherited from~\ unless modified for the current object. \item \mylst!symbol={$\$}! Sets the symbol to~\. At the same time, the height phantom and the slanting phantom are set to the same value. \item \mylst!symbolputleft={$\$}! Adds \ to the left of the symbol. No change is made to the height phantom or the slanting phantom. \item \mylst!symbolputright={$\$}! Adds \ to the right of the symbol. No change is made to the height phantom or the slanting phantom. \item \mylst!heightphantom={$\$}! Sets the height phantom to~\. \item \mylst!slantingphantom={$\$}! Sets the slanting phantom to~\. \item \mylst!gradingposition={$\values\<\default{upper}|lower\>$}!, \\ \mylst!gradingpos={$\values\<\default{upper}|lower\>$}! Sets whether to use upper (\enquote{cohomological}) or lower (\enquote{homological}) grading. The default is~\lstinline!upper!. \item \mylst!command={$\$}! Applies the \ to the symbol. \item \mylst!clearcommand! Clears the list of commands to be applied to the symbol. \item \mylst!return! Invokes the return routine, i.e.\ adds all commands, indices, and arguments to the symbol, if any such exist. \item \mylst!innerreturn! Invokes the inner return routine, i.e.\ adds all commands to the symbol, if any such exist. \item \mylst!rightreturn! Invokes the right return routine, i.e.\ adds all commands, right indices, and right arguments to the symbol, if any such exist. \item \mylst!leftreturn! Invokes the left return routine, i.e.\ adds all commands, left indices, and left arguments to the symbol, if any such exist. \item \mylst!leftindexreturn! Adds the left indices to the symbol, if any such exists. \item \mylst!rightindexreturn! Adds the right indices to the symbol, if any such exists. \item \mylst!indexreturn! Adds all indices, left and right to the symbol, if any such exists. \item \mylst!leftargreturn! Adds the left argument, if any such exists, to the symbol. \item \mylst!rightargreturn! Adds the right argument, if any such exists, to the symbol. \item \mylst!argreturn! Adds the argument, if any such exists, to the symbol. \item \mylst!output={$\$}! Sets the output class to~\. \item \mylst!dooutput={$\values\$}! Sets whether the current object/class should output or not. The default is false, but the system will automatically change this when needed. \emph{Never} set this to \lstinline!true! by default, as this will cause an infinite loop. \item \mylst!outputoptions={$\$}! Adds the \ to the output options, i.e.\ those options passed to the output class. \item \mylst!parseoptions={$\$}! Adds the \ to the parse options. \item \mylst!parse! Invokes the parse routine. \item \mylst!mathclass={$\$}! Sets the \TeX\ math class to be~\. The intended values are \lstinline!\mathord!, \lstinline!\mathop!, \lstinline!\mathbin!, \lstinline!\mathrel!, \lstinline!\mathopen!, \lstinline!\mathclose!, and~\lstinline!\mathpunct!. \item \mylst!default={$\$}! This is the key that is applied whenever the user writes something in the options which is not a key, e.g.~the~\lstinline!1! in~\lstinline!\vf[1]!. By default, this keys has been set to be equal to~\lstinline!sepi!, but it is meant to be changeable by the user. \item \mylst!degreedefault={$\$}! This is the key where the grading goes. It is the one used by \lstinline!Cohomology! class types. By default, this key has been set to be equal to~\lstinline!sepd!, but it is meant to be changable by the user. \item \mylst!*! Adds a bullet to the \lstinline!d!-index. \item \mylst!**! Adds a double bullet to the \lstinline!d!-index. \item \mylst!slot!, \mylst!-! Adds a slot to the \lstinline!i!-index. \item \mylst!dots!, \mylst!...! Adds three dots to the \lstinline!i!-index. \item \mylst!*withothersep={$\$}! Adds a bullet to the \lstinline!d!-index, separated by the \ from any previous \lstinline!d!-indices. \item \mylst!**withothersep={$\$}! Adds a double bullet to the \lstinline!d!-index, separated by the \ from any previous \lstinline!d!-indices. \item \mylst!arg={$\$}! The key that is applied whenever the user adds an argument via the standard syntax, e.g.~\lstinline!\vf{\vx}!. By default, it is set to be equal to \lstinline!setargsinglekeys!, but it is meant to be changable by the user. \item \mylst!smash! Applies the command~\lstinline!\smash! to the symbol. Equivalent to~\lstinline!command=\smash!. \item \mylst!prime!, \mylst!'!, \mylst!''!, \mylst!'''! Adds one or more primes to the symbol in the upper index. The first one is equivalent to \lstinline!upper={\prime},nextupperwithsep=false!, and the rest are equivalent to multiple iterations of~\lstinline!prime!. \end{itemize} \section{Keys for the argument parentheses} \begin{itemize} \item \mylst!par! Turns parentheses on. Equivalent to \lstinline!usepar=true!. \item \mylst!nopar! Turns parentheses off, but still prints them if more than one argument is received. Equivalent to \lstinline!usepar=false!. \item \mylst!neverpar! Turns parentheses completely off, even if more than one argument is received. (This is ugly and should only be used for special constructions.) Equivalent to \lstinline!usepar=never!. \item \mylst!usepar={$\values\<\default{true}|false|never\>$}! Sets whether or not to use parentheses. If~\lstinline!true!, turns parentheses on (this is the default behaviour). If~\lstinline!false!, turns parentheses off, but still prints them if more than one argument is received. If~\lstinline!never!, turns parentheses completely off, even if more than one argument is received. (This is ugly and should only be used for special constructions.) The default value is~\lstinline!true!. \item \mylst!parsize={$\values\<\default{normal}|auto|*|{\textit{other}}\>$}! Sets the parentheses size. Here,~\lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left...\right!. If another value is received, that value is used for the parenthesis size, so the intended values are~\lstinline!\big!, \lstinline!\Big!, \lstinline!\bigg!,~\lstinline!\Bigg!. \item \mylst!leftpar={$\$}! Sets the left parenthesis. The default value is~\lstinline!(!. \item \mylst!rightpar={$\$}! Sets the right parenthesis. The default value is~\lstinline!)!. \end{itemize} \section{Keys for the \texttt{spar} routine} \begin{itemize} \item \mylst!spar! Invokes the \lstinline!spar! routine. \item \mylst!spar={$\values\$}! Invokes the \lstinline!spar! routine, with the specified parenthesis size. Here,~\lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left...\right!. If another value is received, that value is used for the parenthesis size, so the intended values are~\lstinline!\big!, \lstinline!\Big!, \lstinline!\bigg!,~\lstinline!\Bigg!. \item \mylst!sparsize={$\values\<\default{normal}|auto|*|{\textit{other}}\>$}! Sets the \lstinline!spar! parenthesis size. Here,~\lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left...\right!. If another value is received, that value is used for the parenthesis size, so the intended values are~\lstinline!\big!, \lstinline!\Big!, \lstinline!\bigg!,~\lstinline!\Bigg!. \item \mylst!leftspar={$\$}! Sets the left parenthesis for the \lstinline!spar! routine. The default value is~\lstinline!(!. \item \mylst!rightspar={$\$}! Sets the right parenthesis for the \lstinline!spar! routine. The default value is~\lstinline!)!. \item \mylst!otherspar={$\$}{$\$}! Invokes the \lstinline!spar! routine, but with the assigned parentheses. \item \mylst!Otherspar={$\$}{$\$}{$\values\$}! Invokes the \lstinline!spar! routine, but with the assigned parentheses and size. Here, \lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left...\right!. If another value is received, that value is used for the parenthesis size, so the intended values are~\lstinline!\big!, \lstinline!\Big!, \lstinline!\bigg!,~\lstinline!\Bigg!. \end{itemize} \section{Keys for setting the argument} \begin{itemize} \item \mylst!setargkeys={$\$}!, \mylst!argkeysset={$\$}! Sets the argument keys \. \item \mylst!setargkeysx={$\$}!, \mylst!argkeyssetx={$\$}! Sets the argynebt keys \, but fully expands their values. \item \mylst!setargsinglekeys={$\$}!, \mylst!argsinglekeysset={$\$}! Sets the argument keys \, but only supports keys taking no values. This allows the arguments to contain equality signs without causing issues. \item \mylst!setargsinglekeysx={$\$}!, \mylst!argsinglekeyssetx={$\$}! Sets the argument keys \, but only supports keys taking no values. If a key is not found, the value is fully expanded and printed. This allows the arguments to contain equality signs without causing issues. \item \mylst!setoneargsinglekey={$\$}!, \mylst!oneargsinglekeyset={$\$}! Sets one single argument key taking no values. This allows the argument to contain equality signs and commas without cuasing issues. \item \mylst!setoneargsinglekeyx={$\$}!, \mylst!oneargsinglekeysetx={$\$}! Sets one single argument key taking no values, If the key is not found, the value is fully expanded and printed. This allows the argument to contain equality signs and commas without cuasing issues. \item \mylst!setargwithoutkeyval={$\$}!, \mylst!argwithoutkeyvalset={$\$}! Sets the argument, allowing no keyval syntax. \item \mylst!setargwithoutkeyvalx={$\$}!, \mylst!argwithoutkeyvalsetx={$\$}! Sets the argument, fully expanding its value, and allowing no keyval syntax. \item \mylst!prearg={$\$}! Sets the pre-argument. \item \mylst!postarg={$\$}! Sets the post-argument. \item \mylst!setargsep={$\$}! Sets the argument separator. The default value is a comma. \item \mylst!setargslot={$\$}! Sets the argument slot. The default value is~\lstinline!{-}!. \item \mylst!setargdots={$\$}! Sets the argument dots. The default value is~\lstinline!\dots!. \item \mylst!argkeyval={$\values\$}! Sets whether to use argument keyval syntax or not. If \lstinline!true!, \lstinline!arg! is set equal to~\lstinline!setargkeys!. If \lstinline!false!, it is set to~\lstinline!setargwithoutkeyval!. If \lstinline!singlekeys!, it is set to~\lstinline!setargsinglekeys!. If \lstinline!onesinglekey!, it is set to~\lstinline!setoneargsinglekey!. The default value is~\lstinline!singlekeys!. \item \mylst!argposition={$\values\$}! Sets the position of the argument. The default is~\lstinline!right!, so the argument will be printed to the right of the symbol. \item \mylst!nextargwithsep={$\values\$}! Sets whether the next argument should be separated from the current one with a separator or not. The default is \lstinline!false!, but the system will automatically change this when needed. \item \mylst!separg={$\$}! Adds \ to the argument, separated from any previous argument by the default argument separator. \item \mylst!commarg={$\$}! Adds \ to the argument, separated from any previous argument by a comma. \item \mylst!argwithothersep={$\$}{$\$}! Adds \ to the argument, separated from any previous argument by \. \item \mylst!arg...withothersep={$\$}!, \mylst!argdotswithothersep={$\$}! Adds three dots to the argument, separated from any previous argument by the \. \item \mylst!arg-withothersep={$\$}!, \mylst!argslotwithothersep={$\$}! Adds a slot to the argument, separated from any previous argument by the \. \item \mylst!argdots!, \mylst!arg...! Adds three dots to the argument, separated from any previous arguments by the standard separator. \item \mylst!commargdots!, \mylst!commarg...! Adds three dots to the argument, separated from any previous arguments by a comma. \item \mylst!argslot!, \mylst!arg-! Adds a slot to the argument, separated from any previous arguments by the standard separator. \item \mylst!commargslot!, \mylst!commarg-! Adds a slot to the argument, separated from any previous arguments by a comma. \item \mylst!cleararg! Clears the argument. \item \mylst!clearprearg! Clears the pre-argument. \item \mylst!clearpostarg! Clears the post-argument. \end{itemize} \section{Keys for the upper index} \begin{itemize} \item \mylst!upper={$\$}! Adds to the upper index, with no separator from any previous upper index. \item \mylst!sepupper={$\$}! Adds to the upper index, separated from any previous upper index by the default separator. \item \mylst!commaupper={$\$}! Adds to the upper index, separated from any previous upper index by a comma. \item \mylst!preupper={$\$}! Sets the pre-upper index. \item \mylst!postupper={$\$}! Sets the post-upper index. \item \mylst!upperputleft={$\$}! Adds something to the left of the upper index. As with keys like~\lstinline!upper!, this will also increase the number of registered upper indices by~\( 1 \), and it will set \lstinline!nextupperwithsep=true!. \item \mylst!setuppersep={$\$}! Sets the upper index separator to~\. By default, this is a comma. \item \mylst!nextupperwithsep={$\values\$}! Sets whether the next upper index should be separated from the current one by a separator. \item \mylst!upperwithothersep={$\$}{$\$}! Adds \ to the upper index, separated from any prevous upper index by~\. \item \mylst!upper-!, \mylst!upperslot! Adds a slot to the upper index, with no separator from any previous upper index. \item \mylst!sepupper-!, \mylst!sepupperslot! Adds a slot to the upper index, separated from any previous upper index by the default separator. \item \mylst!commaupper-!, \mylst!commaupperslot! Adds a slot to the upper index, separated from any previous upper index by a comma. \item \mylst!setupperslot={$\$}! Sets the slot for the upper index. By default, this is~\lstinline!{-}!. \item \mylst!upper-withothersep={$\$}!, \mylst!upperslotwithothersep={$\$}! Adds a slot to the upper index, separated from any previous upper index by~\. \item \mylst!upper...!, \mylst!upperdots! Adds three dots to the upper index, with no separator from any previous upper index. \item \mylst!sepupper...!, \mylst!sepupperdots! Adds three dots to the upper index, separated from any previous upper index by the default separator. \item \mylst!commaupper...!, \mylst!commaupperdots! Adds three dots to the upper index, separated from any previous upper index by a comma. \item \mylst!setupperdots={$\$}! Sets the dots for the upper index. By default, this is~\lstinline!\dots!. \item \mylst!upper...withothersep={$\$}!, \mylst!upperdotswithothersep={$\$}! Adds three dots to the upper index, separated from any previous upper index by~\. \item \mylst!upper*! Adds a bullet to the upper index, with no separator from any previous upper index. \item \mylst!upper**! Adds a double bullet to the upper index, with no separator from any previous upper index. \item \mylst!sepupper*! Adds a bullet to the upper index, separated from any previous upper index by the default separator. \item \mylst!sepupper**! Adds a double bullet to the upper index, separated from any previous upper index by the default separator. \item \mylst!commaupper*! Adds a bullet to the upper index, separated from any previous upper index by a comma. \item \mylst!commaupper**! Adds a double bullet to the upper index, separated from any previous upper index by a comma. \item \mylst!upper*withothersep={$\$}! Adds a bullet to the upper index, separated from any previous upper index by~\. \item \mylst!upper**withothersep={$\$}! Adds a double bullet to the upper index, separated from any previous upper index by~\. \item \mylst!clearupper! Clears the upper index. \item \mylst!clearpreupper! Clears the pre-upper index. \item \mylst!clearpostupper! Clears the post-upper index. \end{itemize} \section{Keys for the lower index} \begin{itemize} \item \mylst!lower={$\$}! Adds to the lower index, with no separator from any previous lower index. \item \mylst!seplower={$\$}! Adds to the lower index, separated from any previous lower index by the default separator. \item \mylst!commalower={$\$}! Adds to the lower index, separated from any previous lower index by a comma. \item \mylst!prelower={$\$}! Sets the pre-lower index. \item \mylst!postlower={$\$}! Sets the post-lower index. \item \mylst!lowerputleft={$\$}! Adds something to the left of the lower index. As with keys like~\lstinline!lower!, this will also increase the number of registered lower indices by~\( 1 \), and it will set \lstinline!nextlowerwithsep=true!. \item \mylst!setlowersep={$\$}! Sets the lower index separator to~\. By default, this is a comma. \item \mylst!nextlowerwithsep={$\values\$}! Sets whether the next lower index should be separated from the current one by a separator. \item \mylst!lowerwithothersep={$\$}{$\$}! Adds \ to the lower index, separated from any prevous lower index by~\. \item \mylst!lower-!, \mylst!lowerslot! Adds a slot to the lower index, with no separator from any previous lower index. \item \mylst!seplower-!, \mylst!seplowerslot! Adds a slot to the lower index, separated from any previous lower index by the default separator. \item \mylst!commalower-!, \mylst!commalowerslot! Adds a slot to the lower index, separated from any previous lower index by a comma. \item \mylst!setlowerslot={$\$}! Sets the slot for the lower index. By default, this is~\lstinline!{-}!. \item \mylst!lower-withothersep={$\$}!, \mylst!lowerslotwithothersep={$\$}! Adds a slot to the lower index, separated from any previous lower index by~\. \item \mylst!lower...!, \mylst!lowerdots! Adds three dots to the lower index, with no separator from any previous lower index. \item \mylst!seplower...!, \mylst!seplowerdots! Adds three dots to the lower index, separated from any previous lower index by the default separator. \item \mylst!commalower...!, \mylst!commalowerdots! Adds three dots to the lower index, separated from any previous lower index by a comma. \item \mylst!setlowerdots={$\$}! Sets the dots for the lower index. By default, this is~\lstinline!\dots!. \item \mylst!lower...withothersep={$\$}!, \mylst!lowerdotswithothersep={$\$}! Adds three dots to the lower index, separated from any previous lower index by~\. \item \mylst!lower*! Adds a bullet to the lower index, with no separator from any previous lower index. \item \mylst!lower**! Adds a double bullet to the lower index, with no separator from any previous lower index. \item \mylst!seplower*! Adds a bullet to the lower index, separated from any previous lower index by the default separator. \item \mylst!seplower**! Adds a double bullet to the lower index, separated from any previous lower index by the default separator. \item \mylst!commalower*! Adds a bullet to the lower index, separated from any previous lower index by a comma. \item \mylst!commalower**! Adds a double bullet to the lower index, separated from any previous lower index by a comma. \item \mylst!lower*withothersep={$\$}! Adds a bullet to the lower index, separated from any previous lower index by~\. \item \mylst!lower**withothersep={$\$}! Adds a double bullet to the lower index, separated from any previous lower index by~\. \item \mylst!clearlower! Clears the lower index. \item \mylst!clearprelower! Clears the pre-lower index. \item \mylst!clearpostlower! Clears the post-lower index. \end{itemize} \section{Keys for the upper left index} \begin{itemize} \item \mylst!upperleft={$\$}! Adds to the upper left index, with no separator from any previous upper left index. \item \mylst!sepupperleft={$\$}! Adds to the upper left index, separated from any previous upper left index by the default separator. \item \mylst!commaupperleft={$\$}! Adds to the upper left index, separated from any previous upper left index by a comma. \item \mylst!preupperleft={$\$}! Sets the pre-upper left index. \item \mylst!postupperleft={$\$}! Sets the post-upper left index. \item \mylst!upperleftputright={$\$}! Adds something to the right of the upper left index. As with keys like~\lstinline!upperleft!, this will also increase the number of registered upper left indices by~\( 1 \), and it will set \lstinline!nextupperleftwithsep=true!. \item \mylst!setupperleftsep={$\$}! Sets the upper left index separator to~\. By default, this is a comma. \item \mylst!nextupperleftwithsep={$\values\$}! Sets whether the next upper left index should be separated from the current one by a separator. \item \mylst!upperleftwithothersep={$\$}{$\$}! Adds \ to the upper left index, separated from any prevous upper left index by~\. \item \mylst!upperleft-!, \mylst!upperleftslot! Adds a slot to the upper left index, with no separator from any previous upper left index. \item \mylst!sepupperleft-!, \mylst!sepupperleftslot! Adds a slot to the upper left index, separated from any previous upper left index by the default separator. \item \mylst!commaupperleft-!, \mylst!commaupperleftslot! Adds a slot to the upper left index, separated from any previous upper left index by a comma. \item \mylst!setupperleftslot={$\$}! Sets the slot for the upper left index. By default, this is~\lstinline!{-}!. \item \mylst!upperleft-withothersep={$\$}!, \mylst!upperleftslotwithothersep={$\$}! Adds a slot to the upper left index, separated from any previous upper left index by~\. \item \mylst!upperleft...!, \mylst!upperleftdots! Adds three dots to the upper left index, with no separator from any previous upper left index. \item \mylst!sepupperleft...!, \mylst!sepupperleftdots! Adds three dots to the upper left index, separated from any previous upper left index by the default separator. \item \mylst!commaupperleft...!, \mylst!commaupperleftdots! Adds three dots to the upper left index, separated from any previous upper left index by a comma. \item \mylst!setupperleftdots={$\$}! Sets the dots for the upper left index. By default, this is~\lstinline!\dots!. \item \mylst!upperleft...withothersep={$\$}!, \mylst!upperleftdotswithothersep={$\$}! Adds three dots to the upper left index, separated from any previous upper left index by~\. \item \mylst!upperleft*! Adds a bullet to the upper left index, with no separator from any previous upper left index. \item \mylst!upperleft**! Adds a double bullet to the upper left index, with no separator from any previous upper left index. \item \mylst!sepupperleft*! Adds a bullet to the upper left index, separated from any previous upper left index by the default separator. \item \mylst!sepupperleft**! Adds a double bullet to the upper left index, separated from any previous upper left index by the default separator. \item \mylst!commaupperleft*! Adds a bullet to the upper left index, separated from any previous upper left index by a comma. \item \mylst!commaupperleft**! Adds a double bullet to the upper left index, separated from any previous upper left index by a comma. \item \mylst!upperleft*withothersep={$\$}! Adds a bullet to the upper left index, separated from any previous upper left index by~\. \item \mylst!upperleft**withothersep={$\$}! Adds a double bullet to the upper left index, separated from any previous upper left index by~\. \item \mylst!clearupperleft! Clears the upper left index. \item \mylst!clearpreupperleft! Clears the pre-upper left index. \item \mylst!clearpostupperleft! Clears the post-upper left index. \end{itemize} \section{Keys for the lower left index} \begin{itemize} \item \mylst!lowerleft={$\$}! Adds to the lower left index, with no separator from any previous lower left index. \item \mylst!seplowerleft={$\$}! Adds to the lower left index, separated from any previous lower left index by the default separator. \item \mylst!commalowerleft={$\$}! Adds to the lower left index, separated from any previous lower left index by a comma. \item \mylst!prelowerleft={$\$}! Sets the pre-lower left index. \item \mylst!postlowerleft={$\$}! Sets the post-lower left index. \item \mylst!lowerleftputright={$\$}! Adds something to the right of the lower left index. As with keys like~\lstinline!lowerleft!, this will also increase the number of registered lower left indices by~\( 1 \), and it will set \lstinline!nextlowerleftwithsep=true!. \item \mylst!setlowerleftsep={$\$}! Sets the lower left index separator to~\. By default, this is a comma. \item \mylst!nextlowerleftwithsep={$\values\$}! Sets whether the next lower left index should be separated from the current one by a separator. \item \mylst!lowerleftwithothersep={$\$}{$\$}! Adds \ to the lower left index, separated from any prevous lower left index by~\. \item \mylst!lowerleft-!, \mylst!lowerleftslot! Adds a slot to the lower left index, with no separator from any previous lower left index. \item \mylst!seplowerleft-!, \mylst!seplowerleftslot! Adds a slot to the lower left index, separated from any previous lower left index by the default separator. \item \mylst!commalowerleft-!, \mylst!commalowerleftslot! Adds a slot to the lower left index, separated from any previous lower left index by a comma. \item \mylst!setlowerleftslot={$\$}! Sets the slot for the lower left index. By default, this is~\lstinline!{-}!. \item \mylst!lowerleft-withothersep={$\$}!, \mylst!lowerleftslotwithothersep={$\$}! Adds a slot to the lower left index, separated from any previous lower left index by~\. \item \mylst!lowerleft...!, \mylst!lowerleftdots! Adds three dots to the lower left index, with no separator from any previous lower left index. \item \mylst!seplowerleft...!, \mylst!seplowerleftdots! Adds three dots to the lower left index, separated from any previous lower left index by the default separator. \item \mylst!commalowerleft...!, \mylst!commalowerleftdots! Adds three dots to the lower left index, separated from any previous lower left index by a comma. \item \mylst!setlowerleftdots={$\$}! Sets the dots for the lower left index. By default, this is~\lstinline!\dots!. \item \mylst!lowerleft...withothersep={$\$}!, \mylst!lowerleftdotswithothersep={$\$}! Adds three dots to the lower left index, separated from any previous lower left index by~\. \item \mylst!lowerleft*! Adds a bullet to the lower left index, with no separator from any previous lower left index. \item \mylst!lowerleft**! Adds a double bullet to the lower left index, with no separator from any previous lower left index. \item \mylst!seplowerleft*! Adds a bullet to the lower left index, separated from any previous lower left index by the default separator. \item \mylst!seplowerleft**! Adds a double bullet to the lower left index, separated from any previous lower left index by the default separator. \item \mylst!commalowerleft*! Adds a bullet to the lower left index, separated from any previous lower left index by a comma. \item \mylst!commalowerleft**! Adds a double bullet to the lower left index, separated from any previous lower left index by a comma. \item \mylst!lowerleft*withothersep={$\$}! Adds a bullet to the lower left index, separated from any previous lower left index by~\. \item \mylst!lowerleft**withothersep={$\$}! Adds a double bullet to the lower left index, separated from any previous lower left index by~\. \item \mylst!clearlowerleft! Clears the lower left index. \item \mylst!clearprelowerleft! Clears the pre-lower left index. \item \mylst!clearpostlowerleft! Clears the post-lower left index. \end{itemize} \section{Keys for the \texttt{d}-index} \begin{itemize} \item \mylst!d={$\$}! Adds to the \lstinline!d!-index, with no separator from any previous \lstinline!d!-index. \item \mylst!sepd={$\$}! Adds to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by the default separator. \item \mylst!commad={$\$}! Adds to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by a comma. \item \mylst!pred={$\$}! Sets the pre-\lstinline!d!-index. \item \mylst!postd={$\$}! Sets the post-\lstinline!d!-index. \item \mylst!dputleft={$\$}! Adds something to the left of the \lstinline!d!-index. As with keys like~\lstinline!d!, this will also increase the number of registered \lstinline!d!-indices by~\( 1 \), and it will set \lstinline!nextdwithsep=true!. \item \mylst!setdsep={$\$}! Sets the \lstinline!d!-index separator to~\. By default, this is a comma. \item \mylst!nextdwithsep={$\values\$}! Sets whether the next \lstinline!d!-index should be separated from the current one by a separator. \item \mylst!dwithothersep={$\$}{$\$}! Adds \ to the \lstinline!d!-index, separated from any prevous \lstinline!d!-index by~\. \item \mylst!d-!, \mylst!dslot! Adds a slot to the \lstinline!d!-index, with no separator from any previous \lstinline!d!-index. \item \mylst!sepd-!, \mylst!sepdslot! Adds a slot to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by the default separator. \item \mylst!commad-!, \mylst!commadslot! Adds a slot to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by a comma. \item \mylst!setdslot={$\$}! Sets the slot for the \lstinline!d!-index. By default, this is~\lstinline!{-}!. \item \mylst!d-withothersep={$\$}!, \mylst!dslotwithothersep={$\$}! Adds a slot to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by~\. \item \mylst!d...!, \mylst!ddots! Adds three dots to the \lstinline!d!-index, with no separator from any previous \lstinline!d!-index. \item \mylst!sepd...!, \mylst!sepddots! Adds three dots to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by the default separator. \item \mylst!commad...!, \mylst!commaddots! Adds three dots to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by a comma. \item \mylst!setddots={$\$}! Sets the dots for the \lstinline!d!-index. By default, this is~\lstinline!\dots!. \item \mylst!d...withothersep={$\$}!, \mylst!ddotswithothersep={$\$}! Adds three dots to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by~\. \item \mylst!d*! Adds a bullet to the \lstinline!d!-index, with no separator from any previous \lstinline!d!-index. \item \mylst!d**! Adds a double bullet to the \lstinline!d!-index, with no separator from any previous \lstinline!d!-index. \item \mylst!sepd*! Adds a bullet to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by the default separator. \item \mylst!sepd**! Adds a double bullet to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by the default separator. \item \mylst!commad*! Adds a bullet to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by a comma. \item \mylst!commad**! Adds a double bullet to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by a comma. \item \mylst!d*withothersep={$\$}! Adds a bullet to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by~\. \item \mylst!d**withothersep={$\$}! Adds a double bullet to the \lstinline!d!-index, separated from any previous \lstinline!d!-index by~\. \item \mylst!cleard! Clears the \lstinline!d!-index. \item \mylst!clearpred! Clears the pre-\lstinline!d!-index. \item \mylst!clearpostd! Clears the post-\lstinline!d!-index. \end{itemize} \section{Keys for the \texttt{i}-index} \begin{itemize} \item \mylst!i={$\$}! Adds to the \lstinline!i!-index, with no separator from any previous \lstinline!i!-index. \item \mylst!sepi={$\$}! Adds to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by the default separator. \item \mylst!commai={$\$}! Adds to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by a comma. \item \mylst!prei={$\$}! Sets the pre-\lstinline!i!-index. \item \mylst!posti={$\$}! Sets the post-\lstinline!i!-index. \item \mylst!iputleft={$\$}! Adds something to the left of the \lstinline!i!-index. As with keys like~\lstinline!i!, this will also increase the number of registered \lstinline!i!-indices by~\( 1 \), and it will set \lstinline!nextiwithsep=true!. \item \mylst!setisep={$\$}! Sets the \lstinline!i!-index separator to~\. By default, this is a comma. \item \mylst!nextiwithsep={$\values\$}! Sets whether the next \lstinline!i!-index should be separated from the current one by a separator. \item \mylst!iwithothersep={$\$}{$\$}! Adds \ to the \lstinline!i!-index, separated from any prevous \lstinline!i!-index by~\. \item \mylst!i-!, \mylst!islot! Adds a slot to the \lstinline!i!-index, with no separator from any previous \lstinline!i!-index. \item \mylst!sepi-!, \mylst!sepislot! Adds a slot to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by the default separator. \item \mylst!commai-!, \mylst!commaislot! Adds a slot to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by a comma. \item \mylst!setislot={$\$}! Sets the slot for the \lstinline!i!-index. By default, this is~\lstinline!{-}!. \item \mylst!i-withothersep={$\$}!, \mylst!islotwithothersep={$\$}! Adds a slot to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by~\. \item \mylst!i...!, \mylst!idots! Adds three dots to the \lstinline!i!-index, with no separator from any previous \lstinline!i!-index. \item \mylst!sepi...!, \mylst!sepidots! Adds three dots to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by the default separator. \item \mylst!commai...!, \mylst!commaidots! Adds three dots to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by a comma. \item \mylst!setidots={$\$}! Sets the dots for the \lstinline!i!-index. By default, this is~\lstinline!\dots!. \item \mylst!i...withothersep={$\$}!, \mylst!idotswithothersep={$\$}! Adds three dots to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by~\. \item \mylst!i*! Adds a bullet to the \lstinline!i!-index, with no separator from any previous \lstinline!i!-index. \item \mylst!i**! Adds a double bullet to the \lstinline!i!-index, with no separator from any previous \lstinline!i!-index. \item \mylst!sepi*! Adds a bullet to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by the default separator. \item \mylst!sepi**! Adds a double bullet to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by the default separator. \item \mylst!commai*! Adds a bullet to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by a comma. \item \mylst!commai**! Adds a double bullet to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by a comma. \item \mylst!i*withothersep={$\$}! Adds a bullet to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by~\. \item \mylst!i**withothersep={$\$}! Adds a double bullet to the \lstinline!i!-index, separated from any previous \lstinline!i!-index by~\. \item \mylst!cleari! Clears the \lstinline!i!-index. \item \mylst!clearprei! Clears the pre-\lstinline!i!-index. \item \mylst!clearposti! Clears the post-\lstinline!i!-index. \end{itemize} \section{The predefined argument keys}\label{sec:predefined_arg_keys} These are the predefined keys that work inside the argument. \begin{itemize} \item \mylst!execute={$\$}! Executes the \ on the spot. This is not strictly speaking a logic key, but this allows you to perform logical operations that are not allowed by the other logic keys. \item \mylst!setkeys={$\$}!, \mylst!keysset={$\$}! Sets the keys \. \item \mylst!setkeysx={$\$}!, \mylst!keyssetx={$\$}! Sets the keys \, but fully expands their values. \item \mylst!setargkeys={$\$}!, \mylst!argkeysset={$\$}! Sets the argument keys \. \item \mylst!setargkeysx={$\$}!, \mylst!argkeyssetx={$\$}! Sets the argynebt keys \, but fully expands their values. \item \mylst!setargsinglekeys={$\$}!, \mylst!argsinglekeysset={$\$}! Sets the argument keys \, but only supports keys taking no values. This allows the arguments to contain equality signs without causing issues. \item \mylst!setargsinglekeysx={$\$}!, \mylst!argsinglekeyssetx={$\$}! Sets the argument keys \, but only supports keys taking no values. If a key is not found, the value is fully expanded and printed. This allows the arguments to contain equality signs without causing issues. \item \mylst!setoneargsinglekey={$\$}!, \mylst!oneargsinglekeyset={$\$}! Sets one single argument key taking no values. This allows the argument to contain equality signs and commas without cuasing issues. \item \mylst!setoneargsinglekeyx={$\$}!, \mylst!oneargsinglekeysetx={$\$}! Sets one single argument key taking no values, If the key is not found, the value is fully expanded and printed. This allows the argument to contain equality signs and commas without cuasing issues. \item \mylst!setargwithoutkeyval={$\$}!, \mylst!argwithoutkeyvalset={$\$}! Sets the argument, allowing no keyval syntax. \item \mylst!setargwithoutkeyvalx={$\$}!, \mylst!argwithoutkeyvalsetx={$\$}! Sets the argument, fully expanding its value, and allowing no keyval syntax. \item \mylst!default={$\$}! This is the value that is applied whenever a value is passed to the argument that is not recognized as a key, e.g.~the~\lstinline!\vx! in~\lstinline!\vf{\vx}!. By default, this is set to be equivalent to~\lstinline!sep!. \item \mylst!sep={$\$}! Adds the \ to the argument, separated from any previous argument by the default separator. \item \mylst!comma={$\$}! Adds the \ to the argument, separated from any previous argument by a comma. \item \mylst!-!, \mylst!slot! Adds a slot to the argument, separated from any previous argument by the default separator. \item \mylst!comma-!, \mylst!commaslot! Adds a slot to the argument, separated from any previous argument by a comma. \item \mylst!...!, \mylst!dots! Adds three dots to the argument, separated from any previous argument by the default separator. \item \mylst!comma...!, \mylst!commadots! Adds three dots to the argument, separated from any previous argument by a comma. \item \mylst!othersep={$\$}{$\$}! Adds \ to the argument, separated from any previous argument by~\. \item \mylst!-withothersep={$\$}! , \mylst!slotwithothersep={$\$}! Adds a slot to the argument, separated from any previous argument by \. \item \mylst!...withothersep={$\$}! , \mylst!dotswithothersep={$\$}! Adds three dots to the argument, separated from any previous argument by~\. \end{itemize} \section{The programming commands}\label{sec:programming_commands} The following commands are available for programming inside keys, including \lstinline!execute={...}!: \begin{itemize} \item \mylst!\SemantexThis! Returns the name of the current class or object. It is returned in the format \mylst!object_$\$! and \mylst!class_$\$!, which is the way the names are stored internally. \item \mylst!\SemantexSetKeys{$\$}!, \mylst!\SemantexKeysSet{$\$}! Sets the \. \item \mylst!\SemantexSetKeysx{$\$}!, \mylst!\SemantexKeysSetx{$\$}! Sets the \, but fully expands their values. \item \mylst!\SemantexSetArgKeys{$\$}!, \mylst!\SemantexArgKeysSet{$\$}! Sets the argument \. \item \mylst!\SemantexSetArgKeysx{$\$}!, \mylst!\SemantexArgKeysSetx{$\$}! Sets the argument \, but fully expands their values. \item \mylst!\SemantexSetArgSingleKeys{$\$}!, \mylst!\SemantexArgSingleKeysSet{$\$}! Sets the argument keys \, but only supports keys taking no values. This allows the arguments to contain equality signs without causing issues. \item \mylst!\SemantexSetArgSingleKeysx{$\$}!, \mylst!\SemantexArgSingleKeysSetx{$\$}! Sets the argument keys \, but only supports keys taking no values. If a key is not found, the value is fully expanded and printed. This allows the arguments to contain equality signs without causing issues. \item \mylst!\SemantexSetOneArgSingleKey{$\$}!, \mylst!\SemantexOneSingleArgKeySet{$\$}! Sets one single argument key taking no values. This allows the argument to contain equality signs and commas without cuasing issues. \item \mylst!\SemantexSetOneArgSingleKeyx{$\$}!, \mylst!\SemantexOneSingleArgKeySetx{$\$}! Sets one single argument key taking no values, If the key is not found, the value is fully expanded and printed. This allows the argument to contain equality signs and commas without cuasing issues. \item \mylst!\SemantexSetArgWithoutKeyval{$\$}!, \mylst!\SemantexArgWithoutKeyvalSet{$\$}! Sets the argument, allowing no keyval syntax. \item \mylst!\SemantexSetArgWithoutKeyval{$\$}!, \mylst!\SemantexArgWithoutKeyvalSet{$\$}! Sets the argument, fully expanding its value, and allowing no keyval syntax. \item \mylst!\SemantexDataProvide{$\$}! Provides a new piece of data consisting of a token list. \item \mylst!\SemantexDataSet{$\$}{$\$}! Sets the \ to \. \item \mylst!\SemantexDataSetx{$\$}{$\$}! Sets the \ to \, but fully expands the \ first. \item \mylst!\SemantexDataPutLeft{$\$}{$\$}! Adds the \ to the left of \. \item \mylst!\SemantexDataPutLeftx{$\$}{$\$}! Adds the \ to the left of \, but fully expands the \ first. \item \mylst!\SemantexDataPutRight{$\$}{$\$}! Adds the \ to the right of \. \item \mylst!\SemantexDataPutRightx{$\$}{$\$}! Adds the \ to the right of \, but fully expands the \ first. \item \mylst!\SemantexDataGet{$\$}! Returns the value of \. \item \mylst!\SemantexDataGetExpNot{$\$}! Returns the value of \, enclosed in \lstinline!\unexpanded! so that it can be used within an \lstinline!x!-type expansion. \item \mylst!\SemantexDataClear{$\$}! Clears the piece of data~\. \item \mylst!\SemantexBoolProvide{$\$}! Provides a new piece of data consisting of a boolean. \item \mylst!\SemantexBoolSetTrue{$\$}! Sets the \ to true. \item \mylst!\SemantexBoolSetFalse{$\$}! Sets the \ to false. \item \mylst!\SemantexBoolIfTF{$\$}{$\$}{$\$}!,\\ \mylst!\SemantexBoolIfT{$\$}{$\$}!,\\ \mylst!\SemantexBoolIfF{$\$}{$\$}! Runs \ or \, depending on the value of \. \item \mylst!\SemantexIntProvide{$\$}! Provides a new piece of data consisting of an integer. \item \mylst!\SemantexIntGet{$\$}! Returns the value of the \. \item \mylst!\SemantexIntSet{$\$}{$\$}! Sets the \ to \. \item \mylst!\SemantexIntIncr{$\$}! Increases the \ by~\( 1 \). \item \mylst!\SemantexIntIfEqTF{$\$}{$\$}{$\$}{$\$}!, \\ \mylst!\SemantexIntIfEqT$\$}{$\$}{$\$}!, \\ \mylst!\SemantexIntIfEqF{$\$}{$\$}{$\$}! Checks whether the integers \ and \ are equal, and runs \ or \ accordingly. \item \mylst!\SemantexIntIfGreaterTF{$\$}{$\$}{$\$}{$\$}!, \\ \mylst!\SemantexIntIfGreaterT{$\$}{$\$}{$\$}!, \\ \mylst!\SemantexIntIfGreaterF{$\$}{$\$}{$\$}! Checks whether the integer \ is greater than~\, and runs \ or \ accordingly. \item \mylst!\SemantexIntIfLessTF{$\$}{$\$}{$\$}{$\$}!, \\ \mylst!\SemantexIntIfLessT{$\$}{$\$}{$\$}!, \\ \mylst!\SemantexIntIfLessF{$\$}{$\$}{$\$}! Checks whether the integer \ is less than~\, and runs \ or \ accordingly. \item \mylst!\SemantexIntClear{$\$}! Clears the \, i.e.~sets it to~\( 0 \). \item \mylst!\SemantexIfBlankTF{$\$}{$\$}{$\$}!,\\ \mylst!\SemantexIfBlankT{$\$}{$\$}!,\\ \mylst!\SemantexIfBlankF{$\$}{$\$}! Fully expands the \ and checks if it is blank, and runs \ or \ according to this. \item \mylst!\SemantexStrIfEqTF{$\$}{$\$}{$\$}{$\$}!, \\ \mylst!\SemantexStrIfEqT{$\$}{$\$}{$\$}!, \\ \mylst!\SemantexStrIfEqF{$\$}{$\$}{$\$}! Checks whether the strings \ and \ are equal, and runs \ or \ accordingly. \item \mylst!\SemantexERROR{$\$}! Issues an generic error message. At the end of the message, it automatically adds \enquote{object~\usercommand\ on line~\} or \enquote{class~\usercommand\ on line~\}. \item \mylst!\SemantexERRORKeyValueNotFound{$\$}{$\$}! Issues an error, saying that the key~\ was set to the unknown value~\. \item \mylst!\SemantexERRORArgKeyValueNotFound{$\$}{$\$}! Issues an error, saying that the argument key~\ was set to the unknown value~\. \item \mylst!\SemantexExpNot{$\$}! An alias for \lstinline!\unexpanded! (also known as \lstinline!\exp_not:N! in~\LaTeX3). \end{itemize} \section{The class types} The \semantex system uses several different \emph{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{@\usercommand\@}[@\@] \end{lstlisting} A new object is declared by \begin{lstlisting} \NewObject@\usercommand\@@\usercommand\@{@\@}[@\@] \end{lstlisting} The syntax for this object is \begin{lstlisting} @\usercommand\@[@\@]{@\@} \end{lstlisting} \item \lstinline!Cohomology!: A new class is declared with the syntax \begin{lstlisting} \NewCohomologyClass@\usercommand\@[@\@] \end{lstlisting} A new object is declared by \begin{lstlisting} \NewObject@\usercommand\@@\usercommand\@{@\@}[@\@] \end{lstlisting} The syntax for this object is \begin{lstlisting} @\usercommand\@[@\@]{@\@}{@\@} \end{lstlisting} \item \lstinline!Symbol!: A new class is declared with the syntax \begin{lstlisting} \NewSimpleClass@\usercommand\@[@\@] \end{lstlisting} A new object is declared by \begin{lstlisting} \NewObject@\usercommand\@@\usercommand\@{@\@}[@\@] \end{lstlisting} The syntax for this object is \begin{lstlisting} @\usercommand\@[@\@] \end{lstlisting} \item \lstinline!Delimiter!: A new class is declared with the syntax \begin{lstlisting} \NewDelimiterClass@\usercommand\@[@\@] \end{lstlisting} A new object is declared by \begin{lstlisting} \NewObject@\usercommand\@@\usercommand\@{@\@}{@\@}[@\@] \end{lstlisting} The syntax for this object is \begin{lstlisting} @\usercommand\@[@\@]{@\@} \end{lstlisting} \item \lstinline!Simple!: A new class is declared with the syntax \begin{lstlisting} \NewSimpleClass@\usercommand\@[@\@] \end{lstlisting} A new object is declared by \begin{lstlisting} \NewObject@\usercommand\@@\usercommand\@{@\@}[@\@] \end{lstlisting} The syntax for this object is \begin{lstlisting} @\usercommand\@ \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~\mylst!\New$\$Class! and modify it in whatever way you want. The last class type, called \lstinline!Simple!, is the class type of the class~\lstinline!\SemantexBaseObject!. This class is pretty useless as all it does is print its symbol, without allowing any keyval syntax. So you simply should not use it. \section{The predefined data} By default, the following data are defined for each class or object and are accessible via the programming keys and commands: \begin{itemize} \item \mylst!symbol! (token list): the symbol. \item \mylst!output! (token list): the name of the output class. \item \mylst!outputoptions! (token list): the output options, i.e.~the options to be passed to the output class. \item \mylst!parseoptions! (token list): the parse options, i.e.~the options that are invoked during the parse routine. \item \mylst!mathclass! (token list): the \TeX\ math class command that the final output is evnetually wrapped around; the intended use of this is the \TeX\ commands \lstinline!\mathord!, \lstinline!\mathop!, \lstinline!\mathbin!, \lstinline!\mathrel!, \lstinline!\mathopen!, \lstinline!\mathclose!, and~\lstinline!\mathpunct!. \item \lstinline!heightphantom! (token list): the height phantom that is used for calculating the height of left indices. \item \lstinline!slantingphantom! (token list): the slanting phantom that is used for calculating the slanting of left indices. \item \lstinline!parsize! (token list): the size of the argument parentheses. Here, the value~\lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left...\right!. If another value is received, that value is used for the parenthesis size, so the intended values are~\lstinline!\big!, \lstinline!\Big!, \lstinline!\bigg!,~\lstinline!\Bigg!. The default value is \lstinline!normal!. \item \lstinline!leftpar! (token list): the left argument parenthesis; the default value is~\lstinline!(!. \item \lstinline!rightpar! (token list): the right argument parenthesis; the default value is~\lstinline!)!. \item \lstinline!sparsize! (token list): the size of the symbol parentheses (for use with the \lstinline!spar!~routine). Here, the value~\lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left...\right!. If another value is received, that value is used for the parenthesis size, so the intended values are~\lstinline!\big!, \lstinline!\Big!, \lstinline!\bigg!,~\lstinline!\Bigg!. The default value is \lstinline!normal!. \item \lstinline!leftspar! (token list): the left symbol parenthesis (for use with the \lstinline!spar!~routine); the default value is~\lstinline!(!. \item \lstinline!rightspar! (token list): the right symbol parenthesis (for use with the \lstinline!spar!~routine); the default value is~\lstinline!)!. \item \lstinline!arg! (token list): the argument. \item \lstinline!prearg! (token list): to be printed in front of the argument, if the argument is non-empty. \item \lstinline!postarg! (token list): to be printed after the argument, if the argument is non-empty. \item \lstinline!argsep! (token list): the argument separator; comma by default. \item \lstinline!argslot! (token list): the argument slot; \lstinline!{-}!~by default. \item \lstinline!argdots! (token list): the argument dots; \lstinline!\dots!~by default. % Upper index: \item \lstinline!upper! (token list): the upper index. \item \lstinline!preupper! (token list): the pre-upper index, to be printed in front of the upper index, if the upper index is non-empty. \item \mylst!postupper! (token list) the post-upper index, to be printed after the upper index, if the upper index is non-empty. \item \mylst!uppersep! (token list): the upper index separator; comma by default. \item \mylst!upperdots! (token list): the upper dots; \lstinline!\dots!~by default. \item \mylst!upperslot! (token list): the upper slot; \lstinline!{-}!~by default. % Lower index: \item \lstinline!lower! (token list): the lower index. \item \lstinline!prelower! (token list): the pre-lower index, to be printed in front of the lower index, if the lower index is non-empty. \item \mylst!postlower! (token list) the post-lower index, to be printed after the lower index, if the lower index is non-empty. \item \mylst!lowersep! (token list): the lower index separator; comma by default. \item \mylst!lowerdots! (token list): the lower dots; \lstinline!\dots!~by default. \item \mylst!lowerslot! (token list): the lower slot; \lstinline!{-}!~by default. % Upper left index: \item \lstinline!upperleft! (token list): the upper left index. \item \lstinline!preupperleft! (token list): the pre-upper left index, to be printed in front of the upper left index, if the upper left index is non-empty. \item \mylst!postupperleft! (token list) the post-upper left index, to be printed after the upper left index, if the upper left index is non-empty. \item \mylst!upperleftsep! (token list): the upper left index separator; comma by default. \item \mylst!upperleftdots! (token list): the upper left dots; \lstinline!\dots!~by default. \item \mylst!upperleftslot! (token list): the upper left slot; \lstinline!{-}!~by default. % Lower left index: \item \lstinline!lowerleft! (token list): the lower left index. \item \lstinline!prelowerleft! (token list): the pre-lower left index, to be printed in front of the lower left index, if the lower left index is non-empty. \item \mylst!postlowerleft! (token list) the post-lower left index, to be printed after the lower left index, if the lower left index is non-empty. \item \mylst!lowerleftsep! (token list): the lower left index separator; comma by default. \item \mylst!lowerleftdots! (token list): the lower left dots; \lstinline!\dots!~by default. \item \mylst!lowerleftslot! (token list): the lower left slot; \lstinline!{-}!~by default. \item \mylst!uppergrading! (boolean): whether or not to use upper (cohomological) grading; true by default. \item \mylst!par! (boolean): whether or not to use parentheses; true by default. \item \mylst!flexpar! (boolean): if \mylst!par! is set to false, setting \mylst!flexpar! to true will still print a pair of parentheses when there is more than one argument; false by default. \item \mylst!leftargument! (boolean): if true, the argument (and parentheses) will be printed to the \emph{left} of the symbol; false by default. \item \mylst!nextargwithsep! (boolean): if true, the next argument will have a separator printed in front of it. \item \mylst!nextupperwithsep! (boolean): If true, the next upper index will have a separator printed in front of it. \item \mylst!nextlowerwithsep! (boolean): If true, the next lower index will have a separator printed in front of it. \item \mylst!nextupperleftwithsep! (boolean): If true, the next upper left index will have a separator printed in front of it. \item \mylst!nextlowerleftwithsep! (boolean): If true, the next lower upper index will have a separator printed in front of it. \item \mylst!numberofarguments! (integer): the number of arguments. \item \mylst!numberofupperindices! (integer): the number of upper indices. \item \mylst!numberoflowerindices! (integer): the number of lower indices. \item \mylst!numberofupperleftindices! (integer): the number of upper left indices. \item \mylst!numberoflowerindices! (integer): the number of lower left indices. \end{itemize} \end{document}