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/texproc/READ.ME | 34 ++++++++++++++++ support/texproc/texproc.c | 101 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 135 insertions(+) create mode 100644 support/texproc/READ.ME create mode 100644 support/texproc/texproc.c (limited to 'support/texproc') diff --git a/support/texproc/READ.ME b/support/texproc/READ.ME new file mode 100644 index 0000000000..249f231375 --- /dev/null +++ b/support/texproc/READ.ME @@ -0,0 +1,34 @@ +From: dwagon@nella5.cc.monash.edu.au (Dougal Scott) +Newsgroups: comp.graphics.gnuplot,comp.text.tex +Date: 6 Oct 92 05:53:14 GMT +Organization: Monash University, Melb., Australia. +Keywords: gnuplot,tex + +I am converting a set of signal processing notes to AMS-LaTeX, and I needed to +have lots (around 300) different graphs in the document. Rather than have 300 +gnuplot files, and 300 output files hanging around cluttering up my directory, +which would be painful to administer and maintain, I wrote a simple text +filter program which allows you to embed commands in TeX source. + +The program scans stdin for %# at the start of the line, it then saves +everything from that line to the next occurence of %# at the start of a line. +It then executes the program specified in the first line with the saved lines +as data, and puts the result onto stdout. + +I use it just for gnuplot, but it should be able to handle any program that +can output to stdout. + +For example, to include a plot of a sine wave in your LaTeX file. + +\begin{figure}[hbtp] +\begin{center} +%# gnuplot +set terminal eepic +set grid +set nokey +plot sin(x) +%# +\end{center} +\caption{Sine wave} +\end{figure} + diff --git a/support/texproc/texproc.c b/support/texproc/texproc.c new file mode 100644 index 0000000000..aab672b3f3 --- /dev/null +++ b/support/texproc/texproc.c @@ -0,0 +1,101 @@ +/* + * texproc: embedded command preprocessor for TeX and LaTeX + * (c) 1992 Dougal Scott + * Any comments, criticisms, patches to + * Dougal.Scott@FCIT.monash.edu.au + * + * Convert LaTeX: + * .... + * %# gnuplot + * plot sin, cos, and tan + * %# + * .... + * + * to + * + * .... + * \begin{picture} + * \lotsadots + * \end{picture} + * .... + * + * Makefile commands: + * + * CAT=/bin/cat + * PROC=texproc + * + * .SUFFIXES:.zd .tex + * + * .zd.tex: + * $(CAT) $< | $(PROC) > $*.tex + * + */ + +#define TRACE(x) /* x */ + +#include +#include +#include +#include +#include +#include + +extern int errno; +FILE *tmp; + +main(argc,argv) +int argc; +char **argv; +{ +char buff[BUFSIZ]; + +while(gets(buff)!=NULL) { + if(buff[0]=='%' && buff[1]=='#') + process(buff); + else + fprintf(stdout,"%s\n",buff); + } +return(0); +} + +process(buff) +char *buff; +{ +char tmpname[80], /* Name of tmp file */ + progname[80], /* Name of program to execute */ + cmdline[80], /* What to feed to popen */ + outbuff[BUFSIZ]; /* What to take output of prgram from */ +FILE *p; + +strcpy(tmpname,"/tmp/PrcXXXXXX"); +mktemp(tmpname); +if((tmp=fopen(tmpname,"w"))==NULL) { + fprintf(stderr,"Could not open %s for writing\n",tmpname); + fprintf(stderr,"Program aborting\n"); + exit(-1); + } +TRACE(fprintf(stderr,"Saving to tmp file %s\n",tmpname)); +strcpy(progname,&buff[3]); +fprintf(stdout,"%% Including output from %s\n",progname); +/* Put buffer to file for executing */ +while(gets(buff)!=NULL) { + if(buff[0]=='%' && buff[1]=='#') { + fclose(tmp); + sprintf(cmdline,"%s %s",progname,tmpname); + fprintf(stderr,"%s\n",progname); + if((p=popen(cmdline,"r"))==NULL) { + fprintf(stderr,"Could not open pipe to %s\n",cmdline); + exit(-1); + } + while(fgets(outbuff,BUFSIZ,p)!=NULL) + fprintf(stdout,"%s",outbuff); + pclose(p); + unlink(tmpname); + return(0); + } + else { + TRACE(fprintf(stderr,"%s\n",buff)); + fprintf(tmp,"%s\n",buff); + } + } +} -- cgit v1.2.3