+
+ my $image_loc = '';
+ if (exists $param{fig}) {
+ $param{width} = '400' unless exists $param{width} and defined $param{width};
+ $param{height} = '400' unless exists $param{height} and defined $param{height};
+ for (qw(width height)) {
+ if ($param{$_} !~ /^\d+$/) {
+ error("invalid $_; must be an integer: $param{$_}");
+ }
+ }
+ # because even if the code is duplicated, the figure could
+ # still be different, we track the number of figures
+ $pagestate{$param{page}}{$id}{fignum}++;
+ my $md5 = code_md5($param{code},$param{width},$param{height},$pagestate{$param{page}}{$id}{fignum});
+ $image_loc = "$param{page}/${md5}.png";
+ my $image_loc_esc = $image_loc;
+ $image_loc_esc =~ s/"/\\"/g;
+ will_render($param{page},$image_loc);
+ # this makes sure that we can write to the file result
+ writefile($image_loc, $config{destdir}, "");
+ eval {
+ $pagestate{$param{page}}{$id}{R}->run(qq|png(filename="$config{destdir}/$image_loc_esc",width=$param{width},height=$param{height});|);
+ };
+ if ($@) {
+ error(qq|code 'png(filename="$config{destdir}/$image_loc_esc",width=$param{width},height=$param{height});' (from internal figure handling) produced error '$@'|);
+ }
+ }