↑ TeX ↑↑ Home  

Favourite maths TeX macros

Unit matrix -- Long arrows -- Bold maths -- Fraction spacing -- Inline graphics -- Complex signs

Given in the order of ascending complexity.

Unit matrix

A unit matrix is customarily denoted by a 1 with a double vertical stroke. However, I could not find such a symbol anywhere in the AMS or other font packages. So I wrote a macro for it myself. Two \rules are used to draw the second stroke and to extend the baseline.

\def\dblone{\hbox{$1\hskip -1.2pt\vrule depth 0pt height 1.6ex width 0.7pt
                  \vrule depth 0pt height 0.3pt width 0.12em$}}

Long arrows

The AMS fonts give us a numer of arrows which come in two lengths, normal and long. For still longer arrows, one can extend them with minus signs or equals signs (for double arrows). Some negative spaces have to be inserted to make the lines join up:

\def\llra{%
\setbox0=\hbox{$-\!$}
\hbox{\copy0 \copy0 \copy0 \copy0 \copy0 \copy0 \copy0 \copy0 $\longrightarrow$}}
\def\llla{%
\setbox0=\hbox{$\!-$}
\hbox{$\longleftarrow$\copy0 \copy0 \copy0 \copy0 \copy0 \copy0 \copy0 \copy0}}
\def\llda{%
\setbox0=\hbox{$\vert$}
\dimen0=-1\wd0
\hbox to \wd0{%
\raise 2em \copy0 \kern\dimen0 %
\raise 1em \copy0 \kern\dimen0 %
\copy0 \kern\dimen0 %
\lower 1em \copy0 \kern\dimen0 %
\lower 1.9em \hbox to \wd0{\hss $\downarrow$\hss}}
}

The first two are arrows pointing right and left. Their lengths are suitable for commuting algrebra diagrams. The third is a vertical downward arrow for the same application. An upward arrow is left as an exercise ;).

Formulas in bold face

For obtaining small greek charaters or symbols in boldface in math mode, define the macro below. (The usual \mathbf won't do in these cases.)

% bold face in formulas
\def\mbf#1{\mathchoice{\hbox{\boldmath $\displaystyle #1$}}
        {\hbox{\boldmath $\textstyle #1$}}
        {\hbox{\boldmath $\scriptstyle #1$}}
        {\hbox{\boldmath $\scriptscriptstyle #1$}}}

The \mathchoice command chooses one of four expressions depending on whether it is in a displayed formula or a text formula, in the exponent (or subscript) or in the exponent of an exponent. It is necessary here because otherwise the inside of the \hbox would always be set in text style, regardless of the context.

Fraction spacing

The following will increase the spacing between fractions. With the original LaTeX \frac, adjacent fraction bars (eg in a product) are nearly indiscernible.

% fractions look better as "math inner"
\def\frac#1#2{{\mathinner{#1 \over #2}}}

Inline graphics

The following code allows to insert graphics into equations and text. They are centered roughly on the cross bar of the plus sign. The macro's parameter is the truncated file name (without ".eps" or ".pdf"). The size of the image can be adjusted by changing the parameter height=....

% a box with graphics contered on the text line
\def\inlinegraph#1{{\setbox0=\hbox{\includegraphics[height=40mm]{#1.eps}} 
    \dimen0=0.7ex \advance\dimen0 by -0.5\ht0 \raise\dimen0\box0}}

Complex maths signs

The following macro prints an exclamation mark on top of a bidirectional arrow.

% maths "ought to be equivalent" symbol <=!=>
\def\oughttobe{{
\setbox0=\hbox{$\Longleftrightarrow$} \setbox1=\hbox{\scriptsize !}
\dimen0=-0.5\wd0 \advance\dimen0 by -0.5\wd1 
\hbox{\box0\kern\dimen0\vbox to 0pt {\vss\hbox{\raise 0.7em \box1}}}
}}

This can be generalised. The following macro puts any small sign under (putunder) or over (putover) a larger one. I inserted the \mathrel because such signs are usually relational operators ("ought to be equal" signs, limits etc.) and ought to have the appropriate spacing.

\def\putunder#1#2{\mathrel{
\setbox0=\hbox{#1}\setbox1=\hbox{\scriptsize #2}
\dimen0=-0.5\wd0 \advance\dimen0 by -0.5\wd1
\dimen1=0.5\wd0 \advance\dimen1 by -0.5\wd1
\hbox{\box0\kern\dimen0%
\vbox to 0pt {\hbox{\lower 0.7em \box1}\vss}%
\kern\dimen1}
}}

\def\putover#1#2{\mathrel{
\setbox0=\hbox{#1}\setbox1=\hbox{\scriptsize #2}
\dimen0=-0.5\wd0 \advance\dimen0 by -0.5\wd1
\dimen1=0.5\wd0 \advance\dimen1 by -0.5\wd1
\hbox{\box0\kern\dimen0%
\vbox to 0pt {\vss\hbox{\raise 0.7em \box1}}%
\kern\dimen1}
}}

To indicate the limit of an expression when epsilon approaches zero, one could write:

\putunder{$-\!\!\!\longrightarrow$}{$\epsilon\!\to\!0$}

The dollar signs have to be there even in math mode unless you define them into \putunder.