--- loncom/cgi/mimeTeX/mimetex.html 2007/10/09 21:41:41 1.3 +++ loncom/cgi/mimeTeX/mimetex.html 2008/12/04 12:17:13 1.4 @@ -1,10 +1,11 @@ + + +
@@ -117,7 +125,7 @@ Banner across top of page, containing tiFor example, if you're using +
For example,
+ 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 just write - [tex] f(x)=\int_{-\infty}^xe^{-t^2}dt [/tex] - to obtain the same image illustrated above:
+ contributed the following typical one-line mod that lets you write + [tex] c=\sqrt{a^2+b^2} [/tex] to obtain the + same#--------[open]----------------------------------------------------- /includes/bbcode.php @@ -320,26 +385,31 @@ mimeTeX plugins... mimeTeX plugin
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.
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 . $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 . $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.
+ 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, 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. + Otherwise, the Vertical-Align: information is lost, + and attempts to align cached images will fail.
+ MimeTeX's benefit over similar math-on-the-web solutions is, as
@@ -391,35 +547,38 @@ Alternative solutions..., with arbitrary mean
+ alt="" border=0 style="Vertical-Align:-11px">,
+ with arbitrary mean
- and standard deviation
+ src="../cgi-bin/mimetex.cgi?\large\mu" alt="" border=0
+ style="Vertical-Align:-5px"> and standard deviation
, and at mimeTeX's next larger font size, looks like
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 | +
|
+ + |
+ |
+