--- loncom/cgi/mimeTeX/mimetex.html 2006/03/24 23:08:33 1.2
+++ loncom/cgi/mimeTeX/mimetex.html 2012/06/09 00:58:11 1.5
@@ -1,10 +1,11 @@
-
+
-
+
+
+
+
+ true, // return web page
+ CURLOPT_HEADER => true); // return headers
+ $ch = curl_init( $url );
+ //curl_setopt_array( $ch, $options );
+ curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );
+ curl_setopt( $ch, CURLOPT_HEADER, true );
+ $gif = curl_exec( $ch );
+ $errno = curl_errno( $ch );
+ $error = curl_error( $ch );
+ //$info = curl_getinfo( $ch );
+ curl_close( $ch );
+ //echo '
url= ',$url,'
',"\n";
+ //echo '
gif=
',$gif,'
',"\n";
+ if ( $errno == 0 ) {
+ $fields = explode("Vertical-Align:",$gif);
+ $vfield = trim($fields[1]);
+ $fldlen = strspn($vfield,"+-0123456789");
+ $valign = substr($vfield,0,$fldlen); }
+ else {
+ echo 'verticalalign> errno ',$errno,' = ',$error,'
',"\n"; }
+ return $valign;
+ }
+ function mimetextag( $label, $expression ) {
+ global $mimetexurl;
+ $valign = verticalalign($expression);
+ $url = $mimetexurl . $expression;
+ //echo ' valign=',$valign,' ',"\n";
+ echo '';
+ echo '',$expression,'';
+ echo '', "\n";
+ }
+ ?>
+
+
+
+ This page contains more information
+ than you'll probably need to read. If you follow the
+ Installation and Usage Summary
+ below, try installing mimeTeX immediately. Or continue reading until you feel comfortable
+ trying to install mimeTeX.
+ Prerequisites are: some knowledge of your OS's shell,
+ of installing cgi's, of LaTeX.
+
+
+ "Computers are like Old Testament gods:
+ lots of rules and no mercy."
+
+ Joseph Campbell, The Power of Myth
+ (Doubleday 1988, page 18)
@@ -219,7 +352,8 @@ Table of Contents
unzip mimetex.zip cc -DAA mimetex.c gifsave.c -lm -o mimetex.cgi Now just mv mimetex.cgi to your cgi-bin/ - directory, and you're all done. | |||||||||||||||||||||||
Usage: | @@ -251,43 +385,50 @@ SECTION I. INTRODUCTION And mimeTeX is an entirely separate little program that doesn't use TeX or its fonts in any way. It's just one cgi that you put in your site's cgi-bin/ directory, with no other dependencies. So mimeTeX - is very easy to install. And it's equally - easy to use. Just place an html <img> tag in your document - wherever you want to see the corresponding LaTeX expression. - For example, -
mimeTeX | +latexrender | |
- latexrender | +mimeTeX |
- |
- ![]() |
+ + | + + |
Similar LaTeX-based solutions that you may want to look at are + mathtran, textogif and www.tug.org/interest.html and in the tex-faq.
+ + For example, mathtran
+ is a public LaTeX web service that's
+ particularly easy to use by following these simple
+ instructions. In the <head> of your
+ html page, place the tag
+
+ <script type="text/javascript"
+
+ src="http://www.mathtran.org/js/mathtran_img.js"></script>
+ and in the <body>, wherever you want to see latex images,
+ place tags like
+
+ <img alt="tex:any latex math expression">
+ For comparison,
+
+ <img alt="tex: f(x) = \frac1{\sigma\sqrt{2\pi}}
+
+ \int_{-\infty}^x e^{-\frac{(t-\mu)^2}{2\sigma^2}}dt">
+ looks like
mathtran | + |
+ mimeTeX | +
unavailable
+ |
+ + |
+ |
+
Now enter your own LaTeX expression, use the sample provided,
@@ -480,51 +709,111 @@ QUICKSTART
if you submit the sample expression
- already in the box.
And the <img> tag to embed this same integral anywhere - in your own document is
-<img src="../cgi-bin/mimetex.cgi?\large f(x)=\int_{-\infty}^xe^{-t^2}dt" - alt="" border=0 align=middle>- -
- The typical mimeTeX <img> tag has the form
+ alt="" border=0 style="Vertical-Align:-11px"> + if you submit the sample expression already in the box. + Or see error messages whenever an + unexpected image is displayed instead. And (as discussed + above) the <img> tag to embed this same integral anywhere + in your own document isHere are various additional random examples further demonstrating +
Here are various additional random examples further illustrating
mimeTeX's features and usage. To see how they're done, Click any
one of them to place its corresponding expression in the
Query Box above. Then press Submit
@@ -563,7 +852,7 @@ EXAMPLES
alt="" border=0 align=middle>    
   
@@ -671,9 +960,9 @@ EXAMPLES
Some useful scripts that automatically construct + mimeTeX <img> tags for you are illustrated below. + And you can also write your own scripts to simplify + the HTML notation required to incorporate mimeTeX + math images in your pages.
+ +
+ The following javascript snippet (based on
+ mathtran's
+ mathtran_img.js) lets you just write
+ <img alt="mimetex:c=\sqrt{a^2+b^2}">
+ wherever you want to see
<script type="text/javascript"> + <!-- + // Create a namespace to hold variables and functions + mimetex = new Object(); + // Change this to use your server + mimetex.imgSrc = "http://www.yourdomain.com/cgi-bin/mimetex.cgi?"; + // Transform the whole document: add src to each img with + // alt text starting with "mimetex:", unless img already has a src. + mimetex.init = function () { + if (! document.getElementsByTagName) return; + var objs = document.getElementsByTagName("img"); + var len = objs.length; + for (i=0; i<len; i++) { + var img = objs[i]; + if (img.alt.substring(0,8) == 'mimetex:') + if (!img.src) { + var tex_src = img.alt.substring(8); + img.src = mimetex.imgSrc + encodeURIComponent(tex_src); + // Append TEX to the class of the IMG. + img.className +=' tex'; } + } + mimetex.hideElementById("mimetex.error"); } + // Utility function + mimetex.hideElementById = function (id) { + var obj = document.getElementById(id); + if (obj) obj.style.display = 'none'; } + // resolve a cross-browser issue (see CBS events) + mimetex.addEvent = function (obj, evType, fn, useCapture) { + if (obj.addEventListener) { //For Mozilla. + obj.addEventListener(evType, fn, useCapture); + return true; } + else if (obj.attachEvent) { //For Internet Explorer. + var r = obj.attachEvent("on"+evType, fn); + return r; } + } + // Initialize after entire document is loaded + mimetex.addEvent(window, 'load', mimetex.init, false); + --> + </script>+ +
+ Bulletin boards, wikis, etc, can also incorporate mimeTeX images
+ with short scripts. For example, if you're using
+ phpBB2, then
+ Jameson
+ contributed the following typical one-line mod that lets you write
+ [tex] c=\sqrt{a^2+b^2} [/tex] to obtain the
+ same image illustrated above
#--------[open]----------------------------------------------------- + /includes/bbcode.php + #--------[find]----------------------------------------------------- + // Remove our padding from the string.. + #--------[before, add]---------------------------------------------- + $text = preg_replace('/\[tex\](.*?)\[\/tex\]/ie', + "'<img src=\"/cgi-bin/mimetex.cgi?'.rawurlencode('$1').'\" align=\"middle\" />'", + $text);+
If you're using + phpBB3, + then no mod is even needed. + Just click Postings from the Administrator Control Panel, + and add the custom BBCode [tex]{TEXT}[/tex] + with the HTML replacement + <img src="/cgi-bin/mimetex.cgi?{TEXT}" align=middle>
+ +Similarly, PmWiki + also has a + + mimeTeX plugin that lets you just write + {$ f(x)=\int_{-\infty}^xe^{-t^2}dt $} + to obtain that same image. Several other packages + also have similar mimeTeX plugins:
+Package | ++ | Plugin | +
+ + PmWiki | + | + mimeTeX plugin |
+ + + MediaWiki | ++ | + + "mimeTeX alternative" |
+ PunBB | ++ mimeTeX plugin | |
+ + Movable Type | + | mimeTeX plugin |
+ WordPress | ++ + mimeTeX plugin | |
+ Joomla | + | mimeTeX plugin |
+ Mambo | + | "mimeTeX bot" |
Please note: If you're writing your own plugin for mimeTeX, + please don't write php code using system( ), or any other + shell escape mechanism, just to cache images. Use mimeTeX's + -DCACHEPATH=\"path/\" + compile option instead. + system( ) raises security + issues, either real ones if used carelessly, or just in the minds of + system administrators. Either way, I've received many emails from + people unable to use mimeTeX because of unnecessary system( ) + calls prohibited by security-conscious sysadmins. MimeTeX itself poses + minimal risk when used as illustrated above, but you're responsible + for any plugin/wrapper script you write around it.
+ + An image like
+
+ doesn't look as good as the same image
+
+ that's vertically aligned with your surrounding text.
+ Along with several standard
+
+ HTTP header fields, mimeTeX also emits a special
+ Vertical-Align: nn
+ header, where nn is the number of pixels
+ (usually negative as illustrated) needed for a
+ style="Vertical-Align: nn px"
+ attribute in the <img> tag used to
+ render your expression. This Vertical-Align: header
+ is obtained by placing the directive \depth
+ anywhere in your expression.
But mimeTeX's special Vertical-Align: header + is unrecognized and ignored by your browser. You have to get the + header, interpret it, and write the corresponding <img> tag. + The only feasible way to do all this is using a scripting language, + as illustrated by the following, rather naive, php code
+<?php + $mimetexurl = "http://www.yourdomain.com/cgi-bin/mimetex.cgi?"; + function verticalalign( $expression ) { + global $mimetexurl; + // note: curl_init() stops at the first whitespace char in $url argument + $expression = ereg_replace(" ","~",$expression); // so remove whitespace + $url = $mimetexurl . "\depth~" . $expression; + $valign = "0"; + $ch = curl_init( $url ); + curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); + curl_setopt( $ch, CURLOPT_HEADER, true ); + $gif = curl_exec( $ch ); + $errno = curl_errno( $ch ); + curl_close( $ch ); + if ( $errno == 0 ) { + $fields = explode("Vertical-Align:",$gif); + $vfield = trim($fields[1]); + $fldlen = strspn($vfield,"+-0123456789"); + $valign = substr($vfield,0,$fldlen); } + return $valign; + } + function mimetextag( $expression ) { + global $mimetexurl; + $valign = verticalalign($expression); + $url = $mimetexurl . "\depth~" . $expression; + echo ' <img src="',$url,'" '; + echo ' style="Vertical-Align:',$valign,'px" '; + echo ' alt="" border=0>', "\n"; + } + ?>+ +
Now you can write
+ <?php mimetextag('\frac12\left(a^2+b^2\right)'); ?>
+ wherever you want to see
+
+ correctly aligned. Note that the php code automatically
+ prepends \depth to your expression for you.
+
+ (Also note that this code calls mimeTeX twice to render each
+ expression, once to get the Vertical-Align: header and build
+ an <img> tag, and then again to render that tag.
+ If you're a good php programmer and write better code,
+ please email me a copy.)
If you're using mimeTeX's + -DCACHEPATH=\"path/\" + compile option, you can request + that all images be cached with Vertical-Align: headers, + whether or not they contain the \depth directive. Prefix your + path/ with a leading % and write + -DCACHEPATH=\"%path/\" instead. + That leading % won't become part of your cache + directory's path/, but it will signal mimeTeX + to cache headers along with each image. (In this case, + the directive \nodepth suppresses + mimeTeX's header caching for that image.) +
-To protect your own intellectual property, I recommend - Copyright Basics from The Library of Congress, and - similarly, Copyright Basics from The American Bar Association. +
To protect your own intellectual property, I recommend (both are pdf) + Copyright Basics from The Library of Congress, + in particular Circular 61, Copyright Registration for + Computer Programs. + Very briefly, download Form TX and follow the included instructions. In principle, you automatically own the copyright to anything you write the moment it's on paper. In practice, if the matter comes under dispute, the courts look _very_ favorably - on you for demonstrating your intent by registering the copyright.
- + on you for demonstrating your intent by registering the copyright. + + mimetex.zip and then type