' . "\n";
}
s/\\item/$new/;
return 1;
}
}
sub processInput {
if (/(\\input\{)([^{}]*)(\})/xg) {
$tgtfile = $2;
open( my $INPUTFILE, "<" . $tgtfile . ".tex" );
#print $tgtfile;
while (<$INPUTFILE>) {
processDoc();
}
close $INPUTFILE;
}
}
sub processTabular {
# Tabular environment (tricky)
# but there is only one table to
# take into account
# - begin tabular
if (/\\begin\{tabular\}/) {
$intab = 1;
print <
TABLE_HEAD
next;
}
if ($intab) {
# - end tabular
if (/\\end\{tabular\}/) {
$intab = 0;
print "\<\/td\><\/tr\>\\n";
next;
}
# - replace TeX markers with the HTML
# ones
s/\\\\\[([^\]]*)\]/\\\\/g;
s/\\\\/\<\/td\>\<\/tr\>\
\
/g;
s/\&/\<\/td\>\
/g;
}
}
sub quoterx {
$in=shift;
$in =~ s/\(/\\\(/g;
$in =~ s/\)/\\\)/g;
return $in;
}
sub processTeX {
# THIS HAS TO BE CALLED AFTER TABULAR
# Replace std abbreviations
# PG looks better as it is
s/\\PG/\{{PG\}\}/g;
s/\\cO/\{\\mathcal O\}/g;
s/\\cF/\{\\mathcal F\}g/;
s/\\cH/\{\\mathcal H\}/g;
s/\\fB/\{\\mathfrak B\}/g;
s/\\cU/\{\\mathcal U\}/g;
s/\\par/\ /g;
s/\\\`(\w)/\&$1grave;/g;
s/\\\'(\w)/\&$1acute;/g;
s/\\\"(\w)/\&$1uml;/g;
s/---/\—/g;
s/--/\–/g;
s/\~/\ /g;
#inverted commas
s/\`\`/"/g;
s/\'\'/"/g;
#URL indication
s/\\textasciitilde /\~/g;
#Italic processing
if (/\{([\W]*)\\em([ \w]*)\}/g) {
s/$1/\$2\<\/span\>/g;
}
if (/\\emph\{([\W]*)([ \w]*)\}/g) {
s/$1/\$2\<\/span\>/g;
}
#Boldface processing
if (/\{([\W]*)\\bf(series)? ([ \[\]\w]*)\}/g) {
s/$1/\$3\<\/span\>/g;
}
#Typed font (used for email and web)
# (convert in boldface)
if (/\{([\W]*)\\tt([ \~\:\/\@\.\w]*)\}/g) {
s/$1/\\>$2\<\/span\>/g;
}
### CONVERT MACROS
# std macros: url, href,doi
if (/(\\url\{)([^{}]*)(\})/xg) {
$intro = $1;
$url = $2;
$outro = $3;
$all = "\\" . $intro . $url . $outro;
$repl = '' . $url . '';
s/$all/$repl/;
}
if (/(\\href\{)([^{}]*)(\}\{)([^{}]*)(\})/xg) {
$intro = $1;
$tgt = $2;
$sep0 = $3;
$link = $4;
$outro = $5;
$all = "\\" . $intro . $tgt . $sep0 . $link . $outro;
$repl = '' . $link . '';
s/$all/$repl/;
}
if (/(\\doi\{)([^{}]*)(\})/xg) {
$intro = $1;
$doi = $2;
$outro = $3;
$all = "\\" . $intro . $doi . $outro;
$repl =
''
. 'doi: '
. $doi . '';
$all=quoterx($all);
s/$all/$repl/;
}
#My macros: arxiv
if (/(\\arxiv\{)([^{}]*)(\})/xg) {
$intro = $1;
$arxiv = $2;
$outro = $3;
$all = "\\" . $intro . $arxiv . $outro;
$repl =
''
. '(arxiv: '
. $arxiv . ')';
s/$all/$repl/;
}
if (/(\\issn\{)([^{}]*)(\})/xg) {
$cmd=$1;
$issn=$2;
$outro=$3;
$all=".issn.$issn.";
$repl='ISSN: '.$issn.'';
s/$all/$repl/;
}
if (/(\\semmat\{)([^{}]*)(\}\{)([^{}]*)(\})/xg) {
$num = $2;
$year = $4;
$all = ".semmat.$num..$year.";
$repl =
'Quaderno del Seminario Matematico di Brescia n.'
. ''
. $num . '/'
. $year . '';
s/$all/$repl/;
}
}
sub processDoc() {
# look for babel
if (/\\selectlanguage\{([a-z]*)\}/) {
$lang = $1;
$lang =~ s/british/en/;
$lang =~ s/italian/it/;
}
# Ignore the prologue (we should implement
# at least \newcommand ... then we would
# have a "common solution" of a sort, but
# ...
if (/\\begin\{document\}/) {
$indoc = 1;
printhead( $auth, $email );
next;
}
next if ( !$indoc );
#ignore comments
next if (/^\%/);
$comment = 1 if (/\\begin\{comment\}/);
$comment = 0 if (/\\end\{comment\}/);
next if $comment;
#Tables
processTabular();
#TeX markings+macros
processTeX();
processInput();
#section -> DIV; level 2 heading
$depth = 0;
if (/\\section/) {
/(\{(?: [^{}]* | (?0) )*\})/xgm;
$tgt = $1;
$tgt =~ s/^\{//;
$tgt =~ s/\}$//;
printsect( $tgt, 2 );
$secnum++;
next;
}
#subsection -> level 3 heading
if (/\\subsection/) {
/(\{(?: [^{}]* | (?0) )*\})/xgm;
$tgt = $1;
$tgt =~ s/^\{//;
$tgt =~ s/\}$//;
printsect( $tgt, 3 );
next;
}
#paragraph
if (/^\\par$/) {
print "\
\n";
next;
}
if ( processList() ) {
print;
next;
}
#skip all the other tex constructs (and the line they are
# contained in
if (/^\W*\\[^{begin|end|section|subsection|\[|\$}]*/) { next; }
#print out the text
print;
}
#section heading
sub printsect {
my $titl = shift;
my $levl = shift;
( my $idnam = $titl ) =~ s/ /_/g;
$idnam =~ s/[^\w]/_/g;
if ($secnum) {
$enum == 1
and print '' . "\n";
$enum == 2
and print '' . "\n";
print '
' . "\n";
}
if ( $levl == 2 ) {
push @divtit, $titl;
push @divid, $idnam;
}
print <
\$titl\
END_SECT
}
#standard header
sub printhead {
my $author = shift;
my $email = shift;
my $of = "of";
if ( $lang =~ /it/ ) { $of = "di"; }
print <'."\\n"); ?>
Curriculum $of $author
Curriculum $of $auth
END_HEADER
}
sub createbanner {
print <
Navigation:Home page
END_BH
@divtit = reverse @divtit;
@divid = reverse @divid;
while (@divtit) {
$title = pop @divtit;
$name = pop @divid;
if ($title) {
print <$title
ENDD
}
}
print <
ENDBAN
}
#standard epilogue
sub printend {
my $bsname = "curriculum-eng6";
my $oth = "curriculum-ita6";
my $olang = "Italiano";
my $now_str = gmtime;
if ( $lang =~ /it/ ) {
$bsname = "curriculum-ita6";
$olang = "English";
$oth = "curriculum-eng6";
}
print <