Many of computer algebra systems date back to the times when GUI machines were rare and expensive, if were present at all. Thus command line was a standard interface. Unfortunately text terminal doesn’t fit very well for displaying mathematical expressions which demand for rich typesetting. To represent math formulas CAS’s resorted to some kind of ASCII art:

inf 1
==== / n n
\ [ x log (x)
> I ---------- dx
/ ] gamma(n x)
==== /
n = 0 0

That’s the output of Maxima. Some of the systems went further and don’t restrict themselves to plain ASCII. Axiom can produce such a nice output:

2
x - %A ┌──┐
┌┐ %e \│%A
│ ──────────── d%A
└┘ tan(%A) + 2

Even now most CAS’s retain command line interface, for example Mathematica 8’s terminal session:

In[14]:= Pi*(a+b^2/(Exp[12]+3/2 ">2))
2
b
Out[14]= (a + -------) Pi
3 12
- + E
2

The same technique was also spread in Usenet see whim.org for a collection of notes some of which appeared at `sci.math`

. I was even able to find “Guidelines for Using ASCII to Write Mathematics”.

If you are looking for a standalone application to render LaTeX to ASCII the only one I’ve found is `tex2mail`

, more than a decade old Perl script. Much water has flowed under the bridge since then and old character encodings were replaced by Unicode, namely UTF-8. Unicode provides lot’s of math-related symbols and naturally one wants to employ this abundant to allow for prettier output of math formulas in terminal.

I’ve tried to enhance tex2mail by turning it to tex2unicode. To some extent I’ve succeeded:

┌──────┐
┌─┐ 3 4 │ 2 6 4
⌠ \│a x ┌─┐ 3 x \│1 - x + x - 3 x
⎮ ───────── dx = \│a ──────────────────────────────────
⌡ ┌──────┐ ┌──────┐
│ 2 ⎛ 2 ⎞ │ 2 2
\│1 - x ⎝ 3 x - 12 ⎠ \│1 - x - 9x + 12
⎡ 1 ⎤n
lim ⎢ 1 + ─ ⎥ = e
n --> oo ⎣ n ⎦
n n
⌠1 x ──┐oo ⌠1 x (log x)
⎮ x dx = > ⎮ ────────── dx.
⌡0 ──┘n=0 ⌡0 n!
┬─┬oo ⎛ 1 ⎞ ⎛ ┬─┬oo 1 ⎞-1 1 1 6
│ │ ⎜ 1-── ⎟ = ⎜ │ │ ───── ⎟ = ───────────────── = ──── = ── ≈ 61%
┴ ┴p ⎜ 2 ⎟ ⎜ ┴ ┴p -2 ⎟ 1 1 ζ(2) 2
⎝ p ⎠ ⎝ 1-p ⎠ 1 + ── + ── + ∙∙∙ π
2 2
2 3

Unfortunately things turned out to be more complicated with other LaTeX commands. The problem is that some symbols like ‘⟶’ *should* be wider than others. It undermines the whole concept of monospace formatted output. To make things worse the output depends both on the font and the software. Gedit and gnome terminal treat the same string differently. Actually the only reliable symbols to enrich ASCII art are form box-drawing Unicode block.

Making a long story short. Since I don’t really need a full featured LaTeX-to-Monospace-Unicode renderer, I’ll just post what I did by now:

TeX2Unicode Perl script

If you are not content with certain LaTeX commands, for example ‘\otimes’ or ‘\to’ it is *really* easy to improve them. So don’t hesitate and adjust it for your needs. The license is whatever it was for tex2mail.in file in PARI/GP project, where I took it from. I guess it is GPLv2.