mathtex-1.03/0000755000000000000000000000000011304541772011611 5ustar rootrootmathtex-1.03/README0000644000000000000000000002106711154115711012470 0ustar rootroot -------------------------------------------------------------------------- March 6, 2009 Version 1.02 m a t h T e X R e a d m e F i l e Copyright(c) 2007-2009, John Forkosh Associates, Inc. All rights reserved. -------------------------------------------------------------------------- by: John Forkosh john@forkosh.com www.forkosh.com This file is part of mathTeX, which is free software. You may redistribute and/or modify it under the terms of the GNU General Public License, version 3 or later, as published by the Free Software Foundation. See http://www.gnu.org/licenses/gpl.html mathTeX is discussed and illustrated online by the mathTeX manual at its homepage http://www.forkosh.com/mathtex.html Or you can follow the Installation instructions in Section II below to immediately install mathTeX on your own server. I. INTRODUCTION ------------------------------------------------------------------------ MathTeX, licensed under the GPL, is a cgi program that lets you easily embed LaTeX math in your own html pages, blogs, wikis, etc. It parses a LaTeX math expression and immediately emits the corresponding gif (or png) image, rather than the usual TeX dvi. So just place an html tag in your document wherever you want to see the corresponding LaTeX expression. For example, immediately displays the corresponding gif image wherever you put that tag. There's no inherent need to repeatedly write the cumbersome tag illustrated above. For example, if you're using phpBB3, just click Postings from the Administrator Control Panel, and add the Custom BBCode [tex]{TEXT}[/tex] with the HTML replacement Then users can just type [tex] f(x)=\int_{-\infty}^xe^{-t^2}dt [/tex] in their posts to see a gif image of the enclosed expression. MathTeX uses the latex and dvipng programs, along with all necessary fonts, etc, from your TeX distribution. If dvipng is not available, you can compile mathTeX to use dvips from your TeX distribution, and convert from the ImageMagick package, instead. Links to online sources for all these dependencies are on http://www.forkosh.com/mathtex.html and several are listed below. II. INSTALLATION ------------------------------------------------------------------------ Note: The current release of mathTeX only runs under Unix-like operating systems. To compile and install mathTeX on your own Unix server... +--- | Install mathTeX's dependencies and download mathTeX +---------------------------------------------------- * First, make sure you have a recent LaTeX distribution http://www.latex-project.org/ftp.html installed on your server. Ask your ISP or sysadmin if you have any installation problems or questions. Or see http://www.forkosh.com/mimetex.html if you can't install latex. Besides latex, mathTeX uses dvipng, which recent LaTeX distributions typically include. If you can't install dvipng, see http://www.forkosh.com/mathtex.html for instructions to use dvips and convert instead of dvipng. * Then, download http://www.forkosh.dreamhost.com/mathtex.zip and unzip mathtex.zip in any convenient working directory. Your working directory should now contain mathtex.zip your downloaded gnu zipped mathTeX distribution README this file (see mathtex.html for demo/tutorial) COPYING GPL license, under which you may use mathTeX mathtex.c mathTeX source program and all functions mathtex.html mathTeX users manual +--- | Compile and Install mathTeX +---------------------------- * To compile an executable that emits default gif images cc mathtex.c -DLATEX=\"$(which latex)\" \ -DDVIPNG=\"$(which dvipng)\" \ -o mathtex.cgi For default png images, add the -DPNG switch. Additional command-line switches that you may find useful are discussed at http://www.forkosh.com/mathtex.html * Finally, mv mathtex.cgi to your server's cgi-bin/ directory, chmod its permissions as necessary (typically 755), making sure mathtex.cgi can rw files in cgi-bin/, and you're all done. +--- | Test installed image +--------------------- * To quickly test your installed mathtex.cgi, type a url into your browser's locator window something like http://www.yourdomain.com/cgi-bin/mathtex.cgi?x^2+y^2 which should display the same image that you see at http://www.forkosh.com/cgi-bin/mathtex.cgi?x^2+y^2 If you see the same image from your own domain link, then you've completed a successful mathTeX installation. * Optionally, to install a copy of the mathTeX manual on your server, mv mathtex.html to your server's htdocs/ directory. And, if the relative path from htdocs to cgi-bin isn't ../cgi-bin, then edit mathtex.html and change the few dozen occurrences as necessary. Now, http://www.yourdomain.com/mathtex.html should display your own copy of the mathTeX manual. Any problems with the above? Read the more detailed instructions on mathTeX's homepage http://www.forkosh.com/mathtex.html III. REVISION HISTORY ------------------------------------------------------------------------ See http://www.forkosh.com/mathtexchangelog.html for a detailed discussion of mathTeX revisions. o 11 Oct 2007 -- mathTeX version 1.00 released. o 12 Oct 2007 -- optional \usepackage[arg]{package} argument now recognized correctly (initial release neglected to handle optional [arg] following \usepackage). o 12 Oct 2007 -- html &#nnn; now translated during preprocessing, e.g., [ or [ becomes [ (left square bracket) before it's submitted to latex. o 12 Oct 2007 -- special mathTeX directives like \time are now checked for proper command termination, i.e., non-alpha character. (In particular, LaTeX \times had been incorrectly interpreted as mathTeX \time followed by an s.) o 12 Oct 2007 -- url "unescape" translation, i.e., %20-to-blank, etc, repeated (done twice) for
input. (I'm not sure why this is necessary, and can't reproduce the problem myself, but am acting on seemingly reliable reports.) o 20 Oct 2007 -- removed leading and trailing pairs of $$...$$'s from input expressions, interpreting $...$ as \textstyle and $$...$$ as \displaystyle (and $$$...$$$ as \parstyle). Also removed leading and trailing \[...\], interpreting it as \displaystyle. (Note: \displaystyle is mathTeX's default, so $$...$$'s or \[...\] are unnecessary. But some people submit expressions containing them, so they're now interpreted.) o 16 Feb 2008 -- more robust test to display the correct error message when a required dependency isn't installed. (Occasionally, the "ran but failed" message was emitted when a dependency was actually "not installed".) o 16 Feb 2008 -- -DDENYREFERER=\"string\" or -DDENYREFERER=\"string1,string2,etc\" compile switch added. If compiled with it, mathTeX won't render images for HTTP_REFERER's containing string (or string1 or string2, etc) as a substring of their url's. o 17 Feb 2008 -- updated (slightly) documentation o 18 Feb 2008 -- mathTeX version 1.01 released. o 05 Mar 2009 -- \environment directive added to display all http environment variables. o 06 Mar 2009 -- mathTeX version 1.02 released. IV. CONCLUDING REMARKS ------------------------------------------------------------------------ I hope you find mathTeX 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. ========================= END-OF-FILE README =========================== mathtex-1.03/COPYING0000644000000000000000000010451310736776203012657 0ustar rootroot GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The GNU General Public License is a free, copyleft license for software and other kinds of works. The licenses for most software and other practical works are designed to take away your freedom to share and change the works. By contrast, the GNU General Public License is intended to guarantee your freedom to share and change all versions of a program--to make sure it remains free software for all its users. We, the Free Software Foundation, use the GNU General Public License for most of our software; it applies also to any other work released this way by its authors. You can apply it to your programs, too. When we speak of free software, we are referring to freedom, not price. Our General Public Licenses are designed to make sure that you have the freedom to distribute copies of free software (and charge for them if you wish), that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs, and that you know you can do these things. To protect your rights, we need to prevent others from denying you these rights or asking you to surrender the rights. Therefore, you have certain responsibilities if you distribute copies of the software, or if you modify it: responsibilities to respect the freedom of others. For example, if you distribute copies of such a program, whether gratis or for a fee, you must pass on to the recipients the same freedoms that you received. You must make sure that they, too, receive or can get the source code. And you must show them these terms so they know their rights. Developers that use the GNU GPL protect your rights with two steps: (1) assert copyright on the software, and (2) offer you this License giving you legal permission to copy, distribute and/or modify it. For the developers' and authors' protection, the GPL clearly explains that there is no warranty for this free software. For both users' and authors' sake, the GPL requires that modified versions be marked as changed, so that their problems will not be attributed erroneously to authors of previous versions. Some devices are designed to deny users access to install or run modified versions of the software inside them, although the manufacturer can do so. This is fundamentally incompatible with the aim of protecting users' freedom to change the software. The systematic pattern of such abuse occurs in the area of products for individuals to use, which is precisely where it is most unacceptable. Therefore, we have designed this version of the GPL to prohibit the practice for those products. If such problems arise substantially in other domains, we stand ready to extend this provision to those domains in future versions of the GPL, as needed to protect the freedom of users. Finally, every program is threatened constantly by software patents. States should not allow patents to restrict development and use of software on general-purpose computers, but in those that do, we wish to avoid the special danger that patents applied to a free program could make it effectively proprietary. To prevent this, the GPL assures that patents cannot be used to render the program non-free. The precise terms and conditions for copying, distribution and modification follow. TERMS AND CONDITIONS 0. Definitions. "This License" refers to version 3 of the GNU General Public License. "Copyright" also means copyright-like laws that apply to other kinds of works, such as semiconductor masks. "The Program" refers to any copyrightable work licensed under this License. Each licensee is addressed as "you". "Licensees" and "recipients" may be individuals or organizations. To "modify" a work means to copy from or adapt all or part of the work in a fashion requiring copyright permission, other than the making of an exact copy. The resulting work is called a "modified version" of the earlier work or a work "based on" the earlier work. A "covered work" means either the unmodified Program or a work based on the Program. To "propagate" a work means to do anything with it that, without permission, would make you directly or secondarily liable for infringement under applicable copyright law, except executing it on a computer or modifying a private copy. Propagation includes copying, distribution (with or without modification), making available to the public, and in some countries other activities as well. To "convey" a work means any kind of propagation that enables other parties to make or receive copies. Mere interaction with a user through a computer network, with no transfer of a copy, is not conveying. An interactive user interface displays "Appropriate Legal Notices" to the extent that it includes a convenient and prominently visible feature that (1) displays an appropriate copyright notice, and (2) tells the user that there is no warranty for the work (except to the extent that warranties are provided), that licensees may convey the work under this License, and how to view a copy of this License. If the interface presents a list of user commands or options, such as a menu, a prominent item in the list meets this criterion. 1. Source Code. The "source code" for a work means the preferred form of the work for making modifications to it. "Object code" means any non-source form of a work. A "Standard Interface" means an interface that either is an official standard defined by a recognized standards body, or, in the case of interfaces specified for a particular programming language, one that is widely used among developers working in that language. The "System Libraries" of an executable work include anything, other than the work as a whole, that (a) is included in the normal form of packaging a Major Component, but which is not part of that Major Component, and (b) serves only to enable use of the work with that Major Component, or to implement a Standard Interface for which an implementation is available to the public in source code form. A "Major Component", in this context, means a major essential component (kernel, window system, and so on) of the specific operating system (if any) on which the executable work runs, or a compiler used to produce the work, or an object code interpreter used to run it. The "Corresponding Source" for a work in object code form means all the source code needed to generate, install, and (for an executable work) run the object code and to modify the work, including scripts to control those activities. However, it does not include the work's System Libraries, or general-purpose tools or generally available free programs which are used unmodified in performing those activities but which are not part of the work. For example, Corresponding Source includes interface definition files associated with source files for the work, and the source code for shared libraries and dynamically linked subprograms that the work is specifically designed to require, such as by intimate data communication or control flow between those subprograms and other parts of the work. The Corresponding Source need not include anything that users can regenerate automatically from other parts of the Corresponding Source. The Corresponding Source for a work in source code form is that same work. 2. Basic Permissions. All rights granted under this License are granted for the term of copyright on the Program, and are irrevocable provided the stated conditions are met. This License explicitly affirms your unlimited permission to run the unmodified Program. The output from running a covered work is covered by this License only if the output, given its content, constitutes a covered work. This License acknowledges your rights of fair use or other equivalent, as provided by copyright law. You may make, run and propagate covered works that you do not convey, without conditions so long as your license otherwise remains in force. You may convey covered works to others for the sole purpose of having them make modifications exclusively for you, or provide you with facilities for running those works, provided that you comply with the terms of this License in conveying all material for which you do not control copyright. Those thus making or running the covered works for you must do so exclusively on your behalf, under your direction and control, on terms that prohibit them from making any copies of your copyrighted material outside their relationship with you. Conveying under any other circumstances is permitted solely under the conditions stated below. Sublicensing is not allowed; section 10 makes it unnecessary. 3. Protecting Users' Legal Rights From Anti-Circumvention Law. No covered work shall be deemed part of an effective technological measure under any applicable law fulfilling obligations under article 11 of the WIPO copyright treaty adopted on 20 December 1996, or similar laws prohibiting or restricting circumvention of such measures. When you convey a covered work, you waive any legal power to forbid circumvention of technological measures to the extent such circumvention is effected by exercising rights under this License with respect to the covered work, and you disclaim any intention to limit operation or modification of the work as a means of enforcing, against the work's users, your or third parties' legal rights to forbid circumvention of technological measures. 4. Conveying Verbatim Copies. You may convey verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice; keep intact all notices stating that this License and any non-permissive terms added in accord with section 7 apply to the code; keep intact all notices of the absence of any warranty; and give all recipients a copy of this License along with the Program. You may charge any price or no price for each copy that you convey, and you may offer support or warranty protection for a fee. 5. Conveying Modified Source Versions. You may convey a work based on the Program, or the modifications to produce it from the Program, in the form of source code under the terms of section 4, provided that you also meet all of these conditions: a) The work must carry prominent notices stating that you modified it, and giving a relevant date. b) The work must carry prominent notices stating that it is released under this License and any conditions added under section 7. This requirement modifies the requirement in section 4 to "keep intact all notices". c) You must license the entire work, as a whole, under this License to anyone who comes into possession of a copy. This License will therefore apply, along with any applicable section 7 additional terms, to the whole of the work, and all its parts, regardless of how they are packaged. This License gives no permission to license the work in any other way, but it does not invalidate such permission if you have separately received it. d) If the work has interactive user interfaces, each must display Appropriate Legal Notices; however, if the Program has interactive interfaces that do not display Appropriate Legal Notices, your work need not make them do so. A compilation of a covered work with other separate and independent works, which are not by their nature extensions of the covered work, and which are not combined with it such as to form a larger program, in or on a volume of a storage or distribution medium, is called an "aggregate" if the compilation and its resulting copyright are not used to limit the access or legal rights of the compilation's users beyond what the individual works permit. Inclusion of a covered work in an aggregate does not cause this License to apply to the other parts of the aggregate. 6. Conveying Non-Source Forms. You may convey a covered work in object code form under the terms of sections 4 and 5, provided that you also convey the machine-readable Corresponding Source under the terms of this License, in one of these ways: a) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by the Corresponding Source fixed on a durable physical medium customarily used for software interchange. b) Convey the object code in, or embodied in, a physical product (including a physical distribution medium), accompanied by a written offer, valid for at least three years and valid for as long as you offer spare parts or customer support for that product model, to give anyone who possesses the object code either (1) a copy of the Corresponding Source for all the software in the product that is covered by this License, on a durable physical medium customarily used for software interchange, for a price no more than your reasonable cost of physically performing this conveying of source, or (2) access to copy the Corresponding Source from a network server at no charge. c) Convey individual copies of the object code with a copy of the written offer to provide the Corresponding Source. This alternative is allowed only occasionally and noncommercially, and only if you received the object code with such an offer, in accord with subsection 6b. d) Convey the object code by offering access from a designated place (gratis or for a charge), and offer equivalent access to the Corresponding Source in the same way through the same place at no further charge. You need not require recipients to copy the Corresponding Source along with the object code. If the place to copy the object code is a network server, the Corresponding Source may be on a different server (operated by you or a third party) that supports equivalent copying facilities, provided you maintain clear directions next to the object code saying where to find the Corresponding Source. Regardless of what server hosts the Corresponding Source, you remain obligated to ensure that it is available for as long as needed to satisfy these requirements. e) Convey the object code using peer-to-peer transmission, provided you inform other peers where the object code and Corresponding Source of the work are being offered to the general public at no charge under subsection 6d. A separable portion of the object code, whose source code is excluded from the Corresponding Source as a System Library, need not be included in conveying the object code work. A "User Product" is either (1) a "consumer product", which means any tangible personal property which is normally used for personal, family, or household purposes, or (2) anything designed or sold for incorporation into a dwelling. In determining whether a product is a consumer product, doubtful cases shall be resolved in favor of coverage. For a particular product received by a particular user, "normally used" refers to a typical or common use of that class of product, regardless of the status of the particular user or of the way in which the particular user actually uses, or expects or is expected to use, the product. A product is a consumer product regardless of whether the product has substantial commercial, industrial or non-consumer uses, unless such uses represent the only significant mode of use of the product. "Installation Information" for a User Product means any methods, procedures, authorization keys, or other information required to install and execute modified versions of a covered work in that User Product from a modified version of its Corresponding Source. The information must suffice to ensure that the continued functioning of the modified object code is in no case prevented or interfered with solely because modification has been made. If you convey an object code work under this section in, or with, or specifically for use in, a User Product, and the conveying occurs as part of a transaction in which the right of possession and use of the User Product is transferred to the recipient in perpetuity or for a fixed term (regardless of how the transaction is characterized), the Corresponding Source conveyed under this section must be accompanied by the Installation Information. But this requirement does not apply if neither you nor any third party retains the ability to install modified object code on the User Product (for example, the work has been installed in ROM). The requirement to provide Installation Information does not include a requirement to continue to provide support service, warranty, or updates for a work that has been modified or installed by the recipient, or for the User Product in which it has been modified or installed. Access to a network may be denied when the modification itself materially and adversely affects the operation of the network or violates the rules and protocols for communication across the network. Corresponding Source conveyed, and Installation Information provided, in accord with this section must be in a format that is publicly documented (and with an implementation available to the public in source code form), and must require no special password or key for unpacking, reading or copying. 7. Additional Terms. "Additional permissions" are terms that supplement the terms of this License by making exceptions from one or more of its conditions. Additional permissions that are applicable to the entire Program shall be treated as though they were included in this License, to the extent that they are valid under applicable law. If additional permissions apply only to part of the Program, that part may be used separately under those permissions, but the entire Program remains governed by this License without regard to the additional permissions. When you convey a copy of a covered work, you may at your option remove any additional permissions from that copy, or from any part of it. (Additional permissions may be written to require their own removal in certain cases when you modify the work.) You may place additional permissions on material, added by you to a covered work, for which you have or can give appropriate copyright permission. Notwithstanding any other provision of this License, for material you add to a covered work, you may (if authorized by the copyright holders of that material) supplement the terms of this License with terms: a) Disclaiming warranty or limiting liability differently from the terms of sections 15 and 16 of this License; or b) Requiring preservation of specified reasonable legal notices or author attributions in that material or in the Appropriate Legal Notices displayed by works containing it; or c) Prohibiting misrepresentation of the origin of that material, or requiring that modified versions of such material be marked in reasonable ways as different from the original version; or d) Limiting the use for publicity purposes of names of licensors or authors of the material; or e) Declining to grant rights under trademark law for use of some trade names, trademarks, or service marks; or f) Requiring indemnification of licensors and authors of that material by anyone who conveys the material (or modified versions of it) with contractual assumptions of liability to the recipient, for any liability that these contractual assumptions directly impose on those licensors and authors. All other non-permissive additional terms are considered "further restrictions" within the meaning of section 10. If the Program as you received it, or any part of it, contains a notice stating that it is governed by this License along with a term that is a further restriction, you may remove that term. If a license document contains a further restriction but permits relicensing or conveying under this License, you may add to a covered work material governed by the terms of that license document, provided that the further restriction does not survive such relicensing or conveying. If you add terms to a covered work in accord with this section, you must place, in the relevant source files, a statement of the additional terms that apply to those files, or a notice indicating where to find the applicable terms. Additional terms, permissive or non-permissive, may be stated in the form of a separately written license, or stated as exceptions; the above requirements apply either way. 8. Termination. You may not propagate or modify a covered work except as expressly provided under this License. Any attempt otherwise to propagate or modify it is void, and will automatically terminate your rights under this License (including any patent licenses granted under the third paragraph of section 11). However, if you cease all violation of this License, then your license from a particular copyright holder is reinstated (a) provisionally, unless and until the copyright holder explicitly and finally terminates your license, and (b) permanently, if the copyright holder fails to notify you of the violation by some reasonable means prior to 60 days after the cessation. Moreover, your license from a particular copyright holder is reinstated permanently if the copyright holder notifies you of the violation by some reasonable means, this is the first time you have received notice of violation of this License (for any work) from that copyright holder, and you cure the violation prior to 30 days after your receipt of the notice. Termination of your rights under this section does not terminate the licenses of parties who have received copies or rights from you under this License. If your rights have been terminated and not permanently reinstated, you do not qualify to receive new licenses for the same material under section 10. 9. Acceptance Not Required for Having Copies. You are not required to accept this License in order to receive or run a copy of the Program. Ancillary propagation of a covered work occurring solely as a consequence of using peer-to-peer transmission to receive a copy likewise does not require acceptance. However, nothing other than this License grants you permission to propagate or modify any covered work. These actions infringe copyright if you do not accept this License. Therefore, by modifying or propagating a covered work, you indicate your acceptance of this License to do so. 10. Automatic Licensing of Downstream Recipients. Each time you convey a covered work, the recipient automatically receives a license from the original licensors, to run, modify and propagate that work, subject to this License. You are not responsible for enforcing compliance by third parties with this License. An "entity transaction" is a transaction transferring control of an organization, or substantially all assets of one, or subdividing an organization, or merging organizations. If propagation of a covered work results from an entity transaction, each party to that transaction who receives a copy of the work also receives whatever licenses to the work the party's predecessor in interest had or could give under the previous paragraph, plus a right to possession of the Corresponding Source of the work from the predecessor in interest, if the predecessor has it or can get it with reasonable efforts. You may not impose any further restrictions on the exercise of the rights granted or affirmed under this License. For example, you may not impose a license fee, royalty, or other charge for exercise of rights granted under this License, and you may not initiate litigation (including a cross-claim or counterclaim in a lawsuit) alleging that any patent claim is infringed by making, using, selling, offering for sale, or importing the Program or any portion of it. 11. Patents. A "contributor" is a copyright holder who authorizes use under this License of the Program or a work on which the Program is based. The work thus licensed is called the contributor's "contributor version". A contributor's "essential patent claims" are all patent claims owned or controlled by the contributor, whether already acquired or hereafter acquired, that would be infringed by some manner, permitted by this License, of making, using, or selling its contributor version, but do not include claims that would be infringed only as a consequence of further modification of the contributor version. For purposes of this definition, "control" includes the right to grant patent sublicenses in a manner consistent with the requirements of this License. Each contributor grants you a non-exclusive, worldwide, royalty-free patent license under the contributor's essential patent claims, to make, use, sell, offer for sale, import and otherwise run, modify and propagate the contents of its contributor version. In the following three paragraphs, a "patent license" is any express agreement or commitment, however denominated, not to enforce a patent (such as an express permission to practice a patent or covenant not to sue for patent infringement). To "grant" such a patent license to a party means to make such an agreement or commitment not to enforce a patent against the party. If you convey a covered work, knowingly relying on a patent license, and the Corresponding Source of the work is not available for anyone to copy, free of charge and under the terms of this License, through a publicly available network server or other readily accessible means, then you must either (1) cause the Corresponding Source to be so available, or (2) arrange to deprive yourself of the benefit of the patent license for this particular work, or (3) arrange, in a manner consistent with the requirements of this License, to extend the patent license to downstream recipients. "Knowingly relying" means you have actual knowledge that, but for the patent license, your conveying the covered work in a country, or your recipient's use of the covered work in a country, would infringe one or more identifiable patents in that country that you have reason to believe are valid. If, pursuant to or in connection with a single transaction or arrangement, you convey, or propagate by procuring conveyance of, a covered work, and grant a patent license to some of the parties receiving the covered work authorizing them to use, propagate, modify or convey a specific copy of the covered work, then the patent license you grant is automatically extended to all recipients of the covered work and works based on it. A patent license is "discriminatory" if it does not include within the scope of its coverage, prohibits the exercise of, or is conditioned on the non-exercise of one or more of the rights that are specifically granted under this License. You may not convey a covered work if you are a party to an arrangement with a third party that is in the business of distributing software, under which you make payment to the third party based on the extent of your activity of conveying the work, and under which the third party grants, to any of the parties who would receive the covered work from you, a discriminatory patent license (a) in connection with copies of the covered work conveyed by you (or copies made from those copies), or (b) primarily for and in connection with specific products or compilations that contain the covered work, unless you entered into that arrangement, or that patent license was granted, prior to 28 March 2007. Nothing in this License shall be construed as excluding or limiting any implied license or other defenses to infringement that may otherwise be available to you under applicable patent law. 12. No Surrender of Others' Freedom. If conditions are imposed on you (whether by court order, agreement or otherwise) that contradict the conditions of this License, they do not excuse you from the conditions of this License. If you cannot convey a covered work so as to satisfy simultaneously your obligations under this License and any other pertinent obligations, then as a consequence you may not convey it at all. For example, if you agree to terms that obligate you to collect a royalty for further conveying from those to whom you convey the Program, the only way you could satisfy both those terms and this License would be to refrain entirely from conveying the Program. 13. Use with the GNU Affero General Public License. Notwithstanding any other provision of this License, you have permission to link or combine any covered work with a work licensed under version 3 of the GNU Affero General Public License into a single combined work, and to convey the resulting work. The terms of this License will continue to apply to the part which is the covered work, but the special requirements of the GNU Affero General Public License, section 13, concerning interaction through a network will apply to the combination as such. 14. Revised Versions of this License. The Free Software Foundation may publish revised and/or new versions of the GNU General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies that a certain numbered version of the GNU General Public License "or any later version" applies to it, you have the option of following the terms and conditions either of that numbered version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the GNU General Public License, you may choose any version ever published by the Free Software Foundation. If the Program specifies that a proxy can decide which future versions of the GNU General Public License can be used, that proxy's public statement of acceptance of a version permanently authorizes you to choose that version for the Program. Later license versions may give you additional or different permissions. However, no additional obligations are imposed on any author or copyright holder as a result of your choosing to follow a later version. 15. Disclaimer of Warranty. THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 16. Limitation of Liability. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. 17. Interpretation of Sections 15 and 16. If the disclaimer of warranty and limitation of liability provided above cannot be given local legal effect according to their terms, reviewing courts shall apply local law that most closely approximates an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. END OF TERMS AND CONDITIONS How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to the public, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 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 3 of the License, 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 this program. If not, see . Also add information on how to contact you by electronic and paper mail. If the program does terminal interaction, make it output a short notice like this when it starts in an interactive mode: Copyright (C) This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, your program's commands might be different; for a GUI interface, you would use an "about box". You should also get your employer (if you work as a programmer) or school, if any, to sign a "copyright disclaimer" for the program, if necessary. For more information on this, and how to apply and follow the GNU GPL, see . The GNU General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General Public License instead of this License. But first, please read . mathtex-1.03/mathtex.c0000644000000000000000000116172011255473472013445 0ustar rootroot/**************************************************************************** * * Copyright(c) 2007-2009, John Forkosh Associates, Inc. All rights reserved. * http://www.forkosh.com mailto: john@forkosh.com * -------------------------------------------------------------------------- * This file is part of mathTeX, which is free software. You may redistribute * and/or modify it under the terms of the GNU General Public License, * version 3 or later, as published by the Free Software Foundation. * MathTeX is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY, not even the implied warranty of MERCHANTABILITY. * See the GNU General Public License for specific details. * By using mathTeX, 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 mathTeX * in accordance with it. * Your mathtex.zip distribution should contain the file COPYING, * an ascii text copy of the GNU General Public License, version 3. * If not, point your browser to http://www.gnu.org/licenses/ * or write to the Free Software Foundation, Inc., * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * -------------------------------------------------------------------------- * * Purpose: o MathTeX, licensed under the gpl, lets you easily embed * LaTeX math in your html pages or blogs, wikis, bb's, etc. * It submits a LaTeX math expression to latex, and * immediately emits the corresponding gif image, rather than * the usual TeX dvi. * For example, * * immediately generates the corresponding gif image, * displaying the rendered expression wherever you put * that tag. * But there's no inherent need to repeatedly write * cumbersome tags as illustrated above. You can write * your own custom tags, or write a wrapper script around * mathTeX to simplify the notation. * See http://www.forkosh.com/mathtex.html for more information. * * Functions: ============================================================= * main(argc,argv) latex's math expression and emits gif/png * mathtex(expression,filename) create image of math expression * setpaths(method) set paths for latex,dvipng,dvips,convert * isnotfound(filename) check "... 2>.err" file for "not found" * validate(expression) remove illegal \commands from expression * advertisement(expression,mode) wrap expression in ad message * mathlog(expression,filename) write entry in log file * makepath(oath,name,extension) construct path/name.extension * isfexists(filename) check whether or not filename exists * isdexists(dirname) check whether or not directory exists * whichpath(program,nlocate) determines path to command * locatepath(program,nlocate) tries locate if whichpath() fails * rrmdir(path) rm -r path * emitcache(cachefile,maxage,isbuffer) dump cachefile to stdout * readcachefile(cachefile,buffer) read cachefile into buffer * crc16(s) 16-bit crc of string s * md5str(instr) md5 hash library functions * unescape_url(url) xlate all %xx's in url to ascii * x2c(what) xlate a single hex "xx" to equivalent ascii char * timelimit(command,killtime) throttle command after killtime * getdirective(string,directive,iscase,isvalid,nargs,args) \dir * mathprep(expression) preprocessor for mathTeX input * strwstr(string,substr,white,sublen) find substr in string * strreplace(string,from,to,iscase,nreplace) change from to to * strchange(nfirst,from,to) change nfirst chars of from to to * isstrstr(string,snippets,iscase) is any snippet in string? * nomath(s) removes/replaces any LaTeX math chars in s * strwrap(s,linelen,tablen)insert \n's and spaces to wrap lines * strpspn(s,reject,segment) non-{[()]} chars of s not in reject * strqspn(s,q,isunescape) find matching " or ' in quoted string * timestamp(tzdelta,ifmt) returns current date:time stamp * tzadjust(tzdelta,year,month,day,hour) adjust time for tzone * daynumber(year,month,day) #calendar days from Jan 1, 1973 * emitembedded(imagenum,isquery) emit embedded image to stdout * embeddedimages(imagenum,nbytes,imgtype) embedded gif or png * * Source: mathtex.c * * -------------------------------------------------------------------------- * Notes o See the comment block above each function * for more information about it. * o MathTeX runs only under Unix-like operating systems. * To compile mathTeX * cc mathtex.c -DLATEX=\"$(which latex)\" \ * -DDVIPNG=\"$(which dvipng)\" \ * -DDVIPS=\"$(which dvips)\" \ * -DCONVERT=\"$(which convert)\" \ * -o mathtex.cgi * And see discussion of optional -D switches below. * To install mathTeX * (a) mv mathtex.cgi to your cgi-bin/ directory * and chmod its permissions as necessary * (b) mkdir cgi-bin/mathtex which is the cache directory * and chmod its permissions so mathtex.cgi can rw it. * See http://www.forkosh.com/mathtex.html for more information. * o The timelimit() code is adapted from * http://devel.ringlet.net/sysutils/timelimit/ * Compile with -DTIMELIMIT=\"$(which timelimit)\" to use an * installed copy of that program rather than the built-in code. * o Some program parameters adjustable by optional -D switches on * mathTeX's compile line are illustrated with default values... * -DLATEX=\"/usr/share/texmf/bin/latex\" path to LaTeX program * -DDVIPNG=\"/usr/share/texmf/bin/dvipng\"dvipng(same as latex) * -DDVIPS=\"/usr/share/texmf/bin/dvips\" dvips (same as latex) * -DCONVERT=\"/usr/bin/convert\" path to convert executable * -DCACHE=\"mathtex/\" relative path to mathTeX's cache dir * -DTIMELIMIT=\"/usr/local/bin/timelimit\" path to timelimit * -WARNTIME=10 #secs latex can run using standalone timelimit * -KILLTIME=10 #secs latex can run using built-in timelimit() * -DGIF emit gif images * -DPNG emit png images * -DDISPLAYSTYLE \[ \displaystyle \] * -DTEXTSTYLE $ \textstyle $ * -DPARSTYLE paragraph mode, supply your own $ $ or \[ \] * -DFONTSIZE=5 1=\tiny,...,5=\normalsize,...,10=\Huge * -DUSEPACKAGE=\"filename\" file containing \usepackage's * -DNEWCOMMAND=\"filename\" file containing \newcommand's * -DDPI=\"120\" dvipng -D DPI parameter (as \"string\") * -DGAMMA=\"2.5\" dvipng --gamma GAMMA param (as \"string\") * -DNOQUIET -halt-on-error (default reply q(uiet) to error) * -DTEXTAREANAME=\"formdata\"
      Now click Submit to see it rendered below...

You should see   if you submit the sample expression already in the box.

Examples...

Here are various additional random examples further demonstrating mathTeX'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)
definition of derivative
(3) illustrating \left\{...\right.
and note the accents
(4) \overbrace{}^{} and \underbrace{}_{}
(TeXbook page 181, Exercise 18.41)
(5)
\begin{array}
(6) using \begin{eqnarray*} to align equations

(3) MathTeX markup extensions  

To facilitate its use in html <img> tags, mathTeX recognizes several special \directives that modify latex's behavior. These \directives are usually interpreted by mathTeX, and then removed from your expression before it's submitted to latex for rendering.

For example,

  • <img src="/cgi-bin/mathtex.cgi?\png x^2"> renders x^2 as a png image instead of the default gif format.
  • <img src="/cgi-bin/mathtex.cgi?\usepackage{color}\color{blue}x^2"> renders in blue. In this case, mathTeX removes the familiar LaTeX \usepackage directive from your math expression, and places it in the preamble where it belongs.

You can have as many special mathTeX \directives in an expression as you like. They're recognized anywhere at all in an expression, though these examples show them at the beginning. To simplify readability, additional examples below are more tersely illustrated as "query-string" rather than as <img src="/cgi-bin/mathtex.cgi?query-string">.

mathTeX directives...

\displaystyle or \textstyle or \parstyle
mathTeX's usual default wraps the ?query-string expression   "\int_0^1 f(x)dx"   as   \[ \int_0^1 f(x)dx \],   rendering it in LaTeX's \displaystyle math mode as .
      But the expression   "\textstyle \int_0^1 f(x)dx"   is wrapped as   $ \int_0^1 f(x)dx $,   rendering instead. However, if you compiled mathtex.cgi with the -DTEXTSTYLE option, then \textstyle is the default, and you can write   \displaystyle   in your expressions to override it.
      Finally, writing   \parstyle   in an expression leaves it completely unwrapped, and rendered in LaTeX's paragraph mode. When using   \parstyle,   write your own \[ \]'s and $ $'s as needed. For example,   "\parstyle\noindent the answer is $\frac89$"   renders   .   In this case you could just as easily write a LaTeX \mbox{ } in math mode. But you may find   \parstyle   useful for expressions using LaTeX's eqnarray environment, or for other purposes.
\usepackage{packagename}
When mathTeX sees a \usepackage in your expression, it's removed from the expression and placed in the preamble. So, for example,   \usepackage{color} \color{blue} x^2+y^2   renders in blue. You can have up to nine \usepackages's in an expression. The preamble of mathTeX's default wrapper script already contains \usepackage[latin1]{inputenc}, \usepackage{amsmath} \usepackage{amsfonts} and \usepackage{amssymb}.
\tiny thru \Huge
mathTeX moves LaTeX's ten standard size directives outside the math mode wrapper, so that they can have their intended effect. For example, the expression   "\Large x^2"   is wrapped as   \Large \[ x^2 \],   rendering .   LaTeX's \normalsize default renders .   However, if your expression contains mathTeX's   \parstyle   directive, then any LaTeX size directives are left in place, exactly where you've written them.
\dpi{dots-per-inch}
mathTeX runs dvipng (or convert) at default screen resolution of 120dpi. The directive \dpi{300} generates a much larger 300dpi image instead. Here are samples of several dpi's rendered at \scriptsize and \normalsize,
dpi \scriptsize \normalsize
100
120
160
200
\gammacorrection{gamma-correction}
mathTeX runs dvipng with default gamma=2.5 (or convert with default 0.5). The directive \gammacorrection{3.5} renders a darker-than-usual gamma=3.5 image when run with dvipng (or lighter-than-usual when run with convert).
      Note: This gamma correction confusion arises, I believe, as follows. Consider a grayscale from x=0 for black to x=1 for white. Then, the canonical formula to apply gamma correction  is , whereby  becomes blacker and  becomes whiter. The convert program appears to follow this convention, whereas dvipng applies instead.
      Here are some samples (unchanging grayscale values up and down a column signal the corresponding program is unavailable)
gamma dvipng dvips/convert
0.25
0.50
1.0
2.0
4.0
\gif or \png
mathTeX's default renders expressions as gif images. If you want a png image instead, write the directive   \png   in your expression. However, if you compiled mathtex.cgi with the –DPNG switch, then png is the default, and you can write   \gif   in your expression to obtain a gif image.
\dvips or \dvipng
mathTeX uses dvipng when it's available, or dvips and convert otherwise, to render LaTeX's dvi output as gif or png images. If all three programs are available on your server, then expressions containing   \dvips   are rendered using dvips/convert instead of dvipng. Or, when dvips/convert is the default (see \switches below), expressions containing   \dvipng   are rendered using dvipng instead of dvips/convert.
\quiet or \noquiet or \nquiet{n}
If any "! LaTeX Error:" is emitted while processing your expression, mathTeX's default replies <Enter> to the first three errors, and then replies "x", halting LaTeX before it produces a .dvi file. But if your expression contains   \quiet,   then mathTeX replies "q" to the first error, making LaTeX enter batchmode, whereas if your expression contains   \noquiet,   then mathTeX replies "x" to the first error, halting LaTeX immediately. If your expression contains  \nquiet{n},   then mathTeX replies <Enter> to the first n errors, and then replies "x".
\cache or \nocache
By default, mathTeX saves each new image in its cache directory, rather than re-rendering the same image every time the same expression is submitted. But expressions containing   \nocache   are not cached. Expressions containing \today and/or \time are automatically not cached. Otherwise, include \nocache in your expression if it contains volatile information that might affect its appearance between renderings. (The \cache directive forces the image of that expression to be cached, but is usually unnecessary since caching is the default.)
\msglevel{verbosity}
To help debug problems that matheTeX's error messages don't resolve, resubmit the same failed expression with   \msglevel{9}   added.
      After it fails again, login to a shell on your server, and   cd cgi-bin/mathtex/   to mathTeX's cache directory. Then   ls -alt|less   to see the most recent files. These should include   yourexpression.out   (and yourexpression.gif if an image was created), where filename yourexpression is the 32-character MD5 hash of your failed expression.
      Now   cd ..   back up to your cgi-bin/ directory, and you should see a new directory cgi-bin/yourexpression/ created by mathTeX.   cd to it, and follow the command-line error instructions below. When done, you should probably   rm -r cgi-bin/yourexpression/   which is no longer needed (ditto the .out and .gif files in mathTeX's cache if you want to clean up completely).
\which{programname}
mathTeX must be compiled with several –Dswitches that specify paths to its dependencies. If you can't determine these required paths, mathTeX's   \which{programname}   may provide some help (also see \switches below). For example,
directive renders
\which{latex}
\which{dvipng}
\which{dvips}
\which{convert}
displays known paths to mathTeX's dependencies, as they're installed on this server. However, there's a small "Catch-22" (circular logic that may bite you): mathTeX must already know these paths before it runs the programs that display them. You may be able to temporarily circumvent this problem by compiling
   cc mathtex.c –o mathtex.cgi
without any required switches at all. When compiled like this, mathTeX uses which to determine the required paths. If they're found, then mathTeX will run and display them; if not, you'll likely see message 7 or message 9 instead. If mathTeX does run, and displays the required paths, you should immediately re-compile it with the required –Dswitches. Execution time can be doubled, or even worse, when mathTeX has to find these paths itself.
      When \which{programname} can't find the path, mathTeX displays instead. But mathTeX may also display , signalling that Unix which failed. In this case, mathTeX searches your server's locate database, if it exists, and displays that path instead. The "not found" message signals which and locate both failed.
\switches
Submitting the expression   \switches   to mathTeX renders
 ,
displaying several (more will be added) of mathTeX's compile-line switches. "Program image" isn't really a switch: it's the filename of the running program, usually   mathtex.cgi   unless you compiled it differently.
      "Paths" displays what mathTeX knows about the full paths to its dependencies. On the right-hand side of each path is the source of that information. There are four possible sources, listed in order of reliablility (most reliable first):
  • (switch)   means you compiled mathTeX with a –Dswitch for that path. You should always compile mathTeX with its dependencies:   –DLATEX, and either –DDVIPNG or both –DDVIPS and –DCONVERT. When that's not possible, read \which{ } above and temporarily compile mathTeX without them.
  • (which)   means the corresponding –Dswitch was not supplied, but Unix which found the program. If that's latex or another of your dependencies, then re-compile mathTeX with a –Dswitch containing the displayed information.
  • (locate)   means Unix which failed, but your server's locate database found the path. Again, re-compile mathTeX if that's one of your dependencies.
  • (default)   means no path information was found. A default path programmed into mathTeX is displayed instead. This default is frequently wrong. In fact, (default) typically means that the corresponding program isn't installed on your server at all. In that case, if the program is one of your dependencies, you'll likely see message 7 or message 9 instead of the \switches output illustrated above.
Either dvipng or dvips and convert can render LaTeX's dvi output as gif or png images. MathTeX's default choice is based on the reliablity of path information to these programs:   (switch) is most reliable, followed by (which) or (locate), rated equally, and finally (default) is least realiable. If a (switch) path to dvipng is available (i.e., if you compiled mathTeX with a –DDVIPNG switch), then dvipng is default. Otherwise, if (switch) paths to both dvips and convert are available, then they're default. Otherwise, (which) or (locate) paths are preferred to (default), and dvipng wins a "tie".
\time
LaTeX's \today is usually sufficient for the slow-paced world of print. But you may want finer-grained resolution for the faster-paced online world. mathTeX provides   \time   for this purpose, replacing it with the current hh:mm:ss wherever it occurs. The date/timestamp at the top of this document is rendered by mathTeX with an expression like   "\parstyle\begin{center}\today\\\time\end{center}".   You can see the exact expression by clicking on that image. I'm not reproducing it here because mathTeX doesn't cache images containing \today or \time. So use   \time   sparingly because every occurrence is re-rendered through LaTeX.
\advertisement
An expression containing   \advertisement   is displayed along with your mathTeX advertisement rather than by itself, regardless of -DADFREQUENCY. For example,
  c=\sqrt{a^2+b^2}           \advertisement c=\sqrt{a^2+b^2}  
 
See Advertisement to replace the default advertisement, illustrated above, with your own.
\version
An expression containing   \version   is displayed along with mathTeX's current version number. For example,
  \version c=\sqrt{a^2+b^2}  
\environment
Submitting the expression   \environment   to mathTeX renders
displaying the http environment variables known to mathTeX. This is primarily a programming aid, showing information available to mathTeX that might facilitate future enhancements.

(4) Installation and Testing  

Note: The current release of mathTeX only runs
on Unix-like operating systems.


Very quickly   ---   First, install mathTeX's dependencies:
        a recent TeX distribution with dvipng,
on your server, or see mimeTeX if you can't.
Then, download mathtex.zip and type
        unzip mathtex.zip
cc mathtex.c –DLATEX=\"$(which latex)\"   \
  –DDVIPNG=\"$(which dvipng)\"   \
  –o mathtex.cgi

(see –Dswitches below for more information).
Finally,
        mv mathtex.cgi   to your cgi-bin/ directory,
chmod permissions as necessary, and you're all done.
Read the rest of this section only if you want more information.

mathTeX's source code is standard Unix C, which should compile and run without change on any posix-compliant Unix platform. The current release of mathTeX only runs under Unix-like operating systems. The three steps needed to compile, install and test mathTeX are:

(1) Install LaTeX and download mathTeX...

  • First, make sure you have a recent
            TeX distribution with dvipng installed on your server.
    MathTeX's dependencies are the latex and dvipng programs, along with all necessary fonts, etc, from your TeX distribution.
            If you prefer to compile mathTeX with the optional –DDVIPS and –DCONVERT switches (Step 2 immediately below), then dvips from your TeX distribution, and convert from the ImageMagick package, are used instead of dvipng.
            These dependencies — always latex and either dvipng or dvips/convert — must all be installed on your server before you can run mathTeX. Ask your ISP or sysadmin if you have any questions or problems installing them. Or see mimeTeX if you can't install them.
  • Then download and unzip mathtex.zip in any convenient working directory. Your working directory should now contain
    README mathTeX release notes
    COPYING GPL license, version 3, under which you may use mathTeX
    mathtex.c mathTeX source program and all required functions
    mathtex.html this file, the mathTeX user manual

(2) Compile mathTeX and test it from the Unix shell...

  • To compile a mathTeX executable that emits default gif images generated by dvipng (recommended), just type
            cc   mathtex.c   –DLATEX=\"$(which latex)\"   \
            –DDVIPNG=\"$(which dvipng)\"   –o   mathtex.cgi
    Alternatively, to compile a mathTeX executable that emits default gif images generated by dvips/convert, just type
            cc   mathtex.c   –DLATEX=\"$(which latex)\"   \
            –DDVIPS=\"$(which dvips)\"   –DCONVERT=\"$(which convert)\"   \
            –o   mathtex.cgi
    But note that dvipng is easily twice as fast as dvips/convert, and it produces somewhat smaller image files.
            For default png (instead of gif) images, add the optional –DPNG switch to either cc command above. All of mathTeX's optional compile-line switches are discussed below.
            The required switches shown above define paths to mathTeX's dependencies, either latex and dvipng, or latex and dvips/convert. See required switches below for additional information about these path switches, including discussion of that $(which program) construction.
  • Immediately after compiling mathTeX, test it from the Unix shell by typing
            ./mathtex.cgi   "x^2+y^2"   –m 9   –o test
    at the command prompt. After the copyright notice, screen output should look something like
        mathTeX> running image:     ./mathtex.cgi
        mathTeX> input expression:  "x^2+y^2"
        mathTeX> working directory: 8dfaf8281769c217b7e78b27a4747285/
        mathTeX> output image file: test.gif 
    Bring up the output file test.gif in your browser, which should display the rendered image of x^2+y^2. If it does, you can rm -r that working directory and proceed to the next (Install) step. If not, there's some error that _must_ be fixed before proceeding: mathTeX is not going to emit gifs from your server if it won't run from the command line.
    To troubleshoot command-line errors...
    • First,   cd 8dfaf8281769c217b7e78b27a4747285/   to that working directory (whose name is the 32-character MD5 hash of your expression) shown on the screen output above.
    • If it's not an empty file,   view latex.err   A message something like   latex: command not found   probably means that your   –DLATEX=\"path/to/latex\"   is wrong, or that latex is installed wrong. Fix that, or any other indicated error, and then re-compile mathTeX and test it again.
    • Otherwise, if latex.err is empty, then   view latex.out   which contains runtime messages issued by latex, including messages reporting unresolved errors. For example, \usepackage{junk} reports the error File `junk.sty' not found.   Find and fix any reported errors, and then re-compile mathTeX and test it again.
    • If latex.err and latex.out contain no errors, then latex.dvi should contain the dvi image of your expression. Check it with xdvi or any other dvi viewer supplied with your latex distribution. Then view dvipng.err and dvipng.out for any reported errors (note that dvipng emits a benign copyright message to dvipng.out).
    • You should have found some error along the way. Troubleshoot as necessary. Your most likely (and most obvious) problems are: mathTeX's dependencies are installed incorrectly or not at all, you compiled mathtex.cgi with the wrong paths (check which's output), or you don't have rw permissions in the directory you're testing from.

(3) Install mathTeX and test it from a browser...

  • Install your compiled mathtex.cgi executable only after successfully testing it from the Unix shell. Just
            mv mathtex.cgi   to your web server's cgi-bin/ directory,
            chmod permissions as necessary, and you're all done.
    cgi-bin/mathtex.cgi must be executable by your web server, and it must have rw permissions in the cgi-bin/ directory where it's installed. The first time it runs, mathtex.cgi will mkdir mathtex/, where rendered images are subsequently cached. Permissions and ownerships must be set to allow this. chmod 755 typically works, but ask your ISP or sysadmin if you have any questions or problems.
  • Immediately after installation, type a url into your browser's locator window something like
            http://www.yourdomain.com/cgi-bin/mathtex.cgi?\message
    which should display message 1
           
    in the upper-left corner of your window. If, instead, you see Not Found or Error 500 emitted by your server, then mathTeX isn't running. Check that you installed it in the correct directory, set its permissions properly, etc.
  • The preceding test just checked that mathtex.cgi runs from your server. This current test checks that your –DLATEX, etc, paths are correct, and that mathtex.cgi has rw permissions in your cgi-bin/ directory. Type a url into your browser's locator window something like
            http://www.yourdomain.com/cgi-bin/mathtex.cgi?x^2+y^2
    which should display     in the upper-left corner of your window, just like clicking this link does, which tests my mathtex.cgi,
            http://www.forkosh.com/cgi-bin/mathtex.cgi?x^2+y^2
    If you see the same image from your own   yourdomain   link, then you've completed a successful mathTeX installation.
            Otherwise, you'll probably see one of mathTeX's error messages illustrated below. Read the accompanying description, and try to resolve the problem accordingly.

Run-time error messages...

Gif images for 15 messages are embedded in mathTeX, displayable so long as mathtex.cgi can run from your server, even without latex and without rw permissions in your cgi-bin/ directory. In addition, your server may display the first two messages below if mathtex.cgi can't run. Any embedded mathTeX message can be intentionally displayed by submitting an expression containing the special mathTeX directive \message{1} through \message{15} (an out-of-bounds argument, or \message with no argument, displays message 1). Otherwise, various errors signal "unintentional" displays of the corresponding message, e.g., if your –DLATEX switch specifies the wrong path to latex, then you'll see message 7 (unless some earlier error supercedes it).

    Message         Description    
The requested URL was not found. You typed the wrong url, or mathtex.cgi is not installed where you think it is.
Internal server error 500 If mathtex.cgi's permissions are chmod'ed improperly, if your account isn't set up to run cgi's, etc, then mathTeX will not run at all. You'll probably see this error message emitted by your server instead.
Immediately after installing mathtex.cgi to your cgi-bin/ directory, type a url of the form
    yourdomain.com/cgi-bin/mathtex.cgi?\message
into your browser. You should see this message. It means mathtex.cgi ran successfully, its permissions are set properly, and the account hosting yourdomain can run cgi's.
Traps any otherwise unidentified error condition.
The combination of permissions/ownerships on mathtex.cgi itself, and on the cgi-bin/ directory where it's installed, prohibit mathTeX from creating its cache directory mathtex/ underneath cgi-bin/. Change permissions/ownerships as needed.
Same problem as message 3 above, except this time mathTeX can't create a temporary work directory under cgi-bin/.
Unanticipated error. MathTeX should be able to cd to a directory it just created.
Unanticipated error. MathTeX should be able to open a file (for write) in a directory it just created.
Either latex is not installed, or your –DLATEX path to it is incorrect. It's also possible that the shell host on which you compiled mathTeX has different volumes or mount points than your server (see path switches). Check with your ISP or sysadmin, or try mathTeX's \which directive.
A simple latex error, like \alfa instead of \alpha, should not cause this problem (unless your expression contains \noquiet). It's more likely caused by a missing font or package, etc. Simplify your expression until it works, and see if that helps identify the cause. Or add \msglevel{9} to your expression, and check files latex.out and latex.err for error messages.
Either dvipng is not installed, or your –DDVIPNG path to it is incorrect. Also see the remark in message 7.
Rerun the same expression with \msglevel{9} added. Then check files latex.out and latex.err, and dvipng.out and dvipng.err for any clues to the cause of this error.
Either dvips is not installed, or your –DDVIPS path to it is incorrect. Also see the remark in message 7.
Rerun the same expression with \msglevel{9} added. Then check files latex.out and latex.err, and dvips.out and dvips.err for any clues to the cause of this error.
Either convert is not installed, or your –DCONVERT path to it is incorrect. Also see the remark in message 7.
Rerun the same expression with \msglevel{9} added. Then check files latex.out and latex.err, dvips.out and dvips.err, and convert.out and convert.err for any clues to the cause of this error.
An image file was apparently created successfully, but is now inaccessible to mathTeX. Rerun the same expression. If it fails again, rerun it with \msglevel{9} added. Then check all .out and .err files for any clues to the cause of this error.

Compile-line switches...

Required switches...
      MathTeX's required –D switches specify paths to the programs it needs to render LaTeX expressions as images. Your Unix PATH environment variable usually contains the directories where these programs reside. And in that case, the Unix shell command   which progname   emits the string   /path/to/progname.
      Then you can manually copy which's output to the switch, e.g., if   which latex   emits   /usr/bin/latex   then just write the switch   –DLATEX=\"/usr/bin/latex\"   Alternatively, you can use the Unix shell's   $( )   construction to automatically pipe which's output into the switch, e.g.,   –DLATEX=\"$(which latex)\"   automatically places that same path to latex between the literal \"  \" quotes.
      If which doesn't work, you must nevertheless make sure that latex and mathTeX's other dependencies are all installed on your server. Then determine the proper paths to them yourself (ask your ISP or sysadmin, or try mathTeX's \which directive), and manually write mathTeX's required –D switches as described above.
      Occasionally, which may seem to work, but actually doesn't, because your shell account and internet server are hosted on different machines, with different volumes mounted and/or different mount points. When this happens, server volumes are nfs-mounted by your shell machine, so you can work on your internet files. Conversely, shell volumes aren't necessarily mounted by the server, so latex could be visible from your shell but not from the server. Check with your ISP or sysadmin about network topology if you suspect something like this, or mathTeX's \which directive may help. In any case, mathTeX's dependencies, latex and either dvipng or dvips/convert, must be available to your server, and you must compile mathtex.cgi with their paths on your server.
–DLATEX=\"/path/to/latex\"
–DDVIPNG=\"/
path/to/dvipng\"
mathTeX always requires the –DLATEX switch, and its recommended default (using dvipng to render latex's dvi output as gif or png images) also requires the –DDVIPNG switch. So your standard cc command to compile mathTeX looks like
      cc   mathtex.c   \
        –DLATEX=\"$(which latex)\"   \
        –DDVIPNG=\"$(which dvipng)\"   \
        –o   mathtex.cgi
–DDVIPS=\"/path/to/dvips\"
–DCONVERT=\"/
path/to/convert\"
If you can't (or don't want to) use dvipng, then compile mathTeX with the –DDVIPS and –DCONVERT switches (instead of –DDVIPNG). Then dvips from your TeX distribution, and convert from the ImageMagick package, are used (instead of dvipng) to render latex's dvi output as gif or png images. In this case, your cc command to compile mathTeX looks like
      cc   mathtex.c   \
        –DLATEX=\"$(which latex)\"   \
        –DDVIPS=\"$(which dvips)\"   \
        –DCONVERT=\"$(which convert)\"   \
        –o   mathtex.cgi
Finally, if all three programs (dvipng and dvips and convert) are installed on your server, you can compile mathTeX with all the –D switches. This defaults to dvipng, but permits users to submit expressions containing the special \dvips and \dvipng directives, regardless of mathTeX's default. So a comprehensive cc command looks like
      cc   mathtex.c   \
        –DLATEX=\"$(which latex)\"   \
        –DDVIPNG=\"$(which dvipng)\"   \
        –DDVIPS=\"$(which dvips)\"   \
        –DCONVERT=\"$(which convert)\"   \
        –o   mathtex.cgi
along with any other optional switches you choose from those described below,
Optional switches...
      In addition to the –DLATEX and –DDVIPNG switches required on the mathTeX's compile line, as discussed above, you may also include the following optional –D switches, whose functionality is discussed below. Whenever a switch takes a value, its default value is illustrated. An italicized value means there is no default.
–DCACHE=\"mathtex/\"
By default, mathTeX saves each new image it renders to a file in directory   mathtex/   (relative to the cgi-bin/ directory where you installed mathtex.cgi). Then, every time it's given the same expression, mathTeX reads that file rather than re-rendering the same image. You can specify any other cache directory with the   –DCACHE=\"path/\"   switch. Either way, mathTeX's cache directory must be read/writable by it, so set permissions (typically chmod 755) as necessary.
      mathTeX occasionally disables caching, e.g., expressions containing \today are always re-rendered since the date may have changed. Otherwise, caching is mandatory and cannot be disabled.
      Cached image files are named filename.gif or filename.png, where filename is the 32-character MD5 hash of the LaTeX expression. When caching a new image, mathTeX also updates the file path/mathtex.log containing a timestamp, filename, LaTeX expression, and http referer for each new file created. A sample entry looks like
---------------------------------------------------------------------
2007-10-11:09:00:53am            f8ccc8dd93c8eeb1d9c40b353ef781e0.gif
\LARGE x=\frac{-b\pm\sqrt{b^2-4ac}}{2a}
http://www.forkosh.com/mathtex.html
---------------------------------------------------------------------
–DGIF   or   –DPNG
mathTeX generates gif or png images. Users can specify which format they want by including a \gif or \png mathTeX directive in submitted expressions. Otherwise, mathTeX's default is specified at compile time by a   –DGIF   or   –DPNG   switch. If a submitted expression contains neither directive, and if mathTeX was compiled with neither switch, then gif is the default.
–DDISPLAYSTYLE   or   –DTEXTSTYLE   or   –DPARSTYLE
mathTeX's default wraps user expressions inside   \[  \],   rendering generated images in LaTeX's \displaystyle math mode. The   –DTEXTSTYLE   switch wraps expressions inside   $  $,   rendering generated images in LaTeX's \textstyle math mode. And the   –DPARSTYLE   switch leaves expressions unwrapped, rendering generated images in LaTeX's default paragraph mode. Users can override any compiled default with a mathTeX style directive.
–DFONTSIZE=5
You can specify   –DFONTSIZE=1   thru   –DFONTSIZE=10   on mathTeX's compile line, corresponding to default LaTeX font sizes \tiny thru \Huge. If no switch is supplied, the default 5 corresponds to \normalsize. Users can override any compiled default with a mathTeX \tiny...\Huge directive.
–DDPI=\"120\"
The   –DPI   switch changes mathTeX's default screen resolution of \"120\" dots-per-inch, which you enter as a string. Some samples are illustrated above.
–DGAMMA=\"2.5\"
The   –DGAMMA   switch changes mathTeX's default gamma correction of \"2.5\" (for dvipng), which you enter as a string. Some samples are illustrated above.
–DQUIET     or
–DNOQUIET     or
–DNQUIET=n
If any "! LaTeX Error:" is emitted while processing your expression, mathTeX's default replies <Enter> to the first three errors, and then replies "x", halting LaTeX before it produces a .dvi file. Compiling mathTeX with   –DQUIET   replies "q" to the first error, making LaTeX enter batchmode, whereas compiling with   –DNOQUIET   replies "x" to the first error, halting LaTeX immediately. Compiling mathTeX with   –DNQUIET=n   replies <Enter> to the first n errors, and then replies "x". User expressions may contain \quiet\noquiet or \nquiet{n} to override any compiled default.
–DREFERER=\"domain\"     or
–DREFERER=\"domain1,domain2,etc\"
If you compile mathTeX without a   –DREFERER=\" \"   switch, then anyone on the internet can use your mathtex.cgi program by writing a url of the form   http://www.yourdomain.com/cgi-bin/mathtex.cgi?x^2+y^2.   So you're essentially providing mathTeX as a free web service. I encourage this if you have the compute and disk resources to spare.
      Otherwise, if compiled with   –DREFERER=\"domain\",   then mathTeX performs a case-insensitive search of the environment variable HTTP_REFERER to verify that it contains the authorized   domain   as a substring.
      Or, if given a comma-separated list containing several   domain's   (second form of the switch), then HTTP_REFERER must contain either domain1 or domain2, or etc, as a (case-insensitive) substring.
      If HTTP_REFERER doesn't contain a substring matching any of these domain(s), then mathTeX emits the error message image (reporting HTTP_REFERER on the first line)
     
instead of the requested image.
–DKILLTIME=10
Some expressions can unintentionally (or not) force LaTeX to loop endlessly, causing mathTeX to hang. To avoid this problem, if LaTeX fails to complete within KILLTIME seconds, mathTeX kills it and emits an error. The built-in code for this purpose is in mathTeX's timelimit( ) function, which was adapted from timelimit-1.4. Compiling mathTeX with   –KILLTIME=0   places no timelimit restrictions on LaTeX whatsoever; probably not a good idea.
–DTIMELIMIT=\"/path/to/timelimit\"
Rather than using mathTeX's built-in timelimit( ) code to throttle LaTeX (see –DKILLTIME immediately above), you may optionally install a standalone copy of timelimit-1.4 and use that instead. Compiling mathTeX with a switch of the form   –TIMELIMIT=\"$(which timelimit)\"   uses your installed program instead of mathTeX's built-in timelimit( ) function to throttle LaTeX.
–DMAXMSGLEVEL=999999
If you're running mathTeX as a web service, you should probably compile it with the   –DMAXMSGLEVEL=0   switch. This sets the maximum verbosity allowed in a \msglevel{ } directive. At 9 and above, the work directory and files temporarily created by mathTeX to run latex are left in place as a debugging aid. These remain on your file system unless manually removed. And remote users can't access them, anyway.
–DUSEPACKAGE=\"filename\"
The preamble of mathTeX's default LaTeX wrapper script already contains \usepackage[latin1]{inputenc}, \usepackage{amsmath} \usepackage{amsfonts} and \usepackage{amssymb}. All these packages are used with every expression submitted to mathTeX for rendering. And a specific expression may contain one or more \usepackage{ } directive's applied to that expression only. However, if you want additional packages applied to every expression, edit a file containing lines of the form
      "\\usepackage{color}\n"
      "\\usepackage{bm}\n"
      "etc\n"
and place a corresponding DUSEPACKAGE=\"filename\" switch on mathTeX's compile line. Every line in the file is enclosed in "quotes", contains a \n before the closing quote, and all other backslashes are written as double-backslashes \\. And note that, although \usepackage's are illustrated, you aren't limited to them. All directives from this file are just placed in mathTeX's preamble. So you can modify the preamble any way you like.
–DNEWCOMMAND=\"filename\"
Besides modifying the preamble, you may also want to modify the LaTeX wrapper script's body, particularly with (though not limited to) \newcommand's. Again, edit a file containing lines of the form
      "\\newcommand{\\vec}[2]{\\left({#1}_1,\\ldots,{#1}_{#2}\\right)}\n"
      "etc\n"
and place a corresponding DNEWCOMMAND=\"filename\" switch on mathTeX's compile line. The same editing rules apply: every line in the file is enclosed in "quotes", contains a \n before the closing quote, and all other backslashes are written as double-backslashes \\.
      \renewcommand's in this file are useful to disable LaTeX commands that might pose security risks in mathTeX. For example, although Unix's /etc/passwd file doesn't actually contain passwords, you probably don't want users submitting expressions like \input{/etc/passwd}. MathTeX already disables \input with
      "\\renewcommand{\\input}[1]{\\mbox{[[$\\backslash$input\\{#1\\} illegal]]}}\n"
which just displays   [[\input{file} illegal]]   when the user tries to   \input{file}.   You may want to disable other commands as well.
Advertising switches...
The next two switches set up a mathTeX web service that embeds advertising messages along with rendered images. See mathTeX web service above for further discussion.
–DADFREQUENCY=0
If ADFREQUENCY is defined as a positive number n, then one request out of every n submitted to mathTeX is randomly selected to be displayed along with a pre-defined "advertisement". For example, if your expression is   \large\int_0^xe^{-x^2}dx,   then the default advertisement displays
          instead of just    
See the –DADVERTISEMENT switch immediately below for instructions to define your own advertisement replacing my default.
–DADVERTISEMENT=\"filename\"
To define your own advertisement, replacing my default illustrated immediately above, edit a file containing lines of the form
      "\\begin{center}\n"
      "\\fbox{$\\mbox{\\footnotesize\\LaTeX{} rendering courtesy of}\n"
      "\\atop \\mbox{\\scriptsize http://www.forkosh.com/mathtex.html}$}\\\\ \n"
      "\\vspace*{-4mm}\n"
      " %%beginmath%% %%expression%% %%endmath%% \n"
      "\\end{center}\n"
Use the same editing rules as –DUSEPACKAGE and –DNEWCOMMAND above: every line in the file is enclosed in "quotes", contains a \n before the closing quote, and all other backslashes are written as double-backslashes \\. Note \\\\ at the end of the third line, which LaTeX sees as \\. The entire example shows how my default advertisement is defined.
      Your advertisement may consist of any valid LaTeX commands you like. But it must somewhere contain the line
      " %%beginmath%% %%expression%% %%endmath%% \n"
which is replaced by the user's expression, surrounded by whatever math mode delimiters it specifies. The document remains in paragraph mode, allowing   $ $   and   \[ \]   to be placed wherever you like.
      Once mathTeX is compiled with your advertisement, test it by submitting an expression like   \advertisement x^2+y^2   containing the special mathTeX \advertisement directive, which forces that expression to be rendered with your advertisement. In this case (and with my default advertisement message) we see
          instead of just    
regardless of your ADFREQUENCY value.

Running mathTeX from the shell...

MathTeX is usually run by your web server as a cgi program, obtaining its input expression from the query-string of an html <img> tag. But you can also run mathTeX from your Unix shell, supplying all input on the command line. For example,   ./mathtex.cgi "x^2+y^2" –o equation1   renders an image of x^2+y^2 in file equation1.gif. And with the   –m 9   switch, it's also useful for testing.

The complete command-line syntax for mathTeX is

   ./mathtex.cgi "expression"     expression in quotes, e.g., "x^2+y^2",
               | -f input_file    or read (unquoted) expression from input_file
               [ -o output_file ] write image to ouput_file instead of cache
               [ -m msglevel ]    verbosity of debugging message level
               [ -c cache_directory ]   path to cache directory

   "expression"    Either place LaTeX expression directly on
        the command line, between "quotes", with no -switch
        preceding it, or.....

   -f input_file   .....read (unquoted) expression from input_file.
        The input_file may contain the expression on one line
        or spread out over many lines.  If -o is not also given,
        it defaults to the same filename, e.g., -f expression.tex
        produces output file expression.tex.gif unless an
        explicit -o switch is given.

   -o output_file  write output gif or png image to this filename,
        with .gif or .png extension added to it.  If you want the
        image file written in a directory other than your pwd,
        then specify  -o path/output_file  instead.

   -m msglevel     0-99, controls verbosity/message level for
        debugging output.  If msglevel>=9 then the temporary
        directory containing latex-dvips-convert output is
        not removed.  This is your major debugging aid.

   -c cache_directory  If you specify  -o output_file  then no
        cache directory is used (-c is ignored even if you supply it).
        But if you don't specify  -o output_file  then mathTeX writes
        the rendered image to a filename in its usual cache directory
        path.  This switch maintains the standard mathTeX filename
        convention, but writes files into the specified cache directory
        instead.

   Test or Debugging Example:

     ./mathtex.cgi "\Large\frac1{\sqrt{x^2+y^2}}" -o equation1 -m 9
        creates file equation1.gif and saves all the intermediate
        work in temp subdirectory 673d88e172f77f0aafabf6d72e5777ba/
        which is the MD5 hash of the input expression.

     After the copyright notice, screen output from the above command
     should look something like
        mathTeX> running image:     ./mathtex.cgi
        mathTeX> input expression:  "\Large\frac1{\sqrt{x^2+y^2}}"
        mathTeX> working directory: 673d88e172f77f0aafabf6d72e5777ba/
        mathTeX> output image file: equation1.gif

   Production Example (same as above, but without -m 9):

     ./mathtex.cgi "\Large\frac1{\sqrt{x^2+y^2}}" -o equation1
        creates file equation1.gif containing an image of
        the expression (all intermediate work files are removed).

     After the copyright notice, screen output from the above command
     should look something like
        mathTeX> input expression:  "\Large\frac1{\sqrt{x^2+y^2}}"
        mathTeX> output image file: equation1.gif
     Redirect stdout to /dev/null if you don't want to see it.
   

(5) GPL License  

"My grandfather once told me there are two kinds of people:
    Those who do the work and those who take the credit.
    He told me to try to be in the first group; there was much less competition.
"
Indira Gandhi, the late Prime Minister of India

MathTeX'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 mathTeX entirely at your own risk, with no guarantee of any kind, in particular with no warranty of merchantability.

By using mathTeX, 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 mathTeX 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, 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. For example, courts will stop unauthorized use of unregistered material, but monetary damages are awarded _only_ if you register the copyright before infringement occurs.

Concluding Remarks  

I hope you find mathTeX 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.


Copyright © 2007-2009, John Forkosh Associates, Inc.
email: john@forkosh.com