Debian Codegraph @

texmf-dist/source/generic/tex4ht/tex4ht-oo-xtpipes.tex

raw
1 % $Id: tex4ht-oo-xtpipes.tex 740 2020-06-13 22:35:32Z karl $
2 % htlatex tex4ht-oo-xtpipes "xhtml,next,3" "" "-d./"
3 %
4 % Copyright 2009-2020 TeX Users Group
5 % Copyright 2001-2009 Eitan M. Gurari
6 % Released under LPPL 1.3c+.
7 % See tex4ht-cpright.tex for license text.
8
9 \documentclass{article}
10 \Configure{ProTex}{log,<<<>>>,title,list,`,[[]]}
11 \usepackage{url}
12 \begin{document}
13
14 \input{common}
15 \input{tex4ht-cpright}
16 \input{tex4ht-dir}
17
18
19 %%%%%%%%%%%%%%%%%%
20 \section{Outline}
21 %%%%%%%%%%%%%%%%%%
22
23
24 %%%%%%%%%%%%%
25 \subsection{Math}
26 %%%%%%%%%%%%%
27
28
29 \AtEndDocument{\OutputCodE\<oo-math.4xt\>}
30
31 \Needs{"xmllint --valid --noout oo-math.4xt"}
32
33
34
35
36
37 \<oo-math.4xt\><<<
38 <?xml version="1.0" encoding="UTF-8" ?>
39 <!DOCTYPE xtpipes SYSTEM "xtpipes.dtd" >
40 <!-- oo-math.4xt (`version), generated from `jobname.tex
41 Copyright (C) 2009-2013 TeX Users Group
42 Copyright (C) `CopyYear.2006. Eitan M. Gurari
43 `<TeX4ht copyright`> -->
44 <xtpipes preamble="yes" signature="oo-math.4xt (`version)">
45 <sax content-handler="xtpipes.util.ScriptsManager,tex4ht.OomFilter"
46 lexical-handler="xtpipes.util.ScriptsManagerLH" >
47 <script element="math:mtable" >
48 `<normalizing math tables`>
49 </script>
50 <script element="math:math" >
51 `<handle mo elements`>
52 `<handle mrow elements`>
53 `<handle mspace elements`>
54 </script>
55 </sax>
56 </xtpipes>
57 >>>
58
59
60
61
62
63
64
65 \<handle mspace elements\><<<
66 <set name="math:mspace" >
67 `<open mml xslt script`>
68 `<math:mspace templates`>
69 `<close xslt script`>
70 </set>
71 <xslt name="." xml="." xsl="math:mspace" />
72 >>>
73
74
75 \<math:mspace templates\><<<
76 <xsl:template match="math:mspace" >
77 <math:mtext>
78 <xsl:text> </xsl:text>
79 </math:mtext>
80 </xsl:template>
81 >>>
82
83
84
85
86 %%%%%%%%%%%%%
87 \subsection{Text}
88 %%%%%%%%%%%%%
89
90
91
92
93
94
95
96 \AtEndDocument{\OutputCodE\<oo-text.4xt\>}
97
98 \Needs{"xmllint --valid --noout oo-text.4xt"}
99
100
101
102
103
104 \<oo-text.4xt\><<<
105 <?xml version="1.0" encoding="UTF-8" ?>
106 <!DOCTYPE xtpipes SYSTEM "xtpipes.dtd" >
107 <!-- oo-text.4xt (`version), generated from `jobname.tex
108 Copyright (C) 2009-2013 TeX Users Group
109 Copyright (C) `CopyYear.2006. Eitan M. Gurari
110 `<TeX4ht copyright`> -->
111 <xtpipes preamble="yes" signature="oo-text.4xt (`version)">
112 <sax content-handler="xtpipes.util.ScriptsManager,tex4ht.OoFilter"
113 lexical-handler="xtpipes.util.ScriptsManagerLH" >
114 <script element="text:bibliography-mark" >
115 `<bib mark`>
116 </script>
117 <script element="table:table" >
118 `<normalizing text tables`>
119 </script>
120 <script element="text:p" >
121 `<clean paragraphs`>
122 </script>
123 <script element="text:h" >
124 `<spaces for headers`>
125 </script>
126 </sax>
127 </xtpipes>
128 >>>
129
130
131 %%%%%%%%%%%%%
132 \subsubsection{Cross References}
133 %%%%%%%%%%%%%
134
135 This is not used anymore, the make4ht-t4htlinks DOM filter is used instead. The
136 following code may produce broken or empty links, so it is not really usable.
137
138 \<cross references\><<<
139 <set name="t4ht-link" >
140 `<open oo xslt script`>
141 `<handle t4htlink elements`>
142 `<close xslt script`>
143 </set>
144 <xslt name="." xml="." xsl="t4ht-link" />
145 >>>
146
147 \<bib mark\><<<
148 <set name="bib-mark" >
149 `<open oo xslt script`>
150 `<handle bib mark elements`>
151 `<close xslt script`>
152 </set>
153 <xslt name="." xml="." xsl="bib-mark" />
154 >>>
155
156
157
158 \<handle t4htlink elements\><<<
159 <xsl:template match="t4htlink[ @href = concat('#',@name) ]" >
160 <xsl:apply-templates select="*|text()|comment()" />
161 <text:reference-mark>
162 <xsl:attribute name="text:name">
163 <xsl:value-of select="@name"/>
164 </xsl:attribute>
165 <xsl:text> </xsl:text>
166 </text:reference-mark>
167 </xsl:template>
168 >>>
169
170 \<handle t4htlink elements\><<<
171 <xsl:template match="t4htlink[ not(@name)
172 and
173 starts-with(@href, '#')
174 ]" >
175 <xsl:apply-templates select="*|text()|comment()" />
176 <text:span>
177 <xsl:attribute name="text:style-name">
178 <xsl:text>reference-ref</xsl:text>
179 </xsl:attribute>
180 <text:reference-ref>
181 <xsl:attribute name="text:ref-name">
182 <xsl:value-of select="substring( @href, 2 )"/>
183 </xsl:attribute>
184 <xsl:attribute name="text:reference-format">
185 <xsl:text>text</xsl:text>
186 </xsl:attribute>
187 <xsl:text> </xsl:text>
188 </text:reference-ref>
189 </text:span>
190 </xsl:template>
191 >>>
192
193
194
195
196
197
198
199 \<handle t4htlink elements\><<<
200 <xsl:template match="t4htlink[ not(@name)
201 and
202 not(starts-with(@href, '#'))
203 ]" >
204 <text:a>
205 <xsl:attribute name="xlink:type">
206 <xsl:text>simple</xsl:text>
207 </xsl:attribute>
208 <xsl:attribute name="xlink:href">
209 <xsl:value-of select="@href"/>
210 </xsl:attribute>
211 <xsl:apply-templates select="*|text()|comment()" />
212 </text:a>
213 </xsl:template>
214 >>>
215
216
217
218
219
220 \<handle bib mark elements\><<<
221 <xsl:template match="text:bibliography-mark" >
222 <xsl:copy>
223 <xsl:attribute name="text:identifier">
224 <xsl:value-of select="normalize-space(.)" />
225 </xsl:attribute>
226 <xsl:apply-templates select="@*" />
227 </xsl:copy>
228 <text:span>
229 <xsl:attribute name="text:style-name">
230 <xsl:text>reference-ref</xsl:text>
231 </xsl:attribute>
232 <text:reference-ref>
233 <xsl:attribute name="text:ref-name">
234 <xsl:value-of
235 select="text:span/text:reference-ref/@text:ref-name"/>
236 </xsl:attribute>
237 <xsl:attribute name="text:reference-format">
238 <xsl:text>text</xsl:text>
239 </xsl:attribute>
240 <xsl:text> </xsl:text>
241 </text:reference-ref>
242 </text:span>
243 </xsl:template>
244 >>>
245
246
247
248
249
250 \begin{itemize}
251 \item
252 External
253 \begin{verbatim}
254 <text:a xlink:type="simple"
255 xlink:href="http:....">...</text:a>
256 \end{verbatim}
257
258
259 \item internal
260 \url{http://www.linuxjournal.com/article/8112}
261
262
263 \begin{verbatim}
264 <text:reference-mark-start text:name="xx"/>
265 is
266 <text:reference-mark-end text:name="xx"/>
267
268 <text:reference-ref text:reference-format="direction" text:ref-name="xx">
269 above
270 </text:reference-ref>
271 \end{verbatim}
272
273 \end{itemize}
274
275
276 %%%%%%%%%%%%%
277 \subsection{Java Utilities}
278 %%%%%%%%%%%%%
279
280
281
282 \AtEndDocument{\OutputCodE\<OoUtilities.java\>}
283
284 \ifdojava
285 \Needs{"
286 javac OoUtilities.java -d \XTPIPES
287 "}
288 \fi
289
290 \<OoUtilities.java\><<<
291 package tex4ht;
292 /* OoUtilities.java (`version), generated from `jobname.tex
293 Copyright (C) 2009-2013 TeX Users Group
294 Copyright (C) `CopyYear.2006. Eitan M. Gurari
295 `<TeX4ht copyright`> */
296 import org.w3c.dom.*;
297 public class OoUtilities {
298 `<static void mtable(dom)`>
299 `<static void table(dom)`>
300 `<static boolean justSpace(node)`>
301 }
302 >>>
303
304
305 `<static boolean paragraph(node)`>
306
307
308 %%%%%%%%%%%%%%%%%%
309 \section{Text Table}
310 %%%%%%%%%%%%%%%%%%
311
312 %
313 %
314 %
315 % \<handle mrow elements\><<<
316 % <set name="math:mtd" >
317 % `<open oo xslt script`>
318 % `<math:mtd templates`>
319 % `<close xslt script`>
320 % </set>
321 % <xslt name="." xml="." xsl="math:mtd" />
322 % >>>
323 %
324 % \<math:mtd templates\><<<
325 % <xsl:template match="math:mtd" >
326 % <xsl:copy>
327 % <xsl:apply-templates select="*|text()" />
328 % </xsl:copy>
329 % </xsl:template>
330 % >>>
331 %
332 %
333 % \<math:mtd templates\><<<
334 % <xsl:template match="math:mtable">
335 % <math:mtable math:columnalign="right left">
336 % <xsl:apply-templates select="*|text()" />
337 % </math:mtable>
338 % </xsl:template>
339 % >>>
340 %
341 %
342 %
343
344 %%%%%%%%%%%%%
345 \subsection{Outline}
346 %%%%%%%%%%%%%
347
348
349
350
351
352 \<normalizing text tables\><<<
353 <dom name="." xml="." method="table" class="tex4ht.OoUtilities" />
354 >>>
355
356
357 \<static void table(dom)\><<<
358 public static void table(Node dom) {
359 Node tblRow, tblCell, d;
360 // int cols = 0;
361 Node node = dom.getFirstChild();
362 `<bind text namespace prefixes in the root element`>
363 `<tblRow -= empty trailing rows`>
364 if( (tblRow != null) && (tblRow.getPreviousSibling() != null) ){
365 `<bool = is ruler row?`>
366 if( !bool ){
367 `<remove child spaces from row`>
368 `<remove trailing non-content row`>
369 tblCell = tblRow.getFirstChild();
370 if( (tblCell != null)
371 && (tblCell.getNextSibling() == null)
372 && justSpace(tblCell)
373 ){
374 node.removeChild(tblRow);
375 } } }
376 `<n := max number of cols`>
377 `<remove extra col declarations`>
378 }
379 >>>
380
381
382
383 \begin{verbatim}
384 <table:table >
385 <table:table-column table:style-name="equ-col"/>
386 <table:table-column table:style-name="equ-num-col"/>
387
388 <table:table-row>
389 <table:table-cell table:style-name="equ-cell">
390 ....
391 </table:table-cell>
392 </table:table-row>
393
394 <table:table-row>
395 ....
396 </table:table-row>
397
398 </table:table>
399 \end{verbatim}
400
401
402 %%%%%%%%%%%%%
403 \subsection{Remove Rows}
404 %%%%%%%%%%%%%
405
406
407
408
409
410 \<tblRow -= empty trailing rows\><<<
411 tblRow = node.getLastChild();
412 while( (tblRow != null)
413 // && (tblRow.getNodeType() == Node.TEXT_NODE)
414 // && tblRow.getNodeValue().trim().equals("")
415 && tblRow.getTextContent().trim().equals("")
416 ){
417 node.removeChild(tblRow);
418 tblRow = node.getLastChild();
419 }
420 >>>
421
422
423
424
425 %%%%%%%%%%%%%
426 \subsection{Remove Extra Column Declarations}
427 %%%%%%%%%%%%%
428
429
430
431 \<remove child spaces from row\><<<
432 tblCell = tblRow.getFirstChild();
433 while( tblCell != null){
434 d = tblCell.getNextSibling();
435 if( justSpace(tblCell) ){ tblRow.removeChild(tblCell); }
436 tblCell = d;
437 }
438 >>>
439
440
441
442
443 \<n := max number of cols\><<<
444 int n = 0;
445 tblRow = node.getFirstChild();
446 while( tblRow != null ){
447 if(
448 (tblRow.getNodeType() == Node.ELEMENT_NODE)
449 &&
450 tblRow.getNodeName().equals("table:table-row")
451 ){
452 `<m := number of columns`>
453 if( m > n ){ n = m; }
454 }
455 tblRow = tblRow.getNextSibling();
456 }
457 >>>
458
459 \<m := number of columns\><<<
460 int m = 0;
461 tblCell = tblRow.getFirstChild();
462 while( tblCell != null ){
463 if(
464 (tblCell.getNodeType() == Node.ELEMENT_NODE)
465 &&
466 tblCell.getNodeName().equals("table:table-cell")
467 ){
468 m++;
469 `<table:table-cell -= empty text:p`>
470 }
471 tblCell = tblCell.getNextSibling();
472 }
473 >>>
474
475
476
477
478
479 \<remove extra col declarations\><<<
480 tblRow = node.getFirstChild();
481 while( tblRow != null ){
482 d = tblRow.getNextSibling();
483 if(
484 (tblRow.getNodeType() == Node.ELEMENT_NODE)
485 &&
486 tblRow.getNodeName().equals("table:table-column")
487 ){
488 n--;
489 if( n < 0 ){
490 tblRow.getParentNode().removeChild(tblRow);
491 } }
492 tblRow = d;
493 }
494 >>>
495
496
497 %%%%%%%%%%%%%
498 \subsection{Remove Empty Paragraphs within Table Cell}
499 %%%%%%%%%%%%%
500
501
502 There is an exception for paragraphs that are the only child elements.
503
504
505 \<table:table-cell -= empty text:p\><<<
506 Node child = tblCell.getLastChild();
507 while( child != null ){
508 Node prevChild = child.getPreviousSibling();
509 if(
510 (child.getNodeType() == Node.ELEMENT_NODE)
511 &&
512 child.getNodeName().equals("text:p")
513 ){
514 Node sibling = child.getPreviousSibling();
515 while( (sibling != null)
516 &&
517 (sibling.getNodeType() != Node.ELEMENT_NODE)
518 ){
519 sibling = sibling.getPreviousSibling();
520 }
521 if( sibling == null ){
522 sibling = child.getNextSibling();
523 while( (sibling != null)
524 &&
525 (sibling.getNodeType() != Node.ELEMENT_NODE)
526 ){
527 sibling = sibling.getNextSibling();
528 } }
529 if( (sibling != null)
530 && child.getTextContent().trim().equals("")
531 ){
532 tblCell.removeChild(child);
533 } }
534 child = prevChild;
535 }
536 >>>
537
538
539
540 %%%%%%%%%%%%%
541 \subsection{Test for Empty Nodes}
542 %%%%%%%%%%%%%
543
544
545
546
547 \<static boolean justSpace(node)\><<<
548 static boolean justSpace(Node node){
549 if( node == null ){ return true; }
550 if( node.getNodeType() == Node.TEXT_NODE ){
551 if( !node.getNodeValue().trim().equals("") ){ return false; }
552 } else {
553 if( node.getNodeType() == Node.ELEMENT_NODE ){
554 String nm = node.getNodeName();
555 if(
556 !nm.equals("table:table-cell")
557 && !nm.equals("text:p")
558 ){
559 return false;
560 } }
561 }
562 if(!justSpace( node.getNextSibling() )){ return false; }
563 if(!justSpace( node.getFirstChild() )){ return false; }
564 return true;
565 }
566 >>>
567
568 \<bool = is ruler row?\><<<
569 boolean bool = false;
570 if( tblRow.getNodeName().equals("table:table-row")
571 && tblRow.hasAttributes()
572 ){
573 NamedNodeMap attributes = tblRow.getAttributes();
574 Node styleAttr = attributes.getNamedItem( "table:style-name" );
575 String style = (styleAttr==null)? null
576 : styleAttr.getNodeValue();
577 if( (style != null)
578 && ( style.equals("hline-row")
579 || style.equals("cline-row")
580 )
581 ){
582 bool = true;
583 } }
584 >>>
585
586 %%%%%%%%%%%%%%%%%%
587 \section{Nested Paragraphs (OoUtilities)}
588 %%%%%%%%%%%%%%%%%%
589
590
591
592
593 \<clean paragraphs\><<<
594 <set name="text-p" >
595 `<open oo xslt script`>
596 `<remove nested text:p`>
597 `<remove nested text:p in biblatex`>
598 `<multicolumn styles`>
599 `<close xslt script`>
600 </set>
601 <xslt name="." xml="." xsl="text-p" />
602 >>>
603
604
605
606
607 \<remove nested text:p2???\><<<
608 <xsl:template match="text:p[ @text:style-name = 'start_subjclass'
609 ]" >
610 <xsl:comment>
611 <xsl:text>start-subjclass</xsl:text>
612 </xsl:comment>
613 <xsl:apply-templates select="*|text()|comment()" />
614 </xsl:template>
615 <xsl:template match="text:p[ @text:style-name = 'end_subjclass'>
616 <xsl:apply-templates select="*|text()|comment()" />
617 <xsl:comment>
618 <xsl:text>end-subjclass</xsl:text>
619 </xsl:comment>
620 </xsl:template>
621 >>>
622
623
624
625 \<remove nested text:p\><<<
626 <xsl:template match="text:p[ (count(child::*)=1)
627 and child::draw:frame
628 and parent::text:p
629 ]" >
630 <xsl:apply-templates select="child::draw:frame" />
631 </xsl:template>
632 >>>
633
634
635
636 \<remove nested text:p\><<<
637 <xsl:template match="text:p[
638 child::text:p
639 and
640 (count(child::text:p) = count(child::*))
641 ]" >
642 <!--xsl:copy>
643 <xsl:attribute name="text:style-name">
644 <xsl:text>start_</xsl:text>
645 <xsl:value-of select="@text:style-name" />
646 </xsl:attribute-->
647 <xsl:comment>
648 <xsl:text>start </xsl:text>
649 <xsl:value-of select=" @text:style-name " />
650 </xsl:comment>
651 <!--/xsl:copy-->
652 <xsl:apply-templates select="*|text()|comment()" mode="nested-p" />
653 <!--xsl:copy>
654 <xsl:attribute name="text:style-name">
655 <xsl:text>end</xsl:text>
656 <xsl:value-of select="@text:style-name" />
657 </xsl:attribute-->
658 <xsl:comment>
659 <xsl:text>end_</xsl:text>
660 <xsl:value-of select=" @text:style-name " />
661 </xsl:comment>
662 <!--/xsl:copy-->
663 </xsl:template>
664 >>>
665
666 \<remove nested text:p\><<<
667 <xsl:template match="*[not(text:p)]|text()|comment()" mode="nested-p" >
668 <xsl:copy/>
669 </xsl:template>
670 >>>
671
672 \<remove nested text:p\><<<
673 <xsl:template match="text:p" mode="nested-p" >
674 <xsl:copy>
675 <xsl:attribute name="text:style-name">
676 <xsl:value-of select="parent::text:p/@text:style-name" />
677 <xsl:text>_</xsl:text>
678 <xsl:value-of select="@text:style-name" />
679 <xsl:text>_</xsl:text>
680 <xsl:value-of select="child::*[1]/@text:style-name" />
681 </xsl:attribute>
682 <xsl:apply-templates select="@*[ name() != 'text:style-name' ]" />
683 <xsl:apply-templates select="*|text()|comment()" />
684 </xsl:copy>
685 </xsl:template>
686 >>>
687
688 \<remove nested text:p in biblatex\><<<
689 <xsl:template
690 match="text:p[
691 parent::text:p/@text:style-name='printthebibliography-dd'
692 ]"
693 mode="nested-p" >
694 <xsl:copy>
695 <xsl:attribute name="text:style-name">
696 <xsl:value-of select="'printthebibliography-dd'" />
697 </xsl:attribute>
698 <xsl:apply-templates select="@*[ name() != 'text:style-name' ]" />
699 <xsl:apply-templates select="*|text()|comment()" />
700 </xsl:copy>
701 </xsl:template>
702 >>>
703
704
705
706
707
708
709
710
711
712
713
714
715 \<multicolumn styles\><<<
716 <xsl:template match="text:p[ child::text:span[
717 starts-with(@text:style-name, 'multicolumn-')
718 ] ]" >
719 <xsl:copy>
720 <xsl:apply-templates
721 select="child::text:span[
722 starts-with(@text:style-name, 'multicolumn-') ]
723 /@*
724 " />
725 <xsl:apply-templates select="*|text()|comment()" />
726 </xsl:copy>
727 </xsl:template>
728 <xsl:template match="text:span[
729 starts-with(@text:style-name, 'multicolumn-') ]" />
730 >>>
731
732
733 \<handle mixed content\><<<
734 System.out.println("handle mixed content " + name);
735 int i=0;
736 for( Node nd = first; nd != null; nd = nd.getNextSibling() ){
737 nodeType = nd.getNodeType();
738 `<trace mixed content`>
739 i++;
740 }
741 System.out.println("end handle mixed content " + name);
742 >>>
743
744 \<text:p into text:section\><<<
745 System.out.println("text:p into text:section");
746 >>>
747
748
749
750
751 \<trace mixed content\><<<
752 System.out.println(
753 i + " "+ ((Boolean)v.get(i))
754 +
755
756 ((nodeType == Node.TEXT_NODE)?
757 (" TEXT: " + nd.getNodeValue() )
758 :
759 (
760 (nodeType == Node.ELEMENT_NODE)?
761 (" " + nd.getNodeName())
762 :
763 ""
764 )
765 ));
766 >>>>
767
768
769
770
771
772
773
774 %%%%%%%%%%%%%%%%%%
775 \section{Spaces for Headers}
776 %%%%%%%%%%%%%%%%%%
777
778 \<spaces for headers\><<<
779 <set name="headers" >
780 `<open oo xslt script`>
781 `<algorithmic templates`>
782 `<biblatex bib templates`>
783 `<close xslt script`>
784 </set>
785 <xslt name="." xml="." xsl="headers" />
786 >>>
787
788 \<algorithmic templates\><<<
789 <xsl:template match="text:h[@text:style-name='algorithmic-dt']" >
790 <xsl:copy>
791 <xsl:apply-templates select="@*" />
792 <xsl:apply-templates select="*|text()|comment()" mode="algorithmic"/>
793 </xsl:copy>
794 </xsl:template>
795 >>>
796
797
798 \<algorithmic templates\><<<
799 <xsl:template match="*|@*|comment()" mode="algorithmic" >
800 <xsl:copy>
801 <xsl:apply-templates select="@*" />
802 <xsl:apply-templates select="*|text()|comment()" mode="algorithmic"/>
803 </xsl:copy>
804 </xsl:template>
805 >>>
806
807
808
809 \<algorithmic templates\><<<
810 <xsl:template match="text()" mode="algorithmic" >
811 <xsl:value-of select="translate(.,' ','&#xA0;')"/>
812 </xsl:template>
813 >>>
814
815
816 \<biblatex bib templates\><<<
817 <xsl:template match="text:h[
818 (@text:style-name='printthebibliography-dt')
819 and
820 (normalize-space()='')
821 ]" >
822 </xsl:template>
823 >>>
824
825
826 %%%%%%%%%%%%%%%%%%
827 \section{mo}
828 %%%%%%%%%%%%%%%%%%
829
830 \<handle mo elements\><<<
831 <set name="math:mo" >
832 `<open mml xslt script`>
833 <xsl:template match=" math:mo" >
834 <xsl:choose>
835 `<xsl:when mo...`>
836 `<xsl:when mo length ...`>
837 <xsl:otherwise>
838 <math:mo>
839 <xsl:apply-templates select="@*" />
840 <xsl:value-of select="normalize-space(.)" />
841 </math:mo>
842 </xsl:otherwise>
843 </xsl:choose>
844 </xsl:template>
845 `<close xslt script`>
846 </set>
847 <xslt name="." xml="." xsl="math:mo" />
848 >>>
849
850
851
852
853
854 A translation of
855
856 \begin{verbatim}
857 <math:mrow>
858 <math:mn>2</math:mn>
859 <math:mo>+</math:mo>
860 </math:mrow>
861 \end{verbatim}
862
863 to
864
865 \begin{verbatim}
866 <math:mrow>
867 <math:mn>2</math:mn>
868 <math:mo form="postfix">+</math:mo>
869 </math:mrow>
870 \end{verbatim}
871
872 fails to satisfy OO. So the following alternative is offered
873
874 \begin{verbatim}
875 <math:mrow>
876 <math:mn>2</math:mn>
877 <math:mtext>+</math:mtext>
878 </math:mrow>
879 \end{verbatim}
880
881
882 \<xsl:when mo...\><<<
883 <xsl:when test="
884 (preceding-sibling::math:mn or preceding-sibling::math:mi)
885 and not(following-sibling::*)
886 " >
887 <math:mtext>
888 <xsl:apply-templates select="*|@*|text()" />
889 </math:mtext>
890 </xsl:when>
891 >>>
892
893
894
895
896 Isolated mo elements are problematic (e.g.,
897 \verb'<mtd><mo form="...">=</mo></mtd>') in OpenOffice
898 (\url{http://lists.w3.org/Archives/Public/www-math/2006Jul/0012.html})
899 so they are converted into mtext elements.
900
901
902
903
904 \<xsl:when mo...\><<<
905 <xsl:when test="
906 not((preceding-sibling::*) or following-sibling::*)
907 " >
908 <math:mtext>
909 <xsl:apply-templates select="*|@*|text()" />
910 </math:mtext>
911 </xsl:when>
912 >>>
913
914 The original condition
915 `not(preceding-sibling::* or following-sibling::*)'
916 failed with java 1.6 at a MS OS.
917
918
919 \begin{verbatim}
920 <?xml version="1.0" encoding="UTF-8"?>
921 <xsl:stylesheet version="1.0"
922 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
923 xmlns:xlink="http://www.w3.org/1999/xlink"
924 >
925 <xsl:output omit-xml-declaration = "yes" />
926 <xsl:template match="mo" >
927 <xsl:choose>
928 <xsl:when test="preceding-sibling::* or following-sibling::*" >
929 </xsl:when>
930 </xsl:choose>
931 </xsl:template>
932 </xsl:stylesheet>
933
934
935 import java.io.*;
936 import javax.xml.transform.*;
937 import javax.xml.transform.stream.*;
938
939 public class Test {
940 public static void main(String[] args)
941 throws TransformerConfigurationException,
942 TransformerException {
943 try{
944 StreamSource xslt = new StreamSource(new File("test.xslt"));
945 TransformerFactory fc = TransformerFactory.newInstance();
946 Transformer transformer = fc.newTransformer( xslt );
947 } catch (javax.xml.transform.TransformerConfigurationException e){
948
949 } catch (Exception e){
950 System.err.println(e);
951 } } }
952 \end{verbatim}
953
954
955
956
957 Failes on braces within mo elements \verb+<math:mo>{</math:mo>+.
958 Accepts them within mtext elements.
959
960
961 \<xsl:when mo...\><<<
962 <xsl:when test="
963 (.='{') or (.='}')
964 " >
965 <math:mtext>
966 <xsl:apply-templates select="*|@*|text()" />
967 </math:mtext>
968 </xsl:when>
969 >>>
970
971
972
973 \begin{verbatim}
974 A \begin{eqnarray}a&=&b\end{eqnarray} is translated by tex4ht into
975
976 <mi>a</mi><mo>=</mo><mi>b</mi>
977
978 and is loaded as
979
980 matrix {a # = # b}
981
982 by OO2 into a broken display. The xtpipe phase `fixes' the problem by
983 producing improper mathml output
984
985 <mi>a</mi><mtext>=</mtext><mi>b</mi>
986
987 which OO2 loads as
988
989 matrix {a # "=" # b}
990
991 and provides proper display.
992 \end{verbatim}
993
994
995
996
997
998 \<xsl:when mo...\><<<
999 <xsl:when test=" . = '='" >
1000 <xsl:choose>
1001 <xsl:when test=" not(preceding-sibling::*)
1002 or not(following-sibling::*)
1003 or preceding-sibling::*[1] / self::math:mo
1004 ">
1005 <math:mtext>
1006 <xsl:apply-templates select="*|@*|text()" />
1007 </math:mtext>
1008 </xsl:when>
1009 <xsl:otherwise>
1010 <math:mo>
1011 <xsl:apply-templates select="*|@*|text()" />
1012 </math:mo>
1013 </xsl:otherwise>
1014 </xsl:choose>
1015
1016 </xsl:when>
1017 >>>
1018
1019
1020
1021
1022 In cases like \verb!$m \bmod n$!, OpenOffice swallos the characters following the first one.
1023
1024 \<xsl:when mo length ...\><<<
1025 <xsl:when test=" string-length() &gt; 1 " >
1026 <math:mtext>
1027 <xsl:value-of select="normalize-space(.)" />
1028 </math:mtext>
1029 </xsl:when>
1030 >>>
1031
1032
1033 %%%%%%%%%%%%%%%%%%
1034 \section{mrow}
1035 %%%%%%%%%%%%%%%%%%
1036
1037
1038
1039 OpenOffice 2 loads
1040
1041 \begin{verbatim}
1042 <math:msub>
1043 <math:mrow>
1044 <math:mi>x</math:mi>
1045 </math:mrow>
1046 <math:mrow>
1047 <math:msub>
1048 <math:mrow>
1049 <math:mi>i</math:mi>
1050 </math:mrow>
1051 <math:mrow>
1052 <math:mi>j</math:mi>
1053 </math:mrow>
1054 </math:msub>
1055 </math:mrow>
1056 </math:msub>
1057 \end{verbatim}
1058
1059 and
1060
1061 \begin{verbatim}
1062 <math:msub>
1063 <math:mi>x</math:mi>
1064 <math:msub>
1065 <math:mi>i</math:mi>
1066 <math:mi>j</math:mi>
1067 </math:msub>
1068 </math:msub>
1069 \end{verbatim}
1070
1071 into \verb'x_i_j' which is a broken expression. Editing in OpenOffice the source
1072 into
1073 \verb'x_{i_j}'
1074 or
1075 \verb'{x}_{{i}_{j}}'
1076
1077
1078
1079
1080
1081
1082
1083
1084 \<handle mrow elements NO\><<<
1085 <set name="math:mrow" >
1086 `<open mml xslt script`>
1087 `<math:mrow templates`>
1088 `<close xslt script`>
1089 </set>
1090 <xslt name="." xml="." xsl="math:mrow" />
1091 >>>
1092
1093
1094
1095
1096
1097 \<math:mrow templates\><<<
1098 <xsl:template match=" math:mrow[ count(child::*)=1 ]" >
1099 <xsl:apply-templates select="*|@*|text()" />
1100 </xsl:template>
1101 >>>
1102
1103
1104 \begin{verbatim}
1105 The output of tex4ht on $x_{i_j}$ is
1106
1107 <math:msub>
1108 <math:mrow>
1109 <math:mi>x</math:mi>
1110 </math:mrow>
1111 <math:mrow>
1112 <math:msub>
1113 <math:mrow>
1114 <math:mi>i</math:mi>
1115 </math:mrow>
1116 <math:mrow>
1117 <math:mi>j</math:mi>
1118 </math:mrow>
1119 </math:msub>
1120 </math:mrow>
1121 </math:msub>
1122
1123 and OO2 loads the code into a broken format and view x_i_j. The same
1124 outcome occurs when tex4ht is modified to produce the following output.
1125
1126 <math:msub>
1127 <math:mi>x</math:mi>
1128 <math:msub>
1129 <math:mi>i</math:mi>
1130 <math:mi>j</math:mi>
1131 </math:msub>
1132 </math:msub>
1133
1134 A manual editing of x_i_j into {x}_{{i}_{j}} or x_{i_j} provides the
1135 proper display (and identical mathml code).
1136 \end{verbatim}
1137
1138
1139 %%%%%%%%%%%%%%%%%%
1140 \section{Dimenstions of Math Tables}
1141 %%%%%%%%%%%%%%%%%%
1142
1143 %%%%%%%%%%%%%
1144 \subsection{Background}
1145 %%%%%%%%%%%%%
1146
1147
1148
1149
1150
1151 All columns explicitly require identical number of columns.
1152
1153 Broken:
1154
1155 \begin{verbatim}
1156 <math:mtable >
1157 <math:mtr>
1158 <math:mtd columnalign="left"><math:mn>1</math:mn></math:mtd>
1159 <math:mtd columnalign="left"><math:mn>2</math:mn></math:mtd>
1160 </math:mtr>
1161 <math:mtr>
1162 <math:mtd columnalign="left"><math:mn>1</math:mn></math:mtd>
1163 </math:mtr>
1164 </math:mtable>
1165 \end{verbatim}
1166
1167 Works:
1168
1169 \begin{verbatim}
1170 <math:mtable >
1171 <math:mtr>
1172 <math:mtd columnalign="left"><math:mn>1</math:mn></math:mtd>
1173 <math:mtd columnalign="left"><math:mn>2</math:mn></math:mtd>
1174 </math:mtr>
1175 <math:mtr>
1176 <math:mtd columnalign="left"><math:mn>1</math:mn></math:mtd>
1177 <math:mtd columnalign="left"></math:mtd>
1178 </math:mtr>
1179 </math:mtable>
1180 \end{verbatim}
1181
1182
1183 The last \verb+\\+ produces extra line with single entry and no data.
1184
1185 \begin{verbatim}
1186 $
1187 \begin{cases}
1188 1 & 2\\
1189 3 & 4\\
1190 \end{cases}
1191 $
1192 \end{verbatim}
1193
1194 Singlton mspace breaks math tables:
1195
1196 \begin{verbatim}
1197 <math:mtable>
1198 <math:mtr>
1199 <math:mtd><math:mn>1</math:mn></math:mtd>
1200 <math:mtd><math:mspace width="1em"/></math:mtd>
1201 </math:mtr>
1202 </math:mtable>
1203 \end{verbatim}
1204
1205 %%%%%%%%%%%%%
1206 \subsection{Outline}
1207 %%%%%%%%%%%%%
1208
1209 \<normalizing math tables\><<<
1210 <dom name="." xml="." method="mtable" class="tex4ht.OoUtilities" />
1211 >>>
1212
1213
1214 \<static void mtable(dom)\><<<
1215 public static void mtable(Node dom) {
1216 Node mtr, mtd, d;
1217 int cols = 0;
1218 Node node = dom.getFirstChild();
1219 `<remove trailing non-content entries`>
1220 `<fill rows`>
1221 }
1222 >>>
1223
1224
1225
1226
1227
1228
1229
1230 %%%%%%%%%%%%%
1231 \subsection{Remove Trailing Entries}
1232 %%%%%%%%%%%%%
1233
1234 \<remove trailing non-content entries\><<<
1235 if (node.hasChildNodes()) {
1236 mtr = node.getLastChild();
1237 while( mtr != null){
1238 if( mtr.getNodeType() == Node.ELEMENT_NODE ){
1239 if (mtr.hasChildNodes()) {
1240 mtd = mtr.getLastChild();
1241 int count = 0;
1242 while( mtd != null){
1243 if( mtd.getNodeType() == Node.ELEMENT_NODE ){
1244 count++;
1245 d = mtd.getFirstChild();
1246 if( d != null ){
1247 `<remove mspace-only content`>
1248 }
1249 if( d != null ){
1250 `<remove d, if white space text`>
1251 } }
1252 d = mtd;
1253 mtd = mtd.getPreviousSibling();
1254 `<remove d, if white space text`>
1255 if( (d != null)
1256 && (d.getNodeType() == Node.ELEMENT_NODE) ){
1257 `<remove d, if trailing and childless node`>
1258 if( d == null ){ count--; }
1259 } }
1260 if( count > cols ){ cols = count; }
1261 } }
1262 d = mtr;
1263 mtr = mtr.getPreviousSibling();
1264 `<remove d, if white space text`>
1265 if( d != null ){
1266 `<remove d, if trailing and childless node`>
1267 } } }
1268 >>>
1269
1270
1271 \<remove d, if white space text\><<<
1272 if(
1273 (d.getNodeType() == Node.TEXT_NODE)
1274 && d.getNodeValue().trim().equals("")
1275 ){
1276 d.getParentNode().removeChild(d);
1277 d = null;
1278 }
1279 >>>
1280
1281 \<remove d, if trailing and childless node\><<<
1282 if( (d.getNextSibling()==null)
1283 && (d.getFirstChild()==null) ){
1284 d.getParentNode().removeChild(d);
1285 d = null;
1286 }
1287 >>>
1288
1289
1290
1291
1292
1293 %%%%%%%%%%%%%
1294 \subsection{Fill Rows}
1295 %%%%%%%%%%%%%
1296
1297
1298
1299
1300
1301 \<fill rows\><<<
1302 if (node.hasChildNodes()) {
1303 mtr = node.getFirstChild();
1304 while( mtr != null){
1305 if( mtr.getNodeType() == Node.ELEMENT_NODE ){
1306 int count = 0;
1307 if (mtr.hasChildNodes()) {
1308 mtd = mtr.getFirstChild();
1309 while( mtd != null){
1310 if( mtd.getNodeType() == Node.ELEMENT_NODE ){
1311 `<insert new line text node`>
1312 count++;
1313 }
1314 mtd = mtd.getNextSibling();
1315 }
1316 }
1317 if( count < cols ){
1318 `<fill with empty mtd nodes`>
1319 } }
1320 mtr = mtr.getNextSibling();
1321 } }
1322 >>>
1323
1324 \<fill with empty mtd nodes\><<<
1325 for(int i = count; i < cols; i++){
1326 mtr.appendChild( ((Document) dom).createElement("math:mtd") );
1327 }
1328 >>>
1329
1330 \<insert new line text node\><<<
1331 mtr.insertBefore( ((Document) dom).createTextNode("\n"), mtd );
1332 >>>
1333
1334
1335 %%%%%%%%%%%%%
1336 \subsection{mspace}
1337 %%%%%%%%%%%%%
1338
1339
1340 \<remove mspace-only content\><<<
1341 boolean remove = true;
1342 for(Node i=d; i!=null; i=i.getNextSibling() ){
1343 if( (i.getNodeType() == Node.ELEMENT_NODE)
1344 && !i.getNodeName().equals("math:mspace") ) {
1345 remove = false; break;
1346 } }
1347 if( remove ){
1348 while( d != null ){
1349 mtd.removeChild(d);
1350 d = mtd.getFirstChild();
1351 } }
1352 >>>
1353
1354 %%%%%%%%%%%%%%%%%%
1355 \section{Shared}
1356 %%%%%%%%%%%%%%%%%%
1357
1358
1359
1360 %%%%%%%%%%%%%
1361 \subsection{XSLT Setup}
1362 %%%%%%%%%%%%%
1363
1364
1365
1366
1367
1368 \<open oo xslt script\><<<
1369 <![CDATA[
1370 <xsl:stylesheet version="1.0"
1371 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1372
1373 xmlns:office="urn:oasis:names:tc:opendocument:xmlns:office:1.0"
1374 xmlns:style="urn:oasis:names:tc:opendocument:xmlns:style:1.0"
1375 xmlns:text="urn:oasis:names:tc:opendocument:xmlns:text:1.0"
1376 xmlns:table="urn:oasis:names:tc:opendocument:xmlns:table:1.0"
1377 xmlns:draw="urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
1378 xmlns:fo="http://www.w3.org/1999/XSL/Format"
1379 xmlns:xlink="http://www.w3.org/1999/xlink"
1380 xmlns:dc="http://purl.org/dc/elements/1.1/"
1381 xmlns:meta="urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
1382 xmlns:number="urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
1383 xmlns:svg="http://www.w3.org/2000/svg"
1384 xmlns:chart="urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
1385 xmlns:dr3d="urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
1386 xmlns:math="http://www.w3.org/1998/Math/MathML"
1387 xmlns:form="urn:oasis:names:tc:opendocument:xmlns:form:1.0"
1388 xmlns:script="urn:oasis:names:tc:opendocument:xmlns:script:1.0"
1389 xmlns:ooo="http://openoffice.org/2004/office"
1390 xmlns:ooow="http://openoffice.org/2004/writer"
1391 xmlns:oooc="http://openoffice.org/2004/calc"
1392 xmlns:dom="http://www.w3.org/2001/xml-events"
1393 xmlns:xforms="http://www.w3.org/2002/xforms"
1394 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
1395 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
1396 >
1397 <xsl:output omit-xml-declaration = "yes" />
1398 >>>
1399
1400
1401
1402 \<open mml xslt script\><<<
1403 <![CDATA[
1404 <xsl:stylesheet version="1.0"
1405 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
1406 xmlns:math="http://www.w3.org/1998/Math/MathML"
1407 xmlns:xlink="http://www.w3.org/1999/xlink"
1408 >
1409 <xsl:output omit-xml-declaration = "yes" />
1410 >>>
1411
1412
1413 \<close xslt script\><<<
1414 <xsl:template match="*|@*|text()|comment()" >
1415 <xsl:copy>
1416 <xsl:apply-templates select="*|@*|text()|comment()" />
1417 </xsl:copy>
1418 </xsl:template>
1419 </xsl:stylesheet>
1420 ]]>
1421 >>>
1422
1423
1424
1425
1426 %%%%%%%%%%%%%
1427 \subsection{Text Namespaces}
1428 %%%%%%%%%%%%%
1429
1430
1431 \<bind text namespace prefixes in the root elementNO\><<<
1432 ((Element) node).setAttribute(
1433 "xmlns:office",
1434 "urn:oasis:names:tc:opendocument:xmlns:office:1.0"
1435 );
1436 ((Element) node).setAttribute(
1437 "xmlns:style",
1438 "urn:oasis:names:tc:opendocument:xmlns:style:1.0"
1439 );
1440 ((Element) node).setAttribute(
1441 "xmlns:text",
1442 "urn:oasis:names:tc:opendocument:xmlns:text:1.0"
1443 );
1444 ((Element) node).setAttribute(
1445 "xmlns:table",
1446 "urn:oasis:names:tc:opendocument:xmlns:table:1.0"
1447 );
1448 ((Element) node).setAttribute(
1449 "xmlns:draw",
1450 "urn:oasis:names:tc:opendocument:xmlns:drawing:1.0"
1451 );
1452 ((Element) node).setAttribute(
1453 "xmlns:fo",
1454 "http://www.w3.org/1999/XSL/Format"
1455 );
1456 ((Element) node).setAttribute(
1457 "xmlns:xlink",
1458 "http://www.w3.org/1999/xlink"
1459 );
1460 ((Element) node).setAttribute(
1461 "xmlns:dc",
1462 "http://purl.org/dc/elements/1.1/"
1463 );
1464 ((Element) node).setAttribute(
1465 "xmlns:meta",
1466 "urn:oasis:names:tc:opendocument:xmlns:meta:1.0"
1467 );
1468 ((Element) node).setAttribute(
1469 "xmlns:number",
1470 "urn:oasis:names:tc:opendocument:xmlns:datastyle:1.0"
1471 );
1472 ((Element) node).setAttribute(
1473 "xmlns:svg",
1474 "http://www.w3.org/2000/svg"
1475 );
1476 ((Element) node).setAttribute(
1477 "xmlns:chart",
1478 "urn:oasis:names:tc:opendocument:xmlns:chart:1.0"
1479 );
1480 ((Element) node).setAttribute(
1481 "xmlns:dr3d",
1482 "urn:oasis:names:tc:opendocument:xmlns:dr3d:1.0"
1483 );
1484 ((Element) node).setAttribute(
1485 "xmlns:math",
1486 "http://www.w3.org/1998/Math/MathML"
1487 );
1488 ((Element) node).setAttribute(
1489 "xmlns:form",
1490 "urn:oasis:names:tc:opendocument:xmlns:form:1.0"
1491 );
1492 ((Element) node).setAttribute(
1493 "xmlns:script",
1494 "urn:oasis:names:tc:opendocument:xmlns:script:1.0"
1495 );
1496 ((Element) node).setAttribute(
1497 "xmlns:ooo",
1498 "http://openoffice.org/2004/office"
1499 );
1500 ((Element) node).setAttribute(
1501 "xmlns:ooow",
1502 "http://openoffice.org/2004/writer"
1503 );
1504 ((Element) node).setAttribute(
1505 "xmlns:oooc",
1506 "http://openoffice.org/2004/calc"
1507 );
1508 ((Element) node).setAttribute(
1509 "xmlns:dom",
1510 "http://www.w3.org/2001/xml-events"
1511 );
1512 ((Element) node).setAttribute(
1513 "xmlns:xforms",
1514 "http://www.w3.org/2002/xforms"
1515 );
1516 ((Element) node).setAttribute(
1517 "xmlns:xsd",
1518 "http://www.w3.org/2001/XMLSchema"
1519 );
1520 ((Element) node).setAttribute(
1521 "xmlns:xsi",
1522 "http://www.w3.org/2001/XMLSchema-instance"
1523 );
1524 >>>
1525
1526
1527 %%%%%%%%%%%%%%%%%%
1528 \section{Unicode in mtex}
1529 %%%%%%%%%%%%%%%%%%
1530
1531 Openoffice dies on non-breaking space characters \verb+&#xA0;+ within
1532 mtext.
1533
1534
1535 \begin{verbatim}
1536 \documentclass{amsart}
1537 \begin{document}
1538 $\text{ the number of spanning trees of }$
1539 \end{document}
1540 \end{verbatim}
1541
1542
1543
1544 \AtEndDocument{\OutputCodE\<OomFilter.java\>}
1545
1546 \ifdojava
1547 \Needs{"
1548 javac OomFilter.java -d \XTPIPES
1549 "}
1550 \fi
1551
1552 \<OomFilter.java\><<<
1553 package tex4ht;
1554 /* OomFilter.java (`version), generated from `jobname.tex
1555 Copyright (C) 2009-2010 TeX Users Group
1556 Copyright (C) `CopyYear.2002. Eitan M. Gurari
1557 `<TeX4ht copyright`> */
1558
1559 import org.xml.sax.helpers.*;
1560 import org.xml.sax.*;
1561 import java.io.PrintWriter;
1562
1563 public class OomFilter extends XMLFilterImpl {
1564 PrintWriter out = null;
1565 boolean mtext = false;
1566 public OomFilter( PrintWriter out,
1567 PrintWriter log, boolean trace ){
1568 this.out = out;
1569 }
1570 public void startElement(String ns, String sName,
1571 String qName, Attributes attr) {
1572 if( qName.equals( "math:mtext" ) ){ mtext = true; }
1573 try{
1574 super.startElement(ns, sName, qName, attr);
1575 } catch( Exception e ){
1576 System.err.println( "--- OomFilter Error 1 --- " + e);
1577 }
1578 }
1579 public void endElement(String ns, String sName, String qName){
1580 if( qName.equals( "math:mtext" ) ){ mtext = false; }
1581 try{
1582 super.endElement(ns, sName, qName);
1583 } catch( Exception e ){
1584 System.err.println( "--- OomFilter Error 2 --- " + e);
1585 } }
1586 public void characters(char[] ch, int start, int length){
1587 try{
1588 if ( mtext ) {
1589 for(int i = start; i<start+length; i++){
1590 if( ch[i] == 160 ){ ch[i] = ' '; }
1591 } }
1592 super.characters(ch, start, length);
1593 } catch( Exception e ){
1594 System.out.println( "--- OomFilter Error 3 --- " + e);
1595 } } }
1596 >>>
1597
1598
1599
1600
1601 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1602 \section{OoFilter}
1603 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1604
1605
1606 %%%%%%%%%%%%%
1607 \subsection{Outline}
1608 %%%%%%%%%%%%%
1609
1610
1611 \AtEndDocument{\OutputCodE\<OoFilter.java\>}
1612
1613 \ifdojava
1614 \Needs{"
1615 javac OoFilter.java -d \XTPIPES
1616 "}
1617 \fi
1618
1619 \<OoFilter.java\><<<
1620 package tex4ht;
1621 /* OoFilter.java (`version), generated from `jobname.tex
1622 Copyright (C) 2009-2010 TeX Users Group
1623 Copyright (C) `CopyYear.2002. Eitan M. Gurari
1624 `<TeX4ht copyright`> */
1625 `<OoFilter imports`>
1626 public class OoFilter extends XMLFilterImpl {
1627 PrintWriter out = null;
1628 public OoFilter( PrintWriter out,
1629 PrintWriter log, boolean trace ){
1630 this.out = out;
1631 }
1632 public void startElement(String ns, String sName,
1633 String qName, Attributes attr) {
1634 if( qName.equals( "draw:frame" ) ){
1635 `<set dimensions of figures`>
1636 }
1637 try{
1638 super.startElement(ns, sName, qName, attr);
1639 } catch( Exception e ){
1640 System.err.println( "--- OoFilter Error 1 --- " + e);
1641 } }
1642 public void processingInstruction(String target, String fileName) {
1643 if( target.equals("tex4ht-lg") ){
1644 fileName = fileName.trim();
1645 if( fileName.replaceAll(" ","").startsWith("file=") ){
1646 `<load font vars`>
1647 `<load font styles`>
1648 } } }
1649 }
1650 >>>
1651
1652
1653
1654 %%%%%%%%%%%%%
1655 \subsection{Dimensions for Figures}
1656 %%%%%%%%%%%%%
1657
1658 \<set dimensions of figures\><<<
1659 String name = attr.getValue("draw:name");
1660 if( (name != null)
1661 && (attr.getValue("svg:width") == null)
1662 && (attr.getValue("svg:height") == null)
1663 ){
1664 java.awt.Image image = new javax.swing.ImageIcon(name).getImage();
1665 int width = image.getWidth(null);
1666 int height = image.getHeight(null);
1667 if( (width>0) && (height>0) ){
1668 org.xml.sax.helpers.AttributesImpl attrs =
1669 new org.xml.sax.helpers.AttributesImpl( attr );
1670 attrs.addAttribute(null, "svg:width", "svg:width",
1671 "String", (width * 72 / 110) + "pt");
1672 attrs.addAttribute(null, "svg:width", "svg:height",
1673 "String", (height * 72 / 110) + "pt");
1674 attr = attrs;
1675 } }
1676 >>>
1677
1678
1679 %%%%%%%%%%%%%
1680 \subsection{Font Styles}
1681 %%%%%%%%%%%%%
1682
1683
1684
1685
1686 \<load font styles\><<<
1687 int length = fileName.length();
1688 int loc = fileName.indexOf(fileName.charAt(length-1));
1689 fileName = fileName.substring(loc+1,length-1);
1690 try{
1691 String s = "";
1692 FileReader fr = new FileReader( fileName );
1693 BufferedReader in = new BufferedReader( fr );
1694 `<htfcss from lg`>
1695 `<rewind lg file`> `<font=(...) from lg`>
1696 `<rewind lg file`> `<Font-css-base: ...`>
1697 `<rewind lg file`> `<process Font-Size: ...`>
1698 `<rewind lg file`> `<process Font(...)`>
1699 } catch(Exception e){
1700 System.err.println( "--- OoFilter Error 2 --- " + e);
1701 }
1702 >>>
1703
1704 \<rewind lg file\><<<
1705 in.close();
1706 fr = new FileReader( fileName );
1707 in = new BufferedReader( fr );
1708 >>>
1709
1710
1711
1712
1713
1714
1715
1716
1717 \<htfcss from lg\><<<
1718 try{
1719 String key = "", body = "";
1720 while( (s=in.readLine()) != null ){
1721 if( s.startsWith("htfcss: ") ){
1722 s = s.substring(8);
1723 int idx = s.indexOf(' ');
1724 if( idx == 0 ){
1725 body += s;
1726 } else {
1727 `<map += (key, body)`>
1728 if( idx == -1 ){
1729 key = s; body = "";
1730 } else {
1731 key = s.substring(0,idx);
1732 body = s.substring(idx);
1733 } } } }
1734 `<map += (key, body)`>
1735 } catch(java.lang.NumberFormatException e){
1736 System.err.println( "--- OoFilter Error 3 --- Improper record: " + s);
1737 }
1738 >>>
1739
1740
1741
1742
1743 \<map += (key, body)\><<<
1744 body = body.trim();
1745 if( body.startsWith( "@media " ) ){
1746 body = body.substring(7).trim();
1747 if( body.startsWith("print ") ){
1748 body = body.substring(6).trim();
1749 } else { key = ""; }
1750 }
1751 if( !key.equals("") ){
1752 String [] property = body.split(";");
1753 for( int i=0; i<property.length; i++ ){
1754 if( !property[i].trim().equals("") ){
1755 int indx = property[i].indexOf(":");
1756 if( indx != -1 ){
1757 String name = property[i].substring(0,indx).trim();
1758 String value = (property[i]+' ').substring(indx+1).trim();
1759 if( !name.equals("") && !value.equals("") ){
1760 `<map[key] += (name,value)`>
1761 } } } } }
1762 >>>
1763
1764
1765 \<map[key] += (name,value)\><<<
1766 if( map.containsKey(key) ){
1767 HashMap <String,String> entry = map.get(key);
1768 entry.put(name,value);
1769 }
1770 else
1771 {
1772 HashMap <String,String> entry = new HashMap <String,String>();
1773 entry.put(name,value);
1774 map.put(key,entry);
1775 }
1776 >>>
1777
1778
1779 \<load font vars\><<<
1780 HashMap <String,HashMap <String,String>> map
1781 = new HashMap<String,HashMap <String,String>>();
1782 >>>
1783
1784
1785
1786
1787
1788
1789
1790 \<Font-css-base: ...\><<<
1791 try{
1792 while( (s=in.readLine()) != null ){
1793 if( s.startsWith("Font_css_base: ") ){
1794 int idx = s.indexOf("Font_css_mag: ");
1795 if( idx != -1 ){
1796 String [] pattern = s.substring(15,idx).trim().split("%s");
1797 if( pattern.length == 3 ){ font_css_base = pattern; }
1798 pattern = (s+' ').substring(idx).trim().split("%s");
1799 if( pattern.length == 2 ){ font_css_mag = pattern; }
1800 } } }
1801 } catch(Exception e){
1802 System.err.println( "--- OoFilter Error 4 --- Improper record: " + s);
1803 }
1804 >>>
1805
1806
1807
1808
1809 \<process Font-Size: ...\><<<
1810 try{
1811 while( (s=in.readLine()) != null ){
1812 if( s.startsWith("Font_Size:") ){
1813 base_font_size = Integer.parseInt( s.substring(10).trim() );
1814 } }
1815 } catch(java.lang.NumberFormatException e){
1816 System.err.println( "--- OoFilter Error 5 --- Improper record: " + s);
1817 }
1818 >>>
1819
1820 \<process Font(...)\><<<
1821 try{
1822 while( (s=in.readLine()) != null ){
1823 if( s.startsWith("Font(") ){
1824 String [] match = s.split("\"");
1825 match[1] = match[1].trim();
1826 match[2] = match[3].trim();
1827 match[3] = match[5].trim();
1828 match[4] = match[7].trim();
1829 `<get font size`>
1830 `<get font style`>
1831 } }
1832 } catch(Exception e){
1833 System.err.println( "--- OoFilter Error 6 --- Improper record: " + s);
1834 }
1835 >>>
1836
1837
1838
1839
1840 \<get font style\><<<
1841 HashMap <String,String> entry = map.get(match[1]);
1842 if( (entry != null) || (second < 98) || (second > 102) ){
1843 String styleName = font_css_base[0] + match[1] +
1844 font_css_base[1] + match[2] +
1845 font_css_base[2];
1846 if( !match[4].equals("100") ){
1847 styleName += font_css_mag[0] + match[4] + font_css_mag[1];
1848 }
1849 `<attr[style:style] := ...`>
1850 super.startElement(null, "style:style", "style:style", attr);
1851 `<attr[style:text-properties] := ...`>
1852 super.startElement(null, "style:text-properties",
1853 "style:text-properties", attr);
1854 super.endElement(null, "style:text-properties",
1855 "style:text-properties");
1856 super.endElement(null, "style:style", "style:style");
1857 }
1858 >>>
1859
1860
1861 \<attr[style:style] := ...\><<<
1862 org.xml.sax.helpers.AttributesImpl attr =
1863 new org.xml.sax.helpers.AttributesImpl();
1864 attr.addAttribute("", "style:name", "style:name", "String", styleName);
1865 attr.addAttribute("", "style:family", "style:family", "String", "text");
1866 >>>
1867
1868 \<attr[style:text-properties] := ...\><<<
1869 attr = new org.xml.sax.helpers.AttributesImpl();
1870 if( entry != null ){
1871 Object [] name = entry.keySet().toArray();
1872 for(int i=0; i < name.length; i++){
1873 String value = entry.get(name[i]);
1874 attr.addAttribute("", "fo:" + (String) name[i],
1875 "fo:" + (String) name[i],
1876 "String", value);
1877 } }
1878 if( (second < 98) || (second > 102) ){
1879 attr.addAttribute("", "fo:font-size", "fo:font-size",
1880 "String", (second / 10.0) + "pt");
1881 }
1882 >>>
1883
1884
1885 % style:font-family-generic=\"swiss\"
1886 % style:font-pitch=\"variable\"
1887
1888 \<load font vars\><<<
1889 String [] font_css_base = {"" , "-", ""};
1890 String [] font_css_mag = {"x-x-", ""};
1891 >>>
1892
1893
1894 \<print font style css\><<<
1895 (IGNORED) fprintf(css_file,
1896 (Font_css_base == NULL)? ".%s-%s" : Font_css_base,
1897 match[1], match[2]);
1898 if( !eq_str(match[4],"100") ){
1899 (IGNORED) fprintf(css_file,
1900 (Font_css_mag == NULL)? "x-x-%s" : Font_css_mag,
1901 match[4]);
1902 }
1903 (IGNORED) fprintf(css_file, "{");
1904 if( (second < 98) || (second > 102) ){
1905 (IGNORED) fprintf(css_file, "font-size:%d%c;", second, '%');
1906 }
1907 if( font_sty ) {
1908 (IGNORED) fprintf(css_file, font_sty->body);
1909 }
1910 (IGNORED) fprintf(css_file, "}\n");
1911 >>>
1912
1913
1914
1915
1916
1917 \<get font size\><<<
1918 {
1919 if( match[3].replaceAll("[0-9]","").equals("") ){
1920 second = (int)
1921 ( Integer.parseInt( match[3] )
1922 * Long.parseLong( match[4] )
1923 / base_font_size
1924 );
1925 while( second > 700 ){ second /= 10; }
1926 } else { second = 100; }
1927 `<inspect font-size argument`>
1928 }
1929 >>>
1930
1931 The following case handles cases like that of
1932 `\verb'Font("ecti","1095","10","100")'', where
1933 \verb=base_font_size= is 11.
1934
1935 \<inspect font-size argument\><<<
1936 if( (int) ( Double.parseDouble(match[2])
1937 / Long.parseLong(match[4])
1938 + 0.5
1939 )
1940 == base_font_size
1941 ){
1942 second = 100;
1943 };
1944 >>>
1945
1946
1947
1948 \<load font vars\><<<
1949 int base_font_size = 10;
1950 int second;
1951 >>>
1952
1953
1954 \<OoFilter imports\><<<
1955 import java.util.*;
1956 import org.xml.sax.helpers.*;
1957 import org.xml.sax.*;
1958 import java.io.PrintWriter;
1959 import java.io.BufferedReader;
1960 import java.io.FileReader;
1961 >>>
1962
1963
1964 \ifdojava
1965 \AtEndDocument{\Needs{%
1966 "pushd \XTPIPES || exit 1
1967 ;
1968 jar cf tex4ht.jar *
1969 ;
1970 popd
1971 ;
1972 mv \XTPIPES tex4ht.jar \TEXMFTEXivBIN
1973 ;
1974 if [ ! -d \TEXMFTEXivXTPIPES\space]; then exit 1; fi
1975 ;
1976 cp \XTPIPES xtpipes/lib/*
1977 \TEXMFTEXivXTPIPES
1978 "}}
1979 \fi
1980
1981 \end{document}