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
END
gives
_ _ 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?
Enjoy!
(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.
Thanks David, but the hard work was done by the C code authors Przemek Borys and Bart Pieters.
Also I have already pushed a version 0.02 which handles warnings from the C level functions and allows setting the number of text columns.
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).
oylenshepeegul, yeah, I actually have been working on that. The arrayref interface was easy to implement completely in C, but I have already given that up. The Perl level render now calls crender internally, so I can now do some data munging afterwards.
The biggest holdup is that since I am targeting POD rendering I want to be able to tack a leading whitespace on the front of each line when desired. Perhaps the POD hook should just call the list context functionality and munge it itself.
Either way, look for something like this in a 0.03 release.
That is way cool! I wish I had a reason to use it! :)