↑↑ Home ↑ TeX tricks

Favourite TeX macros

Given in the order of ascending complexity.

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

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: (The respective two possibilities are equivalent)

$-\mskip -9mu\longrightarrow$  
$=\mskip -3mu\Rightarrow$

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"). The size of the image can be adjusted by changing the parameter height=....

% a box with graphics contered on the text line
    \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 <=!=>
\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 a larger one. (\putover can be defined analogously by putting the \vss in front of the \hbox and exchanging \lower by \raise, as in \oughttobe.) 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.
\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
\vbox to 0pt {\hbox{\lower 0.7em \box1}\vss}%
To indicate the limit of an expression when epsilon approaches zero, one could write:
The dollar signs have to be there even in math mode.

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$}}