From cfed44562985f2f168a5b2f6df46bcaec533d7e9 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Fri, 25 Mar 2011 22:31:43 +0000 Subject: jmlr 1.11 (24mar11) git-svn-id: svn://tug.org/texlive/trunk@21830 c570f23f-e606-0410-a88d-b1316a301751 --- Master/texmf-dist/scripts/jmlr/makejmlrbook | 515 ++++++++++++++++++++++------ 1 file changed, 409 insertions(+), 106 deletions(-) (limited to 'Master/texmf-dist/scripts/jmlr') diff --git a/Master/texmf-dist/scripts/jmlr/makejmlrbook b/Master/texmf-dist/scripts/jmlr/makejmlrbook index 0bef7f02730..40463b22136 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 : 5th Jan 2011 -# Version : 0.2 +# Last Modified : 24th March 2011 +# Version : 0.3 # 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.2 (2011-01-05)"; +my $version = "0.3 (2011-03-24)"; my $eol = "\n"; my $dd = '/'; @@ -55,23 +55,25 @@ my $latexopts = ''; my $bibtexopts = ''; my $format = 'pdf'; my $logourl = ''; +my $extractpreface = 0; # v0.3 added unless(&GetOptions( "online!" => \$online, "print!" => \$print, "html!" => \$html, + "extractpreface!" => \$extractpreface, "logourl=s" => \$logourl, "format=s" => \$format, "latexapp=s" => \$latexapp, "bibtexapp=s" => \$bibtexapp, "latexopts=s" => \$latexopts, "bibtexopts=s" => \$bibtexopts, - "quieter!" => \$quiet, + "quieter!" => \$quiet, "batchtex!" => \$batchtex, "version" => \$showversion, "help" => \$showhelp)) { - die "$!\n", "Use --help for help\n"; + die "Use --help for help\n"; } my $appname = basename($0); @@ -91,6 +93,8 @@ if ($showhelp) "--noprint\t\tDon't generate the grayscale print version\n", "--html\t\t\tGenerate the HTML version (default)\n", "--nohtml\t\tDon't generate the HTML version\n", + "--extractpreface\tParse document for preface environment\n", + "--noextractpreface\tDon't parse document for preface environment\n", "--logourl \tMake the logo on the HTML index page link to \n", "--batchtex\t\tRun TeX in batch mode\n", "--nobatchtex\t\tDon't run TeX in batch mode\n", @@ -137,8 +141,7 @@ $main_suffix = '.tex' unless $main_suffix; my $org_dir = cwd(); -chdir $main_path - or die "Can't change directory to '$main_path': $!\n"; +&chdirordie($main_path); my $mainaux = "$main_name.aux"; @@ -152,13 +155,15 @@ if (not -e $mainaux or (-M $mainaux > -M "$main_name$main_suffix")) # Parse aux file -open AUX, "$mainaux" or die "Can't open '$mainaux' $!\n"; +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 () { @@ -196,6 +201,42 @@ while () $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; @@ -220,13 +261,176 @@ if ($html) unless (-d 'html-src') { mkdir 'html-src' - or die "Can't create directory 'html-src': $!\n"; + or die "$appname: Can't create directory 'html-src': $!\n"; } unless (-d 'html') { mkdir 'html' - or die "Can't create directory 'html': $!\n"; + or die "$appname: Can't create directory 'html': $!\n"; + } + + if ($extractpreface) # v0.3 new + { + # If the preface needs to be extract, make a directory for it if + # it doesn't already exist + + my $prefdir = &fname("html-src", $preface_data->{'OutFile'}); + + unless (-d $prefdir) + { + mkdir $prefdir + or die "$appname: Can't create directory '$prefdir': $!\n"; + } + + 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 () + { + 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{
}", $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 () + { + # 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{
}", $eol, + &htmlmenu, + "\\end{document}", $eol; + + close PREFOUT; + + # Create the cfg file + + &createjmlrcfg("html-src", $preface_data->{'OutFile'}); + + &chdirordie($prefdir); + + &latex($preface_data->{'OutFile'}); + &htlatex($preface_data->{'OutFile'}, 'jmlr'); + + &chdirordie($org_dir, $main_path); + + # Check the appropriate subdirectory is in html directory + + my $outname = &fname('html', $preface_data->{'OutFile'}); + + unless (-d $outname) + { + mkdir $outname + or die "Can't create directory '$outname': $!\n"; + } + + # Copy pdf file + + $outname = &fname($outname, "$preface_data->{OutFile}.$format"); + + copy("$prefbase.$format", $outname) + or die "Can't copy '$prefbase.$format'", " to '$outname': $!\n"; + + # Copy html file + + ©html($preface_data->{'OutFile'}, $preface_data->{'OutFile'}); } } @@ -244,7 +448,7 @@ 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 "Can't open '$aux' $!\n"; + open AUX, $aux or die "$appname: Can't open '$aux' $!\n"; &message("Reading '$aux'...\n"); @@ -270,16 +474,14 @@ foreach my $import (@imports) unless (-e $log) { - chdir $import->{'path'} - or die "Can't change directory to '$import->{path}': $!\n"; + &chdirordie($import->{'path'}); &latex($import->{'name'}); - chdir "$org_dir/$main_path" or - die "Can't change directory to '$org_dir/$main_path': $!\n"; + &chdirordie($org_dir, $main_path); } - open LOGFD, $log or die "Can't open '$log' $!\n"; + open LOGFD, $log or die "$appname: Can't open '$log' $!\n"; &message("Reading '$log'...\n"); @@ -300,44 +502,38 @@ foreach my $import (@imports) if ($runbibtex) { - chdir $import->{'path'} - or die "Can't change directory to '$import->{path}': $!\n"; + &chdirordie($import->{'path'}); &bibtex($import->{'name'}); &latex($import->{'name'}); - chdir "$org_dir/$main_path" or - die "Can't change directory to '$org_dir/$main_path': $!\n"; + &chdirordie($org_dir, $main_path); } } if ($html) { - # If html is required, we also need pdf versions of the - # individual articles. + # If html is required, we also need pdf versions of the + # individual articles. # v0.2 run latex even if pdf file exists to ensure start page # number is correct. - chdir $import->{'path'} - or die "Can't change directory to '$import->{path}': $!\n"; + &chdirordie($import->{'path'}); - &latexstartpage($import->{'name'}, $pagerefs{$label}->{'start'}); + &latexstartpage($import->{'name'}, $pagerefs{$label}->{'start'}); - chdir "$org_dir/$main_path" or - die "Can't change directory to '$org_dir/$main_path': $!\n"; + &chdirordie($org_dir, $main_path); # Do we need a rerun? if (&needs_rerun($importbase)) { - chdir $import->{'path'} - or die "Can't change directory to '$import->{path}': $!\n"; + &chdirordie($import->{'path'}); &latexstartpage($import->{'name'}, $pagerefs{$label}->{'start'}); - chdir &fname($org_dir,$main_path) or - die "Can't change directory to '$org_dir$dd$main_path': $!\n"; + &chdirordie($org_dir,$main_path); } my $importdir = $import->{'path'}; @@ -354,7 +550,7 @@ foreach my $import (@imports) unless (-d $name) { mkdir $name - or die "Can't create directory '$name': $!\n"; + or die "$appname: Can't create directory '$name': $!\n"; } my $text = ''; @@ -364,7 +560,7 @@ foreach my $import (@imports) my $tex = "$importbase.tex"; - open TEX, $tex or die "Can't open '$tex': $!\n"; + open TEX, $tex or die "$appname: Can't open '$tex': $!\n"; while () { @@ -389,6 +585,16 @@ foreach my $import (@imports) $text=~s/^([^%]*)\\documentclass\s*/$1\\documentclass[html]/m; } + my $aux = "$importbase.aux"; + + $aux=~s/\\/\//g if ($dd eq '\\'); + + my $prebegindoc = '\\hypersetup{draft}' . $eol + . '\\makeatletter' . $eol + . "\\input{../../$aux}" . $eol + . '\\makeatother' + . $eol; + my $begindoc = ''; # Set the authors @@ -402,14 +608,15 @@ foreach my $import (@imports) } # Add content div - $text=~s/^([^%]*)\\begin{document}/$&$begindoc\\HCode{
}/m; + $text=~s/^([^%]*)\\begin{document}/$prebegindoc$&$begindoc\\HCode{
}/m; # Create file containing the abstract - my $absfile = "html-src/$importdir/".$import->{'name'}.'.tex'; + my $absfile = &fname("html-src", $importdir, + $import->{'name'}.'.tex'); open ABSFD,">$absfile" - or die "Can't create '$absfile': $!\n"; + or die "$appname: Can't create '$absfile': $!\n"; print ABSFD "\\batchmode", $eol if ($batchtex or $quiet); @@ -424,78 +631,30 @@ foreach my $import (@imports) $text, $eol, "\\HCode{", &htmltimestamp, "}", $eol, "\\HCode{
}", $eol, + &htmlmenu, # v0.3 added by Olivier Chapelle "\\end{document}",$eol; close ABSFD; # Create the cfg file - my $cfg = "html-src/$importdir/jmlr.cfg"; - - open CFG, ">$cfg" or die "Can't create '$cfg': $!\n"; - -print CFG <{'name'}."\" \"jmlr\""); - - if ($code) - { - die "htlatex failed with exit code $code\n"; - } + &htlatex($import->{'name'}, 'jmlr'); # Go back to main directory - chdir "$org_dir$dd$main_path" - or die "Can't change directory to '$org_dir$dd$main_path': $!\n"; + &chdirordie($org_dir, $main_path); # Copy the html file to the html directory, but rename # the css file to jmlr.css - my $infile = &fname("html-src",$importdir, - $import->{'name'}.".html"); - - open INFD, $infile or die "Can't open '$infile': $!\n"; - - my $outfile = &fname("html", $import->{'name'}.".html"); - - open OUTFD, ">$outfile" or die "Can't open '$outfile': $!\n"; - - while () - { - s/href="$import->{name}\.css"/href="jmlr.css"/; - - print OUTFD; - } - - close OUTFD; - - close INFD; - - # Copy css file - - copy("html-src/$importdir/$import->{name}.css", - "html/jmlr.css") - or die "Can't copy 'html-src/$importdir/$import->{name}.css'", - " to 'html/jmlr.css': $!\n"; + ©html($importdir, $import->{'name'}); # Check the appropriate subdirectory is in html directory @@ -590,12 +749,12 @@ if ($html) while () { unless - (s/^([^%]*)\\documentclass\[([^\]]*)\]/$1\\documentclass[$2,html]/) + (s/^([^%]*)\\documentclass\s*\[([^\]]*)\]/$1\\documentclass[$2,html]/) { - s/^([^%]*)\\documentclass/$&\[html\]/; + s/^([^%]*)\\documentclass\s*/$&\[html\]/; } - s/^([^%]*)\\begin{document}/$&\\HCode{
}/; + s/^([^%]*)\\begin{document}/\\hypersetup{draft}$eol$&\\HCode{
}/; if (/^([^%]*)\\maketitle/) { @@ -670,6 +829,36 @@ if ($html) my $toc = "$main_name.toc"; + # Add link to preface if required + + if ($extractpreface) + { + print OUTFD + "\\begin{description}\\item[\\normalfont \\prefacename]", $eol; + + print OUTFD "\\textbf{\\emph{\\jmlrabbrnamelist{{", + join('},{', @preface_editors), + "}}};} ", + '\\csname @jmlrabbrvproceedings\\endcsname\\space', + '\\csname @jmlrvolume\\endcsname:', + $preface_data->{'Start'}; + + unless ($preface_data->{'Start'} eq $preface_data->{'End'}) + { + print OUTFD '--', $preface_data->{'End'}; + } + + print OUTFD ', \\csname @jmlryear\\endcsname\\newline', $eol; + + my $name = $preface_data->{'OutFile'}; + + print OUTFD "[\\HCode{html}] ", + "[\\HCode{pdf}]", + $eol; + + print OUTFD "\\end{description}$eol"; + } + open TOC, $toc or die "Can't open '$toc': $!\n"; my $idx = 0; @@ -682,7 +871,9 @@ if ($html) } elsif (/\\contentsline\s*{papertitle}{(.*)}{[^{}]*}{[^{}]*}\s*$/) { - print OUTFD "\\par\\noindent $1$eol"; + # v0.3 Changed by Olivier Chapelle to use description + # environment instead of paragraph break + print OUTFD "\\begin{description}\\item[\\normalfont $1]$eol"; } elsif (/\\contentsline\s*{chapterauthor}{(.*)}{[^{}]*}{[^{}]*}\s*$/) { @@ -695,11 +886,17 @@ if ($html) $details=~s/\\articlepagesref\s*{$label}/$pages/; - print OUTFD "\\par $details$eol"; + # v0.3 Changed by Olivier Chapelle to use newline instead of par + print OUTFD "$details\\newline$eol"; my $name = $imports[$idx]->{'name'}; - print OUTFD "\\par [\\href{$name.html}{abs}] [\\href{$name/$name.pdf}{pdf}]$eol$eol"; + print OUTFD "[\\HCode{abs}] ", + "[\\HCode{pdf}]", + $eol; + + # v0.3 Changed by Olivier Chapelle to end description + print OUTFD "\\end{description}$eol"; $idx++; } @@ -711,24 +908,19 @@ if ($html) print OUTFD "\\HCode{", &htmltimestamp, "}$eol"; + print OUTFD &htmlmenu; # v0.3 Added by Olivier Chapelle + print OUTFD "\\HCode{
}\\end{document}$eol"; close OUTFD; # Go into html-src directory and run htlatex - chdir('html-src') - or die "Can't change directory to 'html': $!\n"; + &chdirordie('html-src'); - my $code = system('htlatex index'); + &htlatex("index", 'xhtml'); - if ($code) - { - die "htlatex failed with error code $code\n"; - } - - chdir('..') - or die "Can't change directory to '..': $!\n"; + &chdirordie('..'); # Copy to html directory @@ -880,6 +1072,14 @@ sub needs_rerun{ sub fname{ join($dd, @_) } +# v0.3 new +sub chdirordie{ + my $dirname = &fname(@_); + + chdir $dirname + or die "$appname: Can't change directory to $dirname: $!\n"; +} + # v0.2 new sub htmltimestamp{ my $timestamp = localtime; @@ -887,4 +1087,107 @@ sub htmltimestamp{ return "
Page last modified on $timestamp.
"; } +# v0.3 Added by Olivier Chapelle +sub htmlmenu{ + return ' +\\HCode{

} +\\HCode{} +\\HCode{



} +\\HCode{

Home Page } +\\HCode{

Papers } +\\HCode{

Submissions } +\\HCode{

News } +\\HCode{

Scope } +\\HCode{

Editorial Board } +\\HCode{

Announcements } +\\HCode{

Proceedings } +\\HCode{

Open Source Software} +\\HCode{

Search } +\\HCode{

Login

} +\\HCode{

} +\\HCode{

} +\\HCode{RSS Feed} +\\HCode{} +\\HCode{

} +' +} + +# v0.3 new +sub htlatex{ + my ($filename, $cfg) = @_; + + # unicode-related options suggested by Olivier Chapelle + + my $cmd = "htlatex \"$filename\" \"$cfg,uni-html4\" \" -cunihtf -utf8\""; + + my $code = system($cmd); + + if ($code) + { + die "$appname: htlatex failed with exit code $code. ", + "Function call:\n", + $cmd, "\n"; + } +} + +#v0.3 new +sub createjmlrcfg{ + my $cfg = &fname(@_, "jmlr.cfg"); + + open CFG, ">$cfg" or die "$appname: Can't create '$cfg': $!\n"; + +print CFG <$outfile" or die "Can't open '$outfile': $!\n"; + + while () + { + s/href="$name\.css"/href="jmlr.css"/; + + print OUTFD; + } + + close OUTFD; + + close INFD; + + # 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"; + +} + 1; -- cgit v1.2.3