% \iffalse meta-comment
%
% Copyright (C) 2019-2023 by Antoine Missier <antoine.missier@ac-toulouse.fr>
%
% This file may be distributed and/or modified under the conditions of
% the LaTeX Project Public License, either version 1.3 of this license
% or (at your option) any later version.  The latest version of this
% license is in:
%
%   http://www.latex-project.org/lppl.txt
%
% and version 1.3 or later is part of all distributions of LaTeX version
% 2005/12/01 or later.
% \fi
%
% \iffalse
%<*driver>
\ProvidesFile{mismath.dtx}
%</driver>
%<*package> 
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{mismath}   
    [2023/03/05 v2.7 .dtx mismath file]
%</package>
%<*driver>
\documentclass{ltxdoc}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage[charter]{mathdesign} % in case of font change, modify 2.1 (3rd §)
\usepackage[ibrackets]{mismath}
%\usepackage{amssymb} incompatible with mathdesign
\usepackage{multicol}
\usepackage[Symbol]{upgreek}
\usepackage{sectsty}
\usepackage{xcolor}
\usepackage{spacingtricks}
\usepackage{array}
\usepackage{metalogo} % for logos of XeLaTeX et LuaLaTeX

\definecolor{darkbrown}{rgb}{0.5,0.1,0.1}
\allsectionsfont{\color{darkbrown}}
\MathUp{i} \pinumber[piup]
% I need italicized e in vectors section
% For using in this doc only:
\usepackage[LGR,T1]{fontenc}
\DeclareSymbolFont{UpGr}{LGR}{lmr}{m}{n}
\DeclareMathSymbol{\mypi}\mathalpha{UpGr}{"70}
% For showing original \i and \j in text mode:
\DeclareTextFontCommand{\extrafont}{\fontfamily{lmr}\selectfont}

\DisableCrossrefs         
%\CodelineIndex
%\RecordChanges
\usepackage{hyperref}
\hypersetup{%
    colorlinks, 
    linkcolor=blue,
    citecolor=red,   
    pdftitle={mismath}, 
    pdfsubject={LaTeX package}, 
    pdfauthor={Antoine Missier}
}
\begin{document}
  \DocInput{mismath.dtx}
  %\PrintChanges
  %\PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{618}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \changes{v0.1}{2011/12/27}{First personal version}
%
% \changes{v1.0}{2019/04/11}{
%    - Initial published version: creating dtx and ins files}
%
% \changes{v1.1}{2019/04/20}{
%    - Some forgotten french 'et' -> 'and', citecolor=blue,
%    - changing the default font for pinumber Euler -> Symbol}
%
% \changes{v1.2}{2019/04/26}{
%    - Works fine with beamer now, 
%    - AtBeginDocument for enumber, inumber, jnumber, 
%    - creating general mm@operator macro, 
%    - using mathup instead of mathrm}
% \changes{v1.2}{2019/04/27}{
%    - Added mathtools package, 
%    - font definition Roman -> up, 
%    - changes in documentation, 
%    - replacing the PEroman macro by PEupright}
%
% \changes{v1.3}{2019/05/05}{
%    - Using bslash in the internal mm@warning macro, 
%    - loading of mathfixs package}
% \changes{v1.3}{2019/05/08}{
%    - Many corrections in documentation}
%
% \changes{v1.4}{2019/05/22}{
%    - Changing font definition up -> UpSh, due to incompatibility with unicode-math}
%
% \changes{v1.5}{2019/05/30}{
%    - A solution for using mul with frac -> braces, 
%    - addition of paren macro}
% \changes{v1.5}{2019/06/22}{
%    - Small corrections in documentation}
%
% \changes{v1.6}{2019/09/06}{
%    - Removing mathfixs package, problems with fractions}
%
% \changes{v1.7}{2019/12/27}{
%    - Adding a table of contents to the documentation}
%
% \changes{v1.8}{2020/11/15}{
%    - Incompatibility mentioned when using `i' with accent in beamer titles -> use \^i, 
%    - small changes in documentation}
%
% \changes{v1.9}{2020/10/17}{
%    - UpSh replaced by "operators" font in math mode, 
%    - PackageWarning `command exist' replaced by PackageWarningNoLine,
%    - medspace replaced by thickspace in the lfrac command,
%    - changing font in documentation, lmodern -> Palatino (mathpazo)}
%
% \changes{v1.10}{2020/10/25}{\
%    - pinumber command code adapted to avoid incompatibility with the new frenchmath, 
%    - default option (in upgreek) changed from Symbol to Euler.}
%
% \changes{v2.0}{2022/11/11}{
%    - pinumber command has been improved to use other Greek letter packages,
%        (and LGR encoding pi by default), it is no longer compatible with the older, 
%    - paren command has been removed, 
%    - hvect and hlbar have been slighlty modified (phantom t instead of phantom h),
%    - several changes in documentation, 
%    - now using the Charter font (with the package mathdesign)}
%
% \changes{v2.1}{2022/12/26}{
%    - Improved management of square brackets with the ibrackets package,
%    - new macros codim, sinc, var, eqdef*, 
%    - removing the systematic warning for paren command,
%    - a small change in norm command -> bars in small size,
%    - several changes in documentation}
%
% \changes{v2.2}{2023/01/06}{
%    - Loading of ibrackets package is now optional, due to an error
%        when using DeclarePairedDelimiter with square brackets.}
%
% \changes{v2.3}{2023/02/06}{
%    - Introducing keyval options for enumber, inumber, jnumber, PEupright
%        (corresponding old commands are maintained for now),
%    - and also for ibrackets, boldvect and arrowvect}
% \changes{v2.3}{2023/02/09}{
%    - Documentation update}
%
% \changes{v2.4}{2023/02/18}{
%    - New powerful macros MathUp, MathIt and also MathNumbers, MathProba, MathNormal,
%    - keyval options are no longer useful and have been deleted,
%    - loading package ifthen has been forgotten in v2.3 (causing possible errors),
%    - no more incompatibility when using `i' with accent in beamer titles}
%
% \changes{v2.5}{2023/02/23}{
%    - Unification of the code of MathUp and MathIt,
%    - a powerful macro `apply' is used in MathNormal to act on a list,
%    - a new `tensor' command,
%    - small changes in the documentation}
%
% \changes{v2.6}{2023/03/01}{
%    - A bug correction in mm@macro
%    - incompatibility of \C macro solved, when using babel with russian
%        (thanks to Murray Eisenberg for this bug report on TeX StackExchange)
%    - mathrm added in macro eqdef* (useful if italicized Greek uppercase Delta)
%    - Tiny changes in the documentation}
%
% \changes{v2.7}{2023/03/05}{
%    - Macros for sets of numbers (\R, \C,...) now available only in math mode
%        (following remarks by David Carlisle and Enrico Gregorio)
%    - special (not generic) warning when loading babel with russian
%        (\C will not be defined in that case)}
%
% \GetFileInfo{mismath.sty}
%
% \title{\textsf{mismath}\\ Miscellaneous mathematical macros\thanks{This document
% corresponds to \textsf{mismath}~\fileversion, dated \filedate. 
% Thanks to François Bastouil for help in English translation.}}
% \author{Antoine Missier \\ \texttt{antoine.missier@ac-toulouse.fr}}
% \date{March 5, 2023}
%
% \maketitle
% \tableofcontents
%
% \section{Introduction}
%
% According to the International Standards ISO~31-0:1992 to ISO~31-13:1992, 
% superseded by ISO~80000-2:2009, mathematical constants $\e$, $\i$, $\pi$ 
% should be typeset in roman (upright shape) and not in italic (sloping shape) like
% variables (see~\cite{TYPMA}~\cite{NIST}~\cite{SI}~\cite{ICTNS}).
% This package provides some tools to achieve this (automatically).
%
% \medskip
% Even if it is recommended to typeset vectors names 
% in bold italic style~\cite{NIST}~\cite{ICTNS}, 
% they are often represented with arrows 
% (particularly in school documents or in physics). 
% To draw pretty arrows above vectors, we use the \textsf{esvect} package 
% by Eddie Saudrais~\cite{VECT} 
% and we provide a few more macros related to vectors with arrows, 
% in particular to improve the typesetting of the norm: $\norm{\vect{AB}}$ 
% instead of \LaTeX\ version $\lVert\vect{AB}\rVert$ which is not vertically adjusted,
% or worse $\left\Vert \vect{AB} \right\Vert$ (and even ugly with Latin Modern font family).
% 
% \smallskip
% The package also provides other macros for:
% \begin{itemize}
% \item tensors,
% \item some standard operator names,
% \item a few useful aliases,
% \item improving some spacing in mathematical formulas,
% \item systems of equations and small matrices,
% \item displaymath in double columns for long calculation.
% \end{itemize}
%
% To avoid incompatibility,
% most of our macros will be defined only 
% if there is not another command with the same name in the packages loaded 
% before \textsf{mismath}. If a macro is already defined,
% a warning message will be produced and the \textsf{mismath} definition 
% will simply be ignored. To keep the \textsf{mismath} command or the other one, use 
% |\let\|\meta{command}|\relax|, before loading \textsf{mismath}, or after.
% If the other one is defined with |\AtBeginDocument|, do the same for 
% |\let\|\meta{command}|\relax| and for loading mismath.
%
% \medskip
% \DescribeEnv{\oarg{options}}
% The \textsf{amsmath} package is loaded by \textsf{mismath} without option.
% For using \textsf{amsmath} with options (see~\cite{AMS}),
% these options can be added when calling \textsf{mismath}, or 
% \textsf{amsmath} can be loaded 
% with the required options before \textsf{mismath}.
%
% \medskip
% \textsf{mismath} loads also the package 
% \textsf{mathtools} by Morten Høgholm and Lars Madsen~\cite{TOOL}. 
% It provides many useful macros and improvements of \textsf{amsmath} package.
%
% \medskip
% A recommendation, seldom observed, is to typeset uppercase Greek letters in italic shape 
% like other variables~\cite{ICTNS}. This is automatically done with the packages 
% \textsf{fixmath} by Walter Schmidt~\cite{FIXM},
% \textsf{isomath} by Günter Milde~\cite{ISOM} 
% or \textsf{pm-isomath} by Claudio Beccari~\cite{PMISO} and optionally with many others
% (for instance \textsf{mathpazo} or \textsf{mathptmx} with the option \texttt{slantedGreek}),
% but this feature is not implemented here because this rule is conflicting 
% to the one used in France where all mathematics capitals 
% have to be typeset in upright shape
% \footnote{The \textsf{frenchmath} package~\cite{FR} 
% takes this rule into account.}.
% The choice of loading or not one of these packages remains thus to the user.
%
% \section{Usage}
%
% \subsection{Mathematical constants} 
%
% \DescribeMacro{\mathup} 
% As for classic functions identifiers, \emph{predefined} mathematical constants
% should be typeset in upright shape (generally in roman family), 
% even if this practice is not really common and tedious
% to respect. First we provide the |\mathup| macro, which is better than |\mathrm| 
% \footnote{\texttt{\bslash mathup}
% is based on \texttt{\bslash operatorfont} 
% (from \textsf{amsopn} package, automatically loaded by \textsf{amsmath}).
% The \textsf{beamer} 
% package uses a default sans serif math font, but \texttt{\bslash mathrm}
% produces a font with serif in \textsf{beamer}. Therefore
% using \texttt{\bslash mathup} is better than \texttt{\bslash mathrm}.},
% to set any math text in upright shape, so on can write
% |\mathup{e}| to get the Euler's number.
%
% \medskip
% \DescribeMacro{\e} \DescribeMacro{\i}  \DescribeMacro{\j} 
% To avoid to stuff a document that contains many $\e$ or $\i$ constants 
% with |\mathup{e}| or |\mathup{i}|,
% the package provides |\e| command for Euler's number
% and |\i| or |\j| for imaginary numbers. 
% Let's notice that |\i| and |\j| already exist in \LaTeX: 
% using in LR mode, they produce `\extrafont{\i,\ \j}' without the point, 
% so you can place accents on them, and in mathematical mode they produce 
% ``\texttt{LaTeX Warning: Command \bslash i invalid in math mode on input line} \meta{line}''. 
% The new definition of |\i| and |\j| concerns only the mathematical mode.
%
% \medskip
% \DescribeMacro{\MathUp} 
% Nevertheless, it can be tiresome to type a lot of backslashes
% for these constants, in a document 
% with many formulas containing $\e$, $\i$ or $\j$.
% So a way is proposed here to free of it with the macro
% |\MathUp|\marg{char}.
% For instance when |\MathUp{e}| is called,
% any future occurrence of $\e$ will then automatically be set in roman,
% without the need to type |\e|. 
% The effect is global or local if used inside an environment or braces.
% This macro can also be called in the preamble for applying 
% from the beginning of the document.
% Thanks to this powerful macro, you can bring a document up to the standards afterwards.
% In fact |\MathUp| can apply to any valid but single character (we will see another
% use of it with probability in section \ref{operators}).
%
% \medskip
% \DescribeMacro{\MathIt}
% When there are other $\mathit{e}$, $\mathit{i}$ or $j$ as variables,
% you can still get italicized
% $\mathit{e}$, $\mathit{i}$ or $\mathit{j}$ with \LaTeX\ commands
% |\mathit| or |\mathnormal|, useful for a single use.
% But you can also use the inverse switch |\MathIt|\marg{char},
% with a global effect, or a local one if used inside an environment or braces.
% As |\MathUp|, it can be used for any single character.
%
% \medskip
% \DescribeMacro{\MathNumbers} \DescribeMacro{\MathNormal}
% These macros allow to set upright or normal typesetting for several letters
% in a single command, \eg
% |\MathNumbers{e,i}| is equivalent to |\MathUp{e}\MathUp{i}|.
% In |\MathNumbers| the comma separator can be changed or deleted.
% This macro has no effect on other letters than e, i or j.
% On the other hand |\MathNormal| can be used for probability also 
% (see section \ref{operators})
% and can take any comma separated list argument.
% 
% \medskip
% \DescribeMacro{\pinumber[\meta{command}]}
% The mathematical constant $\pi$  should also be typeset in upright shape 
% (see~\cite{TYPMA}, \cite{NIST}, \cite{ICTNS}), which differs from italicized $\itpi$. 
% This recommendation is even less observed than the one concerning  
% $\e$ and $\i$~\cite{TYPMA}.
% Several packages allow to typeset mathematical Greek letters in upright shape, 
% let us mention \textsf{upgreek}~\cite{GREEK}, \textsf{mathdesign}~\cite{DESIGN} 
% (used here), \textsf{kpfonts}~\cite{KPF}, \textsf{fourier}~\cite{FOUR},
% \textsf{libertinust1math},
% \textsf{pxgreeks}, \textsf{txgreeks}, \textsf{libgreek}, etc.
% A special mention for \textsf{lgrmath} of Jean-François Burnol~\cite{LGR}
% which allow to use, in math mode, any Greek LGR-encoded font.
% These packages provide commands like |\uppi| (\textsf{upgreek}), 
% |\piup| (\textsf{mathdesign}, \textsf{kpfonts}, \textsf{lgrmath}), 
% |\otherpi| (\textsf{fourier}), etc.
% \footnote{They also have options to typeset all the Greek lowercase 
% letters in upright shape by default, but this in not our goal here.}
% To preserve default sloped lowercase Greek letters except for pi, and to
% avoid typing a lot of |\uppi| or |\piup|, we provide the 
% macro |\pinumber|[\meta{command}].
% It redefines |\pi| to match
% the optional command  name given (without backslash), for instance |piup|, 
% assuming the appropriate package has been loaded before. 
%
% By calling preliminary |\MathNumbers{ei}\pinumber[piup]| 
% (and with the \textsf{mathdesign} package loaded)
% you can get for instance:
% \begin{center}
% |$e^{i\pi} = -1$| \quad yields \quad   $\e^{i\pi}=-1$.
% \end{center}
%
% When calling |\pinumber| without argument
% it defines |\pi| with the default LGR font encoding of Greek letters
% to produce $\mypi$. In that case the appropriate option \texttt{LGR}
% for the \textsf{fontenc} package will be automatically loaded,
% provided that the command is called in the preamble (first). 
% The pi character will look the same as the one supplied with
% Günter Milde's \textsf{textalpha} package~\cite{ALPHA}.
% This $\mypi$ is particularly suitable
% for use with the default Computer Modern or Latin Modern font family
% \footnote{This default $\mypi$ doesn't fit well with many text fonts, 
% more bold than Computer Modern;
% the \textsf{upgreek} package~\cite{GREEK} provides often a better $\uppi$
% (with the \texttt{Symbol} option using Adobe Symbol font) 
% that fits well with several text fonts, for instance Times.}.
%
% \medskip
% \DescribeMacro{\itpi}
% When activating |\pinumber|, the original italic $\itpi$ 
% is still available with |\itpi|.
%
% \DescribeMacro{\pinormal}
% In fact |\pinumber| acts as a switch and there is also an inverse switch, 
% |\pinormal|, that can be called anywhere.
%
% \subsection{Vectors (and tensors)}
%
% \DescribeMacro{\vect}
% By default, the |\vect| command
% \footnote{As for many macros of this package, 
% the definition will take effect only if this macro is not defined before 
% by another package.},
% produces vectors with arrows
% (thanks to the \textsf{esvect} package of Eddie Saudrais
% \footnote{\textsf{esvect} provides the \texttt{\bslash vv} macro 
% used by \texttt{\bslash vect}.})
% which are more elegant than those produced by \LaTeX's |\overrightarrow| command.
% The \textsf{esvect} package has an optional argument 
% (one letter between \texttt{a} and \texttt{h}) defining 
% the required type of arrow (see~\cite{VECT}).
% In \textsf{mismath}, \textsf{esvect} is loaded with the option \texttt{b}:
% |\vect{AB}| gives $\vect{AB}$.
% To choose another type of arrow, \textsf{esvect} must be called 
% with the required option \emph{before} \textsf{mismath}, 
% \eg |\usepackage[d]{esvect}|
% will give the arrows produced by default in~\cite{VECT}.
%
% \medskip 
% \DescribeMacro{\boldvect}
% The |\vect| macro allow to typeset vector's names using bold italic
% (according to ISO recommendation~\cite{NIST}~\cite{SI}) rather than arrows. 
% For this, calling |\boldvect| will modify the behavior of |\vect|,
% globally or locally, depending on where |\boldvect| 
% is placed:\\[1ex]
% \begin{minipage}{8cm}
% \begin{verbatim} 
%\[ \boldvect \vect{v}
%   =\lambda\vect{e}_x+\mu\vect{e}_y. \]
% \end{verbatim}
% \end{minipage} 
% \begin{minipage}{6cm}
% $\boldvect \vect{v}=\lambda\vect{e}_x +\mu\vect{e}_y$.
% \end{minipage}
%
% \DescribeMacro{\boldvectcommand}
% By default |\boldvect| uses the |\boldsymbol| command
% \footnote{\texttt{\bslash mathbf} gives upright bold font, 
% even if used in combination with \texttt{\bslash mathit}.}
% from \textsf{amsbsy} package, loaded by \textsf{amsmath}.
% But other packages producing bold italic can be preferred, \eg
% |\mathbold| from \textsf{fixmath}
% package or |\mathbfit| from \textsf{isomath}
% or \texttt{\bslash bm} from \textsf{bm} package.
% For that, redefine |\boldvectcommand|, for instance, after loading \textsf{fixmath}: 
% \begin{center} |\renewcommand\boldvectcommand{\mathbold}|. \end{center}
%
% According to ISO rules, symbols for matrices are also in bold italic,
% so you can use the same |\boldvectcommand| or create another alias.
%
% \medskip
% \DescribeMacro{\arrowvect}
% At any moment, you can get back to the default behavior with the inverse switch
% |\arrowvect|. 
% These switches can be placed anywhere: 
% inside mathematical mode or inside an environment (with local effect) or outside 
% (with global effect).
%
% \medskip
% \DescribeMacro{\hvect}
% When vectors with arrows are typeset side by side,
% arrows can be set up a bit higher (with a vertical phantom box containing $t$) 
% to avoid inelegant effects:
% \begin{itemize}
% \item $\vect{AB}=\hvect{u}+ \vect{AC}$, obtained with |\hvect{u}|,
% is better than $\vect{AB}=\vect{u}+ \vect{AC}$;
% \item $\hvect{a} \cdot \vect{b}=0$, obtained with |\hvect{a}|,
% is better thant $\vect{a} \cdot \vect{b}=0$.
% \end{itemize}
% The |\boldvect| and |\arrowvect| switches have the same effect on |\hvect| than on |\vect|,
% and so have \texttt{boldvect} and \texttt{arrowvect} options.
%
% \DescribeMacro{\hvec}
% In a similar way, |\hvec| raises the little arrow produced by
% the \LaTeX\ command |\vec| (from height of $t$ letter):
% \begin{itemize}
% \item $\mathcal{P}=\vec{f}\cdot\hvec{v}$, obtained with |\hvec{v}|,
% is better than $\mathcal{P}=\vec{f}\cdot\vec{v}$.
% \item $\vec{f} =m \hvec{a}$, obtained with |\hvec{a}|,
% is better than $\vec{f} =m \vec{a}$.
% \end{itemize}
%
% \DescribeMacro{\norm}
% The norm of a vector is classically produced by the delimiters |\lVert| and |\rVert|
% (rather than \texttt{\bslash}$\mid$) or |\left\Vert| and |\right\Vert| 
% for delimiters adapting to the content. Unfortunately, these delimiters 
% are always vertically centered, relatively to the middle of the base line, 
% whereas vectors with arrows are asymmetric objects.
% The code |$\norm{\vec{h}}$| raises a smaller double bar to produce $\norm{\vec{h}}$
% instead of $\left\Vert \vec{h} \right\Vert$.
% Let's notice that the height of the bars don't adjust to content, 
% but however to context: main text, subscripts or exponents, 
% \eg $\e^{\norm{\vec{h}}}$.
%
% \medskip
% \DescribeMacro{\mathbfsfit}\DescribeMacro{\tensor}
% For tensors symbols, ISO rules recommend to use
% sans serif bold italic, but there
% is no such math alphabet in \TeX\ default mathematical style.
% \textsf{mismath} defines this alphabet 
% (assuming the font encoding and package you use permits it), 
% and provides the macro |\mathbfsfit| or its alias |\tensor|.
% So |\tensor{T}| produces $\tensor{T}$.
%
% \subsection{Standard operator names}\label{operators}
%
% \DescribeMacro{\di}
% The \emph{differential} operator should be typeset in upright shape and not in
% italic, to make it different from variables 
% (as mentioned in \cite{TYPMA}~\cite{NIST}~\cite{ICTNS}~\cite{LSHORT}).
% For this, we provide the |\di| command.
% See the following examples (notice the thin spaces before the d, 
% as for classic function's names): \\
% \begin{minipage}[t]{7cm}
% \begin{verbatim} 
%\[ \iint xy\di x\di y \]
% \end{verbatim}
% \end{minipage}
% \begin{minipage}{6cm}
% \[ \iint xy\di x\di y \]
% \end{minipage}
% \\
% \begin{minipage}[t]{7cm}
% \begin{verbatim} 
%\[ m\frac{\di^2x}{\di t^2}
%   + h\frac{\di x}{\di t} + kx = 0 \]
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[t]{6cm}
% \[m\frac{\di^2x}{\di t^2}+h\frac{\di x}{\di t}+kx=0\]
% \end{minipage}
%
% This command can also stand for \emph{distance} (hence its name):
% \[\lambda\di(A,\mathcal{F})+\mu\di(B,\mathcal{H}).\]
%
% \DescribeMacro{\P} \DescribeMacro{\E}
% To refer to probability
% \footnote{\LaTeX\ provides also \texttt{\bslash Pr} which gives $\Pr$.}
% and expectation the proper use is to typeset capital letters $\P$, $\E$ 
% in roman as for any standard function identifier.
% This is obtained with |\P| and |\E|.
%
% \DescribeMacro{\Par}
% The |\P| command already existed to refer to the end of paragraph symbol \Par\ 
% and has been redefined, but this symbol can still be obtained with |\Par|.
%
% \medskip
% \DescribeMacro{\V}
% Variance is generally denoted by $\var$ or $\Var$ (see table below),
% but some authors prefer to use $\V$, produced by |\V|.
%
% \DescribeMacro{\MathProba}\DescribeMacro{\MathNormal}
% In the same way as for $\e$, $\i$ or $\j$, you can use |\MathUp{P}|, |\MathUp{E}| 
% or |\MathUp{V}| to avoid typing many |\P|, |\E| or |\V|. 
% But you can also do that in a single command with |\MathProba|, 
% for example |\MathProba{P,E}| and we get the inverse switch with
% |\MathIt| for any individual letter or |\MathNormal| for a list.
%
% \medskip
% \DescribeMacro{\probastyle}
% Some authors use ``blackboard bold'' font
% to represent probability, expectation and variance: $\mathbb{P}, \mathbb{E}, \mathbb{V}$.
% The |\probastyle| macro sets the appearance of |\P|, |\E| and |\V|:
% for instance |\renewcommand\probastyle{\mathbb}|
% \footnote{As for \texttt{\bslash boldvect} and \texttt{\bslash arrowvect},
% effect is local to the container environment.}
% brings the previous ``openwork'' letters.
% |\mathbb| comes from \textsf{amsfonts} package
% (loaded by \textsf{amssymb} 
% but also available standalone)
% which has to be called in the preamble.
%
% The following standard operator names are defined in \textsf{mismath}:
% \begin{center}
% \begin{tabular}{rlrlrl}
% |\adj| & $\adj$ \qquad\mbox{} & |\erf| & $\erf$ \qquad\mbox{} & |\Re| & $\Re$ \\
% |\Aut| & $\Aut$ & |\grad| & $\grad$ & |\rot| & $\rot$ \\
% |\codim| & $\codim$ & |\id| & $\id$ & |\sgn| & $\sgn$ \\
% |\Conv| & $\Conv$ & |\Id| & $\Id$ & |\sinc| & $\sinc$ \\
% |\cov| & $\cov$ & |\im| & $\im$ & |\spa| & $\spa$ \\
% |\Cov| & $\Cov$ & |\Im| & $\Im$ & |\tr| & $\tr$ \\
% |\curl| & $\curl$ & |\lb| & $\lb$ & |\var| & $\var$ \\
% |\divg| & $\divg$ & |\lcm| & $ \lcm$ & |\Var| & $\Var$  \\
% |\End| & $\End$ & |\rank| & $\rank$ & |\Zu| & $\Zu$
% \end{tabular}
% \end{center}
%
% By default, operators returning vectors,  |\grad| and |\curl| (or its synonym |\rot|
% rather used in Europe), are written with an arrow on the top.
% When |\boldvect| is activated, they are typeset in bold style:
% $\boldvect \grad, \curl, \rot$.
% For the variance, the covariance and the identity function, 
% two notations are proposed, with or without a first capital letter, 
% because they are both very common.
% On the other hand, `$\im$' stands for the image of a linear transformation 
% (like `$\ker$' for the kernel)
% whereas `$\Im$' is the imaginary part of a complex number.
% Notice that |\div| already exist ($\div$) and |\span| is a \TeX\ primitive
% (used in |\multicolumn|);
% they haven't been redefined, therefore the macros |\divg| (divergence) 
% and |\spa| (span of a set of vectors) ;
% |\Z| is used for the set of integers (see \ref{aliases}), therefore we used |\Zu|,
% to designate the center of a group: $\Zu(G)$ (from German Zentrum).
%
%\medskip
% \DescribeMacro{\oldRe} \DescribeMacro{\oldIm}
% The |\Re| and |\Im| macros already existed, to refer to real and imaginary part 
% of a complex number, producing outdated symbols $\oldRe$ and $\oldIm$.
% They have been redefined according to actual use, as mentioned in the above table, 
% but it's still possible to get the old symbols with |\oldRe| and |\oldIm|.
%
% \medskip
% Some (inverse) circular or hyperbolic functions, missing
% in \LaTeX, are also provided by \textsf{mismath}:
% \begin{center}
% \begin{tabular}{rlrlrl}
% |\arccot| & $\arccot$\qquad\mbox{} & |\arsinh| & $\arsinh$\qquad\mbox{} 
%    & |\arcoth| & $\arcoth$ \\
% |\sech| & $\sech$ & |\arcosh| & $\arcosh$ & |\arsech| & $\arsech$ \\
% |\csch| & $\csch$ & |\artanh| & $\artanh$ & |\arcsch| & $\arcsch$
% \end{tabular}
% \end{center} 
%
% \DescribeMacro{\bigO} \DescribeMacro{\bigo} \DescribeMacro{\lito}
% Asymptotic comparison operators (in Landau notation) are obtained with
% |\bigO| or |\bigo| and |\lito| commands: 
% \[ n^2+\bigO(n\log n) \txt{or} n^2+\bigo(n\log n)\txt{and} \e^x=1+x+\lito(x^2).\]
%
% \subsection{A few useful aliases} \label{aliases}
% 
% In the tradition of Bourbaki and D.~Knuth, proper use requires 
% that classic sets of numbers are typeset in bold roman:
% $\R, \C, \Z, \N, \Q$, 
% whereas ``openwork'' letters ($\mathbb{R}, \mathbb{Z}, \ldots$) 
% are reserved for writing at blackboard~\cite{LSHORT};
% and likewise to designate a field: $\F$ or $\K$ (Körper in German).
% We get these symbols with the macros
% \footnote{The \texttt{\bslash C} macro is incompatible with \texttt{russian} option
% of \textsf{babel}; it will not be redefined in that case.}:
% \begin{center}
% |\R|, |\C|, |\Z|, |\N|, |\Q|, |\F|, |\K|.
% \end{center}
%
% \DescribeMacro{\mathset}
% The |\mathset| command enables to change the behavior of all these macros in a global way: 
% by default, |\mathset| is an alias for |\mathbf|, but if you prefer openwork letters, 
% just place |\renewcommand\mathset{\mathbb}| where you want, for instance in the preamble,
% after loading \textsf{amsfonts} package (which provides the ``blackboard bold'' typeface,
% also loaded by \textsf{amssymb}).
%
% \medskip
% \DescribeMacro{\ds}
% The |\displaystyle| command being very common, the |\ds| alias is provided.
% Not only it eases typing but also  it makes source code more readable.
%
% \medskip
% Symbols with limits behave differently for in-line formulas or for displayed equations. 
% In the latter case, ``limits'' are put under or above whereas for in-line math mode, 
% they are placed on the right, as subscript or exponent. Compare:
% $\zeta(s)=\sum_{n=1}^{\infty    }\frac{1}{n^s}$ with
% \[\zeta(s)=\sum_{n=1}^{\infty}\frac{1}{n^s}.\]
%
% \DescribeMacro{\dlim} \DescribeMacro{\dsum} \DescribeMacro{\dprod}
% \DescribeMacro{\dcup} \DescribeMacro{\dcap}
% With in-line math mode, displaymath behavior can be forced with |\displaystyle|
% or its alias |\ds|, but then, all the rest of the current mathematical 
% environment will be set in displaymath mode too (in the previous example, 
% the fraction will be expanded).
% Just as the \textsf{amsmath} command |\dfrac|
% only transforms the required fraction in display style, we can limit 
% the display style effect to the affected symbol, by using the following macros:
% |\dlim|, |\dsum|, |\dprod|, |\dcup|, |\dcap|.
% So 
% \begin{center}
% |$\dlim_{x\to +\infty}\frac{1}{x}$| \quad  gives \quad  $\dlim_{x \to +\infty}\frac{1}{x}$.
% \end{center}
%
% \DescribeMacro{\lbar} \DescribeMacro{\hlbar}
% Large bars over expressions are obtained with |\overline|
% or, shorter, its alias |\lbar|, to get for instance $\lbar{z_1z_2}$.
% Such as for vectors, you can raise the bar (from the height of $h$) with
% the |\hlbar| command, in order to correct uneven bars heights.
% \begin{center}
% $\lbar{z+z'}=\hlbar{z}+\lbar{z'}$, obtained with |\hlbar{z}|,
% is better than $\lbar{z+z'}=\lbar{z}+\lbar{z'}$.
% \end{center}
%
% \pagebreak
% \DescribeMacro{\eqdef} \DescribeMacro{\eqdef*}
% The |\eqdef| macro writes equality symbol topped with `def'
% or with `$\scriptstyle \Delta$' for |\eqdef*|
% (thanks to the \LaTeX\ command |\stackrel|): 
%
% \bigskip
% \noindent\begin{minipage}{8cm}
% \begin{verbatim} 
%$ \e^{\i\theta} \eqdef 
%  \cos\theta + \i\sin\theta $
% \end{verbatim}
% \end{minipage}
% \begin{minipage}{6cm}
% $\e^{\i\theta}\eqdef\cos\theta + \i\sin\theta$
% \end{minipage}
%
% \noindent\begin{minipage}{8cm}
% \begin{verbatim} 
%$ \e^{\i\theta} \eqdef* 
%  \cos\theta + \i\sin\theta $
% \end{verbatim}
% \end{minipage}
% \begin{minipage}{6cm}
% $\e^{\i\theta}\eqdef*\cos\theta + \i\sin\theta$
% \end{minipage}
%
% \DescribeMacro{\unbr}
% |\unbr| is an alias for |\underbrace|
% \footnote{The \textsf{mathtools} package by Morten Høgholm 
% and Lars Madsen~\cite{TOOL} provides a new improved version 
% of \texttt{\bslash underbrace} command (as many other usefull macros);
% it is loaded by \textsf{mismath}.}, 
% making source code more compact.\\[2ex]
% \begin{minipage}{7.5cm}
% \begin{verbatim}
%$ (QAP)^n = \unbr{QAP\mul QAP\mul
%  \cdots\mul QAP}_{n\text{ times}} $
% \end{verbatim}
% \end{minipage}
% \begin{minipage}{6.5cm}
% $ (QAP)^n = \unbr{QAP\mul QAP\mul\cdots\mul QAP}_{n\text{ times}} $
% \end{minipage}
%
% \DescribeMacro{\iif}
% |\iif| is an alias for ``\iif'', to be used in text mode.
%
% \subsection{Improved spacing in mathematical formulas}
%
% \DescribeMacro{\then} 
% The |\then| macro produces the symbol $\Longrightarrow$ surrounded by large spaces
% as the standard macro |\iff| does it with $\Longleftrightarrow$.
% In a similar way, |\txt|, \DescribeMacro{\txt}
% based on the |\text| macro from the \textsf{amstext} package
% (loaded by \textsf{amsmath}),
% leaves em quad spaces (|\quad|) around the text. See the following example:
% \begin{center}
% |\[ \ln x=a \then x=\e^a \txt{rather than}| \\
% | \ln x=a \Longrightarrow x=\e^a \]| \\[1ex]
% $ \ln x=a \then x=\e^a \txt{rather than}    \ln x=a \Longrightarrow x=\e^a$
% \end{center}
%
% \DescribeMacro{\mul}
% The multiplication symbol obtained with |\times| produces the same spacing than addition
% or subtraction operators, whereas division obtained with $/$ is closer to its operands.
% This actually hides the priority of the multiplication on $+$ and $-$.
% This is why we provide the |\mul| macro, behaving like $/$ 
% (ordinary symbol) and leaving less space around than |\times|:
% \begin{center}
% $\lambda+\alpha \mul b-\beta \mul c$, obtained with |\mul|,
% is better than $\lambda+\alpha \times b-\beta \times c$.
% \end{center}
%
% When using |\mul| before a function name or around a |\left...\right| structure, 
% the space may be too large on one side of |\mul|.
% To get the same amount of space on the two sides of |\mul|, 
% you can use thin negative spaces |\!| 
% or enclose the function or the structure with braces:
% \begin{center}
% $x\mul{\sin x}$, obtained with |x\mul{\sin x}|, is slightly better than $x\mul\sin x$.\\[1ex]
% |$\sin\!{\left( \frac{\pi}{3} \right)} \mul 2$| \quad gives\\
% $\sin\!{\left(\frac{\pi}{3}\right)}\mul 2$ which is better than
% $\sin\left(\frac{\pi}{3}\right)\mul 2$. 
% \end{center}
% The thin negative space after the function name is not relative to |\mul|,
% but is due to the fact that spaces around a |\left...\right| structure
% are bigger than those produced by single parenthesis |(...)|.
%
% \medskip
% \DescribeMacro{\pow}
% In the same way, when typesetting an exponent after a closing \emph{big} 
% parenthesis produced by |\right)|,
% the exponent is little to far from the parenthesis.
% The command |\pow|\marg{expr}\marg{pow} sets
% \meta{expr} between parentheses and puts the exponent \meta{pow}
% slightly closer to the right parenthesis
% \footnote{This macro gives bad results with normal sized parenthesis.}. 
% Compare:
% \[ \e^a \sim\pow{1+\frac{a}{n}}{n} \txt{may be better than} 
% \e^a \sim\left(1+\frac{a}{n}\right)^{n}.\]
%
% \DescribeMacro{\abs}
% Absolute value (or modular for a complex number) should be typeset with
% |\lvert| \ldots |\rvert| rather than $\mid$ which doesn't respect correct 
% spaces for delimiters; for bars whose height has to adapt to content, 
% we use |\left\vert| \ldots |\right\vert| or, more simply, 
% the |\abs|\{\ldots\} command which is equivalent
% \footnote{Another solution is to define \texttt{\bslash abs} 
% with the \texttt{\bslash DeclarePairedDelimiter} command 
% from the \textsf{mathtools} package~\cite{TOOL}.}.
%
% \medskip
% \DescribeMacro{\lfrac}
% This macro behaves like |\frac|
% but with thick spaces around the arguments,
% so the corresponding fraction bar is perceptibly a little bit longer:\\
% \begin{minipage}[t]{8cm}
% \begin{verbatim}
%\[ \lbar{Z} = 
%   \lfrac{\lbar{z_1-z_2}}{\lbar{z_1+z_2}} \]
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[t]{4cm}
% \[ \lbar{Z} = \lfrac{\lbar{z_1-z_2}}{\lbar{z_1+z_2}} \]
% \end{minipage}
%
% \medskip
% \DescribeMacro{[ibrackets]}
% Open intervals are usually represented with parenthesis, \eg $(0, +\infty)$,
% but sometimes we find also
% square brackets, for example in French mathematics.
% In that case the space around them is often unsuitable, 
% \eg $x \in \mathclose{]} 0, +\infty[$.
% We have redefined brackets in the \textsf{ibrackets} package~\cite{BRACKET} 
% which can be optionally
% \footnote{This functionality is optional because it causes
% error when using a command defined by 
% \texttt{\bslash DeclarePairedDelimiter}~\cite{TOOL} with square brackets.}
% loaded by \textsf{mismath} with \texttt{ibrackets} package option
% \footnote{It's the only option of the \textsf{mismath} package.}.
%
% Simply type |$x\in ]-\pi,0[ \cup ]2\pi,3\pi[$| to get
% \begin{align*} 
% x\in ]-\pi, 0[ \cup ]2\pi, 3\pi[ &\mbox{\quad with \textsf{ibrackets}}, \\
% \mbox{instead of \quad}
% x\in \mathclose{]}-\pi, 0 \mathopen{[} \cup \mathclose{]} 2\pi, 3\pi \mathopen{[} 
% &\mbox{\quad without \textsf{ibrackets}}.
% \end{align*}
% In our code, $[$ and $]$  symbols become ``active'' 
% and are not defined by default as delimiters. 
% Thereby a line break could occur between the two brackets, but
% it is always possible to transform them 
% into delimiters with |\left| and |\right|.
%
% With \textsf{ibrackets}: a bracket becomes an ordinary character 
% but an open delimiter when it is immediately followed by a + or - character.
% Thus, when the left bound contains an operator sign,
% \emph{you don't have to leave a space between the first bracket and the sign},
% otherwise, the spaces surrounding the operator will be too large:
% \eg |$x \in ] -\infty, 0]$| yields $x \in  ] -\infty, 0]$.
% Contrariwise, when you want to write algebra on intervals then
% \emph{you must leave a blank space between the second bracket and the} +/- 
% \emph{operations},
% \eg |$[a, b] + [c, d]$| yields $[a, b] + [c, d]$
% but |$[a, b]+ [c, d]$| yields $[a, b]+ [c, d]$.
%
% Let us also mention other approaches with the |\interval| macro
% from the \textsf{interval} package~\cite{INT},
% or |\DeclarePairedDelimiters| from the \textsf{mathtools} package~\cite{TOOL}
% (but the latter is incompatible with \textsf{ibrackets}
% for brackets management).
%
% \subsection{Environments for systems of equations and small matrices}
%
% \DescribeEnv{system}
% The \texttt{system} environment produces a system of equations:\\
% \begin{minipage}[t]{6.5cm}
% \begin{verbatim}
%$\begin{system} 
%    x=1+2t \\ y=2-t \\ z=-3-t 
%\end{system}$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[t]{5cm} 
% \[ \begin{system} x=1+2t \\ y=2-t \\z=-3-t \end{system} \]
% \end{minipage}
%
% \medskip
% \DescribeMacro{\systemsep}
% This first example could also have been produced with \texttt{cases} environment
% from \textsf{amsmath} package, although \texttt{cases} places mathematical expressions 
% closer to the bracket (which makes sense considering it's use).
% |\systemsep| enables to set the gap between the bracket and the expressions, 
% set by default to |\medspace|. This gap may be reduced, for instance:
% |\renewcommand{\systemsep}{\thinspace}|,
% or enlarged with |\thickspace| (and with |\renewcommand\systemsep}{}|
% we obtain what \texttt{cases} do).
%
% \medskip
% \DescribeEnv{system\oarg{coldef}}
% By default, a system is written like an \texttt{array} environment with only one column, 
% left aligned. The environment has an optional argument to create several columns,
% specifying their alignment, with the same syntax than the \texttt{array} environment of
% \LaTeX : |\begin{system}[cl]| produces a two-column system, the first one being centered, 
% the second being left aligned, such as in the following example:\\
% \begin{minipage}[t]{7cm}
% \begin{verbatim}
%$\begin{system}[cl] 
%    y & =\dfrac{1}{2}x-2 \\[1ex] 
%    (x,y) & \neq (0,-2) 
%\end{system}$
% \end{verbatim}
% \end{minipage}
% \begin{minipage}[t]{5cm}
% \[ \begin{system}[cl] y&=\dfrac{1}{2}x-2 \\[1ex] (x,y)&\neq (0,-2) \end{system}\]
% \end{minipage}
%
% \DescribeMacro{\systemstretch}
% Default spacing between the lines of a \texttt{system} environment has been slightly 
% enlarged compared to the one from \texttt{array} environments (from 1.2 factor). 
% This spacing may be changed by typing |\renewcommand{\systemstretch}|\marg{stretch},
% inside the current mathematical environment (for a local change) or outside 
% (for a global change). By default, stretch's value is 1.2.
% In addition we can use the end of line with a spacing option such 
% as it has been done above with |\\[1ex]|.
%
% Another example with |\begin{system}[rl@{\quad}l]|
% \footnote{\texttt{@\{\ldots\}} sets inter-column space.}:
% \begin{equation*}
%    \begin{system}[rl@{\quad}l]
%        x+3y+5z&=0 & R_1\\ 2x+2y-z&=3 & R_2\\ 3x-y+z&=2 & R_3
%    \end{system}
%    \iff
%    \begin{system}[rl@{\quad}l]
%        x+3y+5z&=0 & R_1\\
%        4y+11z&=3 & R_2 \gets 2R_1-R_2 \\
%        5y+7z&=-1 & R_3 \gets \frac{1}{2}\left(3R_1-R_3\right)
%    \end{system}
% \end{equation*}
% 
% Let's mention the \textsf{systeme} package~\cite{SYST} which deals with linear systems
% with a lighter syntax and automatic alignments on $+$, $-$, $=$,
% and also the \textsf{spalign} package~\cite{SPAL} which moreover produces nice alignments 
% for matrices (with spaces and semi­colons as de­lim­iters).
%
% \medskip
% \DescribeEnv{spmatrix}
% The \textsf{amsmath} package provides various environments to typeset matrices: 
% for instance \texttt{pmatrix} surrounds the matrix with parenthesis
% or \texttt{smallmatrix} typesets a small matrix that can even be inserted 
% in a text line. We provide a combination of the two with \texttt{spmatrix}:\\
% |$\vec{u}\begin{spmatrix}-1\\2\end{spmatrix}$| yielding
% $\vec{u}\begin{spmatrix}-1\\2\end{spmatrix}$.
%
% The \textsf{mathtools} package enhance \textsf{amsmath} matrices environments
% and provides also a small matrix environment with parenthesis.
% Furthermore, with starred version |\begin{psmallmatrix*}|\oarg{col},
% you can choose the alignment inside the columns (\texttt{c}, \texttt{l} or \texttt{r}).
% But sadly, the space before the left parenthesis is too narrow
% regarding to the space inside the parenthesis.
% Compare previous $\vec{u}\begin{spmatrix}-1\\2\end{spmatrix}$
% with $\vec{u}\begin{psmallmatrix}-1\\2\end{psmallmatrix}$.
%
% \medskip
% For typesetting  various kind of matrices, let's mention the awesome 
% \textsf{nicematrix} package by François Pantigny~\cite{NMATX}.
%
% \subsection{Displaymath in double columns}
%
% \DescribeEnv{mathcols}
% The \texttt{mathcols} environment enables to arrange 
% ``long'' calculation in double columns, separated with a central rule, 
% as shown in the following example.
% But the \textsf{multicol} package must be loaded in the preamble.
% It activates the mathematical mode
% in display style and with an \texttt{aligned} environment.
% \begin{mathcols}
%           & \frac{1}{2 \mul {\pow{\frac{1}{4}}{n}} + 1} \geq 0.999 \\
%     \iff\ & 1 \geq 1.998  \pow{\frac{1}{4}}{n} + 0.999 \\
%     \iff\ & 0.001 \geq \frac{1.998}{4^n} \\
% \changecol
%     & \iff 4^n \geq 1998 \\
%     & \iff n \ln 4 \geq \ln(1998) \\
%     & \iff n \geq \frac{\ln(1998)}{\ln 4} \approx 5.4 \\
%     & \iff n \geq 6
% \end{mathcols}
%
% \DescribeMacro{\changecol}
% The |\changecol| macro causes a change of column;
% alignment is produced using the classic delimiters |&| and |\\|.
% 
% \begin{verbatim}
%\begin{mathcols}
%          & \frac{1}{2 \mul {\pow{\frac{1}{4}}{n}} + 1} \geq 0.999 \\
%    \iff\ & 1 \geq 1.998  \pow{\frac{1}{4}}{n} + 0.999 \\
%    \iff\ & 0.001 \geq \frac{1.998}{4^n} \\
%\changecol
%    & \iff 4^n \geq 1998 \\
%    & \iff n \ln 4 \geq \ln(1998) \\
%    & \iff n \geq \frac{\ln(1998)}{\ln 4} \approx 5.4 \\
%    & \iff n \geq 6
%\end{mathcols}
% \end{verbatim}
%
% \vspace{-4ex}
% \subsection{Deprecated commands}
%
% Here we present a summary table of deprecated commands, used until version 2.2.
% They produce a warning message but are still working and will be maintained for now.
% These deprecated commands
% worked only in the preamble, globally, and there was no inverse switch.
% Therefore they are replaced by the more powerful and more general 
% macro |\MathUp| which can be placed anywhere and has an inverse switch |\MathIt|. 
%
% \begin{center} 
% \setlength{\extrarowheight}{1pt}
% \begin{tabular}{ll}
% \hline
% Deprecated command & New alternative \\
% \hline
% |\enumber| & |\MathUp{e}| \\
% |\inumber| & |\MathUp{i}| \\
% |\jnumber| & |\MathUp{j}| \\
% |\PEupright| & |\MathUp{P}\MathUp{E}| \\
% \hline
% \end{tabular}
% \end{center}
%
% \medskip
% |\MathNumbers| may be used instead of |\MathUp| with an argument containing
% all the constants you want to be typeset in roman (among `e, i, j').
% And |\MathProba{P,E}| may be used instead of |\MathUp{P}\MathUp{E}|
% and you can add also V in its argument to refer to variance.
%
% \medskip
% In version 2.3 we tried a way to replace these deprecated commands
% by package options based on keyval. This less efficient method is abandoned.
% And thus the command |\mismathset| is obsolete.
% Another command, |\paren|, used before version 2.0, is no longer supported.
%
% \StopEventually{}
% \section{Implementation}
%
%    \begin{macrocode}
\newif\ifmm@ibrackets % initialized to false
\DeclareOption{ibrackets}{\mm@ibracketstrue}
\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{amsmath}}
\ProcessOptions \relax
\@ifpackageloaded{amsmath}{}{\RequirePackage{amsmath}}
\@ifpackageloaded{mathtools}{}{\RequirePackage{mathtools}}
\@ifpackageloaded{esvect}{}{\RequirePackage[b]{esvect}}
\RequirePackage{ifthen}
\RequirePackage{xparse} % for \NewDocumentCommand
\RequirePackage{xspace}
\RequirePackage{iftex}
\ifmm@ibrackets\RequirePackage{ibrackets}\fi

%    \end{macrocode}
% The above conditional packages loading avoids ``option clash'' errors if these packages 
% have been previously loaded with other options.
%
% \medskip
% \DescribeMacro{\bslash}
% The |\bslash| macro comes from Frank Mittelbach's \textsf{doc.sty} package. 
% It can also be used in other documents instead of |\textbackslash|
% (which doesn't work inside warnings).
%    \begin{macrocode}
{\catcode`\|=\z@ \catcode`\\=12 |gdef|bslash{\}} % \bslash command

%    \end{macrocode}
%
% \medskip
% \DescribeMacro{\mm@warning} \DescribeMacro{\mm@macro} \DescribeMacro{\mm@operator} 
% The three following internal macros are meta commands for
% conditional macro definition with a warning message if the macro already exists.
% They should be useful in other packages.
% \medskip
%    \begin{macrocode}
\newcommand\mm@warning[1]{
    \PackageWarningNoLine{mismath}{
        Command \bslash #1 already exist and will not be redefined}
}
\newcommand\mm@macro[2]{
    \@ifundefined{#1}{
        \expandafter\def\csname #1\endcsname{#2}
    }{\mm@warning{#1}}
}
\NewDocumentCommand\mm@operator{O{#3}mm}{%
    \@ifundefined{#1}{
        \DeclareMathOperator{#2}{#3}
    }{\mm@warning{#1}}
}
    
%    \end{macrocode}
%
% To produce the correct upright shape font when working 
% with the \textsf{beamer} package, you don't have to use |\mathrm|
% but |\mathup| (based on |\operatorfont| from the \textsf{amsopn} package).
% This command works also fine with other sans serif fonts like \textsf{cmbright}.
%
% Moreover for \textsf{beamer}, which changes the family default font (sans serif)
% |\e|, |\i|, |\j| have no effect without |\AtBeginDocument|.
% 
% |\AtBeginDocument| is also necessary to redefine |\i| when calling 
% the \textsf{hyperref} package which overwrites the |\i| definition.
% \medskip
%    \begin{macrocode}
\providecommand{\mathup}[1]{{\operatorfont #1}} % also in kpfonts
\mm@macro{e}{\mathup{e}}
\AtBeginDocument{\let\oldi\i \let\oldj\j
    \renewcommand{\i}{\TextOrMath{\oldi}{\mathup{i}}}
    \renewcommand{\j}{\TextOrMath{\oldj}{\mathup{j}}} }

%    \end{macrocode}
%
% The following macros are switches that transform in roman vs italic any chosen letter
% in math mode. They can be used anywhere.
% To get a letter in roman instead of italic, we have to change the 
% digit of mathcode that represent the family: 1 to 0.
%
% For example, except for \LuaLaTeX, mathcode of the `e' letter is:
% `e="7165 (decimal 29029), the second digit `1' meaning ``italic''.
% To get a roman `e', we have to change his mathcode in "7065.
%
% When called in the preamble, |\AtBeginDocument| is necessary 
% for using with the \textsf{beamer} package.
% In the preamble, |\math@family{#1}{0}| is equivalent to \\
% |\DeclareMathSymbol{#1}{\mathalpha}{operators}{`#1}|.
% \medskip
%    \begin{macrocode}
\newcount\mm@charcode
\newcount\mm@charclass
\newcount\mm@charfam
\newcount\mm@charslot

\newcommand*\math@family[2]{%
    \mm@charfam=#2
    \ifluatex
        \mm@charclass=\Umathcharclass`#1
        %\mm@charfam=\Umathcharfam`#1
        \mm@charslot=\Umathcharslot`#1
        \Umathcode`#1= \mm@charclass \mm@charfam \mm@charslot
    \else
        \mm@charcode=\mathcode`#1
        % extract charclass
        \@tempcnta=\mm@charcode
        \divide\@tempcnta by "1000
        \multiply\@tempcnta by "1000 % charclass
        \mm@charclass=\@tempcnta
        % extract charslot
        \@tempcnta=\mm@charcode
        \@tempcntb=\mm@charcode
        \divide\@tempcnta by "100
        \multiply\@tempcnta by "100 % charclass + charfam
        \advance\@tempcntb by -\@tempcnta % charslot
        \mm@charslot=\@tempcntb
        % construct charcode
        \mm@charcode=\mm@charclass
        \multiply\mm@charfam by "100
        \advance\mm@charcode by \mm@charfam
        \advance\mm@charcode by \mm@charslot
        \mathcode`#1=\mm@charcode
    \fi
}

\newcommand*\MathFamily[2]{%
    \ifx\@onlypreamble\@notprerr
        \math@family{#1}{#2}
    \else % before \begin{document}
        \AtBeginDocument{\math@family{#1}{#2}}
    \fi
}

\newcommand*\MathUp[1]{\MathFamily{#1}{0}}
\newcommand*\MathIt[1]{\MathFamily{#1}{1}}

%    \end{macrocode}
% On the same model we could also create some other macros to set any letter
% in bold or sans serif, but unfortunately there is no family number associated by default
% to these typefaces. It depends on the font package that is loaded and
% it can also depend on which |\DeclareSymbolFont| is used.
%
% \medskip
% In complement to |\MathUp| and |\MathIt|, we provide the two following commands
% to set in roman a group of letters among `e, i, j' for mathematical constants
% or `P, E, V' for probability operators.
%
% \medskip
%    \begin{macrocode}
\newcommand*\MathNumbers[1]{%
    \in@{e}{#1} \ifin@ \MathUp{e} \fi
    \in@{i}{#1} \ifin@ \MathUp{i} \fi
    \in@{j}{#1} \ifin@ \MathUp{j} \fi
}

\newcommand*\MathProba[1]{%
    \in@{P}{#1} \ifin@ \MathUp{P} \fi
    \in@{E}{#1} \ifin@ \MathUp{E} \fi
    \in@{V}{#1} \ifin@ \MathUp{V} \fi
}

%    \end{macrocode}
% \DescribeMacro{\apply}
% The inverse global switch |\MathNormal| acts on any comma separated list 
% thanks to the |\apply| macro which works as follows:
% |\apply\macro{comma,list}| expands to |\macro{comma}\macro{list}|.
% We could also use |\apply\MathUp{e,i,j}| instead of |\MathNumbers{e,i,j}|.
% I found this macro on Tex RSSing.com by searching 
% ``TeX How to iterate over a comma separated list?''
% The answer was given by ``wipet'' on 2021/02/26.
% I don't know who is wipet but I thank him for this powerful macro!
% Unfortunately usual loop instructions like |\@for| or |\foreach| do not work
% and produce the error message ``!~Improper alphabetic constant''.
% Indeed |\def\letter{A} \MathUp{\letter}| fails,
% the control sequence |\letter| is not considered as the single character `A'.
%
% \medskip
%    \begin{macrocode}
\def\apply#1#2{\apply@#1#2,\apply@,}
\def\apply@#1#2,{\ifx\apply@#2\empty
    \else #1{#2}\afterfi@{\apply@#1}\fi}
\def\afterfi@#1#2\fi{\fi#1}

\newcommand*\MathNormal[1]{% list argument
    \apply\MathIt{#1} 
}

%    \end{macrocode}
%
% The following commands are deprecated but still work.
% They were intended to set some letters in upright shape by default
% in math mode, but worked only in the preamble.
% This is now managed by the more powerful |\MathUp| command.
% The old commands are maintained for now for compatibility reasons.
% \medskip
%
%    \begin{macrocode}
\newcommand{\enumber}{%
    \PackageWarning{mismath}{Command \string\enumber\space
        is deprecated, \MessageBreak
        use \bslash MathUp{e} instead}
    \MathUp{e}
}
\newcommand{\inumber}{%
    \PackageWarning{mismath}{Command \string\inumber\space
        is deprecated, \MessageBreak
        use \bslash MathUp{i} instead}
    \MathUp{i}
}    
\newcommand{\jnumber}{
    \PackageWarning{mismath}{Command \string\jnumber\space
        is deprecated, \MessageBreak
        use \bslash MathUp{j} instead}
    \MathUp{j}
}   
\newcommand{\PEupright}{
    \PackageWarning{mismath}{Command \string\PEupright\space
        is deprecated, \MessageBreak
        use \bslash MathUp{P} and \bslash MathUp{R} instead}
    \MathUp{P}\MathUp{E}
}

%    \end{macrocode}
%
% The Greek letter pi must be managed in a different way. The switches are called
% |\pinumber| and |\pinormal|.
% When given without argument, |\pinumber| uses the LGR font encoding.
% A particularity of the \textsf{fontenc} package is that it can be loaded 
% several times with different options without ``option clash'' error.
% \medskip
%    \begin{macrocode}
\newcommand*\pinumber[1][]{
    \@ifundefined{itpi}{\let\itpi\pi}{}
    \ifthenelse{\equal{#1}{}}{
      \ifx\@onlypreamble\@notprerr
        \@ifundefined{savedpi}{
            \PackageWarning{mismath}{%
                \bslash pinumber without argument\MessageBreak
                must be used in the preamble first\MessageBreak
                to load LGR fontenc for upright pi}
        }{\let\pi\savedpi}
      \else % in the preamble
        \RequirePackage[LGR,T1]{fontenc}
        \DeclareSymbolFont{UpGr}{LGR}{lmr}{m}{n}
        \let\pi\relax
        \DeclareMathSymbol{\pi}\mathalpha{UpGr}{"70}
        \let\savedpi\pi
      \fi
    }{
        \@ifundefined{#1}{
            \PackageWarning{mismath}{%
                Value #1 must be a valid
                command name\MessageBreak for pinumber,
                but command \bslash #1\space
                is undefined.\MessageBreak
                Perhaps a missing package}
        }{\renewcommand{\pi}{%
            \csname #1\endcsname}
        }
    }
} 

\newcommand{\pinormal}{\@ifundefined{itpi}{}{\let\pi\itpi}}

%    \end{macrocode}
%
% And now the commands for vectors (and tensors).
% \medskip
%    \begin{macrocode}
\newboolean{arrowvect}
\setboolean{arrowvect}{true}
\newcommand{\arrowvect}{\setboolean{arrowvect}{true}} 
\newcommand{\boldvect}{\setboolean{arrowvect}{false}}
\newcommand{\boldvectcommand}{\boldsymbol} % from amsbsy package
\mm@macro{vect}{\ifthenelse{\boolean{arrowvect}}{
        \vv}{\boldvectcommand}} % doesn't work well with \if... \fi
\newcommand*{\hvect}[1]{\vect{\vphantom{t}#1}}
\newcommand*{\hvec}[1]{\vec{\vphantom{t}#1}}

\newcommand*{\@norm}[1]{
    \mbox{\raisebox{1.75pt}{\small$\bigl\Vert$}} #1
    \mbox{\raisebox{1.75pt}{\small$\bigr\Vert$}} }
% works better than with relative length
\newcommand*{\@@norm}[1]{
    \mbox{\footnotesize\raisebox{1pt}{$\Vert$}} #1
    \mbox{\footnotesize\raisebox{1pt}{$\Vert$}} }
\newcommand*{\@@@norm}[1]{
    \mbox{\tiny\raisebox{1pt}{$\Vert$}} #1
    \mbox{\tiny\raisebox{1pt}{$\Vert$}} }
\@ifundefined{norm}{\providecommand*{\norm}[1]{
        \mathchoice{\@norm{#1}}{\@norm{#1}}{\@@norm{#1}}{\@@@norm{#1}} 
        }
    }{\mm@warning{norm} } % bad result with libertinust1math

\DeclareMathAlphabet{\mathbfsfit}{\encodingdefault}{\sfdefault}{bx}{it}
\newcommand{\tensor}{\mathbfsfit} % isomath uses \mathsfbfit

%    \end{macrocode}
%
% And now all the other commands.
% \medskip
%    \begin{macrocode}
\mm@macro{di}{\mathop{}\!\mathup{d}}
\newcommand\probastyle{}
\let\Par\P % end of paragraph symbol
\renewcommand{\P}{\operatorname{\probastyle{P}}}
\mm@macro{E}{\operatorname{\probastyle{E}}}
\mm@macro{V}{\operatorname{\probastyle{V}}}

\mm@operator{\adj}{adj}
\mm@operator{\Aut}{Aut}
\mm@operator{\codim}{codim}
\mm@operator{\Conv}{Conv}
\mm@operator{\cov}{cov}
\mm@operator{\Cov}{Cov}
\mm@macro{curl}{\operatorname{\vect{\mathup{curl}}}}
\mm@operator[divg]{\divg}{div}
\mm@operator{\End}{End}

\mm@operator{\erf}{erf}
\mm@macro{grad}{\operatorname{\vect{\mathup{grad}}}}
\mm@operator{\id}{id} % mathop or mathord ?
\mm@operator{\Id}{Id}
\mm@operator{\im}{im}
\let\oldIm\Im \renewcommand{\Im}{\operatorname{Im}}
\mm@operator{\lb}{lb}
\mm@operator{\lcm}{lcm}

\mm@operator{\rank}{rank}
\let\oldRe\Re \renewcommand{\Re}{\operatorname{Re}}
\mm@macro{rot}{\operatorname{\vect{\mathup{rot}}}}
\mm@operator{\sgn}{sgn}
\mm@operator{\sinc}{sinc}
\mm@operator[spa]{\spa}{span}
\mm@operator{\tr}{tr}
\mm@operator{\var}{var}
\mm@operator{\Var}{Var}
\mm@operator[Zu]{\Zu}{Z}

\mm@operator{\arccot}{arccot}
\mm@operator{\sech}{sech}
\mm@operator{\csch}{csch}
\mm@operator{\arsinh}{arsinh}
\mm@operator{\arcosh}{arcosh}
\mm@operator{\artanh}{artanh}
\mm@operator{\arcoth}{arcoth}
\mm@operator{\arsech}{arsech}
\mm@operator{\arcsch}{arcsch}

\mm@operator[bigO]{\bigO}{\mathcal{O}}
\mm@operator[bigo]{\bigo}{O}
\mm@operator[lito]{\lito}{o}

\mm@macro{mathset}{\mathbf}
\mm@macro{R}{\mathset{R}}
\@ifpackagewith{babel}{russian}{
    \PackageWarningNoLine{mismath}{Option russian of babel
    is loaded\MessageBreak    
    Command \bslash C will not be redefined}
    }{\mm@macro{C}{\mathset{C}}}
\mm@macro{N}{\mathset{N}}
\mm@macro{Z}{\mathset{Z}}
\mm@macro{Q}{\mathset{Q}}
\mm@macro{F}{\mathset{F}}
\mm@macro{K}{\mathset{K}}

\mm@macro{ds}{\displaystyle}
\mm@macro{dlim}{\lim\limits}
\mm@macro{dsum}{\sum\limits}
\mm@macro{dprod}{\prod\limits}
\mm@macro{dcup}{\bigcup\limits}
\mm@macro{dcap}{\bigcap\limits}

\mm@macro{lbar}{\overline}
\@ifundefined{hlbar}{
    \providecommand*{\hlbar}[1]{\overline{\vphantom{t}#1}}}{
    \mm@warning{hlbar} }
\newcommand\@eqdef{\stackrel{\mathup{def}}{=}}
\newcommand\@@eqdef{\stackrel{\mathrm{\Delta}}{=}}
\mm@macro{eqdef}{\@ifstar{\@@eqdef}{\@eqdef}}
\mm@macro{unbr}{\underbrace}
\mm@macro{iif}{if and only if\xspace}

%    \end{macrocode}
% We used |\mathurm| before |\Delta| in the case of defining capital Greek letters
% in italic (for example with the \textsf{fixmath} package).
% Without |\mbox{}|, space produced by |\| in macro |\then| would be suppressed in tables.
% \medskip
%    \begin{macrocode}
\mm@macro{then}{\ \Longrightarrow \ \mbox{} } 
\@ifundefined{txt}{
    \providecommand*{\txt}[1]{\quad\text{#1}\quad} }{
    \mm@warning{txt} }
\mm@macro{mul}{\mathord{\times}}
\@ifundefined{pow}{
    \providecommand*{\pow}[2]{\left( #1 \right)^{\!#2}} }{
    \mm@warning{pow} }
\@ifundefined{abs}{
    \providecommand*{\abs}[1]{\left\vert#1\right\vert} }{
    \mm@warning{abs} }
\@ifundefined{lfrac}{
    \providecommand*{\lfrac}[2]{\frac{\;#1\;}{\;#2\;}} }{
    \mm@warning{lfrac} }

\newcommand{\systemstretch}{1.2}
\newcommand{\systemsep}{\medspace}
\newenvironment{system}[1][l]{
    \renewcommand{\arraystretch}{\systemstretch}
    \setlength{\arraycolsep}{0.15em}
    \left\{\begin{array}{@{\systemsep}#1@{}} %
}{\end{array}\right.}

\newenvironment{spmatrix}{
    \left(\begin{smallmatrix}
}{\end{smallmatrix}\right)}

\newenvironment{mathcols}{% needs multicol package
    \renewcommand{\columnseprule}{0.1pt}
    \begin{multicols}{2}
        \par\noindent\hfill
        \begin{math}\begin{aligned}\displaystyle
}{%
        \end{aligned}\end{math} \hfill\mbox{}
    \end{multicols}
}
\newcommand{\changecol}{%
    \end{aligned}\end{math} \hfill\mbox{}
    \par\noindent\hfill
    \begin{math}\begin{aligned}\displaystyle 
}   
%    \end{macrocode}
% \bigskip
% \begin{thebibliography}{24}
% \begin{raggedright}
% \bibitem{TYPMA} \emph{Typesetting mathematics for science and technology according 
% to ISO 31/XI}, Claudio Beccari, TUGboat Volume 18 (1997), No.~1.
% \url{http://www.tug.org/TUGboat/tb18-1/tb54becc.pdf}.
% \bibitem{NIST} \emph{Typefaces for Symbols in Scientific Manuscripts},
% \url{https://www.physics.nist.gov/cuu/pdf/typefaces.pdf}.
% \bibitem{SI} \emph{Guide for the Use of the International System of Units (SI)},
% NIST (National Institute of Standards and Technology), updated March 4, 2020 
% \url{https://www.nist.gov/pml/special-publication-811}.
% \bibitem{ICTNS} \emph{On the Use of Italic and up Fonts for Symbols in Scientific Text},
% I.M.~Mills and W.V.~Metanomski, ICTNS (Interdivisional Committee 
% on Terminology, Nomenclature and Symbols), dec 1999,
% \url{https://old.iupac.org/standing/idcns/italic-roman_dec99.pdf}.
% \bibitem{VECT} \emph{\textsf{esvect}  -- Typesetting vectors with beautiful 
% arrow with \LaTeXe}, Eddie Saudrais, CTAN, v1.3 2013/07/11.
% \bibitem{AMS} \emph{\textsf{amsmath} -- \AmS\ mathmatical facilities for \LaTeX},
% Frank Mittelbach, Rainer Schöpf, Michael Downes, Davis M.~Jones, David Carlisle, 
% CTAN, v2.17n 2022/04/08.
% \bibitem{TOOL} \emph{The \textsf{mathtools} package}, Morten Høgholm, Lars Madsen, CTAN,
% v1.29 2022/06/29.
% \bibitem{FIXM} \emph{The \textsf{fixmath} package for \LaTeXe}, Walter Schmidt, 
% CTAN, v0.9 2000/04/11.
% \bibitem{ISOM} \emph{\textsf{isomath} -- Mathematical style for science and technology}.
% Günter Milde, CTAN, v0.6.1 2012/09/04.
% \bibitem{PMISO} \emph{\textsf{PM-ISOmath}, The Poor Man ISO math bundle}, 
% the \textsf{pm-isomath} package by Claudio Beccari, CTAN, v1.2.00 2021/08/04.
% \bibitem{GREEK} \emph{The \textsf{upgreek} package for \LaTeXe}, Walter Schmidt,
% CTAN, v2.0 2003/02/12.
% \bibitem{DESIGN} \emph{The \textsf{mathdesign} package},
% Paul Pichaureau, CTAN, v2.31 2013/08/29.
% \bibitem{ALPHA} \emph{The \textsf{textalpha} package}
% (part of the \textsf{greek-fontenc} bundle), Günter Milde, CTAN, v2.1 14/06/2022.
% \bibitem{KPF} \emph{\textsf{Kp-Fonts} -- The Johannes Kepler project},
% Christophe Caignaert, CTAN, v3.34 20/09/2022.
% \bibitem{FOUR} \textsf{Fourier-GUT\hspace{-0.1em}\emph{enberg}},
% Michel Bovani, CTAN, v1.3 30/01/2005.
% \bibitem{LGR} \emph{The \textsf{lgrmath} package}, Jean-François B., CTAN, v1.0 2022/11/16.
% \bibitem{INT} \emph{The \textsf{interval} package}. Lars Madsen, CTAN,
% v0.4 2019/03/06.
% \bibitem{SYST} \emph{L'extension pour \TeX\ et \LaTeX\ \textsf{systeme}},
% Christian Tellechea, CTAN v0.32 2019/01/13.
% \bibitem{SPAL} \emph{The \textsf{spalign} package}, Joseph Rabinoff, CTAN, 2016/10/05.
% \bibitem{NMATX} \emph{The package \textsf{nicematrix}}, François Pantigny, CTAN,
% v6.14 2023/02/18.
% \bibitem{FR} \emph{L'extension \textsf{frenchmath}}, Antoine Missier, CTAN, v2.5 2023/02/24.
% \bibitem{BRACKET} \emph{Intelligent brackets -- The \textsf{ibrackets} package}
% Antoine Missier, CTAN, v1.1, 2022/12/26.
% \bibitem{LSHORT} \emph{The Not So Short Introduction to \LaTeXe}, 
% the \textsf{lshort} package by
% Tobias Oetiker, Hubert Partl, Irene Hyna and Elisabeth Schlegl, CTAN, v6.4 2021/04/09.
% \url{http://tug.ctan.org/info/lshort/english/lshort.pdf}.
% \bibitem{COMP} \emph{The \LaTeX\ Companion}, Frank Mittelbach, Michel Goossens, 
% Johannes Braams, David Carlisle, Chris Rowley, 2nd edition, Pearson Education, 2004.
% \end{raggedright}
% \end{thebibliography}

% \Finale
\endinput
