The mattens package^{∗}

Danie Els

Department of Mechanical Engineering University of Stellenbosch, South Africa

             e-mail: dnjels@sun.ac.za

2001/12/09

Abstract

This package contains the definitions to typeset the matrix tensor notation of Hassenpflug[1, 2]. It consists of symbols such as ⟶ e_{i}, x^{^{˙ r}}, \overline{\underline{E}}_{r}^{s}, etc. This notation was developed and refined by Dr. Hassenpflug over many years of teaching engineering, and as stated by him[1]:

“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.”

An appeal is made to the engineering and scientific community to adopt this notation, especially for the representation of common vectors and tensors such as forces, velocities, moments of inertia, etc., because of its consistency and ease of use.

Keywords: vector, matrix, tensor, notation.

∗This file has version number v1.0, last revised 2001/12/09.

Contents

1 Introduction 3 1.1 Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

2 Usage of mattens package 4

3 List of mattens commands 5 3.1 General syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

4 Symbol formatting commands 7 4.1 Bold italic symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 4.2 Struts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 4.3 Additional sub- and superscript spaces . . . . . . . . . . . . . . . . 8

5 Additional commands 9 5.1 Saving equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 5.2 Helper commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

6 Other programs, classes and packages 10

7 Typesetting the Hassenpflug notation in L^{A}TEX 11 7.1 Why? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 7.2 To do’s . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 7.3 Bugs, etc. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

8 The Code: mattens.sty 15 8.1 Identification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 8.2 Packages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 8.3 Workaround commands . . . . . . . . . . . . . . . . . . . . . . . . 15 8.4 Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 8.5 Initialize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 8.6 Main mattens commands . . . . . . . . . . . . . . . . . . . . . . . . 16 8.7 Sub- and superscripts . . . . . . . . . . . . . . . . . . . . . . . . . 20 8.8 Symbol formatting . . . . . . . . . . . . . . . . . . . . . . . . . . . 22 8.9 Main typesetting commands . . . . . . . . . . . . . . . . . . . . . . 22 8.10 A save/recall box utility . . . . . . . . . . . . . . . . . . . . . . . . 25 8.11 Helper utility functions . . . . . . . . . . . . . . . . . . . . . . . . 25

1 Introduction

1.1 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. Hassenpflug[1] identifies the following list of requirements for a good notation for tensor quantities and operations, to which his notation conforms: A notation must

1. be easily written by hand;

2. distinguish between vector and scalar quantities;

3. distinguish between (second order) tensors and vectors;

4. distinguish between physical vectors and their representation by vector arrays, and between physical (second order) tensors and their representation by matrices;

5. distinguish between row and column vectors;

6. 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;

7. distinguish between matrix/vector representation of the same vector/tensor in different coordinate axes;

8. be equally valid in orthonormal and skew coordinate axes;

9. indicate all intended operations uniquely;

10. be equally valid in all dimensions;

11. be equally valid for algebraic vector/matrix algebra which has no connection to any metric space;

12. be applicable to differentials;

13. 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.

14. It must be well documented (own addition). The mattens package was developed to typeset the Hassenpflug matrix tensor symbols in a consistent manner.

2 Usage of mattens package

The mattens package is loaded in the document preamble with:

⋮

     \usepackage[⟨options⟩]{mattens}  % amsmath loaded internally

⋮

     \usepackage{⟨font packages⟩}      %
     \DeclareSymbolFont...  % All the font changes
     \SetSymbolFont...  %
     \DeclareSymbolFontAlphabet...  %

⋮

     \usepackage{bm}       %\boldsymbol redirected to call \bm

⋮

When mattens is loaded, the amsmath package is loaded automatically, because it is needed for the redefined \overrightarrow and \underrightarrow commands, as well as the \boldsymbol command. It must be loaded before any font packages that redefine some of the amsmath symbols or commands.

On the other hand, the preferred method for obtaining bold italic math symbols is the \bm command of the bm package^{1}. The bm package must be loaded after all the font packages in order for it to recognize the bold math versions. The bm package reroutes the \boldsymbol command to point to \bm. If \boldsymbol is called after the bm package is loaded, it is equivalent to \bm. If the bm package is not loaded, mattens defaults to the \boldsymbol command.

The mattens 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.

The following options are recognized by mattens:

noformat — No symbol formatting is performed, otherwise symbols are set by default in bold italics with the \boldsymbol or \bm command.

It is important to note that the Hassenpflug requirement of easily written by hand is not fulfilled if the symbols are formatted by anything else than normal math fonts.

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.

1In the amsmath documentation, AMS recommends the \bm command of the bm package instead of the \boldsymbol command for bold italic math symbols.

3 List of mattens commands

Table 1: List of Matrix Tensor typing commands

Type  Command  Description  Output
Physical column vector \aS[⟨accent⟩]{⟨Symbol⟩}  arrow–Symbol  x ⟶
Physical row vector  \Sa[⟨accent⟩]\{⟨Symbol⟩\}  Symbol–arrow  \underrightarrow{x}
Column vector  \bS[⟨accent⟩]{⟨Symbol⟩}  bar–Symbol  x
Row vector  \Sb[⟨accent⟩]{⟨Symbol⟩}  Symbol–bar  x
Physical tensor  \aSa[⟨accent⟩]\{⟨Symbol⟩\}  arrow–Symbol–arrow  \overrightarrow{\underrightarrow{E}}
Tensor (mixed base)  \aSb[⟨accent⟩]\{⟨Symbol⟩\}  arrow–Symbol–bar  \overrightarrow{\underline{E}}
Tensor (mixed base)  \bSa[⟨accent⟩]\{⟨Symbol⟩\}  bar–Symbol–arrow  \overline{\underrightarrow{E}}
Tensor  \bSb[⟨accent⟩]\{⟨Symbol⟩\}  bar–Symbol–bar  \overline{\underline{E}}
Cross-product tensor^{a} \aCSa[⟨accent⟩]\{⟨Symbol⟩\} arrow–CSymbol–arrow  \overrightarrow{\underrightarrow{w̃}}
Cross-product tensor  \bCSb[⟨accent⟩]\{⟨Symbol⟩\}  bar–CSymbol–bar  \overline{\underline{w̃}}

aIt is defined as the tensor \overline{\underline{ã}} associated with the vector a, where a× c = \overline{\underline{ã}}· c

3.1 General syntax

The general syntax of the mattens commands is

\αSγ[⟨accent⟩]{⟨Symbol⟩} \αCSγ[⟨accent⟩]{⟨Symbol⟩} \αSγ *[⟨accent⟩]{⟨Symbol⟩} \αCSγ *[⟨accent⟩]{⟨Symbol⟩}

with command names \bS, \aS, \aSa, \aSb, etc. See Tab. 1 for a full list of all the commands. 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 bm documentation).

An example of the usage is

     \aS{e}    \aS*{e}  e ⟶ e ⟶
     \Sb{x}    \Sb*{x}  x  x
     \aCSa\{z\}  \aCSa*\{z\}           \overrightarrow{\underrightarrow{z̃}} \overrightarrow{\underrightarrow{z̃}}

The optional argument ⟨accent⟩ is intended for L^{A}TEX accent commands such as \dot, \ddot, etc., or their AMS equivalents, \Dot, \Ddot.

     \bS[\ddot]{x}  ẍ

The mattens commands look ahead for sub- and superscripts in order to place them at the correct horizontal and vertical positions.

     \bS[\dot ]{x}^s_i  x_{i}^{^{˙ s}}
     \bS[\ddot]{x}_i^s  x_{i}^{^{¨ s}}
     \bSa\{E\}^k                     \overline{\underrightarrow{E}}^{k}
     \aSb\{E\}_s                     \overrightarrow{\underline{E}}_{s}

These commands, including the sub- and superscripts, can be used in text mode.

     Vector \bS{x}^s_i{} in text. Vector x_{i}^{s} in text.

The commands are also robust and can be used in moving commands such as footnotes^{2}, headers, etc.

     \footnote{A vector \aS{e}_i{} in a footnote}

The symbols scale to the appropriate sizes if used in sub- and superscripts. For example, for an integration path parameterized by the vector r^{s}(ξ), the equation for a line integral

    \begin{equation*}
       \oint\limits_{\bS{r}^s(\xi)}  \dotsi
     \end{equation*}

gives

∮_{r^{s}(ξ)} ⋯

2A vector ⟶ e_{i} in a footnote

4 Symbol formatting commands

4.1 Bold italic symbols

The symbol format can be set with the package options

     \usepackage{mattens}  Uses \boldsymbol as default
     \usepackage[noformat]{mattens}  No symbol formatting

or anywhere in the document with the command

       \SetSymbFont{⟨font-command⟩}

The bm package reroutes the \boldsymbol command to point to \bm. If \SetSymbFont{\boldsymbol} is called after the bm package is loaded, it is equivalent to \SetSymbFont{\bm}. Bold formatting of individual tensors can also be switched off with the use of the starred forms of the tensor commands.

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 OT1 encoding, you can put in the preamble

     \DeclareMathAlphabet{\mathsfsl}{OT1}{cmss}{m}{sl}

Examples of formats are

     \SetSymbFont\{\bm\}             \overrightarrow{\underline{E}}_{s}
     \SetSymbFont\{\relax\}          \overrightarrow{\underline{E}}_{s}
     \SetSymbFont\{\mathsfsl\}       \overrightarrow{\underline{E}}_{s}

Only the first symbol (or group) in multi-symbol constructions is formatted. This can be used to obtain

     \bS{{}xy} \bS*{xy}  xy xy
     \bS{xy}  xy
     \bS{{xy}}  xy

or

     \bCSb*\{\bS\{x\}+\bS\{y\}\}         \overline{\underline{x̃ + y}}
     \bSb\{E_\{313\}\}^s_r             \overline{\underline{E_{313}}} _{r}^{s}

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 mathptm package for Times fonts. If bold italic symbols are needed for Times fonts, it is advisable to use the txfonts package or one of the commercial fonts.

4.2 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

     \usepackage{mattens}  No strut as default
     \usepackage[mathstrut]{mattens}  Uses \mathstrut

or anywhere in the document with the command

       \SetSymbStrut{⟨strut⟩}

For example

     \SetSymbStrut{\mathstrut}
     \bSb\{E\}, \bS\{f\}, \Sb\{y\}         \overline{\underline{E}}, x, y
     \SetSymbStrut{\vphantom{E}}
     \bSb\{E\}, \bS\{f\}, \Sb\{y\}         \overline{\underline{E}}, x, y
     \SetSymbStrut{\relax}
     \bSb\{E\}, \bS\{f\}, \Sb\{y\}         \overline{\underline{E}}, x, y

4.3 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:

       \SetArrowSkip{⟨muskip length⟩}

\SetBarSkip{⟨muskip length⟩}

       \SetSymSuBSkip{⟨muskip length⟩}
       \SetSymSuPSkip{⟨muskip length⟩}

The length units must be in math units (mu), where 18 mu = 1 em (a little less than the width of the letter “M”).

5 Additional commands

5.1 Saving equations

The mattens commands use a large number of calculations. When the same symbol is used repetitively throughout a document, a command

       \DeclareSBox{⟨\cmd⟩}{⟨contents⟩}

is provided that saves the ⟨contents⟩ in a savebox \MTbox@cmd. It then defines a command \cmd that expands to \usebox{\MTbox@cmd}.

It is very important to remember that it is the fully expanded version of the ⟨contents⟩ that is saved and not the macros. If \cmd is used in a different environment the contents will retain the settings they were declared with. The saved boxes (and commands) are defined globally so that the contents of the box are not destroyed when a group is exited.

     {\large\DeclareSBox{\Le}{\bS{e}^s}}
     {\small\DeclareSBox{\se}{\bS{e}^s}}
     Test \Le\ and \se\ here.  Test e^{s} and e^{s} here.

This command is also useful for saving other objects such as the graphics of logos that are used repetitively.

5.2 Helper commands

When matrices and tensors are typed, there are some commands that occur frequently and these are therefore included in the mattens package.

\SB{⟨argument⟩}

This command puts square brackets, [...], around its argument, and can be used in text mode. The square brackets are preferred for the first level delimiter to indicate that we are dealing with matrices.

     $\SB\{\bSb\{E\}^s_r\}^\{-1\}$  [ \overline{\underline{E}}_{r}^{s}]^{−1}
     $\SB{\bS{x}+\bS{y}\,}$  [ x + y]

This command is provided if it does not already exist.

\norm{⟨argument⟩} $\norm{\aS{x}}=x$  ∥ x ⟶∥ = x

 \tdot

This command, which is shorthand for \ensuremath{{\cdot}}, sets a half-high dot to indicate matrix multiplication. It can be used in text mode.

$\bS{x}^s =
  \bSb\{E\}_r^s\tdot\bS\{x\}^r$ x^{s} = \overline{\underline{E}}_{r}^{s}·x^{r}
 \trnsp

This command types the matrix transpose symbol ,T.

$\SB\{\bSb\{E\}^s_r\}^\trnsp$  [ \overline{\underline{E}}_{r}^{s}]^{T}

6 Other programs, classes and packages

PDFL^{A}TEX — The mattens package works fine, but some workarounds were necessary when the pdftex.def driver is loaded with the color, hyperref or graphics packages. The main problem it the \usebox command that functions differently from standard L^{A}TEX. This is because pdftex does not implement a colour stack such as in the dvips driver, but simulate it at TEX macro level.

hyperref — When tensor symbols are set in chapter and section headers, hyperref crashes if the \texorpdfstring command is not used.

     \section{A header with \texorpdfstring{\bS{x}^i_j}{xij}\ in it}

color — To change the colour of a symbol the \color command must be grouped two levels deep to survive all the expansions if the bm package is loaded.

     \aSb\{\{\{\color\{red\}E\}\}\}_i      \overrightarrow{\underline{E}}_{i}

slide — The Euler math fonts are definitely compulsory. The ratio of the sub- and superscript sizes to normal math font sizes is too big inside the slide class. For tensors such as ^{j} x_{k}, you may find that the sub- and superscripts overlap. Choose your script characters carefully.

eulervm — The Hassenpflug ideal of symbols that are easily written by hand is satisfied with the beautiful letters of the Euler fonts. This package is a must for presentation material, but please do not use bold Euler symbols, they just do not look right! accents — For the creation of alternative accents the mattens package is fully com-

patible with the accents package. As an example of its usage, the equation in Hassenpflug[1], §10.1, p.82

      \SetSymbFont{\relax}
      \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*}

which gives

apparent velocity = \frac{∂_{r}}{dt} r ⟶ = r ⟶^{.r} = \overrightarrow{\underline{E}}_{s}·r^{s^{.r}} ≡ ⟶ v_{app} = ⟶ v_{rel}

bm — The 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:

          \bmdefine{\bO}{\mathit{\Omega}}
          \bSb*\{\bO_i\}                              \overline{\underline{Ω_{i}}}

7 Typesetting the Hassenpflug notation in L^{A}TEX

7.1 Why?

The Hassenpflug notation contains symbols such as, ⟶ e_{i}, ^{^{˙ r}} x_{α}, ˙ \overline{\underrightarrow{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 ...

\bS[\dot]{f}^a_b f_{b}^{^{˙ a}} (correct typesetting)

     $\dot\{\overline\{f\}\}^a_b$      ˙      \overline{f}_{b}^{a}
     $\dot\{\overline\{f\}\}\{\}^a_b$     ˙    \overline{f}_{b}^{a}
     $\dot\{\overline\{f\}^a_b\}$       ˙      \overline{f}_{b}^{a}

When a subscript is inserted for slanted characters, e.g., f_{b}^{a}, the subscript is kerned closer to the symbol. This subscript kerning as well as the superscript height is retained for math accents, e.g., ḟ_{b}^{a}. When the \overline or \overrightarrow commands are used together with math accents, the problems begin^{3}:

• For an \overline, \overline{f}_{b}^{a}, the superscript moves up to the height of the overline, which is fine for vector notation, but the subscript kerning is lost, because the symbol is set inside a box with italic correction added (App. G of the TEXbook). If the subscript is added inside the \overline construct, \overline{f_{b}}^{a}, the overline is stretched, which is acceptable only when the subscript is part of the symbol itself. The subscript kerning can be corrected by attaching the subscript to the symbol and the superscript to the overline and then overtyping (\rlap or \llap) them while using a phantom symbol (without subscript) for the overline,

     \leavevmode\rlap{$f^{}_b$}$\overline{\phantom{f}}^a$

which gives f_{b}^{a}.

The \leavevmode command is nessesary to prevent the symbol being spread over two lines when it is the first token in a new paragraph (TEX in vertical mode).

Care must be taken with the sequence in which the two parts overlap when the symbol (including subscript) is wider than the overline, f_{abcd}^{a}, because the subscript will then run into the following text.

• If a math accent is added to the overline, ˙ \overline{f}_{b}^{a}, the superscript goes to the level of the accent (except if the accents package is loaded). This can be remedied by controlling the height of the accented overline construction with \smash and \vphantom commands,

     \leavevmode\rlap{$f^{}_b$}%
     ${\smash{\dot{\overline{\phantom{f}}}}\vphantom{\overline{f}}}^a$

which gives ^{^{˙ a}} f_{b}.

• For an \overrightarrow in vector notation, (\overrightarrow{i}_{a}, \overrightarrow{iiii}_{a}), the construction of the stretchable arrow results in an arrow wider than most symbols, with the symbol centred below it. The subscript ended up far removed from the symbol. For multiple symbols, the arrow width is equal to the box containing the letters, resulting in better-looking subscripts (but still without the subscript kerning). The previous procedure can be used to correct the subscript kerning, except that additional white space must be inserted before the symbol to centre it beneath the arrow.

3If you are using Equation Editor or MathType inside word processors in the Windows environment, you end up with the same problems and have to fiddle every sub- and superscript individually. A browse through the accompanying sample document, mtsample.tex, will show that this can amount to hundreds of little equations. I challenge anyone to rewrite that document with one of the popular wordprocessors and still be sane afterwards :-)

     \newlength{\ArrWdth}\settowidth{\ArrWdth}{$\overrightarrow{i}$}
     \newlength{\SymWdth}\settowidth{\SymWdth}{$i$}
     \newlength{\Wspace}\setlength{\Wspace}{0.5\ArrWdth}
     \addtolength{\Wspace}{-0.5\SymWdth}
     \leavevmode\rlap{$\hspace*{\Wspace}i^{}_b$}%
     ${\smash{\dot{\overrightarrow{\phantom{i}}}}%
                   \vphantom{\overrightarrow{i}}}^a$

which gives i_{b}^{˙⟶}^{a}

The commands can be optimized by using saveboxes, but the symbols will not scale correctly when used as sub- or superscripts or in the \tfrac macro. A solution is to nest the commands inside a \mathpalette environment, but be warned, this is very expensive! The commands \phantom, \smash, \overrightarrow (in amsmath) are already inside \mathpalette macros, and TEX calls the arguments of a \mathpalette macro four times before deciding on the dimensions. The next piece of code simulates a \mathpalette by using the amsmath command \text. Take a guess at the value of cnt.

     \newcounter{cnt}
     \newcommand*{\Sym}[1]{%
         \boldsymbol{{#1\addtocounter{cnt}{1}}}}
     $Q_\text{\leavevmode\rlap%
           {$\Sym{x}_i$}%
          ${\smash{\dot{\overrightarrow{\phantom{\Sym{x}}}}}%
            \vphantom{\overrightarrow{\Sym{x}^j}}}$%
        }$ ~~cnt $=$ \thecnt

It gives the correct scaled tensor Q_{_{x_{i}} ˙⟶} (proper white space before symbol not implemented)

This piece of code is nominated as the worst L^{A}TEX code, in terms of efficiency, that has ever been written. But before voting, load the accents package, rerun it, and then cast your vote.

• 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. So, people at Y&Y or Bluesky, please do not update your font.

• The subscript heights differ for the cases with and without superscripts, x_{b}, x_{b}^{a}. This is not very satisfactory for a consistent matrix-tensor notation, but it can be remedied by inserting a dummy superscript, $x^{}_b$, which then gives x_{b}, x_{b}^{a}.

The mattens package was developed to overcome (some of) the above-mentioned problems and to typeset the Hassenpflug matrix tensor symbols in a consistent manner.

7.2 To do’s

• The vertical spacing between the symbols and the lines and arrows differs, \overrightarrow{\underline{E}}, \overline{\underrightarrow{E}}. This problem cannot be fixed easily and would need some additional struts or even a rewriting of the arrows and lines commands.

• For the purists: The ends of the \overrightarrow are rounded (ligature of symbols), while the ends of the \overline are squared (TEX line drawing).

• mattens does not yet work with the xspace package.

7.3 Bugs, etc.

I am sure there is much room for improvement, because I am a TEXnatic and not a TEXpert and to quote Knuth from the TEXbook:

Always remember, however, that there’s usually a simpler and better way to do something than the first way that pops into your head. You may not have to resort to any subterfuge at all, since TEX is able to do lots of things in a straightforward way. Try for simple solutions first.

Please send all bug reports, suggestions, advice or code improvements to:

Danie Els Department of Mechanical Engineering University of Stellenbosch Private Bag X1, Matieland 7602, South Africa.

                       e-mail: dnjels@sun.ac.za

8 The Code: mattens.sty

1 ⟨∗package⟩

8.1 Identification

 2 \NeedsTeXFormat{LaTeX2e}
 3 \ProvidesPackage{mattens}[2001/12/09 v1.0 DNJ Els]

8.2 Packages

The amsmath package is loaded to provide the scalable \overrightarrow and \underrightarrow commands, as well as the \boldsymbol command for setting bold math symbols.

 4 \RequirePackage{amsmath}

8.3 Workaround commands

\MT@Overarrow \MT@Underarrow We define over- and under-arrows that bypass the \mathpalette part of the ams-

math macros \overrightarrow and \underrightarrow. It uses the amsmath
internal macros \overarrow@, \underarrow@ and \rightarrowfill@. The first

parameter #1 consists of math styles \displaystyle, \textstyle, etc. The second parameter #2 is the symbol or character.

 5 \newcommand{\MT@Overarrow}[2]{\overarrow@{\rightarrowfill@}{#1}{#2}}
 6 \newcommand{\MT@Underarrow}[2]{\underarrow@{\rightarrowfill@}{#1}{#2}}

\MT@Overline \MT@Underline Make over- and underlines with the same calling syntax as the arrows.

 7 \newcommand{\MT@Overline}[2]{{#1\overline{#2}}}
 8 \newcommand{\MT@Underline}[2]{{#1\underline{#2}}}

\xusebox The \usebox command does not function properly when the pdftex.def driver is loaded, because pdftex does not implement a colour stack such as in the dvips driver, but simulate it at TEX macro level. The \xusebox is a workaround where an additional \begingroup, \endgroup is placed around the \usebox command^{4}. A strut is added after the box to regain its height.

 9 \newcommand{\xusebox}[1]{%
10 \setbox\z@\null%
11 \ht\z@\ht#1%
12 \dp\z@\dp#1%
13 \begingroup%
14  \usebox{#1}%
15 \endgroup%
16 \box\z@}

4Thanks to Heiko Oberdiek for this workaround

8.4 Options

\MT@SymbStrt \SetSymbStrut Struts to set all the lines and arrows at predetermined heights and depths.

17 \newcommand*{\MT@SymbStrt}{}
18 \newcommand*{\SetSymbStrut}[1]{\renewcommand*{\MT@SymbStrt}{#1}}
19 \SetSymbStrut{\relax}
20 \DeclareOption{mathstrut}{\SetSymbStrut{\mathstrut}}

\MT@SymbFnt \SetSymbFont Initialize the symbol font formatting commands.

21 \newcommand*{\MT@SymbFnt}{\relax}
22 \newcommand*{\SetSymbFont}[1]{\renewcommand*{\MT@SymbFnt}{#1}}
23 \SetSymbFont{\boldsymbol}
24 \DeclareOption{noformat}{\SetSymbFont{\relax}}

Process the options

25 \DeclareOption*{%
26  \PackageWarning{mattens}{Unknown option \CurrentOption}}
27 \ProcessOptions\relax

8.5 Initialize

Define skip lengths for insertion in front of sub- and superscripts.

28 \newmuskip{\MT@Askip}
29 \newmuskip{\MT@Bskip}
30 \newmuskip{\MT@SPskip}
31 \newmuskip{\MT@SBskip}

\SetArrowSkip \SetBarSkip \SetSymSuPSkip \SetSymSuBSkip Define commands to set or change the skip lengths and set initial values.

32 \newcommand*{\SetArrowSkip}[1]{\MT@Askip#1}
33 \newcommand*{\SetBarSkip}[1]{\MT@Bskip#1}
34 \newcommand*{\SetSymSuPSkip}[1]{\MT@SPskip#1}
35 \newcommand*{\SetSymSuBSkip}[1]{\MT@SBskip#1}
36 \SetArrowSkip{0mu}
37 \SetBarSkip{1mu}
38 \SetSymSuBSkip{0mu}
39 \SetSymSuPSkip{0mu}

8.6 Main mattens commands

Setup command templates and lengths to function as global variables and pointers.

\MT@accent The \MT@accent command points to the math accent that are inserted as the optional argument inside the main mattens commands.

40 \newcommand*{\MT@accent}{}

\MT@cmd \MT@@cmd The commands \MT@cmd and \MT@cmd do the actual typesetting of the symbols.

41 \newcommand*{\MT@cmd}{}
42 \newcommand*{\MT@@cmd}{}

They can be seen as function pointer that are set with \let commands inside the main mattens commands to point to specific commands.

Cmd Primary command Secondary command

\aS: \MT@cmd ↦ \MT@OverAandB, \MT@@cmd ↦ \MT@Overarrow
\bS: \MT@cmd ↦ \MT@OverAandB, \MT@@cmd ↦ \MT@Overline
\Sa: \MT@cmd ↦ \MT@UnderAandB, \MT@@cmd ↦ \MT@Underarrow
\Sb: \MT@cmd ↦ \MT@UnderAandB, \MT@@cmd ↦ \MT@Underline
\bSb: \MT@cmd ↦ \MT@DoubleAandB, \MT@@cmd ↦ \MT@@bSb
\aSb: \MT@cmd ↦ \MT@DoubleAandB, \MT@@cmd ↦ \MT@@aSb
\bSa: \MT@cmd ↦ \MT@DoubleAandB, \MT@@cmd ↦ \MT@@bSa
\aSa: \MT@cmd ↦ \MT@DoubleAandB, \MT@@cmd ↦ \MT@@aSa
\bCSb: \MT@cmd ↦ \MT@DoubleAandB, \MT@@cmd ↦ \MT@@bCSb
\aCSa: \MT@cmd ↦ \MT@DoubleAandB, \MT@@cmd ↦ \MT@@aCSa

\MT@SuBskip \MT@SuPskip Define math skip lengths to insert in front of the sub- and superscripts. The values are set inside the main mattens commands according to the type of symbol.

43 \newmuskip\MT@SuBskip
44 \newmuskip\MT@SuPskip

The following commands are the main mattens commands that set up all the global variables and pointers and then calls the command \MT@GetScrpts to extract the sub- and superscripts and which then in turn calls the global pointer \MT@cmd to do the typesetting. It first checks if the command is starred and set the bold italic formatting accordingly.

\ifMT@bold A boolean if bold italic formatting is on or off

45 \newif\ifMT@bold
46 \MT@boldfalse

{\aS \atop \@aS} Type the tensor: x ⟶

47 \DeclareRobustCommand*{\aS}{%
48 \@ifstar{\MT@boldfalse\@aS}{\MT@boldtrue\@aS}}
49 \newcommand*{\@aS}[2][\@empty]{%
50 \let\MT@accent=#1%
51 \let\MT@cmd=\MT@OverAandB%
52 \let\MT@@cmd=\MT@Overarrow%
53 \MT@SuPskip=\MT@Askip%
54 \MT@SuBskip=\MT@SBskip%
55 \MT@GetScrpts{#2}}%

{\bS \atop \@bS} Type the tensor: x

56 \DeclareRobustCommand*{\bS}{%
57 \@ifstar{\MT@boldfalse\@bS}{\MT@boldtrue\@bS}}
58 \newcommand*{\@bS}[2][\@empty]{%
59 \let\MT@accent=#1%
60 \let\MT@cmd=\MT@OverAandB%
61 \let\MT@@cmd=\MT@Overline%
62 \MT@SuPskip=\MT@Bskip%
63 \MT@SuBskip=\MT@SBskip%
64 \MT@GetScrpts{#2}}%

{\Sa \atop \@Sa} Type the tensor: x ⟶

65 \DeclareRobustCommand*{\Sa}{%
66 \@ifstar{\MT@boldfalse\@Sa}{\MT@boldtrue\@Sa}}
67 \newcommand*{\@Sa}[2][\@empty]{%
68 \let\MT@accent=#1%
69 \let\MT@cmd=\MT@UnderAandB%
70 \let\MT@@cmd=\MT@Underarrow%
71 \MT@SuPskip=\MT@SPskip%
72 \MT@SuBskip=\MT@Askip%
73 \MT@GetScrpts{#2}}%

{\Sb \atop \@Sb} Type the tensor: x

74 \DeclareRobustCommand*{\Sb}{%
75 \@ifstar{\MT@boldfalse\@Sb}{\MT@boldtrue\@Sb}}
76 \newcommand*{\@Sb}[2][\@empty]{%
77 \let\MT@accent=#1%
78 \let\MT@cmd=\MT@UnderAandB%
79 \let\MT@@cmd=\MT@Underline%
80 \MT@SuPskip=\MT@SPskip%
81 \MT@SuBskip=\MT@Bskip%
82 \MT@GetScrpts{#2}}%

{\bSb \atop \@bSb} Type the tensor: \overline{\underline{E}}

83 \DeclareRobustCommand*{\bSb}{%
84 \@ifstar{\MT@boldfalse\@bSb}{\MT@boldtrue\@bSb}}
85 \newcommand*{\@bSb}[2][\@empty]{%
86 \let\MT@accent=#1%
87 \let\MT@cmd=\MT@DoubleAandB%
88 \let\MT@@cmd=\MT@@bSb%
89 \MT@SuPskip=\MT@Bskip%
90 \MT@SuBskip=\MT@Bskip%
91 \MT@GetScrpts{#2}}

{\aSb \atop \@aSb} Type the tensor: \overrightarrow{\underline{E}}

 92 \DeclareRobustCommand*{\aSb}{%
 93 \@ifstar{\MT@boldfalse\@aSb}{\MT@boldtrue\@aSb}}
 94 \newcommand*{\@aSb}[2][\@empty]{%
 95 \let\MT@accent=#1%
 96 \let\MT@cmd=\MT@DoubleAandB%
 97 \let\MT@@cmd=\MT@@aSb%
 98 \MT@SuPskip=\MT@Askip%
 99 \MT@SuBskip=\MT@Bskip%
100 \MT@GetScrpts{#2}}

{\bSa \atop \@bSa} Type the tensor: \overline{\underrightarrow{E}}

101 \DeclareRobustCommand*{\bSa}{%
102 \@ifstar{\MT@boldfalse\@bSa}{\MT@boldtrue\@bSa}}
103 \newcommand*{\@bSa}[2][\@empty]{%
104 \let\MT@accent=#1%
105 \let\MT@cmd=\MT@DoubleAandB%
106 \let\MT@@cmd=\MT@@bSa%
107 \MT@SuPskip=\MT@Bskip%
108 \MT@SuBskip=\MT@Askip%
109 \MT@GetScrpts{#2}}

{\aSa \atop \@aSa} Type the tensor: \overrightarrow{\underrightarrow{E}}

110 \DeclareRobustCommand*{\aSa}{%
111 \@ifstar{\MT@boldfalse\@aSa}{\MT@boldtrue\@aSa}}
112 \newcommand*{\@aSa}[2][\@empty]{%
113 \let\MT@accent=#1%
114 \let\MT@cmd=\MT@DoubleAandB%
115 \let\MT@@cmd=\MT@@aSa%
116 \MT@SuPskip=\MT@Askip%
117 \MT@SuBskip=\MT@Askip%
118 \MT@GetScrpts{#2}}

\bCSb \@bCSb Type the tensor: \overline{\underline{ω̃}}

119 \DeclareRobustCommand*{\bCSb}{%
120 \@ifstar{\MT@boldfalse\@bCSb}{\MT@boldtrue\@bCSb}}
121 \newcommand*{\@bCSb}[2][\@empty]{%
122 \let\MT@accent=#1%
123 \let\MT@cmd=\MT@DoubleAandB%
124 \let\MT@@cmd=\MT@@bCSb%
125 \MT@SuPskip=\MT@Bskip%
126 \MT@SuBskip=\MT@Bskip%
127 \MT@GetScrpts{#2}}

\aCSa \@aCSa Type the tensor: \overrightarrow{\underrightarrow{ω̃}}

128 \DeclareRobustCommand*{\aCSa}{%
129 \@ifstar{\MT@boldfalse\@aCSa}{\MT@boldtrue\@aCSa}}
130 \newcommand*{\@aCSa}[2][\@empty]{%
131 \let\MT@accent=#1%
132 \let\MT@cmd=\MT@DoubleAandB%
133 \let\MT@@cmd=\MT@@aCSa%
134 \MT@SuPskip=\MT@Askip%
135 \MT@SuBskip=\MT@Askip%
136 \MT@GetScrpts{#2}}

8.7 Sub- and superscripts

This part of the code looks ahead for sub- and superscripts and put those tokens into the global variables (commands) \MT@suB and \MT@suP. If there are sub-and superscripts present then the flags \ifMT@@suB and \ifMT@@suP are set accordingly. These variables are stored for the final typesetting with the commands

\MT@setsuB, \MT@setsuBS and \MT@setsuP.

\ifMT@@suB \ifMT@@suP Define flags that are set inside the extraction commands if sub- or superscripts are present.

137 \newif\ifMT@@suB
138 \newif\ifMT@@suP

\MT@suB \MT@suP Define global variables (commands) that contains the extracted sub- and superscripts. These commands are redefined inside the extraction commands.

139 \newcommand*{\MT@suB}{}
140 \newcommand*{\MT@suP}{}

\MT@GetScrpts The first extraction command. It looks ahead for ^or _, if not present, then calls the typesetting command pointer \MT@cmd with empty sub- and superscripts, otherwise passes the tokens on to the next extraction commands.

141 \newcommand*{\MT@GetScrpts}[1]{%
142  \@ifnextchar^%
143  {\MT@GetsuP{#1}}%
144  {\@ifnextchar_%
145  {\MT@GetsuB{#1}}%
146  {\MT@@suBfalse%
147  \MT@@suPfalse%
148  \ensuremath{\MT@cmd{#1}}}}}

\MT@GetsuP Extract and typeset calls of the form ⟨Sym⟩^⟨sup⟩ if there are no further _tokens available, otherwise pass the tokens on to the next extraction command.

149 \def\MT@GetsuP#1^#2{%
150  \@ifnextchar_%
151  {\MT@GetsuPsuB{#1}{#2}}%
152  {\MT@@suBfalse%
153  \MT@@suPtrue%
154  \renewcommand*{\MT@suP}{#2}%
155  \ensuremath{\MT@cmd{#1}}}}

\MT@GetsuB Extract and typeset calls of the form ⟨Sym⟩_⟨sub⟩ if there are no further ^tokens available, otherwise pass the tokens on to the next extraction command.

156 \def\MT@GetsuB#1_#2{%
157  \@ifnextchar^%
158  {\MT@GetsuBsuP{#1}{#2}}%
159  {\MT@@suBtrue%
160  \MT@@suPfalse%
161  \renewcommand*{\MT@suB}{#2}%
162  \ensuremath{\MT@cmd{#1}}}}

\MT@GetsuPsuB Extract and typeset calls of the form ⟨Sym⟩^⟨sup⟩_⟨sub⟩.

163 \def\MT@GetsuPsuB#1#2_#3{%
164  \MT@@suBtrue%
165  \MT@@suPtrue%
166  \renewcommand*{\MT@suB}{#3}%
167  \renewcommand*{\MT@suP}{#2}%
168  \ensuremath{\MT@cmd{#1}}}

\MT@GetsuBsuP Extract and typeset calls of the form ⟨Sym⟩_⟨sub⟩^⟨sup⟩.

169 \def\MT@GetsuBsuP#1#2^#3{%
170  \MT@@suBtrue%
171  \MT@@suPtrue%
172  \renewcommand*{\MT@suB}{#2}%
173  \renewcommand*{\MT@suP}{#3}%
174  \ensuremath{\MT@cmd{#1}}}

The next commands are for the actual typesetting of the saved sub- and superscripts. These commands are called from within the main typesetting command pointed to by \MT@cmd.

\MT@setsuB Type _{⟨mskip⟩⟨sub⟩} if subscript is present.

175 \newcommand*{\MT@setsuB}{%
176  \ifMT@@suB
177  _{\mskip\MT@SuBskip\relax\MT@suB}%
178  \fi}

\MT@setsuBS Type ^{}_{⟨mskip⟩⟨sub⟩} if subscript is present.

179 \newcommand*{\MT@setsuBS}{%
180  \ifMT@@suB
181  ^{}_{\mskip\MT@SuBskip\relax\MT@suB}%
182  \fi}

\MT@setsuP Type ^{⟨mskip⟩⟨sup⟩} if superscript is present.

183 \newcommand*{\MT@setsuP}{%
184 \ifMT@@suP
185  ^{\mskip\MT@SuPskip\relax\MT@suP}%
186 \fi}

8.8 Symbol formatting

\MT@Symb This command type {⟨strut⟩⟨font-cmd⟩⟨symb⟩}, the formatted symbol preceded by the selected strut. It is called from within the main typesetting commands.

187 \newcommand*{\MT@Symb}[1]{%
188 \MT@SymbStrt%
189 \ifMT@bold\MT@SymbFnt#1\else#1\fi}

\MT@SymbC Puts a widetilde over the symbol for the cross product tensors.

190 \newcommand*{\MT@SymbC}[1]{%
191 \MT@SymbStrt\widetilde{%
192 \ifMT@bold\MT@SymbFnt#1\else#1\fi}}

8.9 Main typesetting commands

The commands in this section are the ones pointed to by the \MT@cmd and \MT@@cmd commands to perform the typesetting of the full tensor symbol. Declare some save boxes

193 \newsavebox{\MT@Abox}   % for overline/arrow
194 \newsavebox{\MT@Sbox}   % for symbol
195 \newsavebox{\MT@Tbox}   % for tempories
196 \newsavebox{\MT@APbox}  % for overline/arrow phantom
197 \newsavebox{\MT@SPbox}  % for symbol phantom

and some lengths.

198 \newlength{\MT@SPwdth}  % symbol width
199 \newlength{\MT@BPwdth}  % Bar width
200 \newlength{\MT@Wwdth}   % leading whitespace width

\MT@OverAandB This command generates the tensor symbols e ⟶ and e. It utilizes the \mathpalette macro for the sizing of the final tensor. L^{A}TEX commands \smash and \phantom with embedded \mathpalette calls are avoided to prevent nested \mathchoice calls.

201 \newcommand*{\MT@OverAandB}{%
202 \mathpalette\MT@@OverAandB}

\MT@@OverAandB For this command the first parameter #1 is supplied by \mathpalette and consists of math styles \displaystyle, \textstyle, etc. The second parameter #2 is the original ⟨symbol⟩ from the call \MT@cmd{⟨symbol⟩}. The command \xusebox is used in place \usebox because of compatibility problems with pdftex.def.

203 \newcommand*{\MT@@OverAandB}[2]{%

Set the symbol inside a box for measurement purposes.

204  \sbox{\MT@Tbox}{$\m@th#1\MT@Symb{#2}$}%

Make phantom symbol box (empty) with size identical to symbol.

205  \setbox\MT@SPbox\null%
206  \ht\MT@SPbox\ht\MT@Tbox%
207  \dp\MT@SPbox\dp\MT@Tbox%
208  \wd\MT@SPbox\wd\MT@Tbox%

Make overline/overarrow over phantom symbol box for measurement.

209  \sbox{\MT@APbox}{$\m@th#1\MT@@cmd{#1}{\copy\MT@SPbox}$}%

Calculate width difference between symbol and arrow/overline.

210  \setlength{\MT@Wwdth}{\the\wd\MT@APbox}%
211  \addtolength{\MT@Wwdth}{-\the\wd\MT@SPbox}%

Make final symbol box with white space in front to center is beneath the arrow/over line and subscript that follows.

212  \sbox{\MT@Sbox}{$\m@th#1\hskip 0.5\MT@Wwdth\MT@Symb{#2}\MT@setsuBS$}%

Add math accent to overline/overarrow and reset box dimensions to original.

213  \sbox{\MT@Tbox}{$\m@th#1\MT@accent{\xusebox{\MT@APbox}}$}%
214  \ht\MT@Tbox\ht\MT@APbox%
215  \dp\MT@Tbox\dp\MT@APbox%

Final overline/overarrow box including accent and superscript at end.

216  \sbox{\MT@Abox}{$\m@th#1\xusebox{\MT@Tbox}\MT@setsuP$}%

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.

217  \ifdim\wd\MT@Abox<\wd\MT@Sbox%
218  \leavevmode\rlap{\xusebox\MT@Abox}{\xusebox\MT@Sbox}%
219  \else%
220  \leavevmode\rlap{\xusebox\MT@Sbox}{\xusebox\MT@Abox}%
221  \fi}

\MT@UnderAandB \MT@@UnderAandB This command generates the tensor symbols e ⟶ and e. It is identical to the previous command except the sub- and superscripts are swapped.

222 \newcommand*{\MT@UnderAandB}{%
223 \mathpalette\MT@@UnderAandB}
224 \newcommand*{\MT@@UnderAandB}[2]{%
225  \sbox{\MT@Tbox}{$\m@th#1\MT@Symb{#2}$}%
226  \setbox\MT@SPbox\null%
227  \ht\MT@SPbox\ht\MT@Tbox%
228  \dp\MT@SPbox\dp\MT@Tbox%
229  \wd\MT@SPbox\wd\MT@Tbox%
230  \sbox{\MT@APbox}{$\m@th#1\MT@@cmd{#1}{\copy\MT@SPbox}$}%
231  \setlength{\MT@Wwdth}{\the\wd\MT@APbox}%
232  \addtolength{\MT@Wwdth}{-\the\wd\MT@SPbox}%
233  \sbox{\MT@Sbox}{$\m@th#1\hskip 0.5\MT@Wwdth\MT@Symb{#2}\MT@setsuP$}%
234  \sbox{\MT@Tbox}{$\m@th#1\MT@accent{\xusebox{\MT@APbox}}$}%
235  \ht\MT@Tbox\ht\MT@APbox%
236  \dp\MT@Tbox\dp\MT@APbox%
237  \sbox{\MT@Abox}{$\m@th#1\xusebox{\MT@Tbox}\MT@setsuB$}%
238  \ifdim\wd\MT@Abox<\wd\MT@Sbox%
239  \leavevmode\rlap{\xusebox\MT@Abox}{\xusebox\MT@Sbox}%
240  \else%
241  \leavevmode\rlap{\xusebox\MT@Sbox}{\xusebox\MT@Abox}%
242  \fi}
\MT@@bSb \MT@@bSa \MT@@aSb \MT@@aSa \MT@@bCSb \MT@@aCSa These commands are pointed to by \MT@@cmd and called from within \MT@DoubleAandB.

It has the same calling syntax as the \MT@Overarrow and \MT@Underarrow commands.

243 \newcommand*{\MT@@bSb}[2]{\MT@Overline{#1}{\MT@Underline{#1}{\MT@Symb{#2}}}}
244 \newcommand*{\MT@@aSb}[2]{\MT@Overarrow{#1}{\MT@Underline{#1}{\MT@Symb{#2}}}}
245 \newcommand*{\MT@@bSa}[2]{\MT@Overline{#1}{\MT@Underarrow{#1}{\MT@Symb{#2}}}}
246 \newcommand*{\MT@@aSa}[2]{\MT@Overarrow{#1}{\MT@Underarrow{#1}{\MT@Symb{#2}}}}
247 \newcommand*{\MT@@bCSb}[2]{\MT@Overline{#1}{\MT@Underline{#1}{\MT@SymbC{#2}}}}
248 \newcommand*{\MT@@aCSa}[2]{\MT@Overarrow{#1}{\MT@Underarrow{#1}{\MT@SymbC{#2}}}}

\MT@DoubleAandB \MT@@DoubleAandB This command is used for the remaining tensor symbols and is not so complex compared to the previous commands.

249 \newcommand*{\MT@DoubleAandB}{%
250 \mathpalette\MT@@DoubleAandB}
251 \newcommand*{\MT@@DoubleAandB}[2]{%
252  \sbox{\MT@Abox}{$\m@th#1\MT@@cmd{#1}{#2}$}%
253  \sbox{\MT@Tbox}{$\m@th#1\MT@accent{\xusebox{\MT@Abox}}$}%
254  \ht\MT@Tbox\ht\MT@Abox%
255  \dp\MT@Tbox\dp\MT@Abox%
256  \xusebox{\MT@Tbox}\MT@setsuP\MT@setsuB}

8.10 A save/recall box utility

\DeclareSBox \MT@cname \MT@bname \MT@bnameuse For the command \DeclareSBox{⟨\cmd⟩}{⟨contents⟩}, it saves the ⟨contents⟩

in a savebox \MTbox@cmd. It then defines a command \cmd that expands to

 \usebox{\MTbox@cmd}.

First a safety check if internal commands exist.

257 \newcommand*{\MT@cname}{}    % ->  <cmd>
258 \newcommand*{\MT@bname}{}    % ->  MTbox@<cmd>
259 \newcommand*{\MT@bnameuse}{} % ->  \MTbox@<cmd>

Here the main command

260 \newcommand{\DeclareSBox}[2]{%
261  \edef\MT@cname{\expandafter\@gobble\string#1}%
262  \edef\MT@bname{MTbox@\MT@cname}%
263  \@ifundefined{\MT@cname}{%
264  \edef\MT@bnameuse{\csname\MT@bname\endcsname}%
265  \expandafter\newbox\MT@bnameuse%
266  \global\sbox{\MT@bnameuse}{#2}%

In the next declaration \xdef was replaced by \protected@xdef and an additional \protect was added before the \xusebox command. This was nessesary to be compatable with pdftex.def^{5}.

267  \protected@xdef#1{\protect\xusebox{\MT@bnameuse}}%

268 }%

269  {\PackageError{mattens}%
270  {Command \space\protect#1\space allready\space defined!}%
271  {Use\space a\space different\space name}}}

8.11 Helper utility functions

\cdot \trnsp \norm \SB The following is a set of very simple utility macro’s inside mattens to ease the typesetting of matrix–tensor stuff. They can all be used in text mode.

272 \newcommand*{\tdot}{\ensuremath{{\cdot}}}                % Center dot
273 \newcommand*{\trnsp}{\ensuremath{\mathsf{T}}}            % Matrix transpose
274 \providecommand*{\norm}[1]{\ensuremath{\lVert{#1}\rVert}}% Norm delimiters
275 \newcommand*{\SB}[1]{\ensuremath{\left[\, #1\right]}}    % Square brackets

276 ⟨/package⟩

5Thanks to Heiko Oberdiek and Robin Fairbairns for this advice.

References

[1] Hassenpflug, W. C., “Matrix Tensor Notation Part I. Rectilinear Orthogonal Coordinates,” Comput. Math. Appl., 26(3), 1993, pp. 55–93.

[2] Hassenpflug, W. C., “Matrix Tensor Notation Part II. Skew and Curved Coordinates,” Comput. Math. Appl., 29(11), 1993, pp. 1–103.

Index

Numbers written in italic refer to the page where the corresponding entry is described; numbers underlined refer to the code line of the definition; numbers in roman refer to the code lines where the entry is used.

Symbols

\@Sa . . . . . . . . . . . . . . . . . . . . . . . . \underline{65} \@Sb . . . . . . . . . . . . . . . . . . . . . . . . \underline{74} \@aCSa . . . . . . . . . . . . . . . . . . . . . . \underline{128} \@aS . . . . . . . . . . . . . . . . . . . . . . . . \underline{47} \@aSa . . . . . . . . . . . . . . . . . . . . . . . \underline{110} \@aSb . . . . . . . . . . . . . . . . . . . . . . . \underline{92} \@bCSb . . . . . . . . . . . . . . . . . . . . . . \underline{119} \@bS . . . . . . . . . . . . . . . . . . . . . . . . \underline{56} \@bSa . . . . . . . . . . . . . . . . . . . . . . . \underline{101} \@bSb . . . . . . . . . . . . . . . . . . . . . . . \underline{83}

A

\aCSa . . . . . . . . . . . . . . . . . . . . . 5, \underline{128} \aS . . . . . . . . . . . . . . . . . . . . . . 5, \underline{47} \aSa . . . . . . . . . . . . . . . . . . . . . . 5, \underline{110} \aSb . . . . . . . . . . . . . . . . . . . . . . 5, \underline{92}

B

\bCSb . . . . . . . . . . . . . . . . . . . . . 5, \underline{119} \bS . . . . . . . . . . . . . . . . . . . . . . 5, \underline{56} \bSa . . . . . . . . . . . . . . . . . . . . . . 5, \underline{101} \bSb . . . . . . . . . . . . . . . . . . . . . . 5, \underline{83}

C

\cdot . . . . . . . . . . . . . . . . . . . . . . . \underline{272}

D

\DeclareSBox . . . . . . . . . . . . . . . 9, \underline{257}

I

\ifMT@@suB . . . . . . . . . . \underline{137}, 176, 180 \ifMT@@suP . . . . . . . . . . . . . . \underline{137}, 184 \ifMT@bold . . . . . . . . . . . \underline{45}, 189, 192

M

\MT@@aCSa . . . . . . . . . . . . . . . 133, \underline{243} \MT@@aSa . . . . . . . . . . . . . . . . 115, \underline{243} \MT@@aSb . . . . . . . . . . . . . . . . . 97, \underline{243} \MT@@bCSb . . . . . . . . . . . . . . . 124, \underline{243} \MT@@bSa . . . . . . . . . . . . . . . . 106, \underline{243} \MT@@bSb . . . . . . . . . . . . . . . . . 88, \underline{243} \MT@@cmd …. \underline{41}, 52, 61, 70, 79, 88,

97, 106, 115, 124, 133, 209, 230, 252

\MT@@DoubleAandB . . . . . . . . . . . . . \underline{249}

\MT@@OverAandB . . . . . . . . . . . 202, \underline{203} \MT@@suBfalse . . . . . . . . . . . . 146, 152 \MT@@suBtrue . . . . . . . . . 159, 164, 170 \MT@@suPfalse . . . . . . . . . . . . 147, 160 \MT@@suPtrue . . . . . . . . . 153, 165, 171 \MT@@UnderAandB . . . . . . . . . . . . . . \underline{222} \MT@Abox . . . . . . . . . . . . 193, 216–

218, 220, 237–239, 241, 252–255 \MT@accent . . \underline{40}, 50, 59, 68, 77, 86,

95, 104, 113, 122, 131, 213, 234, 253 \MT@APbox . . . . . . . . . . . . 196, 209,

210, 213–215, 230, 231, 234–236 \MT@Askip . . . . . . . . . . . . . . 28, 32,

53, 72, 98, 108, 116, 117, 134, 135 \MT@bname . . . . . . . . . . . . . . . . . . . \underline{257} \MT@bnameuse . . . . . . . . . . . . . . . . . \underline{257} \MT@boldfalse . . . . . . . . . . . 46, 48,

57, 66, 75, 84, 93, 102, 111, 120, 129 \MT@boldtrue . . . . . . . . . . . . . . 48,

57, 66, 75, 84, 93, 102, 111, 120, 129 \MT@BPwdth . . . . . . . . . . . . . . . . . . 199 \MT@Bskip . . . . . . . . . . . . . . . . 29,

33, 62, 81, 89, 90, 99, 107, 125, 126 \MT@cmd . . . . . . . . . . . . . . . . . . \underline{41},

51, 60, 69, 78, 87, 96, 105, 114, 123, 132, 148, 155, 162, 168, 174

\MT@cname . . . . . . . . . . . . . . . . . . . \underline{257}

\MT@DoubleAandB . . . . . . . . . . . . . .

… 87, 96, 105, 114, 123, 132, \underline{249} \MT@GetScrpts . . . . . . . . 55, 64, 73,

82, 91, 100, 109, 118, 127, 136, \underline{141} \MT@GetsuB . . . . . . . . . . . . . . 145, \underline{156} \MT@GetsuBsuP . . . . . . . . . . . . 158, \underline{169} \MT@GetsuP . . . . . . . . . . . . . . 143, \underline{149} \MT@GetsuPsuB . . . . . . . . . . . . 151, \underline{163} \MT@OverAandB . . . . . . . . . . 51, 60, \underline{201} \MT@Overarrow …. \underline{5}, 52, 244, 246, 248 \MT@Overline . . . . . \underline{7}, 61, 243, 245, 247 \MT@Sbox . . . . . . . . . . . . . 194, 212,

217, 218, 220, 233, 238, 239, 241 \MT@SBskip . . . . . . . . . . 31, 35, 54, 63 \MT@setsuB . . . . . . . . . . \underline{175}, 237, 256 \MT@setsuBS . . . . . . . . . . . . . . \underline{179}, 212 \MT@setsuP . . . . . . . \underline{183}, 216, 233, 256 \MT@SPbox 197, 205–209, 211, 226–230, 232 \MT@SPskip . . . . . . . . . . 30, 34, 71, 80 \MT@SPwdth . . . . . . . . . . . . . . . . . . 198 \MT@suB … \underline{139}, 161, 166, 172, 177, 181 \MT@SuBskip …. \underline{43}, 54, 63, 72, 81,

90, 99, 108, 117, 126, 135, 177, 181 \MT@suP . . . . . . \underline{139}, 154, 167, 173, 185 \MT@SuPskip . . . . . . . \underline{43}, 53, 62, 71,

80, 89, 98, 107, 116, 125, 134, 185 \MT@Symb \underline{187}, 204, 212, 225, 233, 243–246 \MT@SymbC . . . . . . . . . . . \underline{190}, 247, 248 \MT@SymbFnt . . . . . . . . . . . \underline{21}, 189, 192 \MT@SymbStrt . . . . . . . . . . \underline{17}, 188, 191 \MT@Tbox 195, 204, 206–208, 213–216,

225, 227–229, 234–237, 253–256 \MT@UnderAandB . . . . . . . . . 69, 78, \underline{222} \MT@Underarrow … \underline{5}, 70, 245, 246, 248 \MT@Underline …. \underline{7}, 79, 243, 244, 247 \MT@Wwdth . . . . . 200, 210–212, 231–233 \MTbox@ . . . . . . . . . . . . . . . . . . . . . 259

N \norm . . . . . . . . . . . . . . . . . . . . . 9, \underline{272}

O \overarrow@ . . . . . . . . . . . . . . . . . . . 5

R

                                       \rightarrowfill@ . . . . . . . . . . . . 5, 6

S \Sa . . . . . . . . . . . . . . . . . . . . . . 5, \underline{65} \SB . . . . . . . . . . . . . . . . . . . . . . 9, \underline{272} \Sb . . . . . . . . . . . . . . . . . . . . . . 5, \underline{74} \SetArrowSkip . . . . . . . . . . . . . . 8, \underline{32} \SetBarSkip . . . . . . . . . . . . . . . . 8, \underline{32} \SetSymbFont . . . . . . . . . . . . . . . 7, \underline{21} \SetSymbStrut . . . . . . . . . . . . . . 8, \underline{17} \SetSymSuBSkip . . . . . . . . . . . . . 8, \underline{32} \SetSymSuPSkip . . . . . . . . . . . . . 8, \underline{32}

T \tdot . . . . . . . . . . . . . . . . . . . . 10, 272 \trnsp . . . . . . . . . . . . . . . . . . . 10, \underline{272}

U \underarrow@ . . . . . . . . . . . . . . . . . . 6

X \xusebox …. \underline{9}, 213, 216, 218, 220,

234, 237, 239, 241, 253, 256, 267

Change History

1.0 General: Initial version . . . . . . . . 1