tech@mandoc.bsd.lv
 help / color / Atom feed
* eqn(7) doesn't distinguish mathematical words
@ 2017-06-20  4:36 Anthony J. Bentley
  2017-06-20  5:53 ` Anthony J. Bentley
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Anthony J. Bentley @ 2017-06-20  4:36 UTC (permalink / raw)
  To: tech

Hi,

From the Plan 9 eqn(1) manual:
"Mathematical words like sin, cos, log are made Roman automatically."

The exception proves the rule, which is that eqn(1) italicizes words
in general.

.EQ
a ab sin
.EN

In groff and Heirloom, the above results in italic a and ab, and
roman sin. In mandoc -Tpdf, it instead results in italic a, and roman
ab and sin.

Here's the list of mathematical words in Plan 9 eqn(1) and groff eqn(1):
and
for
if
Re
Im
sin
cos
tan
arc
sinh
coth
tanh
cosh
lim
log
ln
max
min
exp
det

Heirloom adds:
sec
csc
asin
acos
atan
asec
acsc

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

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

* Re: eqn(7) doesn't distinguish mathematical words
  2017-06-20  4:36 eqn(7) doesn't distinguish mathematical words Anthony J. Bentley
@ 2017-06-20  5:53 ` Anthony J. Bentley
  2017-06-21 18:09 ` Ingo Schwarze
  2017-06-22  0:37 ` Ingo Schwarze
  2 siblings, 0 replies; 4+ messages in thread
From: Anthony J. Bentley @ 2017-06-20  5:53 UTC (permalink / raw)
  Cc: tech

Anthony J. Bentley writes:
> In mandoc -Tpdf,

I mean mandoc -Thtml, of course...
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

* Re: eqn(7) doesn't distinguish mathematical words
  2017-06-20  4:36 eqn(7) doesn't distinguish mathematical words Anthony J. Bentley
  2017-06-20  5:53 ` Anthony J. Bentley
@ 2017-06-21 18:09 ` Ingo Schwarze
  2017-06-22  0:37 ` Ingo Schwarze
  2 siblings, 0 replies; 4+ messages in thread
From: Ingo Schwarze @ 2017-06-21 18:09 UTC (permalink / raw)
  To: Anthony J. Bentley; +Cc: tech

Hi Anthony,

Anthony J. Bentley wrote on Mon, Jun 19, 2017 at 10:36:43PM -0600:

> From the Plan 9 eqn(1) manual:
> "Mathematical words like sin, cos, log are made Roman automatically."

Implemented with the commit appended below.

> The exception proves the rule, which is that eqn(1) italicizes words
> in general.

That part is still open.

Thanks for the report,
  Ingo


Log Message:
-----------
Recognize well-known functions names (the same that Heirloom recognizes,
which includes those recognized by groff) and wrap them in a roman box 
unless they already are in roman context.
Missing feature reported by bentley@.

Modified Files:
--------------
    mdocml:
        eqn.c

Revision Data
-------------
Index: eqn.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/eqn.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -Leqn.c -Leqn.c -u -p -r1.63 -r1.64
--- eqn.c
+++ eqn.c
@@ -1,7 +1,7 @@
 /*	$Id$ */
 /*
  * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -80,9 +80,10 @@ enum	eqn_tok {
 	EQN_TOK_TDEFINE,
 	EQN_TOK_NDEFINE,
 	EQN_TOK_UNDEF,
-	EQN_TOK_EOF,
 	EQN_TOK_ABOVE,
-	EQN_TOK__MAX
+	EQN_TOK__MAX,
+	EQN_TOK_FUNC,
+	EQN_TOK_EOF
 };
 
 static	const char *eqn_toks[EQN_TOK__MAX] = {
@@ -130,10 +131,16 @@ static	const char *eqn_toks[EQN_TOK__MAX
 	"tdefine", /* EQN_TOK_TDEFINE */
 	"ndefine", /* EQN_TOK_NDEFINE */
 	"undef", /* EQN_TOK_UNDEF */
-	NULL, /* EQN_TOK_EOF */
 	"above", /* EQN_TOK_ABOVE */
 };
 
+static	const char *const eqn_func[] = {
+	"acos",	"acsc",	"and",	"arc",	"asec",	"asin", "atan",
+	"cos",	"cosh", "coth",	"csc",	"det",	"exp",	"for",
+	"if",	"lim",	"ln",	"log",	"max",	"min",
+	"sec",	"sin",	"sinh",	"tan",	"tanh",	"Im",	"Re",
+};
+
 enum	eqn_symt {
 	EQNSYM_alpha,
 	EQNSYM_beta,
@@ -498,12 +505,12 @@ eqn_tok_parse(struct eqn_node *ep, char 
 	size_t		 i, sz;
 	int		 quoted;
 
-	if (NULL != p)
+	if (p != NULL)
 		*p = NULL;
 
 	quoted = ep->data[ep->cur] == '"';
 
-	if (NULL == (start = eqn_nexttok(ep, &sz)))
+	if ((start = eqn_nexttok(ep, &sz)) == NULL)
 		return EQN_TOK_EOF;
 
 	if (quoted) {
@@ -512,17 +519,18 @@ eqn_tok_parse(struct eqn_node *ep, char 
 		return EQN_TOK__MAX;
 	}
 
-	for (i = 0; i < EQN_TOK__MAX; i++) {
-		if (NULL == eqn_toks[i])
-			continue;
+	for (i = 0; i < EQN_TOK__MAX; i++)
 		if (STRNEQ(start, sz, eqn_toks[i], strlen(eqn_toks[i])))
-			break;
-	}
+			return i;
 
-	if (i == EQN_TOK__MAX && NULL != p)
+	if (p != NULL)
 		*p = mandoc_strndup(start, sz);
 
-	return i;
+	for (i = 0; i < sizeof(eqn_func)/sizeof(*eqn_func); i++)
+		if (STRNEQ(start, sz, eqn_func[i], strlen(eqn_func[i])))
+			return EQN_TOK_FUNC;
+
+	return EQN_TOK__MAX;
 }
 
 static void
@@ -1067,15 +1075,26 @@ this_tok:
 		 * TODO: make sure we're not in an open subexpression.
 		 */
 		return ROFF_EQN;
-	default:
-		assert(tok == EQN_TOK__MAX);
-		assert(NULL != p);
+	case EQN_TOK_FUNC:
+	case EQN_TOK__MAX:
+		assert(p != NULL);
 		/*
 		 * If we already have something in the stack and we're
 		 * in an expression, then rewind til we're not any more.
 		 */
 		while (parent->args == parent->expectargs)
 			parent = parent->parent;
+		if (tok == EQN_TOK_FUNC) {
+			for (cur = parent; cur != NULL; cur = cur->parent)
+				if (cur->font != EQNFONT_NONE)
+					break;
+			if (cur == NULL || cur->font != EQNFONT_ROMAN) {
+				parent = eqn_box_alloc(ep, parent);
+				parent->type = EQN_LISTONE;
+				parent->font = EQNFONT_ROMAN;
+				parent->expectargs = 1;
+			}
+		}
 		cur = eqn_box_alloc(ep, parent);
 		cur->type = EQN_TEXT;
 		for (i = 0; i < EQNSYM__MAX; i++)
@@ -1096,6 +1115,8 @@ this_tok:
 		    parent->args == parent->expectargs)
 			parent = parent->parent;
 		break;
+	default:
+		abort();
 	}
 	goto next_tok;
 }
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

* Re: eqn(7) doesn't distinguish mathematical words
  2017-06-20  4:36 eqn(7) doesn't distinguish mathematical words Anthony J. Bentley
  2017-06-20  5:53 ` Anthony J. Bentley
  2017-06-21 18:09 ` Ingo Schwarze
@ 2017-06-22  0:37 ` Ingo Schwarze
  2 siblings, 0 replies; 4+ messages in thread
From: Ingo Schwarze @ 2017-06-22  0:37 UTC (permalink / raw)
  To: Anthony J. Bentley; +Cc: tech

Hi Anthony,

Anthony J. Bentley wrote on Mon, Jun 19, 2017 at 10:36:43PM -0600:

> From the Plan 9 eqn(1) manual:
> "Mathematical words like sin, cos, log are made Roman automatically."

That was already addressed earlier.

> The exception proves the rule, which is that eqn(1) italicizes words
> in general.
> 
> .EQ
> a ab sin
> .EN
> 
> In groff and Heirloom, the above results in italic a and ab, and
> roman sin.

Fixed for the terminal formatter by the commit appended below.

> In mandoc -Thtml, it instead results in italic a, and roman
> ab and sin.

Improving HTML output is still an open task.

Yours,
  Ingo


Log Message:
-----------
Fix font selection for text boxes in the terminal formatter.
Issue reported by bentley@.

The AST data structure is powerful enough that all required 
information can easily be provided in the parser, and no change
of the formatting code is needed.

Modified Files:
--------------
    mdocml:
        eqn.c

Revision Data
-------------
Index: eqn.c
===================================================================
RCS file: /home/cvs/mdocml/mdocml/eqn.c,v
retrieving revision 1.66
retrieving revision 1.67
diff -Leqn.c -Leqn.c -u -p -r1.66 -r1.67
--- eqn.c
+++ eqn.c
@@ -84,6 +84,8 @@ enum	eqn_tok {
 	EQN_TOK_ABOVE,
 	EQN_TOK__MAX,
 	EQN_TOK_FUNC,
+	EQN_TOK_QUOTED,
+	EQN_TOK_SYM,
 	EQN_TOK_EOF
 };
 
@@ -517,7 +519,7 @@ eqn_tok_parse(struct eqn_node *ep, char 
 	if (quoted) {
 		if (p != NULL)
 			*p = mandoc_strndup(start, sz);
-		return EQN_TOK__MAX;
+		return EQN_TOK_QUOTED;
 	}
 
 	for (i = 0; i < EQN_TOK__MAX; i++)
@@ -528,7 +530,7 @@ eqn_tok_parse(struct eqn_node *ep, char 
 		if (STRNEQ(start, sz,
 		    eqnsyms[i].str, strlen(eqnsyms[i].str))) {
 			mandoc_asprintf(p, "\\[%s]", eqnsyms[i].sym);
-			return EQN_TOK__MAX;
+			return EQN_TOK_SYM;
 		}
 	}
 
@@ -1084,8 +1086,10 @@ this_tok:
 		 * TODO: make sure we're not in an open subexpression.
 		 */
 		return ROFF_EQN;
-	case EQN_TOK_FUNC:
 	case EQN_TOK__MAX:
+	case EQN_TOK_FUNC:
+	case EQN_TOK_QUOTED:
+	case EQN_TOK_SYM:
 		assert(p != NULL);
 		/*
 		 * If we already have something in the stack and we're
@@ -1112,17 +1116,27 @@ this_tok:
 		cur->text = p;
 		/*
 		 * If not inside any explicit font context,
-		 * give every letter its own box.
+		 * quoted strings become italic, and every letter
+		 * of a bare string gets its own italic box.
 		 */
-		if (fontp == NULL && *p != '\0') {
+		do {
+			if (fontp != NULL || *p == '\0' ||
+			    tok == EQN_TOK_SYM)
+				break;
+			if (tok == EQN_TOK_QUOTED) {
+				cur->font = EQNFONT_ITALIC;
+				break;
+			}
 			cp = p;
 			for (;;) {
+				if (isalpha((unsigned char)*cp))
+					cur->font = EQNFONT_ITALIC;
 				cpn = cp + 1;
 				if (*cp == '\\')
 					mandoc_escape(&cpn, NULL, NULL);
 				if (*cpn == '\0')
 					break;
-				if (isalpha((unsigned char)*cp) == 0 &&
+				if (cur->font != EQNFONT_ITALIC &&
 				    isalpha((unsigned char)*cpn) == 0) {
 					cp = cpn;
 					continue;
@@ -1137,7 +1151,7 @@ this_tok:
 				cur = nbox;
 				cp = nbox->text;
 			}
-		}
+		} while (0);
 		/*
 		 * Post-process list status.
 		 */
--
 To unsubscribe send an email to tech+unsubscribe@mdocml.bsd.lv

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

end of thread, back to index

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-06-20  4:36 eqn(7) doesn't distinguish mathematical words Anthony J. Bentley
2017-06-20  5:53 ` Anthony J. Bentley
2017-06-21 18:09 ` Ingo Schwarze
2017-06-22  0:37 ` Ingo Schwarze

tech@mandoc.bsd.lv

Archives are clonable: git clone --mirror http://inbox.vuxu.org/mandoc-tech

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.mandoc.tech


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git