Announcing Text::AsciiTeX

The PDL community has been buzzing with activity as they prepare for the 2.4.10 release.

For those of you who are unaware, PDL is the Perl Data Language, which gives Perl numerical array processing power. Implemented in C these computations are very fast, and with its sublanguage PDL::PP you can easily write your own C implementations of numerical algorithms too.

One of the things coming in this release will be the companion PDL::Book. Its been entirely written by the developers specifically for this release. The source is all in POD of course.

While there aren’t too many formulas in the book, there will be a few. To that end I decided to look into LaTeX->”ASCII art” conversion and found that there is a nice utility called AsciiTeX, which has a command line and a GUI interface and is GPL. Since it was nicely modularized it was easy for me to pull the guts out, put an XS wrapper on it and Text::AsciiTeX was born. (N.B. updated example for version 0.03).

use Text::AsciiTeX;
say for render( <<'END' );
\int_0^W \frac{np}{n+p}dx = \int_0^W \frac{n_0}{
exp \left(\frac{E_0(x-x_0)}{kT} \right)
+exp \left( -\frac{E_0(x-x_0)}{kT}\right)
} dx


   _                 _                       n                         
  /  W  np          /  W                      0                        
  |    -----dx  =   |    ------------------------------------------- dx
 _/  0 n + p       _/  0    / E (x - x ) \       /    E (x - x )\     
                            |  0      0  |       |     0      0 |     
                        exp | ---------- | + exp |  - ----------|     
                            \     kT     /       \        kT    /

(I apologize if that doesn’t display correctly in your browser, I assure you it looks right in my terminal)

It doesn’t do the whole world of LaTeX math, but it does a surprising amount. Of course this is only half the problem, now I have to figure out how to hook this into a POD renderer. Any thoughts?


(Fork Text::AsciiTeX at GitHub)


Freaking amazing! I look forward to applying this in the PDL::Book, and working this into build and distribution tools in the future.

Instead of an array reference, how about returning an array of lines in list context and joining the lines in scalar context? We could even just print the lines in void context (fork on github).

That is way cool! I wish I had a reason to use it! :)

Leave a comment

About Joel Berger

user-pic As I delve into the deeper Perl magic I like to share what I can.