summaryrefslogtreecommitdiff
path: root/support/kamal/DeTeX.c
blob: 804c3172c93c9db323368bd8fa4ab1d42c47dff2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/* COPYRIGHT (C) 1987  Kamal Al-Yahya */
#include   "setups.h"
DeTeX(buffer,out_file)			/* stripping TEX commands */

char *buffer;
FILE *out_file;
{
int c,cc;
char w[MAXWORD];

while ((c = *buffer++) != NULL)
	{
	switch (c)
		{
/* detect TeX commands (backslash) */
		case '\\':
			c=' ' ;		/* "erase" the backslash */
			putc(c,out_file);
			cc = *buffer++;
			if (cc == '\n')			putc(cc,out_file);
			else if (cc == '[')		buffer += display(buffer);
			else if (cc == '(')		buffer += formula(buffer);
			else if (cc == '$' || cc == '%')
				break;
/* check for LaTeX \begin{equation}, \begin{eqnarray}, and \begin{displaymath} */
			else
				{
				buffer--;
				buffer += get_buf_word(buffer,w);
				if (strcmp(w,"begin") == 0)
					{
					buffer++;
					buffer += get_buf_word(buffer,w);
					if (strcmp(w,"equation") == 0 ||
						strcmp(w,"eqnarray") == 0 ||
						strcmp(w,"displaymath") == 0)
						buffer += begin_to_end(buffer,w);
					}
				}
			break;

		case '$':
			buffer += dollar(buffer,out_file);
			break;
		case '%':
			buffer += comment(buffer);
			break;
/* erase these character */
		case '{':
			c=' ';
		case '}':
			c=' ';
		case '_':
			c=' ';
		case '^':
			c=' ';
		case '&':
			c=' ';
		case '#':
			c=' ';
/* default is doing nothing: pass the character to the output */
		default:
			putc(c,out_file);
			break;
		}
	}
}