diff --git a/data/System/LatexModePlugin.txt b/data/System/LatexModePlugin.txt index 543383f..ac8fe92 100644 --- a/data/System/LatexModePlugin.txt +++ b/data/System/LatexModePlugin.txt @@ -424,6 +424,8 @@ This plugin is an enhanced version of the Foswiki:Extensions.MathModePlugin main | Plugin Author: | Foswiki:Main.ScottHoge | | Plugin Version: | 27 Aug 2009 (v 4.0, SVN:%$VERSION%) | | Change History: | %ICON{warning}% v4.0 and above requires Foswiki 1.x.x and above %ICON{warning}% | +| 10 Jun 2014 (v 4.2) | removed all use of depreciated function 'defined' | +| 15 Jun 2010 (v 4.1) | added option for multiple attachments in !LaTeX rendering | | 27 Aug 2009 (v 4.0) | Ported to Foswiki and fixed a few bugs. | | Change History: | %ICON{warning}% v3.x requires TWiki 4.x.x and above %ICON{warning}% | | 27 Oct 2008 (v 3.74) | replaced plugin init with lazy-loading, to fix installer bug | diff --git a/lib/Foswiki/Plugins/LatexModePlugin.pm b/lib/Foswiki/Plugins/LatexModePlugin.pm index c76d613..e512f1e 100644 --- a/lib/Foswiki/Plugins/LatexModePlugin.pm +++ b/lib/Foswiki/Plugins/LatexModePlugin.pm @@ -57,15 +57,10 @@ use strict; use vars qw( $VERSION $RELEASE $debug $sandbox $initialized ); -# @EXPORT_OK -# $user $installWeb -# $default_density $default_gamma $default_scale $preamble -# $eqn $fig $tbl $use_color @norender $tweakinline $rerender - # number the release version of this plugin our $VERSION = '$Rev$'; -our $RELEASE = '4.0'; +our $RELEASE = '4.2'; # our $SHORTDESCRIPTION = 'Enables LaTeX markup (mathematics and more) in Foswiki topics'; # ========================= diff --git a/lib/Foswiki/Plugins/LatexModePlugin/CrossRef.pm b/lib/Foswiki/Plugins/LatexModePlugin/CrossRef.pm index bc3c5a5..5f3c5eb 100644 --- a/lib/Foswiki/Plugins/LatexModePlugin/CrossRef.pm +++ b/lib/Foswiki/Plugins/LatexModePlugin/CrossRef.pm @@ -100,10 +100,11 @@ sub handleReferences } else { # my %tblrefs = %{ $LMPc{'tblrefs'} }; - my %tblrefs = defined(%{ $LMPc{'tblrefs'} }) ? %{$LMPc{'tblrefs'}} : (); - my %figrefs = defined(%{ $LMPc{'figrefs'} }) ? %{$LMPc{'figrefs'}} : (); - my %eqnrefs = defined(%{ $LMPc{'eqnrefs'} }) ? %{$LMPc{'eqnrefs'}} : (); - my %secrefs = defined(%{ $LMPc{'secrefs'} }) ? %{$LMPc{'secrefs'}} : (); + # my %tblrefs = defined(%{ $LMPc{'tblrefs'} }) ? %{$LMPc{'tblrefs'}} : (); + my %tblrefs = (ref($LMPc{'tblrefs'}) eq 'HASH') ? %{$LMPc{'tblrefs'}} : (); + my %figrefs = (ref($LMPc{'figrefs'}) eq 'HASH') ? %{$LMPc{'figrefs'}} : (); + my %eqnrefs = (ref($LMPc{'eqnrefs'}) eq 'HASH') ? %{$LMPc{'eqnrefs'}} : (); + my %secrefs = (ref($LMPc{'secrefs'}) eq 'HASH') ? %{$LMPc{'secrefs'}} : (); # my %eqnrefs = %{ $LMPc{'eqnrefs'} }; # print STDERR map {"$_ => $secrefs{$_}\n"} keys %secrefs; @@ -197,8 +198,8 @@ sub handleFloat } else { ## otherwise, generate HTML ... - my %figrefs = defined(%{ $LMPc{'figrefs'} }) ? %{$LMPc{'figrefs'}} : (); - my %tblrefs = defined(%{ $LMPc{'tblrefs'} }) ? %{$LMPc{'tblrefs'}} : (); + my %figrefs = (ref($LMPc{'figrefs'}) eq 'HASH') ? %{$LMPc{'figrefs'}} : (); + my %tblrefs = (ref($LMPc{'tblrefs'}) eq 'HASH') ? %{$LMPc{'tblrefs'}} : (); my $infrmt = '%s'; my $cpfrmt = ' *%s %d*: %s'; diff --git a/lib/Foswiki/Plugins/LatexModePlugin/Parse.pm b/lib/Foswiki/Plugins/LatexModePlugin/Parse.pm index 972e54f..8fb71e5 100644 --- a/lib/Foswiki/Plugins/LatexModePlugin/Parse.pm +++ b/lib/Foswiki/Plugins/LatexModePlugin/Parse.pm @@ -495,7 +495,7 @@ sub expandComplexBlocks { $str = extractBlocks($str) if ($str =~ m/\\/); # convertSimple($str) if ($str =~ m/\\/); - if (defined($cmd)) { + if ($cmd) { $str =~ s/^(\"|\')|(\"|\')$//g; printF("Try dynamic command: $cmd($str)\n"); my @z = grep(@regSubs,$cmd); @@ -674,9 +674,9 @@ sub extractBlocks { ([\\\w\d\.\=\,\s]+?) \])?$!!xs) # test for a latex command; ); - $star = '' unless defined($star); + $star = '' unless ($star); printF( "\nFound command: $cmd$star ") if ($cmd ne ''); - (defined($opts) and ($opts ne '') ) ? + (($opts) and ($opts ne '') ) ? printF(" opts = $opts \n") : printF("\n"); if ($cmd =~ m!\\[\`\"\'\^\~\.duvtbH]$!) { @@ -699,7 +699,7 @@ sub extractBlocks { $t = ' %SECLABEL{'.$t.'}% '; $txt =~ s/(---\++\!?\s+)([\w\s\$\%\\]+)$/$1$t$2/s; } else { - # (defined($opts)) ? + # ($opts) ? # $b =~ s/\$cmd\*?\Q$opts\E//; # $b =~ s/\$cmd\*?//; $txt .= $b; @@ -714,8 +714,8 @@ sub extractBlocks { my $s1 = "%BEGINLATEX% "; # $b =~ s/(\\[\"\'\`\^\~\.\w]+)$/$s1$1/; $s1 .= $cmd; - $s1 .= $star if defined($star); - $s1 .= $opts if defined($opts); + $s1 .= $star if ($star); + $s1 .= $opts if ($opts); $b = $s1.$b; # if the first character of the next block is a brace, it # likely means we have a complex command... So group diff --git a/lib/Foswiki/Plugins/LatexModePlugin/Render.pm b/lib/Foswiki/Plugins/LatexModePlugin/Render.pm index d3ce551..2252fb7 100644 --- a/lib/Foswiki/Plugins/LatexModePlugin/Render.pm +++ b/lib/Foswiki/Plugins/LatexModePlugin/Render.pm @@ -144,7 +144,10 @@ sub handleLatex my %LMPc = %{ Foswiki::Func::getContext()->{'LMPcontext'} }; - my %eqnrefs = defined(%{ $LMPc{'eqnrefs'} }) ? %{$LMPc{'eqnrefs'}} : (); + my %eqnrefs = (); + if ( $LMPc{'eqnrefs'} ) { + %eqnrefs = %{$LMPc{'eqnrefs'}}; + } # remove latex-common HTML entities from within math env $math_string =~ s/\//og; @@ -180,7 +183,8 @@ sub handleLatex # type inputs). alpha-numeric OK. slash, space, and brackets # are valid in preamble. need semi-colon in eqn lables! # allow '-' and '_' in eqn labels too. - $b =~ m/([\.\\\w\s\:\-\_\{\}]+)/; + # added a ',', to allow multiple attachments. + $b =~ m/([\,\.\\\w\s\:\-\_\{\}]+)/; $b = $1; $opts{$a} = $b; @@ -422,7 +426,7 @@ sub createTempLatexFiles { # restore the declared rendering options my %opts = %{ $markup_opts{$key} }; - # my %opts = defined($LMPc{'markup_opts'}{$key}) ? %{$LMPc{'markup_opts'}{$key}} : (); + # my %opts = ($LMPc{'markup_opts'}{$key}) ? %{$LMPc{'markup_opts'}{$key}} : (); $value =~ s/\n\s*?\n/\n/gs; # disable commands flagged as 'do not render' @@ -432,20 +436,26 @@ sub createTempLatexFiles { } if( exists($opts{'attachment'}) ) { + + $markup_opts{$key}->{'attachment'} = $opts{'attachment'}; # copy image attachments to the working directory + &Foswiki::Func::writeDebug( "copy opts{'attachment'} = ".$opts{'attachment'} ) if $debug; + foreach my $fname (split(/,/,$opts{'attachment'})) { + my ($ext,$af) = ('',''); my @extlist = ('','.eps','.eps.gz','.pdf','.png','.jpg'); + if ( ( $Foswiki::Plugins::VERSION < 1.1 ) or ( $bypassattach ) ) { # filesystem interface $af = join( $pathSep, &Foswiki::Func::getPubDir(), $LMPc{'web'}, $LMPc{'topic'}, - $opts{'attachment'} ); - - $af = Foswiki::Sandbox::normalizeFileName( $af ); + $fname ); + $af = Foswiki::Sandbox::normalizeFileName( $af ); + print "render attachment name: $fname\n"; foreach my $e (@extlist) { $ext = $e; if (-f $af.$ext) { @@ -454,19 +464,20 @@ sub createTempLatexFiles { # copy( $af.$ext, $LATEXWDIR ) || do { copy( $af.$ext, "." ) || do { &Foswiki::Func::writeDebug( "LatexModePlugin: copy failed ".$! ); - $value = "attachment \{".$markup_opts{$key}->{'attachment'}."\} \ not found"; + $value .= "attachment \{".$af.$ext."\} \ not found"; }; - $markup_opts{$key}->{'attachment'} .= $ext; if ($ext ne '') { # if the Plugin chooses the extension, then # set the rendering engine as well. + $markup_opts{$key}->{'attachment'} =~ s/$fname/$fname$ext/; if ($ext =~ m/\.eps/) { $markup_opts{$key}->{'engine'} = 'ps'; } else { $markup_opts{$key}->{'engine'} = 'pdf'; } } + $fname .= $ext; last; } @@ -474,23 +485,24 @@ sub createTempLatexFiles { } else { # database interface my $ext; - my $af= $opts{'attachment'}; + my $af= $fname; foreach my $e (@extlist) { $ext = $e; if ( Foswiki::Func::attachmentExists( $LMPc{'web'}, $LMPc{'topic'}, $af.$ext ) ) { - $markup_opts{$key}->{'attachment'} .= $ext; if ($ext ne '') { # if the Plugin chooses the extension, then # set the rendering engine as well. + $markup_opts{$key}->{'attachment'} =~ s/$fname/$fname$ext/; if ($ext =~ m/\.eps/) { $markup_opts{$key}->{'engine'} = 'ps'; } else { $markup_opts{$key}->{'engine'} = 'pdf'; } } + $fname .= $ext; open(F,">".'.'.$pathSep.$af.$ext); print F Foswiki::Func::readAttachment( $LMPc{'web'}, @@ -501,11 +513,12 @@ sub createTempLatexFiles { } } } - } # end of copy attachment piece - $value = " (attachment ".$markup_opts{$key}->{'attachment'}." not found) " - if ( exists($markup_opts{$key}->{'attachment'}) and - !(-f $markup_opts{$key}->{'attachment'}) ); + $value .= " (attachment ".$fname." not found) " + if ( exists($markup_opts{$key}->{'attachment'}) and + !(-f $fname) ); + } + } # end of copy attachment piece &Foswiki::Func::writeDebug( "LatexModePlugin: ". $value . " :: " . @@ -571,7 +584,7 @@ sub renderEquations { #&Foswiki::Func::writeDebug( "- LatexModePlugin: @revinfo" ) if $debug; #check if there was any math in this document - return unless defined( $LMPc{'hashed_math_strings'} ); + return unless ( $LMPc{'hashed_math_strings'} ); # return unless scalar( keys( %hashed_math_strings ) ); ## 'halt-on-error' is not supported in older versions of tetex, so check to see if it exists: @@ -620,7 +633,7 @@ sub renderEquations { # database interface my ( $meta, undef ) = Foswiki::Func::readTopic( $LMPc{'web'}, $LMPc{'topic'} ); - if ( defined( $meta->{FILEATTACHMENT} ) ) { + if ( $meta->{FILEATTACHMENT} ) { foreach my $c ( @{ $meta->{FILEATTACHMENT} } ) { $extfiles{$c}->{name} = $c->{name}; $extfiles{$c}->{date} = $c->{date} || 0; @@ -826,7 +839,7 @@ sub renderEquations { $_[0] .= "
Latex rendering error!! pdf file was not created.
"; $_[0] .= "
";
-            open(LF,"$LATEXBASENAME.log");
+            open(LF,"pdf_$LATEXBASENAME.log");
             while () {
                 $_[0] .= $_ if (m/Error/);
             }
@@ -845,10 +858,12 @@ sub renderEquations {
             my %opts = %{ $markup_opts{$key} };
             
             if( exists($opts{'attachment'}) ) {
+		&Foswiki::Func::writeDebug( "unlink opts{'attachment'} = ".$opts{'attachment'} ) if $debug;
                 # delete image attachments from the working directory
-                my $af = join( '/', $LATEXWDIR,
-                               $opts{'attachment'} );
-                unlink($af);
+                foreach my $fname (split(/,/,$opts{'attachment'})) {
+		    my $af = join( '/', $LATEXWDIR, $fname );
+		    unlink($af);
+                }
             }
             
             if ( $opts{'engine'} eq 'mimetex' ) {