Conntects Tutorials

Assorted help pages and references.

This is an open blog, owned by Carl Milsted, Jr.

You are not subscribed to this blog. Click the subscribe button if desired.


Current Post

Equations in QTML

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:

1
e=mc2

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 e=mc2 , 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.

A Quick Tour of Eqn

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:

2
e=12mv2

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:

3
vx=ΔxΔt
.eqn 3
v sub x = { DELTA x } over { DELTA t }
..eqn

Not only did we get to use a subscript to denote the x 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:

5
x=b±b24ac2a
.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

5b
ρ=32.3+σ2

You can also use a pair of double quotes instead of the keyword nothing.

Let's move on to power series:

6
Σi=1(12)i=1
.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:

7
01x2dx=[x33]01
.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.

8
F=ma
.eqn 8
F vec = m a vec
..eqn

The second is to make vector quantities bold:

9
F=ma
.eqn 9
bold F = m bold a
..eqn

I prefer the latter, as it leaves room for other decorations:

10
Πe=Π~eeikz
.eqn 10
bold PI sub e = bold PI tilde sub e e sup {i k z}
..eqn

Macros

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.

11
Πe=Π~eeikz
.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:

12
φ=·εΠe
.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.

Piles and Columns

It's time to get really fancy:

13
Let  y  ={10      if  x>2if  x2
.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.

Extending Eqn

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:

Greek Letters, Tex Style

varepsilon ε vartheta ϑ varpi ϖ
varrho ϱ varsigma ς varphi φ
Gamma Γ Delta Δ Theta Θ
Lambda Λ Xi Ξ Pi Π
Sigma Σ Upsilon Υ Phi Φ
Psi Ψ Omega Ω

Binary Operators

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 ⨿

Relation Symbols

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

Arrows

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

Miscellaneous Tex Symbols

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

And a Few Not from Tex

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.

Font Faces

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 𝕫 𝔷 𝖟 𝓏 𝔃 𝗓 𝘇


Tags: equatons QTML


0 COMMENTS

You do not have sufficient clearance to comment


Drag the picture you want to upload into the large box below. You can use the controls to edit the picture to be uploaded. This will not affect the picture on your hard disk.

Or, if you are on a tablet or phone, or don't like Drag and Drop, you can select a picture using this

Get a modern browser to make picture uploads

Rotation:
Up Right Down Left

Brightness:
1.0

Color Balance:
Red: 1.0
Green: 1.0
Blue: 1.0
Gray: 1.0

Contrast:
0.0

Cropping:
Slide the boxes with triangles along the edges of the picture to crop.

(Picture below can be dragged if need be.)