| 1 |
% \iffalse |
| 2 |
% !TEX encoding = UTF-8 Unicode |
| 3 |
% !TEX TS-program = pdflatex |
| 4 |
% |
| 5 |
% |
| 6 |
% |
| 7 |
%% mathcommand.dtx |
| 8 |
%% |
| 9 |
%% Copyright (C) 2019-2021 by Thomas Colcombet |
| 10 |
%% |
| 11 |
%% This work may be distributed and/or modified under the |
| 12 |
%% conditions of the LaTeX Project Public License, either version 1.3 |
| 13 |
%% of this license or (at your option) any later version. |
| 14 |
%% The latest version of this license is in |
| 15 |
%% |
| 16 |
%% http://www.latex-project.org/lppl.txt |
| 17 |
%% |
| 18 |
%% and version 1.3 or later is part of all distributions of LaTeX |
| 19 |
%% version 2005/12/01 or later. |
| 20 |
%% |
| 21 |
%% This work has the LPPL maintenance status ‘maintained’. |
| 22 |
%% |
| 23 |
%% The Current Maintainer of this work is Thomas Colcombet. |
| 24 |
%% |
| 25 |
%% This work consists of the files |
| 26 |
%% mathcommand.dtx, mathcommand.ins, and makefile, |
| 27 |
%% and the derived files |
| 28 |
%% mathcommand.sty and readme.md. |
| 29 |
%% |
| 30 |
% \fi |
| 31 |
% |
| 32 |
% \iffalse |
| 33 |
%<head>\usepackage{expl3} |
| 34 |
%<head>\ProvidesExplPackage{mathcommand}{2021/06/07}{1.04}{} |
| 35 |
%<*driver> |
| 36 |
\documentclass{ltxdoc} |
| 37 |
\usepackage[utf8]{inputenc} |
| 38 |
\usepackage[T1]{fontenc} |
| 39 |
\usepackage{paralist} |
| 40 |
\usepackage[svgnames]{xcolor} |
| 41 |
\usepackage{expl3} |
| 42 |
\usepackage{mathcommand} |
| 43 |
\usepackage[hidelinks]{hyperref} |
| 44 |
\usepackage[quotation,scope,notion,electronic]{knowledge} |
| 45 |
\usepackage{enumitem} |
| 46 |
|
| 47 |
\CheckSum{0} |
| 48 |
\changes{1.01}{2019/05/12}{Initial version} % |
| 49 |
\changes{1.02}{2019/07/03}{Bug correction} % |
| 50 |
\changes{1.03}{2019/12/06}{added disabling commands} % |
| 51 |
\changes{1.04}{2021/06/05}{correction with respect to modification of xparse package} % |
| 52 |
\GetFileInfo{mathcommand.sty} % |
| 53 |
\DoNotIndex{} |
| 54 |
\edef\mathcommandversiondate{\fileversion--\filedate} |
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
\newcommand\smallcode[1]{\colorbox{Honeydew}{\texttt{#1}}} |
| 61 |
|
| 62 |
|
| 63 |
\newsavebox{\fminipagebox} |
| 64 |
|
| 65 |
\NewDocumentEnvironment{cminipage}{m O{\fboxsep}} |
| 66 |
{\par\kern#2\noindent\begin{lrbox}{\fminipagebox} |
| 67 |
\begin{minipage}{#1}\ignorespaces} |
| 68 |
{\end{minipage}\end{lrbox}% |
| 69 |
\makebox[#1]{% |
| 70 |
\kern\dimexpr-\fboxsep-\fboxrule\relax |
| 71 |
\colorbox{Honeydew}{\usebox{\fminipagebox}}% |
| 72 |
\kern\dimexpr-\fboxsep-\fboxrule\relax}\par\kern#2} |
| 73 |
|
| 74 |
\NewDocumentEnvironment{fminipage}{m O{\fboxsep}} |
| 75 |
{\par\kern#2\noindent\begin{lrbox}{\fminipagebox} |
| 76 |
\begin{minipage}{#1}\ignorespaces} |
| 77 |
{\end{minipage}\end{lrbox}% |
| 78 |
\makebox[#1]{% |
| 79 |
\kern\dimexpr-\fboxsep-\fboxrule\relax |
| 80 |
\fbox{\usebox{\fminipagebox}}% |
| 81 |
\kern\dimexpr-\fboxsep-\fboxrule\relax}\par\kern#2\relax} |
| 82 |
|
| 83 |
\newenvironment{code}[1][12.4cm] |
| 84 |
{\par |
| 85 |
\noindent |
| 86 |
\cminipage{#1}% |
| 87 |
\tt |
| 88 |
}{% |
| 89 |
\endcminipage% |
| 90 |
\par |
| 91 |
} |
| 92 |
|
| 93 |
% This is a hack. Introducing Hyphenation everywhere in a sequence of token. |
| 94 |
% Otherwise the macro names tend to always exceed lines. |
| 95 |
% It should be improved in order to always require at least--say--3 symbols before |
| 96 |
% and after the hyphenation. |
| 97 |
\ExplSyntaxOn |
| 98 |
\cs_new:Nn\tl_fragilize:n |
| 99 |
{\__tl_fragilize:N#1\q_stop} |
| 100 |
\cs_new:Nn\__tl_fragilize:N |
| 101 |
{\token_if_eq_meaning:NNTF#1\q_stop |
| 102 |
{}{#1 |
| 103 |
\-\__tl_fragilize:N}} |
| 104 |
\cs_set_eq:NN\textfragilize\tl_fragilize:n |
| 105 |
\cs_new:Npn\Robustdisplay#1 |
| 106 |
{\exp_args:Nx\textfragilize{\robustdisplay{#1}}} |
| 107 |
\ExplSyntaxOff |
| 108 |
|
| 109 |
\let\cs\undefined |
| 110 |
\knowledgenewvariant\cs |
| 111 |
{namespace=cs, |
| 112 |
default style={autoref link,cs}, |
| 113 |
unknown style=cs unknown, |
| 114 |
unknown style cont=cs unknown, |
| 115 |
unknown warning=false, |
| 116 |
unknown diagnose=true, |
| 117 |
suggestion=cs, |
| 118 |
PDF string={\detokenize{#1}}} |
| 119 |
\knowledgestyle{cs}{wrap=\Robustdisplay,typewriter,up,md,color=NavyBlue} |
| 120 |
\knowledgestyle{cs unknown}{wrap=\Robustdisplay,typewriter,up,md,color=black} |
| 121 |
|
| 122 |
\knowledgenewvariant\csintro |
| 123 |
{namespace=cs, |
| 124 |
auto knowledge={autoref,scope=document,also now}, |
| 125 |
default style={autoref target,csintro}, |
| 126 |
unknown style=csintro unknown, |
| 127 |
unknown style cont=csintro unknown, |
| 128 |
unknown warning=false, |
| 129 |
unknown diagnose=false, |
| 130 |
PDF string = {\detokenize{#1}}} |
| 131 |
\knowledgestyle{csintro}{wrap=\Robustdisplay,typewriter,up,md,color=blue} |
| 132 |
\knowledgestyle{csintro unknown}{wrap=\Robustdisplay,typewriter,up,md,color=black} |
| 133 |
|
| 134 |
\knowledgenewvariant\csreintro |
| 135 |
{namespace=cs, |
| 136 |
default style=csintro, |
| 137 |
unknown style=csintro unknown, |
| 138 |
unknown style cont=csintro unknown, |
| 139 |
PDF string = {\Robustdisplay{#1}}} |
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
\newenvironment{commandlist} |
| 145 |
{\begin{description}[font=\normalfont, |
| 146 |
nosep, |
| 147 |
itemindent=-2cm, |
| 148 |
leftmargin=0cm, |
| 149 |
topsep=2.5mm]} |
| 150 |
{\end{description}} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
\knowledgedirective{doc notion} |
| 157 |
{autoref,style=doc notion,intro style=intro doc notion} |
| 158 |
\knowledgestyle{doc notion}{color=DarkBlue} |
| 159 |
\knowledgestyle{intro doc notion}{color=blue,emphasize} |
| 160 |
|
| 161 |
|
| 162 |
\knowledgedirective{package}{style=package} |
| 163 |
\knowledgestyle{package}{typewriter,color=black} |
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
\knowledge{xparse}{package,url = {https://www.ctan.org/pkg/xparse}} |
| 169 |
\knowledge{knowledge}{package,url = {https://www.ctan.org/pkg/knowledge}} |
| 170 |
\knowledge{xcolor}{package,url = {https://www.ctan.org/pkg/xcolor}} |
| 171 |
\knowledge{amsfonts}{package,url = {https://www.ctan.org/pkg/amsfonts}} |
| 172 |
\knowledge{amssymb}{package,url = {https://www.ctan.org/pkg/amssymb}} |
| 173 |
\knowledge{mathcommand}{package} |
| 174 |
|
| 175 |
\knowledge{math variant}{doc notion} |
| 176 |
\knowledge{text variant}{doc notion} |
| 177 |
\knowledge{PIE}[PIEs]{doc notion} |
| 178 |
\knowledge{PIE command}[PIE commands]{doc notion} |
| 179 |
|
| 180 |
\knowledge{notion} |
| 181 |
| Disabling |
| 182 |
| deactivated |
| 183 |
| Deactivating |
| 184 |
|
| 185 |
\knowledge{notion} |
| 186 |
| disabled=warning |
| 187 |
\knowledge{notion} |
| 188 |
| disabled=error |
| 189 |
\knowledge{notion} |
| 190 |
| disabled=silent |
| 191 |
|
| 192 |
\begin{document} |
| 193 |
\title{The \texttt{mathcommand} package for \LaTeX\\ |
| 194 |
{\small[version \mathcommandversiondate]}} |
| 195 |
|
| 196 |
\author{Thomas Colcombet} |
| 197 |
\maketitle |
| 198 |
\begin{abstract} |
| 199 |
\noindent The "mathcommand" package provides functionalities for defining macros |
| 200 |
\begin{compactenum} |
| 201 |
\item that have different behaviors depending on whether in math or text mode, |
| 202 |
\item that absorb Primes, Indices and Exponents (PIE) as extra parameters usable in the code, |
| 203 |
\item offers some iteration facilities for defining macros with similar code, |
| 204 |
\item and deactivating macros. |
| 205 |
\end{compactenum} |
| 206 |
The primary objective of this package is to be used together with the "knowledge" |
| 207 |
package for a proper handling of mathematical notations. |
| 208 |
\end{abstract} |
| 209 |
|
| 210 |
\section{History of the package} |
| 211 |
|
| 212 |
\begin{compactdesc} |
| 213 |
\item[2019-05-12] First version of the package. V1.01 on CTAN, |
| 214 |
\item[2019-05-14] New macros \cs\IfEmptyTF, \cs\GetExponent, and \cs\GetIndex. |
| 215 |
\item[2019-07-03] Corrects bug of functions declaring PIE's issuing an error when already existing. Version 1.02 on CTAN. |
| 216 |
\item[2019-12-06] Added disabling commands, and package options. Version 1.03 on CTAN. |
| 217 |
\item[2021-06-07] Corrected code that was broken due to an update in "xparse". Version 1.04 on CTAN. |
| 218 |
\end{compactdesc} |
| 219 |
|
| 220 |
|
| 221 |
\section{Defining text and math commands} |
| 222 |
|
| 223 |
The principle is that the package will maintain, for a macro \cs{\macro}, two concurrent version of the code: |
| 224 |
a ""math variant"" (technically it is stored in a macro \verb|\Math macro|) and a ""text variant"" |
| 225 |
(technically stored in a macro \verb|\Text macro|\footnote{These cannot be used accidentally by the user since these control sequences contain a space.}). |
| 226 |
The macro \cs{\macro} itself will execute one or the other depending on whether it is |
| 227 |
executed in math or text mode. Note that all the macros are non-expandable for avoiding problems |
| 228 |
with mathematics that would be sent, for instance, to the table of contents. The list of commands is described at the end of the section. |
| 229 |
|
| 230 |
For instance after executing: |
| 231 |
\begin{code} |
| 232 |
\cs{\newmathcommand}\cs\macro[1]\{\cs\mathit\{math\}\verb.^.\cs\mathrm\{code\}\verb._.\{(\#1)\}\}\\ |
| 233 |
\cs{\newtextcommand}\cs\macro[1]\{text code (\#1)\} |
| 234 |
\end{code} |
| 235 |
\noindent when executing \cs{\macro} in math mode, |
| 236 |
the math code will be executed, and in text mode similarly: |
| 237 |
\newmathcommand\toto[1]{\mathit{math}^{\mathrm{code}}_{(#1)}} |
| 238 |
\newtextcommand\toto[1]{text code (#1)} |
| 239 |
\begin{center} |
| 240 |
\smallcode{\cs\macro\{a\}} yields~`\toto{a}' \qquad while \smallcode{\$\cs\macro\{a\}\$} yields `$\toto{a}$'. |
| 241 |
\end{center} |
| 242 |
|
| 243 |
If the macro \cs{\macro} already exists, it is stored |
| 244 |
under the name \cs{\LaTeXmacro}, and then everything happens as |
| 245 |
if it had already been defined both in math and text mode. |
| 246 |
This is useful for redefining known macros. |
| 247 |
For instance \cs{\c} is a convenient way to producing cedillas in \LaTeX, as in \smallcode{\cs\c\ a} |
| 248 |
which yields `\c a'. However, one may want \cs{\c} to reprensent a variable $c$ in math mode. |
| 249 |
This is done using, e.g.: |
| 250 |
\begin{code}[5cm] |
| 251 |
\cs{\renewmathcommand}\cs\c\{c\} |
| 252 |
\end{code} |
| 253 |
\renewmathcommand\c{c} |
| 254 |
\noindent Then, the macro \cs{\c} still works in text mode, |
| 255 |
and using~\cs{\c} in math mode does display simply~`$\c$'. |
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
|
| 260 |
The name of the macros offered by the "mathcommand" package are mere adaptations of the standard macros of \LaTeX\ and of the package "xparse"\footnote{The package "xparse" offers a very convenient way to define macros with complicated parameter signatures.}. |
| 261 |
Their syntax is the same (in particular in terms of parameter definitions): |
| 262 |
\begin{commandlist} |
| 263 |
\itemAP[\csintro{\newmathcommand}] is similar to \cs{\newcommand} and creates a "math variant", |
| 264 |
\itemAP[\csintro{\newtextcommand}] is similar to \cs{\newcommand} and creates a "text variant", |
| 265 |
\itemAP[\csintro{\renewmathcommand}] is similar to \cs{\renewcommand} and creates a "math variant", |
| 266 |
\itemAP[\csintro{\renewtextcommand}] is similar to \cs{\renewcommand} and creates a "text variant", |
| 267 |
\itemAP[\csintro{\declaremathcommand}] is similar to \cs{\newcommand} but defines the macro even if it exists before; it creates a "math variant", |
| 268 |
\itemAP[\csintro{\declaretextcommand}] is similar to \cs{\newcommand} but defines the macro even if it exists before; it creates a "text variant", |
| 269 |
\itemAP[\csintro{\NewDocumentMathCommand}] is like \cs{\NewDocumentCommand} of the "xparse" package, but creates a "math variant", |
| 270 |
\itemAP[\csintro{\NewDocumentTextCommand}] is like \cs{\NewDocumentCommand} of the "xparse" package, but creates a "text variant", |
| 271 |
\itemAP[\csintro{\RenewDocumentMathCommand}] is like \cs{\RenewDocumentCommand} of the "xparse" package, but creates a "math variant", |
| 272 |
\itemAP[\csintro{\RenewDocumentTextCommand}] is like \cs{\RenewDocumentCommand} of the "xparse" package, but creates a "text variant", |
| 273 |
\itemAP[\csintro{\DeclareDocumentMathCommand}] is like \cs{\DeclareDocumentCommand} of the "xparse" package, but creates a "math variant", |
| 274 |
\itemAP[\csintro{\DeclareDocumentTextCommand}] is like \cs{\DeclareDocumentCommand} of the "xparse" package, but creates a "text variant", |
| 275 |
\itemAP[\csintro{\ProvideDocumentMathCommand}] is like \cs{\ProvideDocumentCommand} of the "xparse" package, but creates a "math variant", |
| 276 |
\itemAP[\csintro{\ProvideDocumentTextCommand}] is like \cs{\ProvideDocumentCommand} of the "xparse" package, but creates a "text variant". |
| 277 |
\end{commandlist} |
| 278 |
|
| 279 |
The package offers also the following commands: |
| 280 |
\begin{commandlist} |
| 281 |
\itemAP[\csintro{\declarecommand}] which is similar to \cs{\newcommand} but defines the macro even if it exists before, |
| 282 |
\itemAP[\csintro{\storecommand}\texttt{[optional-prefix]}\texttt{\cs\macro}] which copies the content of the macro \cs\macro\ to \verb|\optional-prefixmacro|. By default, the optional prefix is \verb|LaTeX|. (Hence, it does what is automatically made by commands such as \cs\declarecommand). |
| 283 |
\end{commandlist} |
| 284 |
|
| 285 |
\section{Defining Prime/Indices/Exponents absorbing commands (PIE commands)} |
| 286 |
|
| 287 |
Another feature offered by the "mathcommand" package is to permit the definitions of macros that would |
| 288 |
absorb the primes, subscript and superscript that follow them. |
| 289 |
\AP |
| 290 |
The three pieces of information are abbreviated as ""PIE"" (for ``Primes-Indices-Exponents''). |
| 291 |
This terminology serves as a help for remembering the order prime-index-exponent. |
| 292 |
\AP A ""PIE command"" is similar to a normal macro/command, but for the fact |
| 293 |
that the "PIEs" that follow are absorbed and can be used in the macro as |
| 294 |
three extra parameters. The list of macros usable for for defining "PIE commands" can be found at the end of this section. |
| 295 |
|
| 296 |
This is best explained through an example. After writing: |
| 297 |
\begin{code} |
| 298 |
\cs\newcommandPIE\cs\macro[1]\{([\#1]\#3)\#2\#4\} |
| 299 |
\end{code} |
| 300 |
\noindent one obtains that |
| 301 |
\newcommandPIE\macrob[1]{([#1]#3)#2#4} |
| 302 |
\begin{center} |
| 303 |
\smallcode{\$\cs\macro\{A\}\_2'\$} yields $\macrob{A}_2'$\ . |
| 304 |
\end{center} |
| 305 |
Indeed, in the body of the definition of \cs{macro}, \texttt{\#1} represents the normal parameter of the command, while the three following parameters (\texttt{\#2},\texttt{\#3},\texttt{\#4} in this case) contain respectively the primes (either empty or a sequence of $'$ symbols), |
| 306 |
the index (either empty if there is no subscript or of the form \verb"_{index}" if there is |
| 307 |
an index), and the exponent (either empty if there is no superscript or of the form |
| 308 |
\verb"^{exponent}" if there is one). |
| 309 |
In the case of the above definition, the index (parameter \texttt{\#3}) is written inside the parenthesis, |
| 310 |
while primes and exponents are put outside. |
| 311 |
|
| 312 |
The are furthermore some helper functions: |
| 313 |
\begin{commandlist} |
| 314 |
\itemAP[\csintro\IfEmptyTF] takes a string and two codes, and expands to the first one if the string is empty, and the second otherwise, |
| 315 |
\itemAP[\csintro{\GetIndex}] takes a string that is an index as in "PIE commands", and expands to its content: it maps the empty string to the empty string, and strings of the form \verb|_{sthg}| to \verb|sthg|, |
| 316 |
\itemAP[\csintro{\GetExponent}] takes a string that is an exponent as in "PIE commands", and expands to its content: it maps the empty string to the empty string, and strings of the form \verb|^{sthg}| to \verb|sthg|. |
| 317 |
\end{commandlist} |
| 318 |
|
| 319 |
For instance: |
| 320 |
\begin{code} |
| 321 |
\cs\newmathcommandPIE\cs\F\{\#2F\#1\cs\IfEmptyTF\{\#3\}\{\}\{\verb.^.\{(\cs\GetExponent\{\#3\})\}\}\} |
| 322 |
\end{code} |
| 323 |
\newmathcommandPIE\F{#2F#1\IfEmptyTF{#3}{}{^{(\GetExponent{#3})}}} |
| 324 |
\noindent displays \verb|$\F_2^3$| as `$\F_2^3$': the index is placed before, and the exponent is surrounded by parentheses. |
| 325 |
|
| 326 |
|
| 327 |
\paragraph{List of macros of defining "PIE commands".} Once more, |
| 328 |
appart from the specificity of "PIE commands", the syntax is as the original corresponding commands these are based on. |
| 329 |
\begin{commandlist} |
| 330 |
\itemAP[\csintro{\newcommandPIE}] is similar to \cs\newcommand\ (but defines a non-expandable macro) |
| 331 |
\itemAP[\csintro{\renewcommandPIE}] is similar to \cs\renewcommand\ (but defines a non-expandable macro) |
| 332 |
\itemAP[\csintro{\declarecommandPIE}] is similar to \cs\newcommand\ and works even if the macro already exists (and defines a non-expandable macro) |
| 333 |
\itemAP[\csintro{\NewDocumentCommandPIE}] is similar to \cs\NewDocumentCommand\ of the "xparse" package, |
| 334 |
\itemAP[\csintro{\RenewDocumentCommandPIE}] is similar to \cs\RenewDocumentCommand\ of the "xparse" package, |
| 335 |
\itemAP[\csintro{\DeclareDocumentCommandPIE}] is similar to \cs\DeclareDocumentCommand\ of the "xparse" package, |
| 336 |
\itemAP[\csintro{\ProvideDocumentCommandPIE}] is similar to \cs\ProvideDocumentCommand\ of the "xparse" package. |
| 337 |
\end{commandlist} |
| 338 |
|
| 339 |
Finally, a bunch of macros are used to define "math variants" that are "PIE commands": |
| 340 |
\begin{commandlist} |
| 341 |
\itemAP[\csintro{\newmathcommandPIE}] is like \cs{\newcommandPIE} and creates a "math variant", |
| 342 |
\itemAP[\csintro{\renewmathcommandPIE}] is like \cs{\renewcommandPIE} and creates a "math variant", |
| 343 |
\itemAP[\csintro{\declaremathcommandPIE}] is like \cs{\declarecommandPIE} and creates a "math variant", |
| 344 |
\itemAP[\csintro{\NewDocumentMathCommandPIE}] is like \cs{\NewDocumentCommandPIE}, but creates a "math variant", |
| 345 |
\itemAP[\csintro{\RenewDocumentMathCommandPIE}] is like \cs{\RenewDocumentCommandPIE}, but creates a "math variant", |
| 346 |
\itemAP[\csintro{\DeclareDocumentMathCommandPIE}] is like \cs{\DeclareDocumentCommandPIE}, but creates a "math variant", |
| 347 |
\itemAP[\csintro{\ProvideDocumentMathCommandPIE}] is like \cs{\ProvideDocumentCommandPIE}, but creates a "math variant", |
| 348 |
\end{commandlist} |
| 349 |
|
| 350 |
|
| 351 |
\section{Looping for defining commands} |
| 352 |
|
| 353 |
\begin{scope}\label{LoopCommands} |
| 354 |
\knowledge{list on which to iterate}{doc notion} |
| 355 |
\knowledge{name 1}{doc notion} |
| 356 |
\knowledge{name 2}{doc notion} |
| 357 |
\knowledge{name 7}{doc notion} |
| 358 |
\knowledge{code}{doc notion} |
| 359 |
The "mathcommand" package offer also some capabilities for automatically defining multiple |
| 360 |
similar macros. This is done using only one command:\AP |
| 361 |
\begin{center} |
| 362 |
\csintro{\LoopCommands}\{"list on which to iterate"\}["name 1"]["name 2"]\dots["name 7"]\{"code@@LoopCommands"\} |
| 363 |
\end{center} |
| 364 |
\AP The ""list on which to iterate"" is a list of letters or braced sequences of letters. |
| 365 |
\AP the ""name 1"", ""name 2"" up to ""name 7"" optional parameters are expandable |
| 366 |
pieces of code that are to be evaluated |
| 367 |
and then converted into control sequences; they may use the extra parameter~\texttt{\#1}. |
| 368 |
\AP Finally, ""code"" is the code to be executed that can |
| 369 |
use the parameters~\texttt{\#1}, \texttt{\#2}, up to~\texttt{\#8}. |
| 370 |
|
| 371 |
The result of executing this macro is that each of the letters or sequences of letters |
| 372 |
in the "list on which to iterate" will be taken one after the other. For each of them, the "code" is executed, |
| 373 |
taking as value of the parameter~\texttt{\#1} the element in the list, and as parameters~\texttt{\#2} to~\texttt{\#8} |
| 374 |
control sequences constructed from the evaluation of "name 1" up to "name 7" (using as parameters~\texttt{\#1} the element of the sequence). |
| 375 |
|
| 376 |
For instance, imagine one easily wants to denote vectors simply as `\cs\vx' instead of `\cs\vec~x' or `\cs\vec\{x\}', |
| 377 |
it is sufficient to write: |
| 378 |
\begin{code}[9cm] |
| 379 |
\cs\LoopCommands\{abcdefghijklmnopqrstuvwxyz\}[v\#1]\\ |
| 380 |
\indent~~~~\{\cs\newcommand\#2\{\cs\vec~\#1\}\} |
| 381 |
\end{code} |
| 382 |
\noindent It will result in the successive execution of |
| 383 |
\smallcode{\cs\newcommand\cs\va\{\cs\vec~a\}} and so on up to |
| 384 |
\smallcode{\cs\newcommand\cs\vz\{\cs\vec~z\}}. |
| 385 |
|
| 386 |
Note also that the "list on which to iterate" is automatically expanded, |
| 387 |
and if a non-expandable control sequence is met, then it is replaced by its the text defining the control sequence. |
| 388 |
Hence using \texttt{\{\cs\alpha\cs\beta\}} is equivalent to \texttt{\{\{alpha\}\{beta\}\}}. |
| 389 |
|
| 390 |
|
| 391 |
Some extra remarks may be helpful: |
| 392 |
\begin{itemize} |
| 393 |
\item As usual in \TeX/\LaTeX, the "code" may have to use its own internal parameters, |
| 394 |
for instance for defining macros: such parameters should use double \texttt{\#}'s, i.e., \texttt{\#\#1}, \texttt{\#\#2} up to \texttt{\#\#9}. |
| 395 |
|
| 396 |
\LoopCommands{abcdefghijklmnopqrstuvwxyz}[o#1] |
| 397 |
{\declarecommandPIE#2{\overline{#1##2}##1##3}} |
| 398 |
For instance: |
| 399 |
\begin{code}[10cm] |
| 400 |
\cs\LoopCommands\{abcdefghijklmnopqrstuvwxyz\}[o\#1]\\ |
| 401 |
\indent~~~~\{\cs\declarecommandPIE\#2\{\cs\overline\{\#1\#\#2\}\#\#1\#\#3\} |
| 402 |
\end{code} |
| 403 |
\noindent will result in \cs\ou\ to be declared as the "PIE command" |
| 404 |
defined with as main body \texttt{\cs\overline\{u\#2\}\#1\#3} |
| 405 |
(note the translation of parameters, which is the standard way to proceed for \TeX). |
| 406 |
In our case {\tt \cs\ou\_1\verb.^.2} yields `$\ou_1^2$' (the subscript gets to be inside the bar, |
| 407 |
and the superscript and primes outside), and so on... |
| 408 |
\item When defining multiple commands, some may already exist. To avoid conflicts, one should use |
| 409 |
the `declare' version of the defining commands. These will work independently of the |
| 410 |
context. Is it also good to define only the "math variants" using the appropriate commands |
| 411 |
of the package. |
| 412 |
\itemAP The following strings are predefined for the user to loop on: |
| 413 |
\begin{asparaitem} |
| 414 |
\itemAP[\csintro\lettersUppercase] stands for \texttt{\lettersUppercase} |
| 415 |
\itemAP[\csintro\lettersLowercase] stands for \texttt{\lettersLowercase} |
| 416 |
\itemAP[\csintro\lettersAll] stands for \texttt{\lettersAll}. |
| 417 |
\itemAP[\csintro\lettersGreekLowercase] stands for $\lettersGreekLowercase$. |
| 418 |
\itemAP[\csintro\lettersGreekUppercase] stands for $\lettersGreekUppercase$. |
| 419 |
\itemAP[\csintro\lettersGreekAll] stands for $\lettersGreekAll$. |
| 420 |
\end{asparaitem} |
| 421 |
\end{itemize} |
| 422 |
\end{scope} |
| 423 |
|
| 424 |
Hence, for instance: |
| 425 |
\begin{code}[10cm] |
| 426 |
\cs\LoopCommands\cs\lettersUppercase[bb\#1]\\ |
| 427 |
\indent~~~~~~\{\cs\newmathcommand\#2\{\cs\mathbb \#1\}\}\\ |
| 428 |
\cs\LoopCommands\cs\lettersGreekLowercase[\#1][LaTeX\#1]\\ |
| 429 |
\indent~~~~~~\{\cs\renewmathcommand\#2\{\cs\textcolor\{blue\}\{\#3\}\} |
| 430 |
\end{code} |
| 431 |
\noindent configures the macros \cs\bbA, \dots, \cs\bbZ\ to display |
| 432 |
the letters in blackboard bold alphabet (e.g. with the "amsfonts" package), |
| 433 |
and the lowercase greek letters \cs\alpha,\dots\ to |
| 434 |
be displayed in blue (with the "xcolor" package loaded). Note in the last case |
| 435 |
the use of the third parameter for accessing the macros \cs\LaTeXalpha,\dots\ |
| 436 |
that are automatically generated by the \cs\renewmathcommand\ macro. |
| 437 |
|
| 438 |
\section{Disabling command} |
| 439 |
|
| 440 |
The package "mathcommand" has some facilities for deactivating commands, and suggesting replacements. |
| 441 |
This can be useful when working with coauthors and help them using the same macros. |
| 442 |
"Disabling" a command is achieved using \AP |
| 443 |
\begin{center} |
| 444 |
\csintro{\disablecommand}\{sequence of control sequences\} |
| 445 |
\end{center} |
| 446 |
|
| 447 |
The result of this command is that the control sequences appearing in the sequence are "deactivated". \AP ""Deactivating"" a macro~\cs\macro\ means that: |
| 448 |
\begin{itemize} |
| 449 |
\item The original macro is stored as \cs\LaTeXmacro, and thus can still be used. |
| 450 |
\item Using \cs\macro\ now displays an error message explaining that it has been disabled, that~\cs\LaTeXmacro\ can be used instead, and also provides a list suggestions of replacement that are defined by the command \cs\suggestcommand. |
| 451 |
\end{itemize} |
| 452 |
However, be careful: disabling a command which is used in the system or in the the style may cause problems. |
| 453 |
Hence, it is possible to disable all math symbols but macros like \cs\dagger\ would yield problem if used in footnotes or for the affiliation of the authors. |
| 454 |
\AP The syntax of~\cs\suggestcommand\ is as follows: |
| 455 |
\begin{center} |
| 456 |
\csintro{\suggestcommand}\cs\macro\{suggestion to be displayed when~\cs\macro\ is used\} |
| 457 |
\end{center} |
| 458 |
For instance: |
| 459 |
\begin{code}%[10cm] |
| 460 |
\cs\disablecommand\{\cs\leq\cs\geq\}\\ |
| 461 |
\cs\suggestcommand\{\cs\leq\}\{Use the better looking \cs\leqslant.\}\\ |
| 462 |
\cs\suggestcommand\{\cs\geq\}\{Use the better looking \cs\geqslant.\} |
| 463 |
\end{code} |
| 464 |
Now, executing \cs\leq\ yields: |
| 465 |
\begin{verbatim} |
| 466 |
./filename.tex:linenumber: Package mathcommand Error: |
| 467 |
(mathcommand) The command \geq is disabled. Instead: |
| 468 |
(mathcommand) Use \LaTeXgeq for the original macro. |
| 469 |
(mathcommand) Use the better looking \geqslant . |
| 470 |
\end{verbatim} |
| 471 |
|
| 472 |
|
| 473 |
\section{Options} |
| 474 |
|
| 475 |
\AP Options can be triggered either when the package is loaded, or using: |
| 476 |
\begin{center} |
| 477 |
\csintro\mathcommandconfigure\{option list\} |
| 478 |
\end{center} |
| 479 |
The available options are: |
| 480 |
\begin{itemize} |
| 481 |
\item ""disabled=error"" makes "disabled" commands produce errors, |
| 482 |
\item ""disabled=warning"" makes "disabled" commands produce warnings, |
| 483 |
\item ""disabled=silent"" makes "disabled" commands work as before being disabled |
| 484 |
(useful when including code that cannot be modified). |
| 485 |
\end{itemize} |
| 486 |
|
| 487 |
\newpage |
| 488 |
|
| 489 |
\DocInput{mathcommand.dtx} |
| 490 |
\end{document} |
| 491 |
%</driver> |
| 492 |
% \fi |
| 493 |
% |
| 494 |
% |
| 495 |
% |
| 496 |
%%%%%%%%%% |
| 497 |
% |
| 498 |
% \section{Implementation} |
| 499 |
% \label{section:code} |
| 500 |
% |
| 501 |
% \subsection{README.md} |
| 502 |
% |
| 503 |
%<*readme> |
| 504 |
% \begin{macrocode} |
| 505 |
This directory contains the package |
| 506 |
|
| 507 |
name: mathcommand |
| 508 |
license: LaTeX Project Public License version 1.3 or above |
| 509 |
version: v1.04 |
| 510 |
date: 2021/06/07 |
| 511 |
author: Thomas Colcombet |
| 512 |
mail: [email protected] |
| 513 |
web: https://www.ctan.org/pkg/mathcommand |
| 514 |
|
| 515 |
Purpose: |
| 516 |
The mathcommand package provides functionalities for defining macros: |
| 517 |
- that have different behaviors depending on whether in math or text mode, |
| 518 |
- absorb Primes, Indices, Exponents (PIE) following LaTeX notations and |
| 519 |
have them as extra parameters usable in the code. |
| 520 |
The primary objective of this code is to be used together with the knowledge |
| 521 |
package for a proper handling of mathematical notations. |
| 522 |
|
| 523 |
Install: |
| 524 |
It is sufficient to have the file mathcommand.sty accessible by LaTeX. |
| 525 |
It can be produced by `make mathcommand.sty' if necessary. |
| 526 |
The documentation is in the file mathcommand.pdf. |
| 527 |
|
| 528 |
Content of the file mathcommand-ctan.zip: |
| 529 |
- README.md: this file generated while compiling mathcommand.ins, |
| 530 |
- mathcommand.sty: the package file (generated using mathcommand.ins) |
| 531 |
- mathcommand.pdf: the user documentation (generated by compiling |
| 532 |
mathcommand.dtx) |
| 533 |
- makefile: the makefile. Use 'make all' to generate mathcommand.sty |
| 534 |
and mathcommand.pdf. It can also: clean the directory, make zip |
| 535 |
version of the sources, or ready for CTAN. |
| 536 |
- mathcommand.ins: is the file generating mathcommand.sty and |
| 537 |
README.md from mathcommand.dtx (using docstrip). |
| 538 |
- mathcommand.dtx: code and documentation. |
| 539 |
|
| 540 |
% \end{macrocode} |
| 541 |
%</readme> |
| 542 |
% \subsection{Code preparation} |
| 543 |
%<*package> |
| 544 |
% \begin{macrocode} |
| 545 |
\NeedsTeXFormat{LaTeX2e}[1994/06/01] |
| 546 |
\RequirePackage{expl3,l3keys2e} |
| 547 |
\RequirePackage{etoolbox} |
| 548 |
\RequirePackage{xparse} |
| 549 |
|
| 550 |
\ExplSyntaxOn |
| 551 |
\bool_if_exist:NTF\mathcommand_package_loaded_bool |
| 552 |
\endinput |
| 553 |
{\bool_new:N\mathcommand_package_loaded_bool |
| 554 |
\bool_set_true:N\mathcommand_package_loaded_bool} |
| 555 |
% \end{macrocode} |
| 556 |
|
| 557 |
|
| 558 |
% \subsection{Absorbing primes, indices and exponents (PIE)} |
| 559 |
% \subsubsection{Parsing pies} |
| 560 |
% We start by defining the code used to absorb "PIEs" from the input stream. |
| 561 |
% The main function defined in this context is |
| 562 |
% \begin{quote}\AP |
| 563 |
% \csintro{\__mathcommand_absorb_PIE:nw} |
| 564 |
% \end{quote} |
| 565 |
% which takes some code as first parameter, then absorbs primes, indices and exponents, |
| 566 |
% and finally reinserts the code in the input stream, followed with three braces containing |
| 567 |
% respectively the primes, the index, and the exponent. |
| 568 |
% |
| 569 |
% \AP |
| 570 |
% It works by storing the code to be executed in \csintro{\__mathcommand_absorb_finished_tl}, |
| 571 |
% preparing \csintro{\__mathcommand_primes_tl}, \csintro{\__mathcommand_index_t}, |
| 572 |
% and \csintro{\__mathcommand_exponent_tl} to contain the "PIEs". |
| 573 |
% Then the core of the parsing is performed by \csintro{\__mathcommand_absorb:w}. |
| 574 |
% \begin{macrocode} |
| 575 |
\cs_new:Npn\__mathcommand_absorb_PIE:nw#1{ |
| 576 |
\tl_set:Nn\__mathcommand_absorb_finished_tl{#1} |
| 577 |
\tl_set:Nn\__mathcommand_primes_tl{} |
| 578 |
\tl_set:Nn\__mathcommand_index_tl{} |
| 579 |
\tl_set:Nn\__mathcommand_exponent_tl{} |
| 580 |
\__mathcommand_absorb:w |
| 581 |
} |
| 582 |
% \end{macrocode} |
| 583 |
% \AP |
| 584 |
% When the parsing is finished, \csintro{\__mathcommand_absorb_finished:} is |
| 585 |
% executed, which inserts the original code stored in \cs{\__mathcommand_absorb_finished_tl} |
| 586 |
% followed by the "PIEs" in the input stream. |
| 587 |
% \begin{macrocode} |
| 588 |
\cs_new:Nn\__mathcommand_absorb_finished:{ |
| 589 |
\exp_args:NV\__mathcommand_absorb_finished_:\__mathcommand_exponent_tl |
| 590 |
} |
| 591 |
\cs_new:Nn\__mathcommand_absorb_finished_:{ |
| 592 |
\exp_args:NV\__mathcommand_absorb_finished__:\__mathcommand_index_tl |
| 593 |
} |
| 594 |
\cs_new:Nn\__mathcommand_absorb_finished__:{ |
| 595 |
\exp_args:NV\__mathcommand_absorb_finished_tl\__mathcommand_primes_tl |
| 596 |
} |
| 597 |
% \end{macrocode} |
| 598 |
% \begin{macrocode} |
| 599 |
\cs_new:Npn\peek_subscript_remove:TFw |
| 600 |
{\peek_charcode_remove:NTF _} |
| 601 |
\cs_new:Npn\peek_superscript_remove:TFw |
| 602 |
{\peek_charcode_remove:NTF ^} |
| 603 |
\cs_new:Npn\peek_prime_remove:TFw |
| 604 |
{\peek_charcode_remove:NTF '} |
| 605 |
% \end{macrocode} |
| 606 |
% \begin{macrocode} |
| 607 |
\cs_new:Nn\__mathcommand_absorb_add_prime:{ |
| 608 |
\tl_put_right:Nn\__mathcommand_primes_tl{'} |
| 609 |
} |
| 610 |
% \end{macrocode} |
| 611 |
% \begin{macrocode} |
| 612 |
\ExplSyntaxOff |
| 613 |
\expandafter\def\csname g_tmpa_tl\endcsname{_} |
| 614 |
\ExplSyntaxOn |
| 615 |
\cs_new:Nx\__mathcommand_absorb_add_index_after:Nn{ |
| 616 |
\exp_not:N\tl_set:Nn\exp_not:N\__mathcommand_index_tl |
| 617 |
{\g_tmpa_tl{#2}} |
| 618 |
#1 |
| 619 |
} |
| 620 |
% \end{macrocode} |
| 621 |
% \begin{macrocode} |
| 622 |
\cs_new:Nn\__mathcommand_absorb_add_exponent_after:Nn{ |
| 623 |
\tl_set:Nn\__mathcommand_exponent_tl{^{#2}} |
| 624 |
#1 |
| 625 |
} |
| 626 |
% \end{macrocode} |
| 627 |
% \begin{macrocode} |
| 628 |
\cs_new:Npn\__mathcommand_absorb:w{ |
| 629 |
\peek_prime_remove:TFw |
| 630 |
{\__mathcommand_absorb_add_prime: |
| 631 |
\__mathcommand_absorb_p:w} |
| 632 |
\__mathcommand_absorb_:w} |
| 633 |
\cs_new:Npn\__mathcommand_absorb_:w{ |
| 634 |
\peek_subscript_remove:TFw |
| 635 |
{\__mathcommand_absorb_add_index_after:Nn |
| 636 |
\__mathcommand_absorb_i:w} |
| 637 |
\__mathcommand_absorb__:w} |
| 638 |
\cs_new:Npn\__mathcommand_absorb__:w{ |
| 639 |
\peek_superscript_remove:TFw |
| 640 |
{\__mathcommand_absorb_add_exponent_after:Nn |
| 641 |
\__mathcommand_absorb_e:w} |
| 642 |
\__mathcommand_absorb_finished:} |
| 643 |
% \end{macrocode} |
| 644 |
% \begin{macrocode} |
| 645 |
\cs_new:Npn\__mathcommand_absorb_p:w{ |
| 646 |
\peek_prime_remove:TFw |
| 647 |
{\__mathcommand_absorb_add_prime: |
| 648 |
\__mathcommand_absorb_p:w} |
| 649 |
\__mathcommand_absorb_p_:w} |
| 650 |
\cs_new:Npn\__mathcommand_absorb_p_:w{ |
| 651 |
\peek_subscript_remove:TFw |
| 652 |
{\__mathcommand_absorb_add_index_after:Nn |
| 653 |
\__mathcommand_absorb_pi:w} |
| 654 |
\__mathcommand_absorb_finished:} |
| 655 |
% \end{macrocode} |
| 656 |
% \begin{macrocode} |
| 657 |
\cs_new:Npn\__mathcommand_absorb_pi:w{ |
| 658 |
\peek_prime_remove:TFw |
| 659 |
{\__mathcommand_absorb_add_prime: |
| 660 |
\__mathcommand_absorb_pi:w} |
| 661 |
\__mathcommand_absorb_finished:} |
| 662 |
% \end{macrocode} |
| 663 |
% \begin{macrocode} |
| 664 |
\cs_new:Npn\__mathcommand_absorb_e:w{ |
| 665 |
\peek_subscript_remove:TFw |
| 666 |
{\__mathcommand_absorb_add_index_after:Nn |
| 667 |
\__mathcommand_absorb_finished:} |
| 668 |
\__mathcommand_absorb_finished:} |
| 669 |
% \end{macrocode} |
| 670 |
% \begin{macrocode} |
| 671 |
\cs_new:Npn\__mathcommand_absorb_i:w{ |
| 672 |
\peek_prime_remove:TFw |
| 673 |
{\__mathcommand_absorb_add_prime: |
| 674 |
\__mathcommand_absorb_pi:w} |
| 675 |
\__mathcommand_absorb_i_:w} |
| 676 |
% \end{macrocode} |
| 677 |
% \begin{macrocode} |
| 678 |
\cs_new:Npn\__mathcommand_absorb_i_:w{ |
| 679 |
\peek_superscript_remove:TFw |
| 680 |
{\__mathcommand_absorb_add_exponent_after:Nn |
| 681 |
\__mathcommand_absorb_finished:} |
| 682 |
\__mathcommand_absorb_finished:} |
| 683 |
% \end{macrocode} |
| 684 |
% |
| 685 |
%\subsubsection{Definition of high level commands} |
| 686 |
% |
| 687 |
% \begin{macrocode} |
| 688 |
\NewDocumentCommand\newcommandPIE{ m o o m }{ |
| 689 |
\__mathcommand_check_definable:nNT {#1} \newcommandPIE |
| 690 |
{ |
| 691 |
\cs_if_exist:NTF #1 |
| 692 |
{ |
| 693 |
\__kernel_msg_error:nnxx { mathcommand } { command-already-defined } |
| 694 |
{ \use:nnn \token_to_str:N #1 { } } |
| 695 |
{ \token_to_str:N \newcommandPIE } |
| 696 |
} |
| 697 |
{ \__mathcommand_declarecommandPIE:Nnnn #1{#2}{#3}{#4} } |
| 698 |
} |
| 699 |
} |
| 700 |
\NewDocumentCommand\renewcommandPIE{ m o o m }{ |
| 701 |
\__mathcommand_check_definable:nNT {#1} \renewcommandPIE |
| 702 |
{ |
| 703 |
\cs_if_exist:NTF #1 |
| 704 |
{ \__mathcommand_declarecommandPIE:Nnnn #1{#2}{#3}{#4} } |
| 705 |
{ |
| 706 |
\__kernel_msg_error:nnxx { mathcommand } { command-not-yet-defined } |
| 707 |
{ \use:nnn \token_to_str:N #1 { } } |
| 708 |
{ \token_to_str:N \renewcommandPIE } |
| 709 |
} |
| 710 |
} |
| 711 |
} |
| 712 |
\NewDocumentCommand\declarecommandPIE{ m o o m }{ |
| 713 |
\__mathcommand_check_definable:nNT {#1} \declarecommandPIE |
| 714 |
{ \__mathcommand_declarecommandPIE:Nnnn #1{#2}{#3}{#4} } |
| 715 |
} |
| 716 |
% \end{macrocode} |
| 717 |
% \begin{macrocode} |
| 718 |
\cs_new:Nn\__mathcommand_declarecommandPIE:Nnnn{ |
| 719 |
\use:x{ |
| 720 |
\exp_not:N\__mathcommand_declarePIE_generic:Nnnn |
| 721 |
\exp_not:N#1 |
| 722 |
{\IfNoValueTF{#2}{0}{#2}} |
| 723 |
{\cs_if_exist:NTF#1 |
| 724 |
{\exp_not:N\renewrobustcmd} |
| 725 |
{\exp_not:N\newrobustcmd} |
| 726 |
\exp_not:N#1 |
| 727 |
\IfNoValueTF{#2}{}{[#2]} |
| 728 |
\IfNoValueTF{#3}{}{[{\exp_not:n{#3}}]}} |
| 729 |
{\exp_not:n{#4}} |
| 730 |
}} |
| 731 |
% \end{macrocode} |
| 732 |
% \begin{macrocode} |
| 733 |
\cs_new_protected:Npn\NewDocumentCommandPIE#1#2#3{ |
| 734 |
\__mathcommand_check_definable:nNT {#1} \NewDocumentCommandPIE |
| 735 |
{ |
| 736 |
\cs_if_exist:NTF #1 |
| 737 |
{ |
| 738 |
\__kernel_msg_error:nnxx { mathcommand } { command-already-defined } |
| 739 |
{ \use:nnn \token_to_str:N #1 { } } |
| 740 |
{ \token_to_str:N \NewDocumentCommandPIE } |
| 741 |
} |
| 742 |
{ \__mathcommand_DeclareDocumentCommandPIE:Nnn #1 {#2} {#3} } |
| 743 |
} |
| 744 |
} |
| 745 |
% \end{macrocode} |
| 746 |
% \begin{macrocode} |
| 747 |
\cs_new_protected:Npn\RenewDocumentCommandPIE#1#2#3{ |
| 748 |
\__mathcommand_check_definable:nNT {#1} \RenewDocumentCommandPIE |
| 749 |
{ |
| 750 |
\cs_if_exist:NTF #1 |
| 751 |
{ \__mathcommand_DeclareDocumentCommandPIE:Nnn #1 {#2} {#3} } |
| 752 |
{ |
| 753 |
\__kernel_msg_error:nnxx { mathcommand } { command-not-yet-defined } |
| 754 |
{ \use:nnn \token_to_str:N #1 { } } |
| 755 |
{ \token_to_str:N \RenewDocumentCommandPIE } |
| 756 |
} |
| 757 |
} |
| 758 |
} |
| 759 |
% \end{macrocode} |
| 760 |
% \begin{macrocode} |
| 761 |
\cs_new_protected:Npn\DeclareDocumentCommandPIE#1#2#3{ |
| 762 |
\__mathcommand_check_definable:nNT {#1} \DeclareDocumentCommandPIE |
| 763 |
{ |
| 764 |
\__mathcommand_DeclareDocumentCommandPIE:Nnn #1 {#2} {#3} |
| 765 |
} |
| 766 |
} |
| 767 |
% \end{macrocode} |
| 768 |
% \begin{macrocode} |
| 769 |
\cs_new_protected:Npn\ProvideDocumentCommandPIE#1#2#3{ |
| 770 |
\__mathcommand_check_definable:nNT {#1} \ProvideDocumentCommandPIE |
| 771 |
{ |
| 772 |
\cs_if_exist:NTF #1{} |
| 773 |
{ |
| 774 |
\__mathcommand_DeclareDocumentCommandPIE:Nnn #1 {#2} {#3} |
| 775 |
} |
| 776 |
} |
| 777 |
} |
| 778 |
% \end{macrocode} |
| 779 |
% \begin{macrocode} |
| 780 |
\cs_set:Nn\__mathcommand_DeclareDocumentCommandPIE:Nnn{ |
| 781 |
\group_begin: |
| 782 |
\DeclareDocumentCommand#1{#2}{} |
| 783 |
\int_gset_eq:NN\g_tmpa_int\l__xparse_current_arg_int |
| 784 |
\group_end: |
| 785 |
\__mathcommand_declarePIE_generic:Nnnn |
| 786 |
#1 |
| 787 |
{\g_tmpa_int} |
| 788 |
{\DeclareDocumentCommand#1{#2}} |
| 789 |
{#3} |
| 790 |
} |
| 791 |
% \end{macrocode} |
| 792 |
% Control token, number parameters, defining command, code |
| 793 |
% \begin{macrocode} |
| 794 |
\cs_new:Nn\__mathcommand_declarePIE_generic:Nnnn{ |
| 795 |
\int_compare:nNnTF{#2}>{6} |
| 796 |
{\PackageError{mathcommand} |
| 797 |
{At~most~6~parameters~in~PIE~commands~when~defining~`\token_to_str:N#1'} |
| 798 |
{PIE~commands~(mathcommand~package)~do~not~accept~more~than~six~parameters.}} |
| 799 |
{\int_case:nn{#2} |
| 800 |
{{0} {\cs_set:cpn{\cs_to_str:N#1~PIE~code}##1##2##3} |
| 801 |
{1} {\cs_set:cpn{\cs_to_str:N#1~PIE~code}##1##2##3##4} |
| 802 |
{2} {\cs_set:cpn{\cs_to_str:N#1~PIE~code}##1##2##3##4##5} |
| 803 |
{3} {\cs_set:cpn{\cs_to_str:N#1~PIE~code}##1##2##3##4##5##6} |
| 804 |
{4} {\cs_set:cpn{\cs_to_str:N#1~PIE~code}##1##2##3##4##5##6##7} |
| 805 |
{5} {\cs_set:cpn{\cs_to_str:N#1~PIE~code}##1##2##3##4##5##6##7##8} |
| 806 |
{6} {\cs_set:cpn{\cs_to_str:N#1~PIE~code}##1##2##3##4##5##6##7##8##9}} |
| 807 |
{#4} |
| 808 |
\use:x{ |
| 809 |
\exp_not:n{#3} |
| 810 |
{\exp_not:N\__mathcommand_absorb_PIE:nw |
| 811 |
{\exp_not:c{\cs_to_str:N#1~PIE~code} |
| 812 |
\int_case:nn{#2} |
| 813 |
{{0}{} |
| 814 |
{1}{\exp_not:n{{##1}}} |
| 815 |
{2}{\exp_not:n{{##1}{##2}}} |
| 816 |
{3}{\exp_not:n{{##1}{##2}{##3}}} |
| 817 |
{4}{\exp_not:n{{##1}{##2}{##3}{##4}}} |
| 818 |
{5}{\exp_not:n{{##1}{##2}{##3}{##4}{##5}}} |
| 819 |
{6}{\exp_not:n{{##1}{##2}{##3}{##4}{##5}{##6}}}}}}} |
| 820 |
} |
| 821 |
} |
| 822 |
% \end{macrocode} |
| 823 |
% |
| 824 |
% |
| 825 |
% \subsubsection{Auxiliary functions} |
| 826 |
% |
| 827 |
% |
| 828 |
% \begin{macrocode} |
| 829 |
\def\lettersUppercase{ABCDEFGHIJKLMNOPQRSTUVWXYZ} |
| 830 |
\def\lettersLowercase{abcdefghijklmnopqrstuvwxyz} |
| 831 |
\xdef\lettersAll{\lettersLowercase\lettersUppercase} |
| 832 |
\def\lettersGreekLowercase{\alpha\beta\gamma\delta\epsilon\varepsilon\zeta\eta\theta\vartheta\iota\kappa\lambda\mu\nu\xi\pi\varpi\rho\varrho\sigma\varsigma\tau\upsilon\phi\varphi\chi\psi\omega} |
| 833 |
\def\lettersGreekUppercase{\Gamma\Delta\Theta\Lambda\Xi\Pi\Sigma\Upsilon\Phi\Psi\Omega} |
| 834 |
\xdef\lettersGreekAll{\lettersGreekLowercase\lettersGreekUppercase} |
| 835 |
% \end{macrocode} |
| 836 |
% |
| 837 |
% \begin{macrocode} |
| 838 |
\cs_set_eq:NN\IfEmptyTF\tl_if_empty:nTF |
| 839 |
% \end{macrocode} |
| 840 |
% \begin{macrocode} |
| 841 |
\cs_new:Npn\EmptyContent#1{ |
| 842 |
\tl_if_empty:nTF{#1}{{}}{ |
| 843 |
\__mathcommand_EmptyContent:w #1*\end_marker: |
| 844 |
} |
| 845 |
} |
| 846 |
\cs_new:Npn\__mathcommand_EmptyContent:w #1#2\end_marker:{ |
| 847 |
#1* |
| 848 |
} |
| 849 |
% \end{macrocode} |
| 850 |
% \begin{macrocode} |
| 851 |
\cs_new:Npn\GetExponent#1{ |
| 852 |
\tl_if_empty:nTF{#1}{}{ |
| 853 |
\__mathcommand_GetIndexOrExponent:w #1\__end_marker__ |
| 854 |
} |
| 855 |
} |
| 856 |
\cs_new:Npn\GetIndex#1{ |
| 857 |
\tl_if_empty:nTF{#1}{}{ |
| 858 |
\__mathcommand_GetIndexOrExponent:w #1\__end_marker__ |
| 859 |
} |
| 860 |
} |
| 861 |
\cs_new:Npn\__mathcommand_GetIndexOrExponent:w #1#2#3\__end_marker__{ |
| 862 |
#2 |
| 863 |
} |
| 864 |
% \end{macrocode} |
| 865 |
% |
| 866 |
% |
| 867 |
% \subsection{Separating math and text macros} |
| 868 |
% |
| 869 |
% |
| 870 |
% \begin{macrocode} |
| 871 |
\tl_const:Nn\__mathcommand_prefix_math_tl{Math~} |
| 872 |
\tl_const:Nn\__mathcommand_prefix_text_tl{Text~} |
| 873 |
\tl_const:Nn\__mathcommand_prefix_store_tl{LaTeX} |
| 874 |
% \end{macrocode} |
| 875 |
% \begin{macrocode} |
| 876 |
\cs_new:Nn\__mathcommand_to_mathtl:N{\__mathcommand_prefix_math_tl\cs_to_str:N#1} |
| 877 |
\cs_new:Nn\__mathcommand_to_texttl:N{\__mathcommand_prefix_text_tl\cs_to_str:N#1} |
| 878 |
\cs_new:Nn\__mathcommand_to_storetl:N{\__mathcommand_prefix_store_tl\cs_to_str:N#1} |
| 879 |
\cs_new:Nn\__mathcommand_coretl:N |
| 880 |
{\expandafter\__command_coretl:w\string#1\end_mark} |
| 881 |
\cs_new:Npn\__command_coretl:w#1~#2\end_mark{#2} |
| 882 |
% \end{macrocode} |
| 883 |
% \begin{macrocode} |
| 884 |
\cs_new:Npn\__mathcommand_if_exist:NTF |
| 885 |
{\cs_if_exist:NTF} |
| 886 |
\cs_new:Npn\__mathcommand_if_exist_math:NTF#1 |
| 887 |
{\cs_if_exist:cTF{\__mathcommand_to_mathtl:N#1}} |
| 888 |
\cs_new:Npn\__mathcommand_if_exist_text:NTF#1 |
| 889 |
{\cs_if_exist:cTF{\__mathcommand_to_texttl:N#1}} |
| 890 |
\cs_new:Npn\__mathcommand_if_exist_text_or_math:NTF#1 |
| 891 |
{\__mathcommand_if_exist_math:NTF#1 |
| 892 |
\use_i:nn{\__mathcommand_if_exist_text:NTF#1}} |
| 893 |
% \end{macrocode} |
| 894 |
% \begin{macrocode} |
| 895 |
\cs_new:Nn\__mathcommand_error_if_exist_math:NF{ |
| 896 |
\cs_if_exist:cTF{\__mathcommand_to_mathtl:N#1} |
| 897 |
{\exp_args:Nnx\PackageError{} |
| 898 |
{Command~`\token_to_str:N#1'~already~exists~in~math~mode} |
| 899 |
{} |
| 900 |
}{#2} |
| 901 |
} |
| 902 |
% \end{macrocode} |
| 903 |
% \begin{macrocode} |
| 904 |
\cs_new:Nn\__mathcommand_error_if_exist_text:NF{ |
| 905 |
\cs_if_exist:cTF{\__mathcommand_to_texttl:N#1} |
| 906 |
{\exp_args:Nnx\PackageError{} |
| 907 |
{Command~`\token_to_str:N#1'~already~exists~in~text~mode} |
| 908 |
{} |
| 909 |
}{#2} |
| 910 |
} |
| 911 |
% \end{macrocode} |
| 912 |
% \begin{macrocode} |
| 913 |
\cs_new:Nn\__mathcommand_error_if_not_exist_math:NF{ |
| 914 |
\cs_if_exist:cTF{\__mathcommand_to_mathtl:N#1} |
| 915 |
{#2} |
| 916 |
{\exp_args:Nnx\PackageError{} |
| 917 |
{Command~`\token_to_str:N#1'~does~not~exist~in~math~mode} |
| 918 |
{} |
| 919 |
} |
| 920 |
} |
| 921 |
% \end{macrocode} |
| 922 |
% \begin{macrocode} |
| 923 |
\cs_new:Nn\__mathcommand_error_if_not_exist_text:NF{ |
| 924 |
\cs_if_exist:cTF{\__mathcommand_to_texttl:N#1} |
| 925 |
{#2} |
| 926 |
{\exp_args:Nnx\PackageError{} |
| 927 |
{Command~`\token_to_str:N#1'~does~not~exist~in~text~mode} |
| 928 |
{} |
| 929 |
} |
| 930 |
} |
| 931 |
% \end{macrocode} |
| 932 |
% \begin{macrocode} |
| 933 |
\cs_new:Nn\__mathcommand_error_unknownmath:N{ |
| 934 |
\exp_args:Nnx\PackageError{} |
| 935 |
{Command~`\token_to_str:c{\__mathcommand_coretl:N #1}'~does~not~exist~in~math~mode} |
| 936 |
{} |
| 937 |
} |
| 938 |
% \end{macrocode} |
| 939 |
% \begin{macrocode} |
| 940 |
\cs_new:Nn\__mathcommand_error_unknowntext:N{ |
| 941 |
\exp_args:Nnx\PackageError{} |
| 942 |
{Command~`\token_to_str:c{\__mathcommand_coretl:N #1}'~does~not~exist~in~text~mode} |
| 943 |
{} |
| 944 |
} |
| 945 |
% \end{macrocode} |
| 946 |
% \begin{macrocode} |
| 947 |
\cs_new:Nn\__mathcommand_try_math:N{ |
| 948 |
\cs_if_exist:NTF#1#1{\__mathcommand_error_unknownmath:N#1} |
| 949 |
} |
| 950 |
\cs_new:Nn\__mathcommand_try_text:N{ |
| 951 |
\cs_if_exist:NTF#1#1{\__mathcommand_error_unknowntext:N#1} |
| 952 |
} |
| 953 |
% \end{macrocode} |
| 954 |
% \AP |
| 955 |
% The macro \csintro{\__mathcommand_create_fork:N} takes a control sequence, |
| 956 |
% and creates the forking code that executes either the math branch of the text branch. |
| 957 |
% If this forking code is already present, the command does nothing. |
| 958 |
% However, if some macro was already associated with this control sequence, then |
| 959 |
% it is copied to the "math variant", the "text variant" as well as the stored. |
| 960 |
% \begin{macrocode} |
| 961 |
\cs_set:Nn\__mathcommand_create_fork:N{ |
| 962 |
\let\__mathcommand_tmp_cs\undefined |
| 963 |
\exp_args:NNx |
| 964 |
\cs_new_protected:Npn\__mathcommand_tmp_cs{ |
| 965 |
\exp_not:N\mode_if_math:TF |
| 966 |
{\exp_not:N\__mathcommand_try_math:N\exp_not:c{\__mathcommand_to_mathtl:N#1}} |
| 967 |
{\exp_not:N\__mathcommand_try_text:N\exp_not:c{\__mathcommand_to_texttl:N#1}} |
| 968 |
} |
| 969 |
\cs_if_exist:NTF#1{ |
| 970 |
\cs_if_eq:NNTF#1\__mathcommand_tmp_cs |
| 971 |
{ } |
| 972 |
{ \cs_set_eq:cN{\__mathcommand_to_storetl:N#1}#1 |
| 973 |
\cs_set_eq:cN{\__mathcommand_to_mathtl:N#1}#1 |
| 974 |
\cs_set_eq:cN{\__mathcommand_to_texttl:N#1}#1 |
| 975 |
\cs_set_eq:NN#1\__mathcommand_tmp_cs |
| 976 |
} |
| 977 |
}{ \cs_set_eq:NN#1\__mathcommand_tmp_cs } |
| 978 |
} |
| 979 |
% \end{macrocode} |
| 980 |
% \subsection{Definition of the high level commands} |
| 981 |
% \begin{macrocode} |
| 982 |
\NewDocumentCommand\declarecommand{m}{ |
| 983 |
\__mathcommand_check_definable:nNT {#1} \declarecommand |
| 984 |
{ |
| 985 |
\cs_if_exist:NTF#1 |
| 986 |
{\renewcommand#1} |
| 987 |
{\newcommand#1} |
| 988 |
} |
| 989 |
} |
| 990 |
\newrobustcmd\storecommand[2][\__mathcommand_prefix_store_tl]{ |
| 991 |
\__mathcommand_check_definable:nNT {#2} \storecommand |
| 992 |
{ |
| 993 |
\cs_if_exist:NTF#2{ |
| 994 |
\cs_set_eq:cN{#1\cs_to_str:N#2}#2 |
| 995 |
} |
| 996 |
{ |
| 997 |
\PackageError{mathcommand} |
| 998 |
{The~command~`\token_to_str:N#2'~does~not~exist~(in~\token_to_str:N\storecommand)} |
| 999 |
{} |
| 1000 |
} |
| 1001 |
} |
| 1002 |
} |
| 1003 |
|
| 1004 |
\NewDocumentCommand\NewDocumentMathCommand{m}{ |
| 1005 |
\__mathcommand_check_definable:nNT {#1} \NewDocumentMathCommand |
| 1006 |
{ |
| 1007 |
\__mathcommand_create_fork:N#1 |
| 1008 |
\__mathcommand_error_if_exist_math:NF#1 |
| 1009 |
{\exp_args:Nc\DeclareDocumentCommand{\__mathcommand_to_mathtl:N#1}} |
| 1010 |
} |
| 1011 |
} |
| 1012 |
\NewDocumentCommand\NewDocumentTextCommand{m}{ |
| 1013 |
\__mathcommand_check_definable:nNT {#1} \NewDocumentTextCommand |
| 1014 |
{ |
| 1015 |
\__mathcommand_create_fork:N#1 |
| 1016 |
\__mathcommand_error_if_exist_text:NF#1 |
| 1017 |
{\exp_args:Nc\DeclareDocumentCommand{\__mathcommand_to_texttl:N#1}} |
| 1018 |
} |
| 1019 |
} |
| 1020 |
\NewDocumentCommand\newmathcommand{m}{ |
| 1021 |
\__mathcommand_check_definable:nNT {#1} \newmathcommand |
| 1022 |
{ |
| 1023 |
\__mathcommand_create_fork:N#1 |
| 1024 |
\__mathcommand_error_if_exist_math:NF#1 |
| 1025 |
{\exp_args:Nc\newcommand{\__mathcommand_to_mathtl:N#1}} |
| 1026 |
} |
| 1027 |
} |
| 1028 |
\NewDocumentCommand\newtextcommand{m}{ |
| 1029 |
\__mathcommand_check_definable:nNT {#1} \newtextcommand |
| 1030 |
{ |
| 1031 |
\__mathcommand_create_fork:N#1 |
| 1032 |
\__mathcommand_error_if_exist_text:NF#1 |
| 1033 |
{\exp_args:Nc\newcommand{\__mathcommand_to_texttl:N#1}} |
| 1034 |
} |
| 1035 |
} |
| 1036 |
\NewDocumentCommand\RenewDocumentMathCommand{m}{ |
| 1037 |
\__mathcommand_check_definable:nNT {#1} \RenewDocumentMathCommand |
| 1038 |
{ |
| 1039 |
\__mathcommand_create_fork:N#1 |
| 1040 |
\__mathcommand_error_if_not_exist_math:NF#1 |
| 1041 |
{\exp_args:Nc\DeclareDocumentCommand{\__mathcommand_to_mathtl:N#1}} |
| 1042 |
} |
| 1043 |
} |
| 1044 |
\NewDocumentCommand\RenewDocumentTextCommand{m}{ |
| 1045 |
\__mathcommand_check_definable:nNT {#1} \RenewDocumentMathCommand |
| 1046 |
{ |
| 1047 |
\__mathcommand_create_fork:N#1 |
| 1048 |
\__mathcommand_error_if_not_exist_text:NF#1 |
| 1049 |
{\exp_args:Nc\DeclareDocumentCommand{\__mathcommand_to_texttl:N#1}} |
| 1050 |
} |
| 1051 |
} |
| 1052 |
\NewDocumentCommand\renewmathcommand{m}{ |
| 1053 |
\__mathcommand_check_definable:nNT {#1} \renewmathcommand |
| 1054 |
{ |
| 1055 |
\__mathcommand_create_fork:N#1 |
| 1056 |
\__mathcommand_error_if_not_exist_math:NF#1 |
| 1057 |
{\exp_args:Nc\renewcommand{\__mathcommand_to_mathtl:N#1}} |
| 1058 |
} |
| 1059 |
} |
| 1060 |
\NewDocumentCommand\renewtextcommand{m}{ |
| 1061 |
\__mathcommand_check_definable:nNT {#1} \renewtextcommand |
| 1062 |
{ |
| 1063 |
\__mathcommand_create_fork:N#1 |
| 1064 |
\__mathcommand_error_if_not_exist_text:NF#1 |
| 1065 |
{\exp_args:Nc\renewcommand{\__mathcommand_to_texttl:N#1}} |
| 1066 |
} |
| 1067 |
} |
| 1068 |
\NewDocumentCommand\declaremathcommand{m}{ |
| 1069 |
\__mathcommand_check_definable:nNT {#1} \renewmathcommand |
| 1070 |
{ |
| 1071 |
\__mathcommand_create_fork:N#1 |
| 1072 |
\exp_args:Nc\declarecommand{\__mathcommand_to_mathtl:N#1} |
| 1073 |
} |
| 1074 |
} |
| 1075 |
\NewDocumentCommand\declaretextcommand{m}{ |
| 1076 |
\__mathcommand_check_definable:nNT {#1} \renewtextcommand |
| 1077 |
{ |
| 1078 |
\__mathcommand_create_fork:N#1 |
| 1079 |
\exp_args:Nc\declarecommand{\__mathcommand_to_texttl:N#1} |
| 1080 |
} |
| 1081 |
} |
| 1082 |
|
| 1083 |
\NewDocumentCommand\DeclareDocumentMathCommand{m}{ |
| 1084 |
\__mathcommand_check_definable:nNT {#1} \DeclareDocumentMathCommand |
| 1085 |
{ |
| 1086 |
\__mathcommand_create_fork:N#1 |
| 1087 |
\exp_args:Nc\DeclareDocumentCommand{\__mathcommand_to_mathtl:N#1} |
| 1088 |
} |
| 1089 |
} |
| 1090 |
\NewDocumentCommand\DeclareDocumentTextCommand{m}{ |
| 1091 |
\__mathcommand_check_definable:nNT {#1} \DeclareDocumentTextCommand |
| 1092 |
{ |
| 1093 |
\__mathcommand_create_fork:N#1 |
| 1094 |
\exp_args:Nc\DeclareDocumentCommand{\__mathcommand_to_texttl:N#1} |
| 1095 |
} |
| 1096 |
} |
| 1097 |
\NewDocumentCommand\ProvideDocumentMathCommand{mmm}{ |
| 1098 |
\__mathcommand_check_definable:nNT {#1} \ProvideDocumentMathCommand |
| 1099 |
{ |
| 1100 |
\__mathcommand_create_fork:N#1 |
| 1101 |
\exp_args:Nc\ProvideDocumentCommand{\__mathcommand_to_mathtl:N#1}{#2}{#3} |
| 1102 |
} |
| 1103 |
} |
| 1104 |
\NewDocumentCommand\ProvideDocumentTextCommand{m}{ |
| 1105 |
\__mathcommand_check_definable:nNT {#1} \ProvideDocumentTextCommand |
| 1106 |
{ |
| 1107 |
\__mathcommand_create_fork:N#1 |
| 1108 |
\exp_args:Nc\ProvideDocumentCommand{\__mathcommand_to_texttl:N#1} |
| 1109 |
} |
| 1110 |
} |
| 1111 |
% \end{macrocode} |
| 1112 |
% |
| 1113 |
% \subsection{Definition of the high level combined commands} |
| 1114 |
% |
| 1115 |
% \begin{macrocode} |
| 1116 |
\NewDocumentCommand\NewDocumentMathCommandPIE{m}{ |
| 1117 |
\__mathcommand_check_definable:nNT {#1} \NewDocumentMathCommandPIE |
| 1118 |
{ |
| 1119 |
\__mathcommand_create_fork:N#1 |
| 1120 |
\__mathcommand_error_if_exist_math:NF#1 |
| 1121 |
{\exp_args:Nc\DeclareDocumentCommandPIE{\__mathcommand_to_mathtl:N#1}} |
| 1122 |
} |
| 1123 |
} |
| 1124 |
\NewDocumentCommand\newmathcommandPIE{m}{ |
| 1125 |
\__mathcommand_check_definable:nNT {#1} \newmathcommandPiE |
| 1126 |
{ |
| 1127 |
\__mathcommand_create_fork:N#1 |
| 1128 |
\__mathcommand_error_if_exist_math:NF#1 |
| 1129 |
{\exp_args:Nc\newcommandPIE{\__mathcommand_to_mathtl:N#1}} |
| 1130 |
} |
| 1131 |
} |
| 1132 |
\NewDocumentCommand\RenewDocumentMathCommandPIE{m}{ |
| 1133 |
\__mathcommand_check_definable:nNT {#1} \RenewDocumentMathCommandPIE |
| 1134 |
{ |
| 1135 |
\__mathcommand_create_fork:N#1 |
| 1136 |
\__mathcommand_error_if_not_exist_math:NF#1 |
| 1137 |
{\exp_args:Nc\DeclareDocumentCommandPIE{\__mathcommand_to_mathtl:N#1}} |
| 1138 |
} |
| 1139 |
} |
| 1140 |
\NewDocumentCommand\renewmathcommandPIE{m}{ |
| 1141 |
\__mathcommand_check_definable:nNT {#1} \renewmathcommandPIE |
| 1142 |
{ |
| 1143 |
\__mathcommand_create_fork:N#1 |
| 1144 |
\__mathcommand_error_if_not_exist_math:NF#1 |
| 1145 |
{\exp_args:Nc\renewcommandPIE{\__mathcommand_to_mathtl:N#1}} |
| 1146 |
} |
| 1147 |
} |
| 1148 |
\NewDocumentCommand\DeclareDocumentMathCommandPIE{m}{ |
| 1149 |
\__mathcommand_check_definable:nNT {#1} \DeclareDocumentMathCommand |
| 1150 |
{ |
| 1151 |
\__mathcommand_create_fork:N#1 |
| 1152 |
\exp_args:Nc\DeclareDocumentCommand{\__mathcommand_to_mathtl:N#1} |
| 1153 |
} |
| 1154 |
} |
| 1155 |
\NewDocumentCommand\declaremathcommandPIE{m}{ |
| 1156 |
\__mathcommand_check_definable:nNT {#1} \declaremathcommandPIE |
| 1157 |
{ |
| 1158 |
\__mathcommand_create_fork:N#1 |
| 1159 |
\exp_args:Nc\declarecommandPIE{\__mathcommand_to_mathtl:N#1} |
| 1160 |
} |
| 1161 |
} |
| 1162 |
|
| 1163 |
\NewDocumentCommand\ProvideDocumentMathCommandPIE{mmm}{ |
| 1164 |
\__mathcommand_check_definable:nNT {#1} \ProvideDocumentMathCommandPIE |
| 1165 |
{ |
| 1166 |
\__mathcommand_create_fork:N#1 |
| 1167 |
\exp_args:Nc\ProvideDocumentCommandPIE{\__mathcommand_to_mathtl:N#1}{#2}{#3} |
| 1168 |
} |
| 1169 |
} |
| 1170 |
% \end{macrocode} |
| 1171 |
% |
| 1172 |
% \subsection{Looping for command definitions} |
| 1173 |
% |
| 1174 |
% |
| 1175 |
% \begin{macrocode} |
| 1176 |
\NewDocumentCommand\LoopCommands{ m ooooooo m }{ |
| 1177 |
\IfNoValueTF{#2} |
| 1178 |
{\cs_set:Nn\__tmp_two:n{\exp_not:c{##1}}} |
| 1179 |
{\cs_set:Nn\__tmp_two:n{\exp_not:c{#2}}} |
| 1180 |
\IfNoValueTF{#3} |
| 1181 |
{\cs_set:Nn\__tmp_three:n{\exp_not:c{##1}}} |
| 1182 |
{\cs_set:Nn\__tmp_three:n{\exp_not:c{#3}}} |
| 1183 |
\IfNoValueTF{#4} |
| 1184 |
{\cs_set:Nn\__tmp_four:n{\exp_not:c{##1}}} |
| 1185 |
{\cs_set:Nn\__tmp_four:n{\exp_not:c{#4}}} |
| 1186 |
\IfNoValueTF{#5} |
| 1187 |
{\cs_set:Nn\__tmp_five:n{\exp_not:c{##1}}} |
| 1188 |
{\cs_set:Nn\__tmp_five:n{\exp_not:c{#5}}} |
| 1189 |
\IfNoValueTF{#6} |
| 1190 |
{\cs_set:Nn\__tmp_six:n{\exp_not:c{##1}}} |
| 1191 |
{\cs_set:Nn\__tmp_six:n{\exp_not:c{#6}}} |
| 1192 |
\IfNoValueTF{#7} |
| 1193 |
{\cs_set:Nn\__tmp_seven:n{\exp_not:c{##1}}} |
| 1194 |
{\cs_set:Nn\__tmp_seven:n{\exp_not:c{#7}}} |
| 1195 |
\IfNoValueTF{#8} |
| 1196 |
{\cs_set:Nn\__tmp_eight:n{\exp_not:c{##1}}} |
| 1197 |
{\cs_set:Nn\__tmp_eight:n{\exp_not:c{#8}}} |
| 1198 |
% |
| 1199 |
\cs_gset:Nn\g_tmpb_cs:nnnnnnnn{#9} |
| 1200 |
% |
| 1201 |
\cs_gset:Nn\g_tmpa_cs:n{ |
| 1202 |
\tl_set:Nn\l_tmpa_tl{##1} |
| 1203 |
\use:x{ |
| 1204 |
\exp_not:N\g_tmpb_cs:nnnnnnnn |
| 1205 |
{\l_tmpa_tl} |
| 1206 |
\__tmp_two:n{\l_tmpa_tl} |
| 1207 |
\__tmp_three:n{\l_tmpa_tl} |
| 1208 |
\__tmp_four:n{\l_tmpa_tl} |
| 1209 |
\__tmp_five:n{\l_tmpa_tl} |
| 1210 |
\__tmp_six:n{\l_tmpa_tl} |
| 1211 |
\__tmp_seven:n{\l_tmpa_tl} |
| 1212 |
\__tmp_eight:n{\l_tmpa_tl}} |
| 1213 |
} |
| 1214 |
\exp_args:Nx\tl_map_inline:nn{#1} |
| 1215 |
{\tl_if_blank:nTF{##1} |
| 1216 |
{} |
| 1217 |
{\g_tmpa_cs:n{\__mathcommand_getbasename:n{##1}}} |
| 1218 |
} |
| 1219 |
} |
| 1220 |
\cs_new:Nn\__mathcommand_getbasename:n{ |
| 1221 |
\tl_if_single:nTF{#1}{ |
| 1222 |
\token_if_cs:NTF#1 |
| 1223 |
{\cs_to_str:N#1} |
| 1224 |
{#1} |
| 1225 |
}{#1} |
| 1226 |
} |
| 1227 |
% \end{macrocode} |
| 1228 |
% |
| 1229 |
% \subsection{Deactivating macros} |
| 1230 |
% |
| 1231 |
% \begin{macrocode} |
| 1232 |
\bool_new:N\__mathcommand_disabled_error_bool |
| 1233 |
\bool_set_true:N\__mathcommand_disabled_error_bool |
| 1234 |
\bool_new:N\__mathcommand_disabled_suggest_original_bool |
| 1235 |
\bool_set_true:N\__mathcommand_disabled_suggest_original_bool |
| 1236 |
\bool_new:N\__mathcommand_force_enabled_bool |
| 1237 |
\bool_set_false:N\__mathcommand_force_enabled_bool |
| 1238 |
% \end{macrocode} |
| 1239 |
% \begin{macrocode} |
| 1240 |
\cs_new:Nn\__mathcommand_to_disabled_help_tl:N |
| 1241 |
{mathcommand_disabled_help_\cs_to_str:N#1_tl} |
| 1242 |
% \end{macrocode} |
| 1243 |
% \begin{macrocode} |
| 1244 |
\cs_new:Nn\__mathcommand_error:nn |
| 1245 |
{ \msg_new:nnn{mathcommand}{#1}{#2} |
| 1246 |
\msg_error:nn{mathcommand}{#1} |
| 1247 |
} |
| 1248 |
\cs_new:Nn\__mathcommand_dc_error:n |
| 1249 |
{ \msg_new:nnn{mathcommand}{disabled~command}{#1} |
| 1250 |
\msg_error:nn{mathcommand}{disabled~command} |
| 1251 |
} |
| 1252 |
\cs_new:Nn\__mathcommand_dc_warning:n |
| 1253 |
{ \msg_set:nnn{mathcommand}{disabled~command}{#1} |
| 1254 |
\msg_warning:nn{mathcommand}{disabled~command} |
| 1255 |
} |
| 1256 |
\cs_new:Nn\mathcommand_disabled_error:N |
| 1257 |
{ \bool_if:NTF\__mathcommand_disabled_error_bool |
| 1258 |
{\exp_args:Nx\__mathcommand_dc_error:n} |
| 1259 |
{\exp_args:Nx\__mathcommand_dc_warning:n} |
| 1260 |
{\exp_not:n{\\The~command~\string#1~is~disabled.~Instead:\\ } |
| 1261 |
\bool_if:NT\__mathcommand_disabled_suggest_original_bool |
| 1262 |
{Use~\exp_not:c{\__mathcommand_to_storetl:N#1} for~the~original~macro.} |
| 1263 |
\exp_not:v{\__mathcommand_to_disabled_help_tl:N#1}} |
| 1264 |
} |
| 1265 |
% \end{macrocode} |
| 1266 |
% \begin{macrocode} |
| 1267 |
\msg_new:nnn{mathcommand}{unknown~command} |
| 1268 |
{\\The~control~sequence~#1 is~not~defined \\Origin~macro:~#2} |
| 1269 |
% \end{macrocode} |
| 1270 |
% \begin{macrocode} |
| 1271 |
\NewDocumentCommand\disablecommand{m}{ |
| 1272 |
\tl_map_function:nN{#1}\mathcommand_disablecommand:N |
| 1273 |
} |
| 1274 |
|
| 1275 |
|
| 1276 |
\cs_new:Nn\mathcommand_disablecommand:N |
| 1277 |
{ \cs_if_exist:NTF#1{ |
| 1278 |
\__mathcommand_check_definable:nNT#1\disablecommand |
| 1279 |
{\tl_if_exist:cTF{\__mathcommand_to_disabled_help_tl:N#1} |
| 1280 |
{} |
| 1281 |
{\storecommand#1 |
| 1282 |
\tl_new:c{\__mathcommand_to_disabled_help_tl:N#1} |
| 1283 |
\renewcommand#1 |
| 1284 |
{\bool_if:NF |
| 1285 |
\__mathcommand_force_enabled_bool |
| 1286 |
{\mathcommand_disabled_error:N#1} |
| 1287 |
\use:c{\__mathcommand_to_storetl:N#1}}} |
| 1288 |
} |
| 1289 |
}{ |
| 1290 |
\msg_error:nnnn{mathcommand}{unknown~command}{#1}{\disablecommand} |
| 1291 |
} |
| 1292 |
} |
| 1293 |
% \end{macrocode} |
| 1294 |
% \begin{macrocode} |
| 1295 |
\NewDocumentCommand\suggestcommand{mm} |
| 1296 |
{ \cs_if_exist:NTF#1{ |
| 1297 |
\cs_if_exist:cTF{\__mathcommand_to_disabled_help_tl:N#1}{ |
| 1298 |
\tl_put_right:cx{\__mathcommand_to_disabled_help_tl:N#1}{\exp_not:N\\\tl_to_str:n{#2}} |
| 1299 |
}{ |
| 1300 |
\__mathcommand_error:nn{command~not~disabled} |
| 1301 |
{\\\string\suggestcommand :~Command~#1~has~not~been~disabled.} |
| 1302 |
} |
| 1303 |
} |
| 1304 |
{ \__mathcommand_error:nn{unknown~command} |
| 1305 |
{\\\string\suggestcommand :~Unknown~command~#1.} |
| 1306 |
} |
| 1307 |
} |
| 1308 |
% \end{macrocode} |
| 1309 |
% |
| 1310 |
% \subsection{Options} |
| 1311 |
% |
| 1312 |
% \begin{macrocode} |
| 1313 |
\keys_define:nn { mathcommand }{ |
| 1314 |
disabled .multichoice:, |
| 1315 |
disabled / silent .code:n = {\bool_set_true:N\__mathcommand_force_enabled_bool }, |
| 1316 |
disabled / error .code:n = {\bool_set_false:N\__mathcommand_force_enabled_bool |
| 1317 |
\bool_set_true:N\__mathcommand_disabled_error_bool}, |
| 1318 |
disabled / warning .code:n = {\bool_set_false:N\__mathcommand_force_enabled_bool |
| 1319 |
\bool_set_false:N\__mathcommand_disabled_error_bool}, |
| 1320 |
} |
| 1321 |
\ProcessKeysOptions { mathcommand } % Parses the option list |
| 1322 |
\NewDocumentCommand\mathcommandconfigure{ m } |
| 1323 |
{\keys_set:nn{ mathcommand}{ #1} } |
| 1324 |
% \end{macrocode} |
| 1325 |
% |
| 1326 |
% \subsection{Testing control sequence for definition} |
| 1327 |
% This part of the code is an import of a previous version of xparse (Frank Mittelbach, Chris Rowley, David Carlisle, The LaTeX Project). It is done in a very ugly hack: the code is copied and past, and \texttt{mathcommand} substituted to \texttt{xparse} wherever necessary. |
| 1328 |
% \begin{macrocode} |
| 1329 |
\cs_new_protected:Npn \__mathcommand_check_definable:nNT #1 |
| 1330 |
{ \tl_trim_spaces_apply:nN {#1} \__mathcommand_check_definable_aux:nN } |
| 1331 |
\group_begin: |
| 1332 |
\char_set_catcode_active:n { `? } |
| 1333 |
\cs_new_protected:Npn \__mathcommand_check_definable_aux:nN #1#2 |
| 1334 |
{ |
| 1335 |
\group_begin: |
| 1336 |
\tl_if_single_token:nTF {#1} |
| 1337 |
{ |
| 1338 |
\int_set:Nn \tex_escapechar:D { 92 } |
| 1339 |
\exp_args:Nx \tl_if_empty:nTF |
| 1340 |
{ \exp_args:No \str_tail:n { \token_to_str:N #1 } } |
| 1341 |
{ |
| 1342 |
\exp_args:Nx \char_set_lccode:nn |
| 1343 |
{ ` \str_head:n {#1} } { `? } |
| 1344 |
\tex_lowercase:D { \tl_if_eq:nnTF {#1} } { ? } |
| 1345 |
{ \group_end: \use_iii:nnn } |
| 1346 |
{ \group_end: \use_i:nnn } |
| 1347 |
} |
| 1348 |
{ \group_end: \use_iii:nnn } |
| 1349 |
} |
| 1350 |
{ \group_end: \use_ii:nnn } |
| 1351 |
{ |
| 1352 |
\__kernel_msg_error:nnxx { mathcommand } { not-definable } |
| 1353 |
{ \tl_to_str:n {#1} } { \token_to_str:N #2 } |
| 1354 |
} |
| 1355 |
{ |
| 1356 |
\__kernel_msg_error:nnxx { mathcommand } { not-one-token } |
| 1357 |
{ \tl_to_str:n {#1} } { \token_to_str:N #2 } |
| 1358 |
} |
| 1359 |
} |
| 1360 |
\group_end: |
| 1361 |
% \end{macrocode} |
| 1362 |
% \subsection{Closure} |
| 1363 |
% \begin{macrocode} |
| 1364 |
\ExplSyntaxOff |
| 1365 |
% \end{macrocode} |
| 1366 |
% |
| 1367 |
% \end{document} |
| 1368 |
|