home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / textools2 / part01 / Eqn.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-02-12  |  2.1 KB  |  114 lines

  1. /* COPYRIGHT (C) 1987  Kamal Al-Yahya */
  2. #include    "setups.h"
  3. Eqn(buffer,out_file)            /* srips TEX equations */
  4.  
  5. FILE *out_file;
  6. char *buffer;
  7. {
  8. int c,d;
  9. int i;
  10. char w[MAXLINE], ww[MAXWORD];
  11. while ((c = *buffer++) != NULL)
  12.     {
  13.     if(c == '%')
  14.         {
  15.         while ((c = *buffer++) != NULL)
  16.             if (c == '\n') break;
  17.         }
  18.     else if(c == '$')
  19.         {
  20.         if ((d = *buffer++) == '$')
  21.             {
  22.             putc(c,out_file);    putc(d,out_file);
  23.             while ((c = *buffer++) != NULL)
  24.                 {
  25.                 if(c != '$')   putc(c,out_file);
  26.                 else
  27.                     {
  28.                     buffer++;
  29.                     fprintf(out_file,"$$ \n");
  30.                     break;
  31.                     }
  32.                 }
  33.             }
  34.         }
  35. /* check for LaTeX \begin{equation}, \begin{eqnarray}, and \begin{displaymath} */
  36.     else if(c == '\\')
  37.         {
  38.         c = *buffer++;
  39.         if (c == '[')
  40.             {
  41.             putc('\\',out_file); putc(c,out_file);
  42.             while((c = *buffer++) != NULL)
  43.                 {
  44.                 if(c == '\\')
  45.                     {
  46.                     c = *buffer++;
  47.                     fprintf(out_file,"\\%c",c);
  48.                     if (c == ']')
  49.                         {
  50.                         putc('\n',out_file);
  51.                         break;
  52.                         }
  53.                     }
  54.                 else
  55.                     putc(c,out_file);
  56.                 }
  57.             continue;
  58.             }
  59.         buffer--;
  60.         buffer += get_buf_word(buffer,w);
  61.         if (strcmp(w,"begin") == 0)
  62.             {
  63.             buffer++;
  64.             i = get_buf_word(buffer,w);
  65.             buffer += i;
  66.             if (strcmp(w,"equation") == 0 || strcmp(w,"eqnarray")
  67.                 == 0 || strcmp(w,"displaymath") == 0)
  68.                 {
  69.                 fprintf(out_file,"\\begin{%s}",w);
  70.                 buffer++;
  71.                 while ((c = *buffer++) != NULL)
  72.                     {
  73.                     putc(c,out_file);
  74.                     if (c == '\\')
  75.                         {
  76.                         i = get_buf_word(buffer,ww);
  77.                         buffer += i;
  78.                         fprintf(out_file,"%s",ww);
  79.                         if (strcmp(ww,"end") == 0)
  80.                             {
  81.                             buffer++;
  82.                             i = get_buf_word(buffer,ww);
  83.                             buffer += i;
  84.                             fprintf(out_file,
  85.                                 "{%s}\n",ww);
  86.                             buffer++;
  87.                             if (strcmp(ww,"equation")
  88.                                 == 0 ||
  89.                                 strcmp(ww,"eqnarray")
  90.                                 == 0 ||
  91.                                 strcmp(ww,"displaymath")
  92.                                 == 0)
  93.                                 break;
  94.                             }
  95.                         }
  96.                     }
  97.                 }
  98.             }
  99.         else if (strcmp(w,"def") == 0)
  100.             {
  101.             i = def(buffer,w);
  102.             buffer += i;
  103.             fprintf(out_file,"\\def%s\n",w);
  104.             }
  105.         else if (strcmp(w,"newcommand") == 0)
  106.             {
  107.             i = command(buffer,w);
  108.             buffer += i;
  109.             fprintf(out_file,"\\newcommand%s\n",w);
  110.             }
  111.         }
  112.     }
  113. }
  114.