=================================================================== RCS file: /cvs/mandoc/eqn.c,v retrieving revision 1.44 retrieving revision 1.46 diff -u -p -r1.44 -r1.46 --- mandoc/eqn.c 2014/07/06 19:09:00 1.44 +++ mandoc/eqn.c 2014/09/28 11:32:08 1.46 @@ -1,4 +1,4 @@ -/* $Id: eqn.c,v 1.44 2014/07/06 19:09:00 schwarze Exp $ */ +/* $Id: eqn.c,v 1.46 2014/09/28 11:32:08 kristaps Exp $ */ /* * Copyright (c) 2011 Kristaps Dzonsons * @@ -14,10 +14,10 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#ifdef HAVE_CONFIG_H #include "config.h" -#endif +#include + #include #include #include @@ -198,6 +198,7 @@ static const struct eqnstr eqnposs[EQNPOS__MAX] = { { "", 0 }, /* EQNPOS_NONE */ { "over", 4 }, /* EQNPOS_OVER */ { "sup", 3 }, /* EQNPOS_SUP */ + { NULL, 0 }, /* EQNPOS_SUPSUB */ { "sub", 3 }, /* EQNPOS_SUB */ { "to", 2 }, /* EQNPOS_TO */ { "from", 4 }, /* EQNPOS_FROM */ @@ -569,14 +570,30 @@ eqn_box(struct eqn_node *ep, struct eqn_box *last) return(EQN_OK); } + /* + * Positional elements (e.g., over, sub, sup, ...). + */ for (i = 0; i < (int)EQNPOS__MAX; i++) { - if ( ! EQNSTREQ(&eqnposs[i], start, sz)) + /* Some elements don't have names (are virtual). */ + if (NULL == eqnposs[i].name) continue; + else if ( ! EQNSTREQ(&eqnposs[i], start, sz)) + continue; if (NULL == last->last) { EQN_MSG(MANDOCERR_EQNSYNT, ep); return(EQN_ERR); } - last->last->pos = (enum eqn_post)i; + /* + * If we encounter x sub y sup z, then according to the + * eqn manual, we regard this as x subsup y z. + */ + if (EQNPOS_SUP == i && + NULL != last->last->prev && + EQNPOS_SUB == last->last->prev->pos) + last->last->prev->pos = EQNPOS_SUBSUP; + else + last->last->pos = (enum eqn_post)i; + if (EQN_EOF == (c = eqn_box(ep, last))) { EQN_MSG(MANDOCERR_EQNEOF, ep); return(EQN_ERR); @@ -665,10 +682,11 @@ eqn_box_alloc(struct eqn_node *ep, struct eqn_box *par bp->parent = parent; bp->size = ep->gsize; - if (NULL == parent->first) - parent->first = bp; - else + if (NULL != parent->first) { parent->last->next = bp; + bp->prev = parent->last; + } else + parent->first = bp; parent->last = bp; return(bp);