imgtex-0.20050123.orig/0000755000175000017500000000000010213730345014536 5ustar kohdakohda00000000000000imgtex-0.20050123.orig/imgtex_fcgi.txt0000644000175000017500000000735710213730164017577 0ustar kohdakohda00000000000000#!/usr/bin/perl # # Copyright (C) 2005 Koji Nakamaru # # Author: Koji Nakamaru # Created/Modified: Jan 2 2005 # Keywords: tex, latex, math, web # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with GNU Emacs; see the file COPYING. If not, write to the # Free Software Foundation, Inc., 59 Temple Place - Suite 330, # Boston, MA 02111-1307, USA. # use strict; use File::Temp qw/ mkdtemp /; use FCGI; my $cache_size_limit = 5 * 1024 * 1024; sub xerror; sub getContents; sub cacheCheck; sub cacheAdd; my $pngerr = &getContents("preverr.png"); if (! defined($pngerr)) { die "wrong installation or file system error\n"; } my %cache; my %cache_hit; my $cache_size = 0; my $tmpdir; my $fcgi = FCGI::Request(); while ($fcgi->FCGI::Accept() >= 0) { my $req = $ENV{'QUERY_STRING'}; my $png = &cacheCheck($req); if (! defined($png)) { my $res = 96; my $cmd = $req; # $cmd =~ tr/+/ /; $cmd =~ s/%([a-fA-F0-9]{2})/pack("C",hex($1))/eg; if ($cmd =~ /^\s*\[([^]]+)\](.+)\s*$/) { $cmd = $2; my $opt = $1; $opt =~ s/\s+//g; if ($opt =~ /res=(\d+)/) { $res = $1; } else { &xerror("found unknown option: $1."); next; } } if (! ($res =~ /\d+/ && 10 <= $res && $res <= 1200)) { &xerror("found res out of range [10,1000]."); next; } if ($cmd eq '') { &xerror("found no string."); next; } $tmpdir = mkdtemp("imgtexwork/tXXXXXX"); if (! open(FO, "> $tmpdir/t.tex")) { &xerror("failed to generate a tex file."); next; } print FO <<"EOF"; \\documentclass\{article\} \\usepackage\{type1cm\} \\usepackage[psamsfonts]\{amssymb\} \\usepackage\{amsmath\} \\begin\{document\} \\thispagestyle{empty} $cmd \\end\{document\} EOF close FO; if (system("ulimit -t 10 -f 1024 -c 0; cd $tmpdir ; latex '\\nonstopmode\\input' t.tex > /dev/null 2>&1 ; case \$? in 0) dvipng -q -D $res -T tight -M -pp 1 --noghostscript t.dvi -o t%03d.png > /dev/null 2>&1 ;; *) exit 1 ;; esac") != 0) { &xerror("failed to generate a dvi file."); next; } $png = &getContents("$tmpdir/t001.png"); } if (defined($png)) { &cacheAdd($req, $png); print "Content-type: image/png\r\n\r\n", $png; } else { &xerror("failed to generate a png file."); } system("rm -rf $tmpdir"); } sub xerror { my ($msg) = @_; print "Content-type: image/png\r\n\r\n", $pngerr; system("rm -rf $tmpdir"); } sub getContents { my ($fname) = @_; my $contents = undef; open FI, "< $fname" or return $contents; { local $/; $contents = ; } close FI; return $contents; } sub cacheCheck { my ($req) = @_; if (defined($cache{$req})) { $cache_hit{$req} = localtime(); return $cache{$req}; } return undef; } sub cacheAdd { my ($req, $png) = @_; $cache{$req} = $png; $cache_hit{$req} = localtime(); $cache_size += length($png); my $now = localtime(); while ($cache_size > $cache_size_limit) { my $key0 = undef; my $hit0 = $now; foreach my $key (keys(%cache_hit)) { my $hit = $cache_hit{$key}; if ($hit < $hit0) { $key0 = $key; $hit0 = $hit; } } if (defined($key0)) { $cache_size -= length($cache{$key0}); $cache{$key0} = undef; $cache_hit{$key0} = undef; } } } imgtex-0.20050123.orig/imgtex_inc_php.txt0000644000175000017500000000444210213730164020277 0ustar kohdakohda00000000000000 // Created/Modified: Jan 21 2005 // Keywords: tex, latex, math, web, imgtex // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation; either version 2, or (at your option) // any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with GNU Emacs; see the file COPYING. If not, write to the // Free Software Foundation, Inc., 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // example usage: /* This is an example equation: &imgtex($ \exp x=1+x+\frac{1}{2!}x^2+\frac{1}{3!}x^3+... $);, which is inlined. Centering can be done as follows: CENTER:&imgtex(\[ \exp x=1+x+\frac{1}{2!}x^2+\frac{1}{3!}x^3+... \]); CENTER:&imgtex([res=200]{\[ \exp x=1+x+\frac{1}{2!}x^2+\frac{1}{3!}x^3+... \]}); */ // define('IMGTEX_PATH', '/~maru/imgtex/imgtex.fcgi'); // please specify your own imgtex.fcgi define('IMGTEX_RES', '120'); function plugin_imgtex_inline() { $args = func_get_args(); $args = join($args, ' '); $args = preg_replace('/^\s+/', '', $args); $args = preg_replace('/\s+$/', '', $args); if (preg_match('/^\[/', $args)) { $url = $args; } elseif (preg_match('/^{.*}$/', $args)) { $url = '[res=' . IMGTEX_RES . ']' . $args; } else { $url = '[res=' . IMGTEX_RES . ']{' . $args . '}'; } preg_match('/^\[res=\d+\]{(.*)}$/', $url, $matches); $alt = $matches[1]; // some preg_replace() seems to have a bug cannot handle // backslash-escaping correctly, so we use octal expressions. $alt = preg_replace('/^\s*(\134\133|\$+)\s*/', '', $alt); $alt = preg_replace('/\s*(\134\135|\$+)\s*$/', '', $alt); $url = IMGTEX_PATH . '?' . $url; return "\"$alt\""; } ?> imgtex-0.20050123.orig/preverr.png0000644000175000017500000000047510213730164016736 0ustar kohdakohda00000000000000PNG  IHDRbKGD X pHYsHHFk>IDATxK D pB]E>mY`LvAma|1aDhND/;U$j'/P&"N <Q|s#Ao ޕ R Od$Zg_D|K$kn` 隯Dm:vvHHy mz I@'7Fb6b;