summaryrefslogtreecommitdiff
path: root/support/kamal/Eqn.c
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
committerNorbert Preining <norbert@preining.info>2019-09-02 13:46:59 +0900
commite0c6872cf40896c7be36b11dcc744620f10adf1d (patch)
tree60335e10d2f4354b0674ec22d7b53f0f8abee672 /support/kamal/Eqn.c
Initial commit
Diffstat (limited to 'support/kamal/Eqn.c')
-rw-r--r--support/kamal/Eqn.c113
1 files changed, 113 insertions, 0 deletions
diff --git a/support/kamal/Eqn.c b/support/kamal/Eqn.c
new file mode 100644
index 0000000000..9809c91808
--- /dev/null
+++ b/support/kamal/Eqn.c
@@ -0,0 +1,113 @@
+/* COPYRIGHT (C) 1987 Kamal Al-Yahya */
+#include "setups.h"
+Eqn(buffer,out_file) /* srips TEX equations */
+
+FILE *out_file;
+char *buffer;
+{
+int c,d;
+int i;
+char w[MAXLINE], ww[MAXWORD];
+while ((c = *buffer++) != NULL)
+ {
+ if(c == '%')
+ {
+ while ((c = *buffer++) != NULL)
+ if (c == '\n') break;
+ }
+ else if(c == '$')
+ {
+ if ((d = *buffer++) == '$')
+ {
+ putc(c,out_file); putc(d,out_file);
+ while ((c = *buffer++) != NULL)
+ {
+ if(c != '$') putc(c,out_file);
+ else
+ {
+ buffer++;
+ fprintf(out_file,"$$ \n");
+ break;
+ }
+ }
+ }
+ }
+/* check for LaTeX \begin{equation}, \begin{eqnarray}, and \begin{displaymath} */
+ else if(c == '\\')
+ {
+ c = *buffer++;
+ if (c == '[')
+ {
+ putc('\\',out_file); putc(c,out_file);
+ while((c = *buffer++) != NULL)
+ {
+ if(c == '\\')
+ {
+ c = *buffer++;
+ fprintf(out_file,"\\%c",c);
+ if (c == ']')
+ {
+ putc('\n',out_file);
+ break;
+ }
+ }
+ else
+ putc(c,out_file);
+ }
+ continue;
+ }
+ buffer--;
+ buffer += get_buf_word(buffer,w);
+ if (strcmp(w,"begin") == 0)
+ {
+ buffer++;
+ i = get_buf_word(buffer,w);
+ buffer += i;
+ if (strcmp(w,"equation") == 0 || strcmp(w,"eqnarray")
+ == 0 || strcmp(w,"displaymath") == 0)
+ {
+ fprintf(out_file,"\\begin{%s}",w);
+ buffer++;
+ while ((c = *buffer++) != NULL)
+ {
+ putc(c,out_file);
+ if (c == '\\')
+ {
+ i = get_buf_word(buffer,ww);
+ buffer += i;
+ fprintf(out_file,"%s",ww);
+ if (strcmp(ww,"end") == 0)
+ {
+ buffer++;
+ i = get_buf_word(buffer,ww);
+ buffer += i;
+ fprintf(out_file,
+ "{%s}\n",ww);
+ buffer++;
+ if (strcmp(ww,"equation")
+ == 0 ||
+ strcmp(ww,"eqnarray")
+ == 0 ||
+ strcmp(ww,"displaymath")
+ == 0)
+ break;
+ }
+ }
+ }
+ }
+ }
+ else if (strcmp(w,"def") == 0)
+ {
+ i = def(buffer,w);
+ buffer += i;
+ fprintf(out_file,"\\def%s\n",w);
+ }
+ else if (strcmp(w,"newcommand") == 0)
+ {
+ i = command(buffer,w);
+ buffer += i;
+ fprintf(out_file,"\\newcommand%s\n",w);
+ }
+ }
+ }
+}