From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from scc-mailout-kit-01.scc.kit.edu (scc-mailout-kit-01.scc.kit.edu [129.13.231.81]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTP id a20e7999 for ; Wed, 5 Jul 2017 19:26:44 -0500 (EST) Received: from asta-nat.asta.uni-karlsruhe.de ([172.22.63.82] helo=hekate.usta.de) by scc-mailout-kit-01.scc.kit.edu with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (envelope-from ) id 1dSud0-0007ou-0p; Thu, 06 Jul 2017 02:26:43 +0200 Received: from donnerwolke.usta.de ([172.24.96.3]) by hekate.usta.de with esmtp (Exim 4.77) (envelope-from ) id 1dSucz-00033y-Hx; Thu, 06 Jul 2017 02:26:41 +0200 Received: from athene.usta.de ([172.24.96.10]) by donnerwolke.usta.de with esmtp (Exim 4.84_2) (envelope-from ) id 1dSucz-0007w5-1Y; Thu, 06 Jul 2017 02:26:41 +0200 Received: from localhost (athene.usta.de [local]) by athene.usta.de (OpenSMTPD) with ESMTPA id 7fc3363d; Thu, 6 Jul 2017 02:26:41 +0200 (CEST) Date: Thu, 6 Jul 2017 02:26:41 +0200 From: Ingo Schwarze To: "Anthony J. Bentley" Cc: tech@mandoc.bsd.lv Subject: Re: eqn(7): Precedence of from/to/sub/sup Message-ID: <20170706002640.GG88736@athene.usta.de> References: <14094.1499140567@cathet.us> X-Mailinglist: mandoc-tech Reply-To: tech@mandoc.bsd.lv MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <14094.1499140567@cathet.us> User-Agent: Mutt/1.6.2 (2016-07-01) Hi Anthony, Anthony J. Bentley wrote on Mon, Jul 03, 2017 at 09:56:07PM -0600: > Kernighan & Cherry's "Typesetting Mathematics: User's Guide" (2e) says: > > If you don't use braces, eqn(1) will do operations in the order > shown in this list. > > dyad vec under bar tilde hat dot dotdot > fwd back down up > fat roman italic bold size > sub sup sqrt over > from to Good point, fixed by the commit below. If you still see errors, don't hesitate to tell me. Thanks, Ingo Log Message: ----------- Fix operator precedence according to Brian W. Kernighan and Lorinda L. Cherry, "Typesetting Mathematics - User's Guide (Second Edition)", August 15, 1978, paragraph 23; swarm of bugs pointed out by bentley@. Modified Files: -------------- mandoc: eqn.c eqn_term.c mandoc/regress/eqn/fromto: Makefile mandoc/regress/eqn/over: precedence.in precedence.out_ascii precedence.out_html mandoc/regress/eqn/subsup: Makefile mandoc/regress/eqn/unary: bold.in bold.out_ascii bold.out_html diacrit.in diacrit.out_ascii diacrit.out_html sqrt.in sqrt.out_ascii sqrt.out_html Added Files: ----------- mandoc/regress/eqn/fromto: precedence.in precedence.out_ascii precedence.out_html mandoc/regress/eqn/subsup: precedence.in precedence.out_ascii precedence.out_html Revision Data ------------- Index: eqn_term.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/eqn_term.c,v retrieving revision 1.10 retrieving revision 1.11 diff -Leqn_term.c -Leqn_term.c -u -p -r1.10 -r1.11 --- eqn_term.c +++ eqn_term.c @@ -113,15 +113,6 @@ eqn_box(struct termp *p, const struct eq if (bp->font != EQNFONT_NONE) term_fontpop(p); - if ((bp->type == EQN_LIST && bp->expectargs > 1) || - (bp->type == EQN_PILE && (bp->prev || bp->next)) || - (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) { - p->flags |= TERMP_NOSPACE; - term_word(p, bp->right != NULL ? bp->right : ")"); - if (bp->parent->type == EQN_SUBEXPR && bp->next != NULL) - p->flags |= TERMP_NOSPACE; - } - if (bp->top != NULL) { p->flags |= TERMP_NOSPACE; term_word(p, bp->top); @@ -129,5 +120,13 @@ eqn_box(struct termp *p, const struct eq if (bp->bottom != NULL) { p->flags |= TERMP_NOSPACE; term_word(p, "_"); + } + if ((bp->type == EQN_LIST && bp->expectargs > 1) || + (bp->type == EQN_PILE && (bp->prev || bp->next)) || + (bp->parent != NULL && bp->parent->pos == EQNPOS_SQRT)) { + p->flags |= TERMP_NOSPACE; + term_word(p, bp->right != NULL ? bp->right : ")"); + if (bp->parent->type == EQN_SUBEXPR && bp->next != NULL) + p->flags |= TERMP_NOSPACE; } } Index: eqn.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/eqn.c,v retrieving revision 1.73 retrieving revision 1.74 diff -Leqn.c -Leqn.c -u -p -r1.73 -r1.74 --- eqn.c +++ eqn.c @@ -819,6 +819,8 @@ next_tok: ep->gsize = size; break; } + while (parent->args == parent->expectargs) + parent = parent->parent; parent = eqn_box_alloc(ep, parent); parent->type = EQN_LIST; parent->expectargs = 1; @@ -840,13 +842,25 @@ next_tok: cur->type = EQN_TEXT; cur->text = mandoc_strdup(""); } - /* Handle the "subsup" and "fromto" positions. */ - if (EQN_TOK_SUP == tok && parent->pos == EQNPOS_SUB) { + while (parent->expectargs == 1 && parent->args == 1) + parent = parent->parent; + if (tok == EQN_TOK_FROM || tok == EQN_TOK_TO) { + for (cur = parent; cur != NULL; cur = cur->parent) + if (cur->pos == EQNPOS_SUB || + cur->pos == EQNPOS_SUP || + cur->pos == EQNPOS_SUBSUP || + cur->pos == EQNPOS_SQRT || + cur->pos == EQNPOS_OVER) + break; + if (cur != NULL) + parent = cur->parent; + } + if (tok == EQN_TOK_SUP && parent->pos == EQNPOS_SUB) { parent->expectargs = 3; parent->pos = EQNPOS_SUBSUP; break; } - if (EQN_TOK_TO == tok && parent->pos == EQNPOS_FROM) { + if (tok == EQN_TOK_TO && parent->pos == EQNPOS_FROM) { parent->expectargs = 3; parent->pos = EQNPOS_FROMTO; break; @@ -895,6 +909,8 @@ next_tok: cur->type = EQN_TEXT; cur->text = mandoc_strdup(""); } + while (parent->args == parent->expectargs) + parent = parent->parent; while (EQN_SUBEXPR == parent->type) parent = parent->parent; parent = eqn_box_makebinary(ep, EQNPOS_OVER, parent); @@ -1099,13 +1115,6 @@ next_tok: parent = split->parent; break; } - /* - * Post-process list status. - */ - while (parent->type == EQN_LIST && - parent->expectargs == 1 && - parent->args == 1) - parent = parent->parent; break; default: abort(); -- To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv