From e0c6872cf40896c7be36b11dcc744620f10adf1d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Mon, 2 Sep 2019 13:46:59 +0900 Subject: Initial commit --- support/mathtex/mathtex.c | 6620 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 6620 insertions(+) create mode 100644 support/mathtex/mathtex.c (limited to 'support/mathtex/mathtex.c') diff --git a/support/mathtex/mathtex.c b/support/mathtex/mathtex.c new file mode 100644 index 0000000000..787ea227e0 --- /dev/null +++ b/support/mathtex/mathtex.c @@ -0,0 +1,6620 @@ +/**************************************************************************** + * + * Copyright(c) 2007-2012, 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 + * presentwd(nsub) determines pwd, nsub dirs up + * rrmdir(path) rm -r path + * rewritecache(cachefile,maxage) write cachefile with imageinfo + * 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 + * isnumeric(s) determine if s is an integer + * evalterm(store,term) evaluate numeric value of expression + * getstore(store,identifier)return value corresponding to ident + * timewaitfor(whundredths)delay execution for hundredths of sec + * 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 + * calendar(year,month,day) formats one-month calendar string + * 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 + * -DPDFLATEX=\"/usr/share/texmf/bin/pdflatex\" path to pdflatex + * -DDVIPNG=\"/usr/share/texmf/bin/dvipng\" path to dvipng + * -DDVIPS=\"/usr/share/texmf/bin/dvips\" path to dvips + * -DPS2EPSI=\"/usr/bin/ps2epsi\" path to ps2epsi + * -DCONVERT=\"/usr/bin/convert\" path to convert + * -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\"