Math mode in LaTeX
Preliminery
If you are NOT fimilar with catcode, mathcode, delcode etc, please see my blog: TeX Coding or other material to learn it fisrt.
If you are not familar with LaTeX text font and math font, you can see by blog LaTeX font Guide to learn it.
font family
Unlike the font scheme(NFSS) in LaTeX, font familt in plain tex is something different. Details as below:
- math roman fonts (family 0)
- math italic fonts (family 1)
- symbol fonts (family 2)
- the extension fonts (family 3)
math atom
Each character(a,b,c
, +/-
, etc) or control sequence(\alpha
, \sum
, etc) in math fomulars has its own type, which control its spaces arround(before, after, top, below, etc) it. The math symbol type(atom type) is as follows:
When you need some new math symbols, you need to specify to which atom type this symbol should belong during declaring it.
math code
All of these commands \mathcode
, \mathcahr
, \mathchardef
are related to mathcode in TeX, which is similar to catcode in text but far more complex that it.
Plain TeX
In plain TeX, the syntax of command \mathcode
is:
1 |
|
There is a command \mathchar
– \mathchardef
similar to \char
– \chardef
for text font. See below:
XeTeX
XeTeX provides command \Umathcode
(similar to the original command \mathcode
in plain TeX). It also provides command \Umathcodenum
, which use a bit-packed
single argument.
Thus the syntax is:
1 |
|
delimiter code
Beside mathcode, catcode, there is a code called delimiter code
, you can use command \delcode
to set it. For detailed info, see: TeX Coding.
LaTeX 2e
symbol font
How many math symol font
pre-defined in LaTeX 2e ? see example below:
1 |
|
There are infinite many math symbol font, see fntguide
Page 14:
\DeclareSymbolFont {⟨sym-font⟩} {⟨encoding⟩} {⟨family⟩} {⟨series⟩} {⟨shape⟩}
. If this is the first declaration for⟨sym-font⟩
then a new symbol font with this name is created (i.e. this identifier is assigned to a new TEX math group)
So math symbol font from 3 sources:
- the predefine 4 types:
operators
,letters
,symbols
,largesymbols
- From some package: like
AMSa
,AMSb
in amsfont package;zeur
in eulervm package - The type that your define by command
\DeclareSymbolFont
operator font bug ?
Is this a Bug for \operator@font
in amsopn.sty
or ctex.sty
? See definition in latex2e: Page 631
The definition in ctex:
1 |
|
The definitions in source 2e:ltmath.dtx - Page 722
1 |
|
miscellany
strut and phantom
Reference from “The TeXbook”:
There’s a way out of this dilemma, using an important idea called a “strut.” Plain TEX defines
\strut
to be an invisible box of width zero that extends just enough above and below the baseline so that you would need no interline glue at all if every line contained a strut.
-
strut related:
\mathstrut
in math mode:
1
\DeclareRobustCommand\mathstrut{\vphantom(}
- and the
\strut
in text mode:
1
\def\strut{\relax\ifmmode\copy\strutbox\else\unhcopy\strutbox\fi}
-
phantom related:
1 |
|
math surround
Besides, you can control the space arround math atom by command \mathsurround
, a simple example:
1 |
|
Additional Reference:
TEX does, in fact, insert additional space before and after each formula; the amount of such space is called
\mathsurround
, which is a⟨dimen⟩-valued
parameter.
style in math
There are 2 commands \mathpalette
, \mathchoice
related to style in math fomulars. Definition of \mathpalette
, see:
1 |
|
What is \mathchoice
doing for us? Use different construction in different math style. Syntax of this command is:
1 |
|
An example using example for “The TeX book”:
1 |
|
The output look like:
Then you may know what \mathpalette
doing .