lib/LaTeXML/Post/XMath.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 3 totaltotal 0.0% 0 / 53 CC 4 SCAR 17.0
CC
4
Cov
0%
combineParallel
12.0
convertNode
6.0
rawIDSuffix
2.0
CRAP 5.5
1 # /=====================================================================\ #
2 # | LaTeXML::Post::XMath | #
3 # | XMath pseudo-generator for LaTeXML | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12  
13 # ================================================================================
14 # LaTeXML::XMath Math Formatter for LaTeXML's Parsed Math.
15 # LaTeXML's parallel math markup model is rather primitive;
16 # we just let the ltx:Math contain ltx:XMath and any other math representations.
17 # There isn't any intelligent selection or classification of them (yet?).
18 #
19 # If XMath is going to be kept in the document either alone,
20 # or as the "primary" representation within a Parallel markup,
21 # then all we have to do is leave it alone --- it's fine where it is.
22 #
23 # If it is NOT the primary representation, however, then we'll need
24 # to MOVE the XMath from where it is to whereever the primary representation
25 # wants it. Since it has ID's within it that are already known to the document,
26 # it needs to move, rather than be copied.
27 #
28 # AND, since any formatters that would follow this one would want to translate
29 # the XMath (which is now gone), this math formatter MUST be the last one....
30 # OR... Does it?????
31 # ================================================================================
32  
33 package LaTeXML::Post::XMath;
34 use strict;
35 use warnings;
36 use LaTeXML::Common::XML;
37 use LaTeXML::Post;
38 use base qw(LaTeXML::Post::MathProcessor);
39  
40 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
41 # Top level
42 #%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
43  
44 our $lxMimeType = 'application/x-latexml';
45  
46 sub convertNode {
47 my ($self, $doc, $xmath, $style) = @_;
48 my $idsuffix = $self->IDSuffix;
49 return { processor => $self, encoding => $lxMimeType, mimetype => $lxMimeType,
50 xml => ($idsuffix
51 # Mark this as _sourced (already scanned by associateNode)
52 # If this isn't right, probably have to look into stopping associateNode
53 # when descending into "foreigh" markup??
54 ? ['ltx:XMath', { _sourced => 1 }, map { $doc->cloneNode($_, $idsuffix) } element_nodes($xmath)]
55 # If no idsuffix, we're actually just PRESERVING the xmath,
56 # so we shouldn't need any cloning or id munging (!?!?!?!)
57 : $xmath) }; }
58  
59 sub combineParallel {
60 my ($self, $doc, $xmath, $primary, @secondaries) = @_;
61 # Just return the converted nodes to be added to the ltx:Math
62 my $id = $xmath->getAttribute('fragid');
63 my @alt = ();
64 foreach my $secondary (@secondaries) {
65 my $mimetype = $$secondary{mimetype} || 'unknown';
66 if ($mimetype eq $lxMimeType) { # XMath
67 push(@alt, $$secondary{xml}); }
68 elsif (my $xml = $$secondary{xml}) { # Other XML? may need wrapping.
69 push(@alt, $$secondary{processor}->outerWrapper($doc, $xmath, $xml)); }
70 # elsif (my $src = $$secondary{src}) { # something referred to by a file? Image, maybe?
71 # push(@alt, ['ltx:graphic', { src => $src }]); }
72 # elsif (my $string = $$secondary{string}) { # simple string data?
73 # push(@alt, ['m:annotation', { encoding => $$secondary{encoding} }, $string]); }
74 # anything else ignore?
75 }
76 return { processor => $self, mimetype => $lxMimeType,
77 xml => ['_Fragment_', {}, $$primary{xml}, @alt] }; }
78  
79 sub rawIDSuffix {
80 return '.xm'; }
81  
82 #================================================================================
83  
84 1;