1 /* $Id: eqn_html.c,v 1.10 2014/10/12 19:31:41 schwarze Exp $ */
3 * Copyright (c) 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
31 eqn_box(struct html
*p
, const struct eqn_box
*bp
)
33 struct tag
*post
, *row
, *cell
, *t
;
34 struct htmlpair tag
[2];
35 const struct eqn_box
*child
, *parent
;
44 * Special handling for a matrix, which is presented to us in
45 * column order, but must be printed in row-order.
47 if (EQN_MATRIX
== bp
->type
) {
48 if (NULL
== bp
->first
)
50 if (EQN_LIST
!= bp
->first
->type
) {
51 eqn_box(p
, bp
->first
);
54 if (NULL
== (parent
= bp
->first
->first
))
56 /* Estimate the number of rows, first. */
57 if (NULL
== (child
= parent
->first
))
59 for (rows
= 0; NULL
!= child
; rows
++)
61 /* Print row-by-row. */
62 post
= print_otag(p
, TAG_MTABLE
, 0, NULL
);
63 for (i
= 0; i
< rows
; i
++) {
64 parent
= bp
->first
->first
;
65 row
= print_otag(p
, TAG_MTR
, 0, NULL
);
66 while (NULL
!= parent
) {
67 child
= parent
->first
;
68 for (j
= 0; j
< i
; j
++) {
74 (p
, TAG_MTD
, 0, NULL
);
76 * If we have no data for this
77 * particular cell, then print a
78 * placeholder and continue--don't puke.
81 eqn_box(p
, child
->first
);
83 parent
= parent
->next
;
92 post
= print_otag(p
, TAG_MOVER
, 0, NULL
);
95 post
= print_otag(p
, TAG_MSUP
, 0, NULL
);
98 post
= print_otag(p
, TAG_MUNDER
, 0, NULL
);
101 post
= print_otag(p
, TAG_MSUB
, 0, NULL
);
104 post
= print_otag(p
, TAG_MFRAC
, 0, NULL
);
106 case (EQNPOS_FROMTO
):
107 post
= print_otag(p
, TAG_MUNDEROVER
, 0, NULL
);
109 case (EQNPOS_SUBSUP
):
110 post
= print_otag(p
, TAG_MSUBSUP
, 0, NULL
);
113 post
= print_otag(p
, TAG_MSQRT
, 0, NULL
);
119 if (bp
->top
|| bp
->bottom
) {
120 assert(NULL
== post
);
121 if (bp
->top
&& NULL
== bp
->bottom
)
122 post
= print_otag(p
, TAG_MOVER
, 0, NULL
);
123 else if (bp
->top
&& bp
->bottom
)
124 post
= print_otag(p
, TAG_MUNDEROVER
, 0, NULL
);
126 post
= print_otag(p
, TAG_MUNDER
, 0, NULL
);
129 if (EQN_PILE
== bp
->type
) {
130 assert(NULL
== post
);
131 if (bp
->first
!= NULL
&& bp
->first
->type
== EQN_LIST
)
132 post
= print_otag(p
, TAG_MTABLE
, 0, NULL
);
133 } else if (bp
->type
== EQN_LIST
&&
134 bp
->parent
&& bp
->parent
->type
== EQN_PILE
) {
135 assert(NULL
== post
);
136 post
= print_otag(p
, TAG_MTR
, 0, NULL
);
137 print_otag(p
, TAG_MTD
, 0, NULL
);
140 if (NULL
!= bp
->text
) {
141 assert(NULL
== post
);
142 post
= print_otag(p
, TAG_MI
, 0, NULL
);
143 print_text(p
, bp
->text
);
144 } else if (NULL
== post
) {
145 if (NULL
!= bp
->left
|| NULL
!= bp
->right
) {
146 PAIR_INIT(&tag
[0], ATTR_OPEN
,
147 NULL
== bp
->left
? "" : bp
->left
);
148 PAIR_INIT(&tag
[1], ATTR_CLOSE
,
149 NULL
== bp
->right
? "" : bp
->right
);
150 post
= print_otag(p
, TAG_MFENCED
, 2, tag
);
153 post
= print_otag(p
, TAG_MROW
, 0, NULL
);
155 print_otag(p
, TAG_MROW
, 0, NULL
);
158 eqn_box(p
, bp
->first
);
161 if (NULL
!= bp
->bottom
) {
162 t
= print_otag(p
, TAG_MO
, 0, NULL
);
163 print_text(p
, bp
->bottom
);
166 if (NULL
!= bp
->top
) {
167 t
= print_otag(p
, TAG_MO
, 0, NULL
);
168 print_text(p
, bp
->top
);
175 eqn_box(p
, bp
->next
);
179 print_eqn(struct html
*p
, const struct eqn
*ep
)
184 PAIR_CLASS_INIT(&tag
, "eqn");
185 t
= print_otag(p
, TAG_MATH
, 1, &tag
);
187 p
->flags
|= HTML_NONOSPACE
;
188 eqn_box(p
, ep
->root
);
189 p
->flags
&= ~HTML_NONOSPACE
;