#!/usr/bin/perl -w use strict; (my $basename = $0) =~ s!.*/!!; sub Extract_latex_env { my ($Latex, $Environment) = @_; my $Env_contents; if ($Latex =~ /(\\$Environment(?:\[.*?\])*\{)(.*\})/s) { $Env_contents = $1; my $Search = $2; my $Count = 1; my $Found = 0; while ($Search =~ /\G(.*?(?all_figs.tex' or die "$basename: could not open all_figs.tex for write, $!"; print ALL_FIGS <$figure_fileroot.tex" or die "$basename: could not open $figure_fileroot.tex for write, $!"; print FIG <) { next if (/^%/); s/^(.*?(?; } close BBL or die "$basename: could not close $bbl_file, $!"; my $preamble; if ($tex =~ /^(.*)(?=\\begin{document})/s) { $preamble = $1; } else { die "$basename: no \\begin{document} found in $input_tex_file, aborting.\n"; } $tex =~ s/(?=\\begin{document})/\\newcommand{\\figstretch}{$stretch_factor}\n/; $tex =~ s/(\\begin({figure\*?}).*?\\end\2)/ convert_figure($1,$preamble,\%subfigure_refs)/seg; $tex =~ s/(\\ref{(.*?)})/exists($subfigure_refs{$2}) ? $subfigure_refs{$2} : $1/eg; $tex =~ s/\\bibliography{.*?}/$bbl/; $tex =~ s/(?=\\end{document})/\n\\clearpage\n\\listoffigures\n/; open TEX, ">$output_tex_file" or die "$basename: could not open $output_tex_file for read, $!"; print TEX $tex; close TEX or die "$basename: could not close $output_tex_file, $!";