char *DPS(int f, int t) /* delta ps (t-f) in printable form \s+d or \s-d or \s+-(dd */ { static char buf[100], *lb = buf; char *p; int dn; if (lb > buf + sizeof(buf) - 10) lb = buf; p = lb; *lb++ = '\\'; *lb++ = 's'; dn = EFFPS(t) - EFFPS(f); if (szstack[nszstack] != 0) /* absolute */ dn = EFFPS(t); /* should do proper \s(dd */ else if (dn >= 0) *lb++ = '+'; else { *lb++ = '-'; dn = -dn; } if (dn >= 10) { /* \s+(dd only works in new troff */ *lb++ = '('; *lb++ = dn/10 + '0'; *lb++ = dn%10 + '0'; } else { *lb++ = dn + '0'; } *lb++ = '\0'; return p; }
void sqrt(int p2) { static int af = 0; int nps; /* point size for radical */ double radscale = 0.95; if (ttype == DEVPOST) radscale = 1.05; nps = ps * radscale * eht[p2] / EM(1.0,ps) + 0.99; /* kludgy */ nps = max(EFFPS(nps), ps); yyval = p2; if (ttype == DEVCAT || ttype == DEVAPS) eht[yyval] = EM(1.2, nps); else if (ttype == DEVPOST) eht[yyval] = EM(1.15, nps); else /* DEV202, DEVPOST */ eht[yyval] = EM(1.15, nps); dprintf(".\tS%d <- sqrt S%d;b=%g, h=%g, nps=%d\n", yyval, p2, ebase[yyval], eht[yyval], nps); printf(".as %d \\|\n", yyval); nrwid(p2, ps, p2); if (af++ == 0) printf(".af 10 01\n"); /* make it two digits when it prints */ printf(".nr 10 %.3fu*\\n(.su/10\n", 9.2*eht[p2]); /* this nonsense */ /* guesses point size corresponding to height of stuff */ printf(".ds %d \\v'%gm'\\s(\\n(10", yyval, REL(ebase[p2],ps)); if (ttype == DEVCAT || ttype == DEVAPS) printf("\\v'-.2m'\\(sr\\l'\\n(%du\\(rn'\\v'.2m'", p2); else /* DEV202, DEVPOST so far */ printf("\\(sr\\l'\\n(%du\\(rn'", p2); printf("\\s0\\v'%gm'\\h'-\\n(%du'\\^\\*(%d\n", REL(-ebase[p2],ps), p2, p2); lfont[yyval] = rfont[yyval] = ROM; }
void sqrt(int p2) { #ifndef NEQN float nps; nps = (int)(EFFPS(((eht[p2]*9)/10+(resolution/POINT-1))/(resolution/POINT))); #endif /* NEQN */ yyval.token = p2; #ifndef NEQN eht[yyval.token] = VERT(EM(1.2, nps)); if(dbg)printf(".\tsqrt: S%d <- S%d;b=%g, h=%g\n", yyval.token, p2, ebase[yyval.token], eht[yyval.token]); if (ital(rfont[yyval.token])) printf(".as %d \\|\n", yyval.token); #endif /* NEQN */ nrwid(p2, ps, p2); #ifndef NEQN printf(".ds %d \\v'%gp'\\s%s\\v'-.2m'\\(sr\\l'\\n(%du\\(rn'\\v'.2m'\\s%s", yyval.token, ebase[p2], tsize(nps), p2, tsize(ps)); printf("\\v'%gp'\\h'-\\n(%du'\\*(%d\n", -ebase[p2], p2, p2); lfont[yyval.token] = ROM; #else /* NEQN */ printf(".ds %d \\v'%du'\\e\\L'%du'\\l'\\n(%du'", p2, ebase[p2], -eht[p2], p2); printf("\\v'%du'\\h'-\\n(%du'\\*(%d\n", eht[p2]-ebase[p2], p2, p2); eht[p2] += VERT(1); if(dbg)printf(".\tsqrt: S%d <- S%d;b=%d, h=%d\n", p2, p2, ebase[p2], eht[p2]); #endif /* NEQN */ }
int size(int p1, int p2) { /* old size in p1, new in ps */ int effps, effp1; int yyval; yyval = p2; if(dbg)printf(".\tb:sb: S%d <- \\s%d S%d \\s%d; b=%d, h=%d\n", yyval, ps, p2, p1, ebase[yyval], eht[yyval]); effps = EFFPS(ps); effp1 = EFFPS(p1); printf(".ds %d \\s%d\\*(%d\\s%d\n", yyval, effps, p2, effp1); ps = p1; return yyval; }
double REL(double m, int ps) /* convert m to ems in ps */ { m *= (double) gsize / EFFPS(ps); if (m <= 0.001 && m >= -0.001) return 0; else return m; }
double EM(double m, int ps) /* convert m to ems in gsize */ { m *= (double) EFFPS(ps) / gsize; if (m <= 0.001 && m >= -0.001) return 0; else return m; }
void boverb(int p1, int p2) { int treg; #ifndef NEQN float h, b, d; #else /* NEQN */ int h, b, d; #endif /* NEQN */ treg = oalloc(); yyval.token = p1; #ifndef NEQN d = VERT(EM(0.3, ps)); h = eht[p1] + eht[p2] + d; #else /* NEQN */ d = VERT(1); h = eht[p1] + eht[p2]; #endif /* NEQN */ b = eht[p2] - d; #ifndef NEQN if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%g, h=%g\n", yyval.token, p1, p2, b, h); #else /* NEQN */ if(dbg)printf(".\tb:bob: S%d <- S%d over S%d; b=%d, h=%d\n", yyval.token, p1, p2, b, h); #endif /* NEQN */ nrwid(p1, ps, p1); nrwid(p2, ps, p2); printf(".nr %d \\n(%d\n", treg, p1); printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2); #ifndef NEQN printf(".nr %d \\n(%d+\\s%s.5m\\s0\n", treg, treg, tsize(EFFPS(ps))); printf(".ds %d \\v'%gp'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\\n", yyval.token, eht[p2]-ebase[p2]-d, treg, p2, p2); printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%gp'\\*(%d\\\n", p2, p1, -(eht[p2]-ebase[p2]+d+ebase[p1]), p1); printf("\\h'-\\n(%du-\\n(%du/2u+.1m'\\v'%gp'\\l'\\n(%du-.2m'\\h'.1m'\\v'%gp'\n", treg, p1, ebase[p1]+d, treg, d); #else /* NEQN */ printf(".ds %d \\v'%du'\\h'\\n(%du-\\n(%du/2u'\\*(%d\\\n", yyval.token, eht[p2]-ebase[p2]-d, treg, p2, p2); printf("\\h'-\\n(%du-\\n(%du/2u'\\v'%du'\\*(%d\\\n", p2, p1, -eht[p2]+ebase[p2]-ebase[p1], p1); printf("\\h'-\\n(%du-\\n(%du-2u/2u'\\v'%du'\\l'\\n(%du'\\v'%du'\n", treg, p1, ebase[p1], treg, d); #endif /* NEQN */ ebase[yyval.token] = b; eht[yyval.token] = h; lfont[yyval.token] = rfont[yyval.token] = 0; ofree(p2); ofree(treg); }
void text(int t, char *p1) { int c; char *p; tbl *tp, *lookup(); extern tbl *restbl[]; yyval = oalloc(); ebase[yyval] = 0; #ifndef NEQN eht[yyval] = VERT(EM(1.0, EFFPS(ps))); /* ht in machine units */ #else /* NEQN */ eht[yyval] = VERT(2); /* 2 half-spaces */ #endif /* NEQN */ lfont[yyval] = rfont[yyval] = ROM; if (t == QTEXT) p = p1; else if (t == SPACE) p = "\\ "; else if (t == THIN) p = "\\|"; else if (t == TAB) p = "\\t"; else if ((tp = lookup(restbl, p1, NULL)) != NULL) p = tp->defn; else { lf = rf = 0; for (csp = psp = 0; (c = p1[psp++]) != '\0'; ) { rf = trans(c, p1); if (lf == 0) lf = rf; /* save first */ if (csp > CSSIZE) error(FATAL, gettext( "converted token %.25s... too long"), p1); } cs[csp] = '\0'; p = cs; lfont[yyval] = lf; rfont[yyval] = rf; } if (dbg) printf(".\t%dtext: S%d <- %s; b=%d,h=%d,lf=%c,rf=%c\n", t, yyval, p, ebase[yyval], eht[yyval], lfont[yyval], rfont[yyval]); printf(".ds %d \"%s\n", yyval, p); }
void paren(int leftc, int p1, int rightc) { int n, m, h1, j, b1, v; h1 = eht[p1]; b1 = ebase[p1]; yyval = p1; #ifndef NEQN lfont[yyval] = rfont[yyval] = 0; n = (h1 + EM(1.0, EFFPS(ps)) - 1) / EM(1.0, EFFPS(ps)); #else /* NEQN */ n = max(b1+VERT(1), h1-b1-VERT(1)) / VERT(1); #endif /* NEQN */ if (n < 2) n = 1; m = n-2; if (leftc == '{' || rightc == '}') { if ((n % 2) == 0) { n++; } if (n < 3) n = 3; m = n-3; } #ifndef NEQN eht[yyval] = VERT(EM(n, ps)); ebase[yyval] = b1 + (eht[yyval]-h1)/2; v = b1 - h1/2 + VERT(EM(0.4, ps)); #else /* NEQN */ eht[yyval] = VERT(2 * n); ebase[yyval] = (n)/2 * VERT(2); if (n%2 == 0) ebase[yyval] -= VERT(1); v = b1 - h1/2 + VERT(1); #endif /* NEQN */ printf(".ds %d \\|\\v'%du'", yyval, v); switch (leftc) { case 'n': /* nothing */ case '\0': break; case 'f': /* floor */ if (n <= 1) printf("\\(lf"); else brack(m, "\\(bv", "\\(bv", "\\(lf"); break; case 'c': /* ceiling */ if (n <= 1) printf("\\(lc"); else brack(m, "\\(lc", "\\(bv", "\\(bv"); break; case '{': printf("\\b'\\(lt"); for (j = 0; j < m; j += 2) printf("\\(bv"); printf("\\(lk"); for (j = 0; j < m; j += 2) printf("\\(bv"); printf("\\(lb'"); break; case '(': brack(m, "\\(lt", "\\(bv", "\\(lb"); break; case '[': brack(m, "\\(lc", "\\(bv", "\\(lf"); break; case '|': brack(m, "\\(bv", "\\(bv", "\\(bv"); break; default: brack(m, (char *)&leftc, (char *)&leftc, (char *)&leftc); break; } printf("\\v'%du'\\*(%d", -v, p1); if (rightc) { printf("\\|\\v'%du'", v); switch (rightc) { case 'f': /* floor */ if (n <= 1) printf("\\(rf"); else brack(m, "\\(bv", "\\(bv", "\\(rf"); break; case 'c': /* ceiling */ if (n <= 1) printf("\\(rc"); else brack(m, "\\(rc", "\\(bv", "\\(bv"); break; case '}': printf("\\b'\\(rt"); for (j = 0; j < m; j += 2) printf("\\(bv"); printf("\\(rk"); for (j = 0; j < m; j += 2) printf("\\(bv"); printf("\\(rb'"); break; case ']': brack(m, "\\(rc", "\\(bv", "\\(rf"); break; case ')': brack(m, "\\(rt", "\\(bv", "\\(rb"); break; case '|': brack(m, "\\(bv", "\\(bv", "\\(bv"); break; default: brack(m, (char *)&rightc, (char *)&rightc, (char *)&rightc); break; } printf("\\v'%du'", -v); } printf("\n"); if (dbg) printf(".\tcurly: h=%d b=%d n=%d v=%d l=%c, r=%c\n", eht[yyval], ebase[yyval], n, v, leftc, rightc); }
void nrwid(int n1, float p, int n2) { printf(".nr %d \\w'\\s%s\\*(%d'\n", n1, tsize(EFFPS(p)), n2); }
void setps(float p) { printf(".ps %g\n", EFFPS(p)); }
void bshiftb(int p1, int dir, int p2) { int shval, d1, h1, b1, h2, b2; #ifndef NEQN int diffps, effps, effps2; char *sh1, *sh2; #endif /* NEQN */ yyval = p1; h1 = eht[p1]; b1 = ebase[p1]; h2 = eht[p2]; b2 = ebase[p2]; #ifndef NEQN effps = EFFPS(ps); effps2 = EFFPS(ps+deltaps); diffps = deltaps; sh1 = sh2 = ""; #endif /* NEQN */ if (dir == SUB) { /* subscript */ #ifndef NEQN /* top 1/2m above bottom of main box */ d1 = VERT(EM(0.5, effps2)); #else /* NEQN */ d1 = VERT(1); #endif /* NEQN */ shval = - d1 + h2 - b2; if (d1+b1 > h2) /* move little sub down */ shval = b1-b2; ebase[yyval] = b1 + max(0, h2-b1-d1); eht[yyval] = h1 + max(0, h2-b1-d1); #ifndef NEQN if (rfont[p1] == ITAL && lfont[p2] == ROM) sh1 = "\\|"; if (rfont[p2] == ITAL) sh2 = "\\|"; #endif /* NEQN */ } else { /* superscript */ #ifndef NEQN /* 4/10 up main box */ d1 = VERT(EM(0.2, effps)); #else /* NEQN */ d1 = VERT(1); #endif /* NEQN */ ebase[yyval] = b1; #ifndef NEQN shval = -VERT((4 * (h1-b1)) / 10) - b2; if (VERT(4*(h1-b1)/10) + h2 < h1-b1) /* raise little super */ #else /* NEQN */ shval = -VERT(1) - b2; if (VERT(1) + h2 < h1-b1) /* raise little super */ #endif /* NEQN */ shval = -(h1-b1) + h2-b2 - d1; #ifndef NEQN eht[yyval] = h1 + max(0, h2-VERT((6*(h1-b1))/10)); if (rfont[p1] == ITAL) sh1 = "\\|"; if (rfont[p2] == ITAL) sh2 = "\\|"; #else /* NEQN */ eht[yyval] = h1 + max(0, h2 - VERT(1)); #endif /* NEQN */ } if (dbg) printf(".\tb:b shift b: S%d <- S%d vert %d S%d vert %d; " "b=%d, h=%d\n", yyval, p1, shval, p2, -shval, ebase[yyval], eht[yyval]); #ifndef NEQN printf(".as %d \\v'%du'\\s-%d%s\\*(%d\\s+%d%s\\v'%du'\n", yyval, shval, diffps, sh1, p2, diffps, sh2, -shval); ps += deltaps; if (rfont[p2] == ITAL) rfont[p1] = 0; else rfont[p1] = rfont[p2]; #else /* NEQN */ printf(".as %d \\v'%du'\\*(%d\\v'%du'\n", yyval, shval, p2, -shval); #endif /* NEQN */ ofree(p2); }
void shift2(int p1, int p2, int p3) { int effps, h1, h2, h3, b1, b2, b3, subsh, d1, d2, supsh, treg; #ifndef NEQN int effps2; #endif /* NEQN */ treg = oalloc(); yyval = p1; if (dbg) printf(".\tshift2 s%d <- %d %d %d\n", yyval, p1, p2, p3); effps = EFFPS(ps+deltaps); #ifndef NEQN eht[p3] = h3 = VERT((eht[p3] * effps) / EFFPS(ps)); ps += deltaps; effps2 = EFFPS(ps+deltaps); #endif /* NEQN */ h1 = eht[p1]; b1 = ebase[p1]; h2 = eht[p2]; b2 = ebase[p2]; #ifndef NEQN b3 = ebase[p3]; d1 = VERT(EM(0.5, effps2)); #else /* NEQN */ h3 = eht[p3]; b3 = ebase[p3]; d1 = VERT(1); #endif /* NEQN */ subsh = -d1+h2-b2; if (d1+b1 > h2) /* move little sub down */ subsh = b1-b2; #ifndef NEQN supsh = -VERT((4*(h1-b1))/10) - b3; d2 = VERT(EM(0.2, effps)); if (VERT(4*(h1-b1)/10)+h3 < h1-b1) #else /* NEQN */ supsh = - VERT(1) - b3; d2 = VERT(1); if (VERT(1)+h3 < h1-b1) #endif /* NEQN */ supsh = -(h1-b1) + (h3-b3) - d2; #ifndef NEQN eht[yyval] = h1 + max(0, h3-VERT((6*(h1-b1))/10)) + max(0, h2-b1-d1); #else /* NEQN */ eht[yyval] = h1 + max(0, h3-VERT(1)) + max(0, h2-b1-d1); #endif /* NEQN */ ebase[yyval] = b1+max(0, h2-b1-d1); #ifndef NEQN if (rfont[p1] == ITAL && lfont[p2] == ROM) printf(".ds %d \\|\\*(%d\n", p2, p2); if (rfont[p2] == ITAL) printf(".as %d \\|\n", p2); #endif /* NEQN */ nrwid(p2, effps, p2); #ifndef NEQN if (rfont[p1] == ITAL && lfont[p3] == ROM) printf(".ds %d \\|\\|\\*(%d\n", p3, p3); else printf(".ds %d \\|\\*(%d\n", p3, p3); #endif /* NEQN */ nrwid(p3, effps, p3); printf(".nr %d \\n(%d\n", treg, p3); printf(".if \\n(%d>\\n(%d .nr %d \\n(%d\n", p2, treg, treg, p2); #ifndef NEQN printf(".as %d \\v'%du'\\s%d\\*(%d\\h'-\\n(%du'\\v'%du'\\\n", p1, subsh, effps, p2, p2, -subsh+supsh); printf("\\s%d\\*(%d\\h'-\\n(%du+\\n(%du'\\s%d\\v'%du'\n", effps, p3, p3, treg, effps2, -supsh); #else /* NEQN */ printf(".as %d \\v'%du'\\*(%d\\h'-\\n(%du'\\v'%du'\\\n", p1, subsh, p2, p2, -subsh+supsh); printf("\\*(%d\\h'-\\n(%du+\\n(%du'\\v'%du'\n", p3, p3, treg, -supsh); #endif /* NEQN */ ps += deltaps; #ifndef NEQN if (rfont[p2] == ITAL) rfont[yyval] = 0; /* lie */ #endif /* NEQN */ ofree(p2); ofree(p3); ofree(treg); }