( for mimeTeX version 1.60 ) Click for: LaTeX tutorial mimeTeX QuickStart download mimeTeX |
more_examples... |
- - - T u t o r i a l - - - | - - - - - - - - - - - - - - R e f e r e n c e - - - - - - - - - - - - - - | ||
(I) Introduction a. Quick Start b. Examples c. GPL License |
(II) Building mimeTeX a. Download b. Compile c. Install d. Compile Options e. Command Line |
(III) Syntax Reference a. Math & White Space b. Symbols, Sizes, Modes c. Delimiters d. Accents, Arrows, etc. e. \begin{array} f. \picture( ){ } g. Other Commands h. Other Exceptions |
(IV) Appendices a. Fonts b. make_raster() c. gifsave.c Remarks |
MimeTeX, licensed under the gpl, lets you easily embed LaTeX math in your html pages. It parses a LaTeX math expression and immediately emits the corresponding gif image, rather than the usual TeX dvi. 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,
<img src="../cgi-bin/mimetex.cgi?f(x)=\int_{-\infty}^xe^{-t^2}dt" alt="" border=0 align=middle>
immediately generates the corresponding gif image on-the-fly, displaying wherever you put that <img> tag. MimeTeX doesn't need intermediate dvi-to-gif conversion, and it doesn't store separate gif files for each converted expression. There's also no inherent need to repeatedly write the cumbersome <img> tag illustrated above. You can write your own custom tags, or write a wrapper script around mimeTeX to simplify the notation. For example, PmWiki already has a mimeTeX plugin that let's you just write {$ f(x)=\int_{-\infty}^xe^{-t^2}dt $} to obtain the same image.
MimeTeX's benefit over similar math-on-the-web solutions is, as mentioned above, its easy installation. But if that's not a problem for you, and if your site's server already has a LaTeX distribution installed, and suitable image conversion utilities like ImageMagick, then you may prefer to look at a math rendering script like latexrender which uses LaTeX to create higher quality images than mimeTeX produces. For comparison, , with arbitrary mean and standard deviation , and at mimeTeX's next larger font size, looks like
mimeTeX | latexrender | |
Similar LaTeX-based solutions that you may want to look at are textogif and gladTeX. Additional discussion and several more links are at www.tug.org/interest.html and in the tex-faq.
The remainder of this introductory mimeTeX tutorial section contains
You may now want to browse the additional Examples below before proceeding, to make sure mimeTeX suits your needs before you invest more time learning to use it.
MimeTeX is as TeX-like as possible (though not 100% compliant), and you must already be familiar with LaTeX math markup to use it. If you're not, many online LaTeX turorials are readily available. You may also want to browse Andrew Roberts' Latex Math I and Latex Math II, or my own LaTeX math tutorial. Then, instead of continuing to read this page, you may prefer to play with mimeTeX yourself. In that case, just Submit any LaTeX math expression you like in the Query Box below. I've started you out with a little example already in the box, or, instead, you can Click any of the Examples below to place that corresponding expression in the Query Box.
Meanwhile, here are just a few quickstart tips for Submitting your own mimeTeX expressions in the Query Box below:
Now enter your own expression, use the sample provided, or Click any of the Examples. Then press the Submit button, and mimeTeX's rendering should be displayed in the little window immediately below it.
You should see 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>
You can see numerous additional examples illustrating html <img> tags using mimeTeX by viewing this page's source. The typical mimeTeX <img> tag has the form
<img src="../cgi-bin/mimetex.cgi?any valid LaTeX/mimeTeX expression" alt="" border=0 align=middle>
where ../cgi-bin/mimetex.cgi is the relative path from your html page containing these tags to your compiled mimetex.cgi program, and where any valid LaTeX/mimeTeX expression is pretty much any valid LaTeX math expression:
Here are various additional random examples further demonstrating 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 to re-render it, or you can edit the expression first to suit your own purposes.
(1) |                 | ||||||||
(2) | |||||||||
(3) | |||||||||
(4) |
|
||||||||
(5) | illustrating \frac{}{} for continued fraction | ||||||||
(6) |
illustrating \left\{...\right.
and note the accents |
||||||||
(7) |
\overbrace{}^{} and \underbrace{}_{} (TeXbook page 181, Exercise 18.41) |
||||||||
(8) |
|
||||||||
(9) |
Block diagonal form using nested \begin{array}'s. Also, note rows aligned across all three arrays. |
||||||||
(10) | using \begin{eqnarray} to align equations | ||||||||
(11) | commutative diagram using \begin{array} | ||||||||
(12) | mimeTeX \picture(size){pic_elems} "environment", illustrating the image charge - q for a grounded conducting sphere of radius a with a charge q at distance r > a outside it. | ||||||||
(13) | \picture "environment"
illustrating the surface polarization charge induced by a uniform
electric field. Inside the slab of material, the volume polarization
charge clearly vanishes. The little dipole image is drawn only once, then multiput across two columns, and then that result is further multiput down the rows. MimeTeX \picture's can be used as picture elements in other pictures, nested to any level. The image at left is picture-in-picture-in-picture. |
Finally, illustrated below are some examples of fonts and symbols available with mimeTeX. All symbols and sizes from cmr, cmmi. cmsy, cmex and rsfs should be available, but they're not all shown. Mathbb symbols are also available but not shown. And also not shown are various "constructed symbols" like \sqrt, accents, etc. The illustrated font sizes are numbered 4=\Large, 3=\large and 2=\normalsize (not shown are 5=\LARGE, 1=\small and 0=\tiny).
MimeTeX's copyright is registered by me with the US Copyright Office, and I hereby license it to you under the terms and conditions of the GPL. There is no official support of any kind whatsoever, and you use mimeTeX entirely at your own risk, with no guarantee of any kind, in particular with no warranty of merchantability.
By using mimeTeX, you warrant that you have read, understood and agreed to these terms and conditions, and that you possess the legal right and ability to enter into this agreement and to use mimeTeX in accordance with it.
Hopefully, the law and ethics regarding computer programs will evolve to make this kind of obnoxious banter unnecessary. In the meantime, please forgive me my paranoia.
To protect your own intellectual property, I recommend Copyright Basics from The Library of Congress, and similarly, Copyright Basics from The American Bar Association. 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.
Very quickly --- download mimetex.zip and then type
Read the rest of this section for more detailed information. |
I've built and run mimeTeX under Linux and NetBSD using gcc. The source code is ansi-standard C, and should compile and execute under all environments without any change whatsoever. Build instructions below are for Unix. Modify them as necessary for your particular situation (note the -DWINDOWS switch if applicable).
A summary of the steps needed to build mimeTeX is
And a summary of the steps needed to install mimeTeX is
Any problems with the above? Read the more detailed instructions below.
Download mimetex.zip and unzip it in any convenient working directory. Your working directory should now contain
README | mimeTeX release notes |
LICENSE | GPL license, under which you may use mimeTeX |
mimetex.c | mimeTeX source program and all required functions |
mimetex.h | header file for mimetex.c (and for gfuntype.c) |
gfuntype.c | parses output from gftype -i and writes bitmap data |
texfonts.h | output from several gfuntype runs, needed by mimetex.c |
gifsave.c | gif library by Sverre H. Huseby http://shh.thathost.com |
mimetex.html | this file, mimeTeX tutorial and user's manual |
Note: all files use Unix line termination, i.e., linefeeds (without carriage returns) signal line endings. Conversion for Windows PC's, Macs, VMS, etc, can usually be accomplished by unzip's -a option, i.e., unzip -a mimetex.zip
To compile a mimeTeX executable that emits anti-aliased gif images (which is recommended for most uses) issue the command
Or, for an executable that emits gif images without anti-aliasing, issue the command
Alternatively, to compile a mimeTeX executable that emits mime xbitmaps, just issue the command
Compile Notes:
Several other optional compile-line options available for mimetex.c are discussed below.
The gfuntype program is only needed if you plan to change the font information in texfonts.h, as explained in Appendix IVa below. In that case, compile gfuntype with the command
That's all there is to building mimeTeX. You can now test your mimetex.cgi executable from the Unix command line by typing, e.g., ./mimetex.cgi "x^2+y^2" which should emit two ascii rasters something like the following
Ascii dump of bitmap image... Hex dump of colormap indexes... ...........**....................**... ..........1**1...................1**1.. ..........*..*......*...........*..*.. ..........*23*......*............*23*.. .............*......*..............*.. .............*......*...............*.. ....****.....*......*.....*..*.....*.. ...1****....2*......*.....2*..*....2*.. ...*.*.*....*.......*....**..*....*... ...*.*.*...1*.......*.....**..*...1*... .....*.....*.*..********..*..*...*.*.. ....1*1...2*.*..********..3*..*..2*.*.. .....*....****......*.....*..*..****.. ....2*2...****......*......*12*..****.. ..*.*.*.............*.....*.*......... ..*.*.*.............*......*.*2........ ...****.............*.....***......... ..1****.............*......***......... ....................*.......*......... ....................*........*......... .........................*.*.......... ..........................*.*1......... .........................**........... ..........................**1.......... The 5 colormap indexes denote rgb vals... .-->255 1-->196 2-->186 3-->177 *-->0
(The right-hand illustration shows asterisks in the same positions as the left-hand one, along with anti-aliased grayscale colormap indexes assigned to neighboring pixels, and with the rgb value for each index.) Just typing ./mimetex.cgi without an argument should produce ascii rasters for the default expression f(x)=x^2. If you see the two ascii rasters then your binary's good, so mv it to your server's cgi-bin/ directory and set permissions as necessary.
Once mimetex.cgi is working, mv it to your server's cgi-bin/ directory (wherever cgi programs are expected), and chmod/chown it if necessary. Then mv mimetex.html to your server's htdocs/ directory. Now point your browser to www.yourdomain.com/mimetex.html , and you should see a page identical to this one.
Note: the two directories are typically of the form somewhere/www/cgi-bin/ and somewhere/www/htdocs/ , so I set up mimtex.html to get mimetex.cgi from the relative path ../cgi-bin/. If your directories are non-conforming, you may have to edit the few dozen occurrences of ../cgi-bin/mimetex.cgi in mimetex.html . Sometimes a suitable symlink works; if not, you'll have to edit. Globally changing ../cgi-bin/mimetex.cgi often works.
Either way, once mimetex.html displays properly, you can assume everything is working, and can begin authoring html documents using mimetex.cgi to render your own math.
In addition to -DAA or -DGIF or -DXBITMAP (along with -DWINDOWS when necessary) on the mimetex.c compile line, as discussed above, you may also optionally include the following -D switches, whose functionality is discussed below.
--------------------------------------------------------------------- 2004-08-07:09:00:53am f8ccc8dd93c8eeb1d9c40b353ef781e0.gif \LARGE x=\frac{-b\pm\sqrt{b^2-4ac}}{2a} ---------------------------------------------------------------------
{ "\\iint", NULL, "{\\int\\int}" }, { "\\rightleftharpoons",NULL,"{\\rightharpoonup\\atop\\leftharpoondown}" }, { "\\ldots", NULL, "{\\Large.\\hspace1.\\hspace1.}" }, { "\\cr", NULL, "\\\\" }, { "\\neq", NULL, "{\\not=}" },For newcommands _without_ arguments, as illustrated above, the general form of each line in your file should be { "\\command", NULL, "{replacement}" }, Don't forget a comma at the end of every line, and write a double backslash \\ between quotes "...\\..." wherever you actually want a single backslash \. The only effect of the above examples (without arguments) is simple string substitution, i.e., every occurrence of \command is replaced by {replacement}. Note that the { }'s surrounding replacement aren't required, but are usually a good idea (the case of \cr illustrated above is one exception, where { }'s would defeat the purpose).
{ "\\lvec", "2n", "#2_1,\\cdots,#2_{#1}" },In this case the NULL has been replaced by "2n" (note the mandatory surrounding quotes "..."). This example corresponds to the similar one discussed in TLC2 on page 845. The first character inside the "..."s is 2 indicating the number of arguments, which may be 1 thru 9. If there are no subsequent characters followng this one, then all arguments are mandatory, enclosed in { }'s as usual. Otherwise, any subsequent characters signal that the first argument is optional, enclosed in [ ]'s if given. And these subsequent characters comprise the first argument's default value if it's not explicitly given. The illustrated example's first argument is optional with default value n as shown. In this case that's just a single character, but you can write any length default you like.
MimeTeX usually runs from a browser, obtaining its input expression from a query_string. But you can also run mimeTeX from your Unix shell, supplying all input from the command line. This was briefly illustrated above, where you were advised to test your newly-compiled mimeTeX executable from the command line before installing it.
In addition to such simple testing, mimeTeX also provides some possibly useful functionality from the command line. In particular, you can store a gif (or xbitmap) image of any expression to a file. No syntax checking is applied to command-line arguments, so enter them carefully.
The complete command-line syntax for mimeTeX is
./mimetex [ -d ] dump gif image on stdout, [ -e export_file ] or write gif image to export_file [ expression expression, e.g., "x^2+y^2", | -f input_file ] or read expression from input_file [ -m msglevel ] verbosity of debugging output [ -o ] render image with opaque background [ -s fontsize ] default fontsize, 0-5 -d Rather than printing ascii debugging output, mimeTeX dumps the actual gif (or xbitmap) to stdout, e.g., ./mimetex -d "x^2+y^2" > expression.gif creates expression.gif containing an image of x^2+y^2 -e Like -d but writes the actual gif (or xbitmap) directly to export_file, e.g., ./mimetex -e expression.gif "x^2+y^2" also creates expression.gif containing an image of x^2+y^2 expression Place LaTeX expression directly on command line, with no -switch preceding it, as in the example immediately above, or... -f Read expression from input_file (and automatically assume -d switch). The input_file may contain the expression on one line or spread out over many lines. MimeTeX will concatanate all lines from input_file to construct one long expression. Blanks, tabs, and newlines are just ignored. -m 0-99, controls verbosity level for debugging output (usually used only while testing code). -o Rather than the default transparent gif background, the rendered image will contain black symbols on an opaque white background (or vice versa if compiled with -DWHITE). For example, if you have ImageMagick's display utility, ./mimetex -o -d "x^2+y^2" | display & opens a small window containing the rendered expression. -s 0-5, font size. As usual, the font size can also be specified within the expression by a directive, e.g., \large f(x)=x^2 displays f(x)=x^2 at font size 3, overriding -s. Default font size is 2.
Since mimeTeX's syntax is as TeX-like as possible, we'll mostly discuss the occasional exceptions (which exist only to simplify my programming task, not to impose any syntactic aesthetics of mine on you). This section contains short paragraphs that each discuss some aspect of mimeTeX where your LaTeX experience might not be precisely relevant.
Anything not discussed here that still doesn't behave like you expect is probably just not implemented. That includes (La)TeX packages (though a few ams commands like \begin{gather} and \begin{pmatrix} are recognized), non-standard fonts, etc. You can try out any questionable syntax by Submitting a query to quickly see whether or not it works. And you might want to occasionally re-browse the Examples above, which may better illustrate implemented features.
Lengths in mimeTeX are all ultimately expressed in number of pixels. Various commands discussed below require length arguments, including
(the \longxxxarrow [ ]-arguments are optional mimeTeX extensions to LaTeX) MimeTeX's length-type arguments never take units, e.g., {10pt} and {1cm} are both invalid. Lengths always refer to number of pixels, optionally scaled by a user-specified \unitlength.
MimeTeX's \unitlength{ } command lets you specify the number of pixels per "length unit", e.g., \unitlength{10} \hspace{2.5} renders a 25-pixel space. Both \unitlength{ } and \hspace{ }'s length arguments may be integers or may contain decimal points. Ditto for all other mimeTeX commands that take length arguments. The default \unitlength is, you guessed it, 1.
A specified \unitlength applies to all subsequent terms, i.e., everything to its right. And several \unitlength's may be specified in the same expression, each one overriding those to its left. But if one or more \unitlength's appear within a { }-enclosed subexpression, then terms following its closing right } revert to the \unitlength in effect before its opening left {. For example,
which has a 10-pixel space between A and B, then 25 pixels between B and C, and finally another 10 pixels between C and D.
Except inside text boxes, unescaped blanks, tildes (a ~), and all other usual whitespace characters are completely ignored by mimeTeX, just like they are in LaTeX math mode. As usual, you must explicitly write one of the recognized math spaces to put extra visible space in your rendered expressions.
MimeTeX recognizes math spaces \, \: \; as well as \/ and \quad and \qquad . You may also write \hspace{10} to insert a 10-pixel (or any other number) space, scaled by any preceding \unitlength, as illustrated just above. There are no negative spaces.
Although some browsers occasionally misinterpret typed blank spaces inside html query_string's, mimeTeX also recognizes escaped blanks (a \ followed by a blank) as math spaces, just in case you can safely use them.
MimeTeX also supports \hfill{textwidth}, where textwidth is roughly equivalent to LaTeX's \textwidth, i.e., it's the total number of pixels, scaled by \unitlength, that your entire rendered expression will span. However, if \hfill{ } appears within a { }-enclosed subexpression, then it applies only to that subexpression. For example,
The first/inner \hfill{50} inserts exactly enough whitespace so that subexpression "abc def" spans 50 pixels. Then the second/outer \hfill{100} inserts exactly enough whitespace so that the entire expression spans 100 pixels. Without explicit { }-nesting, mimeTeX evaluates expressions left-to-right (sinistrally), e.g., ...\hfill{100}...\hfill{50}... is exactly equivalent to ...\hfill{100}{...\hfill{50}...}. Notice that, this time, the second/right textwidth argument is necessarily smaller than the first/left.
Finally, mimeTeX begins a new line whenever you write \\ . And you may optionally write \\[10] to put a 10-pixel (or any other number) vertical space, scaled by \unitlength, between lines. \begin{eqnarray} also splits long equations over several lines, as illustrated by Example 10 above. But when that's not the best solution, you can also write, for example,
However, mimeTeX can't correctly handle automatically-sized delimiters across linebreaks, e.g.,
which I produced using \big{...\\...\big} instead of \left\{...\\...\right\}. Expressions of the form \left...\right \\ \left...\right should all be rendered properly. It's only \left...\\...\right that will look odd.
Some browsers occasionally misinterpret typed blank spaces inside html query_string's. In that case, you can write tildes (a ~) wherever blanks are required or desired, e.g., \alpha~w instead of \alpha w, or \frac~xy or \sqrt~z, etc. MimeTeX correctly interprets both blanks and ~'s, and all other usual whitespace characters. So use whatever's convenient as long as it's correctly interpreted inside query_string's by your browser.
Similarly, some browsers occasionally misinterpret linebreaks/newlines inside the middle of long html query_string's. For example,
<img src="../cgi-bin/mimetex.cgi?f(x)=\frac1{\sigma\sqrt{2\pi}} \int\limits_{-\infty}^xe^{-\frac{(t-\mu)^2}{2\sig^2}}dt" alt="" border=0 align=middle>
breaks a long query_string over two lines. If your browser interprets this correctly, then mimeTeX will render it correctly, too. Otherwise, you'll have to enter long expressions on one big long line.
If you can break long query_string's over several lines, then you may find mimeTeX's %%comments%% feature useful, too. Note that comments must be preceded and followed by two %'s rather than LaTeX's usual one. The above example could be written
<img src="../cgi-bin/mimetex.cgi?f(x)=\frac1{\sigma\sqrt{2\pi}} %%normalization%% \int\limits_{-\infty}^xe^{-\frac{(t-\mu)^2}{2\sig^2}}dt %%integral%%" alt="" border=0 align=middle>
Besides whitespace, browsers may misinterpret embedded apostrophes, and especially quotes, within query strings. The a's and b's in Example 7 above actually use superscripted commas for apostrophes, i.e., a^,s and b^,s, and you can also use LaTeX \prime's, as in a^\prime s. For quotes, you can use ^{,,} since " almost certainly won't work. To help make things easier, in addition to the usual LaTeX \prime, mimeTeX also recognizes \apostrophe and \quote and \percent, all with the obvious meanings.
For complete information about the characters and math symbols available in mimeTeX, you'll need to browse through the bottom 500-or-so lines of mimetex.h. And several additional symbols like \ldots and \AA and \hbar are defined by the mimeTeX preprocessor, function mimeprep( ) in mimetex.c Generally speaking, I've tried to encode the cmmi10, cmsy10, cmr10, cmex10, rsfs10 and bbold10 families with "names", e.g., \alpha \beta \forall \sqcup, etc, identical to your LaTeX expectations. For example, the calligraphic symbols in cmsy10 are accessed by writing \mathcal{A} \mathcal{B} \mathcal{XYZ}. Similarly, write \mathscr{A} for the rsfs10 fonts, and write \mathbb{R} for bbold10.
I haven't exhaustively checked all the name-number matchings for the hundreds of symbols in mimetex.h. You can eaily correct any minor mistake you find in what I hope is an obvious manner. The fonts Appendix IVa below provides additional information.
In addition to extra LaTeX symbols like \ldots, \AA and \hbar, mentioned above, the mimeTeX preprocessor mimeprep( ) also recognizes various html special characters like <, >, , ", &, etc. Some web tools apparently translate characters like, e.g., > to >, even inside quoted query_string's, so mimeTeX's preprocessor translates them back to LaTeX symbols for you.
MimeTeX currently has six font sizes, numbered 0-5, with default 2. This font size numbering corresponds to the usual LaTeX declarations \tiny, \small, \normalsize (default), \large, \Large and \LARGE. These declarations can be placed anywhere in a mimeTeX expression, and they change font size from that point forwards. However, as usual, a font size change inside a { }-subexpression remains in effect only within that subexpression.
In mimeTeX you may also write \fontsize{0}...\fontsize{5} or the shorter \fs{0},...,\fs{5} for \tiny,...,\LARGE. And since these arguments are all single digits, the even shorter form \fs0,...,\fs5 works equally well. For example,
<img src="../cgi-bin/mimetex.cgi?f(x)=x^2"> | produces | |
<img src="../cgi-bin/mimetex.cgi?\large f(x)=x^2"> | ||
<img src="../cgi-bin/mimetex.cgi?\fs4f(x)=x^2"> |
rendering f(x)=x^2 in mimeTeX font sizes 2 (default \normalsize), 3 (\large or \fs3), and 4 (\fs4 or \Large).
You'll soon notice that exponents and \frac's and \atop's are automatically rendered one size smaller than their base expressions. For example,
rendering the "y=e" in font size 4 (\Large), the "x" in font size 3 (\large), and the "2" in font size 2 (\normalsize). If you get below font size 0, the font size remains 0.
Explicit size declarations override mimeTeX's default sizing behavior. You can rewrite the preceding example as, say,
rendering the "y=e" in font size 4 (\Large unchanged), the "x" in font size 2 (\normalsize), and the "2" in font size 0 (\tiny).
Preceding an \fs{ } size argument with + or - specifies "relative" sizing. For example, \large\text{abc{\fs{-2}def}ghi} produces , rendering the "def" in font size 1 (two sizes smaller than \large). Note that \fs{-2} affects only the subexpression in which it appears, and that its braces are no longer optional since -2 contains two characters. For exponents (or any other size-changing commands like \frac),
rendering the "y=e" in font size 4 (\Large), as usual. The "x" would usually be rendered one size smaller, in font size 3, and your \fs{-1} is applied to that, resulting in font size 2. And the final "2" is rendered, by the usual rules, one size smaller than the "x", in font size 1.
MimeTeX is always in a math-like mode, so you needn't surround expressions with $...$'s for \textstyle, or $$...$$'s for \displaystyle. By default, operator limits like \int_a^b are rendered \textstyle at font sizes \normalsize and smaller, and rendered \displaystyle at font sizes \large and larger (see the -DDISPLAYSIZE compile option to change this default). And when \displaystyle is invoked (either implicitly at font size \large or larger, or if you explicitly write \displaystyle at any font size), then operators \int, \sum, \prod, etc, are automatically promoted to larger sizes. For example,
and
As usual, \nolimits turns displaystyle off (or textstyle on) for the operator immediately preceding it. For example,
and likewise, \limits turns displaystyle on for the operator immediately preceding it. For example,
By the way, \limits affects _any_ character or subexpression immediately preceding it. For example,
Likewise, for subexpressions,
This side effect may occasionally be useful. For example,
(mimeTeX automatically centers super/subscripts above/below the long and Long arrow forms)
The \displaystyle command turns on displaystyle math mode for the entire expression (or { }-enclosed subexpression), affecting _all_ super/subscripts to the right of the \displaystyle, except for character classes Ordinary and Variable (TeXbook page 154). Similarly, \textstyle turns off displaystyle math mode. For example,
Note that \sum's within the subexpression are all affected by the beginning \displaystyle, but not the Variable x_i^j. An explicit x\limits_i^j always affects any preceding term.
Finally, mimeTeX also has a text-like/roman mode entered by writing either \text{anything at all} or the equivalent LaTeX-2.09-like command {\rm anything at all}, both of which render anything at all in roman (font family cmr10). \mbox{ } and several similar LaTeX commands are recognized by mimeTeX as synonyms for \text{ }. For italic, write \textit{anything at all} or {\it anything at all}, both of which render anything at all in italic (font family cmmi10). All four forms respect spaces between words, except that the first/required space after {\rm etc} and {\it etc} is still ignored. For example,
LaTeX's \left( and \right) may be written exactly like that, or may be abbreviated \( and \) in mimeTeX. Not all \left and \right LaTeX delimiters are currently available in mimeTeX, but those that are can be written in the usual way, or can be abbreviated as described above. One exception is that \left\|...\right\| must instead be abbreviated \=...\= or can be written in full \left\|...\right\| as usual. Also, \left\langle...\right\rangle is abbreviated \<...\> .
Mixing abbreviated and unabbreviated delimiters within a matching pair is not allowed, e.g., \left(...\) _won't_ work. But you can mix nested pairs, e.g., \left(...\(...\)...\right) will work as long as the matching delimiters comprising each pair are either both abbreviated or both unabbreviated.
The complete list of automatically sized delimiters available in mimeTeX is
Notes...
Besides the \left...\right delimiters discussed above, mimeTeX also supports constructions like \left\int_a^b...\right. , which automatically sizes the \left\int to accommodate everything between it and its matching \right. delimiter. The \right delimiter needn't necessarily be the \right. illustrated, e.g., \left\int_a^b x^2dx =\frac{x^3}3\right|\nolimits_a^b produces . Except for Opening (TeX class 4) and Closing (class 5) delimiter characters like ( ) and [ ] and \{ \}, limits are default-rendered \displaystyle, which is why \right|\nolimits_a^b was required. You can also write \left\sum, \left\prod, \left\cup, etc, for many of the symbols in CMEX10. And any symbol that works with \left will also work with \right . But mimeTeX abbreviations like \(...\) for \left(...\right) won't work with any of these CMEX10 symbols. You'll have to write the usual unabbreviated \left...\right form.
Unescaped ( )'s and [ ]'s and | |'s and < >'s don't need to be balanced since mimeTeX just displays them like ordinary characters without any special significance. Ditto for the usual four \big( and \Big( and \bigg( and \Bigg(, and for their four right ) counterparts, which just display (...)'s at fixed larger sizes, and also have no special significance. All four big [ ]'s and < >'s and { }'s are also available as ordinary characters.
As usual, unescaped {...}'s aren't displayed at all, must be balanced, and have the usual special LaTeX significance. MimeTeX interprets escaped \{...\}'s as abbreviations for \left\{...\right\} and therefore always sizes them to fit. If you need displayed but unsized {...}'s, write \lbrace...\rbrace or any of the four \big{...\big}'s.
\vec{ } \hat{ } \bar{ } \tilde{ } \dot{ } and \ddot{ } are the only accents currently supported, and they're all "wide". You can write \widehat{ } if you like, but there's absolutely no difference either way. \bar{ } and \overline{ } are identical.
All 32 usual LaTeX function names \arccos,...,\tanh are recognized by mimeTeX and treated in the usual way. MimeTeX also recognizes \tr for the trace, and also \bmod and \pmod. And those functions that normally take "limits" also behave as expected, e.g.,
All mimeTeX \long and \Long arrows take an optional [width] argument that explicitly sets the arrow's width in pixels, scaled by \unitlength. For example, \longrightarrow[50] draws a 50-pixel wide arrow , whereas just \longrightarrow calculates a default width , as usual. And, in addition to the usual right, left and leftright arrows, there are also \long (and \Long) up, down and updown arrows that take an optional [height] argument, also scaled by any preceding \unitlength.
In the event that you actually want to place an []-enclosed expression immediately following an "unsized" long arrow, just place a ~ or any white space after the arrow, e.g., f:x\longrightarrow~[0,1] produces . Without any intervening white space, mimeTeX would have "eaten" the [0,1].
Super/subscripts immediately following all long/Long left/right arrows are displayed the same way \limits displays them, e.g.,
Subscripted long arrows can occasionally be useful, too, as in Example 11 above, e.g.,
To defeat this default behavior, e.g., \longrightarrow\nolimits^g displays super/subscripts in the usual way.
Super/subscripts immediately following all long/Long up/down arrows are treated correspondingly, i.e., superscripts are vertically centered to the arrow's left, and subscripts to its right. For example,
whose occasional usefulness is also illustrated by Example 11. And as before, to defeat this default behavior, e.g., \longuparrow\nolimits^\gamma displays super/subscripts in the usual way.
The \raisebox{height}{expression} and \rotatebox{angle}{expression} commands help you fine-tune and manipulate mimeTeX renderings. The height argument is number of pixels, scaled by \unitlength, and can be positive or negative. The angle argument is number of degrees, and can also be positive (for clockwise) or negative, but must be a multiple of 90. Finally, the expression can be any valid LaTeX/mimeTeX expression. For example, mimeTeX's preprocessor defines the LaTeX ?` symbol, an upside-down question mark, like
\compose[offset]{base}{overlay} superimposes the overlay expression on top of the base expression, displaying the result. Optionally, the overlay is horizontally offset by the specified number of pixels (positive offsets to the right, negative to the left). For example,
Separately or in some judicious combination, \compose and \raisebox and \rotatebox should help you construct special symbols not "natively" available with mimeTeX's limited set of built-in font families. This can be especially useful in conjunction with the -DNEWCOMMANDS compile-time option discussed above.
\ga displays \gamma, but just \g displays \gg (>>). That is, mimeTeX selects the shortest symbol or command which begins with whatever you type. This feature can help shorten an otherwise very long line, but it may be a bit dangerous.
The mimeTeX preprocessor, briefly mentioned above, is responsible for recognizing several LaTeX symbols like \ldots and several commands like \atop . These symbols and commands cannot be abbreviated. The special html characters like are also recognized by the preprocessor and cannot be abbreviated.
Rudimentary color commands are provided by mimeTeX. You can write \color{red} or \color{green} or\color{blue} (which may be abbreviated \red or \green or \blue) anywhere in an expression to render the entire expression in the specified color. That is, abc{\red def}ghi renders the entire expression red, not just the def part. Also, note that mimeTeX's "green" is actually color #00FF00, which the html standard more accurately calls "lime". For example,
TeX represents characters by boxes, with no idea how ink will be distributed inside. So an expression like \frac12\int_{a+b+c}^{d+e+f}g(x)dx is typically rendered as . But mimeTeX knows the character shapes of its fonts, and therefore tries to remove extra whitespace, rendering the same expression as instead.
Precede any expression with the mimeTeX directive \nosquash to render it without "squashing". Or compile mimetex.c with the -DNOSQUASH option if you prefer the typical TeX behavior as mimeTeX's default. In this case, precede any expression with \squash to render it "squashed". And note that explicit space like \hspace{10} or \; , etc, is never squashed.
The scope of \squash and \nosquash is the { }-enclosed subexpression in which the directive occurs. For example, if you want the g(x) part of the preceding example squashed, but not the 1/2 part, then the expression \nosquash\frac12{\squash\int_{a+b+c}^{d+e+f}g(x)dx} renders as .
For finer-grained control, note that \squash is shorthand for the default \squashmargin{+3} (and \nosquash is shorthand for \squashmargin{0}). \squashmargin's value is the minimum number of pixels between squashed symbols. The leading + is optional. If present, the font size (\tiny=0,...,\LARGE=5) is added to the specified minimum. Compile mimetex.c with the -DSQUASHMARGIN=n option to change the default from 3 to n. Compare the preceding example with the over-squashed \squashmargin{1} instead.
Squashing is in "alpha testing" and some expressions still don't look quite right when squashed, e.g., 1^2,2^2,3^2,\ldots renders as . Just compile with -DNOSQUASH if you come across numerous annoying situations.
The usual LaTeX \not "slashes" the single symbol following it, e.g., i\not\partial\equiv i\not\nabla produces .
For arbitrary expressions, mimeTeX provides \Not which draws a line from the upper-right to lower-left corner of its argument, e.g., a\Not{x^2}=bx^{\not3} produces .
Finally, similar to the ulem.sty package, \sout draws a horizontal strikeout line through its argument, e.g., \sout{abcdefg} produces . MimeTeX's \sout also takes an optional argument that adjusts the vertical position of its strikeout line by the specified number of pixels, e.g., \sout[+2]{abcdefg} produces and \sout[-2]{abcdefg} produces .
Rendering vectors and matrices, aligning equations, etc, is all done using the customary LaTeX environment \begin{array}{lcr} a&b&c\\d&e&f\\etc \end{array} which you can write in exactly that form. MimeTeX also recognizes the following array-like environments
\begin{array}{lcr} | a&b&c \\ d&e&f \\ etc | \end{array} |
\begin{matrix} | a&b&c \\ d&e&f \\ etc | \end{matrix} |
\begin{pmatrix} | a&b&c \\ d&e&f \\ etc | \end{pmatrix} |
\begin{bmatrix} | a&b&c \\ d&e&f \\ etc | \end{bmatrix} |
\begin{Bmatrix} | a&b&c \\ d&e&f \\ etc | \end{Bmatrix} |
\begin{vmatrix} | a&b&c \\ d&e&f \\ etc | \end{vmatrix} |
\begin{Vmatrix} | a&b&c \\ d&e&f \\ etc | \end{Vmatrix} |
\begin{eqnarray} | a&=&b \\ c&=&d \\ etc | \end{eqnarray} |
\begin{align} | a&=b \\ c&=d \\ etc | \end{align} |
\begin{gather} | a \\ b \\ etc | \end{gather} |
There's a built-in maximum of 64 columns and 64 rows. Nested array environments, e.g., \begin{pmatrix}a&\begin{matrix}1&2\\3&4\end{matrix}\\c&d\end{pmatrix}, are permitted.
MimeTeX also provides the abbreviation \array{lcr$a&b&c\\d&e&f\\etc} which has exactly the same effect as \begin{array}{lcr} a&b&c\\d&e&f\\etc \end{array}. And the lcr$ "preamble" in \array{lcr$etc} is optional. In that case, \array{a&b&c\\d&e&f\\etc} has exactly the same effect as \begin{matrix} a&b&c\\d&e&f\\etc \end{matrix}. You can also write \(\array{etc}\) to "manually abbreviate" the pmatrix environment, or \array{rcl$etc} to abbreviate eqnarray, but mimeTeX has no explicit abbreviations for these other environments. For example,
Solid \hline's (but not \cline's) and vertical l|c|r bars are available, as usual. For dashed lines and bars, \begin{array} provides the additional features \hdash and l.c.r . \hline and \hdash may not be abbreviated. For example,
The default font size is unchanged by \array{ }, but you can explicitly control it in the usual way, e.g., {\large\begin{matrix}...\end{matrix}} renders the entire array in font size 3. In addition, any &...& cell may contain font size declarations which are always local to that cell, e.g., &\fs{-1}...& renders that one cell one font size smaller than current.
The {lcr} in \begin{array}{lcr} sets left,center,right "horizontal justification" down columns of an array, as usual. And "vertical justification" across rows defaults to what we'll call baseline, i.e., aligned equations, as in Example 10 above, display properly. But the down arrows (for and for ) in Example 11 require "vertical centering" across the middle row of that array. So, in addition to lowercase lcr, mimeTeX's {lcr} in \begin{array}{lcr} may also contain uppercase BC to set "B"aseline or "C"enter vertical justification across the corresponding rows. For example, \begin{array}{rccclBCB} sets baseline justification for the first and third rows, and center justification for the second row. Without any BC's, all rows default to the usual B baseline justification.
MimeTeX has no \arraycolsep or \arraystretch parameters.
Instead, \begin{array}{lc25rB35C} sets the absolute width
of the second column to 25 pixels, and the absolute height of the
first row to 35 pixels, as illustrated by
Example 9. Any number following
an lcrBC specification sets the width of that one column
(for lcr), or the height of that one row (for BC).
You can optionally precede the number with a + sign,
which "propagates" that value forward to all subsequent columns for
lcr, or all subsequent rows for BC. For example,
\begin{array}{lc+25rB+35C} sets the absolute width of
column 2 and all subsequent columns to 25 pixels,
and the absolute height of row 1 and all subsequent rows
to 35 pixels. After absolute sizing has been set, the special
value 0 reverts to automatic sizing for that one row or
column, and +0 reverts to automatic sizing for all subsequent
rows or columns. For example, \begin{array}{c+25ccc+35ccc+0}
sets the absolute widths of columns 1-3 to 25 pixels,
columns 4-6 to 35 pixels, and then reverts to automatic
sizing for columns 7 and all subsequent columns.
The "propagation" introduced by + is local to the
\begin{array} in which it occurs. So you have to repeat
the same specifications if you want rows aligned across several
arrays on the same line (or columns aligned on several lines
separated by \\). Instead, a lowercase g globally
copies your column specifications to all subsequent arrays,
and an uppercase G globally copies your row specifications.
And gG copies both column and row specifications. For example,
\begin{array}{GC+25} sets the height of all rows in this
array to 25 pixels, and ditto for all subsequent arrays to its right.
Explicit specifications in subsequent arrays override previous global
values.
Click one of the following examples to see illustrations
of the above discussion:
See Examples 8-11 above for several additional \begin{array}{lcr} applications.
Besides \begin{array}{lcr}, mimeTeX also tries to emulate the
familiar LaTeX picture environment with the somewhat similar
\picture(width[,height])
{ (loc1){pic_elem1} (loc2){pic_elem2} ... }
as illustrated by Examples 12-13 above.
Arguments surrounded by [ ]'s are optional.
If the optional [,height] is omitted, then height=width
is assumed. Locations (loc1) and (loc2) ... each
denote either a \put(loc) or a \multiput(loc),
and each location is of the form ([c]x,y[;xinc,yinc[;num]]).
A \put(loc) is denoted by a location of the form ([c]x,y) where x,y denotes the coordinate where the lower-left corner of the subsequent picture_element will be placed, unless the letter c precedes the x-number, in which case cx,y denotes the center point instead. The very lower-left corner of the entire picture is always 0,0, and the upper-right corner is width-1,height-1. Note, for example, that you'd never want to specify location c0,0 since the picture_element would be mostly out-of-bounds (only its upper-right quadrant would be in-bounds).
A \multiput(loc) starts like a \put(loc), but location [c]x,y is followed by ;xinc,yinc[;num] indicating the x,y-increments applied to each of num repetitions of picture_element. If ;num is omitted, repetitions continue until the picture_element goes out-of-bounds of the specified width[,height]. Note that x,y are always positive or zero, but xinc,yinc may be postive, zero or negative.
The \picture(,){...} parameters width, height, x, y, xinc, yinc may be either integer or may contain a decimal point, and they're all scaled by \unitlength. The num parameter must be integer.
Picture_element's {pic_elem1} and {pic_elem2} ... may be any expressions recognized by mimeTeX, even including other \picture's nested to any level.
To help draw useful picture_element's, mimeTeX provides several drawing commands, \line(xinc,yinc)[{xlen}] and \circle(xdiam[,ydiam][;arc]). Although primarily intended for use in \picture's, you can use them in any mimeTeX expression, e.g., abc\circle(20)def produces .
Without its optional {xlen} parameter, the expression (x,y){\line(xinc,yinc)} draws a straight line from point x,y to point x+xinc,y+yinc. The inc's can be positive, zero or negative. Don't prefix location x,y with a leading c for \line's; the intended "corner" is determined by the signs of xinc and yinc. If given, the optional {xlen} parameter rescales the length of the line so its x-projection is xlen and its slope is unchanged.
Without optional ,ydiam and ;arc, the expression
(x,y){\circle(xdiam)} draws a circle of diameter xdiam
centered at x,y. Don't prefix location x,y with a
leading c for \circle's; centering is assumed.
If ,ydiam is also given, then (x,y){\circle(xdiam,ydiam)}
draws the ellipse inscribed in a rectangle of width xdiam
and height ydiam centered at x,y.
Finally, ;arc specifies the arc to be
drawn, in one of two ways. An ;arc argument given in the
form ;1234 interprets each digit as a quadrant to be drawn,
with 1 the upper-right quadrant and then proceeding
counterclockwise, e.g., \circle(12;34) specifies the
lower half of a circle whose diameter is twelve.
Alternatively, an ;arc argument given in
the form 45,180 or -60,120 specifies the endpoints of
the desired arc in degrees, with 0 the positive x-axis and
then proceeding counterclockwise. The first number must always
be smaller than the second (negative numbers are allowed), and the
arc is drawn counterclockwise starting from the smaller number.
Besides Examples 12-13 above,
it's hard to resist illustrating
\unitlength{.6} \picture(100) {
(50,50){\circle(99)} %%head%%
(20,55;50,0;2){\fs{+1}\hat\bullet} %%eyes%%
(50,40){\bullet} %%nose%%
(50,35){\circle(50,25;34)} %%upper lip%%
(50,35){\circle(50,45;34)} %%lower lip%% }
Various and sundry other LaTeX-like commands are also provided by mimeTeX. In addition to features explicitly discussed below, mimeTeX supports the usual sub_scripts and super^scripts, and most of the typical LaTeX commands, many already discussed above, including
All these typical commands should behave as they usually do in LaTeX, and won't be discussed further. Short discussions of some other commands follow.
\stackrel{ }{ } behaves as usual in LaTeX, rendering its first argument one font size smaller and centered above its second. And the amsmath-style \overset{ }{ } is identical. For example,
"Conversely" to \stackrel{ }{ }, mimeTeX provides \relstack{ }{ }, which renders its second argument one font size smaller and centered below its first. And the amsmath-style \underset{ }{ } renders its first argument one font size smaller and centered below its second. For example, the \log function name doesn't treat limits like \lim_, but you can write, for example,
MimeTeX's \limits provides an easier but non-standard alternative to achieve the same effect. For example,
In case html border attributes aren't suitable, mimeTeX provides the usual \fbox{expression} command, e.g.,
You can also write \fbox[width]{expression} to explicitly set the box's width, or you can write \fbox[width][height]{expression} to explicitly set both width and height.
\input{filename} behaves just like the corresponding LaTeX command, reading the entire contents of filename into your expression at the point where the \input command occurs. By default, filename resides in the same directory as mimetex.cgi. Moreover, for security, absolute paths with leading /'s or \'s, and paths with ../'s or ..\'s, are not permitted. See the -DPATHPREFIX compile option, discussed above, if you want \input files in some other directory. In any case, if filename isn't found, then \input tries to read filename.tex instead.
MimeTeX also supports the optional form \input{filename:tag}. In this case, filename is read as before, but only those characters between <tag>...</tag> are placed into your expression. This permits you to have one file containing many different <tag>'s, e.g., one file containing all the questions and/or answers to a homework assignment or a quiz, etc.
The bottom-right corner of this page contains a page hit counter that's maintained using mimeTeX's \counter[logfile]{counterfile:tag} command. As with \input, described immediately above, both the required counterfile and the optional logfile are the names of files that reside in the same directory as your mimetex.cgi executable, unless you compiled mimetex with the -DPATHPREFIX compile option. Before using the \counter command, Unix "touch" and "chmod" those files so they're mimeTeX readable and writable.
If counterfile isn't readable and writable, then the \counter command always displays 1st. Otherwise, it maintains a line in counterfile of the form <tag> value </tag> where value is initialized as 1_ if the specified <tag> line doesn't already exist, and then incremented on each subsequent call. That trailing underscore on the value in the file, e.g., 99_, tells mimeTeX to display 99th with an ordinal suffix. Edit the value in the file and remove the underscore if you don't want the ordinal suffix displayed. Finally, mimeTeX makes no effort to lock files or records (tags), so be careful using \counter if your hit rates are high enough so that frequent collisions are likely.
The same counterfile can contain as many different <tag> lines as you like, so counters for all the pages on your site can be maintained in one file. MimeTeX also maintains a special <timestamp> tag in counterfile that logs the the date/time and name of the most recently updated tag.
Somewhat more detailed log information can be accumulated in the optional logfile. If you provide that filename, mimeTeX writes a line to it of the form 2004-09-20:12:59:33pm <tag>=99 192.168.1.1 http_referer containing a timestamp, the counter tag and its current value, and the user's IP address and http_referer page if they're available.
The page hit counter displayed at the bottom-right corner of this page is maintained by the command \counter[counters.log]{counters.txt:mimetex.html}. After compiling and installing your own mimetex.cgi and your own copy of this page, that counter will continually show 1st's unless/until you "touch" and "chmod" counters.txt (and, optionally, counters.log) in your mimetex.cgi directory.
MimeTeX's bindings are pretty much left-to-right. For example, although mimeTeX correctly interprets \frac12 as well as \frac{1}{2}, etc, the legal LaTeX expression x^\frac12 must be written x^{\frac12}. Otherwise, mimeTeX interprets it as {x^\frac}12, i.e., the same way x^\alpha12 would be interpreted, which is entirely wrong for \frac. The same requirement also applies to other combinations of commands, e.g., you must write \sqrt{\frac\alpha\beta}, etc.
Programming information to help you modify mimeTeX's behavior, and to use its functionality in your own programs, is provided by these appendices. The currently available appendices discuss (a)how to modify or extend mimeTeX's fonts, (b)how to use mimeTeX's principal function, make_raster(), and (c)how to use Sverre Huseby's gifsave.c library.
The font information mimeTeX uses to render characters is derived from .gf font files (usually generated by metafont running against .mf files), which are then run through gftype -i and finally through my gfuntype program (supplied with your mimeTeX distribution).
The final output from each such sequence of three runs (metafont > gftype -i > gfuntype) gives mimeTeX the information it needs to render one particular font family at one particular size. The file texfonts.h supplied with your mimeTeX distribution collects the output from 36 such (sequences of) runs, representing six font families at six sizes each.
This collection of information in texfonts.h is "wired" into mimeTeX through tables maintained in mimetex.h. To change mimeTeX's fonts, you'll have to first modify (or totally replace) texfonts.h using your own gfuntype output, and then change mimetex.h to reflect your texfonts.h modifications.
This appendix provides a brief description of the above process, though you'll probably need at least some previous C programming experience to confidently accomplish it. Your motivation might be to add more fonts to mimeTeX, to change the font sizes I chose, or to add more font sizes, etc. MimeTeX's design permits all this to be easily done once you understand the process.
Running metafont to generate a .gf file from .mf source will usually be your very first step. A typical such run might be
which in this case generates output file cmmi10.131gf (which is mimeTeX's font size 3 for the cmmi family).
Given the cmmi10.131gf file from this metafont run (or substitute any other .gf file you like), next run
where typeout can be any temporary filename you like.
Finally, run gfuntype against the typeout file you just generated with the command
to generate the final output file cmmi131.h (or any filename you supply as the last arg). This contains the cmmi data in an array whose name is taken from the -n arg you supplied to gfuntype.
The above sequence of three runs resulted in output file cmmi131.h, containing the font information mimeTeX needs for one font family (cmmi) at one font size (3). Repeat this sequence of three runs for each font size and each font family. Then pull all the output files into one big texfonts.h file (or write a small texfonts.h which just #include's them all).
For your information, the 36 sequences of runs represented in the texfonts.h file supplied with your mimeTeX distribution correspond to the following six inital metafont runs for cmr10
size=0 (.83gf) mf '\mode=eighthre; input cmr10' 1 (.100gf) mf '\mode=nextscrn; input cmr10' 2 (.118gf) mf '\mode=lview; input cmr10' 3 (.131gf) mf '\mode=onetz; mag=magstep(.5); input cmr10' 4 (.160gf) mf '\mode=itoh; input cmr10' 5 (.180gf) mf '\mode=lqlores; input cmr10'
Then ditto for the five other font families cmmi10, cmsy10, cmex10, rsfs10, bbold10. All the subsequent gftype and gfuntype runs just follow the usual format described above.
To incorporate all this font information you just generated into mimeTeX, edit your mimetex.h file and find the table that looks something like
static fontfamily aafonttable[] = { /* ------------------------------------------------------------- family size=0, 1, 2, 3, 4, 5 ------------------------------------------------------------- */ { CMR10, { cmr83, cmr100, cmr118, cmr131, cmr160, cmr180 } }, { CMMI10, { cmmi83, cmmi100, cmmi118, cmmi131, cmmi160, cmmi180 } }, { CMSY10, { cmsy83, cmsy100, cmsy118, cmsy131, cmsy160, cmsy180 } }, { CMEX10, { cmex83, cmex100, cmex118, cmex131, cmex160, cmex180 } }, { RSFS10, { rsfs83, rsfs100, rsfs118, rsfs131, rsfs160, rsfs180 } }, {BBOLD10, {bbold83,bbold100,bbold118,bbold131,bbold160,bbold180 } }, { -999, { NULL, NULL, NULL, NULL, NULL, NULL } } } ; /* --- end-of-fonttable[] --- */
Note the 36 names cmr83...bbold180 in the table. These must correspond to (or must be changed to) the names following the -n switch you specified for your gfuntype runs.
If you want more than six font sizes, first build up texfonts.h with all the necessary information. Then change LARGESTSIZE (and probably NORMALSIZE) in mimetex.h, and finally edit the above aafonttable[] by extending the columns in each row up to your largest size.
You can also add new rows by #define'ing a new family, and then adding a whole lot of character definitions at the bottom of mimetex.h, all in the obvious way (i.e., it should become obvious after reviewing mimetex.h). A new row would be required, for example, to make another font available in mimeTeX.
MimeTeX converts an input LaTeX math expression to a corresponding GIF image in two steps. First, it converts the input LaTeX expression to a corresponding bitmap raster. Then Sverre Huseby's gifsave library, discussed below, converts that bitmap to the emitted gif. Though you never explicitly see that bitmap, it's mimeTeX's principal result. MimeTeX is written so any program can easily use its expression-to-bitmap conversion capability with just a single line of code. The following complete program demonstrates the simplest such use.
#include <stdio.h> #include "mimetex.h" int main ( int argc, char *argv[] ) { raster *rp = make_raster(argv[1],NORMALSIZE); type_raster(rp,stdout); /* display ascii image of raster */ }
Cut-and-paste the above sample code from this file to, say,
mimedemo.c (and fix the brackets around stdio.h). Then compile
cc mimedemo.c mimetex.c -lm -o mimedemo
and run it from your unix shell command line like
./mimedemo "x^2+y^2"
MimeTeX's expression-to-bitmap conversion is accomplished by the make_raster() call, whose first argument is just a pointer to a (null-terminated) string containing any mimeTeX-compliant LaTeX expression, and whose second argument is the mimeTeX font size to use (overridden if your expression contains a preamble). The ascii display of the bitmap raster returned by make_raster() results from the subsequent call to type_raster(). That's all this program does, but you could use make_raster()'s returned bitmap for any other purpose you have in mind.
MimeTeX's primary purpose is to emit either xbitmaps or gif images rather than ascii displays. And mimeTeX has anti-aliasing and various other options that further complicate its main() function compared to the simple example above. The example below demonstrates mimeTeX usage in the slightly more realistic situation where an input expression is converted to a gif, without anti-aliasing, and emitted on stdout.
#include <stdio.h> #include <stdlib.h> #include "mimetex.h" /* --- global needed by callback function, below, for gifsave.c --- */ static raster *rp = NULL; /* 0/1 bitmap raster image */ /* --- callback function to return pixel value at col x, row y --- */ int GetPixel ( int x, int y ) /* pixel value will be 0 or 1 */ { return (int)getpixel(rp,y,x); } /* just use getpixel() macro */ /* --- main() entry point --- */ int main ( int argc, char *argv[] ) { /* --- get LaTeX expression from either browser query or command-line --- */ char *query = getenv("QUERY_STRING"), /* check for query string */ *expression = (query!=NULL? query : /* input either from query */ (argc>1? argv[1] : "f(x)=x^2")); /* or from command line */ /* ---- mimeTeX converts expression to bitmap raster ---- */ rp = make_raster(expression,NORMALSIZE); /* mimeTeX rasterizes expression */ /* ---- convert returned bitmap raster to gif, and emit it on stdout ---- */ if ( query != NULL ) /* Content-type line for browser */ fprintf( stdout, "Content-type: image/gif\n\n" ); /* --- initialize gifsave library and colors, and set transparent bg --- */ GIF_Create(NULL, rp->width, rp->height, 2, 8); /* init for black/white */ GIF_SetColor(0, 255, 255, 255); /* always set background white */ GIF_SetColor(1, 0, 0, 0); /* and foreground black */ GIF_SetTransparent(0); /* and set transparent background */ /* --- finally, emit compressed gif image (to stdout) --- */ GIF_CompressImage(0, 0, -1, -1, GetPixel); GIF_Close(); }
Cut-and-paste as before, compile like
cc mimedemo.c mimetex.c gifsave.c
-lm -o mimedemo
and run it like the first example, but this time you may want to redirect
stdout
./mimedemo "x^2+y^2"
> mimedemo.gif
since output is now a gif image consisting of mostly unprintable bytes.
Input is typically from the command line as illustrated, but this example
checks for a browser query string too. That means you could actually
replace mimetex.cgi with this executable, though anti-aliasing wouldn't
be available.
Of course, this example's intent isn't to replace the mimetex.cgi executable, but rather to illustrate GIFSAVE library usage, documented in detail below. And this example also illustrates usage of several mimeTeX raster structure elements, like rp->width and rp->height. So you'll probably also want to refer to mimetex.h, which contains those raster structures and other relevant definitions. For instance, the example's GetPixel() callback function illustrates usage of the getpixel() macro in mimetex.h, to retrieve individual pixels by their x,y-coordinates. And there's a similar setpixel() macro in mimetex.h to store pixels. After completing all this reading, you'll be prepared to begin using mimeTeX functions in your own code.
The information below is taken from the README file accompanying Sverre Huseby's distribution of GIFSAVE. I've made a few small editorial modifications, including descriptions of the several minor changes necessary to support mimeTeX. And the mimeTeX example program immediately above uses GIFSAVE in a very straightforward way that should help clarify any questions which may remain after reading the documentation below.
INTRODUCTION ============ The GIFSAVE functions make it possible to save GIF images from your own C programs. GIFSAVE creates simple GIF files following the GIF87a standard. Interlaced images cannot be created. There should only be one image per file. GIFSAVE consists of five functions, all returning type int, and no separate header file is required. The functions should be called in the order listed below for each GIF-file. One file must be closed before a new one can be created. GIF_Create() creates new GIF-files. It takes parameters specifying filename, screen size, number of colors, and color resolution. GIF_SetColor() sets up red, green, blue color components. It should be called once for each possible color. GIF_SetTransparent() is optional. If called, it sets the color number of the color that should be transparent, i.e., the background color shows through this one. GIF_CompressImage() performs the compression of the image. It accepts parameters describing the position and size of the image on screen, and a user defined callback function that is supposed to fetch the pixel values. GIF_Close() terminates and closes the file. To use these functions, you must also write a callback function that returns the pixel values for each point in the image. THE FUNCTIONS ============= GIF_Create() ------------ Function Creates a new GIF-file, and stores info on the screen. Syntax int GIF_Create( char *filename, int width, int height, int numcolors, int colorres ); Remarks Creates a new (or overwrites an existing) GIF-file with the given filename. No .GIF-extension is added. If filename is passed as a NULL pointer, output is directed to stdout. The width- and height- parameters specify the size of the image in pixels. numcolors is the number of colors used in the image. colorres is number of bits used to encode a primary color (red, green or blue). In GIF-files, colors are built by combining given amounts of each primary color. On VGA-cards, each color is built by combining red, green and blue values in the range [0, 63]. Encoding the number 63 would require 6 bits, so colorres would be set to 6. Return value GIF_OK - OK GIF_ERRCREATE - Error creating file GIF_ERRWRITE - Error writing to file GIF_OUTMEM - Out of memory GIF_SetColor() -------------- Function Specifies the primary color component of a color used in the image. Syntax void GIF_SetColor( int colornum, int red, int green, int blue ); Remarks This function updates the colortable-values for color number colornum in the image. Should be called for each color in the range [0, numcolors] with red, green and blue components in the range [0, (2^colorres)-1] colorres and colornum are values previousely given to the function GIF_Create(). Return value None GIF_SetTransparent() -------------------- Function Specifies the color number of the color that should be considered transparent. Syntax void GIF_SetTransparent( int colornum ); Remarks Need not be called at all. But if called, should be called only once with colornum in the range [0, numcolors] i.e., colornum must be one of the values previously given to GIF_SetColor(). Return value None GIF_CompressImage() ------------------- Function Compresses an image and stores it in the current file. Syntax int GIF_CompressImage( int left, int top, int width, int height, int (*getpixel)(int x, int y) ); Remarks The left- and top- parameters indicate the image offset from the upper left corner of the screen. They also give the start values for calls to the userdefined callback function. width and height give the size of the image. A value of -1 indicates the equivalent screen size given in the call to GIF_Create(). If the image is supposed to cover the entire screen, values 0, 0, -1, -1 should be given. GIF_CompressImage() obtains the pixel values by calling a user specified function. This function is passed in the parameter getpixel. See "callback()" further down for a description of this function. Return value GIF_OK - OK GIF_ERRWRITE - Error writing to file GIF_OUTMEM - Out of memory GIF_Close() ----------- Function Closes the GIF-file. Syntax int GIF_Close(void); Remarks This function writes a terminating descriptor to the file, and then closes it. Also frees memory used by the other functions of GIFSAVE. Return value GIF_OK - OK GIF_ERRWRITE - Error writing to file THE CALLBACK FUNCTION ===================== callback() ---------- Function Obtains pixel-values for the GIF_CompressImage() -function. Syntax int callback(int x, int y); Remarks This function must be written by the programmer. It should accept two integer parameters specifying a point in the image, and return the pixel value at this point. The ranges for these parameters are as follows x : [img_left, img_left + img_width - 1] y : [img_top, img_top + img_height - 1] where img_left, img_top, img_width and img_height are the values left, top, width and height passed to GIF_CompressImage(). An example; if the screen has width 640 and height 350, and the image covers the entire screen, x will be in the range [0, 639] and y in the range [0, 349]. callback() need not get its values from the screen. The values can be fetched from a memory array, they can be calculated for each point requested, etc. The function is passed as a parameter to GIF_CompressImage(), and can thus have any name, not only callback(). Return value Pixel value at the point requested. Should be in the range [0, numcolors-1] where numcolors is as specified to GIF_Create().
I hope you find mimeTeX useful. If so, a contribution to your country's TeX Users Group, or to the GNU project, is suggested, especially if you're a company that's currently profitable.
email: john@forkosh.com |