/* The actual work is in this recursive procedure */
static tblock *cvt_eqn(const char *inp, const char *stop,
const int mline, const style sty)
{
tblock *res, *r1, *r2;
const char *mid, *end;
res=new(tblock);
while (inp<stop)
{
if (isspace(*inp) && *inp!='\n')
{
inp++;
continue;
}
switch (*inp)
{
case '\0':
return res;
case '\n':
if (mline)
res->add(" \\\\\n");
break;
case '<':
case '>':
case '=':
if (mline)
{
res->add(" & ");
res->add(*inp);
res->add(" & ");
}
else
res->add(*inp);
break;
case '\\':
inp++;
switch(*inp)
{
case '\0':
cerr<<"Bug: cvt_eqn as \\0\n";
return res; // Safety.
case '(': // Guesswork FIXME
res->add(" (");
break;
case ')': // Guesswork FIXME
res->add(" )");
break;
/*
* This section is meant to catch 72 dpi and render it as
* \hbox{72 dpi} but not catch 12 * 18 (which should become
* 12\times 18).
*/
if (isdigit(*inp) || *inp=='-' || *inp=='+')
{
/* Scan forward to see what comes text */
scn=inp;
if (*scn=='-' || *scn=='+')
scn++; // Skip sign
while (scn<stop && isdigit(*scn))
scn++; // Skip number
if (*scn=='.')
{
scn++;
while (scn<stop && isdigit(*scn))
scn++; // Hanlde decimals number
}
/* Now start looking at what comes next */
while (scn<stop)
{
if (isspace(*scn))
{
scn++;
continue;
}
if (isupper(*scn) || islower(*scn))
flg=1;
else
flg=0;
break;
}
}
/*
* This section is meant to catch strings and render them nicely
* in a mbox.
*/
if (islower(*inp) || isupper(*inp) || flg)
{
res->add("\\text{");
if (flg) // If flag set then add everything up to scn
{
while (inp<scn)
{
res->add(*inp);
inp++;
}
}
flg=0; // Re-use flg
while (inp<stop && (islower(*inp) || isupper(*inp)
|| isspace(*inp)
|| *inp=='_'
|| *inp=='^'))
{
if (isspace(*inp))
{
flg=1;
inp++;
continue; // If space, just set the flag
}
if (flg)
res->add(' '); // If skiped a space, add one
flg=0; // Clear flag
if (*inp=='_' || *inp=='^')
res->add('\\');
res->add(*inp);
inp++;
}
res->add("} ");
inp--;
break;
}
res->add(*inp);
break;
}
inp++;
}
return res;
}
/* Equations --- need more examples here */
static void equation(const char *txt, const docfmt *fmt, FILE *out,
void *d)
{
/* Table of contents entries, used as a cue for stuff like sections */
/* This code jus stashes it away for the paragraph code */
static void add_contents(const char *txt, const docfmt *fmt, FILE *out,
void *d)
{
const char *open, *close;
tblock entry;
struct html_data *dp;
fmt=fmt;
out=out;
dp=(struct html_data *) d;
for (open=txt; *open!='"'; open++)
{
if (*open=='\0')
{
cerr<<"Found tc entry but no openning quote\n";
return;
}
}
for (close=open+1; *close!='"'; close++)
{
if (*close=='\0')
{
cerr<<"Found tc entry but no closing quote\n";
return;
}
}
if (close-open==1)
{
cerr<<"Ignoring empty table of contents entry\n";
return;
}
while (++open<close)
entry.add(*open);
if (dp->last_tc!=NULL)
free((void *) dp->last_tc);
dp->last_tc=strdup(entry);