]> git.vanrenterghem.biz Git - git.ikiwiki.info.git/blobdiff - IkiWiki/Plugin/teximg.pm
(no commit message)
[git.ikiwiki.info.git] / IkiWiki / Plugin / teximg.pm
index 57b23147eb194746e58a256d2ac4bebf9d5801df..e0f97614b9bf29e7424857e45041ca668c7e449a 100644 (file)
@@ -8,10 +8,12 @@ use strict;
 use Digest::MD5 qw(md5_hex);
 use File::Temp qw(tempdir);
 use HTML::Entities;
-use IkiWiki 2.00;
+use Encode;
+use IkiWiki 3.00;
 
 my $default_prefix = <<EOPREFIX;
 \\documentclass{article}
+\\usepackage[utf8]{inputenc}
 \\usepackage{amsmath}
 \\usepackage{amsfonts}
 \\usepackage{amssymb}
@@ -31,6 +33,7 @@ sub getsetup () {
                plugin => {
                        safe => 1,
                        rebuild => undef,
+                       section => "widget",
                },
                teximg_dvipng => {
                        type => "boolean",
@@ -69,13 +72,7 @@ sub preprocess (@) {
        if (! defined $code && ! length $code) {
                error gettext("missing tex code");
        }
-
-       if (check($code)) {
-               return create($code, check_height($height), \%params);
-       }
-       else {
-               error gettext("code includes disallowed latex commands")
-       }
+       return create($code, check_height($height), \%params);
 }
 
 sub check_height ($) {
@@ -108,7 +105,7 @@ sub create ($$$) {
                $height = 12;
        }
 
-       my $digest = md5_hex($code, $height);
+       my $digest = md5_hex(Encode::encode_utf8($code), $height);
 
        my $imglink= $params->{page} . "/$digest.png";
        my $imglog =  $params->{page} .  "/$digest.log";
@@ -147,15 +144,15 @@ sub gen_image ($$$$) {
        }
        
        my $tex = $config{teximg_prefix};
-       $tex .= '$$'.$code.'$$';
+       $tex .= '\['.$code.'\]';
        $tex .= $config{teximg_postfix};
-       $tex =~ s!\\documentclass{article}!\\documentclass[${height}pt]{article}!g;
-       $tex =~ s!\\documentclass{scrartcl}!\\documentclass[${height}pt]{scrartcl}!g;
+       $tex =~ s!\\documentclass\{article}!\\documentclass[${height}pt]{article}!g;
+       $tex =~ s!\\documentclass\{scrartcl}!\\documentclass[${height}pt]{scrartcl}!g;
 
        my $tmp = eval { create_tmp_dir($digest) };
        if (! $@ &&
            writefile("$digest.tex", $tmp, $tex) &&
-           system("cd $tmp; latex --interaction=nonstopmode $tmp/$digest.tex > /dev/null") == 0 &&
+           system("cd $tmp; shell_escape=f openout_any=p openin_any=p latex --interaction=nonstopmode $digest.tex < /dev/null > /dev/null") == 0 &&
            # ensure destination directory exists
            writefile("$imagedir/$digest.png", $config{destdir}, "") &&
            (($config{teximg_dvipng} &&
@@ -191,34 +188,4 @@ sub create_tmp_dir ($) {
        return $tmpdir;
 }
 
-sub check ($) {
-       # Check if the code is ok
-       my $code = shift;
-
-       my @badthings = (
-               qr/\$\$/,
-               qr/\\include/,
-               qr/\\includegraphic/,
-               qr/\\usepackage/,
-               qr/\\newcommand/, 
-               qr/\\renewcommand/,
-               qr/\\def/,
-               qr/\\input/,
-               qr/\\open/,
-               qr/\\loop/,
-               qr/\\errorstopmode/,
-               qr/\\scrollmode/,
-               qr/\\batchmode/,
-               qr/\\read/,
-               qr/\\write/,
-       );
-       
-       foreach my $thing (@badthings) {
-               if ($code =~ m/$thing/ ) {
-                       return 0;
-               }
-       }
-       return 1;
-}
-
 1