/itexToMML

To download this project, use:
bzr branch http://golem.ph.utexas.edu/~distler/code/itexToMML/

« back to all changes in this revision

Viewing changes to plugins/itex2MML/itex2MML.pl

  • Committer: Jacques Distler
  • Date: 2019-01-03 12:28:20 UTC
  • Revision ID: distler@golem.ph.utexas.edu-20190103122820-rqnrpbgnq8784vrk
New version of MovableType plugin

Show diffs side-by-side

added added

removed removed

1
1
# itex2MML
2
 
# version 1.1
3
 
# copyright 2003-2007, Jacques Distler
 
2
# version 2.0
 
3
# copyright 2003-2019, Jacques Distler
4
4
#
5
5
 
6
6
package MT::Plugin::itex2MML;
7
7
 
8
8
use MT;
9
 
use File::Temp qw(tempfile);
 
9
use MathML::itex2MML qw( itex_html_filter );
10
10
 
11
11
use vars qw( $VERSION );
12
 
$VERSION = '1.1';
 
12
$VERSION = '2.0';
13
13
 
14
14
eval{ require MT::Plugin;};
15
15
unless ($@) {
32
32
});
33
33
 
34
34
my $itex2mml_number_equations = 1;
35
 
my $itex2mml_binary = "/usr/local/bin/itex2MML --raw-filter";
36
35
 
37
36
sub itexToMML {
38
37
    $_=shift;
39
38
    $ctx = shift;
40
39
    $_=~ s/\r//g;
41
40
    $_ = number_equations($_, $itex2mml_number_equations, $ctx);
42
 
    my ($Reader,$outfile) = tempfile( UNLINK => 1 );
43
 
    my ($Writer,$infile) = tempfile( UNLINK => 1 );
44
 
    print $Writer "$_";
45
 
    system("$itex2mml_binary <$infile >$outfile");
46
 
    my @out = <$Reader>;
47
 
    close $Reader;
48
 
    close $Writer;
49
 
    eval {unlink ($infile, $outfile);};
50
 
    join('',@out);
 
41
    my $text = itex_html_filter($_);
 
42
    "<div><a href=\"http://golem.ph.utexas.edu/~distler/blog/mathml.html\" onclick=\"window.open\(this.href, \'MathML\', \'width=310,height=150,scrollbars=no,resizable=yes,status=no\'\); return false;\" onkeypress=\"if\(window.event.keyCode == 13\)\{window.open\(this.href, \'MathML\', \'width=310,height=150,scrollbars=no,resizable=yes,status=no\'\); return false;\}\"><img class=\"mathlogo\" src=\"https://golem.ph.utexas.edu/~distler/blog/images/MathML.png\" alt=\"MathML-enabled post \(click for more details\).\" title=\"MathML-enabled post \(click for details\).\" /></a></div>\n" . $text;
51
43
}
52
44
 
53
45
sub itexToMMLpara {
56
48
    $_=~ s/\r//g;
57
49
    $_ = number_equations($_, $itex2mml_number_equations, $ctx);
58
50
    $_ = splitparas($_);
59
 
    my ($Reader,$outfile) = tempfile( UNLINK => 1 );
60
 
    my ($Writer,$infile) = tempfile( UNLINK => 1 );
61
 
    print $Writer "$_";
62
 
    system("$itex2mml_binary <$infile >$outfile");
63
 
    my @out = <$Reader>;
64
 
    close $Reader;
65
 
    close $Writer;
66
 
    eval {unlink ($infile, $outfile);};
67
 
    join('',@out);
 
51
    my $text = itex_html_filter($_);
 
52
    "<div><a href=\"http://golem.ph.utexas.edu/~distler/blog/mathml.html\" onclick=\"window.open\(this.href, \'MathML\', \'width=310,height=150,scrollbars=no,resizable=yes,status=no\'\); return false;\" onkeypress=\"if\(window.event.keyCode == 13\)\{window.open\(this.href, \'MathML\', \'width=310,height=150,scrollbars=no,resizable=yes,status=no\'\); return false;\}\"><img class=\"mathlogo\" src=\"https://golem.ph.utexas.edu/~distler/blog/images/MathML.png\" alt=\"MathML-enabled post \(click for more details\).\" title=\"MathML-enabled post \(click for details\).\" /></a></div>\n" . $text;
68
53
}
69
54
 
70
55
sub splitparas {
73
58
    my @paras = split /\n{2,}/, $str;
74
59
    for my $p (@paras) {
75
60
        if ($p !~ m@^</?(?:h1|h2|h3|h4|h5|h6|table|ol|dl|ul|menu|dir|p|pre|center|form|fieldset|select|blockquote|address|div|hr)@) {
 
61
#        if ($p !~ m@^\s*</?(?:h1|h2|h3|h4|h5|h6|table|ol|dl|ul|menu|dir|p|pre|center|form|fieldset|select|blockquote|address|div|hr)@) {
76
62
            $p = "<p>$p</p>";
77
63
        }
78
64
    }
101
87
 
102
88
  # add equation numbers to \[...\]
103
89
  #  - introduce a wrapper-<div> and a <span> with the equation number
 
90
#  while (s/(^\s*)?\\\[(.*?)\\\]/\n\n$1<div class=\"$cls\"><span>\($eqno\)<\/span>\$\$$2\$\$<\/div>\n\n/s) {
104
91
  while (s/\\\[(.*?)\\\]/\n\n<div class=\"$cls\"><span>\($eqno\)<\/span>\$\$$1\$\$<\/div>\n\n/s) {
105
92
    $eqno++;
106
93
  }