From: Ingo Schwarze <schwarze@usta.de>
To: "Anthony J. Bentley" <anthony@anjbe.name>
Cc: tech@mandoc.bsd.lv
Subject: Re: eqn(7): Precedence of from/to/sub/sup
Date: Thu, 6 Jul 2017 02:26:41 +0200 [thread overview]
Message-ID: <20170706002640.GG88736@athene.usta.de> (raw)
In-Reply-To: <14094.1499140567@cathet.us>
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
prev parent reply other threads:[~2017-07-06 0:26 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-07-04 3:56 Anthony J. Bentley
2017-07-06 0:26 ` Ingo Schwarze [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170706002640.GG88736@athene.usta.de \
--to=schwarze@usta.de \
--cc=anthony@anjbe.name \
--cc=tech@mandoc.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).