tech@mandoc.bsd.lv
 help / color / mirror / Atom feed
* eqn(7): Precedence of from/to/sub/sup
@ 2017-07-04  3:56 Anthony J. Bentley
  2017-07-06  0:26 ` Ingo Schwarze
  0 siblings, 1 reply; 2+ messages in thread
From: Anthony J. Bentley @ 2017-07-04  3:56 UTC (permalink / raw)
  To: tech

Hi,

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

Now consider this example:

.EQ
int from a sub 1 to b sup 2 dx
.EN

groff treats this correctly, as "int from {a sub 1} to {b sup 2} dx".
mandoc instead treats it as "int from {a sub {1 to {b sup 2}}} dx".

-- 
Anthony J. Bentley
--
 To unsubscribe send an email to tech+unsubscribe@mandoc.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: eqn(7): Precedence of from/to/sub/sup
  2017-07-04  3:56 eqn(7): Precedence of from/to/sub/sup Anthony J. Bentley
@ 2017-07-06  0:26 ` Ingo Schwarze
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Schwarze @ 2017-07-06  0:26 UTC (permalink / raw)
  To: Anthony J. Bentley; +Cc: tech

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-06  0:26 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-04  3:56 eqn(7): Precedence of from/to/sub/sup Anthony J. Bentley
2017-07-06  0:26 ` Ingo Schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).