source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* docbook2mdoc: Differentiate between inline and non-inline equations by
@ 2014-10-19 19:11 kristaps
  0 siblings, 0 replies; only message in thread
From: kristaps @ 2014-10-19 19:11 UTC (permalink / raw)
  To: source

Log Message:
-----------
Differentiate between inline and non-inline equations by using delimiters.

Modified Files:
--------------
    docbook2mdoc:
        docbook2mdoc.1
        docbook2mdoc.c

Revision Data
-------------
Index: docbook2mdoc.1
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/docbook2mdoc/docbook2mdoc.1,v
retrieving revision 1.6
retrieving revision 1.7
diff -Ldocbook2mdoc.1 -Ldocbook2mdoc.1 -u -p -r1.6 -r1.7
--- docbook2mdoc.1
+++ docbook2mdoc.1
@@ -71,6 +71,7 @@ and a pager:
 .Dl % docbook2mdoc foo.xml | mandoc | more
 .Sh SEE ALSO
 .Xr mandoc 1 ,
+.Xr eqn 7 ,
 .Xr mdoc 7
 .Sh AUTHORS
 .Nm
Index: docbook2mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/docbook2mdoc/docbook2mdoc.c,v
retrieving revision 1.42
retrieving revision 1.43
diff -Ldocbook2mdoc.c -Ldocbook2mdoc.c -u -p -r1.42 -r1.43
--- docbook2mdoc.c
+++ docbook2mdoc.c
@@ -37,6 +37,8 @@ struct	parse {
 	enum nodeid	 node; /* current (NODE_ROOT if pre-tree) */
 	const char	*fname; /* filename */
 	int		 stop; /* should we stop now? */
+#define	PARSE_EQN	 1
+	unsigned int	 flags; /* document-wide flags */
 	struct pnode	*root; /* root of parse tree */
 	struct pnode	*cur; /* current node in tree */
 	char		*b; /* nil-terminated buffer for pre-print */
@@ -305,7 +307,6 @@ xml_elem_start(void *arg, const XML_Char
 		ps->node = ps->cur->node;
 	}
 
-
 	for (node = 0; node < NODE__MAX; node++)
 		if (NULL == nodes[node].name)
 			continue;
@@ -341,6 +342,9 @@ xml_elem_start(void *arg, const XML_Char
 		return;
 	}
 
+	if (NODE_INLINEEQUATION == node)
+		ps->flags |= PARSE_EQN;
+
 	if (NULL == (dat = calloc(1, sizeof(struct pnode)))) {
 		perror(NULL);
 		exit(EXIT_FAILURE);
@@ -1066,6 +1070,12 @@ pnode_printprologue(struct parse *p, str
 		puts(".Dt UNKNOWN 1");
 		puts(".Os");
 	}
+
+	if (PARSE_EQN & p->flags) {
+		puts(".EQ");
+		puts("delim $$");
+		puts(".EN");
+	}
 }
 
 /*
@@ -1267,6 +1277,16 @@ pnode_print(struct parse *p, struct pnod
 		pnode_printmopen(p);
 		fputs("Fd", stdout);
 		break;
+	case (NODE_INFORMALEQUATION):
+		if ( ! p->newln)
+			putchar('\n');
+		puts(".EQ");
+		p->newln = 0;
+		break;
+	case (NODE_INLINEEQUATION):
+		fputc('$', stdout);
+		p->newln = 0;
+		break;
 	case (NODE_ITEMIZEDLIST):
 		assert(p->newln);
 		pnode_printlist(p, pn);
@@ -1280,12 +1300,6 @@ pnode_print(struct parse *p, struct pnod
 		pnode_printmopen(p);
 		fputs("Li", stdout);
 		break;
-	case (NODE_MML_MATH):
-		if ( ! p->newln)
-			putchar('\n');
-		puts(".EQ");
-		p->newln = 0;
-		break;
 	case (NODE_MML_MFENCED):
 		pnode_printmathfenced(p, pn);
 		pnode_unlinksub(pn);
@@ -1294,7 +1308,9 @@ pnode_print(struct parse *p, struct pnod
 	case (NODE_MML_MI):
 	case (NODE_MML_MN):
 	case (NODE_MML_MO):
-		putchar('{');
+		if (TAILQ_EMPTY(&pn->childq))
+			break;
+		fputs(" { ", stdout);
 		break;
 	case (NODE_MML_MFRAC):
 	case (NODE_MML_MSUB):
@@ -1482,17 +1498,23 @@ pnode_print(struct parse *p, struct pnod
 		pnode_print(p, pp);
 
 	switch (pn->node) {
-	case (NODE_MML_MATH):
+	case (NODE_INFORMALEQUATION):
 		if ( ! p->newln)
 			putchar('\n');
 		puts(".EN");
 		p->newln = 1;
 		break;
+	case (NODE_INLINEEQUATION):
+		fputs("$ ", stdout);
+		p->newln = sv;
+		break;
 	case (NODE_MML_MROW):
 	case (NODE_MML_MI):
 	case (NODE_MML_MN):
 	case (NODE_MML_MO):
-		putchar('}');
+		if (TAILQ_EMPTY(&pn->childq))
+			break;
+		fputs(" } ", stdout);
 		break;
 	case (NODE_APPLICATION):
 	case (NODE_ARG):
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2014-10-19 19:11 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-19 19:11 docbook2mdoc: Differentiate between inline and non-inline equations by kristaps

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).