#!/bin/bash

sed -ibak -E -e "s/\\\\usepackage\{caption\}/\\\\usepackage{etoolbox}\
\\\\robustify\\\\+\
\\\\usepackage{caption}/" "$3/latex/refman.tex"

sed -ibak -E -e "s/\\\\usepackage\[[^\]*\]\{fontenc\}/\\\\usepackage\[$1\]\{fontenc\}\
\\\\usepackage\[$2\]\{babel\}/" "$3/latex/refman.tex"

sed -ibak -E -e "s/documentclass\[twoside\]/documentclass\[oneside\]/" "$3/latex/refman.tex"

# Исправляем слипание длинных номеров (например, 5.40.2.13) в оглавлении PDF
sed -ibak -E -e "s/\\\\setcounter\\{secnumdepth\\}\\{5\\}/\\\\setcounter{secnumdepth}{5}\
\\\\setlength{\\\\cftchapnumwidth}{2.2em}\
\\\\setlength{\\\\cftsecnumwidth}{2.8em}\
\\\\setlength{\\\\cftsubsecnumwidth}{3.6em}\
\\\\setlength{\\\\cftsubsubsecnumwidth}{4.6em}/" "$3/latex/refman.tex"
