From: kristaps@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: docbook2mdoc: Differentiate between inline and non-inline equations by
Date: Sun, 19 Oct 2014 15:11:29 -0400 (EDT) [thread overview]
Message-ID: <201410191911.s9JJBTSI015524@krisdoz.my.domain> (raw)
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
reply other threads:[~2014-10-19 19:11 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=201410191911.s9JJBTSI015524@krisdoz.my.domain \
--to=kristaps@mdocml.bsd.lv \
--cc=source@mdocml.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).