:
#!/bin/sh -- # -*- perl -*-
#
# postprocessing of tex4ht-generated css files from the MuPAD
# documentation

eval 'exec perl -w -S $0 ${1+"$@"}'
    if 0;

use lib '/wiwianka/user/cube/share/lib/perl';

use File::Find;

my $css_start = <<'EOF'
.ecss-1095      {font-family: sans-serif;}
.ecsx-1095      {font-weight: bold;}
.ectt-1095      {font-family: monospace;}
.cmr-8          {font-size:85%;}
.cmr-6          {font-size:70%;}
.cmmi-10x-x-109 {font-style: italic;}
.cmmi-8         {font-size:85%; font-style: italic;}
.cmmi-6         {font-size:70%; font-style: italic;}
.cmsy-10x-x-109 {}
.cmsy-8         {font-size:85%;}
.cmsy-6         {font-size:70%;}
.cmex-10x-x-109 {}
.msbm-10x-x-109 {}
.msbm-8         {font-size:85%;}
.ecrm-1200      {font-size:109%;}
.ectt-1200      {font-size:109%; font-family: monospace;}
.ecbx-1200      {font-size:109%; font-weight: bold;}
.ecbx-1095      {font-size:90%; font-weight: bold;}
.ecsx-1200      {font-size:109%; font-weight: bold;}
.ecti-1095      {font-style: italic;}
.cmtt-10x-x-109 {font-family: monospace;}
.cmtt-8         {font-size:85%;font-family: monospace;}
.ecit-1095      {font-style: italic; font-family: monospace;}
.ecrm-1000      {font-size:90%;}
.ectt-1000      {font-size:90%; font-family: monospace;}
.ecsl-1095      {}
.ectc-1095      {}
.cmmi-12        {font-size:109%;font-style: italic;}
.small-caps     {font-variant: small-caps;}
p.noindent      { text-indent: 0em }
p.nopar         { text-indent: 0em; }
p.indent        { text-indent: 1.5em }
a img           { border-top: 0; border-left: 0; border-right: 0; }
center          { margin-top:1em; margin-bottom:1em; }
td center       { margin-top:0em; margin-bottom:0em; }
.Canvas         { position:relative; }
img.math        {vertical-align:middle;}
li p.indent     { text-indent: 0em }
span.footnotetext { font-size:80%; font-style:italic; } 
.obeylines-h,.obeylines-v {white-space: nowrap; }
.overline       { text-decoration:overline; }
.overline img   { border-top: 1px solid black; }
td.displaylines {text-align:center; white-space:nowrap;}
div.centerline  {text-align:center;}
div.rightline   {text-align:right;}
div.verbatim    {font-family: monospace; white-space: nowrap; }
span.fbox       {padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 1px; }
div.center, div.center div.center {text-align: center; margin-left:1em; margin-right:1em; margin-top:0.5em; margin-bottom:0.5em;}
div.center div {text-align: left;}
div.flushright, div.flushright div.flushright {text-align: right;}
div.flushright div {text-align: left;}
div.flushleft {text-align: left;}
.underline    { text-decoration:underline; }
.underline img{ border-bottom: 1px solid black; margin-bottom:1pt; }
.framebox-c, .framebox-l, .framebox-r { padding-left:3.0pt; padding-right:3.0pt; text-indent:0pt; border:solid black 0.4pt; }
.framebox-c {text-align:center;}
.framebox-l {text-align:left;}
.framebox-r {text-align:right;}
div.array {text-align:center;}
div.tabular, div.center div.tabular {text-align: center; margin-top:0.5em; margin-bottom:0.5em;}
table.tabular td p{margin-top:0em;}
div.td00{ margin-left:0pt; margin-right:0pt; }
div.td01{ margin-left:0pt; margin-right:5pt; }
div.td10{ margin-left:5pt; margin-right:0pt; }
div.td11{ margin-left:5pt; margin-right:5pt; }
td.td00{ padding-left:0pt; padding-right:0pt; }
td.td01{ padding-left:0pt; padding-right:5pt; }
td.td10{ padding-left:5pt; padding-right:0pt; }
td.td11{ padding-left:5pt; padding-right:5pt; }
.hline hr, .cline hr{ height : 1px; }
.tabbing-right {text-align:right;}
div.newtheorem { margin-bottom: 2em; margin-top: 2em;}
span.TEX {letter-spacing: -0.125em; }
span.TEX span.E{ position:relative;top:0.5ex;left:-0.0417em;}
a span.TEX span.E {text-decoration: none; }
span.LATEX span.A{ position:relative; top:-0.5ex; left:-0.4em; font-size:85%;}
span.LATEX span.TEX{ position:relative; left: -0.4em; }
.marginpar {width:20%; float:right; text-align:left; margin-left:auto; margin-top:0.5em; font-size:85%; text-decoration:underline;}
.marginpar p{margin-top:0.4em; margin-bottom:0.4em;}
div.float {text-align:center;}
div.figure {text-align:center;}
.equation td{text-align:center; }
td.equation { margin-top:1em; margin-bottom:1em; } 
td.eqnarray4 { width:5%; white-space: normal; }
td.eqnarray2 { width:5%; }
table.eqnarray-star, table.eqnarray {width:100%;}
div.eqnarray{text-align:center;}
div.pmatrix {text-align:center;}
span.pmatrix img{vertical-align:middle;}
div.pmatrix {text-align:center;}
img.cdots{vertical-align:middle;}
.partToc a, .partToc, .likepartToc a, .likepartToc {line-height: 200%; font-weight:bold; font-size:110%;}
.caption td.id{font-weight: bold; white-space: nowrap; }
table.caption {text-align:center;}
p.bibitem { text-indent: -2em; margin-left: 2em; margin-top:0.6em; margin-bottom :0.6em; }
p.bibitem-p { text-indent: 0em; margin-left: 2em; margin-top:0.6em; margin-bottom:0.6em; }
.paragraphHead, .likeparagraphHead { margin-top:2em; font-weight: bold;}
.subparagraphHead, .likesubparagraphHead { font-weight: bold;}
.quote {margin-bottom:0.25em; margin-top:0.25em; margin-left:1em; }
div.maketitle {text-align:center;}
h2.titleHead{text-align:center;}
div.maketitle{ margin-bottom: 2em; }
div.author, div.date {text-align:center;}
div.thanks{text-align:left; margin-left:10%; font-size:80%; font-style:italic; }
div.author{white-space: nowrap;}
.quotation {margin-bottom:0.25em; margin-top:0.25em; margin-left:1em; }
.abstract p {margin-left:5%; margin-right:5%;}
.equation td{text-align:center; }
table.align, table.alignat, table.xalignat, table.xxalignat, table.flalign, table.align-star, table.alignat-star, table.xalignat-star, table.flalign-star {width:100%; white-space: nowrap;}
td.align-label { width:5%; }
td.align-odd { text-align:right; padding-right:0.3em;}
td.align-even { text-align:left; padding-right:0.6em;}
td.gather-star, td.gather1 {text-align:center; }
div.verbatiminput {font-family: monospace; white-space: nowrap; }
div.longtable{text-align:center;}
div.array {text-align:center;}
div.tabular, div.center div.tabular {text-align: center; margin-top:0.5em; margin-bottom:0.5em;}
table.tabular td p{margin-top:0em;}
div.td00{ margin-left:0pt; margin-right:0pt; }
div.td01{ margin-left:0pt; margin-right:5pt; }
div.td10{ margin-left:5pt; margin-right:0pt; }
div.td11{ margin-left:5pt; margin-right:5pt; }
td.td00{ padding-left:0pt; padding-right:0pt; }
td.td01{ padding-left:0pt; padding-right:5pt; }
td.td10{ padding-left:5pt; padding-right:0pt; }
td.td11{ padding-left:5pt; padding-right:5pt; }
.hline hr, .cline hr{ height : 1px; }
.figure img.graphics {margin-left:10%;}
div.Warning {padding: 2px; border: 2px #CCCCCC solid; background-color: #FFFFEE; margin-top: 5; margin-bottom: 5;}
.mupin {color: #8B0000;}
.mupout {color: blue;}
EOF
    ;

sub change_file {
    /\.css$/ or return;
    rename($_, $_.'.orig') or die "can't rename $_: $!\n";
    
    open(NEW, '> '.$_) or die "can't open $_ for writing: $!\n";
    open(OLD, '< '.$_.'.orig') or die "can't open $_.orig for reading: $!\n";

    my $doprint = 0;
    print NEW $css_start;
    while (<OLD>) {
	print NEW if $doprint;
	$doprint = 1 if m/^\.mupout /;
    }
    close OLD;
    close NEW;
    unlink $_.'.orig';
}

File::Find::find(\&change_file, '.');
