set -eux

rm -f verbatim/output/*.svg

make4ht --shell-escape index.tex "pic-m,pic-equation,svg"

echo 'img[alt="PIC"] { width: 100%; }' >> index.css
echo '.cmtt-10 { font-size: 0.9em; }' >> index.css
echo 'img[src="index3x.svg"] { height: 2.5em; }' >> index.css

sed -i '/prefers-color-scheme/d' index.css
sed -i 's| </span>|</span> |g' index.html
sed -i '/figure.figure/d' index.css
echo 'figure.figure { margin-left: 20px; margin-right: 20px;  }' >> index.css
echo 'pre.verbatim { font-size: 0.9em; }' >> index.css
sed -i 's|color-scheme: light dark;||g' index.css
echo 'figcaption.caption { margin-bottom: 1.3em; margin-top: 0.3em; }' >> index.css
echo '.cmti-10 { font-style: italic; }' >> index.css

sed -i 's/˜/~/g' index.html

sed -i "s|<p class='noindent'><object class='graphics' data='diagrams/z_operations.svg' name='picture diagrams/z_operations' type='image/svg+xml'></object>|<p class='noindent' style='text-align: center;'><object class='graphics' style='width: 40em;' data='diagrams/z_operations.svg' name='picture diagrams/z_operations' type='image/svg+xml'></object>|g" index.html

sed -i '/height: 2.5em;/d' index.css

sed -i 's/index.css/index3.css/g' index.html

mv index.css index3.css

python replace_video.py index.html

for file in verbatim/output/*.svg; do
    sed -i 's|rgb(0%, 0%, 100%)||g' "$file"
    python resize_svg.py "$file"
done
