1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
|
<?php
//
// imgtex.inc.php -- imgtex plugin for pukiwiki
//
// Copyright (C) Koji Nakamaru
//
// Author: Koji Nakamaru (nakamaru at gmail.com)
// Modified: Apr 30 2005
// * changed the contact information.
// 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 "<img src=\"$url\" alt=\"$alt\" style=\"text-align:middle;margin:.25em .125em\" />";
}
?>
|