summaryrefslogtreecommitdiff
path: root/support/kamal/Eqn.c
blob: 9809c918083d0e21a07925ce871ee84e958a4910 (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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);
			}
		}
	}
}