Carl Milsted, Jr

Location: somewhere in NC

The guy who coded up this social network.

Current Post

Extending Eqn

Dec 22 11:05:13

To do equations in QTML, I simply ran the text that is in between the .eqn and ..eqn tags through GNU eqn -- which is part of the groff project. Alas, there were a couple of bugs for GNU eqn in MathML mode: the approximately equal sign didn't work, nor did the lower case xi.

So I checked out the code in order to make the fixes.

Then Megalomania Kicked In

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 E thingies used for math logic out of the box.

Fortunately, thanks to Unicode, you can define symbols like this:

define oppA "\[u2200]"

I think this would work in document creation mode, but not for MathML. I added a check for Unicode macros in the MathML part of eqn, but that still made no distinction between symbols and operators.

So I decided to build in 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

I still have work to do distinguishing which of these are operators and which are just symbols.

The above list misses 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 = {bold scrA} 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 𝕫 𝔷 𝖟 𝓏 𝔃 𝗓 𝘇

I have not checked to see if this works in PostScript mode.

Anyway, since I started with GNU code, I have posted my updates to GNU eqn on Github for your copying pleasure.

There is no warranty! I did a lot of Unicode mapping by hand, so I probably botched a few symbols.



Tags: eqn qtml


3 COMMENTS
#1

Chris Price on Dec 22, 2023 6:38 PM


Impressive!


Replies:
#2

Robert Hartford on Jan 1, 2024 5:53 PM


Quite a tour de force!

I thank you!


Replies:
#3

Carl Milsted, Jr on Jan 1, 2024 7:34 PM
in response to comment_118_2


Pass along to all friends who like to talk shop over the Internet!

That's part of what Conntects is for.

P.S. I have made updates so that symbols are treated as symbols, and operators are treated as operators (more space). Not perfect, and the bug regarding left without a right is challenging to fix. It's deep within the groff code, possibly within YACC generated code which I am incapable of following. Maybe I can get the "owners" of the code to fix that bug. I'm inclined to start from scratch using Go instead of C++ than dig that deep.


Replies:

You must be logged in 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.)