summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/scripts/jmlr/makejmlrbook
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/scripts/jmlr/makejmlrbook')
-rwxr-xr-xMaster/texmf-dist/scripts/jmlr/makejmlrbook787
1 files changed, 451 insertions, 336 deletions
diff --git a/Master/texmf-dist/scripts/jmlr/makejmlrbook b/Master/texmf-dist/scripts/jmlr/makejmlrbook
index 40463b22136..20b82e48893 100755
--- a/Master/texmf-dist/scripts/jmlr/makejmlrbook
+++ b/Master/texmf-dist/scripts/jmlr/makejmlrbook
@@ -2,8 +2,8 @@
# File : makejmlrbook
# Author : Nicola L C Talbot
# Date : 22nd March 2010
-# Last Modified : 24th March 2011
-# Version : 0.3
+# Last Modified : 30th March 2011
+# Version : 0.31
# Description : Given the name of a document using the
# jmlrbook class file, this script runs
# pdflatex (and possibly bibtex) on the
@@ -31,7 +31,7 @@ use File::Copy;
use Cwd;
use strict;
-my $version = "0.3 (2011-03-24)";
+my $version = "0.31 (2011-03-30)";
my $eol = "\n";
my $dd = '/';
@@ -56,6 +56,9 @@ my $bibtexopts = '';
my $format = 'pdf';
my $logourl = '';
my $extractpreface = 0; # v0.3 added
+# execute system calls (--noexecute will just list the system calls
+# without executing them)
+my $execute = 1; # v0.31 added
unless(&GetOptions(
"online!" => \$online,
@@ -70,6 +73,7 @@ unless(&GetOptions(
"bibtexopts=s" => \$bibtexopts,
"quieter!" => \$quiet,
"batchtex!" => \$batchtex,
+ "execute!" => \$execute,
"version" => \$showversion,
"help" => \$showhelp))
{
@@ -100,6 +104,9 @@ if ($showhelp)
"--nobatchtex\t\tDon't run TeX in batch mode\n",
"--quieter\t\tReduce messages to stdout and run TeX in batch mode\n",
"--noquieter\t\tDon't reduce messages to stdout\n",
+ "--execute\t\tExecute system calls (default)\n",
+ "--noexecute\t\tDon't execute system calls, just list the\n",
+ "\t\t\tcommands.\n",
"--version\t\tDisplay version number and exit\n",
"--help\t\t\tDisplay help message and exit\n",
"\nAdvanced options:\n",
@@ -126,7 +133,7 @@ unless ($#ARGV == 0)
if ($quiet or $batchtex)
{
- $latexopts = '-interaction batchmode '.$latexopts;
+ $latexopts = '-interaction=batchmode '.$latexopts;
}
if ($quiet)
@@ -153,93 +160,15 @@ if (not -e $mainaux or (-M $mainaux > -M "$main_name$main_suffix"))
&latex($main_name);
}
-# Parse aux file
-
-open AUX, "$mainaux" or die "$appname: Can't open '$mainaux' $!\n";
-
-&message("Reading '$mainaux'...\n");
-
my $main_bibdata = 0;
my @imports = ();
my %pagerefs = ();
my $preface_data; # v0.3 new
my @preface_editors = ();
-while (<AUX>)
-{
- if (/\\bibdata\b/)
- {
- $main_bibdata = 1;
- }
- elsif (/\\\@jmlr\@import{(.*)}{(.*)}{(.*)}/)
- {
- my $import =
- {
- label => $1,
- path => $2,
- name => $3
- };
-
- $import->{'name'} =~s/\.(tex|ltx)\Z//;
-
- push @imports, $import;
- }
- elsif (/\\contentsline\s*{chapterauthor}{(.*)}{}{}}\s*$/
- and $#imports > -1)
- {
- $imports[$#imports]->{'author'} = $1;
- }
- elsif (/^\\newlabel\s*{([^}]*)jmlrstart}{{([^}]*)}{([^}]*)}/)
- {
- my $label = $1;
-
- $pagerefs{$label}->{'start'} = $3;
- }
- elsif (/^\\newlabel\s*{([^}]*)jmlrend}{{([^}]*)}{([^}]*)}/)
- {
- my $label = $1;
-
- $pagerefs{$label}->{'end'} = $3;
- }
- elsif ($extractpreface) # v0.3 new
- {
- if (/^\\\@prefacestart{([^}]*)}{(\d*)}/)
- {
- $preface_data->{'Start'} = $1;
- $preface_data->{'StartArabic'} = $2;
- }
- elsif (/^\\\@prefaceend{([^}]*)}/)
- {
- $preface_data->{'End'} = $1;
- }
- elsif (/^\\\@prefacefile{([^}]*)}{([^}]*)}/)
- {
- $preface_data->{'File'} = $1;
- $preface_data->{'OutFile'} = $2;
- }
- elsif (/^\\\@prefaceeditor{(.*)}/)
- {
- my $name = $1;
- $name=~s/\\\\.*//;
- push @preface_editors, $name;
- }
- }
-}
-
-# if preface is to be extracted, has the require data been found?
-
-if ($extractpreface)
-{
- unless ($preface_data->{'File'})
- {
- warn "$appname: Can't find preface information in aux file.\n",
- "Have you used the preface environment?\n";
-
- $extractpreface = 0;
- }
-}
+# Parse aux file
-close AUX;
+&parsemainaux($mainaux);
# Replace any instances of \articlepagesref
@@ -260,14 +189,12 @@ if ($html)
unless (-d 'html-src')
{
- mkdir 'html-src'
- or die "$appname: Can't create directory 'html-src': $!\n";
+ &mkdirordie('html-src');
}
unless (-d 'html')
{
- mkdir 'html'
- or die "$appname: Can't create directory 'html': $!\n";
+ &mkdirordie('html');
}
if ($extractpreface) # v0.3 new
@@ -279,126 +206,12 @@ if ($html)
unless (-d $prefdir)
{
- mkdir $prefdir
- or die "$appname: Can't create directory '$prefdir': $!\n";
+ &mkdirordie($prefdir);
}
my $prefbase = &fname($prefdir, $preface_data->{'OutFile'});
- my $prefout = "$prefbase.tex";
-
- # Open preface output file
-
- open PREFOUT, ">$prefout"
- or die "$appname: Can't open '$prefout': $!\n";
-
- print PREFOUT "\\batchmode", $eol if ($batchtex or $quiet);
- print PREFOUT "\\makeatletter", $eol;
- print PREFOUT "\\def\\input\@path{{../../}}", $eol;
- print PREFOUT "\\makeatother", $eol;
-
- # Get the book's preamble
-
- my $filename = "$main_name$main_suffix";
-
- open BOOK, $filename
- or die "$appname: Can't open '$filename': $!\n";
-
- while (<BOOK>)
- {
- if (/\\documentclass/)
- {
- unless (s/^([^%]*)\\documentclass\s*\[(.*)\]/$1\\documentclass[$2,html]/m)
- {
- s/^([^%]*)\\documentclass\s*/$1\\documentclass[html]/m;
- }
-
- print PREFOUT;
- }
- elsif (/^\\begin{document}/)
- {
- if ($preface_data->{'Start'}=~/^[clxvi]+$/)
- {
- print PREFOUT "\\pagenumbering{roman}%", $eol;
- }
- elsif ($preface_data->{'Start'}=~/^[CLXVI]+$/)
- {
- print PREFOUT "\\pagenumbering{Roman}%", $eol;
- }
-
- print PREFOUT
- "\\setcounter{page}{",
- $preface_data->{'StartArabic'},
- "}%", $eol;
-
- # \hypersetup{draft} is used to suppress links.
- # (Only a partial document so internal links may be
- # dead. Also prevents unwanted tag before the DOCTYPE
- # line in the HTML file.)
-
- print PREFOUT
- "\\hypersetup{draft}", $eol,
- '\\makeatletter',
- "\\\@openrightfalse\\input{../../$main_name.aux}",
- '\\makeatother', $eol;
-
- print PREFOUT
- "\\providecommand{\\HCode}[1]{}", $eol,
- "\\title{\\prefacename}", $eol,
- "\\begin{document}", $eol,
- "\\HCode{<div id=\"content\">}", $eol;
-
- last;
- }
- else
- {
- print PREFOUT;
- }
- }
-
- close BOOK;
-
- # Preface file name will have '/' as directory divider
-
- my $preffile = $preface_data->{'File'};
-
- if ($dd eq "\\")
- {
- $preffile=~s/\//\\/g;
- }
-
- open PREFIN, $preffile
- or die "$appname: Can't open '$preffile': $!\n";
-
- my $scanning = 0;
-
- while (<PREFIN>)
- {
- # This is fairly primitive and works best when the begin
- # and end of the environment are on their own line.
-
- if (/\\begin{preface}/)
- {
- print PREFOUT;
- $scanning = 1;
- }
- elsif ($scanning)
- {
- print PREFOUT;
-
- last if /\\end{preface}/;
- }
- }
-
- close PREFIN;
-
- print PREFOUT
- "\\HCode{", &htmltimestamp, "}", $eol,
- "\\HCode{</div>}", $eol,
- &htmlmenu,
- "\\end{document}", $eol;
-
- close PREFOUT;
+ &createprefacefile($prefdir, $prefbase);
# Create the cfg file
@@ -417,16 +230,13 @@ if ($html)
unless (-d $outname)
{
- mkdir $outname
- or die "Can't create directory '$outname': $!\n";
+ &mkdirordie($outname);
}
# Copy pdf file
- $outname = &fname($outname, "$preface_data->{OutFile}.$format");
-
- copy("$prefbase.$format", $outname)
- or die "Can't copy '$prefbase.$format'", " to '$outname': $!\n";
+ &copyordie("$prefbase.$format",
+ &fname($outname, "$preface_data->{OutFile}.$format"));
# Copy html file
@@ -448,21 +258,30 @@ foreach my $import (@imports)
# The aux file should exist because running LaTeX on the
# main file will create the aux file.
- open AUX, $aux or die "$appname: Can't open '$aux' $!\n";
-
- &message("Reading '$aux'...\n");
-
my $bibdata = 0;
- while (<AUX>)
+ if (open AUX, $aux)
{
- if (/\\bibdata\b/)
+ &message("Reading '$aux'...\n");
+
+ while (<AUX>)
{
- $bibdata = 1;
+ if (/\\bibdata\b/)
+ {
+ $bibdata = 1;
+ }
}
- }
- close AUX;
+ close AUX;
+ }
+ elsif (not $execute)
+ {
+ warn "Can't open '$aux' - skipping\n";
+ }
+ else
+ {
+ die "$appname: Can't open '$aux' $!\n";
+ }
# Do we need a bibtex run?
@@ -549,8 +368,7 @@ foreach my $import (@imports)
unless (-d $name)
{
- mkdir $name
- or die "$appname: Can't create directory '$name': $!\n";
+ &mkdirordie($name);
}
my $text = '';
@@ -560,81 +378,96 @@ foreach my $import (@imports)
my $tex = "$importbase.tex";
- open TEX, $tex or die "$appname: Can't open '$tex': $!\n";
+ my $absfile = &fname("html-src", $importdir,
+ $import->{'name'}.'.tex');
- while (<TEX>)
+ if ($execute)
{
- # This doesn't handle complicated cases, such as
- # the author using \abstract ... \endabstract
- # or commenting out the abstract with conditionals
- if (/^([^%]*)\\end{abstract}/)
+ open TEX, $tex or die "$appname: Can't open '$tex': $!\n";
+
+ while (<TEX>)
{
- $text .= $&;
- last;
+ # This doesn't handle complicated cases, such as
+ # the author using \abstract ... \endabstract
+ # or commenting out the abstract with conditionals
+ if (/^([^%]*)\\end{abstract}/)
+ {
+ $text .= $&;
+ last;
+ }
+
+ $text .= $_;
}
- $text .= $_;
- }
+ close TEX;
- close TEX;
+ # Add the 'html' class option:
+ unless ($text=~
+ s/^([^%]*)\\documentclass\s*\[(.*)\]/$1\\documentclass[$2,html]/m)
+ {
+ $text=~s/^([^%]*)\\documentclass\s*/$1\\documentclass[html]/m;
+ }
- # Add the 'html' class option:
- unless ($text=~
- s/^([^%]*)\\documentclass\s*\[(.*)\]/$1\\documentclass[$2,html]/m)
- {
- $text=~s/^([^%]*)\\documentclass\s*/$1\\documentclass[html]/m;
- }
+ my $aux = "$importbase.aux";
- my $aux = "$importbase.aux";
+ $aux=~s/\\/\//g if ($dd eq '\\');
- $aux=~s/\\/\//g if ($dd eq '\\');
+ my $prebegindoc = '\\hypersetup{draft}' . $eol
+ . '\\makeatletter' . $eol
+ . "\\input{../../$aux}" . $eol
+ . '\\makeatother'
+ . $eol;
- my $prebegindoc = '\\hypersetup{draft}' . $eol
- . '\\makeatletter' . $eol
- . "\\input{../../$aux}" . $eol
- . '\\makeatother'
- . $eol;
+ my $begindoc = '';
- my $begindoc = '';
+ # Set the authors
+ if (defined($import->{'author'}))
+ {
+ my $author = $import->{'author'};
- # Set the authors
- if (defined($import->{'author'}))
- {
- my $author = $import->{'author'};
+ $author=~s/^([^;]*);/\\textbf{\\emph{$1};}/;
- $author=~s/^([^;]*);/\\textbf{\\emph{$1};}/;
+ $begindoc .= "\\jmlrauthors{$author}";
+ }
- $begindoc .= "\\jmlrauthors{$author}";
- }
+ # Add content div
- # Add content div
- $text=~s/^([^%]*)\\begin{document}/$prebegindoc$&$begindoc\\HCode{<div id="content">}/m;
+ # v0.31 modified \footnote to set the footnote text as in-line
+ # parenthesis.
- # Create file containing the abstract
+ $text=~s/^([^%\n\r\f]*)\\begin{document}/
+ $prebegindoc$&$begindoc
+ \\HCode{<div id="content">}
+ \\renewcommand{\\footnote}[2][]{ (\#2)}%$eol
+ /mx;
- my $absfile = &fname("html-src", $importdir,
- $import->{'name'}.'.tex');
+ # Create file containing the abstract
- open ABSFD,">$absfile"
- or die "$appname: Can't create '$absfile': $!\n";
+ open ABSFD,">$absfile"
+ or die "$appname: Can't create '$absfile': $!\n";
- print ABSFD "\\batchmode", $eol if ($batchtex or $quiet);
+ print ABSFD "\\batchmode", $eol if ($batchtex or $quiet);
- my $texpath = $import->{path};
+ my $texpath = $import->{path};
- $texpath=~s/\\/\//g if ($dd eq '\\');
+ $texpath=~s/\\/\//g if ($dd eq '\\');
- print ABSFD
- "\\makeatletter",$eol,
- "\\def\\input\@path{{../../$texpath/}}$eol",
- "\\makeatother",$eol,
- $text, $eol,
- "\\HCode{", &htmltimestamp, "}", $eol,
- "\\HCode{</div>}", $eol,
- &htmlmenu, # v0.3 added by Olivier Chapelle
- "\\end{document}",$eol;
+ print ABSFD
+ "\\makeatletter",$eol,
+ "\\def\\input\@path{{../../$texpath/}}$eol",
+ "\\makeatother",$eol,
+ $text, $eol,
+ "\\HCode{", &htmltimestamp, "}", $eol,
+ "\\HCode{</div>}", $eol,
+ &htmlmenu, # v0.3 added by Olivier Chapelle
+ "\\end{document}",$eol;
- close ABSFD;
+ close ABSFD;
+ }
+ else
+ {
+ &messagecall("Skipping creation of '$absfile'\n");
+ }
# Create the cfg file
@@ -662,16 +495,13 @@ foreach my $import (@imports)
unless (-d $outname)
{
- mkdir $outname
- or die "Can't create directory '$outname': $!\n";
+ &mkdirordie($outname);
}
# Copy pdf file
- $outname = &fname($outname, "$import->{name}.$format");
-
- copy("$importbase.$format", $outname)
- or die "Can't copy '$importbase.$format'", " to '$outname': $!\n";
+ &copyordie("$importbase.$format",
+ &fname($outname, "$import->{name}.$format"));
}
}
@@ -724,7 +554,7 @@ if ($print)
}
}
-if ($html)
+if ($html and $execute)
{
# Make the index file
@@ -749,12 +579,14 @@ if ($html)
while (<INFD>)
{
unless
- (s/^([^%]*)\\documentclass\s*\[([^\]]*)\]/$1\\documentclass[$2,html]/)
+ (s/^([^%]*)\\documentclass\s*\[([^\]]*)\]/
+ $1\\documentclass[$2,html]/x)
{
s/^([^%]*)\\documentclass\s*/$&\[html\]/;
}
- s/^([^%]*)\\begin{document}/\\hypersetup{draft}$eol$&\\HCode{<div id="content">}/;
+ s/^([^%]*)\\begin{document}/
+ \\hypersetup{draft}$eol$&\\HCode{<div id="content">}/x;
if (/^([^%]*)\\maketitle/)
{
@@ -768,7 +600,8 @@ if ($html)
close INFD;
# Find the book logo
- if ($preamble=~/\\logo\s*{(%\s*\n)?\\includegraphics\s*(\[[^\]]*\])?{([^}]*)}}/m)
+ if ($preamble
+ =~/\\logo\s*{(%\s*\n)?\\includegraphics\s*(\[[^\]]*\])?{([^}]*)}}/m)
{
my $texpath = $3;
my $orgtexpath = $texpath;
@@ -778,35 +611,30 @@ if ($html)
if (-e $texpath)
{
- copy($texpath, 'html')
- or die "Can't copy '$texpath' to 'html': $!\n";
- copy($texpath, 'html-src')
- or die "Can't copy '$texpath' to 'html-src': $!\n";
+ &copyordie($texpath, 'html');
+
+ &copyordie($texpath, 'html-src');
}
elsif (-e "$texpath.png")
{
- copy("$texpath.png", 'html')
- or die "Can't copy '$texpath.png' to 'html': $!\n";
- copy("$texpath.png", 'html-src')
- or die "Can't copy '$texpath.png' to 'html-src': $!\n";
+ &copyordie("$texpath.png", 'html');
+
+ &copyordie("$texpath.png", 'html-src');
$ext = '.png';
}
elsif (-e "$texpath.jpg")
{
- copy("$texpath.jpg", 'html')
- or die "Can't copy '$texpath.jpg' to 'html': $!\n";
- copy("$texpath.jpg", 'html-src')
- or die "Can't copy '$texpath.jpg' to 'html-src': $!\n";
+ &copyordie("$texpath.jpg", 'html');
+ &copyordie("$texpath.jpg", 'html-src');
$ext = '.jpg';
}
elsif (-e "$texpath.gif")
{
- copy("$texpath.gif", 'html')
- or die "Can't copy '$texpath.gif' to 'html': $!\n";
- copy("$texpath.gif", 'html-src')
- or die "Can't copy '$texpath.gif' to 'html-src': $!\n";
+ &copyordie("$texpath.gif", 'html');
+
+ &copyordie("$texpath.gif", 'html-src');
$ext = '.gif';
}
@@ -815,11 +643,15 @@ if ($html)
if ($logourl)
{
- $preamble=~s/\\includegraphics(\[[^\]]*\])?{$orgtexpath}/\\href{$logourl}{\\includegraphics${1}{$img$ext}}/mg;
+ $preamble=~s/
+ \\includegraphics(\[[^\]]*\])?{$orgtexpath}/
+ \\href{$logourl}{\\includegraphics${1}{$img$ext}}/mgx;
}
else
{
- $preamble=~s/\\includegraphics(\[[^\]]*\])?{$orgtexpath}/\\includegraphics${1}{$img$ext}/mg;
+ $preamble=~s/
+ \\includegraphics(\[[^\]]*\])?{$orgtexpath}/
+ \\includegraphics${1}{$img$ext}/mgx;
}
}
@@ -952,6 +784,11 @@ if ($html)
copy($imagefile, 'html');
}
}
+elsif ($html)
+{
+ &messagecall("chdir 'html-src'\n");
+ &htlatex("index", 'xhtml');
+}
# Return to original directory
chdir $org_dir;
@@ -960,12 +797,24 @@ chdir $org_dir;
sub message{ print @_ unless ($quiet) }
+sub messagecall{ print @_ if (not $quiet or not $execute) }
+
+sub systemcall{
+ my $cmd = shift;
+
+ &messagecall($cmd, "\n");
+
+ my $code = 0;
+
+ $code = system($cmd) if ($execute);
+
+ $code;
+}
+
sub latex{
my $file = shift;
- my $code;
-
- $code = system(join(' ', $latexapp, $latexopts, "\"$file\""));
+ my $code = &systemcall(join(' ', $latexapp, $latexopts, "\"$file\""));
if ($code)
{
@@ -979,9 +828,7 @@ sub latexstartpage{
my $file = shift;
my $page = shift;
- my $code;
-
- $code = system(join(' ', $latexapp, $latexopts,
+ my $code = &systemcall(join(' ', $latexapp, $latexopts,
"\"\\def\\startpage{$page}\\input{$file}\""));
if ($code)
@@ -991,12 +838,21 @@ sub latexstartpage{
}
}
+sub copyordie{
+ my ($org, $dest) = @_;
+
+ &messagecall("copy '$org' to '$dest'\n");
+
+ if ($execute)
+ {
+ copy($org, $dest) or die "Can't copy '$org' to '$dest': $!\n";
+ }
+}
+
sub latexonline{
my $file = shift;
- my $code;
-
- $code = system(join(' ', $latexapp, $latexopts,
+ my $code = &systemcall(join(' ', $latexapp, $latexopts,
"\"\\def\\jmlrgrayscale{0}\\input{$file}\""));
if ($code)
@@ -1005,18 +861,13 @@ sub latexonline{
"Check '$file.log' for details\n";
}
- &message("copying '$file.$format' to '$file-online.$format'\n");
-
- copy("$file.$format", "$file-online.$format")
- or die "Can't copy '$file.$format' to '$file-online.$format': $!\n";
+ &copyordie("$file.$format", "$file-online.$format");
}
sub latexprint{
my $file = shift;
- my $code;
-
- $code = system(join(' ', $latexapp, $latexopts,
+ my $code = &systemcall(join(' ', $latexapp, $latexopts,
"\"\\def\\jmlrgrayscale{1}\\input{$file}\""));
if ($code)
@@ -1025,18 +876,14 @@ sub latexprint{
"Check '$file.log' for details\n";
}
- &message("copying '$file.$format' to '$file-print.$format'\n");
-
- copy("$file.$format", "$file-print.$format")
- or die "Can't copy '$file.$format' to '$file-print.$format': $!\n";
+ &copyordie("$file.$format", "$file-print.$format");
}
sub bibtex{
my $file = shift;
- my $code;
-
- $code = system(join(' ', $bibtexapp, $bibtexopts, "\"$file\""));
+ my $code = &systemcall(
+ join(' ', $bibtexapp, $bibtexopts, "\"$file\""));
if ($code)
{
@@ -1049,6 +896,12 @@ sub needs_rerun{
my $file = shift;
my $rerun = 0;
+ unless ($execute)
+ {
+ &messagecall("Skipping rerun check for '$file'\n");
+ return 0;
+ }
+
# Scan log file for rerun message
my $log = "$file.log";
@@ -1076,8 +929,38 @@ sub fname{ join($dd, @_) }
sub chdirordie{
my $dirname = &fname(@_);
- chdir $dirname
- or die "$appname: Can't change directory to $dirname: $!\n";
+ &messagecall("chdir '$dirname'\n");
+
+ unless (chdir $dirname)
+ {
+ if ($execute)
+ {
+ die "$appname: Can't change directory to $dirname: $!\n";
+ }
+ else
+ {
+ warn "(Can't change directory to '$dirname')\n";
+ }
+ }
+}
+
+# v0.31 new
+sub mkdirordie{
+ my $dirname = &fname(@_);
+
+ &messagecall("mkdir '$dirname'\n");
+
+ unless (mkdir $dirname)
+ {
+ if ($execute)
+ {
+ die "$appname: Can't create directory '$dirname': $!\n";
+ }
+ else
+ {
+ warn "(Can't create directory '$dirname')\n";
+ }
+ }
}
# v0.2 new
@@ -1118,15 +1001,19 @@ sub htlatex{
# unicode-related options suggested by Olivier Chapelle
- my $cmd = "htlatex \"$filename\" \"$cfg,uni-html4\" \" -cunihtf -utf8\"";
+ # v0.31 added latex options in 5th parameter
- my $code = system($cmd);
+ my $code = &systemcall(join(' ', 'htlatex',
+ "\"$filename\"",
+ "\"$cfg,uni-html4\"",
+ "\" -cunihtf -utf8\"",
+ '""',
+ "\" $latexopts\""
+ ));
if ($code)
{
- die "$appname: htlatex failed with exit code $code. ",
- "Function call:\n",
- $cmd, "\n";
+ die "$appname: htlatex failed with exit code $code.\n";
}
}
@@ -1134,6 +1021,12 @@ sub htlatex{
sub createjmlrcfg{
my $cfg = &fname(@_, "jmlr.cfg");
+ unless ($execute)
+ {
+ &messagecall("Skipping creation of '$cfg'\n");
+ return;
+ }
+
open CFG, ">$cfg" or die "$appname: Can't create '$cfg': $!\n";
print CFG <<END_CFG;
@@ -1165,10 +1058,16 @@ sub copyhtml{
my $infile = &fname("html-src", $dir, "$name.html");
- open INFD, $infile or die "Can't open '$infile': $!\n";
-
my $outfile = &fname("html", "$name.html");
+ unless ($execute)
+ {
+ &messagecall("Copy '$infile' to '$outfile'\n");
+ return;
+ }
+
+ open INFD, $infile or die "Can't open '$infile': $!\n";
+
open OUTFD, ">$outfile" or die "Can't open '$outfile': $!\n";
while (<INFD>)
@@ -1184,9 +1083,225 @@ sub copyhtml{
# Copy css file
- copy("html-src/$dir/$name.css", "html/jmlr.css")
- or die "Can't copy 'html-src/$dir/$name.css'",
- " to 'html/jmlr.css': $!\n";
+ &copyordie("html-src/$dir/$name.css", "html/jmlr.css");
+}
+
+sub parsemainaux{
+ my $mainaux = shift;
+
+ &message("Reading '$mainaux'...\n");
+
+ unless (open AUX, "$mainaux")
+ {
+ if ($execute)
+ {
+ die "$appname: Can't open '$mainaux' $!\n";
+ }
+ else
+ {
+ warn "(Can't open '$mainaux' - skipping)\n";
+ return;
+ }
+ }
+
+ while (<AUX>)
+ {
+ if (/\\bibdata\b/)
+ {
+ $main_bibdata = 1;
+ }
+ elsif (/\\\@jmlr\@import{(.*)}{(.*)}{(.*)}/)
+ {
+ my $import =
+ {
+ label => $1,
+ path => $2,
+ name => $3
+ };
+
+ $import->{'name'} =~s/\.(tex|ltx)\Z//;
+
+ push @imports, $import;
+ }
+ elsif (/\\contentsline\s*{chapterauthor}{(.*)}{}{}}\s*$/
+ and $#imports > -1)
+ {
+ $imports[$#imports]->{'author'} = $1;
+ }
+ elsif (/^\\newlabel\s*{([^}]*)jmlrstart}{{([^}]*)}{([^}]*)}/)
+ {
+ my $label = $1;
+
+ $pagerefs{$label}->{'start'} = $3;
+ }
+ elsif (/^\\newlabel\s*{([^}]*)jmlrend}{{([^}]*)}{([^}]*)}/)
+ {
+ my $label = $1;
+
+ $pagerefs{$label}->{'end'} = $3;
+ }
+ elsif ($extractpreface) # v0.3 new
+ {
+ if (/^\\\@prefacestart{([^}]*)}{(\d*)}/)
+ {
+ $preface_data->{'Start'} = $1;
+ $preface_data->{'StartArabic'} = $2;
+ }
+ elsif (/^\\\@prefaceend{([^}]*)}/)
+ {
+ $preface_data->{'End'} = $1;
+ }
+ elsif (/^\\\@prefacefile{([^}]*)}{([^}]*)}/)
+ {
+ $preface_data->{'File'} = $1;
+ $preface_data->{'OutFile'} = $2;
+ }
+ elsif (/^\\\@prefaceeditor{(.*)}/)
+ {
+ my $name = $1;
+ $name=~s/\\\\.*//;
+ push @preface_editors, $name;
+ }
+ }
+ }
+
+ # if preface is to be extracted, has the require data been found?
+
+ if ($extractpreface)
+ {
+ unless ($preface_data->{'File'})
+ {
+ warn "$appname: Can't find preface information in aux file.\n",
+ "Have you used the preface environment?\n";
+
+ $extractpreface = 0;
+ }
+ }
+
+ close AUX;
+}
+
+sub createprefacefile{
+ my ($prefdir, $prefbase) = @_;
+
+ my $prefout = "$prefbase.tex";
+
+ &messagecall("Create preface file '$prefout'\n");
+
+ return unless ($execute);
+
+ # Open preface output file
+
+ open PREFOUT, ">$prefout"
+ or die "$appname: Can't open '$prefout': $!\n";
+
+ print PREFOUT "\\batchmode", $eol if ($batchtex or $quiet);
+ print PREFOUT "\\makeatletter", $eol;
+ print PREFOUT "\\def\\input\@path{{../../}}", $eol;
+ print PREFOUT "\\makeatother", $eol;
+
+ # Get the book's preamble
+
+ my $filename = "$main_name$main_suffix";
+
+ open BOOK, $filename
+ or die "$appname: Can't open '$filename': $!\n";
+
+ while (<BOOK>)
+ {
+ if (/\\documentclass/)
+ {
+ unless (s/^([^%]*)\\documentclass\s*\[(.*)\]/$1\\documentclass[$2,html]/m)
+ {
+ s/^([^%]*)\\documentclass\s*/$1\\documentclass[html]/m;
+ }
+
+ print PREFOUT;
+ }
+ elsif (/^\\begin{document}/)
+ {
+ if ($preface_data->{'Start'}=~/^[clxvi]+$/)
+ {
+ print PREFOUT "\\pagenumbering{roman}%", $eol;
+ }
+ elsif ($preface_data->{'Start'}=~/^[CLXVI]+$/)
+ {
+ print PREFOUT "\\pagenumbering{Roman}%", $eol;
+ }
+
+ print PREFOUT
+ "\\setcounter{page}{",
+ $preface_data->{'StartArabic'},
+ "}%", $eol;
+
+ # \hypersetup{draft} is used to suppress links.
+ # (Only a partial document so internal links may be
+ # dead. Also prevents unwanted tag before the DOCTYPE
+ # line in the HTML file.)
+
+ print PREFOUT
+ "\\hypersetup{draft}", $eol,
+ '\\makeatletter',
+ "\\\@openrightfalse\\input{../../$main_name.aux}",
+ '\\makeatother', $eol;
+
+ print PREFOUT
+ "\\providecommand{\\HCode}[1]{}", $eol,
+ "\\title{\\prefacename}", $eol,
+ "\\begin{document}", $eol,
+ "\\HCode{<div id=\"content\">}", $eol;
+
+ last;
+ }
+ else
+ {
+ print PREFOUT;
+ }
+ }
+
+ close BOOK;
+
+ # Preface file name will have '/' as directory divider
+
+ my $preffile = $preface_data->{'File'};
+
+ if ($dd eq "\\")
+ {
+ $preffile=~s/\//\\/g;
+ }
+
+ open PREFIN, $preffile
+ or die "$appname: Can't open '$preffile': $!\n";
+
+ my $scanning = 0;
+
+ while (<PREFIN>)
+ {
+ # This is fairly primitive and works best when the begin
+ # and end of the environment are on their own line.
+
+ if (/\\begin{preface}/)
+ {
+ print PREFOUT;
+ $scanning = 1;
+ }
+ elsif ($scanning)
+ {
+ print PREFOUT;
+
+ last if /\\end{preface}/;
+ }
+ }
+
+ close PREFIN;
+
+ print PREFOUT
+ "\\HCode{", &htmltimestamp, "}", $eol,
+ "\\HCode{</div>}", $eol,
+ &htmlmenu,
+ "\\end{document}", $eol;
+
+ close PREFOUT;
}