% \iffalse  meta-comment
%
% mattens.dtx
% Copyright (C) 2001--2022 Danie Els
%
% -------------------------------------------------------------------
%                     The mattens package
%                 for vector/tensor typesetting
% -------------------------------------------------------------------
% This work may be distributed and/or modified under the conditions
% of the LaTeX Project Public License, either version 1.3c 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.3c or later is part of all distributions of LaTeX
% version 2005/12/01 or later.
%
% This work has the LPPL maintenance status 'maintained'.
%
% This Current Maintainer of this work is Danie Els (dnjels@gmail.com)
%
% This package consists of the files: mattens.dtx
%                                     mattens.ins
%              and the derived files: mattens.sty
% -------------------------------------------------------------------
%
% \fi
%
% \iffalse
%<*driver>
\documentclass[a4paper,notitlepage]{ltxdoc}
    \makeatletter
    \newcommand{\DeclareSBox}[2]{%
        \@ifdefinable{#1}{%
            \edef\tempa{\expandafter\@gobble\string#1}%
            \edef\tempa{\csname MTbox@\tempa\endcsname}%
            \expandafter\newbox\tempa
            \global\sbox{\tempa}{#2}%
            \protected@xdef#1{\noexpand\usebox{\tempa}}}}
\usepackage{amsmath}
\usepackage{amsfonts}
    \DeclareMathSymbol{\square}{\mathord}{AMSa}{"03}
    \newcommand*{\m}{\raisebox{.1ex}{$\scriptscriptstyle\square$}}
    \DeclareMathAlphabet{\mathsfsl}{OT1}{cmss}{m}{sl}
\usepackage{color}
      % Declare the following saved box before
      % the accents and bm packages are loaded
    \DeclareSBox{\AccentBox}{$\dot{\overline{f}}^a_b$}
\usepackage{array}
\usepackage{enumitem}
    \setlist{itemsep=\smallskipamount, parsep=0pt}
\usepackage{accents}
    \newcommand{\dotr}[1]{\accentset{\phantom{r}{\displaystyle.}r}{#1}}
\usepackage{mattens}
\usepackage{bm}
    \bmdefine{\bO}{\mathit{\Omega}}

    \newcommand*{\pkg}[1]{\textsf{#1}}
    \newcommand*{\opt}[1]{\textsf{#1}}
    \newcommand*{\MT}{\pkg{mattens}}
    \newcommand*{\Hass}{Hassenpflug}
    \newcommand*{\myemph}[1]{\emph{#1}}
    \newenvironment{Decl}[1][l]%
         {\par\small\addvspace{2.3ex plus 1ex}%
          \vskip -\parskip
          \noindent\hspace{\leftmargini}%
          \begin{tabular}{|#1|}\hline\ignorespaces}%
         {\\\hline\end{tabular}\nobreak\par\nobreak
          \vspace{2.3ex}\vskip -\parskip}
    \newenvironment{Indent}[1]{%
        \begin{list}{}{%
            \setlength{\topsep}{0pt}%
            \setlength{\leftmargin}{#1}%
            \setlength{\listparindent}{\parindent}%
            \setlength{\itemindent}{\parindent}%
            \setlength{\parsep}{\parskip}}%
            \item[]
        }{\end{list}}
    \newenvironment{sample}{%
        \begin{quote}\small\begin{tabbing}%
                \hskip12pc\=\kill}%
        {\end{tabbing}\end{quote}}
    \newcommand*{\sphline}{%     horizontal table line with spaces
        \noalign{\vskip3pt}\hline\noalign{\vskip3pt}}
    \newcommand*{\tdot}{\ensuremath{\cdot}}
    \newcommand*{\trnsp}{\ensuremath{\mathsf{T}}}
    \newcommand*{\norm}[1]{\ensuremath{\lVert{#1}\rVert}}
    \newcommand*{\SB}[1]{\ensuremath{\left[\, #1\right]}}

    \MakeShortVerb{\|}
    \EnableCrossrefs
   %\DisableCrossrefs      % Say \DisableCrossrefs if index is ready
    \CodelineIndex
    \RecordChanges         % Gather update information
   %\OnlyDescription       % comment out for implementation details
    \setlength\hfuzz{15pt} % dont make so many
    \hbadness=7000         % over and under full box warnings
    \makeatother
\begin{document}
   \DocInput{mattens.dtx}
\end{document}
%</driver>
%
% \fi
%
% \CheckSum{0}
%% \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         \~}
%%
%
% \DoNotIndex{\,, \@empty, \@gobble, \@ifnextchar, \@ifstar,
%             \@ifundefined, \@firstofone}
% \DoNotIndex{\addtolength}
% \DoNotIndex{\begingroup, \boldsymbol, \box}
% \DoNotIndex{\copy, \csname, \CurrentOption}
% \DoNotIndex{\DeclareOption, \DeclareRobustCommand, \def, \dp}
% \DoNotIndex{\edef, \else, \endcsname, \endgroup, \ensuremath,
%             \expandafter}
% \DoNotIndex{\fi}
% \DoNotIndex{\global}
% \DoNotIndex{\hskip, \ht}
% \DoNotIndex{\ifdim, \ifx}
% \DoNotIndex{\leavevmode, \left, \let, \lVert}
% \DoNotIndex{\m@th, \mathpalette, \mathsf, \mathstrut, \mskip}
% \DoNotIndex{\NeedsTeXFormat, \newbox, \newcommand, \newif, \newlength,
%             \newmuskip, \newsavebox, \null}
% \DoNotIndex{\overline}
% \DoNotIndex{\PackageError, \PackageWarning, \ProcessOptions, \protect,
%             \protected@xdef, \providecommand, \ProvidesPackage}
% \DoNotIndex{\relax, \renewcommand, \RequirePackage, \right, \rlap,
%             \rVert}
% \DoNotIndex{\sbox, \setbox, \setlength, \space, \string}
% \DoNotIndex{\the}
% \DoNotIndex{\underline, \usebox, \wd, \widetilde}
% \DoNotIndex{\z@}
%
% \changes{1.0}{2001 Dec 9}{Initial version}
% \changes{1.1}{2004 Jan 15}{Doc: Updated}
% \changes{1.3}{2009 Sep 1}{Doc: Updated}
% \changes{1.3b}{2022 Mar 1}{Doc: Updated}
%
%
% \GetFileInfo{mattens.sty}
%
%
% \title{The \MT\ package\thanks{This file has version number
%                               \fileversion, last revised
%                               \filedate.}}
% \author{Danie Els}
% \date{\filedate}
% \maketitle
%
%
% \section{Introduction}
%
% \subsection{Background}
%
% A browse through journals and handbooks, in particular those concerned with
% dynamics, reveals an amazing array of private notations for vectors and
% tensors. Every author has his or her own notation, making it very difficult
% to comprehend what is going on in complex multi reference axes environments.
%
% The \MT\ package contains the definitions to typeset vectors and
% tensors such as $\aS{e}_i$, $\bS[\dot]{x}^r$, $\bSb{E}^s_r$, etc., for the
% representation of common vectors and tensors such as forces, velocities,
% moments of inertia, etc. It is based on the well defined notation of
% \Hass\cite{Hass93a,Hass93b}. It was developed and over many years of
%  teaching engineering:
% \begin{quote}\slshape
%     ``It is designed particulary to distinguish between vectors and tensors
%     and their representation as vectors and matrices in different coordinate
%     systems. The main purpose of this notation is that it can be used in the
%     teaching situation, therefore, it conveys all the information explicitly
%     in the symbols, and it can be used in handwriting.''
% \end{quote}
%
% \noindent \Hass\cite{Hass93a} identifies the following list of requirements
% for a good notation for tensor quantities and operations, to which his
% notation conforms. A notation must:
% \begin{itemize}
%     \item Be easily written by hand;
%     \item Distinguish between vector and scalar quantities;
%     \item Distinguish between (second order) tensors and vectors;
%     \item Distinguish between physical vectors and their representation
%         by vector arrays, and between physical (second order) tensors and
%         their representation by matrices;
%     \item Distinguish between row and column vectors;
%     \item Use the same symbol as name for the same vector or tensor in
%         either its physical sense or its representation by a vector array
%         or matrix in different coordinate axes;
%     \item Distinguish between matrix/vector representation of the same
%         vector/tensor in different coordinate axes;
%     \item Be equally valid in orthonormal and skew coordinate axes;
%     \item Indicate all intended operations uniquely;
%     \item Be equally valid in all dimensions;
%     \item Be equally valid for algebraic vector/matrix algebra which has
%         no connection to any metric space;
%     \item Be applicable to differentials;
%     \item Allow for defaults to avoid repetitive elaborate symbols, i.e.,
%         not all the symbols need to be written down explicitly if it is
%         clear from the context.
%     \item It must be well documented (own addition).
% \end{itemize}
%
% \noindent The \MT\ package was developed to typeset the \Hass{} matrix
% tensor symbols in a consistent manner.
%
% \subsection{Why the \MT\ package?}
%
% The \Hass{} notation contains symbols such as, $\aS{e}_i$,
% $\bS[\dot]{x}^{r}_{\alpha}$, $\bSa[\dot]{E}^s$, etc. These symbols
% are quite common and variants thereof are found on many
% blackboards of engineering schools. Based on the reputation of
% \TeX{} it would seem trivial to typeset them, but to the contrary
% ...
% \SetSymbFont{\relax}
% \begin{sample}
%     |$\bS[\dot]{f}^a_b$|         \> $\bS[\dot]{f}^a_b$ ~~~(correct typesetting)\\[.75ex]
%     |$\dot{\overline{f}}^a_b$|   \> \AccentBox\\[.75ex]
%     |$\dot{\overline{f}}{}^a_b$| \> $\dot{\overline{f}}{}^a_b$\\[.75ex]
%     |$\dot{\overline{f}^a_b}$|   \> $\dot{\overline{f}^a_b}$
% \end{sample}
% \SetSymbFont{\bm}
%
% \section{Usage of \MT\ package}
%
% The \MT\ package is loaded in the document preamble with:
% \begin{sample}
% \cmd{\usepackage}\oarg{options}|{mattens}| 
% \end{sample}
%
% \noindent When \MT\ is loaded, the \pkg{amsmath} package is loaded
% automatically, because it is needed for the redefined \cmd{\overrightarrow}
% and \cmd{\underrightarrow} commands, as well as the \cmd{\boldsymbol}
% command. It must be loaded before any font packages that redefine some of the
% \pkg{amsmath} symbols or commands. 

% \AmS{} recommends the \pkg{bm} package instead of the \cmd{\boldsymbol} 
% command for bold italic math symbols\footnote{The \cmd{\boldsymbol} puts 
% its contents in a box,
% \cmd{\mbox\{}\cmd{\boldmath\$}\meta{contents}\texttt{\$\}}, 
% while \cmd{\bm} is a font changing command that uses the appropriate 
% bold math font.}. The \pkg{bm} package reroutes the
% \cmd{\boldsymbol} command to point to \cmd{\bm}. If \cmd{\boldsymbol} is
% called after the \pkg{bm} package is loaded, it is equivalent to \cmd{\bm}.
% If the \pkg{bm} package is not loaded, \MT\ defaults to the \cmd{\boldsymbol}
% command.
%
% The \MT\ package by default sets bold italics symbols. This choice stems from
% the ISO standards for typesetting of vectors and tensors. The formatting of
% symbols then indicates the fact that it is a vector/tensor and the lines,
% arrows and sub- and superscripts indicate the specific type and reference
% axes.
% \pagebreak[2]
%
% \noindent The following options are recognized by \MT:
%
% \begin{description}
%     \item[\normalfont\opt{noformat}:]  No symbol formatting is performed,
%         otherwise symbols are set by default in bold italics with the
%         \cmd{\boldsymbol} command.
%
%         It is important to note that the \Hass{} requirement of easily
%         written by hand is not fulfilled if the symbols are formatted
%         by anything else than normal math fonts.
%
%     \item[\normalfont\opt{mathstrut}:] A mathstrut is inserted with the
%         symbol to force all the lines and arrows to the same height and
%         depth. The default is no mathstrut.
% \end{description}
%
%  \section{List of \MT\ commands}
%
% \begin{table}[htbp]
%     \caption{List of Matrix Tensor typing commands} \label{tab:1}
%     \small
%     \renewcommand{\footnoterule}{}
%     \begin{tabular}{@{}ll>{\itshape}r@{}>{\itshape}c@{}>{\itshape}lc@{}}
%         \sphline
%         \bfseries  Type   &
%         \bfseries Command &
%         \multicolumn{3}{c}{\bfseries  Description} &
%         \bfseries  Output
%         \\
%         \sphline
%
%         Physical column vector&
%         \cmd{\aS}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{aS}  &
%         arrow--&Symbol&       &
%         $\aS{x}$
%         \\[1.0ex]
%
%         Physical row vector   &
%         \cmd{\Sa}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{Sa}  &
%         &Symbol&--arrow&
%         $\Sa{x}$
%         \\[1.0ex]
%
%         Column vector         &
%         \cmd{\bS}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{bS}  &
%         bar--&Symbol&       &
%         $\bS{x}$
%         \\[1.0ex]
%
%         Row vector            &
%         \cmd{\Sb}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{Sb}  &
%         &Symbol&--bar  &
%         $\Sb{x}$
%         \\[1.0ex]
%
%         Physical tensor       &
%         \cmd{\aSa}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{aSa}&
%         arrow--&Symbol&--arrow&
%         $\aSa{E}$
%         \\[1.0ex]
%
%         Tensor (mixed base)   &
%         \cmd{\aSb}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{aSb}&
%         arrow--&Symbol&--bar  &
%         $\aSb{E}$
%         \\[1.0ex]
%
%         Tensor (mixed base)   &
%         \cmd{\bSa}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{bSa}&
%         bar--&Symbol&--arrow&
%         $\bSa{E}$
%         \\[1.0ex]
%
%         Tensor                &
%         \cmd{\bSb}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{bSb}&
%         bar--&Symbol&--bar  &
%         $\bSb{E}$
%         \\[1.0ex]
%
%         Cross-product tensor$^\dag$   &
%         \cmd{\aCSa}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{aCSa}&
%         arrow--C&Symbol&--arrow&
%         $\aCSa{w}$
%         \\[1.0ex]
%
%         Cross-product tensor  &
%         \cmd{\bCSb}\oarg{accent}\marg{Symbol}\SpecialUsageIndex{bCSb}&
%         bar--C&Symbol&--bar  &
%         $\bCSb{w}$
%         \\[1.0ex]
%
%         \sphline
%         \multicolumn{5}{@{}l}{\footnotesize$^\dag$~
%             It is defined as the tensor  $\bCSb{a}$ associated with the
%             vector $\bS{a}$, where $\bS{a}\times\bS{c}=\bCSb{a}\cdot\bS{c}$}
%  \end{tabular}
%  \end{table}
%
% \subsection{General syntax}
%
% The general syntax of the \MT\ commands is
% \begin{Decl}[ll]
%     |\|\m|S|\,\oarg{accent}\marg{Symbol} & 
%     |\|\m|S|\,|*|\oarg{accent}\marg{Symbol} \\
%     |\S|\m\,\oarg{accent}\marg{Symbol} & 
%     |\S|\m\,|*|\oarg{accent}\marg{Symbol} \\[1ex]
%
%     |\|\m|S|\m\,\oarg{accent}\marg{Symbol} & 
%     |\|\m|S|\m\,|*|\oarg{accent}\marg{Symbol}\\[1ex]
%
%     |\|\m|CS|\m\,\oarg{accent}\marg{Symbol}    &
%     |\|\m|CS|\m\,|*|\oarg{accent}\marg{Symbol}
% \end{Decl}
% The ``starred'' form is used to set the symbol in normal math.
% This can be used for compound tensors or for pre-declared symbols (see
% \pkg{bm} documentation). An example of the usage is
% \begin{sample}
%     \hskip4pc\=\hskip8pc\=\hskip2pc\=\kill^^A
%     \cmd{\aS}|{e}|  \> \cmd{\aS*}|{e}|   \> $\aS{e}$  \> $\aS*{e}$\\[0.75ex]
%     \cmd{\Sb}|{x}|  \> \cmd{\Sb*}|{x}|   \> $\Sb{x}$  \> $\Sb*{x}$\\[0.75ex]
%     \cmd{\aCSa}|{z}|\> \cmd{\aCSa*}|{z}| \> $\aCSa{z}$\> $\aCSa*{z}$
% \end{sample}
%
% The optional argument \meta{accent} is intended for \LaTeX{} 
% accent commands % such as $\cmd{\dot}$, $\cmd{\ddot}$, etc., or 
% their $\AmS$ equivalents, $\cmd{\Dot}$, $\cmd{\Ddot}$.
% \begin{sample}
%     |\bS[\Ddot]{x}| \> $\bS[\Ddot]{x}$
% \end{sample}
%
% The \MT\ commands look ahead for sub- and superscripts (including primes) in
% order to place them at the correct horizontal and vertical positions.
% \begin{sample}
%     \cmd{\bS}|[|\cmd{\Dot}|]{x}^s_i|  \> $\bS[\Dot]{x}^s_i$  \\[1ex]
%     \cmd{\bS}|[|\cmd{\Ddot}|]{x}_i^s| \> $\bS[\Ddot]{x}_i^s$ \\[1ex]
%     \cmd{\bS}|{x}''^s_i|              \> $\bS{x}''^s_i$      \\[1ex]
%     \cmd{\bSa}|{E}^k|                 \> $\bSa{E}^k$         \\[1ex]
%     \cmd{\aSb}|[|\cmd{\Dot}|]{E}_s|   \> $\aSb[\Dot]{E}_s$
% \end{sample}
%
% The commands are also robust and can be used in moving commands such as
% footnotes\footnote{A vector $\aS{e}_i$ in a footnote}, headers, etc.
% \begin{sample}
%     |\footnote{A vector $\aS{e}_i$ in a footnote}|
% \end{sample}
%
% The symbols scale to the appropriate sizes if used in sub- and superscripts.
% For example, for an integration path parameterized by the vector
% $\bS{r}^s(\xi)$, the equation for a line integral
% \begin{verbatim}
%     \begin{equation*}
%         \oint\limits_{\bS{r}^s(\xi)}  \dotsi
%     \end{equation*}
% \end{verbatim}
% gives
% \begin{equation*}
% \oint\limits_{\bS{r}^s(\xi)} \dotsi
% \end{equation*}
% \bigskip
%
% ^^A\clearpage
% \section{Symbol formatting commands}
% \subsection{Bold italic symbols}
%
% The symbol format can be set with the package options
% \begin{sample}
%     \hskip14pc\=\kill
%     |\usepackage{mattens}|             \>|% Uses \boldsymbol as default|
% \end{sample}
% or
% \begin{sample}
%     \hskip14pc\=\kill
%     |\usepackage[noformat]{mattens}|   \>|% No symbol formatting|
% \end{sample}
% or anywhere in the document with the command
% \begin{Decl}
%    \cmd{\SetSymbFont}\marg{font-command}^^A
%    \SpecialUsageIndex{\SetSymbFont}
% \end{Decl}
%
% \pagebreak[2]
% \noindent In general a typical setup to include unicode math
% \begin{sample}
% |\usepackage{ifxetex}       |\\
% |\ifxetex                   |\\
% |    ... Unicode-math and font selection ...|\\
% |    \SetSymbFont{\symbfit} |\\
% |\else                      |\\
% |    ... Font selection ... |\\
% |    \usepackage{bm}        |\\
% |    \SetSymbFont{\bm}      |\\
% |\fi                        |
% \end{sample}
%
%
% \noindent If the symbols are interpreted as tensors, then according to the ISO, it can
% be typeset in a slanted sans serif font (if you are fond of fonts).  For the
% Computer Modern fonts with an \texttt{OT1} encoding, you can put in the
% preamble
% \begin{quote}
%     |\DeclareMathAlphabet{\mathsfsl}{OT1}{cmss}{m}{sl}|
% \end{quote}
% Examples of formats are
% \begin{sample}
%     |\SetSymbFont{\bm}|       \>\SetSymbFont{\bm}$\aSb{E}_s$\\[1ex]
%     |\SetSymbFont{\relax}|    \>\SetSymbFont{\relax}$\aSb{E}_s$\\[1ex]
%     |\SetSymbFont{\mathsfsl}| \>\SetSymbFont{\mathsfsl}$\aSb{E}_s$
% \end{sample}
% \SetSymbFont{\bm}
%
% Only the first symbol (or group) in multi-symbol constructions is formatted.
% This can be used to obtain
% \begin{sample}
%     |\bS{{}xy}| ~|\bS*{xy}| \> $\bS{{}xy}$ ~ $\bS*{xy}$\\
%     |\bS{xy}|   \> $\bS{xy}$ \\
%     |\bS{{xy}}| \> $\bS{{xy}}$
% \end{sample}
% or
% \begin{sample}
%     |\bCSb*{\bS{x}+\bS{y}}| \> $\bCSb*{\bS{x}+\bS{y}}$\\[1ex]
%     |\bSb{E_{313}}^s_r| \> $\bSb{E_{313}}^s_r$
% \end{sample}
%
% When a font does not have bold italic symbols and is properly configured, the
% |\bm| command constructs the symbols with the ``poor man's bold'' method.
% This results in the loss of the subscript kerning. This is the case for the
% \pkg{mathptm}\ package for Times fonts. If bold italic symbols are needed for
% Times fonts, it is advisable to use the \pkg{txfonts} package or one of the
% commercial fonts.
%
%
% \subsection{Struts}
%
% A strut can be inserted inside the tensor construction to force all the lines
% to the same height. This can be given in the package options
% \begin{sample}
%     \hskip14pc\=\kill
%     |\usepackage{mattens}|             \>|% No strut as default |
% \end{sample}
% or
% \begin{sample}
%     \hskip14pc\=\kill
%     |\usepackage[mathstrut]{mattens}|  \>|% Uses \mathstrut     |
% \end{sample}
% or anywhere in the document with the command
% \begin{Decl}
%     \SpecialUsageIndex{\SetSymbStrut}^^A
%     \cmd{\SetSymbStrut}\marg{strut}
% \end{Decl}
%
% \pagebreak[2]
% \noindent For example
% \SetSymbStrut{\relax}
% \begin{sample}
%     |\SetSymbStrut{\relax}| \\
%     |\bSb{E}|, |\bS{x}|, |\Sb{y}| \>$\bSb{E}$, $\bS{x}$, $\Sb{y}$
% \end{sample}
% \SetSymbStrut{\mathstrut}
% \begin{sample}
%     |\SetSymbStrut{\mathstrut}| \\
%     |\bSb{E}|, |\bS{x}|, |\Sb{y}| \>$\bSb{E}$, $\bS{x}$, $\Sb{y}$
% \end{sample}
% \SetSymbStrut{\vphantom{E}}
% \begin{sample}
%     |\SetSymbStrut{\vphantom{E}}| \\
%     |\bSb{E}|, |\bS{x}|, |\Sb{y}| \>$\bSb{E}$, $\bS{x}$, $\Sb{y}$
% \end{sample}
% \SetSymbStrut{\relax}
%
% \subsection{Additional sub- and superscript spaces}
%
% The placing of the sub- and superscripts was fine-tuned for Computer Modern
% fonts. Other fonts may require the sub- and superscript to shift closer or
% further away from the lines and the symbols. Additional spaces can be
% inserted before the sub- and superscripts with the following commands:
% \begin{Decl}
%     \cmd{\SetArrowSkip}\marg{muskip length}\\[.5ex]
%     \cmd{\SetBarSkip}\marg{muskip length}\\[.5ex]
%     \cmd{\SetSymSubSkip}\marg{muskip length}\\[.5ex]
%     \cmd{\SetSymSupSkip}\marg{muskip length}
%         \SpecialUsageIndex{\SetArrowSkip}
%         \SpecialUsageIndex{\SetBarSkip}
%         \SpecialUsageIndex{\SetSymSubSkip}
%         \SpecialUsageIndex{\SetSymSupSkip}
% \end{Decl}
% \noindent The length units must be in math units (\myemph{mu}), where
% $18\,\mathit{mu}=1\,\mathit{em}$ (a little less than the width of the letter
% ``M'').
%
% \section{Other packages and classes}
%
% \begin{description}
%     \item[\normalfont\pkg{bm}:\quad] The \pkg{bm} package is preferred
%         for bold\-/\-heavy symbols in math mode. It can also be used to
%         predeclare bold symbols for use with the starred form of the
%         tensor commands, for example: \SetSymbFont{\bm}
%         \begin{sample}
%             | \bmdefine{\bO}{\mathit{\Omega}}|\\
%             |$\bSb*{\bO_i}$|  \>\qquad\qquad\qquad $\bSb*{\bO_i}$
%         \end{sample}
%
%     \item[\normalfont\pkg{hyperref}:\quad] When tensor symbols are set in
%         chapter and section headers, \pkg{hyperref} crashes if the
%         \cmd{\texorpdfstring} command is not used.
%         \begin{sample}
%             |\section{A header with \texorpdfstring{$\bS{x}^i_j$}{xij} in it}|
%         \end{sample}
%
%     \item[\normalfont\pkg{color}:\quad] To change the colour of a symbol
%         the \cmd{\color} command must be grouped two levels deep to
%         survive all the expansions if the \pkg{bm} package is loaded.
%         \begin{sample}
%             |$\aSb{{{\color{red}E}}}_i$| \> $\aSb{{{\color{red}E}}}_i$
%         \end{sample}
%
%     \item[\normalfont\pkg{accents}:\quad] For the creation of alternative
%         accents the \MT\ package is fully compatible with the
%         \pkg{accents}\ package. As an example of its usage, the equation
%         in \Hass\cite{Hass93a}, \S10.1, p.82
%
% \begin{minipage}{\textwidth}
% \begin{verbatim}
%     \SetSymbFont{\relax}
%     \SetSymbStrut{\mathstrut}
%     \newcommand{\dotr}[1]{%
%         \accentset{\phantom{r}{\displaystyle.}r}{#1}}
%     \begin{equation*}
%         \text{apparent velocity}
%                 = \frac{\partial_r}{\mathrm{d}t} \aS{r}
%                 = \aS[\dotr]{r}
%                 = \aSb{E}_s \tdot \bS[\dotr]{r}^s
%            \equiv \aS{v}_{\mathrm{app}}
%                 = \aS{v}_{\mathrm{rel}}
%     \end{equation*}
% \end{verbatim}
% \end{minipage}
% \medskip
%
%         which gives\SetSymbFont{\relax}\SetSymbStrut{\mathstrut}%
%         \begin{equation*}
%             \text{apparent velocity} =
%                 \frac{\partial_r}{\mathrm{d}t} \aS{r} =
%                 \aS[\dotr]{r} =
%                 \aSb{E}_s \tdot \bS[\dotr]{r}^s \equiv
%                 \aS{v}_{\mathrm{app}} =
%                 \aS{v}_{\mathrm{rel}}
%         \end{equation*}
%         \SetSymbStrut{\relax}\SetSymbFont{\bm}
% \end{description}
% ^^A\clearpage
%
% \section{To do's}
%
% \begin{itemize}
%     \item The vertical spacing between the symbols and the lines and
%         arrows differs, $\aSb{E}$, $\bSa{E}$. This problem cannot be
%         fixed easily and would need some additional struts or even a
%         rewriting of the arrows and lines commands.
%
%     \item For the purists: The ends of the |\overrightarrow| are rounded
%         (ligature of symbols), while the ends of the |\overline| are
%         squared (\TeX{} line drawing).
% \item The shape of the arrow tip of the |\overrightarrow| command was
%     probably not designed for this type of application and is much too broad
%     in the final CM font version. This broad arrow shape is incidentally one
%     of last changes by Prof.~Knuth to the CM font symbols. The PostScript
%     version of the CM fonts typesets the arrow much better, but it is highly
%     likely that it is still the old outdated version of the symbol.
%    The \pkg{esvect} provides alternative vector symbols that can
%    be used in \cmd{\overrightarrow}.
% \end{itemize}
% \bigskip
%
% \begin{thebibliography}{7}
%     \bibitem{Hass93a}
%         \Hass, W.~C.,
%         ``Matrix Tensor Notation Part I. Rectilinear Orthogonal Coordinates,''
%         \textsl{Comput. Math. Appl.},
%         \textbf{26}(3), 1993, pp. 55--93.
%
%     \bibitem{Hass93b}
%         \Hass, W.~C.,
%         ``Matrix Tensor Notation Part II. Skew and Curved Coordinates,''
%         \textsl{Comput. Math. Appl.},
%         \textbf{29}(11), 1993, pp. 1--103.
% \end{thebibliography}
%
%  \StopEventually{} ^^A end StopEventually
%
%  \clearpage
%
% \section{The Code: \pkg{mattens.sty}}
%    \setlength{\parskip}{\smallskipamount}
%    \setlength{\parindent}{0pt}
%
%    \begin{macrocode}
%<*package>
%    \end{macrocode}
%
%
%
%    \subsection{Identification}
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mattens}[2022/03/01
                          v1.3b
                          Matrix/Tensors (DNJ Els)]
%    \end{macrocode}
%
%
%
%    \subsection{Options}
%
%    \begin{macro}{\MT@SymbStrt}
%    \begin{macro}{\SetSymbStrut}
%    Struts to set all the lines and arrows at
%    predetermined heights and depths.
%    \begin{macrocode}
\newcommand*{\MT@SymbStrt}{}
\newcommand*{\SetSymbStrut}[1]{\renewcommand*{\MT@SymbStrt}{#1}}
\SetSymbStrut{\relax}
\DeclareOption{mathstrut}{\SetSymbStrut{\mathstrut}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\MT@SymbFnt}
%    \begin{macro}{\SetSymbFont}
%    Initialize the symbol font formatting commands.
%    \begin{macrocode}
\newcommand*{\MT@SymbFnt}{}
\newcommand*{\SetSymbFont}[1]{\renewcommand*{\MT@SymbFnt}{#1}}
\SetSymbFont{\boldsymbol}
\DeclareOption{noformat}{\SetSymbFont{\relax}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%    Process the options
%    \changes{1.3a}{2010 Mar 25}{Remove invalid UTF-8 byte sequences}
%    \begin{macrocode}
\DeclareOption*{%
    \PackageWarning{mattens}{Unknown option: \CurrentOption}}
\ProcessOptions\relax
%    \end{macrocode}
%
%
%
%    \subsection{Packages}
%
%    The \pkg{amsmath} package is loaded to provide the scalable
%    \cmd{\overrightarrow} and \cmd{\underrightarrow} commands, as
%    well as the \cmd{\boldsymbol} command for setting bold math
%    symbols.
%
%    \begin{macrocode}
\RequirePackage{amsmath}
%    \end{macrocode}
%
%
%
%    \subsection{Workaround commands}
%
%    \begin{macro}{\MT@Overarrow}
%    \begin{macro}{\MT@Underarrow}
%    We define over- and under-arrows that bypass the
%    \cmd{\mathpalette} part of the \pkg{amsmath} macros
%    \cmd{\overrightarrow} and \cmd{\underrightarrow}. It uses
%    the \pkg{amsmath} internal macros \cmd{\overarrow@},
%    \cmd{\underarrow@} and \cmd{\rightarrowfill@}.
%    The first parameter |#1| consists of math styles \cmd{\displaystyle},
%    \cmd{\textstyle}, etc.  The second parameter |#2| is the symbol
%    or character.
%    \begin{macrocode}
\newcommand{\MT@Overarrow}[2]{\overarrow@{\rightarrowfill@}{#1}{#2}}
\newcommand{\MT@Underarrow}[2]{\underarrow@{\rightarrowfill@}{#1}{#2}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\MT@Overline}
%    \begin{macro}{\MT@Underline}
%    Make over- and underlines with the same calling syntax as
%    the arrows.
%    \begin{macrocode}
\newcommand{\MT@Overline}[2]{{#1\overline{#2}}}
\newcommand{\MT@Underline}[2]{{#1\underline{#2}}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\xusebox}
%    \changes{1.1}{2004 Jan 15}{More streamline.}
%    \changes{1.2}{2004 Jan 27}{Test if \pkg{pdftex.def} is loaded.
%        and command is rewritten to use a \cmd{\mathord} to
%        restore script heights}
%    The \cmd{\usebox} command does not function properly when the
%    \pkg{pdftex.def} driver is loaded, because \pkg{pdftex} does
%    not implement a colour stack such as in the \pkg{dvips} driver,
%    but simulate it at \TeX{} macro level.  The \cmd{\xusebox} is
%    a workaround where the \cmd{\usebox} command is grouped.\footnote{
%        Thanks to Heiko Oberdiek for this workaround}
%    A |\mathord| is added around the box to regain its height in the
%    \pkg{pdftex} case.
%    \begin{macrocode}
\AtBeginDocument{%
   \@ifl@aded{def}{pdftex}%
      {\newcommand*{\xusebox}[1]{\mathord{{\usebox{#1}}}}}%
      {\let\xusebox\usebox}%
}
%    \end{macrocode}
%    \end{macro}
%
%
%
%    \subsection{Initialize}
%
%    Define skip lengths for insertion in front of sub- and
%    superscripts.
%    \begin{macrocode}
\newmuskip{\MT@Askip}
\newmuskip{\MT@Bskip}
\newmuskip{\MT@SPskip}
\newmuskip{\MT@SBskip}
%    \end{macrocode}
%
%    \begin{macro}{\SetArrowSkip}
%    \begin{macro}{\SetBarSkip}
%    \begin{macro}{\SetSymSupSkip}
%    \begin{macro}{\SetSymSubSkip}
%    Define commands to set or change the skip lengths and set initial values.
%    \begin{macrocode}
\newcommand*{\SetArrowSkip}[1]{\MT@Askip#1}
\newcommand*{\SetBarSkip}[1]{\MT@Bskip#1}
\newcommand*{\SetSymSupSkip}[1]{\MT@SPskip#1}
\newcommand*{\SetSymSubSkip}[1]{\MT@SBskip#1}
\SetArrowSkip{0mu}
\SetBarSkip{1mu}
\SetSymSubSkip{0mu}
\SetSymSupSkip{0mu}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\MT@SubSkip}
%    \begin{macro}{\MT@SupSkip}
%    Define math skip lengths to insert in front of the sub- and
%    superscripts. The values are set inside the main \MT\ commands
%    according to the type of symbol.
%    \begin{macrocode}
\newmuskip\MT@SubSkip
\newmuskip\MT@SupSkip
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%
%
%    \subsection{Main \MT\ commands}
%
%    Setup command templates and lengths to function as global
%    variables and pointers.
%
%    \begin{macro}{\MT@accent}
%    The \cmd{\MT@accent} command points
%    to the math accent that are inserted as the optional argument
%    inside the main \MT\ commands.
%
%    \begin{macrocode}
\newcommand*{\MT@accent}{}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@cmd}
%    \begin{macro}{\MT@@cmd}
%    The commands \cmd{\MT@cmd} and \cmd{\MT@cmd} do the actual
%    typesetting of the symbols.
%    \begin{macrocode}
\newcommand*{\MT@cmd}{}
\newcommand*{\MT@@cmd}{}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%
%     They can be seen
%    as function pointer that are set with |\let| commands inside
%    the main \MT\ commands to point to specific commands.
%
% \newcommand{\RA}{\ensuremath{\,\mapsto\,}}
%
%    \begin{tabbing}
%    \hskip2pc\=\hskip3pc\=\hskip12pc\=\kill
%    \>\textsl{Cmd} \> \textsl{Primary command} \> \textsl{Secondary command}\\[.75ex]
%    \>|\aS|:   \>|\MT@cmd| \RA |\MT@OverAandB|,   \>|\MT@@cmd| \RA |\MT@Overarrow|\\
%    \>|\bS|:   \>|\MT@cmd| \RA |\MT@OverAandB|,   \>|\MT@@cmd| \RA |\MT@Overline|\\
%    \>|\Sa|:   \>|\MT@cmd| \RA |\MT@UnderAandB|,  \>|\MT@@cmd| \RA |\MT@Underarrow|\\
%    \>|\Sb|:   \>|\MT@cmd| \RA |\MT@UnderAandB|,  \>|\MT@@cmd| \RA |\MT@Underline|\\
%    \>|\bSb|:  \>|\MT@cmd| \RA |\MT@DoubleAandB|, \>|\MT@@cmd| \RA |\MT@@bSb| \\
%    \>|\aSb|:  \>|\MT@cmd| \RA |\MT@DoubleAandB|, \>|\MT@@cmd| \RA |\MT@@aSb|\\
%    \>|\bSa|:  \>|\MT@cmd| \RA |\MT@DoubleAandB|, \>|\MT@@cmd| \RA |\MT@@bSa| \\
%    \>|\aSa|:  \>|\MT@cmd| \RA |\MT@DoubleAandB|, \>|\MT@@cmd| \RA |\MT@@aSa|\\
%    \>|\bCSb|: \>|\MT@cmd| \RA |\MT@DoubleAandB|, \>|\MT@@cmd| \RA |\MT@@bCSb|\\
%    \>|\aCSa|: \>|\MT@cmd| \RA |\MT@DoubleAandB|, \>|\MT@@cmd| \RA |\MT@@aCSa|\\
%    \end{tabbing}
%
%
%    \begin{macro}{\MT@bold}
%    The \cmd{\MT@bold} command is used internally and set by the
%    ``starred'' command option.
%    \begin{macrocode}
\newcommand*{\MT@bold}{}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\aS}
%    Type the tensor: $\aS{x}$
%    \begin{macrocode}
\DeclareRobustCommand*{\aS}{%
   \let\MT@cmd=\MT@OverAandB%
   \let\MT@@cmd=\MT@Overarrow%
   \MT@SupSkip=\MT@Askip%
   \MT@SubSkip=\MT@SBskip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\bS}
%    Type the tensor: $\bS{x}$
%    \begin{macrocode}
\DeclareRobustCommand*{\bS}{%
   \let\MT@cmd=\MT@OverAandB%
   \let\MT@@cmd=\MT@Overline%
   \MT@SupSkip=\MT@Bskip%
   \MT@SubSkip=\MT@SBskip%
   \MT@Tensor}%
%    \end{macrocode}
%    \end{macro}
%
%
%    \begin{macro}{\Sa}
%    Type the tensor: $\Sa{x}$
%    \begin{macrocode}
\DeclareRobustCommand*{\Sa}{%
   \let\MT@cmd=\MT@UnderAandB%
   \let\MT@@cmd=\MT@Underarrow%
   \MT@SupSkip=\MT@SPskip%
   \MT@SubSkip=\MT@Askip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\Sb}
%    Type the tensor: $\Sb{x}$
%    \begin{macrocode}
\DeclareRobustCommand*{\Sb}{%
   \let\MT@cmd=\MT@UnderAandB%
   \let\MT@@cmd=\MT@Underline%
   \MT@SupSkip=\MT@SPskip%
   \MT@SubSkip=\MT@Bskip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\bSb}
%    Type the tensor: $\bSb{E}$
%    \begin{macrocode}
\DeclareRobustCommand*{\bSb}{%
   \let\MT@cmd=\MT@DoubleAandB%
   \let\MT@@cmd=\MT@@bSb%
   \MT@SupSkip=\MT@Bskip%
   \MT@SubSkip=\MT@Bskip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\aSb}
%    Type the tensor: $\aSb{E}$
%    \begin{macrocode}
\DeclareRobustCommand*{\aSb}{%
   \let\MT@cmd=\MT@DoubleAandB%
   \let\MT@@cmd=\MT@@aSb%
   \MT@SupSkip=\MT@Askip%
   \MT@SubSkip=\MT@Bskip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\bSa}
%    Type the tensor: $\bSa{E}$
%    \begin{macrocode}
\DeclareRobustCommand*{\bSa}{%
   \let\MT@cmd=\MT@DoubleAandB%
   \let\MT@@cmd=\MT@@bSa%
   \MT@SupSkip=\MT@Bskip%
   \MT@SubSkip=\MT@Askip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\aSa}
%    Type the tensor: $\aSa{E}$
%    \begin{macrocode}
\DeclareRobustCommand*{\aSa}{%
   \let\MT@cmd=\MT@DoubleAandB%
   \let\MT@@cmd=\MT@@aSa%
   \MT@SupSkip=\MT@Askip%
   \MT@SubSkip=\MT@Askip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\bCSb}
%    Type the tensor: $\bCSb{\omega}$
%    \begin{macrocode}
\DeclareRobustCommand*{\bCSb}{%
   \let\MT@cmd=\MT@DoubleAandB%
   \let\MT@@cmd=\MT@@bCSb%
   \MT@SupSkip=\MT@Bskip%
   \MT@SubSkip=\MT@Bskip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\aCSa}
%    Type the tensor: $\aCSa{\omega}$
%    \begin{macrocode}
\DeclareRobustCommand*{\aCSa}{%
   \let\MT@cmd=\MT@DoubleAandB%
   \let\MT@@cmd=\MT@@aCSa%
   \MT@SupSkip=\MT@Askip%
   \MT@SubSkip=\MT@Askip%
   \MT@Tensor}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@Tensor}
%    \changes{1.1}{2004 Jan 15}{Added to reduce overall code.}
%    \begin{macro}{\MT@@Tensor}
%    \changes{1.1}{2004 Jan 15}{Added to reduce overall code.}
%    General tensor commands to look for starred form and
%    and initiate script extraction.
%    \begin{macrocode}
\newcommand*{\MT@Tensor}{%
   \@ifstar{\let\MT@bold=\@firstofone\MT@@Tensor}
           {\let\MT@bold=\MT@SymbFnt\MT@@Tensor}}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*{\MT@@Tensor}[2][\@firstofone]{%
   \let\MT@accent=#1\relax%
   \MT@GetScripts{#2}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%
%
%    \subsection{Sub- and superscripts}
%
%
%    \begin{macro}{\MT@GetScripts}
%    This part of the code looks ahead for sub- and superscripts.
%    \changes{1.1}{2004 Jan 15}{Add: Code to check for primes}
%    \begin{macrocode}
\newcommand*\MT@GetScripts[1]{%
   \@ifnextchar'%
      {\MT@GetPrimes{#1}{\prime}}%
      {\MT@UnprimedScripts{#1}}}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@GetPrimes}
%    \changes{1.1}{2004 Jan 15}{Add: Extract primes}
%    \begin{macro}{\MT@GetPrimedSuper}
%    \changes{1.1}{2004 Jan 15}{Add: Extract primes}
%    \begin{macro}{\MT@GetPrimedSub}
%    \changes{1.1}{2004 Jan 15}{Add: Extract primes}
%    Extract primes and look ahead for superscripts |^|. Note that
%    the sequence of operators for a primed symbol is:
%    \meta{symb}|'|$^{..}\!\!$|'^|\meta{sup}|_|\meta{sub}
%    \begin{macrocode}
\newcommand*\MT@GetPrimes[3]{%
   \@ifnextchar'%
      {\MT@GetPrimes{#1}{#2\prime}}%
      {\@ifnextchar^%
          {\MT@GetPrimedSuper{#1}{#2}}%
          {\@ifnextchar_%
              {\MT@GetPrimedSub{#1}{#2}}%
              {\MT@SetScripts{#1}{#2}{\@empty}}%
          }%
      }%
   }
%    \end{macrocode}
%    \begin{macrocode}
\def\MT@GetPrimedSuper#1#2^#3{%
   \@ifnextchar_{\MT@GetPrimedSub{#1}{#2#3}}%
                {\MT@SetScripts{#1}{#2#3}{\@empty}}}
%    \end{macrocode}
%    \begin{macrocode}
\def\MT@GetPrimedSub#1#2_#3{%
   \MT@SetScripts{#1}{#2}{#3}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\MT@UnprimedScripts}
%    The first extraction command for symbols without primes.
%    It looks ahead for |^| or |_|, if not present, then pass
%    \cmd{\@empty} flags forward, otherwise it passes the tokens
%    on to the next extraction commands.
%
%    \begin{macrocode}
\newcommand*\MT@UnprimedScripts[1]{%
   \@ifnextchar^%
      {\MT@GetSuper{#1}}%
         {\@ifnextchar_%
             {\MT@GetSub{#1}}%
             {\MT@SetScripts{#1}{\@empty}{\@empty}}%
         }%
   }
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@GetSuper}
%    Extract  scripts of the form \meta{Sym}|^|\meta{sup}
%    if there are no further |_| tokens available, otherwise pass the
%    tokens on to the next extraction command.
%
%    \begin{macrocode}
\def\MT@GetSuper#1^#2{%
   \@ifnextchar_{\MT@GetSuperSub{#1}{#2}}%
                {\MT@SetScripts{#1}{#2}{\@empty}}}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@GetSub}
%    Extract scripts of the form \meta{Sym}|_|\meta{sub}
%    if there are no further |^| tokens available, otherwise pass the
%    tokens on to the next extraction command.
%
%    \begin{macrocode}
\def\MT@GetSub#1_#2{%
   \@ifnextchar^{\MT@GetSubSuper{#1}{#2}}%
                {\MT@SetScripts{#1}{\@empty}{#2}}}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@GetSuperSub}
%    Extract scripts of the form
%    \meta{Sym}|^|\meta{sup}|_|\meta{sub}.
%
%    \begin{macrocode}
\def\MT@GetSuperSub#1#2_#3{%
   \MT@SetScripts{#1}{#2}{#3}}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@GetSubSuper}
%    Extract scripts of the form
%    \meta{Sym}|_|\meta{sub}|^|\meta{sup}.
%
%    \begin{macrocode}
\def\MT@GetSubSuper#1#2^#3{%
   \MT@SetScripts{#1}{#3}{#2}}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@SetSup}
%    \begin{macro}{\MT@SetSub}
%    Define global variables commands that contain the extracted
%    sub- and superscripts. These commands are redefined inside the
%    the final \cmd{\MT@SetScripts} command.
%
%    \begin{macrocode}
\newcommand*{\MT@SetSup}{}
\newcommand*{\MT@SetSub}{}
\newcommand*{\MT@SetSubS}{}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%    \changes{1.3}{2009 Sep 1}{Remove \cmd{\ensuremath} to force math mode.}
%    \begin{macrocode}
\newcommand*\MT@SetScripts[3]{%
  \let\MT@SetSup\relax%
  \let\MT@SetSub\relax%
  \let\MT@SetSubS\relax%
  \ifx\@empty#2\@empty\else
     \def\MT@SetSup{^{\mskip\MT@SupSkip\relax#2}}%
  \fi
  \ifx\@empty#3\@empty\else
     \def\MT@SetSub{_{\mskip\MT@SubSkip\relax#3}}%
     \def\MT@SetSubS{^{}_{\mskip\MT@SubSkip\relax#3}}%
  \fi
  \MT@cmd{#1}}
%    \end{macrocode}
%
%
%
%    \subsection{Symbol formatting}
%
%    \begin{macro}{\MT@Symb}
%    This command type |{|\meta{strut}\meta{font-cmd}\meta{symb}|}|,
%    the formatted symbol preceded by the selected strut. It is called
%    from within the main typesetting commands.
%
%    \begin{macrocode}
\newcommand*{\MT@Symb}[1]{\MT@SymbStrt\MT@bold#1}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@SymbC}
%    Puts a widetilde over the symbol for the cross product tensors.
%    \begin{macrocode}
\newcommand*{\MT@SymbC}[1]{%
   \MT@SymbStrt\widetilde{%
   \MT@bold#1}}
%    \end{macrocode}
%    \end{macro}
%
%
%    \subsection{Main typesetting commands}
%
%    The commands in this section are the ones pointed to by
%    the \cmd{\MT@cmd} and \cmd{\MT@@cmd} commands to perform
%    the typesetting of the full tensor symbol.
%
%    Declare some save boxes
%    \begin{macrocode}
\newsavebox{\MT@Abox}   % for overline/arrow
\newsavebox{\MT@Sbox}   % for symbol
\newsavebox{\MT@Tbox}   % for tempories
\newsavebox{\MT@APbox}  % for overline/arrow phantom
\newsavebox{\MT@SPbox}  % for symbol phantom
%    \end{macrocode}
%    and some lengths.
%    \begin{macrocode}
\newlength{\MT@SPwdth}  % symbol width
\newlength{\MT@BPwdth}  % Bar width
\newlength{\MT@Wwdth}   % leading whitespace width
%    \end{macrocode}
%
%    \begin{macro}{\MT@OverAandB}
%    This command generates the tensor symbols $\aS{e}$ and $\bS{e}$.
%    It utilizes the \cmd{\mathpalette} macro for the sizing of the
%    final tensor. \LaTeX{} commands \cmd{\smash} and \cmd{\phantom}
%    with embedded \cmd{\mathpalette} calls are avoided to prevent
%    nested \cmd{\mathchoice} calls.
%    \begin{macrocode}
\newcommand*{\MT@OverAandB}{%
   \mathpalette\MT@@OverAandB}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@@OverAandB}
%    \changes{1.2}{2004 Jan 27}{Use \cmd{\xusebox} inside accent
%             to account for \cmd{\dddot}.}
%    For this command the first parameter |#1| is supplied by
%    \cmd{\mathpalette} and consists of math styles \cmd{\displaystyle},
%    \cmd{\textstyle}, etc.  The second parameter |#2| is the original
%    \meta{symbol} from the call \cmd{\MT@cmd}|{|\meta{symbol}|}|.
%
%    \begin{macrocode}
\newcommand*{\MT@@OverAandB}[2]{%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Set the symbol inside a box for measurement purposes.
%    \end{Indent}
%    \begin{macrocode}
      \sbox{\MT@Tbox}{$\m@th#1\MT@Symb{#2}$}%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Make phantom symbol box (empty) with size identical to symbol.
%    \end{Indent}
%    \begin{macrocode}
      \setbox\MT@SPbox\null%
      \ht\MT@SPbox\ht\MT@Tbox%
      \dp\MT@SPbox\dp\MT@Tbox%
      \wd\MT@SPbox\wd\MT@Tbox%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Make overline/overarrow over phantom symbol box for measurement.
%    \end{Indent}
%    \begin{macrocode}
      \sbox{\MT@APbox}{$\m@th\MT@@cmd{#1}{\copy\MT@SPbox}$}%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Calculate width difference between symbol and arrow/overline.
%    \end{Indent}
%    \begin{macrocode}
      \setlength{\MT@Wwdth}{\the\wd\MT@APbox}%
      \addtolength{\MT@Wwdth}{-\the\wd\MT@SPbox}%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Make final symbol box with white space in front to center is
%    beneath the arrow/over line and subscript that follows.
%    \end{Indent}
%    \begin{macrocode}
      \sbox{\MT@Sbox}{$\m@th#1\hskip 0.5\MT@Wwdth\relax\MT@Symb{#2}\MT@SetSubS$}%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Add math accent to overline/overarrow and reset box dimensions to
%    original.
%    \end{Indent}
%    \begin{macrocode}
      \sbox{\MT@Tbox}{$\m@th#1\MT@accent{\xusebox{\MT@APbox}}$}%
      \ht\MT@Tbox\ht\MT@APbox%
      \dp\MT@Tbox\dp\MT@APbox%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Final overline/overarrow box including accent and superscript at end.
%    \end{Indent}
%    \begin{macrocode}
      \sbox{\MT@Abox}{$\m@th#1\xusebox{\MT@Tbox}\MT@SetSup$}%
%    \end{macrocode}
%    \begin{Indent}{5em}
%    Overtype the symbol and the overline/overarrow boxes. The wider
%    box of the two is typed last to ensure that the spacing after
%    the full tensor symbol is correct.
%    \end{Indent}
%    \begin{macrocode}
      \ifdim\wd\MT@Abox<\wd\MT@Sbox%
          \leavevmode\rlap{\usebox\MT@Abox}{\usebox\MT@Sbox}%
      \else%
          \leavevmode\rlap{\usebox\MT@Sbox}{\usebox\MT@Abox}%
      \fi}
%    \end{macrocode}
%    \end{macro}
%
%    \begin{macro}{\MT@UnderAandB}
%    \begin{macro}{\MT@@UnderAandB}
%    \changes{1.2}{2004 Jan 27}{Make provisions for wide accents (\cmd{\dddot}).}
%    This command generates the tensor symbols $\Sa{e}$ and $\Sb{e}$.
%    It is identical to the previous command except the sub- and
%    superscripts are swapped and the phantom box is set to the width
%    of the accent.
%    \begin{macrocode}
\newcommand*{\MT@UnderAandB}{%
   \mathpalette\MT@@UnderAandB}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*{\MT@@UnderAandB}[2]{%
      \sbox{\MT@Tbox}{$\m@th#1\MT@accent{\MT@Symb{#2}}$}%
      \setbox\MT@SPbox\null%
      \wd\MT@SPbox\wd\MT@Tbox%
      \sbox{\MT@Tbox}{$\m@th#1\MT@Symb{#2}$}%
      \ht\MT@SPbox\ht\MT@Tbox%
      \dp\MT@SPbox\dp\MT@Tbox%
      \sbox{\MT@APbox}{$\m@th\MT@@cmd{#1}{\copy\MT@SPbox}$}%
      \setlength{\MT@Wwdth}{\the\wd\MT@APbox}%
      \addtolength{\MT@Wwdth}{-\the\wd\MT@SPbox}%
      \sbox{\MT@Sbox}{$\m@th#1%
         \hskip 0.5\MT@Wwdth\relax\MT@accent{\MT@Symb{#2}}\MT@SetSup$}%
      \sbox{\MT@Abox}{$\m@th#1\xusebox{\MT@APbox}\MT@SetSub$}%
      \ifdim\wd\MT@Abox<\wd\MT@Sbox%
         \leavevmode\rlap{\usebox\MT@Abox}{\usebox\MT@Sbox}%
      \else%
         \leavevmode\rlap{\usebox\MT@Sbox}{\usebox\MT@Abox}%
      \fi}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\MT@@bSb}
%    \begin{macro}{\MT@@bSa}
%    \begin{macro}{\MT@@aSb}
%    \begin{macro}{\MT@@aSa}
%    \begin{macro}{\MT@@bCSb}
%    \begin{macro}{\MT@@aCSa}
%    These commands are pointed to by \cmd{\MT@@cmd} and called from
%    within \cmd{\MT@DoubleAandB}. It has the same calling syntax as
%    the \cmd{\MT@Overarrow} and \cmd{\MT@Underarrow} commands.
%    \begin{macrocode}
\newcommand*{\MT@@bSb}[2]{\MT@Overline{#1}{\MT@Underline{#1}{\MT@Symb{#2}}}}
\newcommand*{\MT@@aSb}[2]{\MT@Overarrow{#1}{\MT@Underline{#1}{\MT@Symb{#2}}}}
\newcommand*{\MT@@bSa}[2]{\MT@Overline{#1}{\MT@Underarrow{#1}{\MT@Symb{#2}}}}
\newcommand*{\MT@@aSa}[2]{\MT@Overarrow{#1}{\MT@Underarrow{#1}{\MT@Symb{#2}}}}
\newcommand*{\MT@@bCSb}[2]{\MT@Overline{#1}{\MT@Underline{#1}{\MT@SymbC{#2}}}}
\newcommand*{\MT@@aCSa}[2]{\MT@Overarrow{#1}{\MT@Underarrow{#1}{\MT@SymbC{#2}}}}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%    \end{macro}
%
%    \begin{macro}{\MT@DoubleAandB}
%    \begin{macro}{\MT@@DoubleAandB}
%    \changes{1.2}{2004 Jan 27}{Use \cmd{\xusebox} inside accent
%             to account for \cmd{\dddot}.}
%    This command is used for the remaining tensor symbols and is not
%    so complex compared to the previous commands.
%
%    \begin{macrocode}
\newcommand*{\MT@DoubleAandB}{%
  \mathpalette\MT@@DoubleAandB}
%    \end{macrocode}
%    \begin{macrocode}
\newcommand*{\MT@@DoubleAandB}[2]{%
      \sbox{\MT@Abox}{$\m@th#1\MT@@cmd{#1}{#2}$}%
      \sbox{\MT@Tbox}{$\m@th#1\MT@accent{\xusebox{\MT@Abox}}$}%
      \ht\MT@Tbox\ht\MT@Abox%
      \dp\MT@Tbox\dp\MT@Abox%
      \xusebox{\MT@Tbox}\MT@SetSup\MT@SetSub}
%    \end{macrocode}
%    \end{macro}
%    \end{macro}
%
%
%    \changes{1.1}{2004 Jan 15}{Code: Remove helper commands}
%    \begin{macrocode}
%</package>
%    \end{macrocode}
% \clearpage
% \Finale
% \setcounter{IndexColumns}{2}\PrintIndex
% \PrintChanges
%
\endinput