TeX-AutoTeX
view release on metacpan or search on metacpan
lib/TeX/AutoTeX/File.pm view on Meta::CPAN
$log->verbose("We failed utterly to process the TeX file '$self->{filename}'");
}
# ensure that no copies of the tex file are left behind
unlink map {"$dir/$self->{filename}.$_"} qw(with_hyper without_hyper);
return $failed;
}
sub process_encrypted {
my ($self, $process) = @_;
my $log = $self->{fileset}->{log};
my $dir = $self->{fileset}->{dir};
my $file = $self->{filename};
$log->verbose( "Decrypting file '$file'");
my $newfile = $file;
if ('.cry' ne lc substr $newfile, -4, 4, q{}) {
# throw exception
$log->error("filename '$file' does not end in '.cry'.");
}
# arXiv specific
my $key = $process->{decryption_key};
$log->verbose("running: '$CRYPT $newfile $key'");
# ensure proper path so that correct programs decry and cipher are found
if (index($ENV{PATH}, $TEX_PATH) != 0) {
local $ENV{PATH} = "$TEX_PATH/bin:" . $ENV{PATH};
}
my $fullname = "$dir/$newfile";
# The following two lines are necessary to get decry to work
{
open my $OUTFH, '>', $fullname; close $OUTFH;
chmod oct(666), $fullname;
}
$log->verbose("path is: '$ENV{PATH}'");
my $response = `$CRYPT $fullname $key` || "[no response, exit code $?]";
if ($?) {
$log->error("$CRYPT error response: '$response'");
}
if (! -T $fullname || -z _) {
$log->error("'$file' didn't decrypt to a text file.");
}
unlink "$dir/$file" or $log->error("unable to remove '$file': $!");
return;
}
sub process_dvitype {
my ($self, $process) = @_;
my $log = $self->{fileset}->{log};
my $dir = $self->{fileset}->{dir};
my $file = $self->{filename};
my $dvi_flags = $process->{branch} =~ m{texlive/}? '-R2' : '-R';
$dvi_flags .= " $self->{dvi_flags}" if $self->{dvi_flags};
$dvi_flags .= ' -t landscape' if $self->{flags}->{landscape};
$dvi_flags .= $self->{flags}->{keepcomments}? ' -K0' : ' -K1';
my $response;
my $setenv = qq{export HOME=/tmp @{[$ENV{TEXMFCNF}? "TEXMFCNF=$ENV{TEXMFCNF}": q{}]} PATH=$process->{tex_env_path}};
my $crdir = substr $dir, length $TEX_PATH;
while (1) {
$log->verbose(" ~~~~~~~~~~~ Processing file '$file'");
my $dvipscommand = qq#$TEXCHR $TEX_PATH "($setenv; cd $crdir && $DVIPS $dvi_flags -z '$file' -o )" 2>&1#;
$log->verbose('Running: ' . substr $dvipscommand, length "$TEXCHR $TEX_PATH ");
my $dvipstime = time;
$response = `$dvipscommand`;
last if !$?;
$log->verbose("$DVIPS $dvi_flags -z produced an error: $?\nResponse was $response\nRetrying without '-z'");
if (-e "$dir/head.tmp" && -e "$dir/body.tmp") {
unlink "$dir/head.tmp", "$dir/body.tmp";
$log->verbose('removed dvips leftover head.tmp and body.tmp');
}
# dvips -z may have core-dumped. remove only newly generated core file(s)
if (my @corefiles = glob "$dir/core\.[0-9]*") {
@corefiles =
map { m/(.*)/ }
grep { m{^$dir/core\.\d+$} && (stat "$dir/$_")[9] >= $dvipstime }
@corefiles;
if (@corefiles) {
unlink @corefiles;
$log->verbose("removed one or more core files: @corefiles");
}
}
$dvipscommand = qq#$TEXCHR $TEX_PATH "($setenv; cd $crdir && $DVIPS $dvi_flags '$file' -o )" 2>&1#;
$log->verbose('Running: ' . substr $dvipscommand, length "$TEXCHR $TEX_PATH ");
$response = `$dvipscommand`;
last if !$?;
$log->verbose("$DVIPS $dvi_flags produced an error: $?\nResponse was $response.");
$log->error('Failed to produce postscript from dvi.');
}
$log->verbose("dvi(h)ps said ...\n$response.");
my %commondvipsheaders;
@commondvipsheaders{qw(
tex.pro
texc.pro
texps.pro
hps.pro
special.pro
color.pro
finclude.pro
alt-rule.pro
head.tmp
body.tmp
8r.enc
texnansi.enc
)} = ();
while ($response =~ m{<(?:\.//?)*([^><\n]+)>}g) {
my $included = $1;
if ($included !~ m{^/}){
if (-e "$dir/$included") {
$self->{fileset}->new_File($included)->set_flag('used_by_dvips');
$log->verbose("'$included' no longer required ... it's in the postscript file.");
} elsif (!(exists $commondvipsheaders{$included} || '.pfb' eq substr $included, -4)) {
$log->verbose("'$included' was apparently included, but cannot be deleted, because it cannot be found in cwd.");
}
}
}
my $psfile = $file;
substr $psfile, -3, 3, 'ps';
# Change %%Title if wanted
if (my $stampref = $process->get_stamp()) {
TeX::AutoTeX::PostScript::fix_ps_title(
$psfile,
$dir,
$stampref->[0],
$log
);
TeX::AutoTeX::PostScript::stamp_postscript(
$psfile,
$dir,
$stampref,
$log
);
}
$self->{fileset}->new_File($psfile)->set_flag('main_postscript');
return;
}
sub slurp_log {
my $self = shift;
my $log = $self->basename() . '.log';
lib/TeX/AutoTeX/File.pm view on Meta::CPAN
$tex_format = 'htex';
}
if ($tex_format !~ /209$/ && $tex_type =~ /209/) {
$tex_format .= '209';
}
if ($tex_format =~ /^latex209/ && $program =~ /^h/) {
$tex_format = 'hlatex209';
}
if ($tex_format){
## TS: FIXME
## static lookup table instead of (convoluted) regexp. should go into
## TeX::AutoTeX::Config? here is the list of all formats available in
## arXiv's tex installation. For texlive 2009 and newer arXiv doesn't
## build custom formats any longer.
my %known_formats;
@{$known_formats{'3'}}{qw(
amstex
htex
tex
latex
biglatex
pdfamstex
pdflatex
pdftex
)} = ();
@{$known_formats{'2'}}{qw(
amslatex1.1
amslplain
amstex
biglatex
bigtex
cp-aa
hlatex209
hlatex2e
hlatex
hlplain
hplain
htex
latex209
latex2e
latex
lplain
plain
tex
texsis
)} = ();
if (exists $known_formats{$process->{branch}}{$tex_format}) {
$log->verbose("Using format file $tex_format");
$escaped_tex_format = q{&} . $tex_format;
# escape (&) in $tex_format and remove double quotes
# TS: where would those come from after the lookup table replaced older code?
$escaped_tex_format =~ s/&/\\\&/g;
$escaped_tex_format =~ s/"//g; # "
} else {
$log->verbose("'$tex_format' is not a valid TeX format; will ignore.");
}
}
my $setenv = qq{export HOME=/tmp @{[$ENV{TEXMFCNF}? "TEXMFCNF=$ENV{TEXMFCNF}": q{}]} PATH=$process->{tex_env_path}};
$log->verbose(qq{TEXMFCNF is @{[$ENV{TEXMFCNF}? "set to: '$ENV{TEXMFCNF}'": 'unset.']}});
my $crdir = substr $self->{fileset}->{dir}, length $TEX_PATH;
my $runtexcommand = qq#$TEXCHR $TEX_PATH "($setenv; cd $crdir && $program $escaped_tex_format '$self->{filename}' < $feeder)" 2>&1#;
my $passes = 0;
my $rerun = 0;
my $extra_pass = 0;
my $xfontcreate = 0;
my $lastlog_ref;
my $failed;
my @ORDER = qw(first second third fourth fifth sixth seventh);
PASSES:
while ($passes < $tex_passes) {
$log->verbose(" ~~~~~~~~~~~ Running $tex_type for the $ORDER[$passes] time ~~~~~~~~");
$log->verbose('Running: ' . substr $runtexcommand, length "$TEXCHR $TEX_PATH ");
my $out = `$runtexcommand`;
$log->verbose($out);
$lastlog_ref = $self->slurp_log();
# TS: This is due to peculiarities of feynmf and similar dynamical font
# creation. If we get an error exit status from latex then we need to
# check for new font files and possibly rerun. Only do this once, in
# case the non-zero exit status is due to some problem other than
# font-creation and persistent, otherwise this could loop indefinitely.
if ($?) {
if (!$xfontcreate && $self->extra_fontcreation_pass($stime)) {
$xfontcreate++;
redo PASSES;
} else {
#the message below is slightly misleading because $program for
#latex2e hyper/nohyper is the same.
$log->verbose("$program '$self->{filename}' failed.");
$self->trash_tex_aux_files($stime, $written);
my $dvi = $self->basename() . '.dvi';
if (-e "$self->{fileset}->{dir}/$dvi") {
$log->verbose("removing leftover dvi file '$dvi'");
unlink "$self->{fileset}->{dir}/$dvi" or
$log->verbose("Could not remove file '$dvi'.");
}
$failed = 1;
last;
}
}
if ($passes == 0 && ($tex_type eq 'hlatex2e' ||
$tex_type eq 'latex2e' ||
$tex_type =~ /h?pdflatex/o)) {
if (0 <= index ${$lastlog_ref}, 'LaTeX Warning: Writing file `') {
while(${$lastlog_ref} =~ /LaTeX Warning: Writing file \`([^']*)\'\./g) { # ')){
$written->{$1}++;
}
}
}
# TS: added $tex_format b/c otherwise &amslplain will only be processed twice
if ($tex_type =~ /latex/i || $tex_format) {
if (0 <= index(${$lastlog_ref}, q{Label(s) may have changed. Rerun}) ||
0 <= index(${$lastlog_ref}, q{Warning: Citation(s) may have changed.}) ||
0 <= index(${$lastlog_ref}, q{Table widths have changed. Rerun LaTeX.}) ||
0 <= index(${$lastlog_ref}, q{Rerun to get citations correct.})
) {
( run in 0.907 second using v1.01-cache-2.11-cpan-39bf76dae61 )