Carl Milsted, Jr on Sep 11 18:33:52
Here's a quick tutorial to get you started writing equations in QTML.
Let's dive in with a simple example, Albert Einstein's famous equation relating mass and energy:
To typeset the equation above, I typed in the following code:
.eqn 1 e = m c sup 2 ..eqn
The
eqn
QTML tag begins a display equation. For an inline equation, such as
, use the
eqni
tag. The
eqn
tag takes an optional argument which is the equation number or label. Notice
the 1 that shows up to the right of the equation above.
In between the QTML tags, you describe your equation in the venerable
eqn language developed by Brian Kernighan and Lorinda Cherry back in the
1970s for the UNIX operating system. (With some extensions, described below.)
Behind the scenes, the Conntects QTML converter sends your equations to an upgraded version of the GNU version of eqn, with flags to generate MathML, the HTML standard for displaying equations. For some email clients, such as Thunderbird, you can copy the MathML generated here on Conntects and send equations to your friends. Alas, some email clients such as gmail and yahoo mail do not render MathML correctly — yet.
The eqn language is well documented in Typesetting Mathematics — a User's Guide (Second Edition) by Kernighan and Cherry. There are some differences between GNU eqn and what is described in this document, which are described below.
So, let's begin the quick tour to get you hooked, and then you can look at the linked document if you want to get fancy.
Looking back at equation 1, the equation was typed in just as you would do
intuitively, save that I used the
sup
keyword to create a superscript. Baby stuff! And if you need subscripts, just
use the
sub
keyword.
For our next keyword, let's drop back to Newton's formula for kinetic energy:
Which was made with:
.eqn 2 e = 1 over 2 m v sup 2 ..eqn
To make upright fractions, just use the
over
keyword.
Let's make a fancier fraction:
.eqn 3 v sub x = { DELTA x } over { DELTA t } ..eqn
Not only did we get to use a subscript to denote the component of the velocity, we have multiple symbols on the top and bottom of the fraction. To group symbols together for any operator, use curly braces. Finally, we get our first taste of Greek letters. To make a capital Greek delta, spell out DELTA in all capitals. For a small delta, just use the word delta. Likewise for any other Greek letter. (Some capital Greek letters look identical to a Latin letter. In those cases you should generally stick with the Latin letter, such as A instead of ALPHA. Also, to make typing easier you can just capitalize the first letter of Greek letters, such as Gamma instead of GAMMA, as in pure eqn.)
Let's get a wee bit fancier and do the Quadratic Formula:
.eqn 5 x = {- b +- sqrt {b sup 2 - 4 a c}} over {2 a} ..eqn
To get a square root sign, use the keyword
sqrt
.For other roots, fractional powers are usually best. But you can sort of do
other roots by superscripting the keyword
nothing
prior to the square root sign:
.eqn 5b rho = nothing sup 3 sqrt {2.3 + sigma sup 2} ..eqn
You can also use a pair of double quotes instead of the keyword
nothing
.
Let's move on to power series:
.eqn 6 sum from {i=1} to inf left ( 1 over 2 right ) sup i = 1 ..eqn
We have the new
sum
keyword for summation,
inf
for infinity,
and the all important
left
and
right
keywords. The latter two make parentheses grow big enough to
enclose the expression they contain. These keywords can also
be used for square brackets, curly braces, vertical lines and
more. In fact, to make curly braces visible, you have to use left
or right.
The
from
and
to
keywords work for products, integrals, and more. For example:
.eqn 7 int from 0 to 1 x sup 2 dx = left [ x sup 3 over 3 right ] sub 0 sup 1 ..eqn
Decorating Your Variables
Mere letters are not sufficient to denote vector quantities. There are two conventions. The first is to put an arrow over vector quantities.
.eqn 8 F vec = m a vec ..eqn
The second is to make vector quantities bold:
.eqn 9 bold F = m bold a ..eqn
I prefer the latter, as it leaves room for other decorations:
.eqn 10 bold PI sub e = bold PI tilde sub e e sup {i k z} ..eqn
If you go wild with decorated variables in a long post, it's nice to
take some shortcuts. For this purpose there is the
define
statement. For example, I could have rewritten the previous equation
thusly.
.eqn 11 define Pve bold PI sub e define Pvet bold PI tilde sub e Pve = Pvet e sup {i k z} ..eqn
So far, this has bought me nothing. But here's the deal: defines carry over to subsequent equations in the same post or comment! For example:
.eqn 12 phi = - del cdot epsilon Pve ..eqn
A long time ago in a state far far away, I made extensive use of such defines in order to typeset my doctoral dissertation.
It's time to get really fancy:
.eqn 13 roman {Let}~ y~ = left { lpile{ 1 above 0 } ~~~lpile { if~x > 2 above if ~ x <=2} right " " ..eqn
We have several new things to deal with. First the
roman
keyword renders to next block of characters in a Roman font.
Tildes [things thingies: ~~~] act as spacers. (If you want
a half space use a circumflex [^].)
The
pile
stacks things over each other with the
above
keyword as a separator. This is a family of keywords with
lpile
for left justified piles,
pile
for centered piles
and
rpile
for right justified piles.
Finally, note how I used a left brace without a matching right brace.
According to the original eqn specification, a
left
does not need a corresponding
right
. But with the GNU version of eqn, I get a big ugly NULL on the
right if I don't have a corresponding
right
something.
To get the above to work, I added double quotes with a couple of blanks
after the keyword
right
.
This is one place where the freeware hasn't caught up with the original
product.
I could go on to describe how to use piles and braces to build column vectors and matrices, but I'm getting tired, and I've either got your interest going or I haven't. If I have gotten your interest going, look at the old official manual for eqn. It's only eleven pages. Print it out if you are serious about writing equations.
Eqn is easier to type than TeX. Eqn keywords and macros don't need a backslash
for a prefix, and it is easier to type
sup
and
sub
than it is to use punctuation for superscripts and subscripts.
But raw eqn is pretty lame when it comes to supported symbols. It doesn't even have those upside down A and backwards E thingies used for math logic out of the box.
Fortunately, thanks to Unicode, you can define symbols like this:
define oppA "\[u2200]"
You need the quotes in the expression above, and that dreaded backslash. The number is the binary number for the Unicode code point desired. Use capital letters for the hexadecimal A-F digits and leading zeroes if you have less than four digits.
But all this is work, so I extended eqn by adding a large list of predefined symbols. First, I just took the tables of symbols available from Leslie Lamport's LaTeX, A Document Preparation System , ditched the backslashes, and mapped them to Unicode values. The result:
varepsilon | vartheta | varpi | |||
varrho | varsigma | varphi | |||
Gamma | Delta | Theta | |||
Lambda | Xi | Pi | |||
Sigma | Upsilon | Phi | |||
Psi | Omega |
pm | mp | div | |||
ast | star | circ | |||
bullet | cap | cup | |||
uplus | sqcap | sqcup | |||
vee | wedge | setminus | |||
wr | diamond | bigtriangleup | |||
bigtriangledown | triangleleft | triangleright | |||
lhd | rhd | unlhd | |||
unrhd | oplus | ominus | |||
otimes | oslash | odot | |||
bigcirc | dagger | ddagger | |||
amalg |
leq | prec | preceq | |||
ll | subset | subseteq | |||
sqsubset | sqsubseteq | in | |||
vdash | geq | succ | |||
succeq | gg | supset | |||
supseteq | sqsupset | sqsupseteq | |||
ni | dashv | equiv | |||
sim | simeq | asymp | |||
cong | neq | doteq | |||
propto | models | perp | |||
mid | parallel | bowtie | |||
Join | smile | frown |
leftarrow | Leftarrow | rightarrow | |||
Rightarrow | leftrightarrow | Leftrightarrow | |||
mapsto | hookleftarrow | leftharpoonup | |||
leftharpoondown | rightleftharpoons | longleftarrow | |||
Longleftarrow | longrightarrow | Longrightarrow | |||
longleftrightarrow | Longleftrightarrow | longmapsto | |||
hookrightarrow | rightharpoonup | rightharpoondown | |||
leadsto | uparrow | Uparrow | |||
downarrow | Downarrow | updownarrow | |||
Updownarrow | nearrow | swarrow | |||
swarrow | nwarrow |
aleph | hbar | imath | |||
jmath | ell | wp | |||
Re | Im | mho | |||
emptyset | nabla | surd | |||
top | bot | angle | |||
forall | exists | neg | |||
flat | natural | sharp | |||
infty | Box | Diamond | |||
triangle | clubsuit | diamondsuit | |||
heartsuit | spadesuit |
The above lists miss a few symbols which I considered to be obvious, so I threw in some:
therefore | |
because | |
ratio | |
proportional | |
nsubset | |
nsupset | |
nsubseteq | |
nsupseteq | |
langle | |
rangle | |
bra | |
ket | |
nexists | |
nin | |
nni | |
ring | |
deg | |
anglert | |
thorn | |
Thorn | |
eth | |
Eth |
Some of the above match the eqnchar macro names put out by AT&T, but not all.
When troff was created, you needed separate font files for both font styles and for non-ASCII symbols. Today, we have Unicode. The easiest way to use the code points for different math font styles was to put a prefix before Latin letters to get a different style.
Prefix | Name |
---|---|
ds | Double Stroke |
frak | Fraktur |
bfrak | Bold Fraktur |
scr | Script |
bscr | Bold Script |
ss | Sans Serif |
bss | Bold Sans Serif |
For example the eqn code
.eqn scrA hat = {bscrA} over scrA ..eqn
yields
The resulting available symbols:
Letter\Prefix | ds | frak | bfrak | scr | bscr | ss | bss |
---|---|---|---|---|---|---|---|
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 | |||||||
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 |
You need to be logged in to comment