# Software to render formulas to ASCII art

I guess all computer algebra systems have command line interfaces which render formula as 2D monospace "ascii art". But the only standalone tool to render TeX to 2D I know is tex2mail (comes with PARI/GP).

Are there other standalone programs or libraries for that task, preferably making advantage of various Unicode symbols? Or maybe there is a CAS capable for that.

FriCAS:

            ┌──┐
x   \│%A
┌┐  %e
│   ─────── d%A
└┘       2
%A


tex2mail:

         +-+
,- \|x   2
| e    /x    dx
-'


Maxima:

     /   sqrt(x)
[ %e
I --------- dx
]     2
/    x


Those are meant to represent:

$$\int \frac{e^{\sqrt x}}{x^2} \, dx$$

• I have to ask... why?? May 24, 2012 at 17:45
• Because it's BOSS! May 24, 2012 at 18:02
• @AsafKaragila mostly to output a formula to console. May 24, 2012 at 19:09
• I see. Thank you for the answer. If I had to choose between the above examples or a very complicated $\TeX$ code, I'd choose the $\TeX$. That's just me, though. May 24, 2012 at 19:14
• Good lord. That is hideous. If you're stuck in ASCII, it's a million times better to write "the indefinite integral of (exp(root x))/(x^2))dx", or something like that.
– Newb
Apr 15, 2015 at 6:55

You can use this Web Application: Diagon

• Supports ASCII and Unicode.
• Supports other kind of ASCII art diagrams.

## Examples:

sum(i^2, i=0, n) = n^3/2+n^2/2+n/6

output (Unicode)

n
___        3    2
╲     2   n    n    n
╱    i  = ── + ── + ─
‾‾‾        2    2   6
i = 0

output (ASCII):

n
===        3    2
\     2   n    n    n
/    i  = -- + -- + -
===        2    2   6
i = 0


mult(i^2, i=1, n) = (mult(i, i=1, n))^2

                    2
n        ⎛  n    ⎞
━┳┳━   2   ⎜━┳┳━   ⎟
┃┃   i  = ⎜ ┃┃   i⎟
i = 1      ⎝i = 1  ⎠


sqrt(1 + sqrt(1 + x/2))

     _____________
╱        _____
╱        ╱    x
╱        ╱ 1 + ─
╲╱   1 + ╲╱      2


[1,2; 3,4] * [x; y] = [1*x+2*y; 3*x+4*y]

⎛1 2⎞   ⎛x⎞   ⎛1 ⋅ x + 2 ⋅ y⎞
⎜   ⎟ ⋅ ⎜ ⎟ = ⎜             ⎟
⎝3 4⎠   ⎝y⎠   ⎝3 ⋅ x + 4 ⋅ y⎠


int(x^2/2 * dx ,0 ,1) = n^3/6

1
⌠  2         3
⎮ x         n
⎮ ── ⋅ dx = ──
⌡  2         6
0


phi = 1 + 1/(1+1/(1+1/(1+1/(1+...))))

                 1
φ = 1 + ───────────────────
1
1 + ───────────────
1
1 + ───────────
1
1 + ───────
1 + ...


Disclaimer: I am the author.

It is an open source project under the MIT license.

• Wonderful answer :-) Welcome on the MathSE! :-) Jun 1, 2018 at 21:07

At this site one can get following:

Input:

int(int(int(psi^2, x = -inf .. inf), y = -inf .. inf), z = -inf .. inf) = 1

Output:

   oo    oo    oo
/     /     /
|     |     |    2
|     |     | psi  dx dy dz = 1
|     |     |
/     /     /
-oo   -oo   -oo


Input:

sqrt(e) = 1+1/(1+1/(1+1/(1+1/(5+1/(1+1/(1+1/(9+1/(1+1/(1+...)))))))))

Output:

  _                          1
\/e = 1 + ---------------------------------------
1
1 + -----------------------------------
1
1 + -------------------------------
1
1 + ---------------------------
1
5 + -----------------------
1
1 + -------------------
1
1 + ---------------
1
9 + -----------
1
1 + -------
1 + ...


Input:

e^x = 1 + x + x^2/2! + x^3/3! + x^4/4! + ... = 1 + sum(x^n/n!, n = 1 .. inf)

Output:

                                       oo
2    3    4             =====  n
x           x    x    x              \     x
e  = 1 + x + -- + -- + -- + ... = 1 +  >    --
2!   3!   4!             /     n!
=====
n = 1


Input:

(1/4)pisqrt(2) = sum((-1)^(k+1)/(4*k + 1) + (-1)^(k+1)/(4*k - 3), k = 1 .. inf) = 1 + 1/3 - 1/5 - 1/7 + 1/9 + 1/11 - ...

Output:

            oo
===== /    k + 1       k + 1\
1 __   _   \     |(-1)        (-1)     |       1   1   1   1    1
- || \/2 =  >    |--------- + ---------| = 1 + - - - - - + - + -- - ...
4          /     \ 4 k + 1     4 k - 3 /       3   5   7   9   11
=====
k = 1


Input:

sin(a)/a = cos(a/2) * cos(a/4) * cos(a/8) * cos(a/16) * ... = prod(cos(a/2^n), n = 1 .. inf)

Output:

                                        oo
=====
sin a       a     a     a      a        | |       a
----- = cos - cos - cos - cos -- ... =  | |  cos --
a         2     4     8     16        | |       n
| |      2
n = 1


Input:

lim(1/x^2 - (cos(x)/x)^2, x -> inf) = 1

Output:

        /            2\
| 1   /cos x\ |
lim    |-- - |-----| | = 1
| 2   \  x  / |
x -> oo \x            /


Finally,

$$\int \frac{e^{\sqrt x}}{x^2} \, dx$$

is represented as

Input:

int(e^sqrt(x)/x^2 , x)

Output:

  /
|    _
|  \/x
| e
| ---- dx
|   2
|  x
|
/


I've edited a bit tex2mail to use Unicode for output. Here are the results:

                                      ┌──────┐
┌─┐  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


The look depends hugely on the fonts and the browser. If you are interested in the script here is the link.

• As long as you're using Unicode, why not also replace oo with ∞, --> with →, and so on? You might also consider using Unicode's sub- and superscripted characters whenever possible to save vertical space.
– user856
Jun 9, 2012 at 20:22
• @RahulNarain Well, --> should be ⟶, not →. However the space occupied by ⟶ depends on the font and the renderer, which can ruin the formatting. Same story with many others characters, even with ⊗. For my taste is ∞ is too small compared to oo. Well, it is ubelievebly easy to make such substitutions. If one wants he may do it, however the results might not be good. Jun 9, 2012 at 20:24
• @RahulNarain As for the sub and superscripts, I just think that they are small and poorly readable. Anyway, implementing this is beyond my Perl skills. Jun 9, 2012 at 20:32

If you are on *NIX platforms you can use asciitex.

There is also aamath which does a great job in traslating the equation to ascii text files.

If you don't want to install anything locally take a look at http://ascii.gallery/matheq which I believe is a web wrapper over aamath.

• I noticed ascii.gallery is moved. Use the new url textart.io/matheq
– dors
Oct 29, 2018 at 20:04

A lot of the answers here mention tools that output to ASCII but if you're open to using Unicode then I found this really nice script: https://github.com/Pomax/tex2utf. But do note that from a quick glance over the repository the author doesn't seem keen on maintaining or fixing any issues with this script (who can blame him, it's written in perl).

### Example

Input:

g(x) = \int_1^{1/x} \frac{1}{t} f \cdot \left ( \frac{1}{t} \right ) dt


Output:

        ╭ 1/x 1      ╭ 1 ╮
g(x) =  |     ─ f  · │ ─ │ dt
╯ 1   t      ╰ t ╯


For comparison: $$g(x) = \int_1^{1/x} \frac{1}{t} f \cdot \left ( \frac{1}{t} \right ) dt$$