This file is indexed.

/usr/share/perl5/LaTeXML/Post/OpenMath.pm is in latexml 0.7.0-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
# /=====================================================================\ #
# |  LaTeXML::Post::OpenMath                                            | #
# | OpenMath generator for LaTeXML                                      | #
# |=====================================================================| #
# | Part of LaTeXML:                                                    | #
# |  Public domain software, produced as part of work done by the       | #
# |  United States Government & not subject to copyright in the US.     | #
# |---------------------------------------------------------------------| #
# | Bruce Miller <bruce.miller@nist.gov>                        #_#     | #
# | http://dlmf.nist.gov/LaTeXML/                              (o o)    | #
# \=========================================================ooo==U==ooo=/ #

# ================================================================================
# TODO
#     Scheme for mapping from LaTeXML's "meaning" => cd+name
# Unfortunately, OpenMath's naming scheme is unweildy, unless you are
# completely immersed in the OpenMath world. It is also incomplete in
# the sense that it doesn't cover nearly enough symbols that LaTeXML encounters.
# And, of course, many of those symbols are ambiguous!
#
# So, I think LaTeXML's naming scheme is a worthwhile one to pursue,
# but we DO need to provide a rich but customizable mapping, starting with stuff like:
#    equals => arith1:eq
# ================================================================================
package LaTeXML::Post::OpenMath;
use strict;
use LaTeXML::Common::XML;
use base qw(LaTeXML::Post);

our $omURI = "http://www.openmath.org/OpenMath";

sub process {
  my($self,$doc)=@_;
  if(my @maths = $self->find_math_nodes($doc)){
    $self->Progress($doc,"Converting ".scalar(@maths)." formulae");
#    $doc->addNamespace($omURI,'om');
    foreach my $math (@maths){
      $self->processNode($doc,$math); }
    $doc->adjust_latexml_doctype('OpenMath'); } # Add OpenMath if LaTeXML dtd.
  $doc; }

sub setParallel {
  my($self,@moreprocessors)=@_;
  $$self{parallel}=1;
  $$self{math_processors} = [@moreprocessors]; }


sub find_math_nodes { $_[1]->findnodes('//ltx:Math'); }

sub getQName {
  $LaTeXML::Post::DOCUMENT->getQName(@_); }

# $self->processNode($doc,$mathnode) is the top-level conversion
# It converts the XMath within $mathnode, and adds it to the $mathnode,
sub processNode {
  my($self,$doc,$math)=@_;
  my $mode = $math->getAttribute('mode')||'inline';
  my $xmath = $doc->findnode('ltx:XMath',$math);
  my $style = ($mode eq 'display' ? 'display' : 'text');
  if($$self{parallel}){
    $doc->addNodes($math,$self->translateParallel($doc,$xmath,$style,'ltx:Math')); }
  else {
    $doc->addNodes($math,$self->translateNode($doc,$xmath,$style,'ltx:Math')); }}

sub translateNode {
  my($self,$doc,$xmath,$style,$embedding)=@_;
  $doc->addNamespace($omURI,'om');
  my @trans = Expr($xmath);
  # Wrap unless already embedding within MathML.
  ($embedding =~ /^om:/ ? @trans : ['om:OMOBJ',{},@trans]); }

sub getEncodingName { 'OpenMath'; }

sub translateParallel {
  my($self,$doc,$xmath,$style,$embedding)=@_;
  $doc->addNamespace($omURI,'om');
  my @trans = ['om:OMATTR',{},
	       map( (['om:OMS',{cd=>"Alternate", name=>$_->getEncodingName}],
		     ['om:OMFOREIGN',{},$_->translateNode($doc,$xmath,$style,'om:OMATTR')]),
		    @{$$self{math_processors}}),
	       $self->translateNode($doc,$xmath,$style,'om:OMATTR') ];
  # Wrap unless already embedding within MathML.
  ($embedding =~ /^om:/ ? @trans : ['om:OMOBJ',{},@trans]); }

# ================================================================================
our $OMTable={};

sub DefOpenMath {
  my($key,$sub) =@_;
  $$OMTable{$key} = $sub; }

# Is it clear that we should just getAttribute('role'),
# instead of the getOperatorRole like in MML?
sub Expr {
  my($node)=@_;
  return OMError("Missing Subexpression") unless $node;
  my $tag = getQName($node);
  if($tag eq 'ltx:XMath'){
    my($item,@rest)=  element_nodes($node);
    print STDERR "Warning! got extra nodes for content!\n" if @rest;
    Expr($item); }
  elsif($tag eq 'ltx:XMDual'){
    my($content,$presentation) = element_nodes($node);
    Expr($content); }
  elsif($tag eq 'ltx:XMWrap'){
    # Note... Error?
##    Row(grep($_,map(Expr($_),element_nodes($node)))); 
    (); }
  elsif($tag eq 'ltx:XMApp'){
    my($op,@args) = element_nodes($node);
    return OMError("Missing Operator") unless $op;
    my $sub = lookupConverter('Apply',$op->getAttribute('role'),$op->getAttribute('meaning'));
    &$sub($op,@args); }
  elsif($tag eq 'ltx:XMTok'){
    my $sub = lookupConverter('Token',$node->getAttribute('role'),$node->getAttribute('meaning'));
    &$sub($node); }
  elsif($tag eq 'ltx:XMHint'){
    (); }
  else {
    ['om:OMSTR',{},$node->textContent]; }}

sub lookupConverter {
  my($mode,$role,$name)=@_;
  $name = '?' unless $name;
  $role = '?' unless $role;
  $$OMTable{"$mode:$role:$name"} || $$OMTable{"$mode:?:$name"}
    || $$OMTable{"$mode:$role:?"} || $$OMTable{"$mode:?:?"}; }

# ================================================================================
# Helpers
sub OMError {
  my($msg)=@_;
  ['om:OME',{},
   ['om:OMS',{name=>'unexpected', cd=>'moreerrors'}],
   ['om:OMS',{},$msg]]; }
# ================================================================================
# Tokens

# Note: In general, there needs to be a lot more support/analysis.
# Here, we simply assume that the token is a variable if there's no CD!!!
# See comments above about meaning.
# With the gradual refinement of meaning, in the lack of a mapping,
# we'll just presume that the cd defaults to latexml...
DefOpenMath('Token:?:?',    sub { 
  my($token)=@_;
  if(my $meaning = $token->getAttribute('meaning')){
    my $cd = $token->getAttribute('omcd') || 'latexml';
    ['om:OMS',{name=>$meaning, cd=>$cd}]; }
  else {
    my $name = $token->getAttribute('name') || $token->textContent;
    ['om:OMV',{name=>$name}]; }});

# NOTE: Presence of '.' distinguishes float from int !?!?
DefOpenMath('Token:NUMBER:?',sub {
  my($node)=@_;
  my $value = $node->getAttribute('meaning'); # name attribute (may) holds actual value.
  $value = $node->textContent unless defined $value;
  if($value =~ /\./){
    ['om:OMF',{dec=>$value}]; }
  else {
    ['om:OMI',{},$value]; }});

DefOpenMath('Token:SUPERSCRIPTOP:?',sub {
   ['om:OMS',{name=>'superscript',cd=>'ambiguous'}];});
DefOpenMath('Token:SUBSCRIPTOP:?',sub {
   ['om:OMS',{name=>'subscript',cd=>'ambiguous'}];});

DefOpenMath("Token:?:\x{2062}", sub {
  ['om:OMS',{name=>'times', cd=>'arith1'}]; });

# ================================================================================
# Applications.

# Generic

DefOpenMath('Apply:?:?', sub {
  my($op,@args)=@_;
  ['om:OMA',{},map(Expr($_),$op,@args)]; });

# NOTE: No support for OMATTR here...

# NOTE: Sketch of what OMBIND support might look like.
# Currently, no such construct is created in LaTeXML...
DefOpenMath('Apply:LambdaBinding:?', sub {
  my($op,$expr,@vars)=@_;
  ['om:OMBIND',{},
   ['om:OMS',{name=>"lambda", cd=>'fns1'},
    ['om:OMBVAR',{},map(Expr($_),@vars)], # Presumably, these yield OMV
    Expr($expr)]]; });

# ================================================================================
1;