diff options
Diffstat (limited to 'macros/latex/contrib/semantex/semantex.tex')
-rw-r--r-- | macros/latex/contrib/semantex/semantex.tex | 206 |
1 files changed, 137 insertions, 69 deletions
diff --git a/macros/latex/contrib/semantex/semantex.tex b/macros/latex/contrib/semantex/semantex.tex index 3b2630da08..a377e0f217 100644 --- a/macros/latex/contrib/semantex/semantex.tex +++ b/macros/latex/contrib/semantex/semantex.tex @@ -42,19 +42,6 @@ \usepackage[nameinlink]{cleveref} -\title{Seman\!\TeX: semantic, keyval-based mathematics (v0.513)} -\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{% @@ -103,6 +90,19 @@ \usepackage{semantex} +\title{Seman\!\TeX: semantic, keyval-based mathematics (v\SemantexVersion)} +\date{\today} +\author{Sebastian Ørsted (\href{mailto:sorsted@gmail.com}{sorsted@gmail.com})} + +\hypersetup{ + pdfauthor={Sebastian Ørsted}, + pdftitle={SemanTeX: semantic, keyval-based mathematics (v\SemantexVersion)}, + %pdfsubject={}, + %pdfkeywords={}, + %pdfproducer={Latex with hyperref, or other system}, + %pdfcreator={pdflatex, or other tool}, +} + \SemantexSetup{ semtex file=true, } @@ -1761,7 +1761,7 @@ by default, so we shall have to turn them on first: } \end{lstlisting} The key \lstinline!other sep! 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}!, +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. @@ -1867,7 +1867,9 @@ $ \vP[command=\overline,return, upper left=*] $ \end{LTXexample} -\chapter{The \texorpdfstring{\texttt{Symbol}}{Symbol} class type (Example: Derived tensor products and fibre products)} +\chapter{The \texorpdfstring{\texttt{Symbol}}{Symbol} class type (Example: Derived tensor products and fibre products)}\label{chap:symbol_class} + +\begingroup \NewSymbolClass\MyBinaryOperator[ define keys={ @@ -1933,6 +1935,12 @@ $\vX[*] \tensor[\vR] \vY[*]$ $\vk \tensor[\vA,der] \vk$, $\vX \fibre[\vY,der] \vX$ \end{LTXexample} +Later (in~\cref{sec:smart_binary_operators}), we shall see another, more advanced +solution for binary operators which also allows us to express the application of the operator +on \( \vn \)~elements. + + +\endgroup \chapter{Paired delimiters} @@ -1977,12 +1985,12 @@ $\norm[\infty]{\vx}$ We can also create 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\: +\newcommand\wherecommand[1]{% + \nonscript\:% #1\vert \allowbreak - \nonscript\: - \mathopen{} + \nonscript\:% + \mathopen{}% } \NewObject\MyVar\where{ \wherecommand{\SemantexDelimiterSize} } @@ -1995,12 +2003,12 @@ The following is inspired from the \pack{mathtools} package where a similar cons % this turns off all keyval syntax in the argument ] \end{lstlisting} -\newcommand\wherecommand[1]{ - \nonscript\: +\newcommand\wherecommand[1]{% + \nonscript\:% #1\vert \allowbreak - \nonscript\: - \mathopen{} + \nonscript\:% + \mathopen{}% } \NewObject\MyVar\where{ \wherecommand{\SemantexDelimiterSize} } @@ -2848,6 +2856,104 @@ As you see, we use the \lstinline!d!~key to tell the command what superscript it \] \end{LTXexample} +\section{Example: Smart binary operators}\label{sec:smart_binary_operators} + +\begingroup + +\NewVariableClass\MyBinaryOperator[ + set arg dots=\dotsb, + never par, + prepend keys[1]={ + {arg}{ + return, + set keys x={ + set arg sep=\SemantexDataGetExpNot{symbol}, + }, + }, + }, + parse options={ + int if greater T={ \SemantexIntGet{number of arguments} } { 0 } + { + symbol={}, + output=\MyVar, + }, + }, +] + +\NewObject\MyBinaryOperator\mult{\cdot} +\NewObject\MyBinaryOperator\tensor{\otimes} + +\NewVariableClass\InvisibleBinaryOperator[parent=\MyBinaryOperator, set arg dots=\dotsm] +\NewObject\InvisibleBinaryOperator\invmult{} +\NewObject\InvisibleBinaryOperator\spacemult{\,} + +In~\cref{chap:symbol_class}, we saw a simple solution for binary operators using the \lstinline!Symbol!~class. +But that solution only printed the operator itself. However, in semantic markup systems, it is ofen desirable +to also be able to explicitly typeset applications of the operator on \( \vn \)~arguments, like this: +\begin{LTXexample} +Applying the tensor product~$\tensor$ to $\vn$~elements, we get +\[ + \tensor{ \vx[1], \vx[2], ..., + \vx[\vn] }. +\] +Applying the multiplication operator~$\mult$ to $\vn$~elements, we get +\[ + \mult{ \vx[1], \vx[2], ..., + \vx[\vn] }. +\] +\end{LTXexample} + +This can be accomplished using the \lstinline!parse!~routine as follows: + +\begin{lstlisting} +\NewVariableClass\MyBinaryOperator[ + set arg dots=\dotsb, + never par, + prepend keys[1]={ + {arg}{ + return, + set keys x={ + set arg sep=\SemantexDataGetExpNot{symbol}, + }, + }, + }, + parse options={ + int if greater T={ \SemantexIntGet{number of arguments} } { 0 } + { + symbol={}, + output=\MyVar, + }, + }, +] + +\NewObject\MyBinaryOperator\tensor{\otimes} +\NewObject\MyBinaryOperator\mult{\cdot} +\end{lstlisting} + +In mathematical texts, the multiplication symbols in that last equation would usually be omitted. +However, if we want to make the syntax fully semantic, we should also type these multiplication operators explicitly, even if they will be invisible in the final output. +We do this by changing the argument dots and creating an object with an empty symbol. +Alternatively, if we want to insert a space between the variables being multiplied, +we can set the symbol to~\lstinline!\,!: +\begin{lstlisting} +\NewVariableClass\InvisibleBinaryOperator[parent=\MyBinaryOperator, + set arg dots=\dotsm] +\NewObject\InvisibleBinaryOperator\invmult{} +\NewObject\InvisibleBinaryOperator\spacemult{\,} +\end{lstlisting} +\begin{LTXexample} +In mathematical texts, we denote the product of \( \vn \)~elements simply by +\[ + \invmult{ \vx[1], \vx[2], ..., + \vx[\vn] } + = + \spacemult{ \vx[1], \vx[2], ..., + \vx[\vn] }. +\] +\end{LTXexample} + +\endgroup + \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} @@ -2993,7 +3099,7 @@ Let us take a look at the commands defined by \pack{semtex}: \mylst!\SemantexDoubleBullet! The commands that contain the bullets we use in \semantex, - i.e.~the superscript in~\( \co{*} \). + i.e.~the superscript in~\( \co[*] \). These bullets are smaller (and prettier, in my opinion) than the standard \lstinline!\bullet! command from~\LaTeX. @@ -3053,8 +3159,8 @@ Suppose in the following that you \TeX\ document is called~\texttt{mydoc.tex}. 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{$\<a unique ID\>$}! + but in the document body, each command defined using \semantex{} will now + have an expression of the form~\mylst!\SemantexID{$\<a unique ID\>$}! preceding it. \item\label{pt:pre_strip_point} @@ -3079,6 +3185,9 @@ Suppose in the following that you \TeX\ document is called~\texttt{mydoc.tex}. left. You will then have to remove these few commands from your document manually. \end{enumerate} +\newpage +\section{Stripping comments from the document} + 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. @@ -3583,14 +3692,6 @@ In the following sections, we include the full list. e.g.~the~\lstinline!1! in~\lstinline!\vf[1]!. By default, this keys has been set to be equal to~\lstinline!sep i!, but it is meant to be changeable by the user. - - \item - \mylst!degree default={$\<value\>$}! - - This is the key where the grading goes. - It is the one used by the (now deprecated) \lstinline!Cohomology! class type. - By default, this key has been set to be equal to~\lstinline!sep d!, - but it is meant to be changeable by the user. \item \mylst!*! @@ -5701,39 +5802,6 @@ Let me add that \semantex{} uses a very clear separation between the input synta 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. -There are also a few extra class types which are now deprecated, as their syntax will only cause confusion. -They are still included for backwards compatibility, but I highly discourage their use: - -\begin{itemize} - \item \lstinline!Cohomology!: - A new class is declared with the - syntax - \begin{lstlisting} - \NewCohomologyClass@\usercommand\<Class\>@[@\<options\>@] - \end{lstlisting} - A new object is declared by - \begin{lstlisting} - \NewObject@\usercommand\<Class\>@@\usercommand\<object\>@{@\<symbol\>@}[@\<options\>@] - \end{lstlisting} - The syntax for this object is - \begin{lstlisting} - @\usercommand\<object\>@[@\<options\>@]{@\<degree\>@}{@\<argument\>@} - \end{lstlisting} - \item \lstinline!Delimiter!: - A new class is declared with the syntax - \begin{lstlisting} - \NewDelimiterClass@\usercommand\<Class\>@[@\<options\>@] - \end{lstlisting} - A new object is declared by - \begin{lstlisting} - \NewObject@\usercommand\<Class\>@@\usercommand\<object\>@{@\<left bracket\>@}{@\<right bracket\>@}[@\<options\>@] - \end{lstlisting} - The syntax for this object is - \begin{lstlisting} - @\usercommand\<object\>@[@\<options\>@]{@\<argument\>@} - \end{lstlisting} -\end{itemize} - \section{The predefined data} By default, the following data are defined for each class or object and are accessible via @@ -5773,7 +5841,7 @@ the programming keys and commands: \lstinline!par size! (token list): the size of the argument parentheses. - Here, the value~\lstinline!normal! means normal size + The value~\lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left ...\right!. @@ -5796,7 +5864,7 @@ the programming keys and commands: \lstinline!spar size! (token list): the size of the symbol parentheses (for use with the \lstinline!spar!~routine). - Here, the value~\lstinline!normal! means normal size + The value~\lstinline!normal! means normal size parentheses, \lstinline!auto! and~\lstinline!*! mean auto-scaled parentheses using~\lstinline!\left ...\right!. |