Paul L. Snyder on 16 Nov 2004 21:03:31 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

PerlTeX


While delving through CTAN, I happened across PerlTeX.  This is an extremely
slick package that allows you to embed Perl into your LaTeX document.  You
can define new commands and environments in terms of Perl code, and invoke
them as regular TeX macros.

Here's a messy little toy example that sorts the words it is given,
bolds any word that includes the letter 'i', and appends the fraction
of words that contain an 'i':

 \documentstyle{article}
 \usepackage{perltex}
 \newperlcommand{\iwords}[1]{
   my @list = sort split " " $_[0];
   my $wc = @list;
   my $result = join " ", @list;
   my $ic = $result =~ s/(\b\w*i\w*\b)/\\textbf\{\1\}/g;
   return $result . " \\(\frac{$ic}{$wc}\\);
 }
 \newcommand{\str}{jackdaws love my big sphinx of quartz}
 \begin{document}
  \iwords{\str}
 \end{document}
When PerlTeX is called, it passes the following to LaTeX:

  \textbf{big} jackdaws love my of quartz \textbf{sphinx} \frac{2}{7}

which will be typeset appropriately.  I'm sure that this is possible to
do using only raw TeX, but I don't relish the thought of trying it.

 http://texcatalogue.sarovar.org/entries/perltex.html
 ftp://ftp.ctan.org/pub/tex-archive/macros/latex/contrib/perltex/perltex.pdf

I've been looking for something like this for quite a while.

Cheers,
pls
-
**Majordomo list services provided by PANIX <URL:http://www.panix.com>**
**To Unsubscribe, send "unsubscribe phl" to majordomo@lists.pm.org**