fmt_latex2e.pl::postASP: Rearrange post processing of TeX file.

* Where applies, check for matches only in linuxdoc-tools provided
  preamble. In that preamble, do not retry matches where a different
  incompatible one succeeded. Only '\nameurl' test seems to go
  outside that preamble.
* Cosmetic changes.
parent e7f9d155
......@@ -6,7 +6,7 @@
#
# Copyright 1996, Cees de Groot
# Copyright 2000, Juan Jose Amor (Support for PDF files)
# Copyright 2006-2008, Agustin Martin (Better LaTeX packages handling, misc changes)
# Copyright 2006-2009, Agustin Martin
# ------------------------------------------------------------------
package LinuxDocTools::fmt_latex2e;
......@@ -327,75 +327,81 @@ $latex2e->{postASP} = sub
# Getting babel options
my $babeloptions = $langlit || "english";
if (($global->{charset} eq "nippon") ||
($global->{charset} eq "euc-kr"))
{
$babeloptions = '';
}
if ( ($global->{charset} eq "nippon")
||
($global->{charset} eq "euc-kr")) {
$babeloptions = '';
}
# Loop over the TeX file
my $inpreamble = 1;
while (defined($texlines[0])) {
$_ = shift @texlines;
# Set right class name and options in the header
if (/^\\documentclass\[\@CLASSOPTIONS\@\]/) {
s/\@(ARTICLE|REPORT|BOOK)\@/$classprefix . lc($1)/e;
s/\@CLASSOPTIONS\@/$classoptions/;
$_ = $_ . "\\makeindex\n" if ($latex2e->{makeindex});
}
# Set right babel options
if (/^\\usepackage\[\@BABELOPTIONS\@\]{babel}/) {
if ( $babeloptions ) {
s/\@BABELOPTIONS\@/$babeloptions/;
} else {
s/^/%%/;
}
}
if (/^\\usepackage.epsfig/ && ($global->{charset} eq "euc-kr")) {
$hlatexopt = "[noautojosa]" if ($latex2e->{latex} eq "hlatexp");
$_ = $_ . "\\usepackage" . "$hlatexopt" . "{hangul}\n";
}
# Deal with input encoding
if ( /\\usepackage\[\@CHARSET\@\]\{inputenc\}/ ) {
if ( $global->{charset} eq "latin" ) {
s/\@CHARSET\@/latin1/;
} else {
s/^/%%/;
}
}
if ( $inpreamble ) {
if (/%end-preamble/) {
$inpreamble = '';
# nippon or euc-kr do not use T1 encoding
if ((/\\usepackage\[T1\]\{fontenc\}/) &&
(($global->{charset} eq "nippon") ||
($global->{charset} eq "euc-kr")))
{
s/^/%%/;
}
if ($latex2e->{pagenumber}) {
$_ = $_ . '\setcounter{page}{' .
$latex2e->{pagenumber} .
"}\n";
} else {
$_ = $_ . "\\pagestyle{empty}\n";
}
if (/%end-preamble/) {
if ($latex2e->{pagenumber}) {
$_ = $_ . '\setcounter{page}{'.
$latex2e->{pagenumber} . "}\n";
} else {
$_ = $_ . "\\pagestyle{empty}\n";
}
$_ = $_ . $global->{pass} . "\n" if ($global->{pass});
}
# Now include the explicitly added stuff
$_ = $_ . $global->{pass} . "\n" if ($global->{pass});
if (/\\nameurl/ && $latex2e->{output} ne "pdf") {
$_ = shift @urlnames;
}
print $OUTFILE $_;
print $OUTFILE $_;
if (/%end-preamble/) {
if ($urlnum && $latex2e->{output} ne "pdf") {
while (defined($urldefines[0])) {
$_ = shift @urldefines;
print $OUTFILE $_;
# Add to preamble url definitions for \urldef
if ($urlnum && $latex2e->{output} ne "pdf") {
foreach my $thisurl ( @urldefines ) {
print $OUTFILE $thisurl;
}
}
} else { # -- Not in last line of linuxdoc-tools added preamble
# Set correct class name and options in the header
if (/^\\documentclass\[\@CLASSOPTIONS\@\]/) {
s/\@(ARTICLE|REPORT|BOOK)\@/$classprefix . lc($1)/e;
s/\@CLASSOPTIONS\@/$classoptions/;
$_ = $_ . "\\makeindex\n" if ($latex2e->{makeindex});
}
# Set correct babel options
elsif (/^\\usepackage\[\@BABELOPTIONS\@\]{babel}/) {
if ( $babeloptions ) {
s/\@BABELOPTIONS\@/$babeloptions/;
} else {
s/^/%%/;
}
}
elsif (/^\\usepackage.epsfig/ && ($global->{charset} eq "euc-kr")) {
$hlatexopt = "[noautojosa]" if ($latex2e->{latex} eq "hlatexp");
$_ = $_ . "\\usepackage" . "$hlatexopt" . "{hangul}\n";
}
# Deal with input encoding
elsif ( /\\usepackage\[\@CHARSET\@\]\{inputenc\}/ ) {
if ( $global->{charset} eq "latin" ) {
s/\@CHARSET\@/latin1/;
} else {
s/^/%%/;
}
}
# nippon or euc-kr do not use T1 encoding
elsif ( (/\\usepackage\[T1\]\{fontenc\}/) &&
( ($global->{charset} eq "nippon") ||
($global->{charset} eq "euc-kr"))) {
s/^/%%/;
}
print $OUTFILE $_;
}
} else { # -- Not in linuxdocsgml added preamble
#
if (/\\nameurl/ && $latex2e->{output} ne "pdf") {
$_ = shift @urlnames;
}
print $OUTFILE $_;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment